Search in sources :

Example 1 with ClassObject

use of com.intellij.openapi.compiler.ClassObject 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)

Example 2 with ClassObject

use of com.intellij.openapi.compiler.ClassObject 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

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