Skip to content

Commit

Permalink
Update nb-javac to 19+33. (apache#4467)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalek authored Sep 13, 2022
1 parent c8807bb commit e660cc7
Show file tree
Hide file tree
Showing 41 changed files with 427 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
run: tar --zstd -xf build.tar.zst

- name: Setup Xvfb
if: ${{ matrix.java != '19-ea' }} # see #4299
if: ${{ matrix.java != '20-ea' }} # see #4299
run: |
echo "DISPLAY=:99.0" >> $GITHUB_ENV
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ meth public abstract {com.sun.source.tree.TreeVisitor%0} visitErroneous(com.sun.
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitExports(com.sun.source.tree.ExportsTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitForLoop(com.sun.source.tree.ForLoopTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitGuardedPattern(com.sun.source.tree.GuardedPatternTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitIdentifier(com.sun.source.tree.IdentifierTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitIf(com.sun.source.tree.IfTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitImport(com.sun.source.tree.ImportTree,{com.sun.source.tree.TreeVisitor%1})
Expand Down Expand Up @@ -108,7 +107,6 @@ meth public {com.sun.source.util.TreeScanner%0} visitErroneous(com.sun.source.tr
meth public {com.sun.source.util.TreeScanner%0} visitExports(com.sun.source.tree.ExportsTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitForLoop(com.sun.source.tree.ForLoopTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitGuardedPattern(com.sun.source.tree.GuardedPatternTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitIdentifier(com.sun.source.tree.IdentifierTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitIf(com.sun.source.tree.IfTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitImport(com.sun.source.tree.ImportTree,{com.sun.source.util.TreeScanner%1})
Expand Down
2 changes: 1 addition & 1 deletion java/debugger.jpda/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ javac.source=1.8
javadoc.arch=${basedir}/arch.xml
jpda.classes.dir=${build.dir}/jpda/classes/
requires.nb.javac=true
spec.version.base=1.126.0
spec.version.base=1.127.0
test-unit-sys-prop.test.dir.src=${basedir}/test/unit/src/
test-unit-sys-prop.netbeans.user=${basedir}/work/nb_user_dir
test.unit.cp.extra=../java.source.nbjavac/build/test-nb-javac/cluster/modules/org-netbeans-modules-java-source-nbjavac-test.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void op(int a) {
String result = switch (obj) {
case null, String ->
"null & String";
case CharSequence s && s. && obj. && IntStream.of(1).max().->
case CharSequence s when s. && obj. && IntStream.of(1).max().->
"CharSequence";
case (java.util.List list && list. && new StringBuilder().ERROR. && java.util.ArrayList<String>.)->"list";
case (java.util.List list when list. && new StringBuilder().ERROR. && java.util.ArrayList<String>.)->"list";
default ->
"default";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ public void testVariableNameSuggestion() throws Exception {

public void testClassMembersAutoCompletion_GuardedPattern() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
performTest("SwitchPatternMatching", 1085, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch.pass", getLatestSource());
performTest("SwitchPatternMatching", 1087, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch.pass", getLatestSource());
}

public void testClassMembersAutoCompletion_GuardedPattern_1() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
performTest("SwitchPatternMatching", 1093, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_1.pass", getLatestSource());
performTest("SwitchPatternMatching", 1095, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_1.pass", getLatestSource());
}
public void testClassMembersAutoCompletion_GuardedPattern_2() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
performTest("SwitchPatternMatching", 1113, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_2.pass", getLatestSource());
performTest("SwitchPatternMatching", 1115, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_2.pass", getLatestSource());
}
public void testClassMembersAutoCompletion_ParanthesizedPattern() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
performTest("SwitchPatternMatching", 1200, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch.pass", getLatestSource());
performTest("SwitchPatternMatching", 1204, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch.pass", getLatestSource());
}
public void testClassMembersAutoCompletion_ParanthesizedPattern_1() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
performTest("SwitchPatternMatching", 1224, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch_1.pass", getLatestSource());
performTest("SwitchPatternMatching", 1228, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch_1.pass", getLatestSource());
}
public void noop() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.netbeans.modules.editor.java;

import com.sun.source.tree.CaseLabelTree;
import com.sun.source.tree.Tree;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -112,12 +113,23 @@ public void run(ResultIterator resultIterator) throws Exception {
}
treeKindCtx = tree.getKind();
switch (treeKindCtx) {
case CASE:
if (so < controller.getTrees().getSourcePositions().getEndPosition(controller.getCompilationUnit(), ((CaseTree)tree).getExpression())) {
case CASE: {
if (((CaseTree)tree).getCaseKind() == CaseTree.CaseKind.RULE) {
treeKindCtx = null;
} else {
SourcePositions sp = controller.getTrees().getSourcePositions();
List<? extends CaseLabelTree> labels = ((CaseTree)tree).getLabels();
int startPos = labels.isEmpty() ? (int) sp.getEndPosition(controller.getCompilationUnit(), labels.get(labels.size() - 1))
: (int)sp.getStartPosition(controller.getCompilationUnit(), tree);
String headerText = controller.getText().substring(startPos, so);
int idx = headerText.indexOf(':');
if (idx < 0) {
treeKindCtx = null;
}
}
break;
case CLASS:
}
case CLASS: {
SourcePositions sp = controller.getTrees().getSourcePositions();
int startPos = (int)sp.getEndPosition(controller.getCompilationUnit(), ((ClassTree)tree).getModifiers());
if (startPos <= 0) {
Expand All @@ -130,6 +142,7 @@ public void run(ResultIterator resultIterator) throws Exception {
stringCtx = CLASS_HEADER;
}
break;
}
case FOR_LOOP:
case ENHANCED_FOR_LOOP:
if (!isRightParenthesisOfLoopPresent(controller, so)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sun.source.tree.CaseTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ConditionalExpressionTree;
import com.sun.source.tree.ConstantCaseLabelTree;
import com.sun.source.tree.ContinueTree;
import com.sun.source.tree.DoWhileLoopTree;
import com.sun.source.tree.EnhancedForLoopTree;
Expand Down Expand Up @@ -550,6 +551,11 @@ public State visitSwitch(SwitchTree node, Void p) {
}
}

@Override
public State visitConstantCaseLabel(ConstantCaseLabelTree node, Void p) {
return super.scan(node.getConstantExpression(), p);
}

@Override
public State visitEnhancedForLoop(EnhancedForLoopTree node, Void p) {
State s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.CompoundAssignmentTree;
import com.sun.source.tree.ConditionalExpressionTree;
import com.sun.source.tree.ConstantCaseLabelTree;
import com.sun.source.tree.ContinueTree;
import com.sun.source.tree.DeconstructionPatternTree;
import com.sun.source.tree.DefaultCaseLabelTree;
import com.sun.source.tree.DoWhileLoopTree;
import com.sun.source.tree.EmptyStatementTree;
Expand All @@ -44,7 +46,6 @@
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;
Expand All @@ -66,6 +67,7 @@
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.ParenthesizedPatternTree;
import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.PatternCaseLabelTree;
import com.sun.source.tree.PrimitiveTypeTree;
import com.sun.source.tree.ProvidesTree;
import com.sun.source.tree.RequiresTree;
Expand Down Expand Up @@ -110,7 +112,6 @@
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.UnionType;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.ElementFilter;
Expand Down Expand Up @@ -1416,7 +1417,17 @@ public List<? extends TypeMirror> visitDefaultCaseLabel(DefaultCaseLabelTree nod
}

@Override
public List<? extends TypeMirror> visitGuardedPattern(GuardedPatternTree node, Object p) {
public List<? extends TypeMirror> visitConstantCaseLabel(ConstantCaseLabelTree node, Object p) {
return null;
}

@Override
public List<? extends TypeMirror> visitPatternCaseLabel(PatternCaseLabelTree node, Object p) {
return null;
}

@Override
public List<? extends TypeMirror> visitDeconstructionPattern(DeconstructionPatternTree node, Object p) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@ public void testSwitchToRuleSwitchGuardedPattern() throws Exception {
HintTest.create()
.input("package test;" +
"public class Test {\n" +
" private void test(int p) {\n" +
" private void test(Object p) {\n" +
" String result;\n" +
" switch (p) {\n" +
" case Integer i && (i > 10): result = \"a\"; break;\n" +
" case Integer i when (i > 10): result = \"a\"; break;\n" +
" default: System.err.println(\"No.\"); break;\n" +
" }\n" +
" }\n" +
Expand All @@ -1003,10 +1003,10 @@ public void testSwitchToRuleSwitchGuardedPattern() throws Exception {
.assertCompilable()
.assertVerbatimOutput("package test;" +
"public class Test {\n" +
" private void test(int p) {\n" +
" private void test(Object p) {\n" +
" String result;\n" +
" switch (p) {\n" +
" case Integer i && (i > 10) -> result = \"a\";\n" +
" case Integer i when (i > 10) -> result = \"a\";\n" +
" default -> System.err.println(\"No.\");\n" +
" }\n" +
" }\n" +
Expand All @@ -1025,7 +1025,7 @@ public void testSwitchExpressionGuardedPattern() throws Exception {
+ "class Test {\n"
+ " public String test(Object p, Object o1, Object o2) {\n"
+ " switch (p) {\n"
+ " case (Integer i && (i > 10)):\n"
+ " case (Integer i) when (i > 10):\n"
+ " return (String) o1;\n"
+ " default :\n"
+ " return (String) o2;\n"
Expand All @@ -1042,7 +1042,7 @@ public void testSwitchExpressionGuardedPattern() throws Exception {
+ "class Test {\n"
+ " public String test(Object p, Object o1, Object o2) {\n"
+ " return (String) (switch (p) {\n"
+ " case (Integer i && (i > 10)) -> o1;\n"
+ " case (Integer i) when (i > 10) -> o1;\n"
+ " default -> o2;\n"
+ " });\n"
+ " }\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ meth public abstract {com.sun.source.tree.TreeVisitor%0} visitErroneous(com.sun.
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitExports(com.sun.source.tree.ExportsTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitForLoop(com.sun.source.tree.ForLoopTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitGuardedPattern(com.sun.source.tree.GuardedPatternTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitIdentifier(com.sun.source.tree.IdentifierTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitIf(com.sun.source.tree.IfTree,{com.sun.source.tree.TreeVisitor%1})
meth public abstract {com.sun.source.tree.TreeVisitor%0} visitImport(com.sun.source.tree.ImportTree,{com.sun.source.tree.TreeVisitor%1})
Expand Down Expand Up @@ -108,7 +107,6 @@ meth public {com.sun.source.util.TreeScanner%0} visitErroneous(com.sun.source.tr
meth public {com.sun.source.util.TreeScanner%0} visitExports(com.sun.source.tree.ExportsTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitForLoop(com.sun.source.tree.ForLoopTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitGuardedPattern(com.sun.source.tree.GuardedPatternTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitIdentifier(com.sun.source.tree.IdentifierTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitIf(com.sun.source.tree.IfTree,{com.sun.source.util.TreeScanner%1})
meth public {com.sun.source.util.TreeScanner%0} visitImport(com.sun.source.tree.ImportTree,{com.sun.source.util.TreeScanner%1})
Expand Down
2 changes: 1 addition & 1 deletion java/java.source.base/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ javadoc.name=Java Source Base
javadoc.title=Java Source Base
javadoc.arch=${basedir}/arch.xml
javadoc.apichanges=${basedir}/apichanges.xml
spec.version.base=2.58.0
spec.version.base=2.59.0
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
${o.n.core.dir}/lib/boot.jar:\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.sun.source.tree.CaseTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.ConstantCaseLabelTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodTree;
Expand Down Expand Up @@ -79,7 +80,7 @@ public Void visitIdentifier(IdentifierTree node, Void p) {
|| (element.getKind().isField() && ((Symbol) element).isStatic())) {
Tree parent = path.getParentPath() != null ? path.getParentPath().getLeaf() : null;

if ( (parent != null && parent.getKind() == Kind.CASE && ((CaseTree) parent).getExpression() == node && element.getKind() == ElementKind.ENUM_CONSTANT)
if ( (parent != null && parent.getKind() == Kind.CONSTANT_CASE_LABEL && ((ConstantCaseLabelTree) parent).getConstantExpression() == node && element.getKind() == ElementKind.ENUM_CONSTANT)
|| (path.getCompilationUnit() != null && ((Symbol) element).enclClass() != null && path.getCompilationUnit().getSourceFile() == ((Symbol) element).enclClass().sourcefile)) {
translateMap.put(node, make.Identifier(element.getSimpleName()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public CaseTree Case(List<? extends ExpressionTree> patterns, Tree body) {
* @since 2.39
*/
public CaseTree CasePatterns(List<? extends Tree> patterns, Tree body) {
return delegate.CaseMultiplePatterns(patterns.stream().map(p -> (CaseLabelTree) p).collect(Collectors.toList()), body);
return delegate.CaseMultiplePatterns(toCaseLabelTrees(patterns), body);
}

/**
Expand All @@ -288,7 +288,22 @@ public CaseTree CasePatterns(List<? extends Tree> patterns, Tree body) {
* @since 2.39
*/
public CaseTree CasePatterns(List<? extends Tree> patterns, List<? extends StatementTree> statements) {
return delegate.CaseMultiplePatterns(patterns.stream().map(p -> (CaseLabelTree) p).collect(Collectors.toList()), statements);
return delegate.CaseMultiplePatterns(toCaseLabelTrees(patterns), statements);
}

private List<? extends CaseLabelTree> toCaseLabelTrees(List<? extends Tree> patterns) {
return patterns.stream().map(p -> {
if (p instanceof CaseLabelTree) {
return (CaseLabelTree) p;
}
if (p instanceof ExpressionTree) {
return delegate.ConstantCaseLabel((ExpressionTree) p);
}
if (p instanceof PatternTree) {
return delegate.PatternCaseLabel((PatternTree) p, null);
}
throw new IllegalArgumentException("Invalid pattern kind: " + p.getKind()); //NOI18N
}).collect(Collectors.toList());
}

/**
Expand Down
Loading

0 comments on commit e660cc7

Please sign in to comment.