mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
better fix for IDEA-111684
This commit is contained in:
@@ -73,27 +73,27 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
@NonNls public static final String PACKAGE_SUMMARY_FILE = "package-summary.html";
|
||||
|
||||
@Override
|
||||
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
if (element instanceof PsiClass) {
|
||||
return generateClassInfo((PsiClass)element);
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
return generateMethodInfo((PsiMethod)element, calcSubstitutor(originalElement));
|
||||
}
|
||||
else if (element instanceof PsiField) {
|
||||
return generateFieldInfo((PsiField)element, calcSubstitutor(originalElement));
|
||||
}
|
||||
else if (element instanceof PsiVariable) {
|
||||
return generateVariableInfo((PsiVariable)element);
|
||||
}
|
||||
else if (element instanceof PsiPackage) {
|
||||
return generatePackageInfo((PsiPackage)element);
|
||||
}
|
||||
else if (element instanceof BeanPropertyElement) {
|
||||
return generateMethodInfo(((BeanPropertyElement) element).getMethod(), PsiSubstitutor.EMPTY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
if (element instanceof PsiClass) {
|
||||
return generateClassInfo((PsiClass)element);
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
return generateMethodInfo((PsiMethod)element, calcSubstitutor(originalElement));
|
||||
}
|
||||
else if (element instanceof PsiField) {
|
||||
return generateFieldInfo((PsiField)element, calcSubstitutor(originalElement));
|
||||
}
|
||||
else if (element instanceof PsiVariable) {
|
||||
return generateVariableInfo((PsiVariable)element);
|
||||
}
|
||||
else if (element instanceof PsiPackage) {
|
||||
return generatePackageInfo((PsiPackage)element);
|
||||
}
|
||||
else if (element instanceof BeanPropertyElement) {
|
||||
return generateMethodInfo(((BeanPropertyElement) element).getMethod(), PsiSubstitutor.EMPTY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiSubstitutor calcSubstitutor(PsiElement originalElement) {
|
||||
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
|
||||
@@ -115,20 +115,13 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
}
|
||||
|
||||
private static void generateInitializer(StringBuilder buffer, PsiVariable variable) {
|
||||
PsiExpression initializer = JavaDocInfoGenerator.calcInitializerExpression(variable);
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
String text = initializer.getText().trim();
|
||||
int index1 = text.indexOf('\n');
|
||||
if (index1 < 0) index1 = text.length();
|
||||
int index2 = text.indexOf('\r');
|
||||
if (index2 < 0) index2 = text.length();
|
||||
int index = Math.min(index1, index2);
|
||||
boolean trunc = index < text.length();
|
||||
text = text.substring(0, index);
|
||||
buffer.append(" = ");
|
||||
buffer.append(StringUtil.escapeXml(text));
|
||||
if (trunc) {
|
||||
buffer.append("...");
|
||||
JavaDocInfoGenerator.appendExpressionValue(buffer, initializer, " = ");
|
||||
PsiExpression constantInitializer = JavaDocInfoGenerator.calcInitializerExpression(variable);
|
||||
if (constantInitializer != null) {
|
||||
buffer.append("\n");
|
||||
JavaDocInfoGenerator.appendExpressionValue(buffer, constantInitializer, CodeInsightBundle.message("javadoc.resolved.value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class JavaDocInfoGenerator {
|
||||
|
||||
private final Project myProject;
|
||||
private final PsiElement myElement;
|
||||
|
||||
|
||||
interface InheritDocProvider<T> {
|
||||
Pair<T, InheritDocProvider<T>> getInheritDoc();
|
||||
|
||||
@@ -595,7 +595,7 @@ public class JavaDocInfoGenerator {
|
||||
generateEpilogue(buffer);
|
||||
}
|
||||
|
||||
public static PsiExpression calcInitializerExpression(PsiVariable variable) {
|
||||
public static @Nullable PsiExpression calcInitializerExpression(PsiVariable variable) {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
PsiModifierList modifierList = variable.getModifierList();
|
||||
@@ -610,18 +610,35 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
else if (type.equalsToText("char")) text = "'" + text + "'";
|
||||
try {
|
||||
initializer = instance.getElementFactory().createExpressionFromText(text, variable);
|
||||
return instance.getElementFactory().createExpressionFromText(text, variable);
|
||||
} catch (IncorrectOperationException ex) {
|
||||
LOG.error(text, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return initializer;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean appendExpressionValue(StringBuilder buffer, PsiExpression initializer, String label) {
|
||||
String text = initializer.getText().trim();
|
||||
int index1 = text.indexOf('\n');
|
||||
if (index1 < 0) index1 = text.length();
|
||||
int index2 = text.indexOf('\r');
|
||||
if (index2 < 0) index2 = text.length();
|
||||
int index = Math.min(index1, index2);
|
||||
boolean trunc = index < text.length();
|
||||
text = text.substring(0, index);
|
||||
buffer.append(label);
|
||||
buffer.append(StringUtil.escapeXml(text));
|
||||
if (trunc) {
|
||||
buffer.append("...");
|
||||
}
|
||||
return trunc;
|
||||
}
|
||||
|
||||
private static void appendInitializer(StringBuilder buffer, PsiVariable variable) {
|
||||
PsiExpression initializer = calcInitializerExpression(variable);
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
buffer.append(" = ");
|
||||
|
||||
@@ -641,6 +658,11 @@ public class JavaDocInfoGenerator {
|
||||
else {
|
||||
initializer.accept(new MyVisitor(buffer));
|
||||
}
|
||||
PsiExpression constantInitializer = calcInitializerExpression(variable);
|
||||
if (constantInitializer != null) {
|
||||
buffer.append("\n");
|
||||
appendExpressionValue(buffer, constantInitializer, CodeInsightBundle.message("javadoc.resolved.value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://Test"><code>Test</code></a></b></small><PRE>public static final int <b>field =
|
||||
Resolved value: 2</b></PRE></body></html>
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
public static final int field = 1 + 1;
|
||||
}
|
||||
@@ -60,6 +60,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
doTestMethod();
|
||||
}
|
||||
|
||||
public void testConstantFieldInitializer() throws Exception {
|
||||
doTestField();
|
||||
}
|
||||
|
||||
public void testInitializerWithNew() throws Exception {
|
||||
doTestField();
|
||||
}
|
||||
|
||||
@@ -492,3 +492,4 @@ dialog.edit.template.checkbox.html.text=HTML Text
|
||||
dialog.edit.template.checkbox.xsl.text=XSL Text
|
||||
highlight.imported.classes.chooser.title=Choose Imported Classes to Highlight
|
||||
highlight.imported.members.chooser.title=Choose Imported Members to Highlight
|
||||
javadoc.resolved.value=Resolved value\:
|
||||
|
||||
Reference in New Issue
Block a user