mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[javadoc] JavaDocInfoGeneratorTest: test for malformed snippet; better error reporting and recovery
GitOrigin-RevId: 7c1d9fd387a4bc7fc52121e71f56122d6ff05d67
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a9e1d4f55e
commit
6a655aa910
@@ -16,7 +16,6 @@ import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.lang.java.JavaDocumentationProvider;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
@@ -1912,7 +1911,12 @@ public class JavaDocInfoGenerator {
|
||||
throw new AssertionError(node.toString());
|
||||
}
|
||||
if (node.regex() != null) {
|
||||
content = content.replaceAll(node.regex(), replacement.apply("$0"));
|
||||
try {
|
||||
content = content.replaceAll(node.regex(), replacement.apply("$0"));
|
||||
}
|
||||
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
|
||||
buffer.append(getSpanForUnresolvedItem()).append("[").append(e.getMessage()).append("]</span>\n");
|
||||
}
|
||||
}
|
||||
else if (node.substring() != null) {
|
||||
content = content.replace(node.substring(), replacement.apply(node.substring()));
|
||||
@@ -1926,7 +1930,7 @@ public class JavaDocInfoGenerator {
|
||||
|
||||
@Override
|
||||
public void visitError(@NotNull ErrorMarkup errorMarkup) {
|
||||
buffer.append(getSpanForUnresolvedItem()).append("[").append(errorMarkup.message()).append("]</span>");
|
||||
buffer.append(getSpanForUnresolvedItem()).append("[").append(errorMarkup.message()).append("]</span>\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -516,7 +516,9 @@ public class SnippetMarkup {
|
||||
regions.push(start.region());
|
||||
} else if (node instanceof EndRegion end) {
|
||||
if (end.region() == null) {
|
||||
active.remove(regions.pop());
|
||||
if (!regions.isEmpty()) {
|
||||
active.remove(regions.pop());
|
||||
}
|
||||
} else {
|
||||
regions.remove(end.region());
|
||||
active.remove(end.region());
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">Malformed</span></pre></div><div class='content'>
|
||||
<pre>public void malformed() {
|
||||
<span style="color:#ff0000">[@replace: missing 'replacement' attribute]</span>
|
||||
<span style="color:#ff0000">[Unsupported attribute: 'hello']</span>
|
||||
<span style="color:#ff0000">[Markup tag or attribute expected]</span>
|
||||
<span style="color:#000000;background-color:#ffff00;"></span><span style="color:#ff0000">[@replace: missing 'replacement' attribute]</span>
|
||||
<span style="color:#ff0000">[@link: missing 'target' attribute]</span>
|
||||
<span style="color:#ff0000">[Unknown type 'none'; only 'link' and 'linkplain' are supported]</span>
|
||||
<a href="psi_element://"><code><span style="color:#000000;background-color:#ffff00;"></span></code></a><span style="color:#ff0000">[Dangling meta character '?' near index 0
|
||||
???
|
||||
^]</span>
|
||||
System.out.println("hello");
|
||||
}
|
||||
</pre>
|
||||
</div><table class='sections'><p></table>
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* {@snippet class=Region region=malformed}
|
||||
*/
|
||||
class Malformed {
|
||||
}
|
||||
+8
@@ -27,4 +27,12 @@ public class Region {
|
||||
System.out.println("abc"); // @replace substring=a replacement=x @replace regex="b(.?)" replacement="$1z" @highlight substring=out
|
||||
}
|
||||
// @end
|
||||
|
||||
// @start region=malformed
|
||||
public void malformed() {
|
||||
// @replace @highlight hello=world @unknown
|
||||
// @replace @highlight @link type=none
|
||||
System.out.println("hello"); // @replace regex="???" replacement="xyz"
|
||||
}
|
||||
// @end
|
||||
}
|
||||
+5
-1
@@ -150,11 +150,15 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
public void testExternalSnippetTextFile() {
|
||||
createProjectStructure(getTestDataPath() + TEST_DATA_FOLDER + "externalSnippet");
|
||||
verifyJavadocFor("TextFile");
|
||||
}
|
||||
}
|
||||
public void testExternalSnippetUnresolved() {
|
||||
createProjectStructure(getTestDataPath() + TEST_DATA_FOLDER + "externalSnippet");
|
||||
verifyJavadocFor("Unresolved");
|
||||
}
|
||||
public void testExternalSnippetMalformed() {
|
||||
createProjectStructure(getTestDataPath() + TEST_DATA_FOLDER + "externalSnippet");
|
||||
verifyJavadocFor("Malformed");
|
||||
}
|
||||
public void testUnknownInlineTag() { doTestClass(); }
|
||||
public void testUnknownInlineMultilineTag() { doTestClass(); }
|
||||
public void testUnknownTag() { doTestMethod(); }
|
||||
|
||||
Reference in New Issue
Block a user