mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[codeInsight] IDEA-170168 Show method quick doc on modifiers
This patch amends the test class according to the code review, it includes: - removing the code that dissolves the test data class into pieces - adding more test data files which have the caret marker in them - deducing the custom documentation element from the caret position - comparing if the surrounding PsiJavaDocumentationElement of custom documentation element is the same as what JavaDocumentationProvider#myProvider.getCustomDocumentationElement returns Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com> GitOrigin-RevId: d0cefcb38d8a125b1448ef6d1f6537af70c7d30f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
73f501ac0d
commit
6e9855e683
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
public c<caret>lass Main { }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
p<caret>ublic class Main { }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public static f<caret>inal int id = 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public static final i<caret>nt id = 0;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
p<caret>ublic static final int id = 0;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public s<caret>tatic final int id = 0;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public static final S<caret>tring id = 0;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
p<caret>ublic void f() {}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public void f() t<caret>hrows Exception {}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Main {
|
||||
public v<caret>oid f() {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
|
||||
final class A {
|
||||
|
||||
final int i = 0;
|
||||
final String value = 0;
|
||||
|
||||
static void f() throws Exception {}
|
||||
}
|
||||
+49
-66
@@ -3,103 +3,75 @@ package com.intellij.java.codeInsight.javadoc;
|
||||
|
||||
import com.intellij.codeInsight.JavaCodeInsightTestCase;
|
||||
import com.intellij.lang.java.JavaDocumentationProvider;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiJavaDocumentedElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class JavaDocumentationProviderCustomDocumentationElementTest extends JavaCodeInsightTestCase {
|
||||
private static final String TEST_DATA_FOLDER = "/codeInsight/javadocIG/documentationprovider/customDocumentationElements.java";
|
||||
private static final String TEST_DATA_FOLDER = "/codeInsight/javadocIG/documentationprovider/";
|
||||
|
||||
private JavaDocumentationProvider myProvider;
|
||||
|
||||
private PsiClass myClass;
|
||||
private PsiMethod myMethod;
|
||||
private PsiField myIntField;
|
||||
private PsiField myStringField;
|
||||
|
||||
private PsiElement myStaticKeyword;
|
||||
private PsiElement myThrowsKeyword;
|
||||
private PsiElement myFinalKeyword;
|
||||
private PsiElement myClassKeyword;
|
||||
private PsiElement myIntFieldFinalKeyword;
|
||||
private PsiElement myIntFieldTypeKeyword;
|
||||
private PsiElement myStringFieldFinalKeyword;
|
||||
private PsiElement myStringFieldTypeKeyword;
|
||||
|
||||
public void testMethodModifiers() {
|
||||
final String message = "'static' on a method should be a custom documentation element";
|
||||
doTest(message, myStaticKeyword, myMethod);
|
||||
public void testClassClassKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testMethodThrowsList() {
|
||||
final String message = "'throws' on a method should be a custom documentation element";
|
||||
|
||||
doTest(message, myThrowsKeyword, myMethod);
|
||||
public void testClassPublicKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testClassFinalKeyword() {
|
||||
final String message = "'final' on a class should be a custom documentation element";
|
||||
doTest(message, myFinalKeyword, myClass);
|
||||
public void testFieldFinalKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testClassKeyword() {
|
||||
final String message = "'class' on a class should be a custom documentation element";
|
||||
doTest(message, myClassKeyword, myClass);
|
||||
public void testFieldIntType() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testIntFieldFinalKeyword() {
|
||||
final String message = "'final' on a field should be a custom documentation element";
|
||||
doTest(message, myIntFieldFinalKeyword, myIntField);
|
||||
public void testFieldPublicKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testIntFieldTypeKeyword() {
|
||||
final String message = "The primitive type 'int' on a field should be a custom documentation element";
|
||||
doTest(message, myIntFieldTypeKeyword, myIntField);
|
||||
public void testFieldStaticKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testStringFieldFinalKeyword() {
|
||||
final String message = "'final' on a field should be a custom documentation element";
|
||||
doTest(message, myStringFieldFinalKeyword, myStringField);
|
||||
public void testMethodPublicKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testStringFieldTypeKeyword() {
|
||||
public void testMethodThrowsKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testMethodVoidKeyword() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testFieldStringType() throws Exception {
|
||||
configure();
|
||||
|
||||
final PsiElement fieldStringType = PsiUtilBase.getElementAtCaret(getEditor());
|
||||
final String message = "The non-primitive type 'String' on a field can't be a custom documentation element";
|
||||
final PsiElement javadocCarrier = myProvider.getCustomDocumentationElement(myEditor, myFile, myStringFieldTypeKeyword, 0);
|
||||
|
||||
final PsiElement javadocCarrier = myProvider.getCustomDocumentationElement(myEditor, myFile, fieldStringType, 0);
|
||||
|
||||
assertThat(javadocCarrier).withFailMessage(message)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
configureByFile(TEST_DATA_FOLDER);
|
||||
myProvider = new JavaDocumentationProvider();
|
||||
private void doTestClass() throws Exception {
|
||||
configure();
|
||||
|
||||
myClass = ((PsiJavaFile)myFile).getClasses()[0];
|
||||
myMethod = myClass.getMethods()[0];
|
||||
final PsiModifierList methodModifierList = myMethod.getModifierList();
|
||||
myStaticKeyword = PsiTreeUtil.findChildOfType(methodModifierList, PsiKeyword.class);
|
||||
final PsiJavaCodeReferenceElement throwsElement = myMethod.getThrowsList().getReferenceElements()[0];
|
||||
myThrowsKeyword = PsiTreeUtil.getPrevSiblingOfType(throwsElement, PsiKeyword.class);
|
||||
final PsiElement customJavadocElement = PsiUtilBase.getElementAtCaret(getEditor());
|
||||
final PsiJavaDocumentedElement expectedJavadocCarrier = PsiTreeUtil.getParentOfType(customJavadocElement, PsiJavaDocumentedElement.class);
|
||||
|
||||
myFinalKeyword = PsiTreeUtil.findChildOfType(myClass.getModifierList(), PsiKeyword.class);
|
||||
final String message = String.format("'%s' should be custom documentation element", customJavadocElement.getText());
|
||||
|
||||
myClassKeyword = PsiTreeUtil.skipSiblingsForward(myFinalKeyword.getParent(), PsiWhiteSpace.class);
|
||||
|
||||
final PsiField[] fields = myClass.getFields();
|
||||
myIntField = fields[0];
|
||||
final PsiModifierList intFieldModifierList = myIntField.getModifierList();
|
||||
myIntFieldFinalKeyword = PsiTreeUtil.findChildOfType(intFieldModifierList, PsiKeyword.class);
|
||||
final PsiTypeElement type = PsiTreeUtil.findChildOfType(myIntField, PsiTypeElement.class);
|
||||
myIntFieldTypeKeyword = PsiTreeUtil.findChildOfType(type, PsiKeyword.class);
|
||||
|
||||
myStringField = fields[1];
|
||||
final PsiModifierList stringFieldModifierList = myStringField.getModifierList();
|
||||
myStringFieldFinalKeyword = PsiTreeUtil.findChildOfType(stringFieldModifierList, PsiKeyword.class);
|
||||
final PsiTypeElement type1 = PsiTreeUtil.findChildOfType(myStringField, PsiTypeElement.class);
|
||||
myStringFieldTypeKeyword = PsiTreeUtil.findChildOfType(type1, PsiIdentifier.class);
|
||||
doTest(message, customJavadocElement, expectedJavadocCarrier);
|
||||
}
|
||||
|
||||
private void doTest(String message, PsiElement customJavadocElement, PsiElement expectedJavadocCarrier) {
|
||||
@@ -108,4 +80,15 @@ public class JavaDocumentationProviderCustomDocumentationElementTest extends Jav
|
||||
assertThat(javadocCarrier).withFailMessage(message)
|
||||
.isEqualTo(expectedJavadocCarrier);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myProvider = new JavaDocumentationProvider();
|
||||
}
|
||||
|
||||
private void configure() throws Exception {
|
||||
final String name = getTestName(false);
|
||||
configureByFile(TEST_DATA_FOLDER + name + ".java");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user