From a5b81b9ea4b7447c58c3a1236f2cbbe2abd9e514 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 5 Oct 2015 18:41:38 +0300 Subject: [PATCH] show local variables even without sources --- .../engine/FrameExtraVariablesProvider.java | 10 ++++-- .../debugger/engine/JavaStackFrame.java | 32 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/FrameExtraVariablesProvider.java b/java/debugger/impl/src/com/intellij/debugger/engine/FrameExtraVariablesProvider.java index 3943da463b21..f118376f97bf 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/FrameExtraVariablesProvider.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/FrameExtraVariablesProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.intellij.debugger.SourcePosition; import com.intellij.debugger.engine.evaluation.EvaluationContext; import com.intellij.debugger.engine.evaluation.TextWithImports; import com.intellij.openapi.extensions.ExtensionPointName; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -28,7 +29,10 @@ import java.util.Set; public interface FrameExtraVariablesProvider { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.debugger.frameExtraVarsProvider"); - boolean isAvailable(SourcePosition sourcePosition, EvaluationContext evalContext); + boolean isAvailable(@NotNull SourcePosition sourcePosition, @NotNull EvaluationContext evalContext); - Set collectVariables(SourcePosition sourcePosition, EvaluationContext evalContext, Set alreadyCollected); + @NotNull + Set collectVariables(@NotNull SourcePosition sourcePosition, + @NotNull EvaluationContext evalContext, + @NotNull Set alreadyCollected); } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java index 8d08444e9b86..bd56a68193c4 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java @@ -248,6 +248,9 @@ public class JavaStackFrame extends XStackFrame { } } + private static final Pair, Set> EMPTY_USED_VARS = + Pair.create(Collections.emptySet(), Collections.emptySet()); + // copied from FrameVariablesTree private void buildVariables(DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @@ -276,10 +279,6 @@ public class JavaStackFrame extends XStackFrame { if (evaluationContext == null) { return; } - final SourcePosition sourcePosition = debuggerContext.getSourcePosition(); - if (sourcePosition == null) { - return; - } try { if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) { @@ -287,15 +286,19 @@ public class JavaStackFrame extends XStackFrame { superBuildVariables(evaluationContext, children); } else { + final SourcePosition sourcePosition = debuggerContext.getSourcePosition(); final Map visibleVariables = getVisibleVariables(getStackFrameProxy()); - final Pair, Set> usedVars = - ApplicationManager.getApplication().runReadAction(new Computable, Set>>() { + + Pair, Set> usedVars = EMPTY_USED_VARS; + if (sourcePosition != null) { + usedVars = ApplicationManager.getApplication().runReadAction(new Computable, Set>>() { @Override public Pair, Set> compute() { return findReferencedVars(ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition); } }); - // add locals + } + // add locals if (myAutoWatchMode) { for (String var : usedVars.first) { LocalVariableProxyImpl local = visibleVariables.get(var); @@ -310,10 +313,11 @@ public class JavaStackFrame extends XStackFrame { final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject()); evalContextCopy.setAutoLoadClasses(false); - final Set extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext); - - // add extra vars - addToChildrenFrom(extraVars, children, evaluationContext); + if (sourcePosition != null) { + Set extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext); + // add extra vars + addToChildrenFrom(extraVars, children, evaluationContext); + } // add expressions addToChildrenFrom(usedVars.second, children, evalContextCopy); @@ -340,8 +344,8 @@ public class JavaStackFrame extends XStackFrame { } private static Set computeExtraVars(Pair, Set> usedVars, - SourcePosition sourcePosition, - EvaluationContextImpl evalContext) { + @NotNull SourcePosition sourcePosition, + @NotNull EvaluationContextImpl evalContext) { Set alreadyCollected = new HashSet(usedVars.first); for (TextWithImports text : usedVars.second) { alreadyCollected.add(text.getText()); @@ -578,7 +582,7 @@ public class JavaStackFrame extends XStackFrame { return true; } - private static Pair, Set> findReferencedVars(Set visibleVars, SourcePosition position) { + private static Pair, Set> findReferencedVars(Set visibleVars, @NotNull SourcePosition position) { final int line = position.getLine(); if (line < 0) { return Pair.create(Collections.emptySet(), Collections.emptySet());