blob: 8b474608ff78feebbfdec27149b052978412b97a [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2010, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.debug.core.model;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
import org.eclipse.statet.r.core.data.CombinedRElement;
import org.eclipse.statet.r.debug.core.IRIndexedVariableItem;
import org.eclipse.statet.r.debug.core.IRValue;
import org.eclipse.statet.r.debug.core.IRVariable;
import org.eclipse.statet.rj.data.RDataUtils;
@NonNullByDefault
public class RVectorIndexVariable extends RVariable implements IRIndexedVariableItem, IRValue {
private final RVectorValue mainValue;
private final long index;
public RVectorIndexVariable(final RVectorValue value, final long index,
final IRVariable parent) {
super(value.getDebugTarget(), parent);
this.mainValue= value;
this.index= index;
}
@Override
public long[] getIndex() {
return new long[] { this.index };
}
@Override
public String getName() {
final StringBuilder sb= new StringBuilder();
sb.append('[');
sb.append(this.index + 1);
sb.append(']');
final String name= this.mainValue.getName(this.index);
if (name != null) {
sb.append(' ');
sb.append(' ');
sb.append(name);
}
return sb.toString();
}
@Override
public boolean hasValueChanged() throws DebugException {
return this.mainValue.hasValueChanged(this.index);
}
@Override
public IRValue getValue() throws DebugException {
return this;
}
@Override
public IRVariable getAssignedVariable() {
return this;
}
@Override
public boolean isAllocated() throws DebugException {
return true;
}
@Override
public String getReferenceTypeName() throws DebugException {
final CombinedRElement element= this.mainValue.element;
return RDataUtils.getStoreAbbr(element.getData());
}
@Override
public String getValueString() throws DebugException {
final String data= this.mainValue.getDataExpr(this.index);
if (data == null) {
throw newRequestLoadDataFailed();
}
return data;
}
@Override
public boolean supportsValueModification() {
return true;
}
@Override
public boolean verifyValue(final String expression) throws DebugException {
return this.mainValue.validateDataExpr(expression);
}
@Override
public void setValue(final String expression) throws DebugException {
this.mainValue.setDataExpr(this.index, expression);
}
@Override
public String getDetailString() {
final String data= this.mainValue.getDataExpr(this.index);
if (data == null) {
return "<error>"; //$NON-NLS-1$
}
return data;
}
@Override
public boolean hasVariables() throws DebugException {
return false;
}
@Override
public IVariable[] getVariables() throws DebugException {
return RElementVariableValue.NO_VARIABLES;
}
@Override
public int hashCode() {
return this.mainValue.hashCode() + (int) (this.index ^ (this.index >>> 32));
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
obj= RVariableProxy.unproxy(obj);
if (obj instanceof RVectorIndexVariable) {
final RVectorIndexVariable other= (RVectorIndexVariable) obj;
return (this.mainValue.equals(other.mainValue)
&& this.index == other.index );
}
return false;
}
}