[hg] main-silver: #224716: Expressions is Lambda methods are par...

  • From:
  • To:
  • Subject: [hg] main-silver: #224716: Expressions is Lambda methods are par...
  • Date: Sun, 24 Mar 2013 08:08:31 -0700

changeset 578dadd91fc0 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/578dadd91fc0
description:
        #224716: Expressions is Lambda methods are parsed and operations are 
correctly found.

diffstat:

 
debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
 |  36 ++++++++-
 1 files changed, 32 insertions(+), 4 deletions(-)

diffs (88 lines):

diff --git 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
--- 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
+++ 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
@@ -80,6 +80,7 @@
 import com.sun.source.tree.MethodTree;
 import com.sun.source.tree.ModifiersTree;
 import com.sun.source.tree.Scope;
+import com.sun.source.tree.Tree.Kind;
 import com.sun.source.tree.VariableTree;
 import com.sun.source.util.SourcePositions;
 import com.sun.source.util.TreePath;
@@ -88,6 +89,8 @@
 
 import java.util.Collections;
 import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
@@ -167,6 +170,8 @@
     private static String fronting =
         System.getProperty ("netbeans.debugger.fronting", "true");
 
+    private static final Logger logger = 
Logger.getLogger(EditorContextImpl.class.getName());
+
     private PropertyChangeSupport   pcs;
     private Map<Annotation, String> annotationToURL = new 
HashMap<Annotation, String>();
     private PropertyChangeListener  dispatchListener;
@@ -2597,19 +2602,24 @@
                     "\nFree memory = "+Runtime.getRuntime().freeMemory());
             return new Operation[] {};
         }
+        // We need the enclosing statement/block
+        Tree statementTree = 
findStatementInScope(ci.getTreeUtilities().pathFor(offset));
+        logger.log(Level.FINE, "Statement tree found at line {0}:\n{1}\n", 
new Object[]{ lineNumber, statementTree });
+        if (statementTree == null) {
         Scope scope = ci.getTreeUtilities().scopeFor(offset);
         Element method = scope.getEnclosingMethod();
         if (method == null) {
             return new Operation[] {};
         }
-        Tree methodTree = ci.getTrees().getTree(method);
-        if (methodTree == null) { // method not found
+            statementTree = ci.getTrees().getTree(method);
+        }
+        if (statementTree == null) { // method not found
             return new Operation[] {};
         }
         CompilationUnitTree cu = ci.getCompilationUnit();
         ExpressionScanner scanner = new ExpressionScanner(lineNumber, cu, 
ci.getTrees().getSourcePositions());
         ExpressionScanner.ExpressionsInfo info = new 
ExpressionScanner.ExpressionsInfo();
-        List<Tree> expTrees = methodTree.accept(scanner, info);
+        List<Tree> expTrees = statementTree.accept(scanner, info);
 
         //com.sun.source.tree.ExpressionTree expTree = 
scanner.getExpressionTree();
         if (expTrees == null || expTrees.isEmpty()) {
@@ -2641,11 +2651,29 @@
                 new OperationCreationDelegateImpl(),
                 nodeOperations);
         if (ops != null) {
-            assignNextOperations(methodTree, cu, ci, bytecodeProvider, 
expTrees, info, nodeOperations);
+            assignNextOperations(statementTree, cu, ci, bytecodeProvider, 
expTrees, info, nodeOperations);
         }
         return ops;
     }
 
+    private Tree findStatementInScope(TreePath tp) {
+        Tree tree = tp.getLeaf();
+        Kind kind = tree.getKind();
+        switch (kind) {
+            case BLOCK:
+            case EXPRESSION_STATEMENT:
+            case LAMBDA_EXPRESSION:
+            case METHOD:
+                return tree;
+        }
+        tp = tp.getParentPath();
+        if (tp == null) {
+            return null;
+        } else {
+            return findStatementInScope(tp);
+        }
+    }
+
     private static RequestProcessor scanningProcessor = new 
RequestProcessor("Debugger Context Scanning", 1);   // NOI18N
 
     private static abstract class ScanRunnable <E extends Throwable> 
implements Runnable {

[hg] main-silver: #224716: Expressions is Lambda methods are par...

mentlicher 03/25/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close