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; } } }
@Test public void testEvaluate() throws Throwable { ObjectReference promise = remote.evaluateForked("3+4"); ThreadReference thread = ((ThreadReference) remote.invokeMethod( promise, "thread")); Value result1 = remote.invokeMethod(promise, "result"); Value ex = remote.invokeMethod(promise, "throwable"); printThreadState(); VMTargetStarter.sleep(100); printThreadState(); boolean isFinished = ((BooleanValue) remote.invokeMethod(promise, "isFinished")).booleanValue(); assertTrue(isFinished); ObjectReference result = (ObjectReference) remote.invokeMethod(promise, "result"); IntegerValue intValue = (IntegerValue) remote.invokeMethod(result, "intValue"); assertEquals(7, intValue.intValue()); }
private Data getPrimitiveObject(String name, Value value) { Data object = null; if (value instanceof BooleanValue) object = new SimpleData(name,((BooleanValue) value).booleanValue()); else if (value instanceof ByteValue) object = new SimpleData(name,((ByteValue) value).byteValue()); else if (value instanceof CharValue) object = new SimpleData(name,((CharValue) value).charValue()); else if (value instanceof DoubleValue) object = new SimpleData(name,((DoubleValue) value).doubleValue()); else if (value instanceof FloatValue) object = new SimpleData(name,((FloatValue) value).floatValue()); else if (value instanceof IntegerValue) object = new SimpleData(name,((IntegerValue) value).intValue()); else if (value instanceof LongValue) object = new SimpleData(name,((LongValue) value).longValue()); else if (value instanceof ShortValue) object = new SimpleData(name,((ShortValue)value).shortValue()); return object; }
private void ungrabWindowFX(ClassType WindowClass, ObjectReference w, ThreadReference tr) throws Exception { // javafx.stage.Window w // w.focusGrabCounter // while (focusGrabCounter-- > 0) { // w.impl_getPeer().ungrabFocus(); OR: w.impl_peer.ungrabFocus(); // } Field focusGrabCounterField = WindowClass.fieldByName("focusGrabCounter"); if (focusGrabCounterField == null) { logger.info("Unable to release FX X grab, no focusGrabCounter field in "+w); return ; } Value focusGrabCounterValue = w.getValue(focusGrabCounterField); if (!(focusGrabCounterValue instanceof IntegerValue)) { logger.info("Unable to release FX X grab, focusGrabCounter does not have an integer value in "+w); return ; } int focusGrabCounter = ((IntegerValue) focusGrabCounterValue).intValue(); if (logger.isLoggable(Level.FINE)) { logger.fine("Focus grab counter of "+w+" is: "+focusGrabCounter); } while (focusGrabCounter-- > 0) { //Method impl_getPeerMethod = WindowClass.concreteMethodByName("impl_getPeer", ""); Field impl_peerField = WindowClass.fieldByName("impl_peer"); if (impl_peerField == null) { logger.info("Unable to release FX X grab, no impl_peer field in "+w); return ; } ObjectReference impl_peer = (ObjectReference) w.getValue(impl_peerField); if (impl_peer == null) { continue; } InterfaceType TKStageClass = (InterfaceType) w.virtualMachine().classesByName("com.sun.javafx.tk.TKStage").get(0); Method ungrabFocusMethod = TKStageClass.methodsByName("ungrabFocus", "()V").get(0); impl_peer.invokeMethod(tr, ungrabFocusMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (logger.isLoggable(Level.FINE)) { logger.fine("FX Window "+w+" was successfully ungrabbed."); } } }
public void testTargetMirrors() throws Exception { try { Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src") + "org/netbeans/api/debugger/jpda/testapps/MirrorValuesApp.java"); LineBreakpoint lb = bp.getLineBreakpoints().get(0); dm.addBreakpoint (lb); support = JPDASupport.attach (CLASS_NAME); support.waitState (JPDADebugger.STATE_STOPPED); // breakpoint hit JPDADebugger debugger = support.getDebugger(); Variable mirrorVar = debugger.createMirrorVar("Test"); Value v = ((JDIVariable) mirrorVar).getJDIValue(); assertTrue("Value "+v+" should be a String", v instanceof StringReference); assertEquals("Test", ((StringReference) v).value()); Point p = new Point(-1, 1); mirrorVar = debugger.createMirrorVar(p); Object mp = mirrorVar.createMirrorObject(); assertTrue("Correct point was created: "+mp, p.equals(mp)); mirrorVar = debugger.createMirrorVar(1); v = ((JDIVariable) mirrorVar).getJDIValue(); assertTrue("Value "+v+" should be an Integer object.", (v.type() instanceof ClassType) && Integer.class.getName().equals(((ClassType) v.type()).name())); mirrorVar = debugger.createMirrorVar(1, true); v = ((JDIVariable) mirrorVar).getJDIValue(); assertTrue("Value "+v+" should be an int.", v instanceof IntegerValue); assertEquals(((IntegerValue) v).value(), 1); } finally { support.doFinish (); } }
public boolean equals(Object obj) { if ((obj != null) && (obj instanceof IntegerValue)) { return (value == ((IntegerValue)obj).value()) && super.equals(obj); } else { return false; } }
private void extractFilePermActions(ObjectReference permission, StringBuilder sb) { IntegerValue value = (IntegerValue) permission.getValue(permission.referenceType().fieldByName("mask")); Integer mask = value.value(); try { Method meth = FilePermission.class.getDeclaredMethod("getActions", int.class); meth.setAccessible(true); String actions = (String) meth.invoke(null, mask); sb.append(actions); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { sb.append("FILEPERMS ACTIONS UNKNOWN"); } }
@Override public void action() { // TODO: see if it is possible to cache this evaluation // if (myIsEvaluated) return; DebugProcess debugProcess = myEvaluationContext.getDebugProcess(); if (!(debugProcess instanceof DebugProcessImpl)) { return; } final DebuggerContextImpl debuggerContext = ((DebugProcessImpl)debugProcess).getDebuggerContext(); PsiAnnotation annotation = ApplicationManager.getApplication().runReadAction(new Computable<PsiAnnotation>() { @Override public PsiAnnotation compute() { PsiElement context = PositionUtil.getContextElement(debuggerContext); if (context == null) { return null; } if (myDescriptor instanceof LocalVariableDescriptor) { return AndroidResolveHelper.getAnnotationForLocal(context, myDescriptor.getName()); } else if (myDescriptor instanceof FieldDescriptor) { String className = ((FieldDescriptor)myDescriptor).getField().declaringType().name(); return AndroidResolveHelper.getAnnotationForField(context, className, myDescriptor.getName()); } else { return null; } } }); if (annotation != null) { ResourceIdResolver resolver = ServiceManager.getService(myEvaluationContext.getProject(), ResourceIdResolver.class); DynamicResourceIdResolver resolver1 = new DynamicResourceIdResolver(myEvaluationContext, resolver); myResult = AnnotationsRenderer.render(resolver1, annotation, ((IntegerValue)myValue).value()); } evaluationResult(""); }
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); } }
/** * Replace a sequence element with another value. * * Object values must be assignment compatible with the element type. * (This implies that the component type must be loaded through the * declaring class's class loader). Primitive values must be * assignment compatible with the component type. * * @param value the new value * @param index the index of the component to set. If this is beyond the * end of the sequence, the new value is appended to the sequence. * * @throws InvalidTypeException if the type of <CODE><I>value</I></CODE> * is not compatible with the declared type of sequence elements. * @throws ClassNotLoadedException if the sequence element type * has not yet been loaded through the appropriate class loader. * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link com.sun.jdi.VirtualMachine#canBeModified()}. * @return a new sequence with the specified element replaced/added. */ public F3SequenceReference setValue(int index, Value value) { Types type = getElementType(); switch (type) { case INT: return setIntValue(index, (IntegerValue)value); case FLOAT: return setFloatValue(index, (FloatValue)value); case OBJECT: return setObjectValue(index, (ObjectReference)value); case DOUBLE: return setDoubleValue(index, (DoubleValue)value); case BOOLEAN: return setBooleanValue(index, (BooleanValue)value); case LONG: return setLongValue(index, (LongValue)value); case SHORT: return setShortValue(index, (ShortValue)value); case BYTE: return setByteValue(index, (ByteValue)value); case CHAR: return setCharValue(index, (CharValue)value); case OTHER: return setObjectValue(index, (ObjectReference)value); default: throw new IllegalArgumentException("Invalid sequence element type"); } }
private int getFlagMask(String maskName) { int flagMask = 0; // we only work with underlying JDI objects here List<ReferenceType> rtx = this.underlying().classesByName("org.f3.runtime.F3Object"); if (rtx.size() != 1) { System.out.println("Can't find the ReferenceType for org.f3.runtime.F3Object"); return 0; } ReferenceType f3ObjectRefType = rtx.get(0); Field fieldx = f3ObjectRefType.fieldByName(maskName); Value flagValue = f3ObjectRefType.getValue(fieldx); return ((IntegerValue)flagValue).value(); }
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; }
@Override public int compareTo(IntegerValue o) { return value - ((IntegerValue)o).value(); }
public int compareTo(IntegerValue obj) { int other = obj.value(); return (value()<other ? -1 : (value()==other ? 0 : 1)); }
public IntegerValue mirrorOf(int value) { validateVM(); return new IntegerValueImpl(this,value); }
@Override public int compareTo(IntegerValue o) { return value() - o.value(); }
public F3IntegerValue(F3VirtualMachine f3vm, IntegerValue underlying) { super(f3vm, underlying); }
public int compareTo(IntegerValue o) { return underlying().compareTo((IntegerValue)F3Wrapper.unwrap(o)); }
@Override protected IntegerValue underlying() { return (IntegerValue) super.underlying(); }
private IntegerValue getValueAsInt(int index) { Method getAsIntMethod = virtualMachine().f3SequenceType().getAsIntMethod(); return (IntegerValue) getElement(getAsIntMethod, index); }
private F3SequenceReference setIntValue(int index, IntegerValue value) { Method setIntElementMethod = virtualMachine().f3SequencesType().setIntElementMethod(); return setElement(setIntElementMethod, index, value); }
protected F3IntegerValue integerValue(IntegerValue value) { return new F3IntegerValue(this, value); }
protected void runTests() throws Exception { startToMain(); // break into function printSeq(arg: Integer[]) BreakpointEvent bpe = resumeTo(targetClassName, "printSeq", "(Lorg/f3/runtime/sequence/Sequence;)V"); mainThread = bpe.thread(); // get the top frame StackFrame frame = mainThread.frame(0); // get first argument which is Integer[] Value value = frame.getArgumentValues().get(0); Assert.assertEquals(true, value instanceof F3SequenceReference); F3SequenceReference seq = (F3SequenceReference) value; Assert.assertEquals(2, seq.size()); Assert.assertEquals(2, seq.length()); Assert.assertEquals(F3SequenceReference.Types.INT, seq.getElementType()); Value zerothElementAsVal = seq.getValue(0); Assert.assertEquals(true, zerothElementAsVal instanceof IntegerValue); Assert.assertEquals(1729, ((IntegerValue)zerothElementAsVal).intValue()); Value firstElementAsVal = seq.getValue(1); Assert.assertEquals(true, firstElementAsVal instanceof IntegerValue); Assert.assertEquals(9999, ((IntegerValue)firstElementAsVal).intValue()); // sequence element set seq.setValue(0, vm().mirrorOf(1111)); seq.setValue(1, vm().mirrorOf(2222)); Assert.assertEquals(1111, ((IntegerValue)seq.getValue(0)).intValue()); Assert.assertEquals(2222, ((IntegerValue)seq.getValue(1)).intValue()); // sequence setValues List<Value> newValues = new ArrayList<Value>(2); newValues.add(vm().mirrorOf(1234)); newValues.add(vm().mirrorOf(5678)); seq.setValues(newValues); Assert.assertEquals(1234, ((IntegerValue)seq.getValue(0)).intValue()); Assert.assertEquals(5678, ((IntegerValue)seq.getValue(1)).intValue()); // sequence getValues List<Value> values = seq.getValues(0, 2); Assert.assertEquals(1234, ((IntegerValue)values.get(0)).intValue()); Assert.assertEquals(5678, ((IntegerValue)values.get(1)).intValue()); /* * resume until end */ listenUntilVMDisconnect(); }
public int add(int x, int y) throws Throwable { Value resultMirror = invokeMethod("add", vm.mirrorOf(x), vm.mirrorOf(y)); return ((IntegerValue) resultMirror).intValue(); }
@Test public void testValueOf() throws Exception { Value i = this.getLocalValue("i"); Map<String, Object> options = formatter.getDefaultOptions(); Value newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options); assertNotNull("NumericFormatter should be able to create integer by string.", newValue); assertTrue("Should create an integer value.", newValue instanceof IntegerValue); assertEquals("Should create an integer with right value.", "111", newValue.toString()); options.put(NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options); assertNotNull("NumericFormatter should be able to create integer by string.", newValue); assertTrue("Should create an integer value.", newValue instanceof IntegerValue); assertEquals("Should create an integer with right value.", "111", newValue.toString()); options.put(NUMERIC_FORMAT_OPTION, NumericFormatEnum.OCT); newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options); assertNotNull("NumericFormatter should be able to create integer by string.", newValue); assertTrue("Should create an integer value.", newValue instanceof IntegerValue); assertEquals("Should create an integer with right value.", "111", newValue.toString()); newValue = formatter.valueOf("-12121212", i.type(), options); assertNotNull("NumericFormatter should be able to create integer by string.", newValue); assertTrue("Should create an integer value.", newValue instanceof IntegerValue); assertEquals("Should create an integer with right value.", "-12121212", newValue.toString()); newValue = formatter.valueOf("0", i.type(), options); assertNotNull("NumericFormatter should be able to create integer by string.", newValue); assertTrue("Should create an integer value.", newValue instanceof IntegerValue); assertEquals("Should create an integer with right value.", "0", newValue.toString()); VirtualMachine vm = getVM(); newValue = formatter.valueOf("0", vm.mirrorOf(10.0f).type(), options); assertNotNull("NumericFormatter should be able to create float by string.", newValue); assertTrue("Should create an float value.", newValue instanceof FloatValue); assertEquals("Should create an float with right value.", "0.0", newValue.toString()); newValue = formatter.valueOf("10.0", vm.mirrorOf(10.0).type(), options); assertNotNull("NumericFormatter should be able to create double by string.", newValue); assertTrue("Should create an double value.", newValue instanceof DoubleValue); assertEquals("Should create an double with right value.", "10.0", newValue.toString()); newValue = formatter.valueOf("10", vm.mirrorOf((short)10).type(), options); assertNotNull("NumericFormatter should be able to create short by string.", newValue); assertTrue("Should create an short value.", newValue instanceof ShortValue); assertEquals("Should create an short with right value.", "10", newValue.toString()); newValue = formatter.valueOf("10", vm.mirrorOf(10L).type(), options); assertNotNull("NumericFormatter should be able to create long by string.", newValue); assertTrue("Should create an long value.", newValue instanceof LongValue); assertEquals("Should create an long with right value.", "10", newValue.toString()); newValue = formatter.valueOf("10", vm.mirrorOf((byte) 10).type(), options); assertNotNull("NumericFormatter should be able to create byte by string.", newValue); assertTrue("Should create an byte value.", newValue instanceof ByteValue); assertEquals("Should create an byte with right value.", "10", newValue.toString()); }
/** * Draws the axis of the view and displays the minimum and maximum values on * each axis * * @param g * - the graphics context * @param to * - the index of the last drawn point */ private void drawAxis(GC g, int to) { String strMaxX; String strMinX; if (properties.scaleByTime) { strMaxX = "" + getMaxTimeStamp(); strMinX = "" + getMinTimeStamp(); } else { strMaxX = "" + getValuesCount(); strMinX = "" + 1; } Rectangle lineArea = new Rectangle(properties.border, properties.border, view.getSize().x - properties.border * 2, view.getSize().y - properties.border * 2); String strMaxY = "" + ((IntegerValue) getHistory().getMaxValue().getValue()) .value(); String strMinY = "" + ((IntegerValue) getHistory().getMinValue().getValue()) .value(); g.setForeground(new Color(view.getDisplay(), new RGB(0, 0, 0))); g.setLineStyle(SWT.LINE_SOLID); g.setLineWidth(1); g.drawLine(lineArea.x, lineArea.y, lineArea.x, lineArea.y + lineArea.height); g.drawLine(lineArea.x, lineArea.y + lineArea.height, lineArea.x + lineArea.width, lineArea.y + lineArea.height); g.drawString( strMaxY, lineArea.x - g.stringExtent(strMaxY).x - g.stringExtent(strMaxY).y / 2, lineArea.y - g.stringExtent(strMaxY).y / 2); g.drawString( strMinY, lineArea.x - g.stringExtent(strMinY).x - g.stringExtent(strMinY).y / 2, lineArea.y + lineArea.height - g.stringExtent(strMinY).y / 2); g.drawString(strMinX, lineArea.x - g.stringExtent(strMinX).x / 2, lineArea.y + lineArea.height + g.stringExtent(strMinX).y / 2); g.drawString(strMaxX, getItemX(this.getValuesCount() - 1) - g.stringExtent(strMaxX).x / 2, lineArea.y + lineArea.height + g.stringExtent(strMaxX).y / 2); }