package jetbrains.mps.debugger.java.customViewers.plugin.plugin;
/*Generated by MPS */
import jetbrains.mps.debugger.java.api.state.proxy.ValueWrapperFactory;
import jetbrains.mps.debugger.java.api.state.proxy.ValueWrapper;
import jetbrains.mps.debugger.java.api.evaluation.proxies.IValueProxy;
import com.sun.jdi.ThreadReference;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.debugger.java.api.evaluation.EvaluationUtils;
import jetbrains.mps.debugger.java.api.evaluation.EvaluationException;
import com.sun.jdi.Value;
import java.util.List;
import jetbrains.mps.debugger.java.api.state.watchables.CustomJavaWatchable;
import jetbrains.mps.debugger.java.api.evaluation.proxies.IObjectValueProxy;
import java.util.Collections;
import java.util.ArrayList;
import jetbrains.mps.debugger.java.api.evaluation.proxies.PrimitiveValueProxy;
import jetbrains.mps.debugger.java.api.state.customViewers.CustomViewersManager;
public class List_WrapperFactory extends ValueWrapperFactory {
public List_WrapperFactory() {
}
public ValueWrapper createValueWrapper(IValueProxy value, ThreadReference threadReference) {
return new List_WrapperFactory.ListWrapper(value, threadReference);
}
@Override
public boolean canWrapValue(@NotNull final IValueProxy proxy) {
return EvaluationUtils.consumeEvaluationException(new EvaluationUtils.EvaluationInvocatable<Boolean>() {
public Boolean invoke() throws EvaluationException {
Value value = proxy.getJDIValue();
if (value == null) {
return false;
}
if (!(EvaluationUtils.getInstance().instanceOf(value.type(), "Ljava/util/List;", value.virtualMachine()))) {
return false;
}
return true;
}
}, false);
}
@Override
public String getWrappedType() {
return "Ljava/util/List;";
}
public static class ListWrapper extends ValueWrapper {
public ListWrapper(IValueProxy value, ThreadReference threadReference) {
super(value, threadReference);
}
protected List<CustomJavaWatchable> getSubvaluesImpl() {
return EvaluationUtils.consumeEvaluationException(new EvaluationUtils.EvaluationInvocatable<List<CustomJavaWatchable>>() {
public List<CustomJavaWatchable> invoke() throws EvaluationException {
return getSubvaluesImpl((IObjectValueProxy) myValue);
}
}, Collections.<CustomJavaWatchable>emptyList());
}
protected List<CustomJavaWatchable> getSubvaluesImpl(IObjectValueProxy value) throws EvaluationException {
List<CustomJavaWatchable> watchables = new ArrayList<CustomJavaWatchable>();
PrimitiveValueProxy size = ((PrimitiveValueProxy) value.invokeMethod("size", "()I", getThreadReference()));
watchables.add(new jetbrains.mps.debugger.java.customViewers.plugin.plugin.Collections.MyWatchable_size(CustomViewersManager.getInstance().fromJdi(size.getJDIValue(), getThreadReference()), "size"));
for (IObjectValueProxy element : EvaluationUtils.getInstance().<IObjectValueProxy>toIterableProxy(value, getThreadReference())) {
watchables.add(new jetbrains.mps.debugger.java.customViewers.plugin.plugin.Collections.MyWatchable_element(CustomViewersManager.getInstance().fromJdi(element.getJDIValue(), getThreadReference()), "element"));
}
return watchables;
}
}
@Override
public String getName() {
return "List";
}
}