mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[javadoc] Missing enum constructor arguments in quick documentation and ctrl-hover popup
IDEA-218658 GitOrigin-RevId: f40a346285633828feea3a1b08513e50413aab61
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a97880ca82
commit
cec415fdbe
@@ -1132,35 +1132,56 @@ public class JavaDocInfoGenerator {
|
||||
|
||||
private void appendInitializer(StringBuilder buffer, PsiVariable variable, int variableSignatureLength) {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer == null) return;
|
||||
if (initializer != null) {
|
||||
String initializerText = initializer.getText().trim();
|
||||
if (variableSignatureLength + initializerText.length() < 80) {
|
||||
// initializer should be printed on the same line
|
||||
buffer.append(" ");
|
||||
}
|
||||
else {
|
||||
// initializer should be printed on the new line
|
||||
buffer.append("\n");
|
||||
buffer.append(NBSP.repeat(CodeStyle.getIndentSize(variable.getContainingFile())));
|
||||
}
|
||||
appendStyledSpan(buffer, getHighlightingManager().getOperationSignAttributes(), "= ");
|
||||
|
||||
String initializerText = initializer.getText().trim();
|
||||
if (variableSignatureLength + initializerText.length() < 80) {
|
||||
// initializer should be printed on the same line
|
||||
buffer.append(" ");
|
||||
int index = newLineIndex(initializerText);
|
||||
if (index < initializerText.length()) {
|
||||
initializerText = initializerText.substring(0, index);
|
||||
buffer.append(StringUtil.escapeXmlEntities(initializerText));
|
||||
buffer.append("...");
|
||||
}
|
||||
else {
|
||||
generateExpressionText(initializer, buffer);
|
||||
}
|
||||
PsiExpression constantInitializer = calcInitializerExpression(variable);
|
||||
if (constantInitializer != null) {
|
||||
buffer.append(DocumentationMarkup.GRAYED_START);
|
||||
appendExpressionValue(buffer, constantInitializer);
|
||||
buffer.append(DocumentationMarkup.GRAYED_END);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// initializer should be printed on the new line
|
||||
buffer.append("\n");
|
||||
buffer.append(NBSP.repeat(CodeStyle.getIndentSize(variable.getContainingFile())));
|
||||
else if (variable instanceof PsiEnumConstant) {
|
||||
PsiExpressionList list = ((PsiEnumConstant)variable).getArgumentList();
|
||||
if (canComputeArguments(list)) {
|
||||
generateExpressionText(list, buffer);
|
||||
}
|
||||
}
|
||||
appendStyledSpan(buffer, getHighlightingManager().getOperationSignAttributes(), "= ");
|
||||
}
|
||||
|
||||
int index = newLineIndex(initializerText);
|
||||
if (index < initializerText.length()) {
|
||||
initializerText = initializerText.substring(0, index);
|
||||
buffer.append(StringUtil.escapeXmlEntities(initializerText));
|
||||
buffer.append("...");
|
||||
}
|
||||
else {
|
||||
initializer.accept(new MyVisitor(buffer));
|
||||
}
|
||||
PsiExpression constantInitializer = calcInitializerExpression(variable);
|
||||
if (constantInitializer != null) {
|
||||
buffer.append(DocumentationMarkup.GRAYED_START);
|
||||
appendExpressionValue(buffer, constantInitializer);
|
||||
buffer.append(DocumentationMarkup.GRAYED_END);
|
||||
public static boolean canComputeArguments(@Nullable PsiExpressionList list) {
|
||||
if (list == null) return false;
|
||||
PsiExpression[] args = list.getExpressions();
|
||||
JavaPsiFacade instance = JavaPsiFacade.getInstance(list.getProject());
|
||||
PsiConstantEvaluationHelper helper = instance.getConstantEvaluationHelper();
|
||||
for (PsiExpression arg : args) {
|
||||
if (helper.computeConstantExpression(arg) == null) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void generateExpressionText(PsiElement initializer, StringBuilder buffer) {
|
||||
initializer.accept(new MyVisitor(buffer));
|
||||
}
|
||||
|
||||
private static int newLineIndex(String text) {
|
||||
|
||||
@@ -169,6 +169,14 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
generator.appendExpressionValue(buffer, constantInitializer);
|
||||
}
|
||||
}
|
||||
else if (variable instanceof PsiEnumConstant) {
|
||||
PsiEnumConstant enumConstant = (PsiEnumConstant)variable;
|
||||
PsiExpressionList list = enumConstant.getArgumentList();
|
||||
if (JavaDocInfoGenerator.canComputeArguments(list)) {
|
||||
JavaDocInfoGenerator generator = JavaDocInfoGeneratorFactory.create(variable.getProject(), null);
|
||||
generator.generateExpressionText(enumConstant.getArgumentList(), buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateModifiers(StringBuilder buffer, PsiModifierListOwner element) {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a></div><div class='definition'><pre><a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a> <span style="color:#660e7a;">A</span><span style="">(</span><span style="">)</span>
|
||||
<span class='grayed'>// Enum constant ordinal: 0</span></pre></div><table class='sections'></table>
|
||||
@@ -0,0 +1 @@
|
||||
<span style="color:#000000;"><a href="psi_element://E">E</a></span><br/> <span style="color:#000000;"><a href="psi_element://E">E</a></span> <span style="color:#660e7a;">A</span><span style="">(</span><span style="">)</span><br/><span class='grayed'>// Enum constant ordinal: 0</span>
|
||||
@@ -0,0 +1,2 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a></div><div class='definition'><pre><a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a> <span style="color:#660e7a;">A</span><span style="">(</span><span style="color:#008000;font-weight:bold;">"one"</span><span style="">, </span><span style="color:#0000ff;">1</span><span style="">)</span>
|
||||
<span class='grayed'>// Enum constant ordinal: 0</span></pre></div><table class='sections'></table>
|
||||
@@ -0,0 +1,11 @@
|
||||
enum E {
|
||||
A("one", 1);
|
||||
|
||||
E(String s, int num) {
|
||||
this.s = s;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
private final String s;
|
||||
private final int num;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<span style="color:#000000;"><a href="psi_element://E">E</a></span><br/> <span style="color:#000000;"><a href="psi_element://E">E</a></span> <span style="color:#660e7a;">A</span><span style="">(</span><span style="color:#008000;font-weight:bold;">"one"</span><span style="">, </span><span style="color:#0000ff;">1</span><span style="">)</span><br/><span class='grayed'>// Enum constant ordinal: 0</span>
|
||||
@@ -1,2 +1,2 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a></div><div class='definition'><pre><a href="psi_element://E"><code><span style="color:#000000;">E</span></code></a> <span style="color:#660e7a;">A</span>
|
||||
<span class='grayed'>// Enum constant ordinal: 0</span></pre></div><table class='sections'></table>
|
||||
<span class='grayed'>// Enum constant ordinal: 0</span></pre></div><table class='sections'></table>
|
||||
@@ -0,0 +1,17 @@
|
||||
enum E {
|
||||
A(new Bar().foo(), 1);
|
||||
|
||||
E(String s, int num) {
|
||||
this.s = s;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
private final String s;
|
||||
private final int num;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
String foo() {
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
"<span style=\"color:#000080;font-weight:bold;\">class</span> <span style=\"color:#000000;\">repeatableAnnotations</span>",
|
||||
new JavaDocInfoGenerator(getProject(), getTestClass()).generateSignature(getTestClass()));
|
||||
}
|
||||
|
||||
|
||||
public void testAnonymousAndSuperJavadoc() {
|
||||
PsiClass psiClass = PsiTreeUtil.findChildOfType(getTestClass(), PsiAnonymousClass.class);
|
||||
assertNotNull(psiClass);
|
||||
@@ -145,17 +145,16 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
verifyJavaDoc(method);
|
||||
}
|
||||
|
||||
public void testEnumConstantOrdinal() {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields() [0];
|
||||
String docInfo = new JavaDocumentationProvider().generateDoc(field, field);
|
||||
assertNotNull(docInfo);
|
||||
assertFileTextEquals(docInfo);
|
||||
public void testEnumConstant1() {
|
||||
doTestEnumConstant();
|
||||
}
|
||||
|
||||
docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(field, field);
|
||||
assertNotNull(docInfo);
|
||||
String htmlText = loadFile(new File(getTestDataPath() + TEST_DATA_FOLDER + getTestName(true) + "_quick.html"));
|
||||
assertEquals(htmlText, replaceEnvironmentDependentContent(UIUtil.getHtmlBody(docInfo)));
|
||||
public void testEnumConstant2() {
|
||||
doTestEnumConstant();
|
||||
}
|
||||
|
||||
public void testEnumConstant3() {
|
||||
doTestEnumConstant();
|
||||
}
|
||||
|
||||
public void testClickableFieldReference() {
|
||||
@@ -279,6 +278,19 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
verifyJavaDoc(psiClass);
|
||||
}
|
||||
|
||||
private void doTestEnumConstant() {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields()[0];
|
||||
String docInfo = new JavaDocumentationProvider().generateDoc(field, field);
|
||||
assertNotNull(docInfo);
|
||||
assertFileTextEquals(docInfo);
|
||||
|
||||
docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(field, field);
|
||||
assertNotNull(docInfo);
|
||||
String htmlText = loadFile(new File(getTestDataPath() + TEST_DATA_FOLDER + getTestName(true) + "_quick.html"));
|
||||
assertEquals(htmlText, replaceEnvironmentDependentContent(UIUtil.getHtmlBody(docInfo)));
|
||||
}
|
||||
|
||||
private void doTestField() {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields()[0];
|
||||
|
||||
Reference in New Issue
Block a user