Commits

Jan Lahoda committed 359eefa

Adjusting bulk search to consider Member Selects and Identifiers as equivalent, where appropriate.

Comments (0)

Files changed (3)

api/src/org/netbeans/modules/jackpot30/impl/pm/TreeSerializer.java

 import com.sun.source.tree.ClassTree;
 import com.sun.source.tree.IdentifierTree;
 import com.sun.source.tree.MemberSelectTree;
+import com.sun.source.tree.MethodInvocationTree;
 import com.sun.source.tree.MethodTree;
 import com.sun.source.tree.Tree;
 import com.sun.source.tree.Tree.Kind;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import org.netbeans.modules.jackpot30.impl.Utilities;
 
 /**
  *
 
     private int depth;
     private int group;
+    private boolean method;
 
     private TreeSerializer(boolean pattern) {
         this.depth = !pattern ? 0 : -1;
             append(p, "[0-9a-f]+");
         }
         append(p, ">");
-        append(p, kindToShortName.get(tree.getKind()));
-        super.scan(tree, p);
+
+        boolean m = method;
+
+        method = false;
+
+        if (tree.getKind() != Kind.IDENTIFIER && (tree.getKind() != Kind.MEMBER_SELECT || !Utilities.isPureMemberSelect(tree, true))) {
+            append(p, kindToShortName.get(tree.getKind()));
+            super.scan(tree, p);
+        } else {
+            boolean memberSelectWithVariables = tree.getKind() == Kind.MEMBER_SELECT && !Utilities.isPureMemberSelect(tree, false);
+
+            if (memberSelectWithVariables) {
+                append(p, "(?:");
+                append(p, kindToShortName.get(tree.getKind()));
+                super.scan(tree, p);
+                append(p, ")|(?:");
+            }
+
+            append(p, "ID");
+
+            //XXX: is this correct??
+            if (m && (tree.getKind() == Kind.IDENTIFIER)) {
+                append(p, ((IdentifierTree) tree).getName());
+            }
+            if (m && (tree.getKind() == Kind.MEMBER_SELECT)) {
+                append(p, ((MemberSelectTree) tree).getIdentifier());
+            }
+
+            if (memberSelectWithVariables) {
+                append(p, ")");
+            }
+        }
         append(p, "</");
         if (depth != (-1)) {
             append(p, Integer.toHexString(--depth));
         return super.visitMethod(node, p);
     }
 
+    @Override
+    public Void visitMethodInvocation(MethodInvocationTree node, Appendable p) {
+        method = true;
+        return super.visitMethodInvocation(node, p);
+    }
+
     private static void append(Appendable a, CharSequence what) {
         try {
             a.append(what);

api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/BulkSearchTest.java

                     Collections.<String>emptyList());
     }
 
+    public void testMemberSelectAndIdentifier() throws Exception {
+        performTest("package test; public class Test { private static void test() { test();}}",
+                    Arrays.asList("test.Test.test()"),
+                    Collections.<String>emptyList());
+    }
+
+    public void testUnpureMemberSelect() throws Exception {
+        performTest("package test; public class Test { private static void test() { new StringBuilder().append('');}}",
+                    Collections.<String>emptyList(),
+                    Arrays.asList("test.append('')"));
+    }
+
+    public void testMemberSelectWithVariables1() throws Exception {
+        performTest("package test; public class Test { private static void test() { new StringBuilder().append('');}}",
+                    Arrays.asList("$0.append('')"),
+                    Collections.<String>emptyList());
+    }
+
+    public void testMemberSelectWithVariables2() throws Exception {
+        performTest("package test; public class Test { private void append(char c) { append('');}}",
+                    Arrays.asList("$0.append('')"),
+                    Collections.<String>emptyList());
+    }
+    
     public void XtestMeasureTime() throws Exception {
         String code = TestUtilities.copyFileToString(new File("/usr/local/home/lahvac/src/nb//outgoing/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java"));
         List<String> patterns = new LinkedList<String>();

api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/TreeSerializerTest.java

         }
     }
 
+    public void testNamesForMethods() throws Exception {
+        prepareTest("test/Test.java", "package test; public class Test { private static void test() { test(); System.err.println(); } }");
+
+        StringBuilder sb = new StringBuilder();
+
+        TreeSerializer.serializeText(info.getCompilationUnit(), sb);
+
+        String serialized = sb.toString();
+
+        assertEquals(3, serialized.split("test").length);
+        assertEquals(2, serialized.split("println").length);
+    }
+
     private void prepareTest(String fileName, String code) throws Exception {
         clearWorkDir();