Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
patches/7610.diff
patches/8036-draft.diff
patches/8038-draft.diff
patches/8210.diff
patches/8237.diff
patches/8242.diff
patches/8245.diff
patches/8255.diff
patches/8260.diff
patches/8280.diff
patches/8289.diff
patches/mvn-sh.diff
patches/project-marker-jdk.diff
patches/generate-dependencies.diff
Expand Down
435 changes: 435 additions & 0 deletions patches/8210.diff

Large diffs are not rendered by default.

358 changes: 358 additions & 0 deletions patches/8237.diff

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions patches/8242.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
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
index 4eb78d72617c..788c3055aa8a 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java
@@ -39,6 +39,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
@@ -824,6 +825,7 @@ public Completion createInitializeAllConstructorItem(CompilationInfo info, boole
}
labelDetail.append(") - generate");
sortParams.append(')');
+ ElementHandle<?> parentPath = ElementHandle.create(parent);
return CompletionCollector.newBuilder(simpleName)
.kind(Completion.Kind.Constructor)
.labelDetail(labelDetail.toString())
@@ -834,7 +836,11 @@ public Completion createInitializeAllConstructorItem(CompilationInfo info, boole
wc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
TreePath tp = wc.getTreeUtilities().pathFor(substitutionOffset);
if (TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind())) {
- if (parent == wc.getTrees().getElement(tp)) {
+ Element currentType = wc.getTrees().getElement(tp);
+ ElementHandle<?> currentTypePath =
+ currentType != null ? ElementHandle.create(currentType)
+ : null;
+ if (Objects.equals(parentPath, currentTypePath)) {
ArrayList<VariableElement> fieldElements = new ArrayList<>();
for (VariableElement fieldElement : fields) {
if (fieldElement != null && fieldElement.getKind().isField()) {
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
index bc1e4bdb87cf..328a1b5bf62a 100644
--- 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
@@ -18,6 +18,7 @@
*/
package org.netbeans.modules.editor.java;

+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -48,6 +49,8 @@

public class JavaCompletionCollectorTest extends NbTestCase {

+ private FileObject primaryTestFO;
+
public JavaCompletionCollectorTest(String name) {
super(name);
}
@@ -299,21 +302,62 @@ public static Map<Object, Object> test() {
assertEquals(Set.of("()"), found);
}

+ public void testAdditionalEditsGenerateConstructorAfterReparse() throws Exception {
+ AtomicBoolean found = new AtomicBoolean();
+ runJavaCollector(List.of(new FileDescription("test/Test.java",
+ """
+ package test;
+ public class Test {
+ private final int i;
+ |
+ }
+ """)),
+ completions -> {
+ for (Completion completion : completions) {
+ if (completion.getLabel().equals("Test") &&
+ "(int i) - generate".equals(completion.getLabelDetail())) {
+ //force full reparse:
+ byte[] content = primaryTestFO.asBytes();
+ try (OutputStream out = primaryTestFO.getOutputStream()) {
+ out.write(content);
+ }
+ assertEquals(null,
+ completion.getInsertText());
+ assertEquals("63-63:",
+ textEdit2String(completion.getTextEdit()));
+ assertEquals("""
+ 59-59:
+ public Test(int i) {
+ this.i = i;
+ }
+ """.replace("\n", "\\n"),
+ completion.getAdditionalTextEdits()
+ .get()
+ .stream()
+ .map(JavaCompletionCollectorTest::textEdit2String)
+ .collect(Collectors.joining(", ")));
+ found.set(true);
+ }
+ }
+ });
+ assertTrue(found.get());
+ }
+
private void runJavaCollector(List<FileDescription> files, Validator<List<Completion>> validator) throws Exception {
SourceUtilsTestUtil.prepareTest(new String[]{"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[]{new MIMEResolverImpl(), new MIMEDataProvider()});

FileObject scratch = SourceUtilsTestUtil.makeScratchDir(this);
FileObject cache = scratch.createFolder("cache");
FileObject src = scratch.createFolder("src");
- FileObject mainFile = null;
+ primaryTestFO = null;
int caretPosition = -1;

for (FileDescription testFile : files) {
FileObject testFO = FileUtil.createData(src, testFile.fileName);
String code = testFile.code;

- if (mainFile == null) {
- mainFile = testFO;
+ if (primaryTestFO == null) {
+ primaryTestFO = testFO;
caretPosition = code.indexOf('|');

assertTrue(caretPosition >= 0);
@@ -324,16 +368,16 @@ private void runJavaCollector(List<FileDescription> files, Validator<List<Comple
TestUtilities.copyStringToFile(testFO, code);
}

- assertNotNull(mainFile);
+ assertNotNull(primaryTestFO);

if (sourceLevel != null) {
- SourceUtilsTestUtil.setSourceLevel(mainFile, sourceLevel);
+ SourceUtilsTestUtil.setSourceLevel(primaryTestFO, sourceLevel);
}

SourceUtilsTestUtil.prepareTest(src, FileUtil.createFolder(scratch, "test-build"), cache);
SourceUtilsTestUtil.compileRecursively(src);

- EditorCookie ec = mainFile.getLookup().lookup(EditorCookie.class);
+ EditorCookie ec = primaryTestFO.getLookup().lookup(EditorCookie.class);
Document doc = ec.openDocument();
JavaCompletionCollector collector = new JavaCompletionCollector();
Context ctx = new Context(TriggerKind.Invoked, null);
212 changes: 212 additions & 0 deletions patches/8245.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
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 abb39db21f52..ab76a3d05889 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
@@ -1811,15 +1811,17 @@ public DeprecatedTree Deprecated(List<? extends DocTree> text) {
}

public DocCommentTree DocComment(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
- DCDocComment temp = docMake.at(NOPOS).newDocCommentTree(fullBody, tags);
- return DocComment(temp.getFirstSentence(), temp.getBody(), temp.getBlockTags());
+ return DocComment(HTML_JAVADOC_COMMENT, fullBody, tags);
}

public DocCommentTree MarkdownDocComment(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
- DCDocComment temp = docMake.at(NOPOS).newDocCommentTree(fullBody, tags);
- return MarkdownDocComment(temp.getFirstSentence(), temp.getBody(), temp.getBlockTags());
+ return DocComment(MARKDOWN_JAVADOC_COMMENT, fullBody, tags);
}

+ private DocCommentTree DocComment(Comment comment, List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
+ return docMake.at(NOPOS).newDocCommentTree(comment, fullBody, tags, Collections.emptyList(), Collections.emptyList());
+ }
+
public DocTree Snippet(List<? extends DocTree> attributes, TextTree text){
try {
return (DocTree) docMake.getClass().getMethod("newSnippetTree", List.class, TextTree.class).invoke(docMake.at(NOPOS), attributes, text);
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 037eb8251775..8b77849102a8 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
@@ -45,6 +45,7 @@
import com.sun.tools.javac.tree.DCTree.DCLink;
import com.sun.tools.javac.tree.DCTree.DCLiteral;
import com.sun.tools.javac.tree.DCTree.DCParam;
+import com.sun.tools.javac.tree.DCTree.DCRawText;
import com.sun.tools.javac.tree.DCTree.DCReference;
import com.sun.tools.javac.tree.DCTree.DCReturn;
import com.sun.tools.javac.tree.DCTree.DCSee;
@@ -4722,6 +4723,9 @@ private int diffDocTree(DCDocComment doc, DCTree oldT, DCTree newT, int[] elemen
case TEXT:
localpointer = diffText(doc, (DCText)oldT, (DCText)newT, elementBounds);
break;
+ case MARKDOWN:
+ localpointer = diffRawText(doc, (DCRawText)oldT, (DCRawText)newT, elementBounds);
+ break;
case AUTHOR:
localpointer = diffAuthor(doc, (DCAuthor)oldT, (DCAuthor)newT, elementBounds);
break;
@@ -4944,6 +4948,15 @@ private int diffText(DCDocComment doc, DCText oldT, DCText newT, int[] elementBo
return elementBounds[1];
}

+ private int diffRawText(DCDocComment doc, DCTree.DCRawText oldT, DCTree.DCRawText newT, int[] elementBounds) {
+ if(oldT.code.equals(newT.code)) {
+ copyTo(elementBounds[0], elementBounds[1]);
+ } else {
+ printer.print(newT.code);
+ }
+ return elementBounds[1];
+ }
+
private int diffAuthor(DCDocComment doc, DCAuthor oldT, DCAuthor newT, int[] elementBounds) {
int localpointer = oldT.name.isEmpty()? elementBounds[1] : getOldPos(oldT.name.get(0), doc);
copyTo(elementBounds[0], localpointer);
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
index 5c3ce2e65646..5effccaf023d 100644
--- 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
@@ -18,6 +18,13 @@
*/
package org.netbeans.api.java.source.gen;

+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.LinkTree;
+import com.sun.source.doctree.RawTextTree;
+import com.sun.source.doctree.ReferenceTree;
+import com.sun.source.util.DocTreePath;
+import com.sun.source.util.DocTreePathScanner;
+import com.sun.source.util.TreePath;
import java.io.File;
import java.io.IOException;
import org.netbeans.api.java.source.ModificationResult;
@@ -134,7 +141,128 @@ public void run(WorkingCopy copy) throws Exception {

assertEquals(code.replace("test", "foo"), mr.getResultingSource(fo));
}
-
+
+ public void testDoNotBreakFormatting() throws Exception {
+ File f = new File(getWorkDir(), "TestClass.java");
+ String code = """
+ package foo;
+ /**
+ * First line.
+ * Test {@link #test}.
+ */
+ public class TestClass{
+ }
+ """;
+ TestUtilities.copyStringToFile(f, code);
+ FileObject fo = FileUtil.toFileObject(f);
+ JavaSource javaSource = JavaSource.forFileObject(fo);
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
+
+ public void run(WorkingCopy copy) throws Exception {
+ copy.toPhase(Phase.RESOLVED);
+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
+ copy.getCompilationUnit().getTypeDecls().get(0));
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
+
+ new DocTreePathScanner<>() {
+ @Override
+ public Object visitReference(ReferenceTree rt, Object p) {
+ copy.rewrite(topLevelClass.getLeaf(), rt, copy.getTreeMaker().Reference(null, "newName", null));
+ return null;
+ }
+
+ @Override
+ public Object visitLink(LinkTree lt, Object p) {
+ return super.visitLink(lt, p);
+ }
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
+ }
+ });
+
+ assertEquals(code.replace("test", "newName"), mr.getResultingSource(fo));
+ }
+
+ public void testDoNotBreakFormattingMarkdown() throws Exception {
+ File f = new File(getWorkDir(), "TestClass.java");
+ String code = """
+ package foo;
+
+ /// First line.
+ /// Test {@link #test}.
+ public class TestClass{
+ }
+ """;
+ TestUtilities.copyStringToFile(f, code);
+ FileObject fo = FileUtil.toFileObject(f);
+ JavaSource javaSource = JavaSource.forFileObject(fo);
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
+
+ public void run(WorkingCopy copy) throws Exception {
+ copy.toPhase(Phase.RESOLVED);
+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
+ copy.getCompilationUnit().getTypeDecls().get(0));
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
+
+ new DocTreePathScanner<>() {
+ @Override
+ public Object visitReference(ReferenceTree rt, Object p) {
+ copy.rewrite(topLevelClass.getLeaf(), rt, copy.getTreeMaker().Reference(null, "newName", null));
+ return null;
+ }
+
+ @Override
+ public Object visitLink(LinkTree lt, Object p) {
+ return super.visitLink(lt, p);
+ }
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
+ }
+ });
+
+ assertEquals(code.replace("test", "newName"), mr.getResultingSource(fo));
+ }
+
+ public void testMarkdownChangeText() throws Exception {
+ File f = new File(getWorkDir(), "TestClass.java");
+ String code = """
+ package foo;
+
+ /// First line.
+ /// Second line.
+ public class TestClass{
+ }
+ """;
+ TestUtilities.copyStringToFile(f, code);
+ FileObject fo = FileUtil.toFileObject(f);
+ JavaSource javaSource = JavaSource.forFileObject(fo);
+ ModificationResult mr = javaSource.runModificationTask(new Task<WorkingCopy>() {
+
+ public void run(WorkingCopy copy) throws Exception {
+ copy.toPhase(Phase.RESOLVED);
+
+ TreePath topLevelClass = new TreePath(new TreePath(copy.getCompilationUnit()),
+ copy.getCompilationUnit().getTypeDecls().get(0));
+ DocCommentTree docComment = copy.getDocTrees().getDocCommentTree(topLevelClass);
+
+ new DocTreePathScanner<>() {
+ @Override
+ public Object visitDocComment(DocCommentTree dct, Object p) {
+ //XXX: need to translate full body, as the split body has different split of the text trees, and the differ uses fullbody:
+ return scan(dct.getFullBody(), p);
+ }
+ @Override
+ public Object visitRawText(RawTextTree text, Object p) {
+ copy.rewrite(topLevelClass.getLeaf(), text, copy.getTreeMaker().RawText(text.getContent().replace("line", "nueText")));
+ return null;
+ }
+ }.scan(new DocTreePath(topLevelClass, docComment), null);
+ }
+ });
+
+ assertEquals(code.replace("line", "nueText"), mr.getResultingSource(fo));
+ }
+
String getGoldenPckg() {
return "";
}
Loading