diff --git a/.travis.yml b/.travis.yml index 01e00c40b921..297927f9e6c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -446,153 +446,6 @@ matrix: - ant $OPTS -f java/java.completion test - travis_retry ant $OPTS -f java/java.source.base test - - name: Test Java modules with nb-javac on Java 13 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 13 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -f java/java.completion test - - ant $OPTS -f java/java.source.base test - - - name: Test java.hints batch 1 with nb-javac on Java 13 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 13 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch1 -f java/java.hints test - - - name: Test java.hints batch 2 with nb-javac on Java 13 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 13 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch2 -f java/java.hints test - - - name: Test Java modules without nb-javac on Java 14 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 14 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -f java/java.completion test - - ant $OPTS -Dtest.config=vanilla-javac -f java/java.source.base test - - - name: Test refactoring.java without nb-javac on Java 14 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 14 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - travis_retry ant $OPTS -f java/refactoring.java test-unit - - - name: Test java.hints batch1 without nb-javac on Java 14 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 14 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch1-vanilla-javac -f java/java.hints test - - - name: Test java.hints batch2 without nb-javac on Java 14 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 14 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch2-vanilla-javac -f java/java.hints test - - - name: Test Java modules without nb-javac on Java 15 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -f java/java.completion test - - ant $OPTS -Dtest.config=vanilla-javac -f java/java.source.base test - - - name: Test refactoring.java without nb-javac on Java 15 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - travis_retry ant $OPTS -f java/refactoring.java test-unit - - - name: Test java.hints batch1 without nb-javac on Java 15 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch1-vanilla-javac -f java/java.hints test - - - name: Test java.hints batch2 without nb-javac on Java 15 - jdk: openjdk8 - env: - - OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=java -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" - - ant $OPTS clean - - ant $OPTS build - script: - - ant $OPTS -Dtest.config=batch2-vanilla-javac -f java/java.hints test - - - name: Test apisupport modules jdk: openjdk8 env: @@ -772,45 +625,7 @@ matrix: #- ant $TEST_OPTS -f groovy/groovy.kit test - ant $TEST_OPTS -f groovy/groovy.support test - - name: Test groovy modules on Java 14 - jdk: openjdk8 - env: - - BUILD_OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=groovy -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - - TEST_OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -Dcluster.config=groovy -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - ant $BUILD_OPTS clean - - ant $BUILD_OPTS build - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 14 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" - script: - #- ant $TEST_OPTS -f groovy/groovy test - #- ant $TEST_OPTS -f groovy/groovy.java test - - ant $TEST_OPTS -f groovy/groovy.editor test - - ant $TEST_OPTS -f groovy/groovy.gsp test - #- ant $TEST_OPTS -f groovy/groovy.kit test - - ant $TEST_OPTS -f groovy/groovy.support test - - - name: Test groovy modules on Java 15 - jdk: openjdk8 - env: - - BUILD_OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=groovy -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - - TEST_OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -Dcluster.config=groovy -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" - before_script: - - ant $BUILD_OPTS clean - - ant $BUILD_OPTS build - - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" - script: - #- ant $TEST_OPTS -f groovy/groovy test - #- ant $TEST_OPTS -f groovy/groovy.java test - - ant $TEST_OPTS -f groovy/groovy.editor test - - ant $TEST_OPTS -f groovy/groovy.gsp test - #- ant $TEST_OPTS -f groovy/groovy.kit test - - ant $TEST_OPTS -f groovy/groovy.support test - - - name: Test groovy modules on Java 16 + - name: Test groovy modules on Java 17 jdk: openjdk8 env: - BUILD_OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json -quiet -Dcluster.config=groovy -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true" @@ -819,7 +634,7 @@ matrix: - ant $BUILD_OPTS clean - ant $BUILD_OPTS build - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - - export TEST_JDK=`bash install-jdk.sh --feature 16 --license GPL --emit-java-home --silent | tail -1` + - export TEST_JDK=`bash install-jdk.sh --feature 17 --license GPL --emit-java-home --silent | tail -1` - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true" script: #- ant $TEST_OPTS -f groovy/groovy test @@ -882,7 +697,7 @@ matrix: - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - export TEST_JDK=`bash install-jdk.sh --feature 11 --license GPL --emit-java-home --silent | tail -1` - export JAVA_HOME=$TEST_JDK - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dnbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" + - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dnbjdk.home=$TEST_JDK" - ant $OPTS clean - ant $OPTS build - ant $OPTS test -Dtest.includes=NoTestsJustBuild @@ -896,7 +711,7 @@ matrix: before_script: - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh - export TEST_JDK=`bash install-jdk.sh --feature 15 --license GPL --emit-java-home --silent | tail -1` - - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK -Dtest.use.jdk.javac=true" + - export OPTS="-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json $OPTS -Dtest.nbjdk.home=$TEST_JDK" - ant $OPTS clean - ant $OPTS build script: diff --git a/ergonomics/ide.ergonomics/nbproject/project.properties b/ergonomics/ide.ergonomics/nbproject/project.properties index cf4591f5915b..6db1399f6557 100644 --- a/ergonomics/ide.ergonomics/nbproject/project.properties +++ b/ergonomics/ide.ergonomics/nbproject/project.properties @@ -23,9 +23,6 @@ release.dir=${basedir}/build/release src-ant.build=build/classes/ src-ant.cp=${ant.core.lib} -requires.nb.javac=true -requires.nb.javac.impl=true - test.config.commit.includes=\ org/netbeans/modules/ide/ergonomics/DynamicVerifyTest.class,\ org/netbeans/modules/ide/ergonomics/CachingPreventsLoadingOfModuleManifestsTest.class,\ diff --git a/java/java.completion/manifest.mf b/java/java.completion/manifest.mf index 41e664c20324..4742b4af3c69 100644 --- a/java/java.completion/manifest.mf +++ b/java/java.completion/manifest.mf @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.completion OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/completion/Bundle.properties -OpenIDE-Module-Implementation-Version: 1 +OpenIDE-Module-Implementation-Version: 2 diff --git a/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig b/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig index f88f97230264..e68ff021b411 100644 --- a/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig +++ b/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig @@ -138,50 +138,6 @@ meth public void run(org.netbeans.modules.parsing.api.ResultIterator) throws jav supr org.netbeans.modules.parsing.api.UserTask hfds INIT,SUPER_KEYWORD,THIS_KEYWORD,anchorOffset,toolTipData,toolTipIndex,toolTipOffset -CLSS public org.netbeans.modules.java.completion.TreeShims -cons public init() -fld public final static int PATTERN_MATCHING_INSTANCEOF_PREVIEW_JDK_VERSION = 15 -fld public final static java.lang.String BINDING_PATTERN = "BINDING_PATTERN" -fld public final static java.lang.String BINDING_VARIABLE = "BINDING_VARIABLE" -fld public final static java.lang.String DEFAULT_CASE_LABEL = "DEFAULT_CASE_LABEL" -fld public final static java.lang.String GUARDED_PATTERN = "GUARDED_PATTERN" -fld public final static java.lang.String NULL_LITERAL = "NULL_LITERAL" -fld public final static java.lang.String PARENTHESIZED_PATTERN = "PARENTHESIZED_PATTERN" -fld public final static java.lang.String RECORD = "RECORD" -fld public final static java.lang.String SWITCH_EXPRESSION = "SWITCH_EXPRESSION" -fld public final static java.lang.String YIELD = "YIELD" -meth public static <%0 extends com.sun.source.tree.Tree> boolean isRecord({%%0}) -meth public static <%0 extends java.lang.Throwable> java.lang.RuntimeException throwAny(java.lang.Throwable) throws {%%0} -meth public static boolean isJDKVersionRelease16_Or_Above() -meth public static boolean isJDKVersionRelease17_Or_Above() -meth public static boolean isJDKVersionSupportEnablePreview() -meth public static boolean isRecord(javax.lang.model.element.Element) -meth public static boolean isRecordComponent(javax.lang.model.element.Element) -meth public static boolean isRecordComponent(javax.lang.model.element.ElementKind) -meth public static boolean isRuleCase(com.sun.source.tree.CaseTree) -meth public static com.sun.source.doctree.ReferenceTree getRefrenceTree(com.sun.tools.javac.tree.DocTreeMaker,com.sun.source.tree.ExpressionTree,java.lang.CharSequence,java.util.List,com.sun.tools.javac.util.Names,java.util.List) -meth public static com.sun.source.tree.ExpressionTree getGuardedExpression(com.sun.source.tree.Tree) -meth public static com.sun.source.tree.ExpressionTree getValue(com.sun.source.tree.BreakTree) -meth public static com.sun.source.tree.ExpressionTree getYieldValue(com.sun.source.tree.Tree) -meth public static com.sun.source.tree.ModuleTree getModule(com.sun.source.tree.CompilationUnitTree) -meth public static com.sun.source.tree.Tree SwitchExpression(com.sun.tools.javac.tree.TreeMaker,com.sun.source.tree.ExpressionTree,java.util.List) -meth public static com.sun.source.tree.Tree getBindingPatternType(com.sun.source.tree.Tree) -meth public static com.sun.source.tree.Tree getBody(com.sun.source.tree.CaseTree) -meth public static com.sun.source.tree.Tree getGuardedPattern(com.sun.source.tree.Tree) -meth public static com.sun.source.tree.Tree getParenthesizedPattern(com.sun.source.tree.Tree) -meth public static com.sun.source.tree.Tree getPattern(com.sun.source.tree.InstanceOfTree) -meth public static com.sun.source.tree.Tree getTarget(com.sun.source.tree.Tree) -meth public static java.util.List getCases(com.sun.source.tree.Tree) -meth public static java.util.List getExpressions(com.sun.source.tree.CaseTree) -meth public static java.util.List getExpressions(com.sun.source.tree.Tree) -meth public static java.util.List getLabels(com.sun.source.tree.CaseTree) -meth public static java.util.List getPermits(com.sun.source.tree.ClassTree) -meth public static java.util.List getPermits(com.sun.tools.javac.tree.JCTree$JCClassDecl) -meth public static javax.lang.model.element.Element toRecordComponent(javax.lang.model.element.Element) -meth public static javax.lang.model.element.ElementKind getRecordKind() -meth public static javax.lang.model.element.Name getBinding(com.sun.source.tree.Tree) -supr java.lang.Object - CLSS public final org.netbeans.modules.java.completion.Utilities meth public static boolean isCaseSensitive() meth public static boolean isExcludeMethods() diff --git a/java/java.completion/nbproject/project.properties b/java/java.completion/nbproject/project.properties index 62836c82a185..3686ce8fb6d4 100644 --- a/java/java.completion/nbproject/project.properties +++ b/java/java.completion/nbproject/project.properties @@ -17,7 +17,7 @@ is.autoload=true javac.source=1.8 javac.compilerargs=-Xlint -Xlint:-serial -spec.version.base=1.23.0 +spec.version.base=2.0.0 #test configs test.config.jet-main.includes=\ diff --git a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java index 62bc4ea363aa..ff065beb53f2 100644 --- a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java +++ b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java @@ -518,15 +518,15 @@ protected void resolve(CompilationController controller) throws IOException { case STRING_LITERAL: insideStringLiteral(env); break; - default: - if (path.getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { - insideSwitch(env); - } else if (TreeShims.isRecord(path.getLeaf())) { - insideRecord(env); - } else if (path.getLeaf().getKind().toString().equals("DEFAULT_CASE_LABEL")) { - localResult(env); - addKeywordsForBlock(env); - } + case SWITCH_EXPRESSION: + insideSwitch(env); + break; + case RECORD: + insideRecord(env); + break; + case DEFAULT_CASE_LABEL: + localResult(env); + addKeywordsForBlock(env); break; } } @@ -750,7 +750,7 @@ private void insideImport(Env env) throws IOException { if (options.contains(Options.ALL_COMPLETION) || options.contains(Options.COMBINED_COMPLETION)) { EnumSet classKinds = EnumSet.of(CLASS, INTERFACE, ENUM, ANNOTATION_TYPE); if (isRecordSupported(env)) { - classKinds.add(TreeShims.getRecordKind()); + classKinds.add(RECORD); } addTypes(env, classKinds, null); } else { @@ -781,7 +781,7 @@ private void insideClass(Env env) throws IOException { } TreeUtilities tu = controller.getTreeUtilities(); Tree lastPerm = null; - List permits = TreeShims.getPermits(cls); + List permits = cls.getPermitsClause(); permits = permits == null ? new ArrayList<>() : permits; for (Tree perm : permits) { int permPos = (int) sourcePositions.getEndPosition(root, perm); @@ -1588,7 +1588,7 @@ private void insideBlock(Env env) throws IOException { if (SOURCE_VERSION_RELEASE_13 != null && env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_13) >= 0 && Utilities.startsWith(YIELD_KEYWORD, prefix)) { TreePath parentPath = env.getPath().getParentPath(); - if (parentPath.getLeaf().getKind() == Tree.Kind.CASE && parentPath.getParentPath().getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { + if (parentPath.getLeaf().getKind() == Tree.Kind.CASE && parentPath.getParentPath().getLeaf().getKind() == Kind.SWITCH_EXPRESSION) { addKeyword(env, YIELD_KEYWORD, null, false); } } @@ -2133,7 +2133,7 @@ private void insideNewClass(Env env) throws IOException { if (encl == null) { EnumSet classKinds = EnumSet.of(CLASS, INTERFACE, ENUM, ANNOTATION_TYPE); if (isRecordSupported(env)) { - classKinds.add(TreeShims.getRecordKind()); + classKinds.add(RECORD); } addTypes(env, classKinds, base); } else { @@ -2385,16 +2385,15 @@ private void insideSwitch(Env env) throws IOException { exprTree = ((SwitchTree) path.getLeaf()).getExpression(); } else { - List exprTrees = TreeShims.getExpressions(path.getLeaf()); - if (!exprTrees.isEmpty()) { - exprTree = exprTrees.get(0); - } + exprTree = ((SwitchExpressionTree) path.getLeaf()).getExpression(); } SourcePositions sourcePositions = env.getSourcePositions(); CompilationUnitTree root = env.getRoot(); if (sourcePositions.getStartPosition(root, exprTree) < offset) { CaseTree lastCase = null; - for (CaseTree t : TreeShims.getCases(path.getLeaf())) { + List cases = path.getLeaf().getKind() == Kind.SWITCH ? ((SwitchTree) path.getLeaf()).getCases() + : ((SwitchExpressionTree) path.getLeaf()).getCases(); + for (CaseTree t : cases) { int pos = (int) sourcePositions.getStartPosition(root, t); if (pos == Diagnostic.NOPOS || offset <= pos) { break; @@ -2405,7 +2404,7 @@ private void insideSwitch(Env env) throws IOException { StatementTree last = null; List statements = lastCase.getStatements(); if (statements == null) { - Tree caseBody = TreeShims.getBody(lastCase); + Tree caseBody = lastCase.getBody(); if (caseBody instanceof StatementTree) { statements = Collections.singletonList((StatementTree) caseBody); } @@ -2435,8 +2434,8 @@ private void insideSwitch(Env env) throws IOException { localResult(env); addKeywordsForBlock(env); String prefix = env.getPrefix(); - if (SOURCE_VERSION_RELEASE_13 != null && (env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_13) >= 0 - && path.getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION) && Utilities.startsWith(YIELD_KEYWORD, prefix))) { + if (env.getController().getSourceVersion().compareTo(SourceVersion.RELEASE_13) >= 0 + && path.getLeaf().getKind() == Kind.SWITCH_EXPRESSION && Utilities.startsWith(YIELD_KEYWORD, prefix)) { addKeyword(env, YIELD_KEYWORD, null, false); } @@ -2460,7 +2459,7 @@ private void insideCase(Env env) throws IOException { TreePath parentPath = path.getParentPath(); ExpressionTree caseExpressionTree = null; ExpressionTree caseErroneousTree = null; - List caseTreeList = TreeShims.getExpressions(cst); + List caseTreeList = cst.getExpressions(); if (!caseTreeList.isEmpty() && caseTreeList.size() == 1) { caseExpressionTree = caseTreeList.get(0); caseErroneousTree = caseTreeList.get(0); @@ -2477,15 +2476,12 @@ private void insideCase(Env env) throws IOException { if (caseExpressionTree != null && ((sourcePositions.getStartPosition(root, caseExpressionTree) >= offset) || (caseErroneousTree != null && caseErroneousTree.getKind() == Tree.Kind.ERRONEOUS && ((ErroneousTree) caseErroneousTree).getErrorTrees().isEmpty() && sourcePositions.getEndPosition(root, caseErroneousTree) >= offset))) { - if (parentPath.getLeaf().getKind() == Tree.Kind.SWITCH || parentPath.getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { + if (parentPath.getLeaf().getKind() == Tree.Kind.SWITCH || parentPath.getLeaf().getKind() == Kind.SWITCH_EXPRESSION) { ExpressionTree exprTree = null; if (parentPath.getLeaf().getKind() == Tree.Kind.SWITCH) { exprTree = ((SwitchTree) parentPath.getLeaf()).getExpression(); } else { - List exprTrees = TreeShims.getExpressions(parentPath.getLeaf()); - if (!exprTrees.isEmpty()) { - exprTree = exprTrees.get(0); - } + exprTree = ((SwitchExpressionTree) parentPath.getLeaf()).getExpression(); } TypeMirror tm = controller.getTrees().getTypeMirror(new TreePath(parentPath, exprTree)); if (tm.getKind() == TypeKind.DECLARED && ((DeclaredType) tm).asElement().getKind() == ENUM) { @@ -3098,16 +3094,16 @@ private void insideBreakOrContinue(Env env) throws IOException { private void addClassTypes(final Env env, DeclaredType baseType) throws IOException{ EnumSet classKinds = EnumSet.of(CLASS, INTERFACE, ENUM, ANNOTATION_TYPE, TYPE_PARAMETER); if (isRecordSupported(env)) { - classKinds.add(TreeShims.getRecordKind()); + classKinds.add(RECORD); } addTypes(env, classKinds, baseType); } private boolean isRecordSupported(final Env env) { - return (SOURCE_VERSION_RELEASE_14 != null && env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_14) >= 0); + return env.getController().getSourceVersion().compareTo(SourceVersion.RELEASE_14) >= 0; } private boolean isSealedSupported(final Env env) { - return (SOURCE_VERSION_RELEASE_15 != null && env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_15) >= 0); + return env.getController().getSourceVersion().compareTo(SourceVersion.RELEASE_15) >= 0; } private void insideRecord(Env env) throws IOException { @@ -4039,13 +4035,13 @@ private void addEnumConstants(Env env, TypeElement elem) { if (path != null && path.getLeaf().getKind() == Tree.Kind.SWITCH) { SwitchTree st = (SwitchTree) path.getLeaf(); caseTrees = st.getCases(); - } else if (path != null && path.getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { - caseTrees = TreeShims.getCases(path.getLeaf()); + } else if (path != null && path.getLeaf().getKind() == Tree.Kind.SWITCH_EXPRESSION) { + caseTrees = ((SwitchExpressionTree) path.getLeaf()).getCases(); } if (caseTrees != null) { for (CaseTree ct : caseTrees) { - for (ExpressionTree et : TreeShims.getExpressions(ct)) { + for (ExpressionTree et : ct.getExpressions()) { Element e = et != null ? trees.getElement(new TreePath(path, et)) : null; if (e != null && e.getKind() == ENUM_CONSTANT) { alreadyUsed.add(e); @@ -4066,7 +4062,7 @@ private void addEnumConstants(Env env, TypeElement elem) { private void addPackageContent(final Env env, PackageElement pe, EnumSet kinds, DeclaredType baseType, boolean insideNew, boolean srcOnly) throws IOException { if (isRecordSupported(env)) { - kinds.add(TreeShims.getRecordKind()); + kinds.add(RECORD); } Set smartTypes = options.contains(Options.ALL_COMPLETION) ? null : getSmartTypes(env); CompilationController controller = env.getController(); @@ -6365,9 +6361,9 @@ private boolean isLambdaVarType(Env env, Tree tree) { } private static ElementKind simplifyElementKind(ElementKind kind) { - if (TreeShims.BINDING_VARIABLE.equals(kind.name())) { + if (ElementKind.BINDING_VARIABLE == kind) { return ElementKind.LOCAL_VARIABLE; - } else if (TreeShims.RECORD.equals(kind.name())) { + } else if (ElementKind.RECORD == kind) { return ElementKind.CLASS; } return kind; diff --git a/java/java.completion/src/org/netbeans/modules/java/completion/JavaDocumentationTask.java b/java/java.completion/src/org/netbeans/modules/java/completion/JavaDocumentationTask.java index 06c933656dae..fc8228c13444 100644 --- a/java/java.completion/src/org/netbeans/modules/java/completion/JavaDocumentationTask.java +++ b/java/java.completion/src/org/netbeans/modules/java/completion/JavaDocumentationTask.java @@ -77,13 +77,14 @@ protected void resolve(CompilationController controller) throws IOException { } } if (!controller.getElementUtilities().isErroneous(el)) { - switch (simplifyElementKind(el.getKind())) { + switch (el.getKind()) { case MODULE: case PACKAGE: case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: + case RECORD: case CONSTRUCTOR: case ENUM_CONSTANT: case FIELD: @@ -106,10 +107,4 @@ private TreePath refinePath(final TreePath path) { return path; } - private static ElementKind simplifyElementKind(ElementKind kind) { - if (TreeShims.RECORD.equals(kind.name())) { - return ElementKind.CLASS; - } - return kind; - } } diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java index bc751173cc91..73247b09bdc4 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java @@ -214,14 +214,12 @@ public CI createVariableItem(CompilationInfo info, VariableElement elem, TypeMir String varName = elem.getSimpleName().toString(); String typeName = type != null ? info.getTypeUtilities().getTypeName(type).toString() : null; ElementKind ek = elem.getKind(); - if (TreeShims.BINDING_VARIABLE.equals(ek.name())) { - ek = ElementKind.LOCAL_VARIABLE; - } switch (ek) { case LOCAL_VARIABLE: case RESOURCE_VARIABLE: case PARAMETER: case EXCEPTION_PARAMETER: + case BINDING_VARIABLE: return new CI((typeName != null ? typeName + " " : "") + varName, smartType ? 200 - SMART_TYPE : 200, varName); case ENUM_CONSTANT: case FIELD: diff --git a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java index bc7c07883989..456e73ce55ba 100644 --- a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java +++ b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java @@ -242,18 +242,7 @@ private static Coloring collection2Coloring(Collection attr) private static final Set LOCAL_VARIABLES = EnumSet.of( ElementKind.LOCAL_VARIABLE, ElementKind.RESOURCE_VARIABLE, - ElementKind.EXCEPTION_PARAMETER); - private static final ElementKind BINDING_VARIABLE; - - static { - ElementKind bindingVariable; - try { - LOCAL_VARIABLES.add(bindingVariable = ElementKind.valueOf(TreeShims.BINDING_VARIABLE)); - } catch (IllegalArgumentException ex) { - bindingVariable = null; - } - BINDING_VARIABLE = bindingVariable; - } + ElementKind.EXCEPTION_PARAMETER, ElementKind.BINDING_VARIABLE); private static boolean isLocalVariableClosure(Element el) { return el.getKind() == ElementKind.PARAMETER || @@ -411,7 +400,7 @@ private Collection getVariableColoring(Element decl) { addModifiers(decl, c); - if (decl.getKind().isField() || TreeShims.isRecordComponent(decl.getKind())) { + if (decl.getKind().isField() || decl.getKind() == ElementKind.RECORD_COMPONENT) { if (decl.getKind().isField()) { c.add(ColoringAttributes.FIELD); } else { @@ -488,7 +477,7 @@ private void handlePossibleIdentifier(TreePath expr, boolean declaration, Elemen isDeclType = decl.getKind().isClass() || decl.getKind().isInterface(); Collection c = null; - if (decl.getKind().isField() || isLocalVariableClosure(decl) || TreeShims.isRecordComponent(decl.getKind())) { + if (decl.getKind().isField() || isLocalVariableClosure(decl) || decl.getKind() == ElementKind.RECORD_COMPONENT) { c = getVariableColoring(decl); } @@ -922,7 +911,7 @@ record = true; scan(tree.getExtendsClause(), null); scan(tree.getImplementsClause(), null); try { - List permitList = TreeShims.getPermits(tree); + List permitList = tree.getPermitsClause(); if (permitList != null && !permitList.isEmpty()) { tl.moveNext(); Token t = firstIdentifierToken("permits");// NOI18N @@ -953,7 +942,7 @@ record = true; private boolean isRecordComponent(Tree member) { Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), member)); - return el != null && TreeShims.isRecordComponent(Utilities.toRecordComponent(el).getKind()); + return el != null && Utilities.toRecordComponent(el).getKind() == ElementKind.RECORD_COMPONENT; } @Override diff --git a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java index a458ba57536f..2353391d8142 100644 --- a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java +++ b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java @@ -241,18 +241,7 @@ private static boolean isSerializationMethod(CompilationInfo info, ExecutableEle private static final Set LOCAL_VARIABLES = EnumSet.of( ElementKind.LOCAL_VARIABLE, ElementKind.RESOURCE_VARIABLE, - ElementKind.EXCEPTION_PARAMETER); - private static final ElementKind BINDING_VARIABLE; - - static { - ElementKind bindingVariable; - try { - LOCAL_VARIABLES.add(bindingVariable = ElementKind.valueOf(TreeShims.BINDING_VARIABLE)); - } catch (IllegalArgumentException ex) { - bindingVariable = null; - } - BINDING_VARIABLE = bindingVariable; - } + ElementKind.EXCEPTION_PARAMETER, ElementKind.BINDING_VARIABLE); private static boolean isLocalVariableClosure(Element el) { return el.getKind() == ElementKind.PARAMETER || @@ -398,14 +387,6 @@ public Void visitMethod(MethodTree node, Void p) { } } - @Override - public Void scan(Tree tree, Void p) { - if (tree != null && TreeShims.BINDING_PATTERN.equals(tree.getKind().name())) { - handleDeclaration(new TreePath(getCurrentPath(), tree)); - } - return super.scan(tree, p); - } - private void handleDeclaration(TreePath path) { Element el = info.getTrees().getElement(path); @@ -437,7 +418,7 @@ private void handleDeclaration(TreePath path) { //it makes sense to no use it: addUse(el, UseTypes.READ); addUse(el, UseTypes.WRITTEN); - } else if (el.getKind() == BINDING_VARIABLE) { + } else if (el.getKind() == ElementKind.BINDING_VARIABLE) { addUse(el, UseTypes.WRITTEN); } else if (el.getKind() == ElementKind.LOCAL_VARIABLE) { Tree parent = path.getParentPath().getLeaf(); @@ -445,7 +426,7 @@ private void handleDeclaration(TreePath path) { ((EnhancedForLoopTree) parent).getVariable() == path.getLeaf()) { addUse(el, UseTypes.WRITTEN); } - } else if (TreeShims.isRecordComponent(Utilities.toRecordComponent(el).getKind())) { + } else if (Utilities.toRecordComponent(el).getKind() == ElementKind.RECORD_COMPONENT) { addUse(el, UseTypes.READ); addUse(el, UseTypes.WRITTEN); } else if (el.getKind().isField()) { diff --git a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/Utilities.java b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/Utilities.java index 74d6529a7a8d..f04f7b8fa6a3 100644 --- a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/Utilities.java +++ b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/Utilities.java @@ -244,37 +244,6 @@ private static Token findIdentifierSpanImpl(CompilationInfo info, I return null; } - private static Token findIdentifierSpanImplForBindingPattern(CompilationInfo info, Tree tree, CompilationUnitTree cu, SourcePositions positions) { - int start = (int)positions.getStartPosition(cu, tree); - int endPosition = (int)positions.getEndPosition(cu, tree); - - if (start == (-1) || endPosition == (-1)) - return null; - - String member = TreeShims.getBinding(tree).toString(); - - TokenHierarchy th = info.getTokenHierarchy(); - TokenSequence ts = th.tokenSequence(JavaTokenId.language()); - - if (ts.move(endPosition) == Integer.MAX_VALUE) { - return null; - } - - if (ts.moveNext()) { - while (ts.offset() >= start) { - Token t = ts.token(); - - if (t.id() == JavaTokenId.IDENTIFIER && member.equals(info.getTreeUtilities().decodeIdentifier(t.text()).toString())) { - return t; - } - - if (!ts.movePrevious()) - break; - } - } - return null; - } - private static final Map> class2Kind; static { @@ -408,31 +377,6 @@ private static Token findIdentifierSpanImpl(CompilationInfo info, T return findTokenWithText(info, name.toString(), start, end); } - if (class2Kind.get(InstanceOfTree.class).contains(leaf.getKind())) { - Tree pattern = TreeShims.getPattern((InstanceOfTree) leaf); - - if (pattern == null || !"BINDING_PATTERN".equals(pattern.getKind().name())) - return null; - - Name name = TreeShims.getBinding(pattern); - - if (name == null || name.length() == 0) - return null; - - SourcePositions positions = info.getTrees().getSourcePositions(); - CompilationUnitTree cu = info.getCompilationUnit(); - int start = (int)positions.getEndPosition(cu, ((InstanceOfTree) leaf).getType()); - int end = (int)positions.getEndPosition(cu, pattern); - - if (start == (-1) || end == (-1)) { - return null; - } - - return findTokenWithText(info, name.toString(), start, end); - } - if ("BINDING_PATTERN".equals(leaf.getKind().name())) { - return findIdentifierSpanImplForBindingPattern(info, leaf, info.getCompilationUnit(), info.getTrees().getSourcePositions()); - } throw new IllegalArgumentException("Only MethodDecl, VariableDecl, MemberSelectTree, IdentifierTree, ParameterizedTypeTree, AnnotatedTypeTree, ClassDecl, BreakTree, ContinueTree, LabeledStatementTree and BindingPatternTree are accepted by this method. Got: " + leaf.getKind()); } @@ -716,14 +660,8 @@ public static boolean isNonCtorKeyword(Tree tree) { return false; } - private static final Set LOCAL_ELEMENT_KINDS = EnumSet.of(ElementKind.PARAMETER, ElementKind.LOCAL_VARIABLE, ElementKind.EXCEPTION_PARAMETER, ElementKind.RESOURCE_VARIABLE); + private static final Set LOCAL_ELEMENT_KINDS = EnumSet.of(ElementKind.PARAMETER, ElementKind.LOCAL_VARIABLE, ElementKind.EXCEPTION_PARAMETER, ElementKind.RESOURCE_VARIABLE, ElementKind.BINDING_VARIABLE); - static { - try { - LOCAL_ELEMENT_KINDS.add(ElementKind.valueOf(TreeShims.BINDING_VARIABLE)); - } catch (IllegalArgumentException ignore) {} - } - public static boolean isPrivateElement(Element el) { return LOCAL_ELEMENT_KINDS.contains(el.getKind()) || el.getModifiers().contains(Modifier.PRIVATE); } @@ -737,7 +675,7 @@ public static Element toRecordComponent(Element el) { return el; } for (Element encl : owner.getEnclosedElements()) { - if (TreeShims.isRecordComponent(encl.getKind()) && + if (encl.getKind() == ElementKind.RECORD_COMPONENT && encl.getSimpleName().equals(el.getSimpleName())) { return encl; } diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java b/java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java index 4e081ddf6061..26c9ffdc1c7e 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java @@ -67,6 +67,7 @@ import javax.lang.model.element.ModuleElement; import javax.lang.model.element.Name; import javax.lang.model.element.PackageElement; +import javax.lang.model.element.RecordComponentElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; @@ -785,8 +786,9 @@ private static boolean isCaretInsideDeclarationName(CompilationInfo info, Tree t try { switch (t.getKind()) { case INSTANCE_OF: - Tree pattern = TreeShims.getPattern((InstanceOfTree) t); - if (pattern == null || !"BINDING_PATTERN".equals(pattern.getKind().name())) { + //XXX: why the following? + Tree pattern = ((InstanceOfTree) t).getPattern(); + if (pattern == null || pattern.getKind() != Kind.BINDING_PATTERN) { return false; } case ANNOTATION_TYPE: @@ -1040,7 +1042,7 @@ public Void visitVariable(VariableElement e, Boolean highlightName) { if (e.getKind() != ElementKind.PARAMETER && e.getKind() != ElementKind.LOCAL_VARIABLE && e.getKind() != ElementKind.RESOURCE_VARIABLE && e.getKind() != ElementKind.EXCEPTION_PARAMETER - && !TreeShims.BINDING_VARIABLE.equals(e.getKind().name())) { + && e.getKind() != ElementKind.BINDING_VARIABLE) { result.append(" in "); //short typename: @@ -1101,13 +1103,10 @@ Void printExecutable(ExecutableElement e, DeclaredType dt, Boolean highlightName public Void visitTypeParameter(TypeParameterElement e, Boolean highlightName) { return null; } - + @Override - public Void visitUnknown(Element e, Boolean p) { - if (TreeShims.isRecordComponent(e)) { - return visitVariable((VariableElement) e, p); - } - return super.visitUnknown(e, p); + public Void visitRecordComponent(RecordComponentElement e, Boolean p) { + return visitVariable((VariableElement) e, p); } private void modifier(Set modifiers) { diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java index ef0a4414afd9..10dde3cf119a 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java @@ -119,10 +119,10 @@ public static JavaCompletionItem createTypeItem(CompilationInfo info, TypeElemen return new EnumItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList); case ANNOTATION_TYPE: return new AnnotationTypeItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList); + case RECORD: + return new RecordItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList); default: - if(elem.getKind().name().equals(TreeShims.RECORD)) - return new RecordItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList); - else throw new IllegalArgumentException("kind=" + elem.getKind()); + throw new IllegalArgumentException("kind=" + elem.getKind()); } } diff --git a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/GoToSupportTest.java b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/GoToSupportTest.java index b14a8d5b3e6a..6424a9415cd3 100644 --- a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/GoToSupportTest.java +++ b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/GoToSupportTest.java @@ -48,7 +48,6 @@ import org.netbeans.api.lexer.Language; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.editor.java.GoToSupport.UiUtilsCaller; -import org.netbeans.modules.java.source.TreeShims; //import org.netbeans.modules.java.source.TreeLoader; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; @@ -1480,7 +1479,7 @@ public void run(CompilationController parameter) throws Exception { parameter.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Element e = el.resolve(parameter); - assertTrue(TreeShims.isRecord(e)); + assertTrue(e.getKind() == ElementKind.RECORD); assertEquals("test.Auxiliary", ((TypeElement) e).getQualifiedName().toString()); wasCalled[0] = true; } diff --git a/java/java.editor/test/unit/src/org/netbeans/modules/java/editor/codegen/ToStringGeneratorTest.java b/java/java.editor/test/unit/src/org/netbeans/modules/java/editor/codegen/ToStringGeneratorTest.java index f4b8945366a8..fc5db31cd49a 100644 --- a/java/java.editor/test/unit/src/org/netbeans/modules/java/editor/codegen/ToStringGeneratorTest.java +++ b/java/java.editor/test/unit/src/org/netbeans/modules/java/editor/codegen/ToStringGeneratorTest.java @@ -210,7 +210,8 @@ public void post() throws Exception { + " @Override\n" + " public String toString() {\n" + " StringBuilder sb = new StringBuilder();\n" - + " sb.append(\"NewClass{test1=\").append(test1);\n" + + " sb.append(\"NewClass{\");\n" + + " sb.append(\"test1=\").append(test1);\n" + " sb.append(\", test2=\").append(test2);\n" + " sb.append(\", test3=\").append(test3);\n" + " sb.append('}');\n" diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java index d8bec2557bb2..e2e3392d3c3a 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java @@ -20,6 +20,7 @@ package org.netbeans.modules.java.hints.bugs; import com.sun.source.tree.*; +import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.tree.Tree.Kind; import com.sun.source.util.TreePath; import java.util.ArrayList; @@ -49,7 +50,6 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.support.CancellableTreeScanner; -import org.netbeans.modules.editor.java.TreeShims; import org.netbeans.spi.editor.hints.ErrorDescription; import org.openide.util.NbBundle; @@ -645,13 +645,7 @@ public State scan(Tree tree, Void p) { TreePath oldPath = currentPath; try { currentPath = new TreePath(currentPath, tree); - if (TreeShims.SWITCH_EXPRESSION.equals(tree.getKind().name())) { - r = visitSwitchExpression(tree, p); - } else if (TreeShims.YIELD.equals(tree.getKind().name())) { - r = visitYield(tree, p); - } else { - r = super.scan(tree, p); - } + r = super.scan(tree, p); } finally { currentPath = oldPath; } @@ -1263,11 +1257,12 @@ public State visitSwitch(SwitchTree node, Void p) { return null; } - public State visitSwitchExpression(Tree node, Void p) { + @Override + public State visitSwitchExpression(SwitchExpressionTree node, Void p) { List oldPendingYields = pendingYields; try { pendingYields = new ArrayList<>(); - handleGeneralizedSwitch(node, TreeShims.getExpressions(node).get(0), TreeShims.getCases(node)); + handleGeneralizedSwitch(node, node.getExpression(), node.getCases()); if (pendingYields.isEmpty()) { //should not happen (for valid source) return State.POSSIBLE_NULL; @@ -1298,7 +1293,7 @@ private void handleGeneralizedSwitch(Tree switchTree, ExpressionTree expression, State caseResult = scan(ct, null); - if (TreeShims.isRuleCase(ct)) { + if (ct.getCaseKind() == CaseKind.RULE) { pendingYields.add(caseResult); breakTo(switchTree); } @@ -1320,8 +1315,9 @@ public State visitBreak(BreakTree node, Void p) { return null; } - public State visitYield(Tree node, Void p) { - pendingYields.add(scan(TreeShims.getYieldValue(node), p)); + @Override + public State visitYield(YieldTree node, Void p) { + pendingYields.add(scan(node.getValue(), p)); Tree target = info.getTreeUtilities().getBreakContinueTargetTree(getCurrentPath()); diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/errors/DifferentCaseKindsFix.java b/java/java.hints/src/org/netbeans/modules/java/hints/errors/DifferentCaseKindsFix.java index b0a97670c3ed..a1df80afc385 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/errors/DifferentCaseKindsFix.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/errors/DifferentCaseKindsFix.java @@ -19,8 +19,10 @@ package org.netbeans.modules.java.hints.errors; import com.sun.source.tree.CaseTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.Tree; +import com.sun.source.tree.Tree.Kind; import com.sun.source.util.TreePath; import java.util.Arrays; import java.util.Collections; @@ -30,7 +32,6 @@ import org.netbeans.api.java.queries.CompilerOptionsQuery; import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.modules.java.hints.spi.ErrorRule; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.spi.editor.hints.Fix; import org.netbeans.spi.java.hints.JavaFix; import org.netbeans.spi.java.hints.JavaFix.TransformationContext; @@ -65,8 +66,8 @@ public List run(CompilationInfo info, String diagnosticKey, int offset, Tre } List caseTrees = null; boolean flag = false; - if(parentPath.getLeaf().getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)){ - caseTrees = TreeShims.getCases(parentPath.getLeaf()); + if(parentPath.getLeaf().getKind() == Kind.SWITCH_EXPRESSION) { + caseTrees = ((SwitchExpressionTree) parentPath.getLeaf()).getCases(); } else { flag = true; caseTrees = ((SwitchTree) treePath.getParentPath().getLeaf()).getCases(); @@ -75,7 +76,7 @@ public List run(CompilationInfo info, String diagnosticKey, int offset, Tre boolean wasDefault = false; boolean wasEmpty = false; for (CaseTree ct : caseTrees) { - if (ct.getStatements() == null && TreeShims.getBody(ct) == null) { + if (ct.getStatements() == null && ct.getBody() == null) { return null; } else if (flag && ct.getStatements() != null) { if (completesNormally) { diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/errors/ImplementAllAbstractMethods.java b/java/java.hints/src/org/netbeans/modules/java/hints/errors/ImplementAllAbstractMethods.java index 7db9f6eb99e4..6089365b0e44 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/errors/ImplementAllAbstractMethods.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/errors/ImplementAllAbstractMethods.java @@ -66,7 +66,6 @@ import org.netbeans.editor.GuardedException; import org.netbeans.modules.java.editor.codegen.ImplementOverrideMethodGenerator; import org.netbeans.modules.java.hints.spi.ErrorRule; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.spi.editor.hints.ChangeInfo; import org.netbeans.spi.editor.hints.Fix; import org.netbeans.spi.java.hints.JavaFix; diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java b/java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java index 99c936476a44..33e022ffb4dd 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java @@ -39,6 +39,7 @@ import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BinaryTree; import com.sun.source.tree.BlockTree; +import com.sun.source.tree.CaseLabelTree; import com.sun.source.tree.CaseTree; import com.sun.source.tree.CatchTree; import com.sun.source.tree.ClassTree; @@ -63,6 +64,7 @@ import com.sun.source.tree.PrimitiveTypeTree; import com.sun.source.tree.Scope; import com.sun.source.tree.StatementTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.SynchronizedTree; import com.sun.source.tree.Tree; @@ -147,7 +149,6 @@ import org.netbeans.api.java.source.CodeStyleUtils; import org.netbeans.api.java.source.TreeMaker; import org.netbeans.modules.java.source.JavaSourceAccessor; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.spi.java.hints.JavaFix; import org.netbeans.spi.java.hints.JavaFixUtilities; import org.openide.util.Pair; @@ -3178,21 +3179,24 @@ public static void performRewriteRuleSwitch(JavaFix.TransformationContext ctx, T List newCases = new ArrayList<>(); SWITCH_TYPE switchType = SWITCH_TYPE.TRADITIONAL_SWITCH; Tree typeCastTree = null; + ExpressionTree switchExpr; List cases; Set variablesDeclaredInOtherCases = new HashSet<>(); - List patterns = new ArrayList<>(); + List patterns = new ArrayList<>(); Tree leftVariable = null; - boolean ruleSwitchFlag = st.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION); + boolean ruleSwitchFlag = st.getKind() == Kind.SWITCH_EXPRESSION; if (ruleSwitchFlag) { - cases = TreeShims.getCases(st); + switchExpr = ((SwitchExpressionTree) st).getExpression(); + cases = ((SwitchExpressionTree) st).getCases(); switchType = SWITCH_TYPE.RULE_SWITCH; } else { + switchExpr = ((SwitchTree) st).getExpression(); cases = ((SwitchTree) st).getCases(); } for (Iterator it = cases.iterator(); it.hasNext();) { CaseTree ct = it.next(); TreePath casePath = new TreePath(tp, ct); - patterns.addAll(TreeShims.getExpressions(ct)); + patterns.addAll(ct.getLabels()); List statements; if (ct.getStatements() == null) { statements = new ArrayList<>(((JCTree.JCCase) ct).stats); @@ -3279,9 +3283,9 @@ public Void visitIdentifier(IdentifierTree node, Void p) { typeCastTree = ((JCTree.JCTypeCast)body).getType(); body = ((JCTree.JCTypeCast)body).getExpression(); } - newCases.add(make.Case(patterns, make.ExpressionStatement((ExpressionTree) body))); + newCases.add(make.CasePatterns(patterns, make.ExpressionStatement((ExpressionTree) body))); } else { - newCases.add(make.Case(patterns, body)); + newCases.add(make.CasePatterns(patterns, body)); } patterns = new ArrayList<>(); @@ -3294,7 +3298,7 @@ public Void visitIdentifier(IdentifierTree node, Void p) { ExpressionTree et = null; switch (switchType) { case SWITCH_EXPRESSION: - et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases); + et = (ExpressionTree) make.SwitchExpression(switchExpr, newCases); if (typeCastTree != null) { et = make.Parenthesized(et); et = make.TypeCast(typeCastTree, et); @@ -3306,10 +3310,10 @@ public Void visitIdentifier(IdentifierTree node, Void p) { } break; case RULE_SWITCH: - wc.rewrite(st, make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases)); + wc.rewrite(st, make.SwitchExpression(switchExpr, newCases)); break; case TRADITIONAL_SWITCH: - wc.rewrite((SwitchTree) st, make.Switch(((SwitchTree) st).getExpression(), newCases)); + wc.rewrite((SwitchTree) st, make.Switch(switchExpr, newCases)); break; default: break; diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/introduce/Flow.java b/java/java.hints/src/org/netbeans/modules/java/hints/introduce/Flow.java index 8e521409dbbb..6f4c8779f247 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/introduce/Flow.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/introduce/Flow.java @@ -28,6 +28,7 @@ import com.sun.source.tree.BlockTree; import com.sun.source.tree.BreakTree; import com.sun.source.tree.CaseTree; +import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.tree.CatchTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; @@ -59,6 +60,7 @@ import com.sun.source.tree.PrimitiveTypeTree; import com.sun.source.tree.ReturnTree; import com.sun.source.tree.StatementTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.SynchronizedTree; import com.sun.source.tree.ThrowTree; @@ -72,6 +74,7 @@ import com.sun.source.tree.VariableTree; import com.sun.source.tree.WhileLoopTree; import com.sun.source.tree.WildcardTree; +import com.sun.source.tree.YieldTree; import com.sun.source.util.TreePath; import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner; import java.util.ArrayList; @@ -102,7 +105,6 @@ import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.CompilationInfo.CacheClearPolicy; import org.netbeans.api.java.source.support.CancellableTreeScanner; -import org.netbeans.modules.editor.java.TreeShims; import org.netbeans.modules.java.hints.errors.Utilities; import org.netbeans.spi.java.hints.HintContext; @@ -471,13 +473,7 @@ public Boolean scan(Tree tree, ConstructorData p) { TreePath oldPath = currentPath; try { currentPath = new TreePath(currentPath, tree); - if (TreeShims.SWITCH_EXPRESSION.equals(tree.getKind().name())) { - result = visitSwitchExpression(tree, p); - } else if (TreeShims.YIELD.equals(tree.getKind().name())) { - result = visitYield(tree, p); - } else { - result = super.scan(tree, p); - } + result = super.scan(tree, p); } finally { currentPath = oldPath; } @@ -1212,8 +1208,9 @@ public Boolean visitBreak(BreakTree node, ConstructorData p) { return null; } - public Boolean visitYield(Tree node, ConstructorData p) { - scan(TreeShims.getYieldValue(node), p); + @Override + public Boolean visitYield(YieldTree node, ConstructorData p) { + scan(node.getValue(), p); Tree target = info.getTreeUtilities().getBreakContinueTargetTree(getCurrentPath()); @@ -1233,8 +1230,9 @@ public Boolean visitSwitch(SwitchTree node, ConstructorData p) { return null; } - public Boolean visitSwitchExpression(Tree node, ConstructorData p) { - generalizedSwitch(node, TreeShims.getExpressions(node).get(0), TreeShims.getCases(node)); + @Override + public Boolean visitSwitchExpression(SwitchExpressionTree node, ConstructorData p) { + generalizedSwitch(node, node.getExpression(), node.getCases()); return null; //never a constant expression } @@ -1256,7 +1254,7 @@ private void generalizedSwitch(Tree switchTree, ExpressionTree expression, List< scan(ct, null); - if (TreeShims.isRuleCase(ct)) { + if (ct.getCaseKind() == CaseKind.RULE) { breakTo(switchTree); } } diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToPatternInstanceOf.java b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToPatternInstanceOf.java index 488c36c18e3d..e71e0885e273 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToPatternInstanceOf.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToPatternInstanceOf.java @@ -43,7 +43,6 @@ import org.netbeans.api.java.source.TreePathHandle; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.modules.java.hints.errors.Utilities; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.spi.editor.hints.ErrorDescription; import org.netbeans.spi.editor.hints.Fix; import org.netbeans.spi.java.hints.ErrorDescriptionFactory; @@ -139,9 +138,8 @@ protected void performRewrite(JavaFix.TransformationContext ctx) { IfTree it = (IfTree) main.getLeaf(); InstanceOfTree iot = (InstanceOfTree) ((ParenthesizedTree) it.getCondition()).getExpression(); StatementTree bt = it.getThenStatement(); - InstanceOfTree cond = wc.getTreeMaker().InstanceOf(iot.getExpression(), TreeShims.isJDKVersionSupportEnablePreview() - ? wc.getTreeMaker().BindingPattern(varName, iot.getType()) - : wc.getTreeMaker().BindingPattern(wc.getTreeMaker().Variable(wc.getTreeMaker().Modifiers(EnumSet.noneOf(Modifier.class)), varName, iot.getType(), null))); + InstanceOfTree cond = wc.getTreeMaker().InstanceOf(iot.getExpression(), + wc.getTreeMaker().BindingPattern(wc.getTreeMaker().Variable(wc.getTreeMaker().Modifiers(EnumSet.noneOf(Modifier.class)), varName, iot.getType(), null))); StatementTree thenBlock = removeFirst ? wc.getTreeMaker().removeBlockStatement((BlockTree) bt, 0) : bt; wc.rewrite(it, wc.getTreeMaker().If(wc.getTreeMaker().Parenthesized(cond), thenBlock, it.getElseStatement())); replaceOccurrences.stream().map(tph -> tph.resolve(wc)).forEach(tp -> { diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java index 3777b88c8552..6dfcfd0cf243 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java @@ -250,7 +250,7 @@ protected void performRewrite(JavaFix.TransformationContext ctx) { iot = (InstanceOfTree) ((ParenthesizedTree) ifTree.getCondition()).getExpression(); StatementTree bt = ifTree.getThenStatement(); StatementTree thenBlock = removeFirst ? wc.getTreeMaker().removeBlockStatement((BlockTree) bt, 0) : bt; - Tree pattern = TreeShims.getPattern(iot); + Tree pattern = iot.getPattern(); caseBindPattern.add(pattern); BlockTree blockTree = (BlockTree) thenBlock; Tree statementTree = blockTree.getStatements().size() == 1 && isValidCaseTree(blockTree.getStatements().get(0))? blockTree.getStatements().get(0) : thenBlock; diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/suggestions/ExpectedTypeResolver.java b/java/java.hints/src/org/netbeans/modules/java/hints/suggestions/ExpectedTypeResolver.java index a2424e53da09..e87f86e92f0a 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/suggestions/ExpectedTypeResolver.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/suggestions/ExpectedTypeResolver.java @@ -35,6 +35,7 @@ import com.sun.source.tree.CompoundAssignmentTree; import com.sun.source.tree.ConditionalExpressionTree; import com.sun.source.tree.ContinueTree; +import com.sun.source.tree.DefaultCaseLabelTree; import com.sun.source.tree.DoWhileLoopTree; import com.sun.source.tree.EmptyStatementTree; import com.sun.source.tree.EnhancedForLoopTree; @@ -43,6 +44,7 @@ import com.sun.source.tree.ExpressionStatementTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.ForLoopTree; +import com.sun.source.tree.GuardedPatternTree; import com.sun.source.tree.IdentifierTree; import com.sun.source.tree.IfTree; import com.sun.source.tree.ImportTree; @@ -62,6 +64,7 @@ import com.sun.source.tree.OpensTree; import com.sun.source.tree.PackageTree; import com.sun.source.tree.ParameterizedTypeTree; +import com.sun.source.tree.ParenthesizedPatternTree; import com.sun.source.tree.ParenthesizedTree; import com.sun.source.tree.PrimitiveTypeTree; import com.sun.source.tree.ProvidesTree; @@ -1392,15 +1395,33 @@ public List visitUses(UsesTree node, Object p) { return null; } + @Override public List visitBindingPattern(BindingPatternTree bpt, Object p) { return null; } + @Override public List visitSwitchExpression(SwitchExpressionTree set, Object p) { return null; } + @Override public List visitYield(YieldTree yt, Object p) { return null; } + + @Override + public List visitDefaultCaseLabel(DefaultCaseLabelTree node, Object p) { + return null; + } + + @Override + public List visitGuardedPattern(GuardedPatternTree node, Object p) { + return null; + } + + @Override + public List visitParenthesizedPattern(ParenthesizedPatternTree node, Object p) { + return null; + } } diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProviderTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProviderTest.java index 7795423250c6..6020de5f77c6 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProviderTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProviderTest.java @@ -46,7 +46,6 @@ import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater; import org.netbeans.spi.editor.hints.ErrorDescription; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.java.completion.TreeShims; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; diff --git a/java/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java b/java/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java index 02ac898f9441..4aa850c6b01c 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java @@ -46,7 +46,6 @@ 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.TreeShims; import org.netbeans.modules.java.source.usages.ClassFileUtil; import org.openide.util.Parameters; import org.openide.util.WeakSet; @@ -470,12 +469,6 @@ public static ElementHandle createModuleElementHandle( Parameters.notNull("element", element); ElementKind kind = element.getKind(); ElementKind simplifiedKind = kind; - if (TreeShims.isRecord(element)) { - simplifiedKind = ElementKind.CLASS; - } - if (TreeShims.isRecordComponent(element)) { - simplifiedKind = ElementKind.FIELD; - } String[] signatures; switch (simplifiedKind) { case PACKAGE: @@ -486,6 +479,7 @@ public static ElementHandle createModuleElementHandle( case INTERFACE: case ENUM: case ANNOTATION_TYPE: + case RECORD: assert element instanceof TypeElement; signatures = new String[] {ClassFileUtil.encodeClassNameOrArray((TypeElement)element)}; break; @@ -498,6 +492,7 @@ public static ElementHandle createModuleElementHandle( break; case FIELD: case ENUM_CONSTANT: + case RECORD_COMPONENT: assert element instanceof VariableElement; signatures = ClassFileUtil.createFieldDescriptor((VariableElement)element); break; @@ -610,6 +605,7 @@ public ElementHandle create(ElementKind kind, String... descriptors) { case INTERFACE: case ENUM: case ANNOTATION_TYPE: + case RECORD: case OTHER: if (descriptors.length != 1) { throw new IllegalArgumentException (); @@ -634,11 +630,7 @@ public ElementHandle create(ElementKind kind, String... descriptors) { } return new ElementHandle (kind, descriptors); default: - if (kind.name().equals(TreeShims.RECORD) && (descriptors.length == 1)) { - return new ElementHandle(kind, descriptors); - } else { - throw new IllegalArgumentException(); - } + throw new IllegalArgumentException(); } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java b/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java index 711e945f5a8e..229711ca2a9f 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java @@ -69,6 +69,7 @@ import javax.lang.model.element.ModuleElement; import javax.lang.model.element.Name; import javax.lang.model.element.PackageElement; +import javax.lang.model.element.RecordComponentElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; @@ -85,7 +86,6 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.ElementsService; import org.netbeans.modules.java.source.base.SourceLevelUtils; import org.openide.util.Parameters; @@ -595,17 +595,10 @@ public StringBuilder visitModule(ModuleElement e, Boolean p) { } @Override - public StringBuilder visitUnknown(Element e, Boolean p) { - if (TreeShims.isRecord(e)) { - //TODO: test! - return visitType((TypeElement) e, p); - } - if (TreeShims.isRecordComponent(e)) { - //TODO: test! - return visitVariable((VariableElement) e, p); - } - return super.visitUnknown(e, p); + public StringBuilder visitRecordComponent(RecordComponentElement e, Boolean p) { + return visitVariable((VariableElement) e, p); } + } /** diff --git a/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java b/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java index b945f7e14226..63b51be1277a 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java @@ -122,7 +122,6 @@ import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.api.scripting.Scripting; import org.netbeans.modules.java.source.GeneratorUtilitiesAccessor; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.builder.CommentSetImpl; import org.netbeans.modules.java.source.parsing.AbstractSourceFileObject; @@ -1138,6 +1137,7 @@ private CompilationUnitTree addImports(CompilationUnitTree cut, List> getMainClasses (final @NonN public void run(final CompilationController control) throws Exception { if (control.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED).compareTo (JavaSource.Phase.ELEMENTS_RESOLVED)>=0) { final List types = new ArrayList<>(); - final ElementScanner6 visitor = new ElementScanner6() { + final ElementScanner6 visitor = new ElementScanner14() { @Override public Void visitType(TypeElement e, Void p) { if (e.getEnclosingElement().getKind() == ElementKind.PACKAGE @@ -883,14 +879,6 @@ public Void visitType(TypeElement e, Void p) { } } - @Override - public Void scan(Element e, Void p) { - if (TreeShims.isRecordComponent(e)) { - return visitVariable((VariableElement) e, p); - } else { - return super.scan(e, p); - } - } }; visitor.scan(control.getTopLevelElements(), null); for (TypeElement type : types) { diff --git a/java/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java b/java/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java index 97e455af67ce..69c16e38c10f 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java @@ -66,6 +66,7 @@ import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; @@ -73,7 +74,6 @@ import org.netbeans.api.lexer.TokenSequence; import org.netbeans.api.java.lexer.JavaTokenId; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.ASTService; import org.netbeans.modules.java.source.query.CommentSet; @@ -276,7 +276,7 @@ public CaseTree Case(List patterns, Tree body) { * @since 2.39 */ public CaseTree CasePatterns(List patterns, Tree body) { - return delegate.CaseMultiplePatterns(patterns, body); + return delegate.CaseMultiplePatterns(patterns.stream().map(p -> (CaseLabelTree) p).collect(Collectors.toList()), body); } /** @@ -288,7 +288,7 @@ public CaseTree CasePatterns(List patterns, Tree body) { * @since 2.39 */ public CaseTree CasePatterns(List patterns, List statements) { - return delegate.CaseMultiplePatterns(patterns, statements); + return delegate.CaseMultiplePatterns(patterns.stream().map(p -> (CaseLabelTree) p).collect(Collectors.toList()), statements); } /** @@ -2908,9 +2908,7 @@ private N setLabelImpl(final N node, final CharSequence aLabel) // todo (#pf): Shouldn't here be check that names are not the same? // i.e. node label == aLabel? -- every case branch has to check itself // This will improve performance, no change was done by API user. - Tree.Kind kind = TreeShims.isRecord(node) ? Kind.CLASS : node.getKind(); - - switch (kind) { + switch (node.getKind()) { case BREAK: { BreakTree t = (BreakTree) node; N clone = (N) Break( @@ -2921,7 +2919,8 @@ private N setLabelImpl(final N node, final CharSequence aLabel) case ANNOTATION_TYPE: case CLASS: case ENUM: - case INTERFACE: { + case INTERFACE: + case RECORD: { ClassTree t = (ClassTree) node; // copy all the members, for constructor change their name // too! diff --git a/java/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java b/java/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java index 6ce4e4d50b66..b1a025350cfc 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/TreePathHandle.java @@ -51,7 +51,6 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.modules.java.source.PositionRefProvider; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.parsing.FileObjects; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; @@ -321,9 +320,11 @@ private static boolean isSupported(Element el) { case FIELD: case ANNOTATION_TYPE: case ENUM_CONSTANT: + case RECORD: + //TODO: record component return true; default: - return (el.getKind().name().equals(TreeShims.RECORD)); + return false; } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java b/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java index b94657dbaf3b..bbfde528eaf9 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java @@ -104,7 +104,6 @@ import org.netbeans.lib.nbjavac.services.NBAttr; import org.netbeans.lib.nbjavac.services.NBParserFactory; import org.netbeans.lib.nbjavac.services.NBResolve; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.TreeUtilitiesAccessor; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.builder.CommentSetImpl; @@ -127,15 +126,7 @@ public final class TreeUtilities { * * @since 0.67 */ - public static final Set CLASS_TREE_KINDS = EnumSet.of(Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE); - static { - Kind recKind = null; - try { - recKind = Kind.valueOf(TreeShims.RECORD); - CLASS_TREE_KINDS.add(recKind); - } catch (IllegalArgumentException ex) { - } - } + public static final Set CLASS_TREE_KINDS = EnumSet.of(Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.RECORD); private final CompilationInfo info; private final CommentHandlerService handler; @@ -1442,10 +1433,9 @@ public Tree getBreakContinueTargetTree(TreePath breakOrContinue) throws IllegalA } else { return target; } + case YIELD: + return (Tree) ((JCTree.JCYield) leaf).target; default: - if (TreeShims.YIELD.equals(leaf.getKind().name())) { - return TreeShims.getTarget(leaf); - } throw new IllegalArgumentException("Unsupported kind: " + leaf.getKind()); } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/TypeMirrorHandle.java b/java/java.source.base/src/org/netbeans/api/java/source/TypeMirrorHandle.java index e777239ac7a3..b917c01c2e37 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/TypeMirrorHandle.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/TypeMirrorHandle.java @@ -465,10 +465,10 @@ public Void visitClassType(ClassType t, Void s) { @Override public Void visitTypeVar(TypeVar t, Void s) { - if (t.bound instanceof PlaceholderType) - t.bound = ((PlaceholderType)t.bound).delegate; - else if (t.bound != null) - t.bound.accept(this, s); + if (t.getUpperBound() instanceof PlaceholderType) + t.setUpperBound(((PlaceholderType)t.getUpperBound()).delegate); + else if (t.getUpperBound() != null) + t.getUpperBound().accept(this, s); if (t.lower instanceof PlaceholderType) t.lower = ((PlaceholderType)t.lower).delegate; else if (t.lower != null) @@ -482,8 +482,8 @@ public Void visitWildcardType(Type.WildcardType t, Void s) { t.type = ((PlaceholderType)t.type).delegate; else if (t.type != null) t.type.accept(this, s); - if (t.bound != null) - t.bound.accept(this, s); + if (t.getUpperBound() != null) + t.getUpperBound().accept(this, s); return null; } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java b/java/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java index a416ad712b2c..ff8bc89c2022 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/WorkingCopy.java @@ -82,7 +82,6 @@ import static org.netbeans.api.java.source.ModificationResult.*; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.modules.java.source.FileObjectFromTemplateCreator; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.builder.CommentSetImpl; import org.netbeans.modules.java.source.builder.TreeFactory; @@ -865,10 +864,6 @@ public Tree translate(Tree tree) { Tree t; if (translated != null) { t = translate(translated); - } else if (tree != null && tree.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { - t = visitSwitchExpression(tree, null); - } else if (tree != null && tree.getKind().toString().equals("YIELD")) { - t = visitYield(tree, null); } else { t = super.translate(tree); } @@ -891,14 +886,6 @@ public DocTree translate(DocTree tree) { } return super.translate(tree); } - - public Tree visitSwitchExpression(Tree set, Object p) { - return rewriteChildren(set); - } - - public Tree visitYield(Tree set, Object p) { - return set; - } }; Context c = impl.getJavacTask().getContext(); itt.attach(c, ia, tree2Tag); diff --git a/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java b/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java index c1d97e6eb5b8..31b3376049f1 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreePathScanner.java @@ -20,8 +20,8 @@ import com.sun.source.tree.ErroneousTree; import com.sun.source.tree.CaseTree; +import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.util.TreePathScanner; -import org.netbeans.modules.java.source.TreeShims; /** * @@ -36,7 +36,12 @@ public R visitErroneous(ErroneousTree et, P p) { @Override public R visitCase(CaseTree node, P p) { - scan(TreeShims.getLabels(node), p); - return super.visitCase(node, p); + R r = scan(node.getLabels(), p); + if (node.getCaseKind() == CaseKind.STATEMENT) { + r = reduce(scan(node.getStatements(), p), r); + } else { + r = reduce(scan(node.getBody(), p), r); + } + return r; } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java b/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java index 16e06698f7af..1208f99bedae 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/support/ErrorAwareTreeScanner.java @@ -20,8 +20,8 @@ import com.sun.source.tree.ErroneousTree; import com.sun.source.tree.CaseTree; +import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.util.TreeScanner; -import org.netbeans.modules.java.source.TreeShims; /** * @@ -36,7 +36,12 @@ public R visitErroneous(ErroneousTree et, P p) { @Override public R visitCase(CaseTree node, P p) { - scan(TreeShims.getLabels(node), p); - return super.visitCase(node, p); + R r = scan(node.getLabels(), p); + if (node.getCaseKind() == CaseKind.STATEMENT) { + r = reduce(scan(node.getStatements(), p), r); + } else { + r = reduce(scan(node.getBody(), p), r); + } + return r; } } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java b/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java index 4c401d70ef4e..a6efd50592b9 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java @@ -308,7 +308,7 @@ public static String parseModuleName( null, FileEncodingQuery.getEncoding(moduleInfo)))); final CompilationUnitTree cu = jt.parse().iterator().next(); - final ModuleTree module = TreeShims.getModule(cu); + final ModuleTree module = cu.getModule(); if (module != null) { return module.getName().toString(); } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java b/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java index ecadb7d0ce16..d2dc46f4de00 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; +import javax.lang.model.SourceVersion; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.openide.modules.OnStart; @@ -41,9 +42,9 @@ public static boolean hasWorkingJavac() { return res; } try { - Class.forName("javax.lang.model.element.ModuleElement"); + SourceVersion.valueOf("RELEASE_17"); res = true; - } catch (ClassNotFoundException ex) { + } catch (IllegalArgumentException ex) { //OK res = false; } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/TreeShims.java b/java/java.source.base/src/org/netbeans/modules/java/source/TreeShims.java index a27181ee4934..f92d90938ad2 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/TreeShims.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/TreeShims.java @@ -32,8 +32,6 @@ import com.sun.tools.javac.tree.DocTreeMaker; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Names; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -46,288 +44,326 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; public class TreeShims { - public static final String BINDING_PATTERN = "BINDING_PATTERN"; //NOI18N - public static final String SWITCH_EXPRESSION = "SWITCH_EXPRESSION"; //NOI18N - public static final String YIELD = "YIELD"; //NOI18N - public static final String BINDING_VARIABLE = "BINDING_VARIABLE"; //NOI18N - public static final String RECORD = "RECORD"; //NOI18N - public static final int PATTERN_MATCHING_INSTANCEOF_PREVIEW_JDK_VERSION = 15; //NOI18N - public static final String DEFAULT_CASE_LABEL = "DEFAULT_CASE_LABEL"; //NOI18N - public static final String NULL_LITERAL = "NULL_LITERAL"; //NOI18N - public static final String PARENTHESIZED_PATTERN = "PARENTHESIZED_PATTERN"; //NOI18N - public static final String GUARDED_PATTERN = "GUARDED_PATTERN"; //NOI18N - - public static List getExpressions(CaseTree node) { - try { - Method getExpressions = CaseTree.class.getDeclaredMethod("getExpressions"); - return (List) getExpressions.invoke(node); - } catch (NoSuchMethodException ex) { - return Collections.singletonList(node.getExpression()); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static List getLabels(CaseTree node) { - try { - Method getLabels = CaseTree.class.getDeclaredMethod("getLabels"); - return (List) getLabels.invoke(node); - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree getBody(CaseTree node) { - try { - Method getBody = CaseTree.class.getDeclaredMethod("getBody"); - return (Tree) getBody.invoke(node); - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static boolean isRuleCase(CaseTree node) { - try { - Method getCaseKind = CaseTree.class.getDeclaredMethod("getCaseKind"); - return "RULE".equals(String.valueOf(getCaseKind.invoke(node))); - } catch (NoSuchMethodException ex) { - return false; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree getPattern(InstanceOfTree node) { - try { - Method getPattern = InstanceOfTree.class.getDeclaredMethod("getPattern"); - return (Tree) getPattern.invoke(node); - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static List getExpressions(Tree node) { - List exprTrees = new ArrayList<>(); - - switch (node.getKind().toString()) { - case "CASE": - exprTrees = getExpressions((CaseTree) node); - break; - case SWITCH_EXPRESSION: { - try { - Class swExprTreeClass = Class.forName("com.sun.source.tree.SwitchExpressionTree"); - Method getExpressions = swExprTreeClass.getDeclaredMethod("getExpression"); - exprTrees = Collections.singletonList((ExpressionTree) getExpressions.invoke(node)); - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - break; - } - case "SWITCH": - exprTrees = Collections.singletonList(((SwitchTree) node).getExpression()); - break; - default: - break; - } - return exprTrees; - } - - public static List getCases(Tree node) { - List caseTrees = new ArrayList<>(); - - switch (node.getKind().toString()) { - case "SWITCH": - caseTrees = ((SwitchTree) node).getCases(); - break; - case "SWITCH_EXPRESSION": { - try { - Class swExprTreeClass = Class.forName("com.sun.source.tree.SwitchExpressionTree"); - Method getCases = swExprTreeClass.getDeclaredMethod("getCases"); - caseTrees = (List) getCases.invoke(node); - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - } - return caseTrees; - } - - public static ExpressionTree getValue(BreakTree node) { - try { - Method getExpression = BreakTree.class.getDeclaredMethod("getValue"); - return (ExpressionTree) getExpression.invoke(node); - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Name getBinding(Tree node) { - try { - Class bpt = Class.forName("com.sun.source.tree.BindingPatternTree"); //NOI18N - return isJDKVersionSupportEnablePreview() - ? (Name)bpt.getDeclaredMethod("getBinding").invoke(node) //NOI18N - : ((VariableTree)bpt.getDeclaredMethod("getVariable").invoke(node)).getName(); //NOI18N - - } catch (NoSuchMethodException | ClassNotFoundException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree getGuardedPattern(Tree node) { - try { - Class gpt = Class.forName("com.sun.source.tree.GuardedPatternTree"); //NOI18N - return isJDKVersionRelease17_Or_Above() - ? (Tree)gpt.getDeclaredMethod("getPattern").invoke(node) //NOI18N - : null; - - } catch (NoSuchMethodException | ClassNotFoundException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree getParenthesizedPattern(Tree node) { - try { - Class ppt = Class.forName("com.sun.source.tree.ParenthesizedPatternTree"); //NOI18N - return isJDKVersionRelease17_Or_Above() - ? (Tree)ppt.getDeclaredMethod("getPattern").invoke(node) //NOI18N - : null; - - } catch (NoSuchMethodException | ClassNotFoundException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static ExpressionTree getGuardedExpression(Tree node) { - try { - Class gpt = Class.forName("com.sun.source.tree.GuardedPatternTree"); //NOI18N - return isJDKVersionRelease17_Or_Above() - ? (ExpressionTree)gpt.getDeclaredMethod("getExpression").invoke(node) //NOI18N - : null; - - } catch (NoSuchMethodException | ClassNotFoundException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static List getPermits(ClassTree node) { - List perms = null; - try { - Class classTree = Class.forName("com.sun.source.tree.ClassTree"); - Method getPerms = classTree.getDeclaredMethod("getPermitsClause"); - perms = (List) getPerms.invoke(node); - } catch (ClassNotFoundException | NoSuchMethodException ex) { - return null; - } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - return perms; - } - - public static ReferenceTree getRefrenceTree(DocTreeMaker docMake, ExpressionTree qualExpr, CharSequence member, List paramTypes, Names names, List paramTypesList) { - int NOPOS = -2; - try { - Class classTree = Class.forName("com.sun.tools.javac.tree.DocTreeMaker"); - Method newReferenceTree = classTree.getDeclaredMethod("newReferenceTree", java.lang.String.class, com.sun.tools.javac.tree.JCTree.JCExpression.class, com.sun.tools.javac.tree.JCTree.class, javax.lang.model.element.Name.class, java.util.List.class); - return (ReferenceTree) newReferenceTree.invoke(docMake.at(NOPOS), "", (JCTree.JCExpression) qualExpr, qualExpr == null ? null : ((JCTree.JCExpression) qualExpr).getTree(), member != null ? (com.sun.tools.javac.util.Name) names.fromString(member.toString()) : null, paramTypesList); - } catch (ClassNotFoundException | NoSuchMethodException ex) { - return null; - } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static List getPermits(JCClassDecl newT) { - List newPermitings = new ArrayList<>(); - try { - Class jCClassDecl = Class.forName("com.sun.tools.javac.tree.JCTree$JCClassDecl"); - newPermitings = (com.sun.tools.javac.util.List) jCClassDecl.getDeclaredField("permitting").get(newT); - } catch (ClassNotFoundException | NoSuchFieldException ex) { - return null; - } catch (IllegalArgumentException | IllegalAccessException ex) { - throw TreeShims.throwAny(ex); - } - return newPermitings; - } - - public static ExpressionTree getYieldValue(Tree node) { - if (!node.getKind().toString().equals(YIELD)) { - return null; - } - try { - Class yieldTreeClass = Class.forName("com.sun.source.tree.YieldTree"); //NOI18N - Method getExpression = yieldTreeClass.getDeclaredMethod("getValue"); //NOI18N - return (ExpressionTree) getExpression.invoke(node); - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree SwitchExpression(TreeMaker make, ExpressionTree selector, List caseList) throws SecurityException { - ListBuffer cases = new ListBuffer(); - for (CaseTree t : caseList) { - cases.append((JCTree.JCCase) t); - } - try { - Method getMethod = TreeMaker.class.getDeclaredMethod("SwitchExpression", JCTree.JCExpression.class, com.sun.tools.javac.util.List.class); - return (Tree) getMethod.invoke(make, (JCTree.JCExpression) selector, cases.toList()); - } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(ex); - } - } - - public static Tree getBindingPatternType(Tree node) { - if (!node.getKind().toString().equals(BINDING_PATTERN)) { - return null; - } - try { - Class bpt = Class.forName("com.sun.source.tree.BindingPatternTree"); //NOI18N - return isJDKVersionSupportEnablePreview() - ? (Tree) bpt.getDeclaredMethod("getType").invoke(node) //NOI18N - : ((VariableTree) bpt.getDeclaredMethod("getVariable").invoke(node)).getType(); //NOI18N - - } catch (NoSuchMethodException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException ex) { - throw TreeShims.throwAny(ex); - } - } - - @SuppressWarnings("unchecked") - public static RuntimeException throwAny(Throwable t) throws T { - throw (T) t; - } - public static boolean isRecord(Element el) { - return el != null && "RECORD".equals(el.getKind().name()); - } - - public static boolean isRecord(final N node) { - return node != null && TreeShims.RECORD.equals(node.getKind().name()); - } - - public static boolean isRecordComponent(Element el) { - return el != null && "RECORD_COMPONENT".equals(el.getKind().name()); - } +// public static final String BINDING_PATTERN = "BINDING_PATTERN"; //NOI18N +// public static final String SWITCH_EXPRESSION = "SWITCH_EXPRESSION"; //NOI18N +// public static final String YIELD = "YIELD"; //NOI18N +// public static final String BINDING_VARIABLE = "BINDING_VARIABLE"; //NOI18N +// public static final String RECORD = "RECORD"; //NOI18N +// public static final int PATTERN_MATCHING_INSTANCEOF_PREVIEW_JDK_VERSION = 15; //NOI18N +// public static final String DEFAULT_CASE_LABEL = "DEFAULT_CASE_LABEL"; //NOI18N +// public static final String NULL_LITERAL = "NULL_LITERAL"; //NOI18N +// public static final String PARENTHESIZED_PATTERN = "PARENTHESIZED_PATTERN"; //NOI18N +// public static final String GUARDED_PATTERN = "GUARDED_PATTERN"; //NOI18N +// +// public static List getExpressions(CaseTree node) { +// try { +// Method getExpressions = CaseTree.class.getDeclaredMethod("getExpressions"); +// return (List) getExpressions.invoke(node); +// } catch (NoSuchMethodException ex) { +// return Collections.singletonList(node.getExpression()); +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static List getLabels(CaseTree node) { +// try { +// Method getLabels = CaseTree.class.getDeclaredMethod("getLabels"); +// return (List) getLabels.invoke(node); +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Tree getBody(CaseTree node) { +// try { +// Method getBody = CaseTree.class.getDeclaredMethod("getBody"); +// return (Tree) getBody.invoke(node); +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static boolean isRuleCase(CaseTree node) { +// try { +// Method getCaseKind = CaseTree.class.getDeclaredMethod("getCaseKind"); +// return "RULE".equals(String.valueOf(getCaseKind.invoke(node))); +// } catch (NoSuchMethodException ex) { +// return false; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Tree getPattern(InstanceOfTree node) { +// try { +// Method getPattern = InstanceOfTree.class.getDeclaredMethod("getPattern"); +// return (Tree) getPattern.invoke(node); +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static List getExpressions(Tree node) { +// List exprTrees = new ArrayList<>(); +// +// switch (node.getKind().toString()) { +// case "CASE": +// exprTrees = getExpressions((CaseTree) node); +// break; +// case SWITCH_EXPRESSION: { +// try { +// Class swExprTreeClass = Class.forName("com.sun.source.tree.SwitchExpressionTree"); +// Method getExpressions = swExprTreeClass.getDeclaredMethod("getExpression"); +// exprTrees = Collections.singletonList((ExpressionTree) getExpressions.invoke(node)); +// } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// break; +// } +// case "SWITCH": +// exprTrees = Collections.singletonList(((SwitchTree) node).getExpression()); +// break; +// default: +// break; +// } +// return exprTrees; +// } +// +// public static List getCases(Tree node) { +// List caseTrees = new ArrayList<>(); +// +// switch (node.getKind().toString()) { +// case "SWITCH": +// caseTrees = ((SwitchTree) node).getCases(); +// break; +// case "SWITCH_EXPRESSION": { +// try { +// Class swExprTreeClass = Class.forName("com.sun.source.tree.SwitchExpressionTree"); +// Method getCases = swExprTreeClass.getDeclaredMethod("getCases"); +// caseTrees = (List) getCases.invoke(node); +// } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// } +// return caseTrees; +// } +// +// public static ExpressionTree getValue(BreakTree node) { +// try { +// Method getExpression = BreakTree.class.getDeclaredMethod("getValue"); +// return (ExpressionTree) getExpression.invoke(node); +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Name getBinding(Tree node) { +// try { +// Class bpt = Class.forName("com.sun.source.tree.BindingPatternTree"); //NOI18N +// return isJDKVersionSupportEnablePreview() +// ? (Name)bpt.getDeclaredMethod("getBinding").invoke(node) //NOI18N +// : ((VariableTree)bpt.getDeclaredMethod("getVariable").invoke(node)).getName(); //NOI18N +// +// } catch (NoSuchMethodException | ClassNotFoundException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Tree getGuardedPattern(Tree node) { +// try { +// Class gpt = Class.forName("com.sun.source.tree.GuardedPatternTree"); //NOI18N +// return isJDKVersionRelease17_Or_Above() +// ? (Tree)gpt.getDeclaredMethod("getPattern").invoke(node) //NOI18N +// : null; +// +// } catch (NoSuchMethodException | ClassNotFoundException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Tree getParenthesizedPattern(Tree node) { +// try { +// Class ppt = Class.forName("com.sun.source.tree.ParenthesizedPatternTree"); //NOI18N +// return isJDKVersionRelease17_Or_Above() +// ? (Tree)ppt.getDeclaredMethod("getPattern").invoke(node) //NOI18N +// : null; +// +// } catch (NoSuchMethodException | ClassNotFoundException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static ExpressionTree getGuardedExpression(Tree node) { +// try { +// Class gpt = Class.forName("com.sun.source.tree.GuardedPatternTree"); //NOI18N +// return isJDKVersionRelease17_Or_Above() +// ? (ExpressionTree)gpt.getDeclaredMethod("getExpression").invoke(node) //NOI18N +// : null; +// +// } catch (NoSuchMethodException | ClassNotFoundException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static List getPermits(ClassTree node) { +// List perms = null; +// try { +// Class classTree = Class.forName("com.sun.source.tree.ClassTree"); +// Method getPerms = classTree.getDeclaredMethod("getPermitsClause"); +// perms = (List) getPerms.invoke(node); +// } catch (ClassNotFoundException | NoSuchMethodException ex) { +// return null; +// } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// return perms; +// } +// +// public static ReferenceTree getRefrenceTree(DocTreeMaker docMake, ExpressionTree qualExpr, CharSequence member, List paramTypes, Names names, List paramTypesList) { +// int NOPOS = -2; +// try { +// Class classTree = Class.forName("com.sun.tools.javac.tree.DocTreeMaker"); +// Method newReferenceTree = classTree.getDeclaredMethod("newReferenceTree", java.lang.String.class, com.sun.tools.javac.tree.JCTree.JCExpression.class, com.sun.tools.javac.tree.JCTree.class, javax.lang.model.element.Name.class, java.util.List.class); +// return (ReferenceTree) newReferenceTree.invoke(docMake.at(NOPOS), "", (JCTree.JCExpression) qualExpr, qualExpr == null ? null : ((JCTree.JCExpression) qualExpr).getTree(), member != null ? (com.sun.tools.javac.util.Name) names.fromString(member.toString()) : null, paramTypesList); +// } catch (ClassNotFoundException | NoSuchMethodException ex) { +// return null; +// } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static List getPermits(JCClassDecl newT) { +// List newPermitings = new ArrayList<>(); +// try { +// Class jCClassDecl = Class.forName("com.sun.tools.javac.tree.JCTree$JCClassDecl"); +// newPermitings = (com.sun.tools.javac.util.List) jCClassDecl.getDeclaredField("permitting").get(newT); +// } catch (ClassNotFoundException | NoSuchFieldException ex) { +// return null; +// } catch (IllegalArgumentException | IllegalAccessException ex) { +// throw TreeShims.throwAny(ex); +// } +// return newPermitings; +// } +// +// public static ExpressionTree getYieldValue(Tree node) { +// if (!node.getKind().toString().equals(YIELD)) { +// return null; +// } +// try { +// Class yieldTreeClass = Class.forName("com.sun.source.tree.YieldTree"); //NOI18N +// Method getExpression = yieldTreeClass.getDeclaredMethod("getValue"); //NOI18N +// return (ExpressionTree) getExpression.invoke(node); +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static Tree getBindingPatternType(Tree node) { +// if (!node.getKind().toString().equals(BINDING_PATTERN)) { +// return null; +// } +// try { +// Class bpt = Class.forName("com.sun.source.tree.BindingPatternTree"); //NOI18N +// return isJDKVersionSupportEnablePreview() +// ? (Tree) bpt.getDeclaredMethod("getType").invoke(node) //NOI18N +// : ((VariableTree) bpt.getDeclaredMethod("getVariable").invoke(node)).getType(); //NOI18N +// +// } catch (NoSuchMethodException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// public static boolean isRecord(Element el) { +// return el != null && "RECORD".equals(el.getKind().name()); +// } +// +// public static boolean isRecord(final N node) { +// return node != null && TreeShims.RECORD.equals(node.getKind().name()); +// } +// +// public static boolean isRecordComponent(Element el) { +// return el != null && "RECORD_COMPONENT".equals(el.getKind().name()); +// } +// +// +// public static boolean isRecordComponent(ElementKind kind) { +// return "RECORD_COMPONENT".equals(kind.name()); +// } +// +// public static ElementKind getRecordKind() { +// try { +// return ElementKind.valueOf(RECORD); //NOI18N +// } catch (IllegalArgumentException ex) { +// return null; +// } +// } +// +// public static Tree getTarget(Tree node) { +// if (!node.getKind().name().equals(YIELD)) { +// throw new IllegalStateException(); +// } +// try { +// Field target = node.getClass().getField("target"); +// return (Tree) target.get(node); +// } catch (NoSuchFieldException ex) { +// return null; +// } catch (IllegalAccessException | IllegalArgumentException ex) { +// throw TreeShims.throwAny(ex); +// } +// } +// +// +// public static boolean isJDKVersionSupportEnablePreview() { +// return Integer.valueOf(SourceVersion.latest().name().split("_")[1]).compareTo(PATTERN_MATCHING_INSTANCEOF_PREVIEW_JDK_VERSION) <= 0; +// } +// +// public static boolean isJDKVersionRelease16_Or_Above(){ +// return Integer.valueOf(SourceVersion.latest().name().split("_")[1]).compareTo(16) >= 0; +// } +// +// +// public static ModuleTree getModule(CompilationUnitTree cut) { +// try { +// return (ModuleTree) CompilationUnitTree.class.getDeclaredMethod("getModule").invoke(cut); +// } catch (NoSuchMethodException | SecurityException ex) { +// final List typeDecls = cut.getTypeDecls(); +// if (!typeDecls.isEmpty()) { +// final Tree typeDecl = typeDecls.get(0); +// if (typeDecl.getKind() == Tree.Kind.MODULE) { +// return (ModuleTree)typeDecl; +// } +// } +// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { +// throwAny(ex); +// } +// return null; +// } public static Element toRecordComponent(Element el) { if (el == null ||el.getKind() != ElementKind.FIELD) { @@ -337,41 +373,14 @@ public static Element toRecordComponent(Element el) { if (!"RECORD".equals(owner.getKind().name())) { return el; } - for (Element encl : owner.getEnclosedElements()) { - if (isRecordComponent(encl.getKind()) && - encl.getSimpleName().equals(el.getSimpleName())) { + for (Element encl : ElementFilter.recordComponentsIn(owner.getEnclosedElements())) { + if (encl.getSimpleName().equals(el.getSimpleName())) { return encl; } } return el; } - public static boolean isRecordComponent(ElementKind kind) { - return "RECORD_COMPONENT".equals(kind.name()); - } - - public static ElementKind getRecordKind() { - try { - return ElementKind.valueOf(RECORD); //NOI18N - } catch (IllegalArgumentException ex) { - return null; - } - } - - public static Tree getTarget(Tree node) { - if (!node.getKind().name().equals(YIELD)) { - throw new IllegalStateException(); - } - try { - Field target = node.getClass().getField("target"); - return (Tree) target.get(node); - } catch (NoSuchFieldException ex) { - return null; - } catch (IllegalAccessException | IllegalArgumentException ex) { - throw TreeShims.throwAny(ex); - } - } - public static boolean isPatternMatch(Tree node) { if (isJDKVersionRelease17_Or_Above()) { try { @@ -383,32 +392,12 @@ public static boolean isPatternMatch(Tree node) { return false; } - public static boolean isJDKVersionSupportEnablePreview() { - return Integer.valueOf(SourceVersion.latest().name().split("_")[1]).compareTo(PATTERN_MATCHING_INSTANCEOF_PREVIEW_JDK_VERSION) <= 0; - } - - public static boolean isJDKVersionRelease16_Or_Above(){ - return Integer.valueOf(SourceVersion.latest().name().split("_")[1]).compareTo(16) >= 0; - } - public static boolean isJDKVersionRelease17_Or_Above(){ return Integer.valueOf(SourceVersion.latest().name().split("_")[1]).compareTo(17) >= 0; } - public static ModuleTree getModule(CompilationUnitTree cut) { - try { - return (ModuleTree) CompilationUnitTree.class.getDeclaredMethod("getModule").invoke(cut); - } catch (NoSuchMethodException | SecurityException ex) { - final List typeDecls = cut.getTypeDecls(); - if (!typeDecls.isEmpty()) { - final Tree typeDecl = typeDecls.get(0); - if (typeDecl.getKind() == Tree.Kind.MODULE) { - return (ModuleTree)typeDecl; - } - } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throwAny(ex); - } - return null; + @SuppressWarnings("unchecked") + public static RuntimeException throwAny(Throwable t) throws T { + throw (T) t; } } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/TreeShimsCopier.java b/java/java.source.base/src/org/netbeans/modules/java/source/TreeShimsCopier.java index 1130fb9bbb49..94c3b553bc28 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/TreeShimsCopier.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/TreeShimsCopier.java @@ -98,7 +98,7 @@ public boolean process(Set annos, RoundEnvironment roundE private static final Map ALLOWED_CLASSES2TARGET_PACKAGE = new HashMap() {{ put("org.netbeans.modules.java.hints.infrastructure.ErrorHintsProvider", "org.netbeans.modules.java.hints"); - put("org.netbeans.modules.java.completion.JavaCompletionTask", "org.netbeans.modules.java.completion"); + put("org.netbeans.modules.java.completion.JavaCompletionTask", "org.netbeans.modules.java.completion.impl"); put("org.netbeans.modules.editor.java.GoToSupport", "org.netbeans.modules.editor.java"); put("org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase", "org.netbeans.modules.java.editor.base.semantic"); }}; diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java b/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java index 0601b0626298..de5f566b73dc 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java @@ -46,6 +46,7 @@ import com.sun.source.doctree.ValueTree; import com.sun.source.doctree.VersionTree; import com.sun.source.tree.*; +import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.tree.MemberReferenceTree.ReferenceMode; import com.sun.source.tree.Tree.Kind; import com.sun.tools.javac.code.BoundKind; @@ -63,11 +64,14 @@ import com.sun.tools.javac.tree.DocTreeMaker; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; +import com.sun.tools.javac.tree.JCTree.JCCaseLabel; +import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.DiagnosticSource; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Context; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -80,7 +84,6 @@ import javax.lang.model.util.Types; import javax.tools.JavaFileObject; import org.netbeans.api.annotations.common.NonNull; -import org.netbeans.modules.java.source.TreeShims; import static org.netbeans.modules.java.source.save.PositionEstimator.*; /** @@ -195,105 +198,47 @@ public BlockTree Block(List statements, boolean isStati public BreakTree Break(CharSequence label) { Name n = label != null ? names.fromString(label.toString()) : null; - try { - return make.at(NOPOS).Break(n); - } catch (NoSuchMethodError err) { - try { - return (BreakTree) make.getClass().getMethod("Break", JCExpression.class).invoke(make.at(NOPOS), label != null ? Identifier(label) : null); - } catch (Throwable t) { - err.addSuppressed(t); - throw throwAny(err); - } - } + return make.at(NOPOS).Break(n); } - public BreakTree Break(ExpressionTree value) { - try { - return (BreakTree) make.getClass().getMethod("Break", JCExpression.class).invoke(make.at(NOPOS), (JCExpression) value); - } catch (Throwable t) { - throw throwAny(t); - } + public YieldTree Yield(ExpressionTree value) { + return make.at(NOPOS).Yield((JCExpression) value); } + public DefaultCaseLabelTree DefaultCaseLabel() { + return make.at(NOPOS).DefaultCaseLabel(); + } + public CaseTree Case(ExpressionTree expression, List statements) { - ListBuffer lb = new ListBuffer(); - for (StatementTree t : statements) - lb.append((JCStatement)t); - try { - return make.at(NOPOS).Case((JCExpression)expression, lb.toList()); - } catch (NoSuchMethodError err) { - try { - Class caseKind = (Class) Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCTree.class.getClassLoader()); - com.sun.tools.javac.util.List pats = expression != null ? com.sun.tools.javac.util.List.of((JCExpression)expression) : com.sun.tools.javac.util.List.nil(); - return (CaseTree) make.getClass().getMethod("Case", caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class).invoke(make.at(NOPOS), Enum.valueOf(caseKind, "STATEMENT"), pats, lb.toList(), null); - } catch (Throwable t) { - err.addSuppressed(t); - throw throwAny(err); - } - } + return Case(expression != null ? Collections.singletonList(expression) : Collections.emptyList(), statements); } public CaseTree Case(List expressions, List statements) { - switch (expressions.size()) { - case 0: return Case((ExpressionTree) null, statements); - case 1: return Case(expressions.get(0), statements); - } - ListBuffer lb = new ListBuffer(); - for (StatementTree t : statements) - lb.append((JCStatement)t); - ListBuffer exprs = new ListBuffer<>(); - for (ExpressionTree t : expressions) - exprs.append((JCExpression)t); - try { - Class caseKind = (Class) Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCTree.class.getClassLoader()); - return (CaseTree) make.getClass().getMethod("Case", caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class).invoke(make.at(NOPOS), Enum.valueOf(caseKind, "STATEMENT"), exprs.toList(), lb.toList(), null); - } catch (Throwable t) { - throw throwAny(t); - } + return CaseMultiplePatterns(expressions.isEmpty() ? Collections.singletonList(DefaultCaseLabel()) : expressions, statements); } public CaseTree Case(List expressions, Tree body) { - ListBuffer lb = new ListBuffer<>(); - lb.append(body instanceof ExpressionTree ? (JCStatement) Break((ExpressionTree) body) : (JCStatement) body); - ListBuffer exprs = new ListBuffer<>(); - for (ExpressionTree t : expressions) - exprs.append((JCExpression)t); - try { - Class caseKind = (Class) Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCTree.class.getClassLoader()); - return (CaseTree) make.getClass().getMethod("Case", caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class).invoke(make.at(NOPOS), Enum.valueOf(caseKind, "RULE"), exprs.toList(), lb.toList(), body); - } catch (Throwable t) { - throw throwAny(t); - } + return CaseMultiplePatterns(expressions.isEmpty() ? Collections.singletonList(DefaultCaseLabel()) : expressions, body); } - public CaseTree CaseMultiplePatterns(List expressions, Tree body) { + public CaseTree CaseMultiplePatterns(List expressions, Tree body) { ListBuffer lb = new ListBuffer<>(); - lb.append(body instanceof ExpressionTree ? (JCStatement) Break((ExpressionTree) body) : (JCStatement) body); - ListBuffer exprs = new ListBuffer<>(); + lb.append(body instanceof ExpressionTree ? (JCStatement) Yield((ExpressionTree) body) : (JCStatement) body); + ListBuffer exprs = new ListBuffer<>(); for (Tree t : expressions) - exprs.append((JCTree)t); - try { - Class caseKind = (Class) Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCTree.class.getClassLoader()); - return (CaseTree) make.getClass().getMethod("Case", caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class).invoke(make.at(NOPOS), Enum.valueOf(caseKind, "RULE"), exprs.toList(), lb.toList(), body); - } catch (Throwable t) { - throw throwAny(t); - } + exprs.append((JCCaseLabel)t); + return make.at(NOPOS).Case(CaseKind.RULE, exprs.toList(), lb.toList(), (JCTree) body); } - public CaseTree CaseMultiplePatterns(List expressions, List statements) { + public CaseTree CaseMultiplePatterns(List expressions, List statements) { ListBuffer lb = new ListBuffer(); for (StatementTree t : statements) lb.append((JCStatement)t); - ListBuffer exprs = new ListBuffer<>(); + ListBuffer exprs = new ListBuffer<>(); for (Tree t : expressions) - exprs.append((JCTree)t); - try { - Class caseKind = (Class) Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCTree.class.getClassLoader()); - return (CaseTree) make.getClass().getMethod("Case", caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class).invoke(make.at(NOPOS), Enum.valueOf(caseKind, "STATEMENT"), exprs.toList(), lb.toList(), null); - } catch (Throwable t) { - throw throwAny(t); - } + exprs.append((JCCaseLabel)t); + return make.at(NOPOS).Case(CaseKind.STATEMENT, exprs.toList(), lb.toList(), null); } public CatchTree Catch(VariableTree parameter, BlockTree block) { @@ -837,8 +782,12 @@ public SwitchTree Switch(ExpressionTree expression, List cas return make.at(NOPOS).Switch((JCExpression)expression, cases.toList()); } - public Tree SwitchExpression(ExpressionTree expression, List caseList) { - return TreeShims.SwitchExpression(make.at(NOPOS), expression, caseList); + public SwitchExpressionTree SwitchExpression(ExpressionTree expression, List caseList) { + ListBuffer cases = new ListBuffer(); + for (CaseTree t : caseList) { + cases.append((JCTree.JCCase) t); + } + return make.at(NOPOS).SwitchExpression((JCExpression) expression, cases.toList()); } public SynchronizedTree Synchronized(ExpressionTree expression, BlockTree block) { @@ -952,12 +901,16 @@ public Tree BindingPattern(CharSequence name, } } - public Tree BindingPattern(VariableTree vt) { - try { - return (Tree) make.getClass().getMethod("BindingPattern",JCVariableDecl.class).invoke(make.at(NOPOS), vt); - } catch (Throwable t) { - throw throwAny(t); - } + public BindingPatternTree BindingPattern(VariableTree vt) { + return make.at(NOPOS).BindingPattern((JCVariableDecl) vt); + } + + public GuardedPatternTree GuardedPattern(PatternTree pattern, ExpressionTree guard) { + return make.at(NOPOS).GuardPattern((JCPattern) pattern, (JCExpression) guard); + } + + public ParenthesizedPatternTree ParenthesizedPattern(PatternTree pattern) { + return make.at(NOPOS).ParenthesizedPattern((JCPattern) pattern); } public VariableTree Variable(VariableElement variable, ExpressionTree initializer) { @@ -1736,7 +1689,7 @@ private List c(List originalList, int index, E } return copy; } - + /** * Represents operation on list */ @@ -1952,19 +1905,15 @@ public LinkTree LinkPlain(ReferenceTree ref, List label) { } public ReferenceTree Reference(ExpressionTree qualExpr, CharSequence member, List paramTypes) { - com.sun.tools.javac.util.List paramTypesList = null; + com.sun.tools.javac.util.List paramTypesParam = null; if (paramTypes != null) { ListBuffer lbl = new ListBuffer<>(); for (Tree t : paramTypes) { lbl.append((JCTree) t); } - paramTypesList = lbl.toList(); - } - ReferenceTree refrenceTree = TreeShims.getRefrenceTree(docMake, qualExpr, member, paramTypes, names, paramTypesList); - if (refrenceTree != null) { - return refrenceTree; + paramTypesParam = lbl.toList(); } - return docMake.at(NOPOS).newReferenceTree("", (JCExpression) qualExpr, member != null ? (Name) names.fromString(member.toString()) : null, paramTypesList); + return docMake.at(NOPOS).newReferenceTree("", (JCTree.JCExpression) qualExpr, qualExpr == null ? null : ((JCTree.JCExpression) qualExpr).getTree(), member != null ? (com.sun.tools.javac.util.Name) names.fromString(member.toString()) : null, paramTypesParam); } @SuppressWarnings("unchecked") diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/FQN2Files.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/FQN2Files.java index d7295ce437c7..5af6b03d879c 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/FQN2Files.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/FQN2Files.java @@ -37,11 +37,11 @@ import javax.lang.model.element.ModuleElement; import javax.lang.model.element.Name; import javax.lang.model.element.PackageElement; +import javax.lang.model.element.RecordComponentElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.util.ElementScanner9; import javax.tools.JavaFileObject; -import org.netbeans.modules.java.source.TreeShims; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; @@ -101,14 +101,14 @@ public Object visitPackage(PackageElement e, Object p) { } } return null; - } + } + @Override + public Object visitRecordComponent(RecordComponentElement e, Object p) { + return visitVariable((VariableElement) e, p); + } @Override public Object scan(Element e, Object p) { - if (TreeShims.isRecordComponent(e)) { - return visitVariable((VariableElement) e, p); - } else { - return super.scan(e, p); - } + return super.scan(e, p); } }.scan(topLevelElements, null); } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/matching/CopyFinder.java b/java/java.source.base/src/org/netbeans/modules/java/source/matching/CopyFinder.java index ac5f7440e907..8c87ca2afdec 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/matching/CopyFinder.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/matching/CopyFinder.java @@ -107,7 +107,6 @@ import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.TreeUtilities; import org.netbeans.modules.java.source.JavaSourceAccessor; -import org.netbeans.modules.java.source.TreeShims; /**TODO: tested by CopyFinderTest in java.hints module. * @@ -1840,8 +1839,8 @@ public static List getStatements(TreePath firstLeaf) { CaseTree caseTree = (CaseTree) firstLeaf.getParentPath().getLeaf(); if (caseTree.getStatements() != null) { return caseTree.getStatements(); - } else if (TreeShims.getBody(caseTree) instanceof StatementTree) { - return Collections.singletonList((StatementTree) TreeShims.getBody(caseTree)); + } else if (caseTree.getBody() instanceof StatementTree) { + return Collections.singletonList((StatementTree) caseTree.getBody()); } else { return null; } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/pretty/VeryPretty.java b/java/java.source.base/src/org/netbeans/modules/java/source/pretty/VeryPretty.java index 3a8e6600e0bf..4b24e6b58bed 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/pretty/VeryPretty.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/pretty/VeryPretty.java @@ -70,6 +70,7 @@ import com.sun.source.doctree.ValueTree; import com.sun.source.doctree.VersionTree; import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTrees; @@ -107,7 +108,6 @@ import org.netbeans.api.java.source.Comment.Style; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.query.CommentHandler; import org.netbeans.modules.java.source.query.CommentSet; @@ -411,15 +411,7 @@ private void doAccept(JCTree t, boolean printComments/*XXX: should ideally alway } else { boolean saveComments = this.commentsEnabled; this.commentsEnabled = printComments; - if (t.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { - visitSwitchExpression(t); - } - else if (t.getKind().toString().equals(TreeShims.YIELD)) { - visitYield(t); - } - else { - t.accept(this); - } + t.accept(this); this.commentsEnabled = saveComments; } @@ -1292,13 +1284,14 @@ public void visitSwitch(JCSwitch tree) { print('}'); } - public void visitSwitchExpression(Tree tree) { + @Override + public void visitSwitchExpression(JCSwitchExpression tree) { print("switch"); print(cs.spaceBeforeSwitchParen() ? " (" : "("); if (cs.spaceWithinSwitchParens()) { print(' '); } - printNoParenExpr((JCTree) TreeShims.getExpressions(tree).get(0)); + printNoParenExpr(tree.selector); print(cs.spaceWithinSwitchParens() ? " )" : ")"); int bcol = out.leftMargin; switch (cs.getOtherBracePlacement()) { @@ -1321,10 +1314,10 @@ public void visitSwitchExpression(Tree tree) { needSpace(); } print('{'); - if (!TreeShims.getCases(tree).isEmpty()) { + if (!tree.getCases().isEmpty()) { newline(); ListBuffer newTcases = new ListBuffer(); - for (CaseTree t : TreeShims.getCases(tree)) { + for (CaseTree t : tree.getCases()) { newTcases.append((JCTree.JCCase) t); } printStats(newTcases.toList()); @@ -1337,8 +1330,10 @@ public void visitSwitchExpression(Tree tree) { public void visitCase(JCCase tree) { int old = cs.indentCasesFromSwitch() ? indent() : out.leftMargin; toLeftMargin(); - java.util.List labels = CasualDiff.getCaseLabelPatterns(tree); - if (labels.size() > 0) { + java.util.List labels = tree.labels; + if (labels.size() == 1 && labels.get(0).hasTag(Tag.DEFAULTCASELABEL)) { + print("default"); + } else { print("case "); String sep = ""; for (JCTree lab : labels) { @@ -1346,19 +1341,6 @@ public void visitCase(JCCase tree) { printNoParenExpr(lab); sep = ", "; //TODO: space or not should be a configuration setting } - } else { - java.util.List patterns = CasualDiff.getCasePatterns(tree); - if (patterns.isEmpty()) { - print("default"); - } else { - print("case "); - String sep = ""; - for (JCExpression pat : patterns) { - print(sep); - printNoParenExpr(pat); - sep = ", "; //TODO: space or not should be a configuration setting - } - } } Object caseKind = CasualDiff.getCaseKind(tree); if (caseKind == null || !String.valueOf(caseKind).equals("RULE")) { @@ -1513,19 +1495,16 @@ public void visitExec(JCExpressionStatement tree) { @Override public void visitBreak(JCBreak tree) { print("break"); - if (TreeShims.getValue(tree) != null) { - needSpace(); - print((JCTree) TreeShims.getValue(tree)); - } else if (tree.getLabel() != null) { + if (tree.getLabel() != null) { needSpace(); print(tree.getLabel()); } print(';'); } - public void visitYield(Tree tree) { + public void visitYield(JCYield tree) { print("yield"); - ExpressionTree expr = TreeShims.getYieldValue(tree); + ExpressionTree expr = tree.getValue(); if (expr != null) { needSpace(); print((JCTree) expr); @@ -2074,6 +2053,18 @@ public void visitReference(JCMemberReference tree) { else print("new"); } + @Override + public void visitBindingPattern(JCBindingPattern tree) { + print((JCTree) tree.var.vartype); + print(' '); + print((Name) tree.var.name); + } + + @Override + public void visitDefaultCaseLabel(JCDefaultCaseLabel that) { + print("default"); + } + @Override public void visitLetExpr(LetExpr tree) { print("(let " + tree.defs + " in " + tree.expr + ")"); @@ -2086,19 +2077,6 @@ public void visitErroneous(JCErroneous tree) { @Override public void visitTree(JCTree tree) { - if ("BINDING_PATTERN".equals(tree.getKind().name())) { - try { - print((JCTree) TreeShims.getBindingPatternType(tree)); - print(' '); - print((Name) TreeShims.getBinding(tree)); - return ; - } catch (RuntimeException ex) { - Exceptions.printStackTrace(ex); - } - }else if ("DEFAULT_CASE_LABEL".equals(tree.getKind().name())) { - print("default"); - return; - } print("(UNKNOWN: " + tree + ")"); newline(); } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/pretty/WidthEstimator.java b/java/java.source.base/src/org/netbeans/modules/java/source/pretty/WidthEstimator.java index f2e9980ba162..cfec39deb671 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/pretty/WidthEstimator.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/pretty/WidthEstimator.java @@ -210,7 +210,7 @@ public void visitTypeTest(JCInstanceOf tree) { open(prec, TreeInfo.ordPrec); width += 12; width(tree.expr, TreeInfo.ordPrec); - width(tree.clazz); + width(tree.pattern); } public void visitIndexed(JCArrayAccess tree) { diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java b/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java index 011af4778f51..39610d8d3fa7 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java @@ -68,6 +68,7 @@ import com.sun.tools.javac.tree.JCTree.JCAssign; import com.sun.tools.javac.tree.JCTree.JCAssignOp; import com.sun.tools.javac.tree.JCTree.JCBinary; +import com.sun.tools.javac.tree.JCTree.JCBindingPattern; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCBreak; import com.sun.tools.javac.tree.JCTree.JCCase; @@ -107,6 +108,7 @@ import com.sun.tools.javac.tree.JCTree.JCReturn; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCSwitch; +import com.sun.tools.javac.tree.JCTree.JCSwitchExpression; import com.sun.tools.javac.tree.JCTree.JCSynchronized; import com.sun.tools.javac.tree.JCTree.JCThrow; import com.sun.tools.javac.tree.JCTree.JCTry; @@ -171,7 +173,6 @@ import org.openide.util.NbBundle; import org.openide.util.NbCollections; import javax.lang.model.type.TypeKind; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.transform.TreeHelpers; public class CasualDiff { @@ -1934,24 +1935,24 @@ protected int diffSwitch(JCSwitch oldT, JCSwitch newT, int[] bounds) { return bounds[1]; } - protected int diffSwitchExpression(Tree oldT, Tree newT, int[] bounds) { + protected int diffSwitchExpression(JCSwitchExpression oldT, JCSwitchExpression newT, int[] bounds) { int localPointer = bounds[0]; // rename in switch - int[] selectorBounds = getBounds((JCTree)TreeShims.getExpressions(oldT).get(0)); + int[] selectorBounds = getBounds(oldT.selector); copyTo(localPointer, selectorBounds[0]); - localPointer = diffTree((JCTree)TreeShims.getExpressions(oldT).get(0), (JCTree)TreeShims.getExpressions(newT).get(0), selectorBounds); + localPointer = diffTree(oldT.selector, newT.selector, selectorBounds); tokenSequence.move(selectorBounds[1]); do { } while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id()); tokenSequence.moveNext(); copyTo(localPointer, localPointer = tokenSequence.offset()); - PositionEstimator est = EstimatorFactory.cases(TreeShims.getCases(oldT), TreeShims.getCases(newT), diffContext); + PositionEstimator est = EstimatorFactory.cases(oldT.cases, newT.cases, diffContext); ListBuffer oldTcases = new ListBuffer(); - for (CaseTree t : TreeShims.getCases(oldT)) + for (CaseTree t : oldT.getCases()) oldTcases.append((JCTree.JCCase)t); ListBuffer newTcases = new ListBuffer(); - for (CaseTree t : TreeShims.getCases(newT)) + for (CaseTree t : newT.getCases()) newTcases.append((JCTree.JCCase)t); localPointer = diffList(oldTcases.toList(), newTcases.toList(), localPointer, est, Measure.MEMBER, printer); @@ -1959,21 +1960,8 @@ protected int diffSwitchExpression(Tree oldT, Tree newT, int[] bounds) { return bounds[1]; } - protected int diffBindingPattern(Tree oldT, Tree newT, int[] bounds) { - VariableTree oldVar = getBindingVariableTree(oldT); - VariableTree newVar = getBindingVariableTree(newT); - - return diffTree((JCTree) oldVar, (JCTree) newVar, bounds); - } - - @NbBundle.Messages("ERR_PatternMatchingInstanceOf=Transformation for pattern matching in instanceof not supported on this version of JDK. Please run on JDK 16 or newer, or install nb-javac.") - public static VariableTree getBindingVariableTree(Tree node) { - try { - Class bpt = Class.forName("com.sun.source.tree.BindingPatternTree"); //NOI18N - return (VariableTree)bpt.getDeclaredMethod("getVariable").invoke(node); //NOI18N - } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw TreeShims.throwAny(Exceptions.attachLocalizedMessage(ex, Bundle.ERR_PatternMatchingInstanceOf())); - } + protected int diffBindingPattern(JCBindingPattern oldT, JCBindingPattern newT, int[] bounds) { + return diffTree((JCTree) oldT.var, (JCTree) newT.var, bounds); } protected int diffCase(JCCase oldT, JCCase newT, int[] bounds) { @@ -5744,6 +5732,12 @@ private int diffTreeImpl0(JCTree oldT, JCTree newT, JCTree parent /*used only fo case ANNOTATED_TYPE: retVal = diffAnnotatedType((JCAnnotatedType)oldT, (JCAnnotatedType)newT, elementBounds); break; + case SWITCH_EXPRESSION: + retVal = diffSwitchExpression((JCSwitchExpression) oldT, (JCSwitchExpression) newT, elementBounds); + break; + case BINDINGPATTERN: + retVal = diffBindingPattern((JCBindingPattern) oldT, (JCBindingPattern) newT, elementBounds); + break; default: // handle special cases like field groups and enum constants if (oldT.getKind() == Kind.OTHER) { @@ -5752,14 +5746,6 @@ private int diffTreeImpl0(JCTree oldT, JCTree newT, JCTree parent /*used only fo } break; } - if(oldT.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)){ - retVal = diffSwitchExpression(oldT, newT, elementBounds); - break; - } - if(oldT.getKind().toString().equals(TreeShims.BINDING_PATTERN)){ - retVal = diffBindingPattern(oldT, newT, elementBounds); - break; - } String msg = "Diff not implemented: " + ((com.sun.source.tree.Tree)oldT).getKind().toString() + " " + oldT.getClass().getName(); @@ -5875,7 +5861,7 @@ private boolean matchSwitch(JCSwitch t1, JCSwitch t2) { } private boolean matchCase(JCCase t1, JCCase t2) { - return treesMatch(t1.pat, t2.pat) && listsMatch(t1.stats, t2.stats); + return listsMatch(t1.labels, t2.labels) && listsMatch(t1.stats, t2.stats); } private boolean matchSynchronized(JCSynchronized t1, JCSynchronized t2) { diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/save/PositionEstimator.java b/java/java.source.base/src/org/netbeans/modules/java/source/save/PositionEstimator.java index e2f50546fc81..351f163419b5 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/save/PositionEstimator.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/PositionEstimator.java @@ -22,7 +22,6 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.ImportTree; import com.sun.source.tree.Tree; -import org.netbeans.modules.java.source.TreeShims; import com.sun.source.tree.VariableTree; import com.sun.source.util.SourcePositions; import com.sun.tools.javac.code.Flags; @@ -314,7 +313,7 @@ public int prepare(final int startPos, StringBuilder aHead, StringBuilder aTail) do { Tree t = cut.getTypeDecls().get(tdpos); typeDeclStart = (int) positions.getStartPosition(cut, t); - if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind()) || t.getKind().toString().equals(TreeShims.RECORD)) { + if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind())) { break; } tdpos++; diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java index 18eea7f53be4..185c677065c5 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java @@ -20,6 +20,7 @@ import com.sun.source.tree.*; import com.sun.source.tree.LambdaExpressionTree.BodyKind; +import com.sun.source.tree.Tree.Kind; import com.sun.source.util.*; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTrees; @@ -54,7 +55,6 @@ import org.netbeans.modules.editor.indent.spi.ReformatTask; import org.netbeans.modules.java.source.JavaSourceAccessor; import org.netbeans.modules.java.source.NoJavacHelper; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.modules.parsing.api.Embedding; @@ -584,29 +584,8 @@ public Boolean scan(Tree tree, Void p) { Boolean ret; - switch (tree.getKind().toString()) { - case TreeShims.SWITCH_EXPRESSION: - ret = scanSwitchExpression(tree, p); - break; - case TreeShims.YIELD: - ret = scanYield(tree, p); - break; - case TreeShims.BINDING_PATTERN: - ret = scanBindingPattern(tree, p); - break; - case TreeShims.GUARDED_PATTERN: - ret = scanGuardedPattern(tree, p); - break; - case TreeShims.PARENTHESIZED_PATTERN: - ret = scanParenthesizedPattern(tree, p); - break; - case TreeShims.RECORD: - ret = scanRecord((ClassTree) tree, p); - break; - default: - ret = super.scan(tree, p); - break; - } + ret = super.scan(tree, p); + return ret != null ? ret : true; } finally { @@ -898,6 +877,9 @@ public Boolean visitImport(ImportTree node, Void p) { @Override public Boolean visitClass(ClassTree node, Void p) { + if (node.getKind() == Kind.RECORD) { + return scanRecord(node, p); + } Tree parent = getCurrentPath().getParentPath().getLeaf(); if (parent.getKind() != Tree.Kind.NEW_CLASS && (parent.getKind() != Tree.Kind.VARIABLE || !isEnumerator((VariableTree)parent))) { boolean old = continuationIndent; @@ -961,7 +943,7 @@ public Boolean visitClass(ClassTree node, Void p) { wrapToken(cs.wrapExtendsImplementsKeyword(), 1, id == INTERFACE ? EXTENDS : IMPLEMENTS); wrapList(cs.wrapExtendsImplementsList(), cs.alignMultilineImplements(), true, COMMA, impls); } - List perms = TreeShims.getPermits(node); + List perms = node.getPermitsClause(); if (perms != null && !perms.isEmpty()) { wrapToken(cs.wrapExtendsImplementsKeyword(), 1, EXTENDS); wrapList(cs.wrapExtendsImplementsList(), cs.alignMultilineImplements(), true, COMMA, perms); @@ -1095,14 +1077,12 @@ public Boolean visitClass(ClassTree node, Void p) { } blankLines(cs.getBlankLinesAfterClass()); break; - default: - if (member.getKind().toString().equals(TreeShims.RECORD)) { + case RECORD: if (!first) - blankLines(cs.getBlankLinesBeforeMethods()); - scanRecord((ClassTree)member, p); + blankLines(cs.getBlankLinesBeforeMethods()); + scanRecord((ClassTree)member, p); blankLines(cs.getBlankLinesAfterMethods()); break; - } } first = false; } @@ -1177,7 +1157,7 @@ public Boolean visitVariable(VariableTree node, Void p) { WrapStyle newWrapStyle = cs.wrapAnnotations(); if (parent instanceof ClassTree) { for (Tree member : ((ClassTree) parent).getMembers()) { - if (member.getKind().toString().equals(TreeShims.RECORD)) { + if (member.getKind() == Kind.RECORD) { ClassTree cls = (ClassTree) member; for (Tree recMember : cls.getMembers()) { if (recMember.equals(getCurrentPath().getLeaf())) { @@ -2796,88 +2776,64 @@ public Boolean visitSwitch(SwitchTree node, Void p) { return handleSwitch(node, p); } - private Boolean scanSwitchExpression(Tree node, Void p) { - return handleSwitch(node,p); - } - - private Boolean scanYield(Tree node, Void p) { - return handleYield(node, p); + @Override + public Boolean visitSwitchExpression(SwitchExpressionTree node, Void p) { + return handleSwitch(node,p); } - private Boolean scanBindingPattern(Tree node, Void p) { - Name name = TreeShims.getBinding(node); - Tree type = TreeShims.getBindingPatternType(node); - scan(type, p); - if (name != null) { - space(); + @Override + public Boolean visitYield(YieldTree node, Void p) { + ExpressionTree exprTree = node.getValue(); + if (exprTree != null) { accept(IDENTIFIER); + space(); + scan(exprTree, p); } + accept(SEMICOLON); return true; } - private Boolean scanGuardedPattern(Tree node, Void p) { - try { - Tree gpt = TreeShims.getGuardedPattern(node); - if (gpt != null) { - if (scanParenthesizedPattern(gpt, p) == false) { - Name name = TreeShims.getBinding(gpt); - Tree type = TreeShims.getBindingPatternType(gpt); - scan(type, p); - if (name != null) { - removeWhiteSpace(IDENTIFIER); - } - } - } - } catch (RuntimeException ex) { - return false; - } - - ExpressionTree exprTree = TreeShims.getGuardedExpression(node); - if (exprTree != null) { - accept(IDENTIFIER); - removeWhiteSpace(IDENTIFIER); - scan(exprTree, p); - } + @Override + public Boolean visitBindingPattern(BindingPatternTree node, Void p) { + scan(node.getVariable(), p); return true; } - private Boolean scanParenthesizedPattern(Tree node, Void p) { - try { - Tree ppt = TreeShims.getParenthesizedPattern(node); - if (ppt != null) { - if (scanGuardedPattern(ppt, p) == false) { - scanBindingPattern(ppt, p); - } - removeWhiteSpace(IDENTIFIER); - } - } catch (RuntimeException ex) { - return false; - } + @Override + public Boolean visitGuardedPattern(GuardedPatternTree node, Void p) { + scan(node.getPattern(), p); + space(); + accept(AMPAMP); + space(); + scan(node.getExpression(), p); + return true; } - private Boolean handleYield(Tree node, Void p) { - ExpressionTree exprTree = TreeShims.getYieldValue(node); - if (exprTree != null) { - accept(IDENTIFIER); - space(); - scan(exprTree, p); - } - accept(SEMICOLON); + @Override + public Boolean visitParenthesizedPattern(ParenthesizedPatternTree node, Void p) { + accept(LPAREN); + scan(node.getPattern(), p); + accept(RPAREN); return true; } private boolean handleSwitch(Tree node, Void p) { + ExpressionTree selExpr; + List cases; + if (node.getKind() == Kind.SWITCH) { + selExpr = ((SwitchTree) node).getExpression(); + cases = ((SwitchTree) node).getCases(); + } else { + selExpr = ((SwitchExpressionTree) node).getExpression(); + cases = ((SwitchExpressionTree) node).getCases(); + } accept(SWITCH); boolean oldContinuationIndent = continuationIndent; try { continuationIndent = true; spaces(cs.spaceBeforeSwitchParen() ? 1 : 0); - List exprTrees = TreeShims.getExpressions(node); - if (!exprTrees.isEmpty()) { - ExpressionTree expressionTree = exprTrees.get(0); - scan(expressionTree, p); - } + scan(selExpr, p); } finally { continuationIndent = oldContinuationIndent; } @@ -2886,7 +2842,7 @@ private boolean handleSwitch(Tree node, Void p) { boolean indentCases = cs.indentCasesFromSwitch() ; int old = lastIndent; int halfIndent = lastIndent; - if (node.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { + if (node.getKind() == Kind.SWITCH_EXPRESSION) { continuationIndent = false; } switch (bracePlacement) { @@ -2926,12 +2882,11 @@ private boolean handleSwitch(Tree node, Void p) { } break; } - if (node.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { + if (node.getKind() == Kind.SWITCH_EXPRESSION) { indent = lastIndent + indentSize; } - List caseTrees = TreeShims.getCases(node); try { - for (CaseTree caseTree : caseTrees) { + for (CaseTree caseTree : cases) { newline(); scan(caseTree, p); } @@ -2977,32 +2932,37 @@ private boolean handleSwitch(Tree node, Void p) { @Override public Boolean visitCase(CaseTree node, Void p) { - List labels = TreeShims.getLabels(node); + List labels = node.getLabels(); if (labels != null && labels.size() > 0) { - if (tokens.token().id() == JavaTokenId.DEFAULT && labels.get(0).getKind().toString().equals(TreeShims.DEFAULT_CASE_LABEL)) { + if (tokens.token().id() == JavaTokenId.DEFAULT && labels.get(0).getKind() == Kind.DEFAULT_CASE_LABEL) { accept(DEFAULT); } else { accept(CASE); space(); for (Tree label : labels) { - if (label.getKind().toString().equals(TreeShims.DEFAULT_CASE_LABEL)) { - removeWhiteSpace(JavaTokenId.DEFAULT); - accept(DEFAULT); - } else if (label.getKind().toString().equals(TreeShims.BINDING_PATTERN) - || label.getKind().toString().equals(TreeShims.PARENTHESIZED_PATTERN) - || label.getKind().toString().equals(TreeShims.GUARDED_PATTERN)) { - removeWhiteSpace(JavaTokenId.IDENTIFIER); - scan(label, p); - } else if (label.getKind().toString().equals(TreeShims.NULL_LITERAL)) { - removeWhiteSpace(JavaTokenId.NULL); - scan(label, p); - } else { - scan(label, p); + switch (label.getKind()) { + case DEFAULT_CASE_LABEL: + removeWhiteSpace(JavaTokenId.DEFAULT); + accept(DEFAULT); + break; + case BINDING_PATTERN: + case PARENTHESIZED_PATTERN: + case GUARDED_PATTERN: + removeWhiteSpace(JavaTokenId.IDENTIFIER); + scan(label, p); + break; + case NULL_LITERAL: + removeWhiteSpace(JavaTokenId.NULL); + scan(label, p); + break; + default: + scan(label, p); + break; } } } - } else if (TreeShims.getExpressions(node).size() > 0) { - List exprs = TreeShims.getExpressions(node); + } else if (node.getExpressions().size() > 0) { + List exprs = node.getExpressions(); accept(CASE); space(); exprs.forEach(exp -> { @@ -3018,7 +2978,7 @@ public Boolean visitCase(CaseTree node, Void p) { else { space(); accept(ARROW); - caseBody = TreeShims.getBody(node); + caseBody = node.getBody(); if (caseBody instanceof StatementTree) statements = Collections.singletonList((StatementTree) caseBody); } @@ -3071,16 +3031,10 @@ private void removeWhiteSpace(JavaTokenId forToken) { @Override public Boolean visitBreak(BreakTree node, Void p) { JavaTokenId token = accept(BREAK); - ExpressionTree exprTree = TreeShims.getValue(node); - if (exprTree != null) { + Name label = node.getLabel(); + if (label != null) { space(); - scan(exprTree, p); - } else { - Name label = node.getLabel(); - if (label != null) { - space(); - accept(IDENTIFIER, UNDERSCORE); - } + accept(IDENTIFIER, UNDERSCORE); } accept(SEMICOLON); return true; @@ -3454,7 +3408,7 @@ public Boolean visitInstanceOf(InstanceOfTree node, Void p) { space(); accept(INSTANCEOF); space(); - Tree pattern = TreeShims.getPattern(node); + Tree pattern = node.getPattern(); if (pattern == null) pattern = node.getType(); scan(pattern, p); @@ -3526,6 +3480,7 @@ public Boolean visitParenthesized(ParenthesizedTree node, Void p) { spaceWithinParens = cs.spaceWithinWhileParens(); break; case SWITCH: + case SWITCH_EXPRESSION: spaceWithinParens = cs.spaceWithinSwitchParens(); break; case SYNCHRONIZED: diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java index 361b68162c09..e6be5785011d 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java @@ -35,6 +35,7 @@ import com.sun.source.tree.NewArrayTree; import com.sun.source.tree.NewClassTree; import com.sun.source.tree.StatementTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.SynchronizedTree; import com.sun.source.tree.Tree; @@ -81,7 +82,6 @@ import org.netbeans.modules.editor.indent.spi.ExtraLock; import org.netbeans.modules.editor.indent.spi.IndentTask; import org.netbeans.modules.java.source.NoJavacHelper; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.TreeUtilitiesAccessor; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; @@ -692,7 +692,7 @@ private int getNewIndent(int startOffset, int endOffset) throws BadLocationExcep if (statements != null) { tokenId = JavaTokenId.COLON; } else { - Tree caseBody = TreeShims.getBody((CaseTree) last); + Tree caseBody = ((CaseTree) last).getBody(); if (caseBody instanceof StatementTree) { statements = Collections.singletonList((StatementTree) caseBody); tokenId = JavaTokenId.ARROW; @@ -813,14 +813,14 @@ private int getNewIndent(int startOffset, int endOffset) throws BadLocationExcep currentIndent += cs.getLabelIndent(); } break; + case SWITCH_EXPRESSION: + currentIndent = getSwitchIndent(startOffset, endOffset,nextTokenId,lastPos,currentIndent) ; + break; + case RECORD: + currentIndent = getRecordIndent(startOffset, endOffset, nextTokenId, lastPos, currentIndent); + break; default: - if (last.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION)) { - currentIndent = getSwitchIndent(startOffset, endOffset,nextTokenId,lastPos,currentIndent) ; - } - else if (last.getKind().toString().equals(TreeShims.RECORD)) { - currentIndent = getRecordIndent(startOffset, endOffset, nextTokenId, lastPos, currentIndent); - } - else currentIndent = getContinuationIndent(path, currentIndent); + currentIndent = getContinuationIndent(path, currentIndent); break; } return currentIndent; @@ -845,7 +845,13 @@ private int getSwitchIndent(int startOffset, int endOffset, JavaTokenId nextToke } } else { Tree t = null; - for (CaseTree ct : TreeShims.getCases(last)) { + List cases; + if (last.getKind() == Tree.Kind.SWITCH) { + cases = ((SwitchTree) last).getCases(); + } else { + cases = ((SwitchExpressionTree) last).getCases(); + } + for (CaseTree ct : cases) { if (getEndPosition(ct) > startOffset) { break; } @@ -858,7 +864,7 @@ private int getSwitchIndent(int startOffset, int endOffset, JavaTokenId nextToke List statements = ct.getStatements(); if(statements == null) { - Tree caseBody = TreeShims.getBody(ct); + Tree caseBody = ct.getBody(); if (caseBody instanceof StatementTree) { statements = Collections.singletonList((StatementTree) caseBody); } @@ -893,7 +899,7 @@ else if (getEndPosition(caseBody) > startOffset ) { if (last.getKind() == Tree.Kind.SWITCH) { currentIndent = getStmtIndent(startOffset, endOffset, EnumSet.of(JavaTokenId.RPAREN), getEndPosition(((SwitchTree) last).getExpression()) - 1, currentIndent); } else { - currentIndent = getStmtIndent(startOffset, endOffset, EnumSet.of(JavaTokenId.RPAREN), getEndPosition(TreeShims.getExpressions(last).get(0)) - 1, currentIndent); + currentIndent = getStmtIndent(startOffset, endOffset, EnumSet.of(JavaTokenId.RPAREN), getEndPosition(((SwitchExpressionTree) last).getExpression()) - 1, currentIndent); } } } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java b/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java index b490380dba31..7844e18854ba 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java @@ -27,7 +27,6 @@ import com.sun.tools.javac.tree.JCTree.JCLambda; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.util.Context; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,19 +40,15 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.modules.java.source.GeneratorUtilitiesAccessor; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.ASTService; import org.netbeans.modules.java.source.builder.CommentHandlerService; import org.netbeans.modules.java.source.builder.QualIdentTree; import org.netbeans.modules.java.source.builder.TreeFactory; import org.netbeans.modules.java.source.pretty.ImportAnalysis2; import org.netbeans.modules.java.source.query.CommentHandler; -import org.netbeans.modules.java.source.save.CasualDiff; import org.netbeans.modules.java.source.save.ElementOverlay; import static org.netbeans.modules.java.source.save.PositionEstimator.*; -import org.openide.util.Exceptions; -import org.openide.util.NbBundle; /** A subclass of Tree.Visitor, this class defines * a general tree translator pattern. Translation proceeds recursively in @@ -124,8 +119,6 @@ public void release() { public Tree translate(Tree tree) { if (tree == null) { return null; - } else if (tree.getKind().name().equals(TreeShims.BINDING_PATTERN)) { - return rewriteChildrenBindingPattern(tree); } else { Tree t = tree.accept(this, null); @@ -535,6 +528,24 @@ public Tree visitRequires(RequiresTree tree, Object p) { public Tree visitUses(UsesTree tree, Object p) { return rewriteChildren(tree); } + public Tree visitBindingPattern(BindingPatternTree tree, Object p) { + return rewriteChildren(tree); + } + public Tree visitDefaultCaseLabel(DefaultCaseLabelTree tree, Object p) { + return rewriteChildren(tree); + } + public Tree visitGuardedPattern(GuardedPatternTree tree, Object p) { + return rewriteChildren(tree); + } + public Tree visitParenthesizedPattern(ParenthesizedPatternTree tree, Object p) { + return rewriteChildren(tree); + } + public Tree visitSwitchExpression(SwitchExpressionTree tree, Object p) { + return rewriteChildren(tree); + } + public Tree visitYield(YieldTree tree, Object p) { + return rewriteChildren(tree); + } public Tree visitOther(Tree tree, Object p) { throw new Error("Tree not overloaded: "+tree); } @@ -814,39 +825,26 @@ protected final SwitchTree rewriteChildren(SwitchTree tree) { return tree; } - protected final Tree rewriteChildren(Tree tree) { - ExpressionTree selector = (ExpressionTree)translate(TreeShims.getExpressions(tree).get(0)); - List cases = translateStable(TreeShims.getCases(tree)); - if (selector != TreeShims.getExpressions(tree).get(0) || !cases.equals(TreeShims.getCases(tree))) { - Tree switchExpression = make.SwitchExpression(selector, cases); - model.setType(switchExpression, model.getType(tree)); - copyCommentTo(tree,switchExpression); - copyPosTo(tree,switchExpression); - tree = switchExpression; - } - return tree; - } - protected final CaseTree rewriteChildren(CaseTree tree) { - Tree body = TreeShims.getBody(tree); - List expressions = TreeShims.getExpressions(tree); + Tree body = tree.getBody(); + List labels = tree.getLabels(); if (body == null) { - List pats = translate(expressions); + List pats = translate(labels); List stats = translate(tree.getStatements()); - if (!pats.equals(expressions) || !stats.equals(tree.getStatements())) { + if (!pats.equals(labels) || !stats.equals(tree.getStatements())) { if (stats != tree.getStatements()) stats = optimize(stats); - CaseTree n = make.Case(pats, stats); + CaseTree n = make.CaseMultiplePatterns(pats, stats); model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); tree = n; } } else { - List pats = translate(expressions); + List pats = translate(labels); Tree nueBody = translate(body); - if (!pats.equals(expressions) || body != nueBody) { - CaseTree n = make.Case(pats, nueBody); + if (!pats.equals(labels) || body != nueBody) { + CaseTree n = make.CaseMultiplePatterns(pats, nueBody); model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); @@ -1139,7 +1137,7 @@ protected final TypeCastTree rewriteChildren(TypeCastTree tree) { protected final InstanceOfTree rewriteChildren(InstanceOfTree tree) { ExpressionTree expr = (ExpressionTree)translate(tree.getExpression()); - Tree origPattern = TreeShims.getPattern(tree); + Tree origPattern = tree.getPattern(); if (origPattern == null) { origPattern = tree.getType(); } @@ -1415,11 +1413,28 @@ private Tree rewriteChildren(UsesTree tree) { return tree; } - private Tree rewriteChildrenBindingPattern(Tree tree) { - VariableTree var = CasualDiff.getBindingVariableTree(tree); //replace with tree.getVariable when javac supported is 16+: - VariableTree newVar = (VariableTree) translate(var); - if (newVar != var) { - Tree n = make.BindingPattern(newVar); + private BindingPatternTree rewriteChildren(BindingPatternTree tree) { + VariableTree newVar = (VariableTree) translate(tree.getVariable()); + if (newVar != tree.getVariable()) { + BindingPatternTree n = make.BindingPattern(newVar); + model.setType(n, model.getType(tree)); + copyCommentTo(tree,n); + copyPosTo(tree,n); + tree = n; + } + return tree; + } + + private DefaultCaseLabelTree rewriteChildren(DefaultCaseLabelTree tree) { + return tree; + } + + private GuardedPatternTree rewriteChildren(GuardedPatternTree tree) { + PatternTree newPattern = (PatternTree) translate(tree.getPattern()); + ExpressionTree newGuard = (ExpressionTree) translate(tree.getExpression()); + if (newPattern != tree.getPattern() || + newGuard != tree.getExpression()) { + GuardedPatternTree n = make.GuardedPattern(newPattern, newGuard); model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); @@ -1427,4 +1442,41 @@ private Tree rewriteChildrenBindingPattern(Tree tree) { } return tree; } + + private ParenthesizedPatternTree rewriteChildren(ParenthesizedPatternTree tree) { + PatternTree newPattern = (PatternTree) translate(tree.getPattern()); + if (newPattern != tree.getPattern()) { + ParenthesizedPatternTree n = make.ParenthesizedPattern(newPattern); + model.setType(n, model.getType(tree)); + copyCommentTo(tree,n); + copyPosTo(tree,n); + tree = n; + } + return tree; + } + + protected final SwitchExpressionTree rewriteChildren(SwitchExpressionTree tree) { + ExpressionTree selector = (ExpressionTree)translate(tree.getExpression()); + List cases = translateStable(tree.getCases()); + if (selector!=tree.getExpression() || !cases.equals(tree.getCases())) { + SwitchExpressionTree n = make.SwitchExpression(selector, cases); + model.setType(n, model.getType(tree)); + copyCommentTo(tree,n); + copyPosTo(tree,n); + tree = n; + } + return tree; + } + + protected final YieldTree rewriteChildren(YieldTree tree) { + ExpressionTree value = (ExpressionTree)translate(tree.getValue()); + if (value != tree.getValue()) { + YieldTree n = make.Yield(value); + model.setType(n, model.getType(tree)); + copyCommentTo(tree,n); + copyPosTo(tree,n); + tree = n; + } + return tree; + } } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/transform/TreeDuplicator.java b/java/java.source.base/src/org/netbeans/modules/java/source/transform/TreeDuplicator.java index 9920726db24a..39c57437d9b0 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/transform/TreeDuplicator.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/transform/TreeDuplicator.java @@ -25,6 +25,7 @@ import com.sun.source.tree.AssertTree; import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BinaryTree; +import com.sun.source.tree.BindingPatternTree; import com.sun.source.tree.BlockTree; import com.sun.source.tree.BreakTree; import com.sun.source.tree.CaseTree; @@ -34,6 +35,7 @@ import com.sun.source.tree.CompoundAssignmentTree; import com.sun.source.tree.ConditionalExpressionTree; import com.sun.source.tree.ContinueTree; +import com.sun.source.tree.DefaultCaseLabelTree; import com.sun.source.tree.DoWhileLoopTree; import com.sun.source.tree.EmptyStatementTree; import com.sun.source.tree.EnhancedForLoopTree; @@ -42,6 +44,7 @@ import com.sun.source.tree.ExpressionStatementTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.ForLoopTree; +import com.sun.source.tree.GuardedPatternTree; import com.sun.source.tree.IdentifierTree; import com.sun.source.tree.IfTree; import com.sun.source.tree.ImportTree; @@ -61,11 +64,13 @@ import com.sun.source.tree.OpensTree; import com.sun.source.tree.PackageTree; import com.sun.source.tree.ParameterizedTypeTree; +import com.sun.source.tree.ParenthesizedPatternTree; import com.sun.source.tree.ParenthesizedTree; import com.sun.source.tree.PrimitiveTypeTree; import com.sun.source.tree.ProvidesTree; import com.sun.source.tree.RequiresTree; import com.sun.source.tree.ReturnTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.SynchronizedTree; import com.sun.source.tree.ThrowTree; @@ -80,6 +85,7 @@ import com.sun.source.tree.VariableTree; import com.sun.source.tree.WhileLoopTree; import com.sun.source.tree.WildcardTree; +import com.sun.source.tree.YieldTree; import com.sun.tools.javac.util.Context; import java.util.List; import org.netbeans.modules.java.source.builder.ASTService; @@ -644,6 +650,60 @@ public Tree visitUses(UsesTree tree, Void p) { return n; } + @Override + public Tree visitYield(YieldTree tree, Void p) { + YieldTree n = make.Yield(tree.getValue()); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + + @Override + public Tree visitBindingPattern(BindingPatternTree tree, Void p) { + BindingPatternTree n = make.BindingPattern(tree.getVariable()); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + + @Override + public Tree visitDefaultCaseLabel(DefaultCaseLabelTree tree, Void p) { + DefaultCaseLabelTree n = make.DefaultCaseLabel(); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + + @Override + public Tree visitGuardedPattern(GuardedPatternTree tree, Void p) { + GuardedPatternTree n = make.GuardedPattern(tree.getPattern(), tree.getExpression()); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + + @Override + public Tree visitParenthesizedPattern(ParenthesizedPatternTree tree, Void p) { + ParenthesizedPatternTree n = make.ParenthesizedPattern(tree.getPattern()); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + + @Override + public Tree visitSwitchExpression(SwitchExpressionTree tree, Void p) { + SwitchExpressionTree n = make.SwitchExpression(tree.getExpression(), tree.getCases()); + model.setType(n, model.getType(tree)); + comments.copyComments(tree, n); + model.setPos(n, model.getPos(tree)); + return n; + } + @Override public Tree visitOther(Tree tree, Void p) { return tree; diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/usages/DocumentUtil.java b/java/java.source.base/src/org/netbeans/modules/java/source/usages/DocumentUtil.java index 16fe554ea41a..86387ebe96fc 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/usages/DocumentUtil.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/usages/DocumentUtil.java @@ -52,7 +52,6 @@ import org.netbeans.api.java.source.ClassIndex; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.modules.java.source.ElementHandleAccessor; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.parsing.lucene.support.Convertor; import org.netbeans.modules.parsing.lucene.support.Convertors; @@ -119,14 +118,9 @@ public static Convertor fileObjectConvertor ( @NonNull public static Convertor> typeElementConvertor() { - ElementKind recordKind = TreeShims.getRecordKind(); - List eleKindList = new ArrayList<>(); - ElementKind[] otherElekinds = {ElementKind.ENUM, ElementKind.INTERFACE, ElementKind.ANNOTATION_TYPE}; + ElementKind[] otherElekinds = {ElementKind.ENUM, ElementKind.INTERFACE, ElementKind.ANNOTATION_TYPE, ElementKind.RECORD}; eleKindList.addAll(Arrays.asList(otherElekinds)); - if (recordKind != null) { - eleKindList.add(recordKind); - } return new ElementHandleConvertor<>( ElementKind.CLASS, eleKindList.toArray(new ElementKind[0])); diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/usages/SourceAnalyzerFactory.java b/java/java.source.base/src/org/netbeans/modules/java/source/usages/SourceAnalyzerFactory.java index 2e6ad6394f2f..84e73a5973ca 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/usages/SourceAnalyzerFactory.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/usages/SourceAnalyzerFactory.java @@ -57,7 +57,6 @@ import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.SourceUtils; import org.netbeans.modules.java.source.ElementHandleAccessor; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.builder.ElementsService; import org.netbeans.modules.java.source.indexing.JavaCustomIndexer; import org.netbeans.modules.java.source.parsing.FileObjects; @@ -404,7 +403,7 @@ public Void visitCompilationUnit(@NonNull final CompilationUnitTree node, @NonNu state=oldState; } scan(node.getTypeDecls(),p); - scan(TreeShims.getModule(cu),p); //note: on older JDKs, this will analyze the ModuleTree twice + scan(cu.getModule(),p); Pair name = null; if (!imports.isEmpty() || diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java index e113741caf64..92dcfdb519e4 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java @@ -53,7 +53,6 @@ import org.netbeans.modules.java.source.BootClassPathUtil; import org.netbeans.modules.java.source.ElementUtils; import org.netbeans.modules.java.source.TestUtil; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.usages.IndexUtil; import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.classpath.support.ClassPathSupport; @@ -432,11 +431,9 @@ public void testCreateTypeElementHandle() { ElementKind.CLASS, ElementKind.INTERFACE, ElementKind.ENUM, - ElementKind.ANNOTATION_TYPE + ElementKind.ANNOTATION_TYPE, + ElementKind.RECORD })); - ElementKind recordKind = TreeShims.getRecordKind(); - if (recordKind != null) - allowed.add(recordKind); for (ElementKind aek : allowed) { ElementHandle eh = ElementHandle.createTypeElementHandle(aek, "org.me.Foo"); //NOI18N assertEquals(aek, eh.getKind()); diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/InstanceOfTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/InstanceOfTest.java index aff6ea1713a0..919c938caf9f 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/InstanceOfTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/InstanceOfTest.java @@ -40,7 +40,6 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.completion.TreeShims; /** * Tests correct adding cast to statement. @@ -94,13 +93,8 @@ public void run(WorkingCopy workingCopy) throws IOException { MethodTree method = (MethodTree) clazz.getMembers().get(1); IfTree ift = (IfTree) method.getBody().getStatements().get(0); InstanceOfTree it = (InstanceOfTree) ((ParenthesizedTree) ift.getCondition()).getExpression(); - InstanceOfTree nue = null; - if (TreeShims.isJDKVersionSupportEnablePreview()) { - nue = make.InstanceOf(it.getExpression(), make.BindingPattern("t", it.getType())); - } else { - VariableTree var = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "t", it.getType(), null); - nue = make.InstanceOf(it.getExpression(), make.BindingPattern(var)); - } + VariableTree var = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "t", it.getType(), null); + InstanceOfTree nue = make.InstanceOf(it.getExpression(), make.BindingPattern(var)); workingCopy.rewrite(it, nue); } diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ModuleInfoTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ModuleInfoTest.java index 3e243ddeacaa..4cbabdf60e5a 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ModuleInfoTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ModuleInfoTest.java @@ -24,7 +24,6 @@ import org.netbeans.api.java.source.*; import static org.netbeans.api.java.source.JavaSource.*; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.source.TreeShims; /** * @@ -61,7 +60,7 @@ public void run(WorkingCopy workingCopy) throws IOException { CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); - ModuleTree moduleTree = TreeShims.getModule(cut); + ModuleTree moduleTree = cut.getModule(); ExpressionTree nju = make.QualIdent("hierbas.test"); workingCopy.rewrite(moduleTree.getName(), nju); } @@ -95,7 +94,7 @@ public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); - ModuleTree moduleTree = TreeShims.getModule(cut); + ModuleTree moduleTree = cut.getModule(); ModuleTree nju = moduleTree; for (DirectiveTree tree : moduleTree.getDirectives()) { nju = make.removeModuleDirective(nju, tree); @@ -131,7 +130,7 @@ public void run(WorkingCopy workingCopy) throws IOException { CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); - ModuleTree moduleTree = TreeShims.getModule(cut); + ModuleTree moduleTree = cut.getModule(); ExpressionTree name = make.QualIdent("java.base"); ModuleTree copy = make.insertModuleDirective(moduleTree, 0, make.Requires(false, false, name)); workingCopy.rewrite(moduleTree, copy); @@ -164,7 +163,7 @@ public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); - ModuleTree moduleTree = TreeShims.getModule(cut); + ModuleTree moduleTree = cut.getModule(); ExpressionTree pkgName = make.QualIdent("hierbas.del.litoral"); ModuleTree copy = make.addModuleDirective(moduleTree, make.Exports(pkgName, Collections.emptyList())); workingCopy.rewrite(moduleTree, copy); @@ -196,7 +195,7 @@ public void run(WorkingCopy workingCopy) throws IOException { CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); - ModuleTree moduleTree = TreeShims.getModule(cut); + ModuleTree moduleTree = cut.getModule(); ExpressionTree pkgName = make.QualIdent("hierbas.del.litoral"); ModuleTree copy = make.addModuleDirective(moduleTree, make.Exports(pkgName, Collections.emptyList())); workingCopy.rewrite(moduleTree, copy); diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchExpressionTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchExpressionTest.java index 1617e48e19a5..dc92785fe32c 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchExpressionTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchExpressionTest.java @@ -25,8 +25,10 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.StatementTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.Tree; +import com.sun.source.tree.Tree.Kind; import com.sun.source.tree.VariableTree; import com.sun.tools.javac.tree.JCTree; import java.io.IOException; @@ -46,7 +48,6 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; import org.openide.filesystems.FileObject; @@ -174,16 +175,19 @@ public void run(WorkingCopy workingCopy) throws IOException { VariableTree switcExpression = (VariableTree) ((BlockTree) method.getBody()).getStatements().get(0); Tree switchBlock = switcExpression.getInitializer(); List cases; + ExpressionTree selExpr; List patterns = new ArrayList<>(); - boolean switchExpressionFlag = switchBlock.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION); + boolean switchExpressionFlag = switchBlock.getKind() == Kind.SWITCH_EXPRESSION; if (switchExpressionFlag) { - cases = TreeShims.getCases(switchBlock); + selExpr = ((SwitchExpressionTree) switchBlock).getExpression(); + cases = ((SwitchExpressionTree) switchBlock).getCases(); } else { + selExpr = ((SwitchTree) switchBlock).getExpression(); cases = ((SwitchTree) switchBlock).getCases(); } for (Iterator it = cases.iterator(); it.hasNext();) { CaseTree ct = it.next(); - patterns.addAll(TreeShims.getExpressions(ct)); + patterns.addAll(ct.getExpressions()); List statements; if (ct.getStatements() == null) { statements = new ArrayList<>(((JCTree.JCCase) ct).stats); @@ -210,7 +214,7 @@ public void run(WorkingCopy workingCopy) throws IOException { patterns = new ArrayList<>(); } } - workingCopy.rewrite(switchBlock, make.SwitchExpression(TreeShims.getExpressions(switchBlock).get(0), newCases)); + workingCopy.rewrite(switchBlock, make.SwitchExpression(selExpr, newCases)); } }; diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchRuleFormattingTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchRuleFormattingTest.java index 49167d2205fb..0ef62eeb5083 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchRuleFormattingTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchRuleFormattingTest.java @@ -25,8 +25,10 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.StatementTree; +import com.sun.source.tree.SwitchExpressionTree; import com.sun.source.tree.SwitchTree; import com.sun.source.tree.Tree; +import com.sun.source.tree.Tree.Kind; import com.sun.tools.javac.tree.JCTree; import java.io.IOException; import java.util.ArrayList; @@ -45,7 +47,6 @@ import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.junit.NbTestSuite; -import org.netbeans.modules.java.source.TreeShims; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; import org.openide.filesystems.FileObject; @@ -205,15 +206,15 @@ public void run(WorkingCopy workingCopy) throws IOException { List cases; List patterns = new ArrayList<>(); if(switchBlock!=null){ - boolean switchExpressionFlag = switchBlock.getKind().toString().equals(TreeShims.SWITCH_EXPRESSION); + boolean switchExpressionFlag = switchBlock.getKind() == Kind.SWITCH_EXPRESSION; if (switchExpressionFlag) { - cases = TreeShims.getCases(switchBlock); + cases = ((SwitchExpressionTree) switchBlock).getCases(); } else { cases = ((SwitchTree) switchBlock).getCases(); } for (Iterator it = cases.iterator(); it.hasNext();) { CaseTree ct = it.next(); - patterns.addAll(TreeShims.getExpressions(ct)); + patterns.addAll(ct.getExpressions()); List statements; if (ct.getStatements() == null) { statements = new ArrayList<>(((JCTree.JCCase) ct).stats); diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java index 9d796938b0e3..ae896dbdd970 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java @@ -42,7 +42,6 @@ import org.netbeans.api.java.source.TestUtilities; import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.WorkingCopy; -import org.netbeans.modules.java.source.TreeShims; /** * The following shell script was used to generate the code snippets @@ -257,21 +256,21 @@ public TestCase(String caseText, BiFunction con TestCase[] testCases = new TestCase[] { new TestCase("case 0:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.add(copy.getTreeMaker().Literal(1)); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case 0, 1:"), new TestCase("case 0:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.add(0, copy.getTreeMaker().Literal(-1)); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case -1, 0:"), new TestCase("case 0:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.add(0, copy.getTreeMaker().Literal(-1)); labels.add(copy.getTreeMaker().Literal(1)); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); @@ -279,35 +278,35 @@ public TestCase(String caseText, BiFunction con "case -1, 0, 1:"), new TestCase("case -1, 1:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.add(1, copy.getTreeMaker().Literal(0)); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case -1, 0, 1:"), new TestCase("case -1, 0, 1:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.remove(0); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case " + /*XXX: too many spaces:*/ " " + "0, 1:"), new TestCase("case -1, 0, 1:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.remove(1); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case -1, 1:"), new TestCase("case -1, 0, 1:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.remove(2); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, "case -1, 0:"), new TestCase("default:", (copy, tree) -> { - List labels = new ArrayList<>(TreeShims.getExpressions(tree)); + List labels = new ArrayList<>(tree.getExpressions()); labels.add(copy.getTreeMaker().Literal(0)); return copy.getTreeMaker().CaseMultipleLabels(labels, tree.getStatements()); }, @@ -405,7 +404,7 @@ public void run(final WorkingCopy copy) throws IOException { new ErrorAwareTreePathScanner() { @Override public Void visitCase(CaseTree node, Void p) { copy.rewrite(getCurrentPath().getLeaf(), - make.Case(TreeShims.getExpressions(node), make.Block(node.getStatements().subList(0, 2), false))); + make.Case(node.getExpressions(), make.Block(node.getStatements().subList(0, 2), false))); return super.visitCase(node, p); } }.scan(copy.getCompilationUnit(), null); @@ -452,10 +451,10 @@ public void run(final WorkingCopy copy) throws IOException { final TreeMaker make = copy.getTreeMaker(); new ErrorAwareTreePathScanner() { @Override public Void visitCase(CaseTree node, Void p) { - List statements = new ArrayList<>(((BlockTree) TreeShims.getBody(node)).getStatements()); + List statements = new ArrayList<>(((BlockTree) node.getBody()).getStatements()); statements.add(make.Break(null)); copy.rewrite(getCurrentPath().getLeaf(), - make.CaseMultipleLabels(TreeShims.getExpressions(node), statements)); + make.CaseMultipleLabels(node.getExpressions(), statements)); return super.visitCase(node, p); } }.scan(copy.getCompilationUnit(), null); @@ -499,7 +498,7 @@ public void run(final WorkingCopy copy) throws IOException { new ErrorAwareTreePathScanner() { @Override public Void visitCase(CaseTree node, Void p) { copy.rewrite(getCurrentPath().getLeaf(), - make.Case(TreeShims.getExpressions(node), node.getStatements().get(0))); + make.Case(node.getExpressions(), node.getStatements().get(0))); return super.visitCase(node, p); } }.scan(copy.getCompilationUnit(), null); @@ -549,7 +548,7 @@ public void run(final WorkingCopy copy) throws IOException { new ErrorAwareTreePathScanner() { @Override public Void visitCase(CaseTree node, Void p) { copy.rewrite(getCurrentPath().getLeaf(), - make.Case(TreeShims.getExpressions(node), node.getStatements().get(0))); + make.Case(node.getExpressions(), node.getStatements().get(0))); return super.visitCase(node, p); } }.scan(copy.getCompilationUnit(), null); @@ -602,7 +601,7 @@ public void run(final WorkingCopy copy) throws IOException { new ErrorAwareTreePathScanner() { @Override public Void visitCase(CaseTree node, Void p) { copy.rewrite(getCurrentPath().getLeaf(), - make.Case(TreeShims.getExpressions(node), make.Block(node.getStatements(), false))); + make.Case(node.getExpressions(), make.Block(node.getStatements(), false))); return super.visitCase(node, p); } }.scan(copy.getCompilationUnit(), null); diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java index 2ce8bf96d6e7..86b595a49776 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java @@ -2040,14 +2040,14 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " switch( i ){\n" + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " switch (i)\n" @@ -2055,7 +2055,7 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " switch (i)\n" @@ -2063,7 +2063,7 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " switch (i)\n" @@ -2071,14 +2071,14 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " switch (i) {\n" + " case 0:\n" + " System.out.println(i);\n" + " break;\n" - + " case default:\n" + + " default:\n" + " System.out.println(\"DEFAULT\");\n" + " }\n" + " }\n" @@ -2971,7 +2971,7 @@ public void testSwitchCaseParenthesizedBindingPattern() throws Exception { + " void testSwitchCaseParenthesizedBindingPattern() {\n" + " Object str = \"pattern matching switch\";\n" + " switch (str) {\n" - + " case (String s ) ->\n" + + " case (String s) ->\n" + " System.out.println(\"case with Parenthesized Binding Pattern formatting\");\n" + " default ->\n" + " System.out.println(\"default formatting\");\n" @@ -3020,7 +3020,7 @@ public void testSwitchCaseNullAndParenthesizedBindingPattern() throws Exception + " void testSwitchCaseNullAndParenthesizedBindingPattern() {\n" + " Object str = \"pattern matching switch\";\n" + " switch (str) {\n" - + " case null, (String s ) ->\n" + + " case null, (String s) ->\n" + " System.out.println(\"case with null and Parenthesized Binding Pattern formatting\");\n" + " default ->\n" + " System.out.println(\"default formatting\");\n" @@ -3071,7 +3071,7 @@ public void testSwitchCaseParenthesizedGuardedPattern() throws Exception { + " void testSwitchCaseParenthesizedGuardedPattern() {\n" + " Object str = \"pattern matching switch\";\n" + " switch (str) {\n" - + " case (String s && s.length() == 1 ) ->\n" + + " case (String s && s.length() == 1) ->\n" + " System.out.println(\"case with Parenthesized Guarded Pattern formatting\");\n" + " default ->\n" + " System.out.println(\"default formatting\");\n" @@ -3123,7 +3123,7 @@ public void testSwitchCaseParenthesizedGuardedPatternAndNull() throws Exception + " void testSwitchCaseParenthesizedGuardedPatternAndNull() {\n" + " Object str = \"pattern matching switch\";\n" + " switch (str) {\n" - + " case (String s && s.length() == 1 ) , null ->\n" + + " case (String s && s.length() == 1) , null ->\n" + " System.out.println(\"case with Parenthesized Binding Pattern formatting\");\n" + " default ->\n" + " System.out.println(\"default formatting\");\n" @@ -3175,7 +3175,7 @@ public void testSwitchCaseGuardedPatternNestedParenthesizedPatternWithNull() thr + " void testSwitchCaseGuardedPatternNestedParenthesizedPattern() {\n" + " Object str = \"pattern matching switch\";\n" + " switch (str) {\n" - + " case (String s ) && s.length() == 1 , null ->\n" + + " case (String s) && s.length() == 1 , null ->\n" + " System.out.println(\"SwitchCaseGuardedPatternNestedParenthesizedPattern\");\n" + " default ->\n" + " System.out.println(\"default formatting\");\n" @@ -3292,7 +3292,7 @@ public void testSwitchCaseAllPatterns() throws Exception { + " System.out.println(\"case with pattern matching + condition + lambda expression formatting\");\n" + " case String s && s.length() == 1 ->\n" + " System.out.println(\"case with pattern matching + condition formatting\");\n" - + " case (String s && true ) ->\n" + + " case (String s && true) ->\n" + " System.out.println(\"case with pattern matching + condition formatting\");\n" + " case CharSequence s ->\n" + " System.out.println(\"case with pattern matching formatting\");\n" @@ -3361,7 +3361,7 @@ public void testSwitchCaseAllPatternsWithReturnValue() throws Exception { + " \"case with pattern matching + condition + lambda expression formatting\";\n" + " case String s && s.length() == 1 ->\n" + " \"case with pattern matching + condition formatting\";\n" - + " case (String s && true ) ->\n" + + " case (String s && true) ->\n" + " \"case with pattern matching + condition formatting\";\n" + " case CharSequence s ->\n" + " \"case with pattern matching formatting\";\n" diff --git a/java/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java b/java/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java index 066a321bd4e5..82c292b33983 100644 --- a/java/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java +++ b/java/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java @@ -24,7 +24,6 @@ import java.awt.HeadlessException; import java.util.logging.Level; import java.util.prefs.Preferences; -import javax.lang.model.SourceVersion; import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.modules.autoupdate.ui.api.PluginManager; import org.netbeans.modules.java.source.usages.ClassIndexManager; @@ -66,7 +65,7 @@ public JBrowseModule() { " Please either:" + "
    " + "
  • install nb-javac library (highly recommended)
  • " + - "
  • run NetBeans on JDK 9 or later
  • " + + "
  • run NetBeans on JDK 17 or later
  • " + "
", "BN_Install=Install nb-javac", "DN_nbjavac=nb-javac library", @@ -99,7 +98,7 @@ public void restored() { prefs.putBoolean(KEY_WARNING_SHOWN, true); } - if (!NoJavacHelper.hasNbJavac() && !hasJDK14OrAboveJavac()) { + if (!NoJavacHelper.hasNbJavac()) { NotificationDisplayer.getDefault().notify("Install nb-javac Library", ImageUtilities.loadImageIcon(WARNING_ICON, false), Bundle.DESC_InstallNbJavac(), evt -> { PluginManager.installSingle("org.netbeans.modules.nbjavac", Bundle.DN_nbjavac()); }, prefs.getBoolean(KEY_WARNING_SHOWN, false) ? Priority.SILENT : Priority.HIGH); @@ -110,15 +109,6 @@ public void restored() { super.restored(); } - private boolean hasJDK14OrAboveJavac() { - try { - SourceVersion.valueOf("RELEASE_14"); - return true; - } catch (IllegalArgumentException ex) { - return false; - } - } - @Override public void close () { super.close(); diff --git a/java/jshell.support/src/org/netbeans/modules/jshell/editor/CompletionFilter.java b/java/jshell.support/src/org/netbeans/modules/jshell/editor/CompletionFilter.java index 56adfd1c5068..11969b4fb297 100644 --- a/java/jshell.support/src/org/netbeans/modules/jshell/editor/CompletionFilter.java +++ b/java/jshell.support/src/org/netbeans/modules/jshell/editor/CompletionFilter.java @@ -20,6 +20,7 @@ import com.sun.source.doctree.DocCommentTree; import com.sun.source.doctree.DocTree; +import com.sun.source.doctree.EntityTree; import com.sun.source.tree.CatchTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; @@ -242,6 +243,17 @@ public void printMessage(Diagnostic.Kind kind, CharSequence cs, Tree tree, Compi public TypeMirror getLub(CatchTree ct) { return delegate.getLub(ct); } + + @Override + public TypeMirror getType(DocTreePath path) { + return delegate.getType(path); + } + + @Override + public String getCharacters(EntityTree tree) { + return delegate.getCharacters(tree); + } + private DocTrees delegate; @Override diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBParserFactory.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBParserFactory.java index e9d5a0a72e2e..ab82f76bbae3 100644 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBParserFactory.java +++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBParserFactory.java @@ -116,13 +116,14 @@ protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) { } @Override - protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List typarams, boolean isInterface, boolean isVoid, Comment dc) { + protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List typarams, boolean isInterface, boolean isVoid, boolean isRecord, Comment dc) { if (cancelService != null) { cancelService.abortIfCanceled(); } - return super.methodDeclaratorRest(pos, mods, type, name, typarams, isInterface, isVoid, dc); + return super.methodDeclaratorRest(pos, mods, type, name, typarams, isInterface, isVoid, isRecord, dc); } + @Override public int getEndPos(JCTree jctree) { return TreeInfo.getEndPos(jctree, endPosTable); diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java index 21f09477c816..8b8472ae3c0a 100644 --- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java +++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java @@ -460,9 +460,6 @@ public Boolean reduce(Boolean r1, Boolean r2) { return (r1 == Boolean.TRUE || r2 == Boolean.TRUE); } }; - if (workingCopy.getTrees().getTree(el) == null) { - System.err.println("!!!"); - } Boolean needsArgument = needsArgumentScanner.scan(workingCopy.getTrees().getTree(el).getBody(), sourceType); if (needsArgument == Boolean.TRUE) { ExpressionTree newArgument; diff --git a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java index b41ef3717033..49fb0dda9f21 100644 --- a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java +++ b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java @@ -1365,34 +1365,8 @@ protected JCModifiers modifiersOpt(JCModifiers partial) { } - public JCVariableDecl formalParameter(boolean lambdaParam, boolean recordComponents) { - if (token.kind == TokenKind.IDENTIFIER) { - if (token.name().startsWith(dollar)) { - com.sun.tools.javac.util.Name name = token.name(); - - Token peeked = S.token(1); - - if (peeked.kind == TokenKind.COMMA || peeked.kind == TokenKind.RPAREN) { - nextToken(); - return JackpotTrees.createVariableWildcard(ctx, name); - } - } - } - JCTree.JCVariableDecl result = null; - try { - Class[] paramTypes = {boolean.class, boolean.class}; - result = (JCTree.JCVariableDecl) MethodHandles.lookup() - .findSpecial(JavacParser.class, "formalParameter", MethodType.methodType(JCTree.JCVariableDecl.class, paramTypes), JackpotJavacParser.class) // NOI18N - .invoke(this, lambdaParam, recordComponents); - } catch (Throwable ex) { - throw new IllegalStateException(ex); - } - return result; - - } - @Override - public JCVariableDecl formalParameter(boolean lambdaParam) { + public JCVariableDecl formalParameter(boolean lambdaParam, boolean recordComponents) { if (token.kind == TokenKind.IDENTIFIER) { if (token.name().startsWith(dollar)) { com.sun.tools.javac.util.Name name = token.name(); @@ -1405,8 +1379,7 @@ public JCVariableDecl formalParameter(boolean lambdaParam) { } } } - - return super.formalParameter(lambdaParam); + return super.formalParameter(lambdaParam, recordComponents); } @Override @@ -1448,6 +1421,7 @@ protected JCCatch catchClause() { return super.catchClause(); } + @Override public com.sun.tools.javac.util.List classOrInterfaceOrRecordBodyDeclaration(com.sun.tools.javac.util.Name className, boolean isInterface, boolean isRecord) { if (token.kind == TokenKind.IDENTIFIER) { @@ -1465,36 +1439,9 @@ public com.sun.tools.javac.util.List classOrInterfaceOrRecordBodyDeclara } } - com.sun.tools.javac.util.List result = null; - Class[] argsType = {com.sun.tools.javac.util.Name.class, boolean.class, boolean.class}; - try { - result = (com.sun.tools.javac.util.List) MethodHandles.lookup().findSpecial(JavacParser.class, "classOrInterfaceOrRecordBodyDeclaration", MethodType.methodType(com.sun.tools.javac.util.List.class, argsType), JackpotJavacParser.class) // NOI18N - .invoke(this, className, false, false); - } catch (Throwable ex) { - throw new IllegalStateException(ex); - } - return result; + return super.classOrInterfaceOrRecordBodyDeclaration(className, isInterface, isRecord); } - @Override - public com.sun.tools.javac.util.List classOrInterfaceBodyDeclaration(com.sun.tools.javac.util.Name className, boolean isInterface) { - if (token.kind == TokenKind.IDENTIFIER) { - if (token.name().startsWith(dollar)) { - com.sun.tools.javac.util.Name name = token.name(); - - Token peeked = S.token(1); - - if (peeked.kind == TokenKind.SEMI) { - nextToken(); - nextToken(); - - return com.sun.tools.javac.util.List.of(F.Ident(name)); - } - } - } - return super.classOrInterfaceBodyDeclaration(className, isInterface); - } - @Override protected JCExpression checkExprStat(JCExpression t) { if (t.getTag() == JCTree.Tag.IDENT) { diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps index 5358c4b6d420..4b775fcb0818 100644 --- a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps +++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps @@ -42,6 +42,10 @@ nbbuild/external/langtools-9.zip nbbuild/external/langtools-9.zip # Used to parse data during build, but need to as a lib for ide cluster nbbuild/external/json-simple-1.1.1.jar ide/libs.json_simple/external/json-simple-1.1.1.jar +# Compile only nb-javac +java/libs.nbjavacapi/external/nb-javac-jdk-17+35-api.jar nbbuild/external/nb-javac-jdk-17+35-api.jar +java/libs.nbjavacapi/external/nb-javac-jdk-17+35.jar nbbuild/external/nb-javac-jdk-17+35.jar + # JFlex is used by multiple modules. webcommon/javascript2.jade/external/jflex-1.4.3.jar webcommon/javascript2.lexer/external/jflex-1.4.3.jar diff --git a/nbbuild/build.xml b/nbbuild/build.xml index d3b906a1e6d8..887f735d7c12 100644 --- a/nbbuild/build.xml +++ b/nbbuild/build.xml @@ -240,38 +240,7 @@ metabuild.hash=${metabuild.hash} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -582,7 +551,6 @@ Hg ID: ${hg.id} - @@ -596,7 +564,6 @@ Hg ID: ${hg.id} - @@ -606,7 +573,6 @@ Hg ID: ${hg.id} - diff --git a/nbbuild/external/binaries-list b/nbbuild/external/binaries-list index a71d7d097cc1..0a7bdd9ec606 100644 --- a/nbbuild/external/binaries-list +++ b/nbbuild/external/binaries-list @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. 16398550402B27F81CD0D508CEF54B3E47A4A6DA org.apache.rat:apache-rat:0.12 -AB396EE119BFAD809CC9F09950CC22E2BCE2FE35 langtools-9.zip E32B3483FBF362C92088CB79E9F1F161F3F64A21 org.apidesign.javadoc:codesnippet-doclet:0.30 B8A142EBDE0CDC071A347B2E93C8548C2A5D09B0 org.netbeans.tools:sigtest-maven-plugin:1.4 C9AD4A0850AB676C5C64461A05CA524CDFFF59F1 com.googlecode.json-simple:json-simple:1.1.1 diff --git a/nbbuild/external/langtools-9-license.txt b/nbbuild/external/langtools-9-license.txt deleted file mode 100644 index 921004dd7caa..000000000000 --- a/nbbuild/external/langtools-9-license.txt +++ /dev/null @@ -1,356 +0,0 @@ -Name: Javac Compiler -Description: Javac Compiler -Version: 9 -License: GPL-2-CP -Origin: OpenJDK (http://hg.openjdk.java.net/) -Source: http://hg.openjdk.java.net/jdk9/jdk9/langtools/archive/tip.zip -Type: compile-time -Comment: Used at compile to compile code that runs either against JDK 9+ or (optional) nb-javac library. - -The GNU General Public License (GPL) - -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share -and change it. By contrast, the GNU General Public License is intended to -guarantee your freedom to share and change free software--to make sure the -software is free for all its users. This General Public License applies to -most of the Free Software Foundation's software and to any other program whose -authors commit to using it. (Some other Free Software Foundation software is -covered by the GNU Library General Public License instead.) You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our -General Public Licenses are designed to make sure that you have the freedom to -distribute copies of free software (and charge for this service if you wish), -that you receive source code or can get it if you want it, that you can change -the software or use pieces of it in new free programs; and that you know you -can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny -you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies of the -software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for -a fee, you must give the recipients all the rights that you have. You must -make sure that they, too, receive or can get the source code. And you must -show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) -offer you this license which gives you legal permission to copy, distribute -and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that -everyone understands that there is no warranty for this free software. If the -software is modified by someone else and passed on, we want its recipients to -know that what they have is not the original, so that any problems introduced -by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We -wish to avoid the danger that redistributors of a free program will -individually obtain patent licenses, in effect making the program proprietary. -To prevent this, we have made it clear that any patent must be licensed for -everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification -follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice -placed by the copyright holder saying it may be distributed under the terms of -this General Public License. The "Program", below, refers to any such program -or work, and a "work based on the Program" means either the Program or any -derivative work under copyright law: that is to say, a work containing the -Program or a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is included -without limitation in the term "modification".) Each licensee is addressed as -"you". - -Activities other than copying, distribution and modification are not covered by -this License; they are outside its scope. The act of running the Program is -not restricted, and the output from the Program is covered only if its contents -constitute a work based on the Program (independent of having been made by -running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as -you receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice and -disclaimer of warranty; keep intact all the notices that refer to this License -and to the absence of any warranty; and give any other recipients of the -Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may -at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus -forming a work based on the Program, and copy and distribute such modifications -or work under the terms of Section 1 above, provided that you also meet all of -these conditions: - - a) You must cause the modified files to carry prominent notices stating - that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or - in part contains or is derived from the Program or any part thereof, to be - licensed as a whole at no charge to all third parties under the terms of - this License. - - c) If the modified program normally reads commands interactively when run, - you must cause it, when started running for such interactive use in the - most ordinary way, to print or display an announcement including an - appropriate copyright notice and a notice that there is no warranty (or - else, saying that you provide a warranty) and that users may redistribute - the program under these conditions, and telling the user how to view a copy - of this License. (Exception: if the Program itself is interactive but does - not normally print such an announcement, your work based on the Program is - not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Program, and can be reasonably -considered independent and separate works in themselves, then this License, and -its terms, do not apply to those sections when you distribute them as separate -works. But when you distribute the same sections as part of a whole which is a -work based on the Program, the distribution of the whole must be on the terms -of this License, whose permissions for other licensees extend to the entire -whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your -rights to work written entirely by you; rather, the intent is to exercise the -right to control the distribution of derivative or collective works based on -the Program. - -In addition, mere aggregation of another work not based on the Program with the -Program (or with a work based on the Program) on a volume of a storage or -distribution medium does not bring the other work under the scope of this -License. - -3. You may copy and distribute the Program (or a work based on it, under -Section 2) in object code or executable form under the terms of Sections 1 and -2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source - code, which must be distributed under the terms of Sections 1 and 2 above - on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to - give any third party, for a charge no more than your cost of physically - performing source distribution, a complete machine-readable copy of the - corresponding source code, to be distributed under the terms of Sections 1 - and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to - distribute corresponding source code. (This alternative is allowed only - for noncommercial distribution and only if you received the program in - object code or executable form with such an offer, in accord with - Subsection b above.) - -The source code for a work means the preferred form of the work for making -modifications to it. For an executable work, complete source code means all -the source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the executable. However, as a special exception, the source code -distributed need not include anything that is normally distributed (in either -source or binary form) with the major components (compiler, kernel, and so on) -of the operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the source -code from the same place counts as distribution of the source code, even though -third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as -expressly provided under this License. Any attempt otherwise to copy, modify, -sublicense or distribute the Program is void, and will automatically terminate -your rights under this License. However, parties who have received copies, or -rights, from you under this License will not have their licenses terminated so -long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. -However, nothing else grants you permission to modify or distribute the Program -or its derivative works. These actions are prohibited by law if you do not -accept this License. Therefore, by modifying or distributing the Program (or -any work based on the Program), you indicate your acceptance of this License to -do so, and all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), -the recipient automatically receives a license from the original licensor to -copy, distribute or modify the Program subject to these terms and conditions. -You may not impose any further restrictions on the recipients' exercise of the -rights granted herein. You are not responsible for enforcing compliance by -third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), conditions -are imposed on you (whether by court order, agreement or otherwise) that -contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot distribute so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not distribute the Program at all. -For example, if a patent license would not permit royalty-free redistribution -of the Program by all those who receive copies directly or indirectly through -you, then the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply and -the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or -other property right claims or to contest validity of any such claims; this -section has the sole purpose of protecting the integrity of the free software -distribution system, which is implemented by public license practices. Many -people have made generous contributions to the wide range of software -distributed through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing to -distribute software through any other system and a licensee cannot impose that -choice. - -This section is intended to make thoroughly clear what is believed to be a -consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain -countries either by patents or by copyrighted interfaces, the original -copyright holder who places the Program under this License may add an explicit -geographical distribution limitation excluding those countries, so that -distribution is permitted only in or among countries not thus excluded. In -such case, this License incorporates the limitation as if written in the body -of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the -General Public License from time to time. Such new versions will be similar in -spirit to the present version, but may differ in detail to address new problems -or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any later -version", you have the option of following the terms and conditions either of -that version or of any later version published by the Free Software Foundation. -If the Program does not specify a version number of this License, you may -choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs -whose distribution conditions are different, write to the author to ask for -permission. For software which is copyrighted by the Free Software Foundation, -write to the Free Software Foundation; we sometimes make exceptions for this. -Our decision will be guided by the two goals of preserving the free status of -all derivatives of our free software and of promoting the sharing and reuse of -software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR -THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE -STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE -PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND -PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, -YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL -ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE -PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR -INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA -BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER -OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible -use to the public, the best way to achieve this is to make it free software -which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach -them to the start of each source file to most effectively convey the exclusion -of warranty; and each file should have at least the "copyright" line and a -pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - - Copyright (C) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it -starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes - with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free - software, and you are welcome to redistribute it under certain conditions; - type 'show c' for details. - -The hypothetical commands 'show w' and 'show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may be -called something other than 'show w' and 'show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, -if any, to sign a "copyright disclaimer" for the program, if necessary. Here -is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - 'Gnomovision' (which makes passes at compilers) written by James Hacker. - - signature of Ty Coon, 1 April 1989 - - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General Public -License instead of this License. - - -"CLASSPATH" EXCEPTION TO THE GPL - -Certain source files distributed by Oracle America and/or its affiliates are -subject to the following clarification and special exception to the GPL, but -only where Oracle has expressly included in the particular source file's header -the words "Oracle designates this particular file as subject to the "Classpath" -exception as provided by Oracle in the LICENSE file that accompanied this code." - - Linking this library statically or dynamically with other modules is making - a combined work based on this library. Thus, the terms and conditions of - the GNU General Public License cover the whole combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent modules, - and to copy and distribute the resulting executable under terms of your - choice, provided that you also meet, for each linked independent module, - the terms and conditions of the license of that module. An independent - module is a module which is not derived from or based on this library. If - you modify this library, you may extend this exception to your version of - the library, but you are not obligated to do so. If you do not wish to do - so, delete this exception statement from your version. diff --git a/nbbuild/templates/projectized.xml b/nbbuild/templates/projectized.xml index 6d640efb46c6..6d649fbda329 100644 --- a/nbbuild/templates/projectized.xml +++ b/nbbuild/templates/projectized.xml @@ -86,7 +86,7 @@ - + @@ -94,17 +94,14 @@ - - + - - - - + + @@ -124,14 +121,16 @@ - +