summaryrefslogtreecommitdiff
path: root/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java')
-rw-r--r--python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java b/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java
index d29259d559c6..d25596a13f2a 100644
--- a/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java
+++ b/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java
@@ -80,25 +80,29 @@ public class PyDebugSupportUtils {
element instanceof PyNamedParameter;
}
- // is expression a variable reference
+ // is expression a variable reference and can be evaluated
// todo: use patterns (?)
- public static boolean isVariable(final Project project, final String expression) {
+ public static boolean canSaveToTemp(final Project project, final String expression) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
public Boolean compute() {
final PsiFile file = PyElementGenerator.getInstance(project).createDummyFile(LanguageLevel.getDefault(), expression);
final PsiElement root = file.getFirstChild();
- return root instanceof PyExpressionStatement &&
- root.getFirstChild() instanceof PyReferenceExpression &&
- root.getFirstChild() == root.getLastChild() &&
- root.getFirstChild().getFirstChild() != null &&
- root.getFirstChild().getFirstChild().getNode().getElementType() == PyTokenTypes.IDENTIFIER &&
- root.getFirstChild().getFirstChild() == root.getFirstChild().getLastChild() &&
- root.getFirstChild().getFirstChild().getFirstChild() == null;
+ return !isVariable(root) && (root instanceof PyExpressionStatement);
}
});
}
+ private static Boolean isVariable(PsiElement root) {
+ return root instanceof PyExpressionStatement &&
+ root.getFirstChild() instanceof PyReferenceExpression &&
+ root.getFirstChild() == root.getLastChild() &&
+ root.getFirstChild().getFirstChild() != null &&
+ root.getFirstChild().getFirstChild().getNode().getElementType() == PyTokenTypes.IDENTIFIER &&
+ root.getFirstChild().getFirstChild() == root.getFirstChild().getLastChild() &&
+ root.getFirstChild().getFirstChild().getFirstChild() == null;
+ }
+
@Nullable
private static String getLineText(@NotNull Document document, int line) {
if (line > 0 && line < document.getLineCount()) {