Search in sources :

Example 1 with ClassType

use of com.sun.jdi.ClassType in project jdk8u_jdk by JetBrains.

the class OomDebugTest method test1.

/*
     * Test case: Object reference as method parameter.
     */
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
    System.out.println("DEBUG: ------------> Running test1");
    try {
        Field field = targetClass.fieldByName("fooCls");
        ClassType clsType = (ClassType) field.type();
        Method constructor = getConstructorForClass(clsType);
        for (int i = 0; i < 15; i++) {
            @SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
            if (objRef.isCollected()) {
                System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
                continue;
            }
            invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) InvocationException(com.sun.jdi.InvocationException) ArrayList(java.util.ArrayList) Method(com.sun.jdi.Method) ClassType(com.sun.jdi.ClassType)

Example 2 with ClassType

use of com.sun.jdi.ClassType in project intellij-community by JetBrains.

the class UnBoxingEvaluator method convertToPrimitive.

private static Value convertToPrimitive(EvaluationContextImpl context, ObjectReference value, final String conversionMethodName, String conversionMethodSignature) throws EvaluateException {
    final DebugProcessImpl process = context.getDebugProcess();
    final ClassType wrapperClass = (ClassType) value.referenceType();
    Method method = wrapperClass.concreteMethodByName(conversionMethodName, conversionMethodSignature);
    if (method == null) {
        throw new EvaluateException("Cannot convert to primitive value of type " + value.type() + ": Unable to find method " + conversionMethodName + conversionMethodSignature);
    }
    return process.invokeMethod(context, value, method, Collections.emptyList());
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) Method(com.sun.jdi.Method) ClassType(com.sun.jdi.ClassType)

Example 3 with ClassType

use of com.sun.jdi.ClassType in project che by eclipse.

the class Evaluator method isAssignable.

private boolean isAssignable(Type from, Type to) {
    if (from.equals(to)) {
        return true;
    }
    if (from instanceof BooleanType) {
        return to instanceof BooleanType;
    }
    if (to instanceof BooleanType) {
        return false;
    }
    if (from instanceof PrimitiveType) {
        return to instanceof PrimitiveType;
    }
    if (to instanceof PrimitiveType) {
        return false;
    }
    if (from instanceof ArrayType) {
        if (to instanceof ArrayType) {
            Type fromArrayComponent;
            Type toArrayComponent;
            try {
                fromArrayComponent = ((ArrayType) from).componentType();
                toArrayComponent = ((ArrayType) to).componentType();
            } catch (ClassNotLoadedException e) {
                return false;
            }
            if (fromArrayComponent instanceof PrimitiveType) {
                return fromArrayComponent.equals(toArrayComponent);
            }
            return !(toArrayComponent instanceof PrimitiveType) && isAssignable(fromArrayComponent, toArrayComponent);
        }
        return to.name().equals("java.lang.Object");
    }
    if (from instanceof ClassType) {
        ClassType superClass = ((ClassType) from).superclass();
        if (superClass != null && isAssignable(superClass, to)) {
            return true;
        }
        for (InterfaceType interfaceType : ((ClassType) from).interfaces()) {
            if (isAssignable(interfaceType, to)) {
                return true;
            }
        }
    }
    for (InterfaceType interfaceType : ((InterfaceType) from).subinterfaces()) {
        if (isAssignable(interfaceType, to)) {
            return true;
        }
    }
    return false;
}
Also used : ArrayType(com.sun.jdi.ArrayType) ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) InterfaceType(com.sun.jdi.InterfaceType) Type(com.sun.jdi.Type) ClassType(com.sun.jdi.ClassType) ArrayType(com.sun.jdi.ArrayType) PrimitiveType(com.sun.jdi.PrimitiveType) BooleanType(com.sun.jdi.BooleanType) ReferenceType(com.sun.jdi.ReferenceType) InterfaceType(com.sun.jdi.InterfaceType) BooleanType(com.sun.jdi.BooleanType) PrimitiveType(com.sun.jdi.PrimitiveType) ClassType(com.sun.jdi.ClassType)

Example 4 with ClassType

use of com.sun.jdi.ClassType in project intellij-community by JetBrains.

the class RuntimeTypeEvaluator method getCastableRuntimeType.

@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;
}
Also used : InterfaceType(com.sun.jdi.InterfaceType) Type(com.sun.jdi.Type) ClassType(com.sun.jdi.ClassType) InterfaceType(com.sun.jdi.InterfaceType) ClassType(com.sun.jdi.ClassType) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ClassType

use of com.sun.jdi.ClassType in project intellij-community by JetBrains.

the class CompilingEvaluator method defineClasses.

private ClassType defineClasses(Collection<ClassObject> classes, EvaluationContext context, DebugProcess process, ClassLoaderReference classLoader) throws EvaluateException {
    for (ClassObject cls : classes) {
        if (cls.getPath().contains(GEN_CLASS_NAME)) {
            final byte[] content = cls.getContent();
            if (content != null) {
                final byte[] bytes = changeSuperToMagicAccessor(content);
                ClassLoadingUtils.defineClass(cls.getClassName(), bytes, context, process, classLoader);
            }
        }
    }
    return (ClassType) process.findClass(context, getGenClassQName(), classLoader);
}
Also used : ClassObject(com.intellij.openapi.compiler.ClassObject) ClassType(com.sun.jdi.ClassType)

Aggregations

ClassType (com.sun.jdi.ClassType)6 InterfaceType (com.sun.jdi.InterfaceType)3 Method (com.sun.jdi.Method)3 Type (com.sun.jdi.Type)2 ArrayList (java.util.ArrayList)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 ClassObject (com.intellij.openapi.compiler.ClassObject)1 ArrayType (com.sun.jdi.ArrayType)1 BooleanType (com.sun.jdi.BooleanType)1 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)1 Field (com.sun.jdi.Field)1 InvocationException (com.sun.jdi.InvocationException)1 ObjectReference (com.sun.jdi.ObjectReference)1 PrimitiveType (com.sun.jdi.PrimitiveType)1 ReferenceType (com.sun.jdi.ReferenceType)1 Nullable (org.jetbrains.annotations.Nullable)1