Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java.editor tests #4931

Merged
merged 4 commits into from
Nov 8, 2022
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,10 @@ jobs:
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.completion test

- name: java.editor
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.editor test-unit

- name: java.freeform
run: ant $OPTS -f java/java.freeform test

Expand Down Expand Up @@ -1244,6 +1248,10 @@ jobs:
if: env.test_java == 'true' && success()
run: ant $OPTS $OPTS_11 -f java/java.completion test

- name: java.editor
if: env.test_java == 'true' && success()
run: ant $OPTs $OPTS_11 -f java/java.editor test-unit

- name: java/java.source
run: ant $OPTS $OPTS_11 -f java/java.source test-unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.DocTree.Kind;
import com.sun.source.doctree.ParamTree;
import com.sun.source.doctree.ReferenceTree;
import com.sun.source.tree.Scope;
Expand Down Expand Up @@ -285,7 +286,15 @@ private DocTreePath getTag(final JavadocContext jdctx, final int offset) {
new DocTreePathScanner<Void, Void>() {
@Override
public Void scan(DocTree node, Void p) {
if (node != null && jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node) <= normalizedOffset && jdctx.positions.getEndPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node) >= normalizedOffset) {
long endPos = jdctx.positions.getEndPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node);
long startPos = jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node);
if (node.getKind() == Kind.ERRONEOUS && getCurrentPath() != null) {
String text = jdctx.javac.getText().substring((int) startPos, (int) endPos);
if (text.length() > 0 && text.charAt(0) == '{' && text.charAt(text.length() - 1) != '}') {
endPos = jdctx.positions.getEndPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, getCurrentPath().getLeaf());
}
}
if (node != null && startPos <= normalizedOffset && endPos >= normalizedOffset) {
final DocTreePath docTreePath = new DocTreePath(getCurrentPath(), node);
if (JavadocCompletionUtils.isBlockTag(docTreePath) || JavadocCompletionUtils.isInlineTag(docTreePath)) {
result[0] = docTreePath;
Expand Down Expand Up @@ -374,6 +383,9 @@ private void insideTag(DocTreePath tag, JavadocContext jdctx) {
case REFERENCE:
insideReference(tag, jdctx);
break;
case SNIPPET:
insideSnippet(tag, jdctx);
break;
}
}

Expand Down Expand Up @@ -1216,11 +1228,6 @@ void resolveOtherText(JavadocContext jdctx, TokenSequence<JavadocTokenId> jdts)
CharSequence text = token.text();
int pos = caretOffset - jdts.offset();
DocTreePath tag = getTag(jdctx, caretOffset);
int startPos = (int) jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, tag.getLeaf());
String subStr = JavadocCompletionUtils.getCharSequence(jdctx.doc, startPos, caretOffset).toString();
int index = subStr.lastIndexOf("\n");
String markupLine = JavadocCompletionUtils.getCharSequence(jdctx.doc, (index + startPos), caretOffset).toString();
insideInlineSnippet(markupLine);

if (pos > 0 && pos <= text.length() && text.charAt(pos - 1) == '{') {
if (tag != null && !JavadocCompletionUtils.isBlockTag(tag)) {
Expand All @@ -1242,26 +1249,43 @@ void resolveOtherText(JavadocContext jdctx, TokenSequence<JavadocTokenId> jdts)
}
}

void insideSnippet(DocTreePath tag, JavadocContext jdctx) {
int startPos = (int) jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, tag.getLeaf());
String subStr = JavadocCompletionUtils.getCharSequence(jdctx.doc, startPos, caretOffset).toString();
int index = subStr.lastIndexOf("\n");
String markupLine = JavadocCompletionUtils.getCharSequence(jdctx.doc, (index + startPos), caretOffset).toString();
insideInlineSnippet(markupLine);
}

private static final List<String> SNIPPET_TAGS = Collections.unmodifiableList(Arrays.asList(
"@highlight",
"@replace",
"@link",
"@start",
"@end"
));

private static final Pattern TAG_PATTERN = Pattern.compile("@\\b\\w{1,}\\b\\s+(?!.*@\\b\\w{1,}\\b\\s+)");

void insideInlineSnippet(String subStr) {
if (subStr.contains("//")) {
if (subStr.endsWith("@")) {
List<String> inlineAttr = new ArrayList() {
{
add("highlight");
add("replace");
add("link");
add("start");
add("end");
int lastAt = subStr.lastIndexOf('@');
if (lastAt != (-1)) {
String suffix = subStr.substring(lastAt);
if (!suffix.contains(" ")) {
for (String str : SNIPPET_TAGS) {
if (str.startsWith(suffix)) {
items.add(factory.createNameItem(str.substring(1), this.caretOffset));
}
}
};
for (String str : inlineAttr) {
items.add(factory.createNameItem(str, this.caretOffset));
return ;
}
} else {
String[] tags = {"@highlight", "@replace", "@link", "@start", "@end"};
Matcher match = Pattern.compile("@\\b\\w{1,}\\b\\s+(?!.*@\\b\\w{1,}\\b\\s+)").matcher(subStr);
if (match.find() && Arrays.asList(tags).contains(match.group(0).trim())) {
completeInlineMarkupTag(match.group(0).trim(), new ArrayList() {
}
Matcher match = TAG_PATTERN.matcher(subStr);
if (match.find()) {
String tag = match.group(0);
if (SNIPPET_TAGS.contains(tag.trim())) {
completeInlineMarkupTag(tag.trim(), new ArrayList() {
{
add("substring");
add("regex");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testHighlightAndReplace_cornercase</b>()</pre><p><div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> public static void \bmain\b(String... args) {
S<b>y</b><b>s</b>replace<b>.</b><b>o</b><b>u</b><b>t</b>.println("tests");
}

</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
public static void main(String... args) {
System.out.println("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a><a href='*1'>t</a><a href='*1'>e</a><a href='*1'>m</a><a href='*1'>.</a><a href='*1'>o</a><a href='*1'>u</a><a href='*1'>t</a>.println("Hello World!");
}
}


</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag_AlongWith_HighlightTag</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
public static void main(String... args) {

System.<span style="background-color:yellow;">o</span><span style="background-color:yellow;">u</span><span style="background-color:yellow;">t</span><span style="background-color:yellow;">.</span><span style="background-color:yellow;">p</span><span style="background-color:yellow;">r</span><span style="background-color:yellow;">i</span><span style="background-color:yellow;">n</span><span style="background-color:yellow;">t</span><span style="background-color:yellow;">l</span><span style="background-color:yellow;">n</span>("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a><a href='*1'>t</a><a href='*1'>e</a><a href='*1'>m</a><a href='*1'>.</a><span style="background-color:yellow;"><a href='*1'>o</a></span><span style="background-color:yellow;"><a href='*1'>u</a></span><span style="background-color:yellow;"><a href='*1'>t</a></span><span style="background-color:yellow;">.</span><span style="background-color:yellow;">p</span><span style="background-color:yellow;">r</span><span style="background-color:yellow;">i</span><span style="background-color:yellow;">n</span><span style="background-color:yellow;">t</span><span style="background-color:yellow;">l</span><span style="background-color:yellow;">n</span>("Hello World!");
}
}

</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag_AlongWith_ReplaceTag</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
public static void main(String... args) {

Syserr.out.println("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a>err.o<a href='*1'>u</a><a href='*1'>t</a>.println("Hello World!");
}
}

</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag_AlongWith_SubStringAndReplaceTag</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
public static void main(String... args) {

System.<span style="background-color:yellow;">r</span><span style="background-color:yellow;">e</span><span style="background-color:yellow;">p</span><span style="background-color:yellow;">l</span><span style="background-color:yellow;">a</span><span style="background-color:yellow;">c</span><span style="background-color:yellow;">e</span><span style="background-color:yellow;">d</span>out.println("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a><a href='*1'>t</a><a href='*1'>e</a><a href='*1'>m</a><a href='*1'>.</a><span style="background-color:yellow;">r</span><span style="background-color:yellow;">e</span><span style="background-color:yellow;">p</span><span style="background-color:yellow;">l</span><span style="background-color:yellow;">a</span><span style="background-color:yellow;">c</span><span style="background-color:yellow;">e</span><span style="background-color:yellow;">d</span>out.println("Hello World!");
}
}

</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag_AppliesToNextLine</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
public static void main(String... args) {

System.out.println("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a><a href='*1'>t</a><a href='*1'>e</a><a href='*1'>m</a><a href='*1'>.</a><a href='*1'>o</a><a href='*1'>u</a><a href='*1'>t</a>.println("Hello World!");
}
}

</code></pre></div><p>
</code></pre></div><p>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
<html><body><font size='+0'><b><a href='*0'>test.&#x200B;Test</a></b></font><pre>public void <b>testLinkTag_EmptyReplacementValue</b>()</pre><p>A simple program

<div id="snippet1" style="font-size: 10px; border: 1px solid black; margin-top: 2px; margin-bottom: 2px"><div align=right><a href="copy.snippet1">Copy</a></div>
<pre><code> class HelloWorld {
<pre><code> class HelloWorld {
public static void main(String... args) {

System.out.println("Hello World!");
<a href='*1'>S</a><a href='*1'>y</a><a href='*1'>s</a><a href='*1'>t</a><a href='*1'>e</a><a href='*1'>m</a><a href='*1'>.</a><a href='*1'>o</a><a href='*1'>u</a><a href='*1'>t</a>.println("Hello World!");
}
}

</code></pre></div><p>
</code></pre></div><p>
Loading