Skip to content

Commit 0d0bfcf

Browse files
authored
Merge pull request #7377 from apache/delivery
Sync delivery to release220 for 22-rc4
2 parents 9f0aa24 + 26b10a0 commit 0d0bfcf

File tree

19 files changed

+109
-63
lines changed

19 files changed

+109
-63
lines changed

extide/gradle/nbproject/project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
file.reference.netbeans-gradle-tooling.jar=release/modules/gradle/netbeans-gradle-tooling.jar
1919
is.autoload=true
20-
javac.source=17
21-
javac.target=17
20+
javac.source=1.8
21+
javac.target=1.8
2222
javac.compilerargs=-Xlint -Xlint:-serial
2323
javadoc.arch=${basedir}/arch.xml
2424
javadoc.apichanges=${basedir}/apichanges.xml

extide/gradle/src/org/netbeans/modules/gradle/newproject/GradleInitPanelVisual.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void read(WizardDescriptor settings) {
228228

229229
if (settings.getProperty(PROP_JAVA_VERSIONS) != null) {
230230
List<Integer> javaVersions = (List<Integer>) settings.getProperty(PROP_JAVA_VERSIONS);
231-
DefaultComboBoxModel<Integer> versionModel = new DefaultComboBoxModel<>(javaVersions.toArray(Integer[]::new));
231+
DefaultComboBoxModel<Integer> versionModel = new DefaultComboBoxModel<>(javaVersions.toArray(new Integer[0]));
232232
cbJavaVersion.setModel(versionModel);
233233

234234
if (settings.getProperty(PROP_JAVA_VERSION) != null) {
@@ -241,7 +241,7 @@ void read(WizardDescriptor settings) {
241241

242242
if (settings.getProperty(PROP_TEST_FRAMEWORKS) != null) {
243243
List<TestFramework> testframeworks = (List<TestFramework>) settings.getProperty(PROP_TEST_FRAMEWORKS);
244-
DefaultComboBoxModel<TestFramework> frameworkModel = new DefaultComboBoxModel<>(testframeworks.toArray(TestFramework[]::new));
244+
DefaultComboBoxModel<TestFramework> frameworkModel = new DefaultComboBoxModel<>(testframeworks.toArray(new TestFramework[0]));
245245
cbTestFramework.setModel(frameworkModel);
246246
if (settings.getProperty(PROP_TEST_FRAMEWORK) != null) {
247247
cbTestFramework.setSelectedItem(settings.getProperty(PROP_TEST_FRAMEWORK));

extide/gradle/src/org/netbeans/modules/gradle/output/GradleProcessorFactory.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import java.io.File;
3434
import java.net.MalformedURLException;
3535
import java.net.URL;
36+
import java.util.Arrays;
37+
import java.util.Collections;
38+
import java.util.HashSet;
3639
import java.util.Set;
3740
import java.util.regex.Matcher;
3841
import java.util.regex.Pattern;
@@ -56,18 +59,18 @@ public class GradleProcessorFactory implements OutputProcessorFactory {
5659

5760
@Override
5861
public Set<? extends OutputProcessor> createOutputProcessors(RunConfig cfg) {
59-
return Set.of(
62+
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
6063
GRADLE_PROCESSOR,
6164
JAVAC_PROCESSOR,
6265
GROOVYC_PROCESSOR,
6366
new WarningModeAllProcessor(cfg)
64-
);
67+
)));
6568
}
6669

70+
private static final Pattern GRADLE_ERROR = Pattern.compile("(Build file|Script) '(.*)\\.gradle' line: ([0-9]+)");
6771

6872
public static final OutputProcessor GRADLE_PROCESSOR = new OutputProcessor() {
6973

70-
private static final Pattern GRADLE_ERROR = Pattern.compile("(Build file|Script) '(.*)\\.gradle' line: ([0-9]+)");
7174

7275
@Override
7376
public boolean processLine(OutputDisplayer out, String line) {
@@ -90,9 +93,9 @@ public boolean processLine(OutputDisplayer out, String line) {
9093
}
9194
};
9295

93-
public static final OutputProcessor JAVAC_PROCESSOR = new OutputProcessor() {
96+
private static final Pattern JAVA_ERROR = Pattern.compile("(.*)\\.java\\:([0-9]+)\\: (error|warning)\\:(.*)");
9497

95-
private static final Pattern JAVA_ERROR = Pattern.compile("(.*)\\.java\\:([0-9]+)\\: (error|warning)\\:(.*)");
98+
public static final OutputProcessor JAVAC_PROCESSOR = new OutputProcessor() {
9699

97100
@Override
98101
public boolean processLine(OutputDisplayer out, String line) {
@@ -118,10 +121,10 @@ public boolean processLine(OutputDisplayer out, String line) {
118121
}
119122
};
120123

121-
public static final OutputProcessor GROOVYC_PROCESSOR = new OutputProcessor() {
124+
private static final Pattern GROOVY_ERROR = Pattern.compile("(.*)\\.groovy\\: ([0-9]+)\\: (.+)");
125+
private static final Pattern COLUMN_INFO = Pattern.compile(" @ line ([0-9]+), column ([0-9]+)\\.$");
122126

123-
private static final Pattern GROOVY_ERROR = Pattern.compile("(.*)\\.groovy\\: ([0-9]+)\\: (.+)");
124-
private static final Pattern COLUMN_INFO = Pattern.compile(" @ line ([0-9]+), column ([0-9]+)\\.$");
127+
public static final OutputProcessor GROOVYC_PROCESSOR = new OutputProcessor() {
125128

126129
@Override
127130
public boolean processLine(OutputDisplayer out, String line) {
@@ -156,9 +159,9 @@ public boolean processLine(OutputDisplayer out, String line) {
156159

157160
};
158161

159-
public static final OutputProcessor URL_PROCESSOR = new OutputProcessor() {
162+
private static final Pattern URL_PATTERN = Pattern.compile("(((https?|ftp|file)://|file:/)[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])");
160163

161-
private static final Pattern URL_PATTERN = Pattern.compile("(((https?|ftp|file)://|file:/)[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])");
164+
public static final OutputProcessor URL_PROCESSOR = new OutputProcessor() {
162165

163166
@Override
164167
public boolean processLine(OutputDisplayer out, String line) {

extide/gradle/src/org/netbeans/modules/gradle/spi/newproject/GradleInitWizard.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
package org.netbeans.modules.gradle.spi.newproject;
2020

2121
import java.io.File;
22+
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.stream.Collectors;
2426
import org.netbeans.modules.gradle.newproject.GradleInitPanel;
2527
import org.netbeans.spi.project.ui.support.CommonProjectActions;
2628
import org.openide.WizardDescriptor;
@@ -49,10 +51,11 @@ public enum GradleDSL {
4951

5052
@Override
5153
public String toString() {
52-
return switch(this) {
53-
case GROOVY -> Bundle.LBL_DSL_GROOVY();
54-
case KOTLIN -> Bundle.LBL_DSL_KOTLIN();
55-
};
54+
switch(this) {
55+
case GROOVY: return Bundle.LBL_DSL_GROOVY();
56+
case KOTLIN: return Bundle.LBL_DSL_KOTLIN();
57+
default: throw new IllegalStateException("update switch");
58+
}
5659
}
5760
}
5861

@@ -88,16 +91,17 @@ public String getId() {
8891

8992
@Override
9093
public String toString() {
91-
return switch(this) {
92-
case CPP_TEST -> Bundle.LBL_TFW_CPP_TEST();
93-
case JUNIT -> Bundle.LBL_TFW_JUNIT();
94-
case JUNIT_5 -> Bundle.LBL_TFW_JUNIT_5();
95-
case KOTLIN_TEST -> Bundle.LBL_TFW_KOTLIN_TEST();
96-
case SCALA_TEST -> Bundle.LBL_TFW_SCALA_TEST();
97-
case SPOCK -> Bundle.LBL_TFW_SPOCK();
98-
case TESTNG -> Bundle.LBL_TFW_TESTNG();
99-
case XCTEST -> Bundle.LBL_TFW_XCTEST();
100-
};
94+
switch(this) {
95+
case CPP_TEST: return Bundle.LBL_TFW_CPP_TEST();
96+
case JUNIT: return Bundle.LBL_TFW_JUNIT();
97+
case JUNIT_5: return Bundle.LBL_TFW_JUNIT_5();
98+
case KOTLIN_TEST: return Bundle.LBL_TFW_KOTLIN_TEST();
99+
case SCALA_TEST: return Bundle.LBL_TFW_SCALA_TEST();
100+
case SPOCK: return Bundle.LBL_TFW_SPOCK();
101+
case TESTNG: return Bundle.LBL_TFW_TESTNG();
102+
case XCTEST: return Bundle.LBL_TFW_XCTEST();
103+
default: throw new IllegalStateException("update switch");
104+
}
101105
}
102106
}
103107

@@ -108,7 +112,7 @@ public String toString() {
108112
private TestFramework preferredTestFramework;
109113
private List<Integer> javaVersions;
110114
private List<TestFramework> testFrameworks;
111-
private List<String> important = List.of();
115+
private List<String> important = Collections.emptyList();
112116

113117
private GradleInitWizard(String type, String title) {
114118
this.type = type;
@@ -211,14 +215,14 @@ protected void collectOperations(TemplateOperation ops, Map<String, Object> para
211215
List<String> open = important.stream()
212216
.map((s) -> packageBase != null ? s.replace("${package}", packageBase.replace('.', '/')) : s) //NOI18N
213217
.map((s) -> s.replace("${projectName}", name)) //NOI18N
214-
.toList();
218+
.collect(Collectors.toList());
215219
ops.addProjectPreload(root, open);
216220
}
217221

218222

219223
@Override
220224
protected List<? extends WizardDescriptor.Panel<WizardDescriptor>> createPanels() {
221-
return List.of(new GradleInitPanel());
225+
return Collections.singletonList(new GradleInitPanel());
222226
}
223227

224228
@Override

extide/gradle/src/org/netbeans/modules/gradle/spi/newproject/TemplateOperation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.File;
2424
import java.io.IOException;
2525
import java.io.InputStreamReader;
26+
import java.io.OutputStream;
2627
import java.io.OutputStreamWriter;
2728
import java.io.Reader;
2829
import java.io.Writer;
@@ -353,8 +354,8 @@ public Set<FileObject> execute() {
353354
args.add("--use-defaults");
354355

355356
try (
356-
var out = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, false));
357-
var err = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, false))
357+
OutputStream out = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, false));
358+
OutputStream err = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, false))
358359
) {
359360
BuildLauncher gradleInit = pconn.newBuild().forTasks(args.toArray(new String[0]));
360361
if (GradleSettings.getDefault().isOffline()) {
@@ -488,7 +489,7 @@ private static final class PreloadProject extends BaseOperationStep {
488489
final List<String> importantFiles;
489490

490491
public PreloadProject(File dir) {
491-
this(dir, List.of());
492+
this(dir, Collections.emptyList());
492493
}
493494

494495
public PreloadProject(File dir, List<String> importantFiles) {

ide/terminal.nb/src/org/netbeans/modules/terminal/nb/actions/CloseAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
@ActionRegistration(displayName = "#CTL_Close", lazy = true) //NOI18N
3535
@ActionReferences({
3636
@ActionReference(path = ActionFactory.ACTIONS_PATH, name = "CloseAction"), //NOI18N
37-
@ActionReference(path = "Shortcuts", name = "CS-W")
3837
})
3938
public final class CloseAction extends TerminalAction {
4039

java/java.editor/src/org/netbeans/modules/java/editor/imports/ComputeImports.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,20 @@ public Void visitIdentifier(IdentifierTree tree, Map<String, Object> p) {
596596
}
597597
}
598598

599-
if (type != null && type.getKind() == TypeKind.PACKAGE) {
599+
if (type.getKind() == TypeKind.PACKAGE) {
600+
TreePath parent = getCurrentPath().getParentPath();
601+
Element fullPackage = el;
602+
while (parent != null) {
603+
Element parentElement = info.getTrees().getElement(parent);
604+
if (parentElement != null && parentElement.getKind() == ElementKind.PACKAGE) {
605+
fullPackage = parentElement;
606+
parent = parent.getParentPath();
607+
} else {
608+
break;
609+
}
610+
}
600611
//does the package really exists?
601-
String s = ((PackageElement) el).getQualifiedName().toString();
612+
String s = ((PackageElement) fullPackage).getQualifiedName().toString();
602613
Element thisPack = info.getTrees().getElement(new TreePath(info.getCompilationUnit()));
603614
ModuleElement module = thisPack != null ? info.getElements().getModuleOf(thisPack) : null;
604615
PackageElement pack = module != null ? info.getElements().getPackageElement(module, s) : info.getElements().getPackageElement(s);

java/java.editor/test/unit/src/org/netbeans/modules/java/editor/imports/ComputeImportsTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727
import java.io.InputStreamReader;
2828
import java.io.OutputStream;
2929
import java.io.OutputStreamWriter;
30-
import java.io.PrintStream;
3130
import java.io.Reader;
3231
import java.io.StringWriter;
3332
import java.io.Writer;
3433
import java.nio.charset.StandardCharsets;
3534
import java.util.ArrayList;
3635
import java.util.Arrays;
3736
import java.util.Collections;
38-
import java.util.Comparator;
3937
import java.util.HashSet;
4038
import java.util.LinkedList;
4139
import java.util.List;
@@ -308,6 +306,26 @@ public void testRecordImport() throws Exception {
308306
"");
309307
}
310308

309+
// https://github.com/apache/netbeans/issues/7073
310+
public void testDontImportRootPackageMatchingMember() throws Exception {
311+
doTest("test/Test",
312+
"11",
313+
Arrays.asList(
314+
new FileData("test/Test.java",
315+
"package test;\n" +
316+
"import java.util.List;\n" +
317+
"public class Test {\n" +
318+
" public static class SomeClass {\n" +
319+
" public static Object java(java.util.Map<String, String> value) {\n" +
320+
" return value;\n" +
321+
" }\n" +
322+
" }\n" +
323+
"}")
324+
),
325+
"",
326+
"");
327+
}
328+
311329
private void prepareTest(String capitalizedName, String sourceLevel, Iterable<FileData> files) throws Exception {
312330
FileObject workFO = FileUtil.toFileObject(getWorkDir());
313331

java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,14 @@ private PathFinder(int pos, SourcePositions sourcePositions) {
358358

359359
public Void scan(Tree tree, Void p) {
360360
if (tree != null) {
361+
long startPos = sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree);
361362
long endPos = sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), tree);
362363
if (endPos == (-1)) {
363364
switch (tree.getKind()) {
364365
case ASSIGNMENT:
365366
if (getCurrentPath().getLeaf().getKind() == Kind.ANNOTATION) {
366367
ExpressionTree value = ((AssignmentTree) tree).getExpression();
368+
startPos = sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), value);
367369
endPos = sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), value);
368370
}
369371
break;
@@ -376,7 +378,7 @@ public Void scan(Tree tree, Void p) {
376378
break;
377379
}
378380
}
379-
if (sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree) < pos && endPos >= pos) {
381+
if (startPos < pos && endPos >= pos) {
380382
if (tree.getKind() == Tree.Kind.ERRONEOUS) {
381383
tree.accept(this, p);
382384
throw new Result(getCurrentPath());

java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,15 @@ public void testAnnotationSyntheticValue3() throws Exception {
420420
assertEquals(Kind.MEMBER_SELECT, tp.getLeaf().getKind());
421421
assertEquals("Test.VALUE", tp.getLeaf().toString());
422422
}
423+
424+
public void testAnnotationSyntheticValue4() throws Exception {
425+
prepareTest("Test", "package test; @Meta(String.class) public class Test { } @interface Meta { public Class value(); }");
426+
427+
TreePath tp = info.getTreeUtilities().pathFor(24);
428+
429+
assertEquals(Kind.IDENTIFIER, tp.getLeaf().getKind());
430+
assertEquals("String", tp.getLeaf().toString());
431+
}
423432

424433
public void testAutoMapComments1() throws Exception {
425434
prepareTest("Test", "package test;\n" +

0 commit comments

Comments
 (0)