Java 类com.sun.jdi.StringReference 实例源码

项目:incubator-netbeans    文件:JPDAThreadImpl.java   
public Variable getPendingVariable(Object action) {
    Variable var;
    synchronized (pendingActionsLock) {
        var = (action == pendingAction) ? pendingVariable : null;
    }
    if (var == null) {
        StringReference sr = threadReference.virtualMachine().mirrorOf(getPendingString(action));
        var = new AbstractObjectVariable (debugger, sr, null);
    }
    synchronized (pendingActionsLock) {
        if (action == pendingAction) {
            pendingVariable = var;
        }
    }
    return var;
}
项目:incubator-netbeans    文件:InvocationExceptionTranslated.java   
private String getMessageFromField() throws InternalExceptionWrapper,
                                            VMDisconnectedExceptionWrapper,
                                            ObjectCollectedExceptionWrapper,
                                            ClassNotPreparedExceptionWrapper {
    List<ReferenceType> throwableClasses = VirtualMachineWrapper.classesByName(exeption.virtualMachine(), Throwable.class.getName());
    if (throwableClasses.isEmpty()) {
        return null;
    }
    Field detailMessageField = ReferenceTypeWrapper.fieldByName(throwableClasses.get(0), "detailMessage");
    if (detailMessageField != null) {
        Value messageValue = ObjectReferenceWrapper.getValue(exeption, detailMessageField);
        if (messageValue instanceof StringReference) {
            message = StringReferenceWrapper.value((StringReference) messageValue);
            if (invocationMessage != null) {
                return invocationMessage + ": " + message;
            } else {
                return message;
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
private static StringReference createStringMirrorWithDisabledCollection(String s, VirtualMachine vm, EvaluationContext evaluationContext) {
    StringReference sr;
    do {
        try {
            sr = vm.mirrorOf(s);
        } catch (UnsupportedOperationException e) {
            Assert.error(null, "unsupportedStringCreation");
            return null;
        }
        try {
            evaluationContext.disableCollectionOf(sr);
        } catch (ObjectCollectedException oce) {
            sr = null; // Already collected! Create a new value and try again...
        }
    } while (sr == null);
    return sr;
}
项目:incubator-netbeans    文件:EvaluatorTest.java   
@Override
public boolean equals(Object obj) {
    if (!(obj instanceof JDIValue)) return false;
    Value v = ((JDIValue) obj).value;
    if (value == null) return v == null;
    if (value instanceof StringReference) {
        if (!(v instanceof StringReference)) return false;
        return ((StringReference) value).value().equals(((StringReference) v).value());
    }
    if (value instanceof ArrayReference) {
        if (!(v instanceof ArrayReference)) return false;
        ArrayReference a1 = (ArrayReference) value;
        ArrayReference a2 = (ArrayReference) v;
        if (!a1.type().equals(a2.type())) return false;
        if (a1.length() != a2.length()) return false;
        int n = a1.length();
        for (int i = 0; i < n; i++) {
            if (!new JDIValue(a1.getValue(i)).equals(new JDIValue(a2.getValue(i)))) {
                return false;
            }
        }
        return true;
    }
    return value.equals(v);
}
项目:jdk8u-jdk    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:openjdk-jdk10    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:java-debug    文件:StringObjectFormatterTest.java   
@Test
public void testToString() throws Exception {
    Value string = this.getLocalValue("str");
    Map<String, Object> options = formatter.getDefaultOptions();
    options.put(MAX_STRING_LENGTH_OPTION, 4);
    assertEquals("Should be able to format string type.", String.format("\"s...\" (id=%d)",
        ((ObjectReference) string).uniqueID()),
        formatter.toString(string, options));

    options.put(MAX_STRING_LENGTH_OPTION, 5);
    assertEquals("Should be able to format string type.", String.format("\"st...\" (id=%d)",
        ((ObjectReference) string).uniqueID()),
        formatter.toString(string, options));
    assertTrue("Should not trim long string by default",
        formatter.toString(string, new HashMap<>()).contains(((StringReference) string).value()));
}
项目:acdebugger    文件:BreakpointProcessor.java   
private String getBundleLocation(ObjectReference permissions) {
  List<String> walker;
  if (hasBundlePerms(permissions)) {
    walker = BUNDLE_PERM_WALKER;
  } else if (hasBlueprintProtectionDomain(permissions)) {
    walker = BLUEPRINT_PERM_WALKER;
  } else {
    walker = BUNDLE_PROTDOMAIN_WALKER;
  }

  ObjectReference revList = getReference(permissions, walker);
  ArrayReference revArray =
      (ArrayReference) revList.getValue(revList.referenceType().fieldByName("elementData"));
  ObjectReference moduleRev = (ObjectReference) revArray.getValue(0);
  return getValue(
      moduleRev,
      ImmutableList.of("symbolicName"),
      currRef -> ((StringReference) currRef).value());
}
项目:openjdk9    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:jdk8u_jdk    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:lookaside_java-1.8.0-openjdk    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:form-follows-function    文件:F3Wrapper.java   
public static F3ObjectReference wrap(F3VirtualMachine f3vm, ObjectReference ref) {
    if (ref == null) {
        return null;
    } else if (ref instanceof ArrayReference) {
        return f3vm.arrayReference((ArrayReference)ref);
    } else if (ref instanceof StringReference) {
        return f3vm.stringReference((StringReference)ref);
    } else if (ref instanceof ThreadReference) {
        return f3vm.threadReference((ThreadReference)ref);
    } else if (ref instanceof ThreadGroupReference) {
        return f3vm.threadGroupReference((ThreadGroupReference)ref);
    } else if (ref instanceof ClassLoaderReference) {
        return f3vm.classLoaderReference((ClassLoaderReference)ref);
    } else if (ref instanceof ClassObjectReference) {
        return f3vm.classObjectReference((ClassObjectReference)ref);
    } else {
        return f3vm.objectReference(ref);
    }
}
项目:infobip-open-jdk-8    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:jdk8u-dev-jdk    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:OLD-OpenJDK8    文件:GetUninitializedStringValue.java   
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
项目:JavaTracer    文件:ClassUtils.java   
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;
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static void retrieveScreenshots(JPDAThreadImpl t, final ThreadReference tr, VirtualMachine vm, DebuggerEngine engine, JPDADebuggerImpl d, final List<RemoteScreenshot> screenshots) throws RetrievalException {
    try {
        final ClassType windowClass = getClass(vm, tr, "javafx.stage.Window");

        Method getWindows = windowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;");
        Method windowName = windowClass.concreteMethodByName("impl_getMXWindowType", "()Ljava/lang/String;");

        ObjectReference iterator = (ObjectReference)windowClass.invokeMethod(tr, getWindows, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
        ClassType iteratorClass = (ClassType)iterator.referenceType();
        Method hasNext = iteratorClass.concreteMethodByName("hasNext", "()Z");
        Method next = iteratorClass.concreteMethodByName("next", "()Ljava/lang/Object;");

        boolean nextFlag = false;
        do {
            BooleanValue bv = (BooleanValue)iterator.invokeMethod(tr, hasNext, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
            nextFlag = bv.booleanValue();
            if (nextFlag) {
                ObjectReference window = (ObjectReference)iterator.invokeMethod(tr, next, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                StringReference name = (StringReference)window.invokeMethod(tr, windowName, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                SGComponentInfo windowInfo = new SGComponentInfo(t, window);

                screenshots.add(createRemoteFXScreenshot(engine, vm, tr, name.value(), window, windowInfo));
            }
        } while (nextFlag);
    } catch (Exception e) {
        throw new RetrievalException(e.getMessage(), e);
    }
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static ReferenceType getType(VirtualMachine vm, ThreadReference tr, String name) {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName0(vm, name);
    if (!classList.isEmpty()) {
        return classList.iterator().next();
    }
    List<ReferenceType> classClassList = VirtualMachineWrapper.classesByName0(vm, "java.lang.Class"); // NOI18N
    if (classClassList.isEmpty()) {
        throw new IllegalStateException("Cannot load class Class"); // NOI18N
    }

    ClassType cls = (ClassType) classClassList.iterator().next();
    try {
        Method m = ClassTypeWrapper.concreteMethodByName(cls, "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); // NOI18N
        StringReference mirrorOfName = VirtualMachineWrapper.mirrorOf(vm, name);
        ClassTypeWrapper.invokeMethod(cls, tr, m, Collections.singletonList(mirrorOfName), ObjectReference.INVOKE_SINGLE_THREADED);
        List<ReferenceType> classList2 = VirtualMachineWrapper.classesByName0(vm, name);
        if (!classList2.isEmpty()) {
            return classList2.iterator().next();
        }
    } catch (ClassNotLoadedException | ClassNotPreparedExceptionWrapper |
             IncompatibleThreadStateException | InvalidTypeException |
             InvocationException | InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper | UnsupportedOperationExceptionWrapper |
             VMDisconnectedExceptionWrapper ex) {
        logger.log(Level.FINE, "Cannot load class " + name, ex); // NOI18N
    }

    return null;
}
项目:incubator-netbeans    文件:JavaComponentInfo.java   
private void addProperties() {
    addPropertySet(new PropertySet("main", NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropMain"),
                                           NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropMainDescr")) {
        @Override
        public Property<?>[] getProperties() {
            return new Property[] {
                new ReadOnly("name", String.class,
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropName"),
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropNameDescr")) {
                    @Override
                    public Object getValue() throws IllegalAccessException, InvocationTargetException {
                        return JavaComponentInfo.this.getName();
                    }
                },
                new ReadOnly("type", String.class,
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropType"),
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropTypeDescr")) {
                    @Override
                    public Object getValue() throws IllegalAccessException, InvocationTargetException {
                        return JavaComponentInfo.this.getType();
                    }
                },
                new ReadOnly("bounds", String.class,
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropBounds"),
                             NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropBoundsDescr")) {
                    @Override
                    public Object getValue() throws IllegalAccessException, InvocationTargetException {
                        Rectangle r = JavaComponentInfo.this.getWindowBounds();
                        return "[x=" + r.x + ",y=" + r.y + ",width=" + r.width + ",height=" + r.height + "]";
                    }
                },
            };
        }
    });
    final LazyProperties lazyProperties = new LazyProperties();
    addPropertySet(
        new PropertySet("Properties",
                        NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentProps"),
                        NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropsDescr")) {

            @Override
            public Property<?>[] getProperties() {
                //System.err.println("JavaComponentInfo.Properties PropertySet.getProperties()");
                // To fix https://netbeans.org/bugzilla/show_bug.cgi?id=243065
                //        https://netbeans.org/bugzilla/show_bug.cgi?id=241154
                // Do not compute properties above, compute them on demand in a separate thread now.
                // When done, fire Node.PROP_PROPERTY_SETS, null, null.
                Property<?>[] props = lazyProperties.getProperties();
                //System.err.println("\nprops = "+props.length+"\n");
                return props;
            }
        });
    try {
        Method getTextMethod = ClassTypeWrapper.concreteMethodByName(
                (ClassType) ObjectReferenceWrapper.referenceType(component), "getText", "()Ljava/lang/String;");
        //Method getTextMethod = methodsByName.get("getText");    // NOI18N
        if (getTextMethod != null) {
            try {
                Value theText = ObjectReferenceWrapper.invokeMethod(component, getThread().getThreadReference(), getTextMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                if (theText instanceof StringReference) {
                    setComponentText(StringReferenceWrapper.value((StringReference) theText));
                }
            } catch (VMDisconnectedExceptionWrapper vmdex) {
                return;
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    } catch (ClassNotPreparedExceptionWrapper | InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper | VMDisconnectedExceptionWrapper cnpe) {
    }
}
项目:incubator-netbeans    文件:AbstractVariable.java   
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 "";
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
private Value getEnumConstant(Tree arg0, VariableElement ve, EvaluationContext evaluationContext) {
    String constantName = ve.getSimpleName().toString();
    ReferenceType enumType = getClassType(arg0, ve.asType(), evaluationContext);
    Method valueOfMethod = enumType.methodsByName("valueOf").get(0);
    VirtualMachine vm = evaluationContext.getDebugger().getVirtualMachine();
    if (vm == null) {
        return null;
    }
    StringReference constantNameRef = createStringMirrorWithDisabledCollection(constantName, vm, evaluationContext);
    Value enumValue = invokeMethod(arg0, valueOfMethod, true, (ClassType) enumType, null,
                 Collections.singletonList((Value) constantNameRef), evaluationContext, false);
    return enumValue;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
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.
    }
}
项目:incubator-netbeans    文件:MethodInvocationTest.java   
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 ("org.netbeans.api.debugger.jpda.testapps.MirrorValuesApp");

        support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit

        JPDADebugger debugger = support.getDebugger();

        List<JPDAClassType> systemClasses = debugger.getClassesByName("java.lang.System");
        assertEquals(systemClasses.size(), 1);
        JPDAClassType systemClass = systemClasses.get(0);
        Properties properties = System.getProperties();
        Variable propertiesVar = systemClass.invokeMethod("getProperties", "()Ljava/util/Properties;", new Variable[]{});
        Value pv = ((JDIVariable) propertiesVar).getJDIValue();
        assertTrue("Properties "+pv, (pv instanceof ObjectReference) &&
                                     Properties.class.getName().equals(((ClassType) pv.type()).name()));
        String userHomeProperty = properties.getProperty("user.home");
        Variable propVar = ((ObjectVariable) propertiesVar).invokeMethod("getProperty",
                "(Ljava/lang/String;)Ljava/lang/String;",
                new Variable[] { debugger.createMirrorVar("user.home") });
        Value p = ((JDIVariable) propVar).getJDIValue();
        assertTrue(p instanceof StringReference);
        assertEquals(userHomeProperty, ((StringReference) p).value());
    } finally {
        support.doFinish ();
    }
}
项目:incubator-netbeans    文件:MirrorValuesTest.java   
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 ();
    }
}
项目:openjdk-jdk10    文件:StringReferenceImpl.java   
public String value() {
    if (value == null) {
        // Does not need synchronization, since worst-case
        // static info is fetched twice
        try {
            value = JDWP.StringReference.Value.
                process(vm, this).stringValue;
        } catch (JDWPException exc) {
            throw exc.toJDIException();
        }
    }
    return value;
}
项目:openjdk-jdk10    文件:VirtualMachineImpl.java   
public StringReference mirrorOf(String value) {
    validateVM();
    try {
        return JDWP.VirtualMachine.CreateString.
            process(vm, value).stringObject;
    } catch (JDWPException exc) {
        throw exc.toJDIException();
    }
}
项目:java-debug    文件:StringObjectFormatter.java   
@Override
public String toString(Object value, Map<String, Object> options) {
    int maxLength = getMaxStringLength(options);
    return String.format("\"%s\" %s",
            maxLength > 0 ? StringUtils.abbreviate(((StringReference) value).value(), maxLength) : ((StringReference) value).value(),
            getIdPostfix((ObjectReference) value, options));
}
项目:form-follows-function    文件:F3SequenceReference.java   
private Types typesFromTypeInfo(ObjectReference typeInfo) {
    Field typeField = typeInfo.referenceType().fieldByName("type");
    ObjectReference typeValue = (ObjectReference) typeInfo.getValue(typeField);
    Field nameField = typeValue.referenceType().fieldByName("name");
    String typeName = ((StringReference)typeValue.getValue(nameField)).value();
    return Types.valueOf(typeName);
}
项目:form-follows-function    文件:VSGC4440Test.java   
@Test
public void testStringSequencesSet() {
    compile("VSGC4440Test.f3");

    stop("in VSGC4440Test.func");
    f3run();
    resumeToBreakpoint();
    F3SequenceReference seq = (F3SequenceReference) evaluate("VSGC4440Test.seq");
    // used to get NPE from this setValue call.
    seq.setValue(0, vm().mirrorOf("sun"));
    Assert.assertEquals(((StringReference)seq.getValue(0)).value(), "sun");
}
项目:gravel    文件:VMTargetRemoteTest.java   
@Test
    public void testDNU() throws Throwable {
        ObjectReference promise = remote.evaluateForked("3 fromage");
        ThreadReference thread = ((ThreadReference) remote.invokeMethod(
                promise, "thread"));
        remote.invokeMethod(thread, "start");
        ObjectReference state = (ObjectReference) remote.invokeMethod(thread, "getState");
        StringReference str = (StringReference) remote.invokeMethod(state, "toString");
        System.out.println(str.value());

        printStack(thread);
//      assertFalse(thread.isSuspended());
        printThreadState();
        System.out.println("VMTargetStarter.sleep(1000)");
        VMTargetStarter.sleep(1000);
        printStack(thread);
        printThreadState();

        boolean isFinished = ((BooleanValue) remote.invokeMethod(promise,
                "isFinished")).booleanValue();

        assertFalse(isFinished);
        printThreadState();

        printStack(thread);
        assertTrue(thread.isAtBreakpoint());
    }
项目:codehint    文件:SideEffectHandler.java   
@Override
public boolean handleEvent(Event event, JDIDebugTarget target, boolean suspendVote, EventSet eventSet) {
    try {
        //System.out.println("Reflection: " + event);
        ThreadReference thread = ((LocatableEvent)event).thread();
        StackFrame stack = thread.frame(0);
        ObjectReference fieldValue = stack.thisObject();
        ReferenceType fieldType = fieldValue.referenceType();
        //String className = ((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).invokeMethod(thread, event.virtualMachine().classesByName("java.lang.Class").get(0).methodsByName("getName").get(0), new ArrayList<Value>(0), 0).toString();  // Calling methods in the child JVM seems to crash here.
        //String className = ((StringReference)((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).getValue(event.virtualMachine().classesByName("java.lang.Class").get(0).fieldByName("name"))).value();  // This works in JDK 7 but breaks in JDK 8 (because getting fields no longer calls SecurityManager.checkMemberAccess).
        String className = ((ClassObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).reflectedType().name();
        String fieldName = ((StringReference)fieldValue.getValue(fieldType.fieldByName("name"))).value();
        Field field = event.virtualMachine().classesByName(className).get(0).fieldByName(fieldName);
        List<Value> argValues = stack.getArgumentValues();
        ObjectReference obj = (ObjectReference)argValues.get(0);
        if (!field.isStatic() && obj == null)
            return true;  // The execution will crash.
        Value oldValue = field.isStatic() ? field.declaringType().getValue(field) : obj.getValue(field);
        if (argValues.size() == 2) {  // We're setting the value of a field.
            Value newValue = argValues.get(1);
            if (newValue instanceof ObjectReference && EclipseUtils.isPrimitive(field.signature()))  // Unbox primitive values.
                newValue = ((ObjectReference)newValue).getValue(((ReferenceType)newValue.type()).fieldByName("value"));
            recordEffect(FieldLVal.makeFieldLVal(obj, field), oldValue, newValue);
        } else if (oldValue instanceof ArrayReference)  // We're reading the value of an array.
            backupArray(FieldLVal.makeFieldLVal(obj, field), oldValue);
    } catch (IncompatibleThreadStateException e) {
        throw new RuntimeException(e);
    }
    return true;
}
项目:incubator-netbeans    文件:ShortenedStrings.java   
private static void register(String shortedString, StringReference sr, int length, ArrayReference chars) {
    StringInfo si = new StringInfo(sr, shortedString.length() - 3, length, chars);
    synchronized (infoStrings) {
        infoStrings.put(shortedString, si);
    }
}
项目:incubator-netbeans    文件:ShortenedStrings.java   
private StringInfo(StringReference sr, int shortLength, int length, ArrayReference chars) {
    this.sr = sr;
    this.shortLength = shortLength;
    this.length = length;
    this.chars = chars;
}
项目:incubator-netbeans    文件:InvocationExceptionTranslated.java   
@Override
public synchronized String getMessage() {
    if (message == null) {
        try {
            Method getMessageMethod = ClassTypeWrapper.concreteMethodByName((ClassType) ValueWrapper.type(exeption),
                        "getMessage", "()Ljava/lang/String;");  // NOI18N
            if (getMessageMethod == null) {
                if (invocationMessage != null) {
                    message = "";
                } else {
                    message = "Unknown exception message";
                }
            } else {
                try {
                    StringReference sr = (StringReference) debugger.invokeMethod (
                            preferredThread,
                            exeption,
                            getMessageMethod,
                            new Value [0],
                            this
                        );
                    message = sr != null ? StringReferenceWrapper.value(sr) : ""; // NOI18N
                } catch (InvalidExpressionException ex) {
                    if (ex.getTargetException() == this) {
                        String msg = getMessageFromField();
                        if (msg == null) {
                            if (invocationMessage != null) {
                                message = "";
                            } else {
                                message = "Unknown exception message";
                            }
                        }
                    } else {
                        return ex.getMessage();
                    }
                } catch (VMMismatchException vmMismatchEx) {
                    VirtualMachine ptvm = ((preferredThread != null) ? preferredThread.getThreadReference().virtualMachine() : null);
                    VirtualMachine ctvm = null;
                    JPDAThread currentThread = debugger.getCurrentThread();
                    if (currentThread != null) {
                        ctvm = ((JPDAThreadImpl) currentThread).getThreadReference().virtualMachine();
                    }
                    throw Exceptions.attachMessage(vmMismatchEx, "DBG VM = "+printVM(debugger.getVirtualMachine())+
                                                               ", preferredThread VM = "+printVM(ptvm)+
                                                               ", currentThread VM = "+printVM(ctvm)+
                                                               ", exeption VM = "+printVM(exeption.virtualMachine()));
                }
            }
        } catch (InternalExceptionWrapper iex) {
            return iex.getMessage();
        } catch (VMDisconnectedExceptionWrapper vdex) {
            return vdex.getMessage();
        } catch (ObjectCollectedExceptionWrapper ocex) {
            Exceptions.printStackTrace(ocex);
            return ocex.getMessage();
        } catch (ClassNotPreparedExceptionWrapper cnpex) {
            return cnpex.getMessage();
        }
    }
    if (invocationMessage != null) {
        return invocationMessage + ": " + message;
    } else {
        return message;
    }
}
项目:incubator-netbeans    文件:InvocationExceptionTranslated.java   
@Override
public String getLocalizedMessage() {
    if (localizedMessage == null) {
        try {
            Method getMessageMethod = ClassTypeWrapper.concreteMethodByName((ClassType) ValueWrapper.type(exeption),
                        "getLocalizedMessage", "()Ljava/lang/String;");  // NOI18N
            if (getMessageMethod == null) {
                if (invocationMessage != null) {
                    localizedMessage = "";
                } else {
                    localizedMessage = "Unknown exception message";
                }
            } else {
                try {
                    StringReference sr = (StringReference) debugger.invokeMethod (
                            preferredThread,
                            exeption,
                            getMessageMethod,
                            new Value [0],
                            this
                        );
                    localizedMessage = sr == null ? "" : StringReferenceWrapper.value(sr); // NOI18N
                } catch (InvalidExpressionException ex) {
                    if (ex.getTargetException() == this) {
                        String msg = getMessageFromField();
                        if (msg == null) {
                            if (invocationMessage != null) {
                                localizedMessage = "";
                            } else {
                                localizedMessage = "Unknown exception message";
                            }
                        }
                    } else {
                        return ex.getLocalizedMessage();
                    }
                } catch (AssertionError ae) {
                    Exceptions.printStackTrace(new IllegalStateException("Do preload the exception content", createdAt));
                    throw ae;
                }
            }
        } catch (InternalExceptionWrapper iex) {
            return iex.getMessage();
        } catch (VMDisconnectedExceptionWrapper vdex) {
            return vdex.getMessage();
        } catch (ObjectCollectedExceptionWrapper ocex) {
            Exceptions.printStackTrace(ocex);
            return ocex.getMessage();
        } catch (ClassNotPreparedExceptionWrapper cnpex) {
            return cnpex.getMessage();
        }
    }
    if (invocationMessage != null) {
        return invocationMessage + ": " + localizedMessage;
    } else {
        return localizedMessage;
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public Mirror visitLiteral(LiteralTree arg0, EvaluationContext evaluationContext) {
    VirtualMachine vm = evaluationContext.getDebugger().getVirtualMachine();
    if (vm == null) {
        return null;
    }
    Object value = arg0.getValue();
    if (value instanceof Boolean) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Byte) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Character) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Double) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Float) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Integer) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Long) {
        return mirrorOf(vm, value);
    }
    if (value instanceof Short) {
        return mirrorOf(vm, value);
    }
    if (value instanceof String) {
        StringReference str = createStringMirrorWithDisabledCollection((String) value, vm, evaluationContext);
        VMCache cache = evaluationContext.getVMCache();
        ClassType strClass = (ClassType) cache.getClass(String.class.getName());
        if (strClass == null) {
            return str;
        }
        try {
            List<Value> args = Collections.emptyList();
            return invokeMethod(arg0, strClass.methodsByName("intern").get(0),
                                false, strClass, str, args, evaluationContext, false);
        } catch (Exception ex) {
            return str;
        }
    }
    if (value == null) {
        return null;
    }
    throw new UnsupportedOperationException("Unsupported value: "+value);
}
项目:intellij-ce-playground    文件:StringReferenceProxy.java   
public StringReferenceProxy(VirtualMachineProxyImpl virtualMachineProxy, StringReference objectReference) {
  super(virtualMachineProxy, objectReference);
}
项目:intellij-ce-playground    文件:StringReferenceProxy.java   
public StringReference getStringReference() {
  return (StringReference)getObjectReference();
}
项目:jBPMNSuite    文件:ProcessInstanceViewerAction.java   
String getStringReference(ObjectReference or, String field) {
    return ((StringReference) or.getValue(or.referenceType().fieldByName(field))).value();
}
项目:form-follows-function    文件:F3StringReference.java   
public F3StringReference(F3VirtualMachine f3vm, StringReference underlying) {
    super(f3vm, underlying);
}