private Object createTranslation (Object o, Object v) { switch (translationID) { case LOCALS_ID: if (o instanceof LocalVariable && (v == null || v instanceof Value)) { LocalVariable lv = (LocalVariable) o; org.netbeans.api.debugger.jpda.LocalVariable local; if (v instanceof ObjectReference || v == null) { local = new ObjectLocalVariable ( debugger, (ObjectReference) v, null, lv, JPDADebuggerImpl.getGenericSignature (lv), null ); } else { local = new Local (debugger, (PrimitiveValue) v, null, lv, null); } return local; } default: throw new IllegalStateException(""+o); } }
ArrayFieldVariable ( JPDADebuggerImpl debugger, PrimitiveValue value, String declaredType, ObjectVariable array, int index, int maxIndex, String parentID ) { super ( debugger, value, parentID + '.' + index + (value instanceof ObjectReference ? "^" : "") ); this.index = index; this.maxIndexLog = log10(maxIndex); this.declaredType = declaredType; this.parent = array; this.array = (ArrayReference) ((JDIVariable) array).getJDIValue(); }
Local ( JPDADebuggerImpl debugger, PrimitiveValue value, String className, LocalVariable local, CallStackFrameImpl frame ) { super ( debugger, value, getID(local, value) ); this.local = local; if (frame != null) { this.thread = frame.getThread(); this.depth = frame.getFrameDepth(); } this.className = className; }
public FieldVariable ( JPDADebuggerImpl debugger, PrimitiveValue value, // String className, Field field, String parentID, ObjectReference objectReference // instance or null for static fields ) { super ( debugger, value, getID(parentID, field) ); this.field = field; //this.className = className; this.objectReference = objectReference; }
@Override public Mirror visitArrayAccess(ArrayAccessTree arg0, EvaluationContext evaluationContext) { Mirror array = arg0.getExpression().accept(this, evaluationContext); if (array == null) { Assert.error(arg0, "arrayIsNull", arg0.getExpression()); } Mirror index = arg0.getIndex().accept(this, evaluationContext); if (!(array instanceof ArrayReference)) { Assert.error(arg0, "notArrayType", arg0.getExpression()); } if (!(index instanceof PrimitiveValue)) { Assert.error(arg0, "arraySizeBadType", index); } int i = ((PrimitiveValue) index).intValue(); if (i < 0 || i >= ((ArrayReference) array).length()) { Assert.error(arg0, "arrayIndexOutOfBounds", array, i); } evaluationContext.putArrayAccess(arg0, (ArrayReference)array, i); return ((ArrayReference) array).getValue(i); }
/** * Auto-boxes or un-boxes arguments of a method. */ static void autoboxArguments(List<Type> types, List<Value> argVals, ThreadReference evaluationThread, EvaluationContext evaluationContext) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException { if (types.size() != argVals.size()) { return ; } int n = types.size(); for (int i = 0; i < n; i++) { Type t = types.get(i); Value v = argVals.get(i); if (v instanceof ObjectReference && t instanceof PrimitiveType) { argVals.set(i, unbox((ObjectReference) v, (PrimitiveType) t, evaluationThread, evaluationContext)); } if (v instanceof PrimitiveValue && t instanceof ReferenceType) { argVals.set(i, box((PrimitiveValue) v, (ReferenceType) t, evaluationThread, evaluationContext)); } } }
void writeUntaggedValueChecked(Value val) throws InvalidTypeException { byte tag = ValueImpl.typeValueKey(val); if (isObjectTag(tag)) { if (val == null) { writeObjectRef(0); } else { if (!(val instanceof ObjectReference)) { throw new InvalidTypeException(); } writeObjectRef(((ObjectReferenceImpl)val).ref()); } } else { switch (tag) { case JDWP.Tag.BYTE: if(!(val instanceof ByteValue)) throw new InvalidTypeException(); writeByte(((PrimitiveValue)val).byteValue()); break; case JDWP.Tag.CHAR: if(!(val instanceof CharValue)) throw new InvalidTypeException(); writeChar(((PrimitiveValue)val).charValue()); break; case JDWP.Tag.FLOAT: if(!(val instanceof FloatValue)) throw new InvalidTypeException(); writeFloat(((PrimitiveValue)val).floatValue()); break; case JDWP.Tag.DOUBLE: if(!(val instanceof DoubleValue)) throw new InvalidTypeException(); writeDouble(((PrimitiveValue)val).doubleValue()); break; case JDWP.Tag.INT: if(!(val instanceof IntegerValue)) throw new InvalidTypeException(); writeInt(((PrimitiveValue)val).intValue()); break; case JDWP.Tag.LONG: if(!(val instanceof LongValue)) throw new InvalidTypeException(); writeLong(((PrimitiveValue)val).longValue()); break; case JDWP.Tag.SHORT: if(!(val instanceof ShortValue)) throw new InvalidTypeException(); writeShort(((PrimitiveValue)val).shortValue()); break; case JDWP.Tag.BOOLEAN: if(!(val instanceof BooleanValue)) throw new InvalidTypeException(); writeBoolean(((PrimitiveValue)val).booleanValue()); break; } } }
@Override protected Integer getArrayElement(int i) { try { IJavaValue val = exp.getValue().getValue(i); if (field == null) { return ((JDIPrimitiveValue)val).getIntValue(); } else { Value fieldVal = ((JDIObjectValue)val).getUnderlyingObject().getValue(field); return ((PrimitiveValue)fieldVal).intValue(); } } catch (DebugException e) { System.out.println("index: "); e.printStackTrace(); return null; } }
@Override protected Integer getArrayElement(int i) { try { IJavaValue val = exp.getValue().getValue(i); if (field == null) { return ((JDIPrimitiveValue)val).getIntValue(); } else { Value fieldVal = ((JDIObjectValue)val).getUnderlyingObject().getValue(field); return ((PrimitiveValue)fieldVal).intValue(); } } catch (DebugException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
public Data getObj(boolean force,String name,Value value,List<Long> objectProcessed){ Data object = null; if (value instanceof ArrayReference){ object = getArrayFromArrayReference(force,name,(ArrayReference)value,objectProcessed); } else if (value instanceof PrimitiveValue){ object = getPrimitiveObject(name,value); } else if (value instanceof StringReference){ object = getStringFromStringReference(name,(StringReference)value); } else if (value instanceof ObjectReference){ object = getObjectFromObjectReference(force,name,(ObjectReference)value,objectProcessed); } else if (value == null){ object = new NullData(name); } return object; }
private static void setValueToFinalField(ObjectReference obj, String name, ClassType clazz, Value fv, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException, InvalidObjectException { ObjectReference fieldRef = getDeclaredOrInheritedField(clazz, name, vm, thread); if (fieldRef == null) { InvalidObjectException ioex = new InvalidObjectException("No field "+name+" of class "+clazz); throw ioex; } // field.setAccessible(true); ClassType fieldClassType = (ClassType) ValueWrapper.type(fieldRef); com.sun.jdi.Method setAccessibleMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "setAccessible", "(Z)V"); try { ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setAccessibleMethod, Collections.singletonList(vm.mirrorOf(true)), ClassType.INVOKE_SINGLE_THREADED); // field.set(newInstance, fv); com.sun.jdi.Method setMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V"); if (fv instanceof PrimitiveValue) { PrimitiveType pt = (PrimitiveType) ValueWrapper.type(fv); ReferenceType fieldBoxingClass = EvaluatorVisitor.adjustBoxingType(clazz, pt, null); fv = EvaluatorVisitor.box((PrimitiveValue) fv, fieldBoxingClass, thread, null); } List<Value> args = Arrays.asList(new Value[] { obj, fv }); ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setMethod, args, ClassType.INVOKE_SINGLE_THREADED); } catch (InvocationException iex) { throw new InvalidObjectException( "Problem setting value "+fv+" to field "+name+" of class "+clazz+ " : "+iex.exception()); } }
public ArgumentVariable ( JPDADebuggerImpl debugger, PrimitiveValue value, String name, String className ) { super ( debugger, value, name + className ); this.name = name; this.className = className; }
static String getValue (Value v) { if (v == null) { return "null"; } if (v instanceof VoidValue) { return "void"; } if (v instanceof CharValue) { return "\'" + v.toString () + "\'"; } if (v instanceof PrimitiveValue) { return v.toString (); } try { if (v instanceof StringReference) { String str = ShortenedStrings.getStringWithLengthControl((StringReference) v); return "\"" + str + "\""; } if (v instanceof ClassObjectReference) { return "class " + ReferenceTypeWrapper.name(ClassObjectReferenceWrapper.reflectedType((ClassObjectReference) v)); } if (v instanceof ArrayReference) { return "#" + ObjectReferenceWrapper.uniqueID((ArrayReference) v) + "(length=" + ArrayReferenceWrapper.length((ArrayReference) v) + ")"; } return "#" + ObjectReferenceWrapper.uniqueID((ObjectReference) v); } catch (InternalExceptionWrapper iex) { return ""; } catch (ObjectCollectedExceptionWrapper oex) { return ""; } catch (VMDisconnectedExceptionWrapper dex) { return ""; } }
JPDAWatchImpl (JPDADebuggerImpl debugger, Watch watch, PrimitiveValue v) { super ( debugger, v, "" + watch + (v instanceof ObjectReference ? "^" : "") ); this.debugger = debugger; this.watch = watch; }
public JPDAWatchImpl clone() { JPDAWatchImpl clon; if (exceptionDescription == null) { clon = new JPDAWatchImpl(getDebugger(), watch, (PrimitiveValue) getJDIValue()); } else { clon = new JPDAWatchImpl(getDebugger(), watch, new Exception(exceptionDescription)); } return clon; }
public ArrayFieldVariable clone() { ArrayFieldVariable clon = new ArrayFieldVariable( getDebugger(), (PrimitiveValue) getJDIValue(), declaredType, parent, index, 0, getID().substring(0, getID().length() - ('.' + index + (getJDIValue() instanceof ObjectReference ? "^" : "")).length())); clon.maxIndexLog = this.maxIndexLog; return clon; }
public Local clone() { Local clon; clon = new Local(getDebugger(), (PrimitiveValue) getJDIValue(), className, local, null); clon.depth = this.depth; clon.thread = this.thread; return clon; }
public static JPDAWatch createJPDAWatch(JPDADebuggerImpl debugger, Watch watch, Value v) { JPDAWatch jw; if (v instanceof PrimitiveValue) { jw = new JPDAWatchImpl (debugger, watch, (PrimitiveValue) v); } else { // ObjectReference or VoidValue jw = new JPDAObjectWatchImpl (debugger, watch, v); } return jw; }
private String toString(Tree arg0, Mirror v, EvaluationContext evaluationContext) { if (v instanceof PrimitiveValue) { PrimitiveValue pv = (PrimitiveValue) v; PrimitiveType t = (PrimitiveType) pv.type(); if (t instanceof ByteType) { return Byte.toString(pv.byteValue()); } if (t instanceof BooleanType) { return Boolean.toString(pv.booleanValue()); } if (t instanceof CharType) { return Character.toString(pv.charValue()); } if (t instanceof ShortType) { return Short.toString(pv.shortValue()); } if (t instanceof IntegerType) { return Integer.toString(pv.intValue()); } if (t instanceof LongType) { return Long.toString(pv.longValue()); } if (t instanceof FloatType) { return Float.toString(pv.floatValue()); } if (t instanceof DoubleType) { return Double.toString(pv.doubleValue()); } throw new IllegalStateException("Unknown primitive type: "+t); } if (v == null) { return "" + null; } ObjectReference ov = (ObjectReference) v; if (ov instanceof ArrayReference) { return "#" + ov.uniqueID() + " " + ov.type().name() + "(length=" + ((ArrayReference) ov).length() + ")"; } if (ov instanceof StringReference) { return ((StringReference) ov).value(); } // Call toString() method: List<? extends TypeMirror> typeArguments = Collections.emptyList(); Method method; try { method = getConcreteMethod((ReferenceType) ov.type(), "toString", typeArguments); } catch (UnsuitableArgumentsException uaex) { throw new IllegalStateException(uaex); } ((ClassType) ov.type()).methodsByName("toString"); List<Value> argVals = Collections.emptyList(); Value sv = invokeMethod(arg0, method, false, null, ov, argVals, evaluationContext, false); if (sv instanceof StringReference) { return ((StringReference) sv).value(); } else if (sv == null) { return null; } else { return "Result of toString() call on "+ov+" is not a String, but: "+sv; // NOI18N - should not ever happen. } }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedDoubleValue()); }
public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException { final Value value = descriptor.getValue(); LOG.assertTrue(!(value instanceof PrimitiveValue)); String result; final DebugProcess debugProcess = evaluationContext.getDebugProcess(); if (value != null) { try { final ExpressionEvaluator evaluator = myLabelExpression.getEvaluator(debugProcess.getProject()); if(!debugProcess.isAttached()) { throw EvaluateExceptionUtil.PROCESS_EXITED; } EvaluationContext thisEvaluationContext = evaluationContext.createEvaluationContext(value); Value labelValue = evaluator.evaluate(thisEvaluationContext); result = DebuggerUtils.getValueAsString(thisEvaluationContext, labelValue); } catch (final EvaluateException ex) { throw new EvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + ex.getMessage(), ex); } } else { //noinspection HardCodedStringLiteral result = "null"; } return result; }
public static Value create(Object value) { if (value == null) { return new ComplexValueImpl(null); } if (value instanceof Value) { return (Value) value; } if (value instanceof ArrayReference) { ArrayReference array = (ArrayReference) value; List<Value> arrayValues = create(array.getValues()); return new ArrayValueImpl(array.type().name(), array, arrayValues, value); } if (value instanceof ObjectReference) { return new ComplexValueImpl((ObjectReference) value); } if (value instanceof ClassType) { return new TypeValueImpl((ClassType) value); } if (value instanceof PrimitiveValue) { try { java.lang.reflect.Method valueMethod = value.getClass().getMethod("value"); Object result = valueMethod.invoke(value); PrimitiveValueImpl primitiveValue = new PrimitiveValueImpl(result); primitiveValue.setJDIValue((PrimitiveValue) value); return primitiveValue; } catch (Exception e) { return null; } } if (value.getClass().isArray()) { List<Object> values = new ArrayList<>(); int length = Array.getLength(value); for (int i = 0; i< length; i++) { values.add(Array.get(value, i)); } return new ArrayValueImpl(value.getClass().getComponentType().getCanonicalName(), null, create(values), value); } return new PrimitiveValueImpl(value); }
public static F3Value wrap(F3VirtualMachine f3vm, Value value) { if (value == null) { return null; } if (value instanceof PrimitiveValue) { if (value instanceof BooleanValue) { return f3vm.booleanValue((BooleanValue)value); } else if (value instanceof CharValue) { return f3vm.charValue((CharValue)value); } else if (value instanceof ByteValue) { return f3vm.byteValue((ByteValue)value); } else if (value instanceof ShortValue) { return f3vm.shortValue((ShortValue)value); } else if (value instanceof IntegerValue) { return f3vm.integerValue((IntegerValue)value); } else if (value instanceof LongValue) { return f3vm.longValue((LongValue)value); } else if (value instanceof FloatValue) { return f3vm.floatValue((FloatValue)value); } else if (value instanceof DoubleValue) { return f3vm.doubleValue((DoubleValue)value); } else { throw new IllegalArgumentException("illegal primitive value : " + value); } } else if (value instanceof VoidValue) { return f3vm.voidValue(); } else if (value instanceof ObjectReference) { return wrap(f3vm, (ObjectReference)value); } else { throw new IllegalArgumentException("illegal value: " + value); } }
public Object evaluate(EvaluationContextImpl context) throws EvaluateException { Value value = (Value)myOperandEvaluator.evaluate(context); if (value == null) { if (myIsPrimitive) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.cast.null", myCastType)); } return null; } VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy(); if (DebuggerUtilsEx.isInteger(value)) { value = DebuggerUtilsEx.createValue(vm, myCastType, ((PrimitiveValue)value).longValue()); if (value == null) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.cast.numeric", myCastType)); } } else if (DebuggerUtilsEx.isNumeric(value)) { value = DebuggerUtilsEx.createValue(vm, myCastType, ((PrimitiveValue)value).doubleValue()); if (value == null) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.cast.numeric", myCastType)); } } else if (value instanceof BooleanValue) { value = DebuggerUtilsEx.createValue(vm, myCastType, ((BooleanValue)value).booleanValue()); if (value == null) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.cast.boolean", myCastType)); } } else if (value instanceof CharValue) { value = DebuggerUtilsEx.createValue(vm, myCastType, ((CharValue)value).charValue()); if (value == null) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.cast.char", myCastType)); } } return value; }
public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException { final Value value = descriptor.getValue(); LOG.assertTrue(!(value instanceof PrimitiveValue)); String result; final DebugProcess debugProcess = evaluationContext.getDebugProcess(); if (value != null) { try { final ExpressionEvaluator evaluator = myLabelExpression.getEvaluator(debugProcess.getProject()); if(!debugProcess.isAttached()) { throw EvaluateExceptionUtil.PROCESS_EXITED; } EvaluationContext thisEvaluationContext = evaluationContext.createEvaluationContext(value); Value labelValue = evaluator.evaluate(thisEvaluationContext); result = DebuggerUtils.convertToPresentationString(DebuggerUtils.getValueAsString(thisEvaluationContext, labelValue)); } catch (final EvaluateException ex) { throw new EvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + ex.getMessage(), ex); } } else { //noinspection HardCodedStringLiteral result = "null"; } return result; }
@Override public WatchPointValue addValue(Value value, long timestamp, ThreadReference thread, boolean modification) { WatchPointValue wpv = super.addValue(value, timestamp, thread, modification); PrimitiveValue nValue = (PrimitiveValue)value; if (nValue.intValue() < minvalue) { minvalue = nValue.intValue(); minWpValue = wpv; } if (nValue.intValue() > maxValue) { maxValue = nValue.intValue(); maxWpValue = wpv; } return wpv; }
public ArgumentVariable clone() { ArgumentVariable clon; clon = new ArgumentVariable(getDebugger(), (PrimitiveValue) getJDIValue(), name, className); return clon; }
public static Value unbox(ObjectReference val, PrimitiveType type, ThreadReference thread, EvaluationContext context) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException { ReferenceType rt = val.referenceType(); String classType = rt.name(); PrimitiveValue pv; if (classType.equals("java.lang.Boolean")) { pv = invokeUnboxingMethod(val, "booleanValue", thread, context); } else if (classType.equals("java.lang.Byte")) { pv = invokeUnboxingMethod(val, "byteValue", thread, context); } else if (classType.equals("java.lang.Character")) { pv = invokeUnboxingMethod(val, "charValue", thread, context); } else if (classType.equals("java.lang.Short")) { pv = invokeUnboxingMethod(val, "shortValue", thread, context); } else if (classType.equals("java.lang.Integer")) { pv = invokeUnboxingMethod(val, "intValue", thread, context); } else if (classType.equals("java.lang.Long")) { pv = invokeUnboxingMethod(val, "longValue", thread, context); } else if (classType.equals("java.lang.Float")) { pv = invokeUnboxingMethod(val, "floatValue", thread, context); } else if (classType.equals("java.lang.Double")) { pv = invokeUnboxingMethod(val, "doubleValue", thread, context); //throw new RuntimeException("Invalid type while unboxing: " + type.signature()); // never happens } else { return val; } VirtualMachine vm = pv.virtualMachine(); if (type instanceof BooleanType && !(pv instanceof BooleanValue)) { return vm.mirrorOf(pv.booleanValue()); } if (type instanceof ByteType && !(pv instanceof ByteValue)) { return vm.mirrorOf(pv.byteValue()); } if (type instanceof CharType && !(pv instanceof CharValue)) { return vm.mirrorOf(pv.charValue()); } if (type instanceof ShortType && !(pv instanceof ShortValue)) { return vm.mirrorOf(pv.shortValue()); } if (type instanceof IntegerType && !(pv instanceof IntegerValue)) { return vm.mirrorOf(pv.intValue()); } if (type instanceof LongType && !(pv instanceof LongValue)) { return vm.mirrorOf(pv.longValue()); } if (type instanceof FloatType && !(pv instanceof FloatValue)) { return vm.mirrorOf(pv.floatValue()); } if (type instanceof DoubleType && !(pv instanceof DoubleValue)) { return vm.mirrorOf(pv.doubleValue()); } return pv; }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedShortValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedByteValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedFloatValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedLongValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedCharValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedBooleanValue()); }
PrimitiveValue convert(PrimitiveValue value) throws InvalidTypeException { return vm.mirrorOf(((PrimitiveValueImpl)value).checkedIntValue()); }
private static boolean isActiveTooltipApplicable(final Value value) { return value != null && !(value instanceof PrimitiveValue); }
public boolean isPrimitive() { return getValue() instanceof PrimitiveValue; }
private boolean isPrimitive() { return jdiValue instanceof PrimitiveValue; }
@Override public boolean isPrimitive() { return jdiValue instanceof PrimitiveValue; }
public F3PrimitiveValue(F3VirtualMachine f3vm, PrimitiveValue underlying) { super(f3vm, underlying); }