Search in sources :

Example 1 with ClassNotLoadedException

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

the class Evaluator method invokeMethod.

public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
    if (!(value instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ObjectReference object = (ObjectReference) value;
    ReferenceType type = object.referenceType();
    List<Method> methods = type.methodsByName(name);
    Method method = findMethod(methods, arguments);
    if (method == null) {
        throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
    }
    try {
        return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
    } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
}
Also used : ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) ObjectReference(com.sun.jdi.ObjectReference) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) InvocationException(com.sun.jdi.InvocationException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) InvalidTypeException(com.sun.jdi.InvalidTypeException)

Example 2 with ClassNotLoadedException

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

the class Evaluator method findMethod.

private Method findMethod(List<Method> methods, List<Value> arguments) {
    Method m = null;
    for (Method mm : methods) {
        List<Type> argumentTypes;
        try {
            argumentTypes = mm.argumentTypes();
        } catch (ClassNotLoadedException e) {
            continue;
        }
        ARGUMENT_MATCHING argumentMatching = argumentsMatching(argumentTypes, arguments);
        if (argumentMatching == ARGUMENT_MATCHING.MATCH) {
            m = mm;
            break;
        } else if (argumentMatching == ARGUMENT_MATCHING.ASSIGNABLE) {
            if (m == null) {
                m = mm;
            } else {
                throw new ExpressionException("Multiple methods with name " + mm.name() + " matched to specified arguments. ");
            }
        }
    }
    return m;
}
Also used : 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) Method(com.sun.jdi.Method)

Example 3 with ClassNotLoadedException

use of com.sun.jdi.ClassNotLoadedException 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)

Aggregations

ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)3 ReferenceType (com.sun.jdi.ReferenceType)3 ArrayType (com.sun.jdi.ArrayType)2 BooleanType (com.sun.jdi.BooleanType)2 ClassType (com.sun.jdi.ClassType)2 InterfaceType (com.sun.jdi.InterfaceType)2 Method (com.sun.jdi.Method)2 PrimitiveType (com.sun.jdi.PrimitiveType)2 Type (com.sun.jdi.Type)2 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)1 InvalidTypeException (com.sun.jdi.InvalidTypeException)1 InvocationException (com.sun.jdi.InvocationException)1 ObjectReference (com.sun.jdi.ObjectReference)1