geertjanw closed pull request #335: [NETBEANS-224] Fixing handling of methods
without names; stripping th?
URL: https://github.com/apache/incubator-netbeans/pull/335
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.editor.base/nbproject/project.xml
b/java.editor.base/nbproject/project.xml
index 987772e6f..74fddcaf4 100644
--- a/java.editor.base/nbproject/project.xml
+++ b/java.editor.base/nbproject/project.xml
@@ -196,6 +196,10 @@
<recursive/>
<compile-dependency/>
</test-dependency>
+ <test-dependency>
+
<code-name-base>org.netbeans.modules.java.j2seplatform</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
<test-dependency>
<code-name-base>org.netbeans.modules.java.source.base</code-name-base>
<recursive/>
diff --git
a/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MarkOccurrencesHighlighterBase.java
b/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MarkOccurrencesHighlighterBase.java
index c60c51a7a..9bb4164a9 100644
---
a/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MarkOccurrencesHighlighterBase.java
+++
b/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MarkOccurrencesHighlighterBase.java
@@ -140,7 +140,8 @@ private boolean isIn(int caretPosition, Token span) {
//detect caret inside the return type or throws clause:
if (typePath != null && typePath.getParentPath().getLeaf().getKind()
== Kind.METHOD) {
//hopefully found something, check:
- MethodTree decl = (MethodTree) typePath.getParentPath().getLeaf();
+ TreePath declPath = typePath.getParentPath();
+ MethodTree decl = (MethodTree) declPath.getLeaf();
Tree type = decl.getReturnType();
if ( node.getBoolean(MarkOccurencesSettingsNames.EXIT, true)
@@ -150,7 +151,7 @@ private boolean isIn(int caretPosition, Token span) {
setExitDetector(med);
try {
- return med.process(info, doc, decl, null);
+ return med.process(info, doc, declPath, null);
} finally {
setExitDetector(null);
}
@@ -164,7 +165,7 @@ private boolean isIn(int caretPosition, Token span) {
setExitDetector(med);
try {
- return med.process(info, doc, decl,
Collections.singletonList(exc));
+ return med.process(info, doc, declPath,
Collections.singletonList(exc));
} finally {
setExitDetector(null);
}
@@ -189,7 +190,7 @@ private boolean isIn(int caretPosition, Token span) {
try {
TreePath tryPath = tu.getPathElementOfKind(Kind.TRY,
typePath);
if (tryPath != null) {
- return med.process(info, doc,
((TryTree)tryPath.getLeaf()).getBlock(),
Collections.singletonList(typePath.getLeaf()));
+ return med.process(info, doc, new
TreePath(tryPath, ((TryTree)tryPath.getLeaf()).getBlock()),
Collections.singletonList(typePath.getLeaf()));
}
} finally {
setExitDetector(null);
diff --git
a/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MethodExitDetector.java
b/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MethodExitDetector.java
index 6ad57e6ce..8f052647c 100644
---
a/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MethodExitDetector.java
+++
b/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/MethodExitDetector.java
@@ -63,7 +63,7 @@ public MethodExitDetector() {}
private Collection<TypeMirror> exceptions;
private Stack<Map<TypeMirror, List<Tree>>> exceptions2HighlightsStack;
- public List<int[]> process(CompilationInfo info, Document document, Tree
methoddeclorblock, Collection<Tree> excs) {
+ public List<int[]> process(CompilationInfo info, Document document,
TreePath methoddeclorblock, Collection<Tree> excs) {
this.info = info;
this.doc = document;
this.highlights = new ArrayList<int[]>();
@@ -76,13 +76,13 @@ public MethodExitDetector() {}
//"return" exit point only if not searching for exceptions:
doExitPoints = excs == null;
- Boolean wasReturn = scan(TreePath.getPath(cu, methoddeclorblock),
null);
+ Boolean wasReturn = scan(methoddeclorblock, null);
if (isCanceled())
return null;
if (doExitPoints && wasReturn != Boolean.TRUE) {
- int lastBracket = Utilities.findLastBracket(methoddeclorblock,
cu, info.getTrees().getSourcePositions(), document);
+ int lastBracket =
Utilities.findLastBracket(methoddeclorblock.getLeaf(), cu,
info.getTrees().getSourcePositions(), document);
if (lastBracket != (-1)) {
//highlight the "fall over" exitpoint:
diff --git
a/java.editor.base/test/unit/data/goldenfiles/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest/testErroneousMethod.pass
b/java.editor.base/test/unit/data/goldenfiles/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest/testErroneousMethod.pass
new file mode 100644
index 000000000..e69de29bb
diff --git
a/java.editor.base/test/unit/data/org/netbeans/modules/java/editor/base/semantic/data/ErroneousMethod.java
b/java.editor.base/test/unit/data/org/netbeans/modules/java/editor/base/semantic/data/ErroneousMethod.java
new file mode 100644
index 000000000..c1d02cf71
--- /dev/null
+++
b/java.editor.base/test/unit/data/org/netbeans/modules/java/editor/base/semantic/data/ErroneousMethod.java
@@ -0,0 +1,5 @@
+package test;
+
+public class ErroneousMethod {
+ public abstract void
+}
diff --git
a/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest.java
b/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest.java
index be54b62f2..c9fb1b19e 100644
---
a/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest.java
+++
b/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/MarkOccDetTest.java
@@ -316,6 +316,10 @@ public void testExitPointsAnnonymous162974b() throws
Exception {
performTest("ExitPoints", 115, 22);
}
+ public void testErroneousMethodNETBEANS_224() throws Exception {
+ performTest("ErroneousMethod", 3, 24);
+ }
+
//Support for exotic identifiers has been removed 6999438
public void REMOVEDtestExoticIdentifiers1() throws Exception {
performTest("ExoticIdentifier", 3, 43);
diff --git
a/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
b/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
index c1b44f009..82b6d9bf1 100644
---
a/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
+++
b/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
@@ -56,6 +56,7 @@
import com.sun.tools.javac.util.FatalError;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Names;
import java.io.File;
import java.io.IOException;
import java.util.*;
@@ -373,6 +374,7 @@ public void run() throws IOException {
private void dropMethodsAndErrors(com.sun.tools.javac.util.Context ctx,
CompilationUnitTree cut) {
Symtab syms = Symtab.instance(ctx);
+ Names names = Names.instance(ctx);
TreeMaker make = TreeMaker.instance(ctx);
//TODO: should preserve error types!!!
new TreePathScanner<Void, Void>() {
@@ -423,14 +425,21 @@ public Void visitMethod(MethodTree node, Void p) {
@Override
public Void visitClass(ClassTree node, Void p) {
- Symbol.ClassSymbol csym = ((JCTree.JCClassDecl) node).sym;
+ JCClassDecl clazz = (JCTree.JCClassDecl) node;
+ Symbol.ClassSymbol csym = clazz.sym;
Type.ClassType ct = (Type.ClassType) csym.type;
ct.all_interfaces_field =
error2Object(ct.all_interfaces_field);
ct.allparams_field = error2Object(ct.allparams_field);
ct.interfaces_field = error2Object(ct.interfaces_field);
ct.typarams_field = error2Object(ct.typarams_field);
ct.supertype_field = error2Object(ct.supertype_field);
- return super.visitClass(node, p);
+ super.visitClass(node, p);
+ for (JCTree def : clazz.defs) {
+ if (def.hasTag(JCTree.Tag.ERRONEOUS)) {
+ clazz.defs =
com.sun.tools.javac.util.List.filter(clazz.defs, def);
+ }
+ }
+ return null;
}
private void clearAnnotations(SymbolMetadata metadata) {
diff --git
a/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
b/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
index 86ba81f20..0616a3731 100644
---
a/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
+++
b/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
@@ -192,4 +192,26 @@ public void testModuleInfoAndSourceLevel8() throws
Exception {
assertEquals(new
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test.sig")),
createdFiles);
}
+
+ public void testErroneousMethodClassNETBEANS_224() throws Exception {
+ ParsingOutput result =
runIndexing(Arrays.asList(compileTuple("test/Test1.java", "package test; public
class Test1 { public abstract void }"),
+
compileTuple("test/Test2.java", "package test; public class Test2 { public
abstract Object }"),
+
compileTuple("test/Test3.java", "package test; public class Test3 { public
abstract class }"),
+
compileTuple("test/Test4.java", "package test; public class ")),
+ 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/Test1.sig",
+
"cache/s1/java/15/classes/test/Test2.sig",
+
"cache/s1/java/15/classes/test/Test3.sig")),
+ createdFiles);
+ }
}
----------------------------------------------------------------
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