From f8dd0c8baadfdfddca7a86aa65ecde760c871b68 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 16 Dec 2016 14:15:24 +0300 Subject: [PATCH] IDEA-164680 Exception when creating Class Level Watch with stream().filter() --- .../debugger/ui/impl/watch/CompilingEvaluator.java | 11 +++++++---- .../debugger/ui/impl/watch/EvaluationDescriptor.java | 7 +++---- .../ExtractLightMethodObjectHandler.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java index 6a7c25653a0e..75ab401f215e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java @@ -79,12 +79,16 @@ public abstract class CompilingEvaluator implements ExpressionEvaluator { public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException { DebugProcess process = evaluationContext.getDebugProcess(); - ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(evaluationContext, process); + 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 classes = compile(JdkVersionUtil.getVersion(version)); - defineClasses(classes, evaluationContext, process, classLoader); + defineClasses(classes, autoLoadContext, process, classLoader); try { // invoke base evaluator on call code @@ -99,8 +103,7 @@ public abstract class CompilingEvaluator implements ExpressionEvaluator { return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position); } }); - ((EvaluationContextImpl)evaluationContext).setClassLoader(classLoader); - return evaluator.evaluate(evaluationContext); + return evaluator.evaluate(autoLoadContext); } catch (Exception e) { throw new EvaluateException("Error during generated code invocation " + e, e); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/EvaluationDescriptor.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/EvaluationDescriptor.java index a84617b9aabe..fb96be1ed0bc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/EvaluationDescriptor.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/EvaluationDescriptor.java @@ -74,13 +74,12 @@ public abstract class EvaluationDescriptor extends ValueDescriptorImpl { PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position); ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, () -> { + PsiCodeFragment code = getEvaluationCode(thisEvaluationContext); try { - return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext) - .getEvaluatorBuilder() - .build(getEvaluationCode(thisEvaluationContext), position); + return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position); } catch (UnsupportedExpressionException ex) { - ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, psiContext, this::createCodeFragment); + ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code); if (eval != null) { return eval; } diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java index c9ca2c95695f..712b9921e0dd 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java @@ -108,7 +108,7 @@ public class ExtractLightMethodObjectHandler { } } - final PsiClass containingClass = PsiTreeUtil.getParentOfType(originalAnchor, PsiClass.class); + final PsiClass containingClass = PsiTreeUtil.getParentOfType(originalAnchor, PsiClass.class, false); if (containingClass == null) { return null; }