Search in sources :

Example 1 with PrimitiveType

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

ArrayType (com.sun.jdi.ArrayType)1 BooleanType (com.sun.jdi.BooleanType)1 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)1 ClassType (com.sun.jdi.ClassType)1 InterfaceType (com.sun.jdi.InterfaceType)1 PrimitiveType (com.sun.jdi.PrimitiveType)1 ReferenceType (com.sun.jdi.ReferenceType)1 Type (com.sun.jdi.Type)1