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 Map_WrapperFactory extends ValueWrapperFactory {
public Map_WrapperFactory() {
}
public ValueWrapper createValueWrapper(IValueProxy value, ThreadReference threadReference) {
return new Map_WrapperFactory.MapWrapper(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/Map;", value.virtualMachine()))) {
return false;
}
return true;
}
}, false);
}
@Override
public String getWrappedType() {
return "Ljava/util/Map;";
}
public static class MapWrapper extends ValueWrapper {
public MapWrapper(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> result = new ArrayList<CustomJavaWatchable>();
PrimitiveValueProxy size = ((PrimitiveValueProxy) value.invokeMethod("size", "()I", getThreadReference()));
result.add(new jetbrains.mps.debugger.java.customViewers.plugin.plugin.Collections.MyWatchable_size(CustomViewersManager.getInstance().fromJdi(size.getJDIValue(), getThreadReference()), "size"));
IObjectValueProxy entries = ((IObjectValueProxy) value.invokeMethod("entrySet", "()Ljava/util/Set;", getThreadReference()));
for (IObjectValueProxy entry : EvaluationUtils.getInstance().<IObjectValueProxy>toIterableProxy(entries, getThreadReference())) {
result.add(new jetbrains.mps.debugger.java.customViewers.plugin.plugin.Collections.MyWatchable_entry(CustomViewersManager.getInstance().fromJdi(entry.getJDIValue(), getThreadReference()), "entry"));
}
return result;
}
}
@Override
public String getName() {
return "Map";
}
}