You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2017/10/04 19:41:23 UTC
[11/13] incubator-netbeans git commit: Work in progress: an
experiment on using javac from JDK for source code modeling.
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.j2seprofiles/src/org/netbeans/modules/java/j2seprofiles/ProfilesAnalyzer.java
----------------------------------------------------------------------
diff --git a/java.j2seprofiles/src/org/netbeans/modules/java/j2seprofiles/ProfilesAnalyzer.java b/java.j2seprofiles/src/org/netbeans/modules/java/j2seprofiles/ProfilesAnalyzer.java
index 79df8ba..b6a220b 100644
--- a/java.j2seprofiles/src/org/netbeans/modules/java/j2seprofiles/ProfilesAnalyzer.java
+++ b/java.j2seprofiles/src/org/netbeans/modules/java/j2seprofiles/ProfilesAnalyzer.java
@@ -22,7 +22,7 @@ import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import com.sun.source.util.Trees;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -634,7 +634,7 @@ nextCpE:for (ClassPath.Entry e : cp.entries()) {
}
//@NonThreadSafe
- private static final class FindPosScanner extends TreePathScanner<Void, Void> {
+ private static final class FindPosScanner extends ErrorAwareTreePathScanner<Void, Void> {
private final FileObject target;
private final Elements elements;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.j2seproject/nbproject/project.properties
----------------------------------------------------------------------
diff --git a/java.j2seproject/nbproject/project.properties b/java.j2seproject/nbproject/project.properties
index e242fda..ca9f13c 100644
--- a/java.j2seproject/nbproject/project.properties
+++ b/java.j2seproject/nbproject/project.properties
@@ -37,3 +37,4 @@ test.config.stableBTD.excludes=\
**/BuildImplTest.class,\
**/J2SEConfigurationProviderTest.class,\
**/J2SEProjectGeneratorTest.class
+requires.nb.javac=true
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ClassMetrics.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ClassMetrics.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/ClassMetrics.java
index fe483ce..f7a129c 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ClassMetrics.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/ClassMetrics.java
@@ -34,7 +34,7 @@ import com.sun.source.tree.TypeCastTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.beans.Expression;
import java.util.Collection;
import java.util.EnumSet;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/CyclomaticComplexityVisitor.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/CyclomaticComplexityVisitor.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/CyclomaticComplexityVisitor.java
index 98de561..edad948 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/CyclomaticComplexityVisitor.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/CyclomaticComplexityVisitor.java
@@ -30,7 +30,7 @@ import com.sun.source.tree.ForLoopTree;
import com.sun.source.tree.IfTree;
import com.sun.source.tree.ThrowTree;
import com.sun.source.tree.WhileLoopTree;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
/**
* This Visitor counts a Cyclomatic complexity on the visited tree.
@@ -40,7 +40,7 @@ import com.sun.source.util.TreePathScanner;
*
* @author sdedic
*/
-public final class CyclomaticComplexityVisitor extends TreePathScanner<Object, Object> {
+public final class CyclomaticComplexityVisitor extends ErrorAwareTreePathScanner<Object, Object> {
private int complexity;
private boolean inClass;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DependencyCollector.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DependencyCollector.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/DependencyCollector.java
index 03128ef..2716b23 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DependencyCollector.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/DependencyCollector.java
@@ -34,7 +34,7 @@ import com.sun.source.tree.TypeCastTree;
import com.sun.source.tree.UnionTypeTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -51,7 +51,7 @@ import org.netbeans.api.java.source.CompilationInfo;
* Collect dependencies on external classes.
* Depending on 'ignoreJavaLibraries' it ignores classes whose QN begins with 'java.' or 'javax.'.
*/
-class DependencyCollector extends TreePathScanner<Object, Object> {
+class DependencyCollector extends ErrorAwareTreePathScanner<Object, Object> {
private boolean ignoreJavaLibraries;
private final CompilationInfo info;
private TypeElement outermostClass;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DepthVisitor.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DepthVisitor.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/DepthVisitor.java
index e6fd546..1954a57 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/DepthVisitor.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/DepthVisitor.java
@@ -29,14 +29,14 @@ import com.sun.source.tree.SwitchTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.TryTree;
import com.sun.source.tree.WhileLoopTree;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
/**
* Counts the maximum depth of the Tree
*
* @author sdedic
*/
-public final class DepthVisitor extends TreePathScanner {
+public final class DepthVisitor extends ErrorAwareTreePathScanner {
private int depth;
private int maxDepth;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ExpressionVisitor.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/ExpressionVisitor.java
index 01d2fb5..0ef1d89 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/ExpressionVisitor.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/ExpressionVisitor.java
@@ -24,7 +24,7 @@ import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.UnaryTree;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
@@ -48,7 +48,7 @@ import org.netbeans.api.java.source.CompilationInfo;
*
* @author sdedic
*/
-class ExpressionVisitor extends TreePathScanner<Object, Object> {
+class ExpressionVisitor extends ErrorAwareTreePathScanner<Object, Object> {
private static final EnumSet<Tree.Kind> NUMERIC_OPERATORS = EnumSet.of(
Tree.Kind.BITWISE_COMPLEMENT, Tree.Kind.LEFT_SHIFT, Tree.Kind.RIGHT_SHIFT, Tree.Kind.UNSIGNED_RIGHT_SHIFT,
Tree.Kind.DIVIDE, Tree.Kind.MINUS, Tree.Kind.MULTIPLY, Tree.Kind.PLUS, Tree.Kind.REMAINDER,
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/MethodMetrics.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/MethodMetrics.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/MethodMetrics.java
index c973cc1..25dca56 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/MethodMetrics.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/MethodMetrics.java
@@ -33,7 +33,7 @@ import com.sun.source.tree.Tree;
import com.sun.source.tree.UnaryTree;
import com.sun.source.tree.WhileLoopTree;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.util.Collection;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
@@ -484,7 +484,7 @@ public class MethodMetrics {
* The visitor will ignore returns, which are the *sole* statement in a if-branch.
* Such branches are considered to be guards, which abort further processing.
*/
- private static class ReturnCountVisitor extends TreePathScanner {
+ private static class ReturnCountVisitor extends ErrorAwareTreePathScanner {
/**
* Suppressed in local classes
*/
@@ -585,7 +585,7 @@ public class MethodMetrics {
* Counts number of 'negations' in a Tree. A negation is either unary ! or binary != inequality
* operator.
*/
- private static class NegationsVisitor extends TreePathScanner {
+ private static class NegationsVisitor extends ErrorAwareTreePathScanner {
private int negationsCount;
private final boolean ignoreAsserts;
@@ -627,7 +627,7 @@ public class MethodMetrics {
/**
* Utility scanner class, which counts all kinds of loops in the scanned subtree
*/
- private static class LoopFinder extends TreePathScanner {
+ private static class LoopFinder extends ErrorAwareTreePathScanner {
private int loopCount;
public int getLoopCount() {
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/src/org/netbeans/modules/java/metrics/hints/NCLOCVisitor.java
----------------------------------------------------------------------
diff --git a/java.metrics/src/org/netbeans/modules/java/metrics/hints/NCLOCVisitor.java b/java.metrics/src/org/netbeans/modules/java/metrics/hints/NCLOCVisitor.java
index add17e0..253ca4b 100644
--- a/java.metrics/src/org/netbeans/modules/java/metrics/hints/NCLOCVisitor.java
+++ b/java.metrics/src/org/netbeans/modules/java/metrics/hints/NCLOCVisitor.java
@@ -40,7 +40,7 @@ import com.sun.source.tree.VariableTree;
import com.sun.source.tree.WhileLoopTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
/**
* Non-comment line visitor. Counts the number of non-comment
@@ -50,7 +50,7 @@ import com.sun.source.util.TreePathScanner;
*
* @author sdedic
*/
-public final class NCLOCVisitor extends TreePathScanner<Object, Object> {
+public final class NCLOCVisitor extends ErrorAwareTreePathScanner<Object, Object> {
/**
* The source text
*/
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.metrics/test/unit/src/org/netbeans/modules/java/metrics/hints/MethodMetricsTest.java
----------------------------------------------------------------------
diff --git a/java.metrics/test/unit/src/org/netbeans/modules/java/metrics/hints/MethodMetricsTest.java b/java.metrics/test/unit/src/org/netbeans/modules/java/metrics/hints/MethodMetricsTest.java
index d0601bd..e9937a1 100644
--- a/java.metrics/test/unit/src/org/netbeans/modules/java/metrics/hints/MethodMetricsTest.java
+++ b/java.metrics/test/unit/src/org/netbeans/modules/java/metrics/hints/MethodMetricsTest.java
@@ -74,7 +74,7 @@ public class MethodMetricsTest extends NbTestCase {
}
/**
- * Runs the hints through code, which triggers all branches of TreeScanner.
+ * Runs the hints through code, which triggers all branches of ErrorAwareTreeScanner.
* This is just a sanity check that a hint does not throw exceptions on some
* construction; but will not catch all errors, obviously.
*/
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.module.graph/nbproject/project.properties
----------------------------------------------------------------------
diff --git a/java.module.graph/nbproject/project.properties b/java.module.graph/nbproject/project.properties
index 5137752..b3de9cd 100644
--- a/java.module.graph/nbproject/project.properties
+++ b/java.module.graph/nbproject/project.properties
@@ -17,3 +17,4 @@
javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial
+requires.nb.javac=true
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.module.graph/nbproject/project.xml
----------------------------------------------------------------------
diff --git a/java.module.graph/nbproject/project.xml b/java.module.graph/nbproject/project.xml
index cec3af8..dc2b425 100644
--- a/java.module.graph/nbproject/project.xml
+++ b/java.module.graph/nbproject/project.xml
@@ -69,15 +69,15 @@
<specification-version>1.44</specification-version>
</run-dependency>
</dependency>
- <dependency>
+<!-- <dependency>
<code-name-base>org.netbeans.libs.javacapi</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.19</specification-version>
</run-dependency>
- </dependency>
- <dependency>
+ </dependency>-->
+<!-- <dependency>
<code-name-base>org.netbeans.libs.javacimpl</code-name-base>
<build-prerequisite/>
<compile-dependency/>
@@ -85,7 +85,7 @@
<release-version>1</release-version>
<specification-version>0.42</specification-version>
</run-dependency>
- </dependency>
+ </dependency>-->
<dependency>
<code-name-base>org.netbeans.modules.java.graph</code-name-base>
<build-prerequisite/>
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.navigation/src/org/netbeans/modules/java/navigation/BreadCrumbsNodeImpl.java
----------------------------------------------------------------------
diff --git a/java.navigation/src/org/netbeans/modules/java/navigation/BreadCrumbsNodeImpl.java b/java.navigation/src/org/netbeans/modules/java/navigation/BreadCrumbsNodeImpl.java
index 807ecfe..616c234 100644
--- a/java.navigation/src/org/netbeans/modules/java/navigation/BreadCrumbsNodeImpl.java
+++ b/java.navigation/src/org/netbeans/modules/java/navigation/BreadCrumbsNodeImpl.java
@@ -49,7 +49,7 @@ import com.sun.source.tree.VariableTree;
import com.sun.source.tree.WhileLoopTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.source.util.Trees;
import java.awt.Image;
import java.io.CharConversionException;
@@ -511,7 +511,7 @@ public class BreadCrumbsNodeImpl implements BreadcrumbsElement {
return;
}
- tp.getLeaf().accept(new TreeScanner<Void, TreePath>() {
+ tp.getLeaf().accept(new ErrorAwareTreeScanner<Void, TreePath>() {
@Override public Void scan(Tree node, TreePath p) {
if (node == null) return null;
if (node.getKind() == Kind.IF) {
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.navigation/src/org/netbeans/modules/java/navigation/ElementScanningTask.java
----------------------------------------------------------------------
diff --git a/java.navigation/src/org/netbeans/modules/java/navigation/ElementScanningTask.java b/java.navigation/src/org/netbeans/modules/java/navigation/ElementScanningTask.java
index 1ed6372..3b73e42 100644
--- a/java.navigation/src/org/netbeans/modules/java/navigation/ElementScanningTask.java
+++ b/java.navigation/src/org/netbeans/modules/java/navigation/ElementScanningTask.java
@@ -27,7 +27,7 @@ import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import com.sun.source.util.Trees;
import java.util.Collections;
import java.util.EnumSet;
@@ -211,7 +211,7 @@ public class ElementScanningTask implements CancellableTask<CompilationInfo>{
}
}
- private static class PositionVisitor extends TreePathScanner<Context, Void> {
+ private static class PositionVisitor extends ErrorAwareTreePathScanner<Context, Void> {
private final Trees trees;
private final SourcePositions sourcePositions;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.navigation/src/org/netbeans/modules/java/navigation/actions/OpenAction.java
----------------------------------------------------------------------
diff --git a/java.navigation/src/org/netbeans/modules/java/navigation/actions/OpenAction.java b/java.navigation/src/org/netbeans/modules/java/navigation/actions/OpenAction.java
index a700f1d..875ede6 100644
--- a/java.navigation/src/org/netbeans/modules/java/navigation/actions/OpenAction.java
+++ b/java.navigation/src/org/netbeans/modules/java/navigation/actions/OpenAction.java
@@ -31,7 +31,7 @@ import com.sun.source.tree.RequiresTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.UsesTree;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.awt.Toolkit;
import org.netbeans.api.java.source.ElementHandle;
import org.netbeans.api.java.source.ui.ElementOpen;
@@ -237,7 +237,7 @@ public final class OpenAction extends AbstractAction {
@Override
public void run(final CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
- new TreePathScanner<Void, Void>() {
+ new ErrorAwareTreePathScanner<Void, Void>() {
@Override
public Void visitExports(ExportsTree node, Void p) {
if (matches(handle, ModuleElement.DirectiveKind.EXPORTS, node.getPackageName())) {
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.preprocessorbridge/nbproject/project.properties
----------------------------------------------------------------------
diff --git a/java.preprocessorbridge/nbproject/project.properties b/java.preprocessorbridge/nbproject/project.properties
index 8aff049..a6f0b61 100644
--- a/java.preprocessorbridge/nbproject/project.properties
+++ b/java.preprocessorbridge/nbproject/project.properties
@@ -20,3 +20,4 @@ javac.source=1.8
spec.version.base=1.49.0
javadoc.apichanges=${basedir}/apichanges.xml
+requires.nb.javac=true
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/manifest.mf
----------------------------------------------------------------------
diff --git a/java.source.base/manifest.mf b/java.source.base/manifest.mf
index 09331a8..21b5540 100644
--- a/java.source.base/manifest.mf
+++ b/java.source.base/manifest.mf
@@ -3,3 +3,4 @@ OpenIDE-Module: org.netbeans.modules.java.source.base
OpenIDE-Module-Implementation-Version: 2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/base/Bundle.properties
OpenIDE-Module-Layer: org/netbeans/modules/java/source/base/layer.xml
+OpenIDE-Module-Requires: org.netbeans.modules.javac
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/nbproject/project.properties
----------------------------------------------------------------------
diff --git a/java.source.base/nbproject/project.properties b/java.source.base/nbproject/project.properties
index 85952e9..e83bfa0 100644
--- a/java.source.base/nbproject/project.properties
+++ b/java.source.base/nbproject/project.properties
@@ -146,6 +146,7 @@ test.config.generator.includes=\
test.config.jet-main.includes=\
${test.config.core.includes},\
${test.config.generator.includes},\
+ org/netbeans/api/java/source/TreeUtilitiesTest.class,\
org/netbeans/api/java/source/TypeUtilitiesTest.class,\
org/netbeans/api/java/source/TreePathHandleTest.class,\
org/netbeans/api/java/source/TreeMirrorHandleTest.class,\
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/nbproject/project.xml
----------------------------------------------------------------------
diff --git a/java.source.base/nbproject/project.xml b/java.source.base/nbproject/project.xml
index e21285e..dcc344b 100644
--- a/java.source.base/nbproject/project.xml
+++ b/java.source.base/nbproject/project.xml
@@ -290,6 +290,9 @@
<test-type>
<name>unit</name>
<test-dependency>
+ <code-name-base>org.netbeans.api.progress.nb</code-name-base>
+ </test-dependency>
+ <test-dependency>
<code-name-base>org.netbeans.core.startup</code-name-base>
</test-dependency>
<test-dependency>
@@ -410,18 +413,15 @@
<code-name-base>org.openide.text</code-name-base>
</test-dependency>
<test-dependency>
- <code-name-base>org.openide.util.ui</code-name-base>
+ <code-name-base>org.openide.util.lookup</code-name-base>
<compile-dependency/>
<test/>
</test-dependency>
<test-dependency>
- <code-name-base>org.openide.util.lookup</code-name-base>
+ <code-name-base>org.openide.util.ui</code-name-base>
<compile-dependency/>
<test/>
</test-dependency>
- <test-dependency>
- <code-name-base>org.netbeans.api.progress.nb</code-name-base>
- </test-dependency>
</test-type>
</test-dependencies>
<public-packages>
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/AssignComments.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/AssignComments.java b/java.source.base/src/org/netbeans/api/java/source/AssignComments.java
index ec75aef..1606b2d 100644
--- a/java.source.base/src/org/netbeans/api/java/source/AssignComments.java
+++ b/java.source.base/src/org/netbeans/api/java/source/AssignComments.java
@@ -36,7 +36,7 @@ import com.sun.source.tree.UnaryTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.tools.javac.tree.JCTree;
import java.util.Collections;
import java.util.EnumSet;
@@ -63,7 +63,7 @@ import static org.netbeans.modules.java.source.save.PositionEstimator.NOPOS;
*
* @author Pavel Flaska, Rastislav Komara, Jan Lahoda
*/
-class AssignComments extends TreeScanner<Void, Void> {
+class AssignComments extends ErrorAwareTreeScanner<Void, Void> {
private static final EnumSet<Tree.Kind> JAVADOC_KINDS = EnumSet.of(
Tree.Kind.CLASS,
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/CompilationInfo.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/CompilationInfo.java b/java.source.base/src/org/netbeans/api/java/source/CompilationInfo.java
index 8a47f53..33937b7 100644
--- a/java.source.base/src/org/netbeans/api/java/source/CompilationInfo.java
+++ b/java.source.base/src/org/netbeans/api/java/source/CompilationInfo.java
@@ -23,16 +23,19 @@ import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.DocTrees;
+import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.model.JavacElements;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement;
@@ -41,6 +44,7 @@ import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.swing.text.Document;
import javax.tools.Diagnostic;
+
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.CheckReturnValue;
import org.netbeans.api.annotations.common.NonNull;
@@ -48,6 +52,8 @@ import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.annotations.common.NullUnknown;
import org.netbeans.api.lexer.TokenHierarchy;
import org.netbeans.modules.java.preprocessorbridge.spi.WrapperFactory;
+import org.netbeans.modules.java.source.CompilationInfoAccessor;
+import org.netbeans.modules.java.source.ElementUtils;
import org.netbeans.modules.java.source.parsing.CompilationInfoImpl;
import org.netbeans.modules.java.source.parsing.DocPositionRegion;
import org.netbeans.modules.java.source.parsing.FileObjects;
@@ -222,8 +228,8 @@ public class CompilationInfo {
SourceUtils.getModuleName(impl.getRoot().toURL(), true) :
null)
.map(elements::getModuleElement)
- .map((module) -> elements.getTypeElementByBinaryName(module, name))
- .orElseGet(() -> elements.getTypeElementByBinaryName(name));
+ .map((module) -> ElementUtils.getTypeElementByBinaryName(this, module, name))
+ .orElseGet(() -> ElementUtils.getTypeElementByBinaryName(this, name));
if (e != null) {
result.add (e);
}
@@ -257,6 +263,8 @@ public class CompilationInfo {
public synchronized @NonNull Trees getTrees() {
checkConfinement();
if (trees == null) {
+ //use a working init order:
+ com.sun.tools.javac.main.JavaCompiler.instance(impl.getJavacTask().getContext());
trees = JavacTrees.instance(impl.getJavacTask().getContext());
Snapshot snapshot = impl.getSnapshot();
Document doc = snapshot != null ? snapshot.getSource().getDocument(false) : null;
@@ -283,6 +291,8 @@ public class CompilationInfo {
*/
public @NonNull Types getTypes() {
checkConfinement();
+ //use a working init order:
+ com.sun.tools.javac.main.JavaCompiler.instance(impl.getJavacTask().getContext());
return impl.getJavacTask().getTypes();
}
@@ -292,6 +302,8 @@ public class CompilationInfo {
*/
public @NonNull Elements getElements() {
checkConfinement();
+ //use a working init order:
+ com.sun.tools.javac.main.JavaCompiler.instance(impl.getJavacTask().getContext());
return impl.getJavacTask().getElements();
}
@@ -474,4 +486,13 @@ public class CompilationInfo {
/** The cached value will be cleared when a method/field/class is added, removed or its signature changes. */
ON_SIGNATURE_CHANGE;
}
+
+ static {
+ CompilationInfoAccessor.setInstance(new CompilationInfoAccessor() {
+ @Override
+ public JavacTask getJavacTask(CompilationInfo info) {
+ return info.impl.getJavacTask();
+ }
+ });
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java b/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java
index 93e1984..c15ea75 100644
--- a/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java
+++ b/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java
@@ -41,9 +41,11 @@ import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
+
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.modules.java.source.ElementHandleAccessor;
+import org.netbeans.modules.java.source.ElementUtils;
import org.netbeans.modules.java.source.usages.ClassFileUtil;
import org.openide.util.Parameters;
import org.openide.util.WeakSet;
@@ -633,10 +635,9 @@ public final class ElementHandle<T extends Element> {
return Symtab.instance(jt.getContext()).arrayClass;
}
else {
- final JavacElements elements = (JavacElements) jt.getElements();
return (TypeElement) (module != null
- ? elements.getTypeElementByBinaryName(module, signature)
- : elements.getTypeElementByBinaryName(signature));
+ ? ElementUtils.getTypeElementByBinaryName(jt, module, signature)
+ : ElementUtils.getTypeElementByBinaryName(jt, signature));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java b/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java
index a0c404b..58ee801 100644
--- a/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java
+++ b/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java
@@ -53,8 +53,8 @@ import com.sun.source.tree.VariableTree;
import com.sun.source.tree.WildcardTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.code.Flags;
@@ -89,6 +89,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
@@ -114,6 +115,8 @@ import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.swing.text.Document;
import javax.tools.JavaFileObject;
+
+import com.sun.tools.javac.parser.ParserFactory;
import org.netbeans.api.editor.document.LineDocumentUtils;
import org.netbeans.api.editor.guards.DocumentGuards;
import org.netbeans.api.java.lexer.JavaTokenId;
@@ -124,6 +127,7 @@ import org.netbeans.modules.java.source.builder.CommentHandlerService;
import org.netbeans.modules.java.source.builder.CommentSetImpl;
import org.netbeans.modules.java.source.parsing.AbstractSourceFileObject;
import org.netbeans.modules.java.source.parsing.FileObjects;
+import org.netbeans.modules.java.source.parsing.ParsingUtils;
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition;
import org.netbeans.modules.java.source.save.DiffContext;
import org.openide.filesystems.FileObject;
@@ -171,7 +175,7 @@ public final class GeneratorUtilities {
JavaFileObject sourceFile = FileObjects.templateFileObject(sourceRoot, nameComponent[0], nameComponent[1]);
FileObject template = FileUtil.getConfigFile(copy.template(kind));
FileObject targetFile = copy.doCreateFromTemplate(template, sourceFile);
- CompilationUnitTree templateCUT = copy.impl.getJavacTask().parse(FileObjects.sourceFileObject(targetFile, targetFile.getParent())).iterator().next();
+ CompilationUnitTree templateCUT = ParsingUtils.parseArbitrarySource(copy.impl.getJavacTask(), FileObjects.sourceFileObject(targetFile, targetFile.getParent()));
CompilationUnitTree importComments = GeneratorUtilities.get(copy).importComments(templateCUT, templateCUT);
CompilationUnitTree result = copy.getTreeMaker().CompilationUnit(importComments.getPackageAnnotations(),
sourceRoot,
@@ -498,7 +502,7 @@ public final class GeneratorUtilities {
* the revDependencies and dependencies can be used to determine partial order
* between existing members and the newly inserted one.
*/
- private class FieldRefVisitor extends TreePathScanner {
+ private class FieldRefVisitor extends ErrorAwareTreePathScanner {
private final ClassTree clazz;
// collects field names; serves to identify unqualified indentifiers
// which might refer to field names.
@@ -1781,7 +1785,7 @@ public final class GeneratorUtilities {
}
final Map<Tree, Tree> translate = new IdentityHashMap<Tree, Tree>();
- new TreeScanner<Void, Void>() {
+ new ErrorAwareTreeScanner<Void, Void>() {
@Override public Void visitWildcard(WildcardTree node, Void p) {
Tree bound = node.getBound();
@@ -1853,7 +1857,7 @@ public final class GeneratorUtilities {
private Map<Name, TypeElement> getUsedTypes(final CompilationUnitTree cut) {
final Trees trees = copy.getTrees();
final Map<Name, TypeElement> map = new HashMap<Name, TypeElement>();
- new TreePathScanner<Void, Void>() {
+ new ErrorAwareTreePathScanner<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
@@ -2218,7 +2222,7 @@ public final class GeneratorUtilities {
}
private static boolean containsErrors(Tree tree) {
- Boolean b = new TreeScanner<Boolean, Boolean>() {
+ Boolean b = new ErrorAwareTreeScanner<Boolean, Boolean>() {
@Override
public Boolean visitErroneous(ErroneousTree node, Boolean p) {
return true;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java b/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
index 10016b6..3bb7694 100644
--- a/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
+++ b/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
@@ -60,6 +60,7 @@ import com.sun.tools.javac.comp.Check;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
+
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.function.Predicate;
@@ -93,6 +94,7 @@ import org.netbeans.modules.classfile.ClassFile;
import org.netbeans.modules.classfile.Module;
import org.netbeans.modules.java.preprocessorbridge.spi.ImportProcessor;
import org.netbeans.modules.java.source.ElementHandleAccessor;
+import org.netbeans.modules.java.source.ElementUtils;
import org.netbeans.modules.java.source.JavadocHelper;
import org.netbeans.modules.java.source.indexing.FQN2Files;
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
@@ -206,39 +208,6 @@ public class SourceUtils {
*/
public static List<? extends Completion> getAttributeValueCompletions(CompilationInfo info, Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
List<Completion> completions = new LinkedList<>();
- if (info.getPhase().compareTo(Phase.ELEMENTS_RESOLVED) >= 0) {
- String fqn = ((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName().toString();
- Iterable<? extends Processor> processors = info.impl.getJavacTask().getProcessors();
- if (processors != null) {
- for (Processor processor : processors) {
- boolean match = false;
- for (String sat : processor.getSupportedAnnotationTypes()) {
- if ("*".equals(sat)) { //NOI18N
- match = true;
- break;
- } else if (sat.endsWith(".*")) { //NOI18N
- sat = sat.substring(0, sat.length() - 1);
- if (fqn.startsWith(sat)) {
- match = true;
- break;
- }
- } else if (fqn.equals(sat)) {
- match = true;
- break;
- }
- }
- if (match) {
- try {
- for (Completion c : processor.getCompletions(element, annotation, member, userText)) {
- completions.add(c);
- }
- } catch (Exception e) {
- Logger.getLogger(processor.getClass().getName()).log(Level.INFO, e.getMessage(), e);
- }
- }
- }
- }
- }
return completions;
}
@@ -931,7 +900,7 @@ public class SourceUtils {
public void run(CompilationController control) throws Exception {
control.toPhase(Phase.ELEMENTS_RESOLVED);
final JavacElements elms = (JavacElements)control.getElements();
- TypeElement type = elms.getTypeElementByBinaryName(qualifiedName);
+ TypeElement type = ElementUtils.getTypeElementByBinaryName(control, qualifiedName);
if (type == null) {
return;
}
@@ -1358,13 +1327,12 @@ public class SourceUtils {
null,
null,
null,
- null);
- try {
- final CompilationUnitTree cu = jt.parse(FileObjects.fileObjectFileObject(
+ Collections.singletonList(FileObjects.fileObjectFileObject(
moduleInfo,
moduleInfo.getParent(),
null,
- FileEncodingQuery.getEncoding(moduleInfo))).iterator().next();
+ FileEncodingQuery.getEncoding(moduleInfo))));
+ final CompilationUnitTree cu = jt.parse().iterator().next();
final List<? extends Tree> typeDecls = cu.getTypeDecls();
if (!typeDecls.isEmpty()) {
final Tree typeDecl = typeDecls.get(0);
@@ -1372,9 +1340,6 @@ public class SourceUtils {
return ((ModuleTree)typeDecl).getName().toString();
}
}
- } catch (IOException ioe) {
- Exceptions.printStackTrace(ioe);
- }
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/TranslateIdentifier.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/TranslateIdentifier.java b/java.source.base/src/org/netbeans/api/java/source/TranslateIdentifier.java
index 2d29fe6..9f9021f 100644
--- a/java.source.base/src/org/netbeans/api/java/source/TranslateIdentifier.java
+++ b/java.source.base/src/org/netbeans/api/java/source/TranslateIdentifier.java
@@ -27,7 +27,7 @@ import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import com.sun.tools.javac.code.Symbol;
import java.util.HashMap;
import java.util.Map;
@@ -47,7 +47,7 @@ import org.netbeans.api.annotations.common.NonNull;
*
* @author Pavel Flaska
*/
-class TranslateIdentifier extends TreePathScanner<Void, Void>{
+class TranslateIdentifier extends ErrorAwareTreePathScanner<Void, Void>{
public static <T extends Tree> T importFQNs(WorkingCopy copy, T tree) {
if (tree == null) return null;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java b/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java
index 55bc7ea..ae550cd 100644
--- a/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java
+++ b/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java
@@ -52,7 +52,7 @@ import static com.sun.source.tree.Tree.*;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
@@ -1096,7 +1096,7 @@ public final class TreeMaker {
Tree typeTree = copy.getTreeUtilities().parseType(type);
final Map<Tree, Tree> translate = new HashMap<Tree, Tree>();
- new TreeScanner<Void, Void>() {
+ new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void visitMemberSelect(MemberSelectTree node, Void p) {
translate.put(node, QualIdent(node.toString()));
@@ -3344,7 +3344,7 @@ public final class TreeMaker {
}*/
}
- private static class TreePosCleaner extends TreeScanner<Void, Void> {
+ private static class TreePosCleaner extends ErrorAwareTreeScanner<Void, Void> {
@Override
public Void scan(Tree tree, Void p) {
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java b/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java
index c2eebef..4f4be2b 100644
--- a/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java
+++ b/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java
@@ -24,7 +24,7 @@ import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.JCTree;
@@ -864,7 +864,7 @@ public final class TreePathHandle {
private static List<Tree> listChildren(@NonNull Tree t) {
final List<Tree> result = new LinkedList<Tree>();
- t.accept(new TreeScanner<Void, Void>() {
+ t.accept(new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void scan(Tree node, Void p) {
result.add(node);
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java b/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
index af36c3d..b35b14c 100644
--- a/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
+++ b/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
@@ -18,6 +18,12 @@
*/
package org.netbeans.api.java.source;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.nio.CharBuffer;
+
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.ReferenceTree;
@@ -28,8 +34,8 @@ import com.sun.source.util.DocTreePath;
import com.sun.source.util.DocTreePathScanner;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacScope;
import com.sun.tools.javac.api.JavacTrees;
@@ -45,9 +51,12 @@ import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.util.Context;
+
import java.util.*;
+import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
+
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.DeclaredType;
@@ -57,6 +66,24 @@ import javax.lang.model.type.UnionType;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+
+import com.sun.source.util.DocTrees;
+import com.sun.tools.javac.api.JavacTaskImpl;
+import com.sun.tools.javac.comp.ArgumentAttr;
+import com.sun.tools.javac.comp.Attr;
+import com.sun.tools.javac.main.JavaCompiler;
+import com.sun.tools.javac.parser.JavacParser;
+import com.sun.tools.javac.parser.Parser;
+import com.sun.tools.javac.parser.ParserFactory;
+import com.sun.tools.javac.parser.ScannerFactory;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.tree.JCTree.JCExpression;
+import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Names;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
@@ -64,6 +91,8 @@ import org.netbeans.api.java.lexer.JavaTokenId;
import org.netbeans.api.java.lexer.JavadocTokenId;
import org.netbeans.api.java.source.JavaSource.Phase;
import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.lib.nbjavac.services.CancelService;
+import org.netbeans.lib.nbjavac.services.NBParserFactory;
import org.netbeans.lib.nbjavac.services.NBResolve;
import org.netbeans.lib.nbjavac.services.NBTreeMaker.IndexedClassDecl;
import org.netbeans.modules.java.source.builder.CommentHandlerService;
@@ -71,6 +100,7 @@ import org.netbeans.modules.java.source.builder.CommentSetImpl;
import org.netbeans.modules.java.source.pretty.ImportAnalysis2;
import org.netbeans.modules.java.source.transform.ImmutableDocTreeTranslator;
import org.netbeans.modules.java.source.transform.ImmutableTreeTranslator;
+import org.openide.util.Exceptions;
/**
*
@@ -301,7 +331,7 @@ public final class TreeUtilities {
}
}
- class PathFinder extends TreePathScanner<Void,Void> {
+ class PathFinder extends ErrorAwareTreePathScanner<Void,Void> {
private int pos;
private SourcePositions sourcePositions;
@@ -345,6 +375,7 @@ public final class TreeUtilities {
return super.visitMethod(node, p);
}
+
}
try {
@@ -534,13 +565,7 @@ public final class TreeUtilities {
* @return parsed {@link TypeMirror} or null if the given specification cannot be parsed
*/
Tree parseType(String expr) {
- com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
- int oldPos = jcMaker.pos;
- try {
- return info.impl.getJavacTask().parseType(expr);
- } finally {
- jcMaker.pos = oldPos;
- }
+ return doParse(expr, null, 0, Parser::parseType);
}
/**Parses given statement.
@@ -550,16 +575,9 @@ public final class TreeUtilities {
* @return parsed {@link StatementTree} or null?
*/
public StatementTree parseStatement(String stmt, SourcePositions[] sourcePositions) {
- com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
- int oldPos = jcMaker.pos;
-
- try {
- return (StatementTree)info.impl.getJavacTask().parseStatement(stmt, sourcePositions);
- } finally {
- jcMaker.pos = oldPos;
- }
+ return doParse(stmt, sourcePositions, 0, Parser::parseStatement);
}
-
+
/**Parses given expression.
*
* @param expr expression code
@@ -567,14 +585,7 @@ public final class TreeUtilities {
* @return parsed {@link ExpressionTree} or null?
*/
public ExpressionTree parseExpression(String expr, SourcePositions[] sourcePositions) {
- com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
- int oldPos = jcMaker.pos;
-
- try {
- return (ExpressionTree) info.impl.getJavacTask().parseExpression(expr, sourcePositions);
- } finally {
- jcMaker.pos = oldPos;
- }
+ return doParse(expr, sourcePositions, 0, Parser::parseExpression);
}
/**Parses given variable initializer.
@@ -584,14 +595,7 @@ public final class TreeUtilities {
* @return parsed {@link ExpressionTree} or null?
*/
public ExpressionTree parseVariableInitializer(String init, SourcePositions[] sourcePositions) {
- com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
- int oldPos = jcMaker.pos;
-
- try {
- return (ExpressionTree)info.impl.getJavacTask().parseVariableInitializer(init, sourcePositions);
- } finally {
- jcMaker.pos = oldPos;
- }
+ return doParse(init, sourcePositions, 0, p -> ((JavacParser) p).variableInitializer());
}
/**Parses given static block.
@@ -601,15 +605,86 @@ public final class TreeUtilities {
* @return parsed {@link BlockTree} or null?
*/
public BlockTree parseStaticBlock(String block, SourcePositions[] sourcePositions) {
+ return doParse("{ class C { " + block + " }", sourcePositions, "{ class C { ".length(), p -> {
+ JCClassDecl decl = (JCClassDecl) ((BlockTree) p.parseStatement()).getStatements().get(0);
+ return decl.defs.head.getKind() == Kind.BLOCK ? (BlockTree) decl.defs.head : null; //check result
+ });
+ }
+
+ /**Parses given statement.
+ *
+ * @param text code
+ * @param sourcePositions return value - new SourcePositions for the new tree
+ * @return parsed {@link T} or null?
+ */
+ private <T extends Tree> T doParse(String text, SourcePositions[] sourcePositions, int offset, Function<Parser, T> actualParse) {
+ if (text == null || (sourcePositions != null && sourcePositions.length != 1))
+ throw new IllegalArgumentException();
+ //use a working init order:
+ com.sun.tools.javac.main.JavaCompiler.instance(info.impl.getJavacTask().getContext());
com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
int oldPos = jcMaker.pos;
try {
- return (BlockTree)info.impl.getJavacTask().parseStaticBlock(block, sourcePositions);
+ //from org/netbeans/modules/java/hints/spiimpl/Utilities.java:
+ Context context = info.impl.getJavacTask().getContext();
+ JavaCompiler compiler = JavaCompiler.instance(context);
+ JavaFileObject prev = compiler.log.useSource(new DummyJFO());
+ Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(compiler.log) {
+ @Override
+ public void report(JCDiagnostic diag) {
+ //ignore:
+ }
+ };
+ try {
+ CharBuffer buf = CharBuffer.wrap((text+"\u0000").toCharArray(), 0, text.length());
+ ParserFactory factory = ParserFactory.instance(context);
+ Parser parser = factory.newParser(buf, false, true, false, false);
+ if (parser instanceof JavacParser) {
+ if (sourcePositions != null)
+ sourcePositions[0] = new ParserSourcePositions((JavacParser)parser, offset);
+ return actualParse.apply(parser);
+ }
+ return null;
+ } finally {
+ compiler.log.useSource(prev);
+ compiler.log.popDiagnosticHandler(discardHandler);
+ }
} finally {
jcMaker.pos = oldPos;
}
}
+
+ //from org/netbeans/modules/java/hints/spiimpl/Utilities.java:
+ private static final class DummyJFO extends SimpleJavaFileObject {
+ private DummyJFO() {
+ super(URI.create("dummy.java"), JavaFileObject.Kind.SOURCE);
+ }
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ return "";
+ }
+ }
+
+ //from org/netbeans/modules/java/hints/spiimpl/Utilities.java:
+ private static class ParserSourcePositions implements SourcePositions {
+
+ private final JavacParser parser;
+ private final int offset;
+
+ private ParserSourcePositions(JavacParser parser, int offset) {
+ this.parser = parser;
+ this.offset = offset;
+ }
+
+ public long getStartPosition(CompilationUnitTree file, Tree tree) {
+ return parser.getStartPos((JCTree)tree) - offset;
+ }
+
+ public long getEndPosition(CompilationUnitTree file, Tree tree) {
+ return parser.getEndPos((JCTree)tree) - offset;
+ }
+ }
//XXX: parseAnnotationValue
@@ -687,7 +762,7 @@ public final class TreeUtilities {
NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
}
try {
- return info.impl.getJavacTask().attributeTree((JCTree) tree, ((JavacScope) scope).getEnv());
+ return attributeTree(info.impl.getJavacTask(), (JCTree) tree, scope, new ArrayList<>());
} finally {
NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
}
@@ -701,7 +776,7 @@ public final class TreeUtilities {
NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
}
try {
- return info.impl.getJavacTask().attributeTreeTo((JCTree)tree, ((JavacScope)scope).getEnv(), (JCTree)to);
+ return attributeTreeTo(info.impl.getJavacTask(), (JCTree)tree, scope, (JCTree)to, new ArrayList<>());
} finally {
NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
}
@@ -714,7 +789,7 @@ public final class TreeUtilities {
NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
}
try {
- return info.impl.getJavacTask().attributeTree((JCTree)tree, env);
+ return attributeTree(info.impl.getJavacTask(), (JCTree)tree, scope, new ArrayList<>());
} finally {
NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
}
@@ -727,12 +802,80 @@ public final class TreeUtilities {
NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
}
try {
- return info.impl.getJavacTask().attributeTreeTo((JCTree)tree, env, (JCTree)to);
+ return attributeTreeTo(info.impl.getJavacTask(), (JCTree)tree, scope, (JCTree)to, new ArrayList<>());
} finally {
NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
}
}
+ //from org/netbeans/modules/java/hints/spiimpl/Utilities.java:
+ private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, final List<Diagnostic<? extends JavaFileObject>> errors) {
+ Log log = Log.instance(jti.getContext());
+ JavaFileObject prev = log.useSource(new DummyJFO());
+ Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
+ @Override
+ public void report(JCDiagnostic diag) {
+ errors.add(diag);
+ }
+ };
+ NBResolve resolve = NBResolve.instance(jti.getContext());
+ resolve.disableAccessibilityChecks();
+// Enter enter = Enter.instance(jti.getContext());
+// enter.shadowTypeEnvs(true);
+// ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
+// ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
+ try {
+ Attr attr = Attr.instance(jti.getContext());
+ Env<AttrContext> env = ((JavacScope) scope).getEnv();
+ if (tree instanceof JCExpression)
+ return attr.attribExpr((JCTree) tree,env, Type.noType);
+ return attr.attribStat((JCTree) tree,env);
+ } finally {
+// cacheContext.leave();
+ log.useSource(prev);
+ log.popDiagnosticHandler(discardHandler);
+ resolve.restoreAccessbilityChecks();
+// enter.shadowTypeEnvs(false);
+ }
+ }
+
+ private static Scope attributeTreeTo(JavacTaskImpl jti, Tree tree, Scope scope, Tree to, final List<Diagnostic<? extends JavaFileObject>> errors) {
+ Log log = Log.instance(jti.getContext());
+ JavaFileObject prev = log.useSource(new DummyJFO());
+ Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
+ @Override
+ public void report(JCDiagnostic diag) {
+ errors.add(diag);
+ }
+ };
+ NBResolve resolve = NBResolve.instance(jti.getContext());
+ resolve.disableAccessibilityChecks();
+// Enter enter = Enter.instance(jti.getContext());
+// enter.shadowTypeEnvs(true);
+// ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
+// ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
+ try {
+ Attr attr = Attr.instance(jti.getContext());
+ Env<AttrContext> env = ((JavacScope) scope).getEnv();
+ Env<AttrContext> result = tree instanceof JCExpression ?
+ attr.attribExprToTree((JCExpression) tree, env, (JCTree) to) :
+ attr.attribStatToTree((JCTree) tree, env, (JCTree) to);
+ try {
+ Constructor<JavacScope> c = JavacScope.class.getDeclaredConstructor(Env.class);
+ c.setAccessible(true);
+ return c.newInstance(result);
+ } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
+ throw new IllegalStateException(ex);
+ }
+ } finally {
+// cacheContext.leave();
+ log.useSource(prev);
+ log.popDiagnosticHandler(discardHandler);
+ resolve.restoreAccessbilityChecks();
+// enter.shadowTypeEnvs(false);
+ }
+ }
+
/**Returns tokens for a given tree.
*/
public TokenSequence<JavaTokenId> tokensFor(Tree tree) {
@@ -764,7 +907,7 @@ public final class TreeUtilities {
/**Checks whether the given scope is in "static" context.
*/
public boolean isStaticContext(Scope scope) {
- return Resolve.instance(info.impl.getJavacTask().getContext()).isStatic(((JavacScope)scope).getEnv());
+ return NBResolve.isStatic(((JavacScope)scope).getEnv());
}
/**Returns uncaught exceptions inside the given tree path.
@@ -797,7 +940,7 @@ public final class TreeUtilities {
fields.add(ve);
}
}
- new TreePathScanner<Void, Boolean>() {
+ new ErrorAwareTreePathScanner<Void, Boolean>() {
@Override
public Void visitAssignment(AssignmentTree node, Boolean p) {
Element el = trees.getElement(new TreePath(getCurrentPath(), node.getVariable()));
@@ -1454,7 +1597,7 @@ public final class TreeUtilities {
private void copyInnerClassIndexes(Tree from, Tree to) {
final int[] fromIdx = {-3};
- TreeScanner<Void, Void> scanner = new TreeScanner<Void, Void>() {
+ ErrorAwareTreeScanner<Void, Void> scanner = new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void scan(Tree node, Void p) {
return fromIdx[0] < -1 ? super.scan(node, p) : null;
@@ -1486,7 +1629,7 @@ public final class TreeUtilities {
scanner.scan(from, null);
if (fromIdx[0] < -1)
return;
- scanner = new TreeScanner<Void, Void>() {
+ scanner = new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void visitClass(ClassTree node, Void p) {
((IndexedClassDecl)node).index = fromIdx[0]++;
@@ -1496,7 +1639,7 @@ public final class TreeUtilities {
scanner.scan(to, null);
}
- private static class UncaughtExceptionsVisitor extends TreePathScanner<Void, Set<TypeMirror>> {
+ private static class UncaughtExceptionsVisitor extends ErrorAwareTreePathScanner<Void, Set<TypeMirror>> {
private final CompilationInfo info;
@@ -1657,7 +1800,9 @@ public final class TreeUtilities {
TreePath tp = path.getTreePath();
DCReference ref = (DCReference) path.getLeaf();
- ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
+ ((DocTrees) this.info.getTrees()).getElement(path);
+// was:
+// ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
return (ExpressionTree) ref.qualifierExpression;
}
@@ -1682,19 +1827,44 @@ public final class TreeUtilities {
TreePath tp = path.getTreePath();
DCReference ref = (DCReference) path.getLeaf();
- ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
+ ((DocTrees) this.info.getTrees()).getElement(path);
+// was:
+// ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
return ref.paramTypes;
}
- private static final class NBScope extends JavacScope {
+ private static final class NBScope implements Scope {
- private NBScope(JavacScope scope) {
- super(scope.getEnv());
+ private final JavacScope delegate;
+
+ private NBScope(JavacScope delegate) {
+ this.delegate = delegate;
}
private boolean areAccessibilityChecksDisabled() {
return true;
}
+
+ @Override
+ public Scope getEnclosingScope() {
+ //TODO: wrap?
+ return delegate.getEnclosingScope();
+ }
+
+ @Override
+ public TypeElement getEnclosingClass() {
+ return delegate.getEnclosingClass();
+ }
+
+ @Override
+ public ExecutableElement getEnclosingMethod() {
+ return delegate.getEnclosingMethod();
+ }
+
+ @Override
+ public Iterable<? extends Element> getLocalElements() {
+ return delegate.getLocalElements();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java b/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
index 2bd3d1a..3e47602 100644
--- a/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
+++ b/java.source.base/src/org/netbeans/api/java/source/TypeUtilities.java
@@ -26,11 +26,14 @@ import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.model.JavacTypes;
+
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ArrayType;
@@ -42,6 +45,7 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.SimpleTypeVisitor6;
+
import org.netbeans.api.annotations.common.CheckReturnValue;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
@@ -169,7 +173,7 @@ public final class TypeUtilities {
} else if (tk == TypeKind.NONE || tk == TypeKind.OTHER) {
return types.createErrorType(inType);
}
- Type t = types.upward(inType, types.captures(inType));
+ Type t = (Type) resolveCapturedType(info, type);
if (t == null) {
return types.createErrorType(inType);
}
@@ -240,6 +244,108 @@ public final class TypeUtilities {
}
};
+ //from java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java:
+ private static TypeMirror resolveCapturedType(CompilationInfo info, TypeMirror tm) {
+ if (tm == null) {
+ return tm;
+ }
+ if (tm.getKind() == TypeKind.ERROR) {
+ tm = info.getTrees().getOriginalType((ErrorType) tm);
+ }
+ TypeMirror type = resolveCapturedTypeInt(info, tm);
+ if (type == null) {
+ return tm;
+ }
+ if (type.getKind() == TypeKind.WILDCARD) {
+ TypeMirror tmirr = ((WildcardType) type).getExtendsBound();
+ if (tmirr != null)
+ return tmirr;
+ else { //no extends, just '?'
+ TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
+ return te == null ? null : te.asType();
+ }
+
+ }
+
+ return type;
+ }
+
+ /**
+ * Note: may return {@code null}, if an intersection type is encountered, to indicate a
+ * real type cannot be created.
+ */
+ private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
+ if (tm == null) return tm;
+
+ TypeMirror orig = SourceUtils.resolveCapturedType(tm);
+
+ if (orig != null) {
+ tm = orig;
+ }
+
+ if (tm.getKind() == TypeKind.WILDCARD) {
+ TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
+ TypeMirror superBound = ((WildcardType) tm).getSuperBound();
+ if (extendsBound != null || superBound != null) {
+ TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : superBound);
+ if (rct != null) {
+ switch (rct.getKind()) {
+ case WILDCARD:
+ return rct;
+ case ARRAY:
+ case DECLARED:
+ case ERROR:
+ case TYPEVAR:
+ case OTHER:
+ return info.getTypes().getWildcardType(
+ extendsBound != null ? rct : null, superBound != null ? rct : null);
+ }
+ } else {
+ // propagate failure out of all wildcards
+ return null;
+ }
+ }
+ } else if (tm.getKind() == TypeKind.INTERSECTION) {
+ return null;
+ }
+
+ if (tm.getKind() == TypeKind.DECLARED) {
+ DeclaredType dt = (DeclaredType) tm;
+ List<TypeMirror> typeArguments = new LinkedList<TypeMirror>();
+
+ for (TypeMirror t : dt.getTypeArguments()) {
+ TypeMirror targ = resolveCapturedTypeInt(info, t);
+ if (targ == null) {
+ // bail out, if the type parameter is a wildcard, it's probably not possible
+ // to create a proper parametrized type from it
+ if (t.getKind() == TypeKind.WILDCARD || t.getKind() == TypeKind.INTERSECTION) {
+ return null;
+ }
+ // use rawtype
+ typeArguments.clear();
+ break;
+ }
+ typeArguments.add(targ);
+ }
+
+ final TypeMirror enclosingType = dt.getEnclosingType();
+ if (enclosingType.getKind() == TypeKind.DECLARED) {
+ return info.getTypes().getDeclaredType((DeclaredType) enclosingType, (TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
+ } else {
+ if (dt.asElement() == null) return dt;
+ return info.getTypes().getDeclaredType((TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
+ }
+ }
+
+ if (tm.getKind() == TypeKind.ARRAY) {
+ ArrayType at = (ArrayType) tm;
+ TypeMirror tm2 = resolveCapturedTypeInt(info, at.getComponentType());
+ return info.getTypes().getArrayType(tm2 != null ? tm2 : tm);
+ }
+
+ return tm;
+ }
+
/**Options for the {@link #getTypeName(javax.lang.model.type.TypeMirror, org.netbeans.api.java.source.TypeUtilities.TypeNameOptions[]) } method.
* @since 0.62
*/
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java b/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java
index f613b9e..5428253 100644
--- a/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java
+++ b/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java
@@ -32,8 +32,8 @@ import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
-import com.sun.source.util.TreePathScanner;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.Context;
@@ -66,9 +66,11 @@ import com.sun.source.tree.TreeVisitor;
import com.sun.source.tree.TryTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.DocTrees;
+
import java.util.Collection;
import java.util.Comparator;
+import com.sun.tools.javac.parser.ParserFactory;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.annotations.common.NullUnknown;
@@ -85,6 +87,7 @@ import org.netbeans.modules.java.source.builder.CommentSetImpl;
import org.netbeans.modules.java.source.builder.TreeFactory;
import org.netbeans.modules.java.source.parsing.CompilationInfoImpl;
import org.netbeans.modules.java.source.parsing.FileObjects;
+import org.netbeans.modules.java.source.parsing.ParsingUtils;
import org.netbeans.modules.java.source.pretty.ImportAnalysis2;
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition;
import org.netbeans.modules.java.source.save.CasualDiff;
@@ -275,7 +278,7 @@ public class WorkingCopy extends CompilationController {
return ok || introducedTrees.containsKey(t);
}
- private static class TreeCollector extends TreeScanner {
+ private static class TreeCollector extends ErrorAwareTreeScanner {
private final Map<Tree, Boolean> collectTo;
private final boolean add;
@@ -577,7 +580,7 @@ public class WorkingCopy extends CompilationController {
final Map<Tree, Boolean> presentInResult = new IdentityHashMap<Tree, Boolean>();
if (CasualDiff.OLD_TREES_VERBATIM) {
- new TreeScanner<Void, Void>() {
+ new ErrorAwareTreeScanner<Void, Void>() {
private boolean synthetic = false;
@Override
public Void scan(Tree node, Void p) {
@@ -624,7 +627,7 @@ public class WorkingCopy extends CompilationController {
}.scan(diffContext.origUnit, null);
} else {
- new TreeScanner<Void, Void>() {
+ new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void scan(Tree node, Void p) {
addSyntheticTrees(diffContext, node);
@@ -635,7 +638,7 @@ public class WorkingCopy extends CompilationController {
}
if (!REWRITE_WHOLE_FILE) {
- new TreePathScanner<Void, Void>() {
+ new ErrorAwareTreePathScanner<Void, Void>() {
private TreePath currentParent;
private final Map<Tree, TreePath> tree2Path = new IdentityHashMap<Tree, TreePath>();
private final FQNComputer fqn = new FQNComputer();
@@ -1031,7 +1034,7 @@ public class WorkingCopy extends CompilationController {
* <li>copies comments from a tree to an associated tree
* <li>
*/
- private class CommentReplicator extends TreePathScanner<Object, Object> {
+ private class CommentReplicator extends ErrorAwareTreePathScanner<Object, Object> {
private final Set<Tree> stillPresent;
private boolean collectCommentsFromRemovedNodes;
@@ -1188,7 +1191,7 @@ public class WorkingCopy extends CompilationController {
for (CompilationUnitTree t : externalChanges.values()) {
try {
FileObject targetFile = doCreateFromTemplate(t);
- CompilationUnitTree templateCUT = impl.getJavacTask().parse(FileObjects.sourceFileObject(targetFile, targetFile.getParent())).iterator().next();
+ CompilationUnitTree templateCUT = ParsingUtils.parseArbitrarySource(impl.getJavacTask(), FileObjects.sourceFileObject(targetFile, targetFile.getParent()));
CompilationUnitTree importComments = GeneratorUtilities.get(this).importComments(templateCUT, templateCUT);
rewrite(importComments, getTreeMaker().asRemoved(t));
@@ -1296,7 +1299,7 @@ public class WorkingCopy extends CompilationController {
fqn.setCompilationUnit(t);
overlay.registerPackage(fqn.getFQN());
- new TreeScanner<Void, Void>() {
+ new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void visitClass(ClassTree node, Void p) {
String parent = fqn.getFQN();
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreePathScanner.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreePathScanner.java b/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreePathScanner.java
index c519b91..d5f88d6 100644
--- a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreePathScanner.java
+++ b/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreePathScanner.java
@@ -19,14 +19,14 @@
package org.netbeans.api.java.source.support;
import com.sun.source.tree.Tree;
-import com.sun.source.util.TreePathScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import java.util.concurrent.atomic.AtomicBoolean;
/**
*
* @author Jan Lahoda
*/
-public class CancellableTreePathScanner<R,P> extends TreePathScanner<R,P> {
+public class CancellableTreePathScanner<R,P> extends ErrorAwareTreePathScanner<R,P> {
private final AtomicBoolean internalCanceled;
private final AtomicBoolean canceled;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreeScanner.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreeScanner.java b/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreeScanner.java
index e3ec87c..4c535ea 100644
--- a/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreeScanner.java
+++ b/java.source.base/src/org/netbeans/api/java/source/support/CancellableTreeScanner.java
@@ -19,14 +19,14 @@
package org.netbeans.api.java.source.support;
import com.sun.source.tree.Tree;
-import com.sun.source.util.TreeScanner;
+import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import java.util.concurrent.atomic.AtomicBoolean;
/**
*
* @author Jan Lahoda
*/
-public class CancellableTreeScanner<R,P> extends TreeScanner<R,P> {
+public class CancellableTreeScanner<R,P> extends ErrorAwareTreeScanner<R,P> {
private final AtomicBoolean internalCanceled;
private final AtomicBoolean canceled;
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java b/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java
new file mode 100644
index 0000000..a04e544
--- /dev/null
+++ b/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.api.java.source.support;
+
+import com.sun.source.tree.ErroneousTree;
+import com.sun.source.util.TreePathScanner;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public class ErrorAwareTreePathScanner<R,P> extends TreePathScanner<R,P> {
+
+ @Override
+ public R visitErroneous(ErroneousTree et, P p) {
+ return scan(et.getErrorTrees(), p);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java b/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java
new file mode 100644
index 0000000..eebbcb5
--- /dev/null
+++ b/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.api.java.source.support;
+
+import com.sun.source.tree.ErroneousTree;
+import com.sun.source.util.TreeScanner;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public class ErrorAwareTreeScanner<R,P> extends TreeScanner<R,P> {
+
+ @Override
+ public R visitErroneous(ErroneousTree et, P p) {
+ return scan(et.getErrorTrees(), p);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans/blob/ffc0de5a/java.source.base/src/org/netbeans/modules/java/source/CompilationInfoAccessor.java
----------------------------------------------------------------------
diff --git a/java.source.base/src/org/netbeans/modules/java/source/CompilationInfoAccessor.java b/java.source.base/src/org/netbeans/modules/java/source/CompilationInfoAccessor.java
new file mode 100644
index 0000000..efe5d7f
--- /dev/null
+++ b/java.source.base/src/org/netbeans/modules/java/source/CompilationInfoAccessor.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.source;
+
+import com.sun.source.util.JavacTask;
+import org.netbeans.api.java.source.CompilationInfo;
+
+/**
+ *
+ * @author lahvac
+ */
+public abstract class CompilationInfoAccessor {
+
+ private static volatile CompilationInfoAccessor INSTANCE;
+
+ public static CompilationInfoAccessor getInstance() {
+ CompilationInfoAccessor result = INSTANCE;
+
+ if (result == null) {
+ synchronized (CompilationInfoAccessor.class) {
+ if (INSTANCE == null) {
+ Class c = CompilationInfo.class;
+ try {
+ Class.forName(c.getName(), true, c.getClassLoader());
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ assert INSTANCE != null;
+ }
+
+ return INSTANCE;
+ }
+ }
+
+ return result;
+ }
+
+ public static void setInstance(CompilationInfoAccessor instance) {
+ assert instance != null;
+ INSTANCE = instance;
+ }
+
+ protected CompilationInfoAccessor() {
+ }
+
+ public abstract JavacTask getJavacTask(CompilationInfo info);
+
+}