Search in sources :

Example 1 with ClassLoaderReference

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

the class TypeEvaluator method evaluate.

/**
   * @return ReferenceType in the target VM, with the given fully qualified name
   */
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    ClassLoaderReference classLoader = context.getClassLoader();
    ReferenceType lastRes = SoftReference.dereference(myLastResult);
    if (lastRes != null && classLoader == SoftReference.dereference(myLastClassLoader)) {
        // if class loader is null, check that vms match
        if (classLoader != null || lastRes.virtualMachine().equals(context.getDebugProcess().getVirtualMachineProxy().getVirtualMachine())) {
            return lastRes;
        }
    }
    DebugProcessImpl debugProcess = context.getDebugProcess();
    String typeName = myTypeName.getName(debugProcess);
    ReferenceType type = debugProcess.findClass(context, typeName, classLoader);
    if (type == null) {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.class.not.loaded", typeName));
    }
    myLastClassLoader = new WeakReference<>(classLoader);
    myLastResult = new WeakReference<>(type);
    return type;
}
Also used : DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ClassLoaderReference(com.sun.jdi.ClassLoaderReference) ReferenceType(com.sun.jdi.ReferenceType)

Example 2 with ClassLoaderReference

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

the class CompilingEvaluator method evaluate.

@Override
public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();
    EvaluationContextImpl autoLoadContext = ((EvaluationContextImpl) evaluationContext).createEvaluationContext(evaluationContext.getThisObject());
    autoLoadContext.setAutoLoadClasses(true);
    ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process);
    autoLoadContext.setClassLoader(classLoader);
    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version));
    defineClasses(classes, autoLoadContext, process, classLoader);
    try {
        // invoke base evaluator on call code
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, new EvaluatingComputable<ExpressionEvaluator>() {

            @Override
            public ExpressionEvaluator compute() throws EvaluateException {
                TextWithImports callCode = getCallCode();
                PsiElement copyContext = myData.getAnchor();
                CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position);
            }
        });
        return evaluator.evaluate(autoLoadContext);
    } catch (Exception e) {
        throw new EvaluateException("Error during generated code invocation " + e, e);
    }
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ClassObject(com.intellij.openapi.compiler.ClassObject) ClassLoaderReference(com.sun.jdi.ClassLoaderReference) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) DebugProcess(com.intellij.debugger.engine.DebugProcess) SourcePosition(com.intellij.debugger.SourcePosition) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ClassLoaderReference (com.sun.jdi.ClassLoaderReference)2 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcess (com.intellij.debugger.engine.DebugProcess)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)1 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)1 ClassObject (com.intellij.openapi.compiler.ClassObject)1 PsiElement (com.intellij.psi.PsiElement)1 ReferenceType (com.sun.jdi.ReferenceType)1