Search in sources :

Example 1 with Type

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

the class CreateRendererAction method actionPerformed.

public void actionPerformed(@NotNull final AnActionEvent event) {
    final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext());
    final List<JavaValue> values = ViewAsGroup.getSelectedValues(event);
    if (values.size() != 1) {
        return;
    }
    final JavaValue javaValue = values.get(0);
    final DebugProcessImpl process = debuggerContext.getDebugProcess();
    if (process == null) {
        return;
    }
    final Project project = event.getProject();
    process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) {

        public void threadAction() {
            Type type = javaValue.getDescriptor().getType();
            final String name = type != null ? type.name() : null;
            DebuggerUIUtil.invokeLater(() -> {
                final UserRenderersConfigurable ui = new UserRenderersConfigurable();
                ConfigurableBase<UserRenderersConfigurable, NodeRendererSettings> configurable = new ConfigurableBase<UserRenderersConfigurable, NodeRendererSettings>("reference.idesettings.debugger.typerenderers", DebuggerBundle.message("user.renderers.configurable.display.name"), "reference.idesettings.debugger.typerenderers") {

                    @NotNull
                    @Override
                    protected NodeRendererSettings getSettings() {
                        return NodeRendererSettings.getInstance();
                    }

                    @Override
                    protected UserRenderersConfigurable createUi() {
                        return ui;
                    }
                };
                SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable);
                if (name != null) {
                    NodeRenderer renderer = NodeRendererSettings.getInstance().createCompoundTypeRenderer(name, name, null, null);
                    renderer.setEnabled(true);
                    ui.addRenderer(renderer);
                }
                editor.show();
            });
        }
    });
}
Also used : ConfigurableBase(com.intellij.openapi.options.ConfigurableBase) SingleConfigurableEditor(com.intellij.openapi.options.ex.SingleConfigurableEditor) JavaValue(com.intellij.debugger.engine.JavaValue) NotNull(org.jetbrains.annotations.NotNull) NodeRenderer(com.intellij.debugger.ui.tree.render.NodeRenderer) Project(com.intellij.openapi.project.Project) Type(com.sun.jdi.Type) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) NodeRendererSettings(com.intellij.debugger.settings.NodeRendererSettings) UserRenderersConfigurable(com.intellij.debugger.settings.UserRenderersConfigurable) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 2 with Type

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

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

the class Evaluator method argumentsMatching.

private ARGUMENT_MATCHING argumentsMatching(List<Type> argumentTypes, List<Value> arguments) {
    if (argumentTypes.size() == arguments.size()) {
        Iterator<Value> argumentIterator = arguments.iterator();
        Iterator<Type> argumentTypesIterator = argumentTypes.iterator();
        ARGUMENT_MATCHING result = ARGUMENT_MATCHING.MATCH;
        while (argumentIterator.hasNext() && result != ARGUMENT_MATCHING.NOT_MATCH) {
            Value argumentValue = argumentIterator.next();
            Type argumentType = argumentTypesIterator.next();
            if (argumentValue == null) {
                if (isPrimitive(argumentType)) {
                    // Null may not be used as value if argument type is primitive.
                    result = ARGUMENT_MATCHING.NOT_MATCH;
                }
            } else {
                if (!(argumentValue.type().equals(argumentType))) {
                    result = isAssignable(argumentValue.type(), argumentType) ? ARGUMENT_MATCHING.ASSIGNABLE : ARGUMENT_MATCHING.NOT_MATCH;
                }
            }
        }
        return result;
    }
    return ARGUMENT_MATCHING.NOT_MATCH;
}
Also used : 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) PrimitiveValue(com.sun.jdi.PrimitiveValue) IntegerValue(com.sun.jdi.IntegerValue) LongValue(com.sun.jdi.LongValue) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) FloatValue(com.sun.jdi.FloatValue) Value(com.sun.jdi.Value)

Example 4 with Type

use of com.sun.jdi.Type 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 5 with Type

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

Aggregations

Type (com.sun.jdi.Type)5 ClassType (com.sun.jdi.ClassType)4 InterfaceType (com.sun.jdi.InterfaceType)4 ArrayType (com.sun.jdi.ArrayType)3 BooleanType (com.sun.jdi.BooleanType)3 PrimitiveType (com.sun.jdi.PrimitiveType)3 ReferenceType (com.sun.jdi.ReferenceType)3 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 JavaValue (com.intellij.debugger.engine.JavaValue)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 NodeRendererSettings (com.intellij.debugger.settings.NodeRendererSettings)1 UserRenderersConfigurable (com.intellij.debugger.settings.UserRenderersConfigurable)1 NodeRenderer (com.intellij.debugger.ui.tree.render.NodeRenderer)1 ConfigurableBase (com.intellij.openapi.options.ConfigurableBase)1 SingleConfigurableEditor (com.intellij.openapi.options.ex.SingleConfigurableEditor)1 Project (com.intellij.openapi.project.Project)1 BooleanValue (com.sun.jdi.BooleanValue)1 DoubleValue (com.sun.jdi.DoubleValue)1