geertjanw closed pull request #345: Keep parameter names during indexing and 
read them back while reading?
URL: https://github.com/apache/incubator-netbeans/pull/345
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
 
b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
index 83d1cb36d..c3fb0e960 100644
--- 
a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
+++ 
b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
@@ -811,6 +811,7 @@ private static JavacTaskImpl createJavacTask(
         }
         options.add("-XDide");   // NOI18N, javac runs inside the IDE
         options.add("-XDsave-parameter-names");   // NOI18N, javac runs inside 
the IDE
+        options.add("-parameters");   // NOI18N, save and read parameter names
         options.add("-XDsuppressAbortOnBadClassFile");   // NOI18N, when a 
class file cannot be read, produce an error type instead of failing with an 
exception
         options.add("--should-stop:at=GENERATE");   // NOI18N, parsing should 
not stop in phase where an error is found
         options.add("-g:source"); // NOI18N, Make the compiler to maintian 
source file info
diff --git 
a/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
 
b/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
index ad8e5a330..f550f7ebc 100644
--- 
a/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
+++ 
b/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
@@ -18,6 +18,7 @@
  */
 package org.netbeans.modules.java.source.indexing;
 
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
@@ -26,10 +27,15 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.ElementFilter;
 import javax.swing.event.ChangeListener;
+import javax.tools.JavaFileObject;
 import org.netbeans.api.java.classpath.ClassPath;
-import org.netbeans.api.java.queries.SourceLevelQuery;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
 import org.netbeans.api.java.source.SourceUtilsTestUtil;
+import org.netbeans.api.java.source.Task;
 import org.netbeans.api.java.source.TestUtilities;
 import org.netbeans.junit.NbTestCase;
 import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput;
@@ -83,6 +89,44 @@ public void testClassesLivingElsewhere() throws Exception {
         assertFalse(ErrorsCache.isInError(getRoot(), true));
     }
 
+    public void testStoreAndReadParameterNames() throws Exception {
+        ParsingOutput result = 
runIndexing(Arrays.asList(compileTuple("test/Test.java",
+                                                                      "package 
test; public class Test { public void test(int parameter) { } }")),
+                                           Arrays.asList());
+
+        assertFalse(result.lowMemory);
+        assertTrue(result.success);
+
+        Set<String> createdFiles = new HashSet<String>();
+
+        for (File created : result.createdFiles) {
+            
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
+        }
+
+        assertEquals(new 
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test.sig")),
+                     createdFiles);
+        assertFalse(ErrorsCache.isInError(getRoot(), false));
+
+        JavaSource js = 
JavaSource.forFileObject(src.getFileObject("test/Test.java"));
+
+        js = JavaSource.create(js.getClasspathInfo());
+        js.runUserActionTask(new Task<CompilationController>() {
+            @Override
+            public void run(CompilationController cc) throws Exception {
+                cc.toPhase(JavaSource.Phase.RESOLVED);
+                TypeElement clazz = 
cc.getElements().getTypeElement("test.Test");
+                assertEquals(JavaFileObject.Kind.CLASS, ((ClassSymbol) 
clazz).classfile.getKind());
+                assertEquals("parameter", 
ElementFilter.methodsIn(clazz.getEnclosedElements())
+                                                       .iterator()
+                                                       .next()
+                                                       .getParameters()
+                                                       .get(0)
+                                                       .getSimpleName()
+                                                       .toString());
+            }
+        }, true);
+    }
+
     protected ParsingOutput runIndexing(List<CompileTuple> files, 
List<CompileTuple> virtualFiles) throws Exception {
         TransactionContext txc = 
TransactionContext.beginStandardTransaction(src.toURL(), true, false, false);
         Factory f = new JavaCustomIndexer.Factory();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to