Skip to content

Commit 2d7c06e

Browse files
authored
Merge pull request #383 from Achal1607/upgrade-nb-25
Backport patches of NB-26
2 parents 419f2fd + 83e3f12 commit 2d7c06e

File tree

13 files changed

+2001
-4
lines changed

13 files changed

+2001
-4
lines changed

build.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
patches/7610.diff
4949
patches/8036-draft.diff
5050
patches/8038-draft.diff
51+
patches/8210.diff
52+
patches/8237.diff
53+
patches/8242.diff
54+
patches/8245.diff
55+
patches/8255.diff
56+
patches/8260.diff
57+
patches/8280.diff
58+
patches/8289.diff
5159
patches/mvn-sh.diff
5260
patches/project-marker-jdk.diff
5361
patches/generate-dependencies.diff

patches/8210.diff

Lines changed: 435 additions & 0 deletions
Large diffs are not rendered by default.

patches/8237.diff

Lines changed: 358 additions & 0 deletions
Large diffs are not rendered by default.

patches/8242.diff

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java
2+
index 4eb78d72617c..788c3055aa8a 100644
3+
--- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java
4+
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java
5+
@@ -39,6 +39,7 @@
6+
import java.util.Iterator;
7+
import java.util.List;
8+
import java.util.Map;
9+
+import java.util.Objects;
10+
import java.util.Set;
11+
import java.util.concurrent.Callable;
12+
import java.util.concurrent.CompletableFuture;
13+
@@ -824,6 +825,7 @@ public Completion createInitializeAllConstructorItem(CompilationInfo info, boole
14+
}
15+
labelDetail.append(") - generate");
16+
sortParams.append(')');
17+
+ ElementHandle<?> parentPath = ElementHandle.create(parent);
18+
return CompletionCollector.newBuilder(simpleName)
19+
.kind(Completion.Kind.Constructor)
20+
.labelDetail(labelDetail.toString())
21+
@@ -834,7 +836,11 @@ public Completion createInitializeAllConstructorItem(CompilationInfo info, boole
22+
wc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
23+
TreePath tp = wc.getTreeUtilities().pathFor(substitutionOffset);
24+
if (TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind())) {
25+
- if (parent == wc.getTrees().getElement(tp)) {
26+
+ Element currentType = wc.getTrees().getElement(tp);
27+
+ ElementHandle<?> currentTypePath =
28+
+ currentType != null ? ElementHandle.create(currentType)
29+
+ : null;
30+
+ if (Objects.equals(parentPath, currentTypePath)) {
31+
ArrayList<VariableElement> fieldElements = new ArrayList<>();
32+
for (VariableElement fieldElement : fields) {
33+
if (fieldElement != null && fieldElement.getKind().isField()) {
34+
diff --git a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCompletionCollectorTest.java b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCompletionCollectorTest.java
35+
index bc1e4bdb87cf..328a1b5bf62a 100644
36+
--- a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCompletionCollectorTest.java
37+
+++ b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaCompletionCollectorTest.java
38+
@@ -18,6 +18,7 @@
39+
*/
40+
package org.netbeans.modules.editor.java;
41+
42+
+import java.io.OutputStream;
43+
import java.util.ArrayList;
44+
import java.util.HashSet;
45+
import java.util.List;
46+
@@ -48,6 +49,8 @@
47+
48+
public class JavaCompletionCollectorTest extends NbTestCase {
49+
50+
+ private FileObject primaryTestFO;
51+
+
52+
public JavaCompletionCollectorTest(String name) {
53+
super(name);
54+
}
55+
@@ -299,21 +302,62 @@ public static Map<Object, Object> test() {
56+
assertEquals(Set.of("()"), found);
57+
}
58+
59+
+ public void testAdditionalEditsGenerateConstructorAfterReparse() throws Exception {
60+
+ AtomicBoolean found = new AtomicBoolean();
61+
+ runJavaCollector(List.of(new FileDescription("test/Test.java",
62+
+ """
63+
+ package test;
64+
+ public class Test {
65+
+ private final int i;
66+
+ |
67+
+ }
68+
+ """)),
69+
+ completions -> {
70+
+ for (Completion completion : completions) {
71+
+ if (completion.getLabel().equals("Test") &&
72+
+ "(int i) - generate".equals(completion.getLabelDetail())) {
73+
+ //force full reparse:
74+
+ byte[] content = primaryTestFO.asBytes();
75+
+ try (OutputStream out = primaryTestFO.getOutputStream()) {
76+
+ out.write(content);
77+
+ }
78+
+ assertEquals(null,
79+
+ completion.getInsertText());
80+
+ assertEquals("63-63:",
81+
+ textEdit2String(completion.getTextEdit()));
82+
+ assertEquals("""
83+
+ 59-59:
84+
+ public Test(int i) {
85+
+ this.i = i;
86+
+ }
87+
+ """.replace("\n", "\\n"),
88+
+ completion.getAdditionalTextEdits()
89+
+ .get()
90+
+ .stream()
91+
+ .map(JavaCompletionCollectorTest::textEdit2String)
92+
+ .collect(Collectors.joining(", ")));
93+
+ found.set(true);
94+
+ }
95+
+ }
96+
+ });
97+
+ assertTrue(found.get());
98+
+ }
99+
+
100+
private void runJavaCollector(List<FileDescription> files, Validator<List<Completion>> validator) throws Exception {
101+
SourceUtilsTestUtil.prepareTest(new String[]{"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[]{new MIMEResolverImpl(), new MIMEDataProvider()});
102+
103+
FileObject scratch = SourceUtilsTestUtil.makeScratchDir(this);
104+
FileObject cache = scratch.createFolder("cache");
105+
FileObject src = scratch.createFolder("src");
106+
- FileObject mainFile = null;
107+
+ primaryTestFO = null;
108+
int caretPosition = -1;
109+
110+
for (FileDescription testFile : files) {
111+
FileObject testFO = FileUtil.createData(src, testFile.fileName);
112+
String code = testFile.code;
113+
114+
- if (mainFile == null) {
115+
- mainFile = testFO;
116+
+ if (primaryTestFO == null) {
117+
+ primaryTestFO = testFO;
118+
caretPosition = code.indexOf('|');
119+
120+
assertTrue(caretPosition >= 0);
121+
@@ -324,16 +368,16 @@ private void runJavaCollector(List<FileDescription> files, Validator<List<Comple
122+
TestUtilities.copyStringToFile(testFO, code);
123+
}
124+
125+
- assertNotNull(mainFile);
126+
+ assertNotNull(primaryTestFO);
127+
128+
if (sourceLevel != null) {
129+
- SourceUtilsTestUtil.setSourceLevel(mainFile, sourceLevel);
130+
+ SourceUtilsTestUtil.setSourceLevel(primaryTestFO, sourceLevel);
131+
}
132+
133+
SourceUtilsTestUtil.prepareTest(src, FileUtil.createFolder(scratch, "test-build"), cache);
134+
SourceUtilsTestUtil.compileRecursively(src);
135+
136+
- EditorCookie ec = mainFile.getLookup().lookup(EditorCookie.class);
137+
+ EditorCookie ec = primaryTestFO.getLookup().lookup(EditorCookie.class);
138+
Document doc = ec.openDocument();
139+
JavaCompletionCollector collector = new JavaCompletionCollector();
140+
Context ctx = new Context(TriggerKind.Invoked, null);

patches/8245.diff

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
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
2+
index abb39db21f52..ab76a3d05889 100644
3+
--- a/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java
4+
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java
5+
@@ -1811,15 +1811,17 @@ public DeprecatedTree Deprecated(List<? extends DocTree> text) {
6+
}
7+
8+
public DocCommentTree DocComment(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
9+
- DCDocComment temp = docMake.at(NOPOS).newDocCommentTree(fullBody, tags);
10+
- return DocComment(temp.getFirstSentence(), temp.getBody(), temp.getBlockTags());
11+
+ return DocComment(HTML_JAVADOC_COMMENT, fullBody, tags);
12+
}
13+
14+
public DocCommentTree MarkdownDocComment(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
15+
- DCDocComment temp = docMake.at(NOPOS).newDocCommentTree(fullBody, tags);
16+
- return MarkdownDocComment(temp.getFirstSentence(), temp.getBody(), temp.getBlockTags());
17+
+ return DocComment(MARKDOWN_JAVADOC_COMMENT, fullBody, tags);
18+
}
19+
20+
+ private DocCommentTree DocComment(Comment comment, List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
21+
+ return docMake.at(NOPOS).newDocCommentTree(comment, fullBody, tags, Collections.emptyList(), Collections.emptyList());
22+
+ }
23+
+
24+
public DocTree Snippet(List<? extends DocTree> attributes, TextTree text){
25+
try {
26+
return (DocTree) docMake.getClass().getMethod("newSnippetTree", List.class, TextTree.class).invoke(docMake.at(NOPOS), attributes, text);
27+
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
28+
index 037eb8251775..8b77849102a8 100644
29+
--- a/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
30+
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
31+
@@ -45,6 +45,7 @@
32+
import com.sun.tools.javac.tree.DCTree.DCLink;
33+
import com.sun.tools.javac.tree.DCTree.DCLiteral;
34+
import com.sun.tools.javac.tree.DCTree.DCParam;
35+
+import com.sun.tools.javac.tree.DCTree.DCRawText;
36+
import com.sun.tools.javac.tree.DCTree.DCReference;
37+
import com.sun.tools.javac.tree.DCTree.DCReturn;
38+
import com.sun.tools.javac.tree.DCTree.DCSee;
39+
@@ -4722,6 +4723,9 @@ private int diffDocTree(DCDocComment doc, DCTree oldT, DCTree newT, int[] elemen
40+
case TEXT:
41+
localpointer = diffText(doc, (DCText)oldT, (DCText)newT, elementBounds);
42+
break;
43+
+ case MARKDOWN:
44+
+ localpointer = diffRawText(doc, (DCRawText)oldT, (DCRawText)newT, elementBounds);
45+
+ break;
46+
case AUTHOR:
47+
localpointer = diffAuthor(doc, (DCAuthor)oldT, (DCAuthor)newT, elementBounds);
48+
break;
49+
@@ -4944,6 +4948,15 @@ private int diffText(DCDocComment doc, DCText oldT, DCText newT, int[] elementBo
50+
return elementBounds[1];
51+
}
52+
53+
+ private int diffRawText(DCDocComment doc, DCTree.DCRawText oldT, DCTree.DCRawText newT, int[] elementBounds) {
54+
+ if(oldT.code.equals(newT.code)) {
55+
+ copyTo(elementBounds[0], elementBounds[1]);
56+
+ } else {
57+
+ printer.print(newT.code);
58+
+ }
59+
+ return elementBounds[1];
60+
+ }
61+
+
62+
private int diffAuthor(DCDocComment doc, DCAuthor oldT, DCAuthor newT, int[] elementBounds) {
63+
int localpointer = oldT.name.isEmpty()? elementBounds[1] : getOldPos(oldT.name.get(0), doc);
64+
copyTo(elementBounds[0], localpointer);
65+
diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/RewriteInCommentTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/RewriteInCommentTest.java
66+
index 5c3ce2e65646..5effccaf023d 100644
67+
--- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/RewriteInCommentTest.java
68+
+++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/RewriteInCommentTest.java
69+
@@ -18,6 +18,13 @@
70+
*/
71+
package org.netbeans.api.java.source.gen;
72+
73+
+import com.sun.source.doctree.DocCommentTree;
74+
+import com.sun.source.doctree.LinkTree;
75+
+import com.sun.source.doctree.RawTextTree;
76+
+import com.sun.source.doctree.ReferenceTree;
77+
+import com.sun.source.util.DocTreePath;
78+
+import com.sun.source.util.DocTreePathScanner;
79+
+import com.sun.source.util.TreePath;
80+
import java.io.File;
81+
import java.io.IOException;
82+
import org.netbeans.api.java.source.ModificationResult;
83+
@@ -134,7 +141,128 @@ public void run(WorkingCopy copy) throws Exception {
84+
85+
assertEquals(code.replace("test", "foo"), mr.getResultingSource(fo));
86+
}
87+
-
88+
+
89+
+ public void testDoNotBreakFormatting() throws Exception {
90+
+ File f = new File(getWorkDir(), "TestClass.java");
91+
+ String code = """
92+
+ package foo;
93+
+ /**
94+
+ * First line.
95+
+ * Test {@link #test}.
96+
+ */
97+
+ public class TestClass{
98+
+ }
99+
+ """;
100+
+ TestUtilities.copyStringToFile(f, code);
101+
+ FileObject fo = FileUtil.toFileObject(f);
102+
+ JavaSource javaSource = JavaSource.forFileObject(fo);
103+
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
104+
+
105+
+ public void run(WorkingCopy copy) throws Exception {
106+
+ copy.toPhase(Phase.RESOLVED);
107+
+
108+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
109+
+ copy.getCompilationUnit().getTypeDecls().get(0));
110+
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
111+
+
112+
+ new DocTreePathScanner<>() {
113+
+ @Override
114+
+ public Object visitReference(ReferenceTree rt, Object p) {
115+
+ copy.rewrite(topLevelClass.getLeaf(), rt, copy.getTreeMaker().Reference(null, "newName", null));
116+
+ return null;
117+
+ }
118+
+
119+
+ @Override
120+
+ public Object visitLink(LinkTree lt, Object p) {
121+
+ return super.visitLink(lt, p);
122+
+ }
123+
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
124+
+ }
125+
+ });
126+
+
127+
+ assertEquals(code.replace("test", "newName"), mr.getResultingSource(fo));
128+
+ }
129+
+
130+
+ public void testDoNotBreakFormattingMarkdown() throws Exception {
131+
+ File f = new File(getWorkDir(), "TestClass.java");
132+
+ String code = """
133+
+ package foo;
134+
+
135+
+ /// First line.
136+
+ /// Test {@link #test}.
137+
+ public class TestClass{
138+
+ }
139+
+ """;
140+
+ TestUtilities.copyStringToFile(f, code);
141+
+ FileObject fo = FileUtil.toFileObject(f);
142+
+ JavaSource javaSource = JavaSource.forFileObject(fo);
143+
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
144+
+
145+
+ public void run(WorkingCopy copy) throws Exception {
146+
+ copy.toPhase(Phase.RESOLVED);
147+
+
148+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
149+
+ copy.getCompilationUnit().getTypeDecls().get(0));
150+
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
151+
+
152+
+ new DocTreePathScanner<>() {
153+
+ @Override
154+
+ public Object visitReference(ReferenceTree rt, Object p) {
155+
+ copy.rewrite(topLevelClass.getLeaf(), rt, copy.getTreeMaker().Reference(null, "newName", null));
156+
+ return null;
157+
+ }
158+
+
159+
+ @Override
160+
+ public Object visitLink(LinkTree lt, Object p) {
161+
+ return super.visitLink(lt, p);
162+
+ }
163+
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
164+
+ }
165+
+ });
166+
+
167+
+ assertEquals(code.replace("test", "newName"), mr.getResultingSource(fo));
168+
+ }
169+
+
170+
+ public void testMarkdownChangeText() throws Exception {
171+
+ File f = new File(getWorkDir(), "TestClass.java");
172+
+ String code = """
173+
+ package foo;
174+
+
175+
+ /// First line.
176+
+ /// Second line.
177+
+ public class TestClass{
178+
+ }
179+
+ """;
180+
+ TestUtilities.copyStringToFile(f, code);
181+
+ FileObject fo = FileUtil.toFileObject(f);
182+
+ JavaSource javaSource = JavaSource.forFileObject(fo);
183+
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
184+
+
185+
+ public void run(WorkingCopy copy) throws Exception {
186+
+ copy.toPhase(Phase.RESOLVED);
187+
+
188+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
189+
+ copy.getCompilationUnit().getTypeDecls().get(0));
190+
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
191+
+
192+
+ new DocTreePathScanner<>() {
193+
+ @Override
194+
+ public Object visitDocComment(DocCommentTree dct, Object p) {
195+
+ //XXX: need to translate full body, as the split body has different split of the text trees, and the differ uses fullbody:
196+
+ return scan(dct.getFullBody(), p);
197+
+ }
198+
+ @Override
199+
+ public Object visitRawText(RawTextTree text, Object p) {
200+
+ copy.rewrite(topLevelClass.getLeaf(), text, copy.getTreeMaker().RawText(text.getContent().replace("line", "nueText")));
201+
+ return null;
202+
+ }
203+
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
204+
+ }
205+
+ });
206+
+
207+
+ assertEquals(code.replace("line", "nueText"), mr.getResultingSource(fo));
208+
+ }
209+
+
210+
String getGoldenPckg() {
211+
return "";
212+
}

0 commit comments

Comments
 (0)