Java Code Examples for com.sun.jdi.ObjectReference#referenceType()

The following examples show how to use com.sun.jdi.ObjectReference#referenceType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataBreakpointInfoRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
    DataBreakpointInfoArguments dataBpArgs = (DataBreakpointInfoArguments) arguments;
    if (dataBpArgs.variablesReference > 0) {
        Object container = context.getRecyclableIdPool().getObjectById(dataBpArgs.variablesReference);
        if (container instanceof VariableProxy) {
            if (!(((VariableProxy) container).getProxiedVariable() instanceof StackFrameReference)) {
                ObjectReference containerObj = (ObjectReference) ((VariableProxy) container).getProxiedVariable();
                ReferenceType type = containerObj.referenceType();
                Field field = type.fieldByName(dataBpArgs.name);
                if (field != null) {
                    String fullyQualifiedName = type.name();
                    String dataId = String.format("%s#%s", fullyQualifiedName, dataBpArgs.name);
                    String description = String.format("%s.%s : %s", getSimpleName(fullyQualifiedName), dataBpArgs.name, getSimpleName(field.typeName()));
                    response.body = new DataBreakpointInfoResponseBody(dataId, description,
                        DataBreakpointAccessType.values(), true);
                }
            }
        }
    }
    return CompletableFuture.completedFuture(response);
}
 
Example 2
Source File: VariableDetailUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean containsToStringMethod(ObjectReference obj) {
    ReferenceType refType = obj.referenceType();
    if (refType instanceof ClassType) {
        Method m = ((ClassType) refType).concreteMethodByName(TO_STRING_METHOD, TO_STRING_METHOD_SIGNATURE);
        if (m != null) {
            if (!Objects.equals("Ljava/lang/Object;", m.declaringType().signature())) {
                return true;
            }
        }

        for (InterfaceType iface : ((ClassType) refType).allInterfaces()) {
            List<Method> matches = iface.methodsByName(TO_STRING_METHOD, TO_STRING_METHOD_SIGNATURE);
            for (Method ifaceMethod : matches) {
                if (!ifaceMethod.isAbstract()) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 3
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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.emptyList(), 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.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
            nextFlag = bv.booleanValue();
            if (nextFlag) {
                ObjectReference window = (ObjectReference)iterator.invokeMethod(tr, next, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                StringReference name = (StringReference)window.invokeMethod(tr, windowName, Collections.emptyList(), 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);
    }
}
 
Example 4
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Rectangle convertBounds(ObjectReference bounds) {
    ClassType boundsClass = (ClassType)bounds.referenceType();
    Field minX = boundsClass.fieldByName("minX");
    Field minY = boundsClass.fieldByName("minY");
    Field width = boundsClass.fieldByName("width");
    Field height = boundsClass.fieldByName("height");

    return new Rectangle(((DoubleValue)bounds.getValue(minX)).intValue(), 
       ((DoubleValue)bounds.getValue(minY)).intValue(), 
       ((DoubleValue)bounds.getValue(width)).intValue(), 
       ((DoubleValue)bounds.getValue(height)).intValue()
    );
}
 
Example 5
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void pauseMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    final ClassType audioClipClass = getClass(vm, tr, "com.sun.media.jfxmedia.AudioClip");
    final ClassType mediaManagerClass = getClass(vm, tr, "com.sun.media.jfxmedia.MediaManager");
    final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer");
    final ClassType playerStateEnum = getClass(vm, tr, "com.sun.media.jfxmedia.events.PlayerStateEvent$PlayerState");
    
    if (audioClipClass != null) {
        Method stopAllClips = audioClipClass.concreteMethodByName("stopAllClips", "()V");
        audioClipClass.invokeMethod(tr, stopAllClips, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
    }
    
    if (mediaManagerClass != null && mediaPlayerClass != null && playerStateEnum != null) {
        Method getAllPlayers = mediaManagerClass.concreteMethodByName("getAllMediaPlayers", "()Ljava/util/List;");

        ObjectReference plList = (ObjectReference)mediaManagerClass.invokeMethod(tr, getAllPlayers, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);

        if (plList != null) {
            ClassType listType = (ClassType)plList.referenceType();
            Method iterator = listType.concreteMethodByName("iterator", "()Ljava/util/Iterator;");
            ObjectReference plIter = (ObjectReference)plList.invokeMethod(tr, iterator, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);

            ClassType iterType = (ClassType)plIter.referenceType();
            Method hasNext = iterType.concreteMethodByName("hasNext", "()Z");
            Method next = iterType.concreteMethodByName("next", "()Ljava/lang/Object;");


            Field playingState = playerStateEnum.fieldByName("PLAYING");

            Method getState = mediaPlayerClass.methodsByName("getState", "()Lcom/sun/media/jfxmedia/events/PlayerStateEvent$PlayerState;").get(0);
            Method pausePlayer = mediaPlayerClass.methodsByName("pause", "()V").get(0);
            boolean hasNextFlag = false;
            do {
                BooleanValue v = (BooleanValue)plIter.invokeMethod(tr, hasNext, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                hasNextFlag = v.booleanValue();
                if (hasNextFlag) {
                    ObjectReference player = (ObjectReference)plIter.invokeMethod(tr, next, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                    ObjectReference curState = (ObjectReference)player.invokeMethod(tr, getState, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                    if (playingState.equals(curState)) {
                        player.invokeMethod(tr, pausePlayer, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                        pausedPlayers.add(player);
                    }
                }
            } while (hasNextFlag);
        }
    }
}