[javadoc][snippet] IDEA-285783 Add snippet to allowed javadoc tags

GitOrigin-RevId: 326a6039748ff843277f9731853d06e6ac9cc417
This commit is contained in:
Nikita Eshkeev
2021-12-27 17:57:00 +03:00
committed by intellij-monorepo-bot
parent 10b7fa124a
commit c9e32ed723
5 changed files with 23 additions and 4 deletions

View File

@@ -40,6 +40,7 @@ public enum LanguageLevel {
JDK_16_PREVIEW(JavaPsiBundle.messagePointer("jdk.16.preview.language.level.description"), 16),
JDK_17(JavaPsiBundle.messagePointer("jdk.17.language.level.description"), 17),
JDK_17_PREVIEW(JavaPsiBundle.messagePointer("jdk.17.preview.language.level.description"), 17),
// TODO please notify nikita.eshkeev@jetbrains.com after having JDK_18 added, he need to update the "snippet" tag in JavadocManagerImpl.java:49
JDK_X(JavaPsiBundle.messagePointer("jdk.X.language.level.description"), 18);
public static final LanguageLevel HIGHEST = JDK_17;

View File

@@ -45,6 +45,8 @@ public class JavadocManagerImpl implements JavadocManager {
myInfos.add(new SimpleDocTagInfo("index", LanguageLevel.JDK_1_9, true, PsiElement.class));
myInfos.add(new SimpleDocTagInfo("summary", LanguageLevel.JDK_10, true, PsiElement.class));
myInfos.add(new SimpleDocTagInfo("systemProperty", LanguageLevel.JDK_12, true, PsiElement.class));
// TODO nikita.eshkeev@jetbrains.com, please change the language level to LanguageLevel.JDK_18 when it's available
myInfos.add(new SimpleDocTagInfo("snippet", LanguageLevel.JDK_17, true, PsiElement.class));
// not a standard tag, used by IDEA for suppressing inspections
myInfos.add(new SimpleDocTagInfo(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME, LanguageLevel.JDK_1_3, false, PsiElement.class));

View File

@@ -0,0 +1,15 @@
/**
* {@snippet lang=JAVA :
* public class ShowOptional {
* void show(Optional<String> v) {
* // @start region="example"
* if (v.isPresent()) {
* System.out.println("v: " + v.get());
* }
* // @end
* }
* }
* }
*/
class Main {
}

View File

@@ -160,7 +160,7 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
void testInlineLookup() {
configureByFile("InlineTagName.java")
assertStringItems("code", "docRoot", "index", "inheritDoc", "link", "linkplain", "literal", "summary", "systemProperty", "value")
assertStringItems("code", "docRoot", "index", "inheritDoc", "link", "linkplain", "literal", "snippet", "summary", "systemProperty", "value")
}
@NeedsIndex.ForStandardLibrary
@@ -775,7 +775,7 @@ interface Bar<T> extends Foo<T> {
void "test tags at top level inline"() {
myFixture.configureByText 'a.java', "interface Foo { /** Hello <caret> */void foo(int a); }"
myFixture.completeBasic()
assert myFixture.lookupElementStrings == ['{@code}', '{@docRoot}', '{@index}', '{@inheritDoc}', '{@linkplain}', '{@link}', '{@literal}', '{@summary}', '{@systemProperty}', '{@value}']
assert myFixture.lookupElementStrings == ['{@code}', '{@docRoot}', '{@index}', '{@inheritDoc}', '{@linkplain}', '{@link}', '{@literal}', '{@snippet}', '{@summary}', '{@systemProperty}', '{@value}']
def element = myFixture.lookupElements[5]
assert element.lookupString == "{@link}"
selectItem(element)
@@ -785,7 +785,7 @@ interface Bar<T> extends Foo<T> {
void "test tags after return"() {
myFixture.configureByText 'a.java', "interface Foo { /** @return <caret> */int foo(int a); }"
myFixture.completeBasic()
assert myFixture.lookupElementStrings == ['{@code}', '{@docRoot}', '{@index}', '{@inheritDoc}', '{@linkplain}', '{@link}', '{@literal}', '{@return}', '{@summary}', '{@systemProperty}', '{@value}']
assert myFixture.lookupElementStrings == ['{@code}', '{@docRoot}', '{@index}', '{@inheritDoc}', '{@linkplain}', '{@link}', '{@literal}', '{@return}', '{@snippet}', '{@summary}', '{@systemProperty}', '{@value}']
def element = myFixture.lookupElements[5]
assert element.lookupString == "{@link}"
selectItem(element)
@@ -795,7 +795,7 @@ interface Bar<T> extends Foo<T> {
void "test tags at top level inline in brace"() {
myFixture.configureByText 'a.java', "interface Foo { /** Hello {<caret>} */void foo(int a); }"
myFixture.completeBasic()
assert myFixture.lookupElementStrings == ['@code', '@docRoot', '@index', '@inheritDoc', '@link', '@linkplain', '@literal', '@summary', '@systemProperty', '@value']
assert myFixture.lookupElementStrings == ['@code', '@docRoot', '@index', '@inheritDoc', '@link', '@linkplain', '@literal', '@snippet', '@summary', '@systemProperty', '@value']
def element = myFixture.lookupElements[4]
assert element.lookupString == "@link"
selectItem(element)

View File

@@ -125,6 +125,7 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIgnoreAccessors() { myInspection.setIgnoreSimpleAccessors(true); doTest(); }
public void testAuthoredMethod() { doTest(); }
public void testThrowsInheritDoc() { doTest(); }
public void testSnippetInlineTag() { doTest(); }
public void testIssueLinksInJavaDoc() {
IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(getProject());