/** * Shared implementation of {@linkplain ClassType#allMethods()} and * {@linkplain InterfaceType#allMethods()} * @return A list of all methods (recursively) */ public final List<Method> allMethods() { ArrayList<Method> list = new ArrayList<>(methods()); ClassType clazz = superclass(); while (clazz != null) { list.addAll(clazz.methods()); clazz = clazz.superclass(); } /* * Avoid duplicate checking on each method by iterating through * duplicate-free allInterfaces() rather than recursing */ for (InterfaceType interfaze : getAllInterfaces()) { list.addAll(interfaze.methods()); } return list; }
/** * JDI addition: Determines if this is a F3 class. * * @return <code>true</code> if this is a F3 class; false otherwise. */ @Override public boolean isF3Type() { if (!isIsF3TypeSet) { isIsF3TypeSet = true; F3VirtualMachine f3vm = virtualMachine(); InterfaceType f3ObjType = (InterfaceType) F3Wrapper.unwrap(f3vm.f3ObjectType()); if (f3ObjType != null) { ClassType thisType = underlying(); List<InterfaceType> allIfaces = thisType.allInterfaces(); for (InterfaceType iface : allIfaces) { if (iface.equals(f3ObjType)) { isF3Type = true; break; } } } } return isF3Type; }
@Override boolean isAssignableTo(ReferenceType type) { ClassTypeImpl superclazz = (ClassTypeImpl) superclass(); if (this.equals(type)) { return true; } else if ((superclazz != null) && superclazz.isAssignableTo(type)) { return true; } else { List<InterfaceType> interfaces = interfaces(); Iterator<InterfaceType> iter = interfaces.iterator(); while (iter.hasNext()) { InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next(); if (interfaze.isAssignableTo(type)) { return true; } } return false; } }
private void handleInterfaceLoad(final InterfaceType intfType, final ThreadReference thread) { // do not proceed if this part of the hierarchy has been processed if (contourFactory().lookupStaticContour(intfType.name()) == null) { // update the meta-data for this type and all other types in its file resolveType(intfType); // recursively create the schemas, as necessary final List<?> superTypes = intfType.superinterfaces(); for (final Object o : superTypes) { final InterfaceType superType = (InterfaceType) o; handleInterfaceLoad(superType, thread); } // all interfaces are either top-level or static; // we only create a contour if the interface declares fields if (intfType.fields().size() > 0) { // creates and dispatches a type load event for this type manager().jiveDispatcher().dispatchLoadEvent(intfType, thread); } } }
@Override final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) { /* * Add methods from * parent types first, so that the methods in this class will * overwrite them in the hash table */ Iterator<InterfaceType> iter = interfaces().iterator(); while (iter.hasNext()) { InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next(); if (!seenInterfaces.contains(interfaze)) { interfaze.addVisibleMethods(methodMap, seenInterfaces); seenInterfaces.add(interfaze); } } ClassTypeImpl clazz = (ClassTypeImpl) superclass(); if (clazz != null) { clazz.addVisibleMethods(methodMap, seenInterfaces); } addToMethodMap(methodMap, methods()); }
void writeLocation(Location location) { ReferenceTypeImpl refType = (ReferenceTypeImpl)location.declaringType(); byte tag; if (refType instanceof ClassType) { tag = JDWP.TypeTag.CLASS; } else if (refType instanceof InterfaceType) { // It's possible to have executable code in an interface tag = JDWP.TypeTag.INTERFACE; } else { throw new InternalException("Invalid Location"); } writeByte(tag); writeClassRef(refType.ref()); writeMethodRef(((MethodImpl)location.method()).ref()); writeLong(location.codeIndex()); }
public List<Method> visibleMethods() { /* * Build a collection of all visible methods. The hash * map allows us to do this efficiently by keying on the * concatenation of name and signature. */ Map<String, Method> map = new HashMap<String, Method>(); addVisibleMethods(map, new HashSet<InterfaceType>()); /* * ... but the hash map destroys order. Methods should be * returned in a sensible order, as they are in allMethods(). * So, start over with allMethods() and use the hash map * to filter that ordered collection. */ List<Method> list = allMethods(); list.retainAll(new HashSet<Method>(map.values())); return list; }
boolean isAssignableTo(ReferenceType destType) { if (destType instanceof ArrayType) { try { Type destComponentType = ((ArrayType)destType).componentType(); return isComponentAssignable(destComponentType, componentType()); } catch (ClassNotLoadedException e) { // One or both component types has not yet been // loaded => can't assign return false; } } else if (destType instanceof InterfaceType) { // Only valid InterfaceType assignee is Cloneable return destType.name().equals("java.lang.Cloneable"); } else { // Only valid ClassType assignee is Object return destType.name().equals("java.lang.Object"); } }
@Override void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) { /* * Add methods from * parent types first, so that the methods in this class will * overwrite them in the hash table */ Iterator<InterfaceType> iter = superinterfaces().iterator(); while (iter.hasNext()) { InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next(); if (!seenInterfaces.contains(interfaze)) { interfaze.addVisibleMethods(methodMap, seenInterfaces); seenInterfaces.add(interfaze); } } addToMethodMap(methodMap, methods()); }
List getAllMethods() { ArrayList list = new ArrayList(methods()); ClassType clazz = superclass(); while (clazz != null) { list.addAll(clazz.methods()); clazz = clazz.superclass(); } /* * Avoid duplicate checking on each method by iterating through * duplicate-free allInterfaces() rather than recursing */ Iterator iter = allInterfaces().iterator(); while (iter.hasNext()) { InterfaceType interfaze = (InterfaceType)iter.next(); list.addAll(interfaze.methods()); } return list; }
@Override void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) { /* * Add methods from * parent types first, so that the methods in this class will * overwrite them in the hash table */ Iterator<InterfaceType> iter = interfaces().iterator(); while (iter.hasNext()) { InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next(); if (!seenInterfaces.contains(interfaze)) { interfaze.addVisibleMethods(methodMap, seenInterfaces); seenInterfaces.add(interfaze); } } ClassTypeImpl clazz = (ClassTypeImpl)superclass(); if (clazz != null) { clazz.addVisibleMethods(methodMap, seenInterfaces); } addToMethodMap(methodMap, methods()); }
boolean isAssignableTo(ReferenceType destType) { if (destType instanceof ArrayType) { try { Type destComponentType = ((ArrayType)destType).componentType(); return isComponentAssignable(destComponentType, componentType()); } catch (ClassNotLoadedException e) { // One or both component types has not yet been // loaded => can't assign return false; } } else { Symbol typeName = ((ReferenceTypeImpl)destType).typeNameAsSymbol(); if (destType instanceof InterfaceType) { // Every array type implements java.io.Serializable and // java.lang.Cloneable. fixme in JVMDI-JDI, includes only // Cloneable but not Serializable. return typeName.equals(vm.javaLangCloneable()) || typeName.equals(vm.javaIoSerializable()); } else { // Only valid ClassType assignee is Object return typeName.equals(vm.javaLangObject()); } } }
@Nullable public static PsiType getCastableRuntimeType(Project project, Value value) { Type type = value.type(); PsiType psiType = findPsiType(project, type); if (psiType != null) { return psiType; } if (type instanceof ClassType) { ClassType superclass = ((ClassType)type).superclass(); if (superclass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(superclass.name())) { psiType = findPsiType(project, superclass); if (psiType != null) { return psiType; } } for (InterfaceType interfaceType : ((ClassType)type).interfaces()) { psiType = findPsiType(project, interfaceType); if (psiType != null) { return psiType; } } } return null; }
/** * JDI addition: Determines if this is a F3 type. * * @return <code>true</code> if this is a F3 type; false otherwise. */ public boolean isF3Type() { if (!isIsF3TypeSet) { isIsF3TypeSet = true; F3VirtualMachine f3vm = virtualMachine(); InterfaceType f3ObjType = (InterfaceType) F3Wrapper.unwrap(f3vm.f3ObjectType()); if (f3ObjType != null) { InterfaceType thisType = underlying(); List<InterfaceType> allIfaces = thisType.superinterfaces(); for (InterfaceType iface : allIfaces) { if (iface.equals(f3ObjType)) { isF3Type = true; break; } } } } return isF3Type; }
public static PsiClass getCastableRuntimeType(Project project, Value value) { Type type = value.type(); PsiClass psiClass = findPsiClass(project, type); if (psiClass != null) { return psiClass; } if (type instanceof ClassType) { ClassType superclass = ((ClassType)type).superclass(); if (superclass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(superclass.name())) { psiClass = findPsiClass(project, superclass); if (psiClass != null) { return psiClass; } } for (InterfaceType interfaceType : ((ClassType)type).interfaces()) { psiClass = findPsiClass(project, interfaceType); if (psiClass != null) { return psiClass; } } } return null; }
private boolean ungrabWindowFX(ThreadReference tr) { // javafx.stage.Window.impl_getWindows() - Iterator<Window> // while (iterator.hasNext()) { // Window w = iterator.next(); // ungrabWindowFX(w); // } try { VirtualMachine vm = MirrorWrapper.virtualMachine(tr); List<ReferenceType> windowClassesByName = VirtualMachineWrapper.classesByName(vm, "javafx.stage.Window"); if (windowClassesByName.isEmpty()) { logger.info("Unable to release FX X grab, no javafx.stage.Window class in target VM "+VirtualMachineWrapper.description(vm)); return true; // We do not know whether there was any grab } ClassType WindowClass = (ClassType) windowClassesByName.get(0); Method getWindowsMethod = WindowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;"); if (getWindowsMethod == null) { logger.info("Unable to release FX X grab, no impl_getWindows() method in "+WindowClass); return true; // We do not know whether there was any grab } ObjectReference windowsIterator = (ObjectReference) WindowClass.invokeMethod(tr, getWindowsMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (windowsIterator == null) { return true; // We do not know whether there was any grab } InterfaceType IteratorClass = (InterfaceType) VirtualMachineWrapper.classesByName(vm, Iterator.class.getName()).get(0); Method hasNext = IteratorClass.methodsByName("hasNext", "()Z").get(0); Method next = IteratorClass.methodsByName("next", "()Ljava/lang/Object;").get(0); while (hasNext(hasNext, tr, windowsIterator)) { ObjectReference w = next(next, tr, windowsIterator); ungrabWindowFX(WindowClass, w, tr); } } catch (VMDisconnectedExceptionWrapper vmdex) { return true; // Disconnected, all is good. } catch (Exception ex) { logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex); return true; // We do not know whether there was any grab } return true; }
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."); } } }
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.EMPTY_LIST, 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.EMPTY_LIST, 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.EMPTY_LIST, 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.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); hasNextFlag = v.booleanValue(); if (hasNextFlag) { ObjectReference player = (ObjectReference)plIter.invokeMethod(tr, next, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); ObjectReference curState = (ObjectReference)player.invokeMethod(tr, getState, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (playingState.equals(curState)) { player.invokeMethod(tr, pausePlayer, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); pausedPlayers.add(player); } } } while (hasNextFlag); } } }
private static void resumeMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException { if (!pausedPlayers.isEmpty()) { final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer"); List<Method> play = mediaPlayerClass.methodsByName("play", "()V"); if (play.isEmpty()) { return; } Method p = play.iterator().next(); for(ObjectReference pR : pausedPlayers) { pR.invokeMethod(tr, p, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); } } }
private static InterfaceType getInterface(VirtualMachine vm, ThreadReference tr, String name) { ReferenceType t = getType(vm, tr, name); if (t instanceof InterfaceType) { return (InterfaceType)t; } logger.log(Level.WARNING, "{0} is not an interface but {1}", new Object[]{name, t}); // NOI18N return null; }