mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
IDEA-91337 doc popup for variable: missing link for ArrayList
This commit is contained in:
@@ -26,7 +26,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
@@ -53,22 +52,23 @@ import java.util.regex.Pattern;
|
||||
public class JavaDocInfoGenerator {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.javadoc.JavaDocInfoGenerator");
|
||||
|
||||
private static final @NonNls Pattern ourNotDot = Pattern.compile("[^.]");
|
||||
private static final @NonNls Pattern ourNotDot = Pattern.compile("[^.]");
|
||||
private static final @NonNls Pattern ourWhitespaces = Pattern.compile("[ \\n\\r\\t]+");
|
||||
|
||||
private final Project myProject;
|
||||
private final PsiElement myElement;
|
||||
private static final @NonNls String THROWS_KEYWORD = "throws";
|
||||
private static final @NonNls String BR_TAG = "<br>";
|
||||
private static final @NonNls String LINK_TAG = "link";
|
||||
private static final @NonNls String LITERAL_TAG = "literal";
|
||||
private static final @NonNls String CODE_TAG = "code";
|
||||
private static final @NonNls String LINKPLAIN_TAG = "linkplain";
|
||||
private static final @NonNls String BR_TAG = "<br>";
|
||||
private static final @NonNls String LINK_TAG = "link";
|
||||
private static final @NonNls String LITERAL_TAG = "literal";
|
||||
private static final @NonNls String CODE_TAG = "code";
|
||||
private static final @NonNls String LINKPLAIN_TAG = "linkplain";
|
||||
private static final @NonNls String INHERITDOC_TAG = "inheritDoc";
|
||||
private static final @NonNls String DOCROOT_TAG = "docRoot";
|
||||
private static final @NonNls String VALUE_TAG = "value";
|
||||
|
||||
interface InheritDocProvider <T> {
|
||||
private static final @NonNls String DOCROOT_TAG = "docRoot";
|
||||
private static final @NonNls String VALUE_TAG = "value";
|
||||
|
||||
private final Project myProject;
|
||||
private final PsiElement myElement;
|
||||
|
||||
interface InheritDocProvider<T> {
|
||||
Pair<T, InheritDocProvider<T>> getInheritDoc();
|
||||
|
||||
PsiClass getElement();
|
||||
@@ -87,7 +87,8 @@ public class JavaDocInfoGenerator {
|
||||
private static final InheritDocProvider<PsiElement[]> ourEmptyElementsProvider = mapProvider(ourEmptyProvider, false);
|
||||
|
||||
private static InheritDocProvider<PsiElement[]> mapProvider(final InheritDocProvider<PsiDocTag> i,
|
||||
final boolean dropFirst) {
|
||||
final boolean dropFirst)
|
||||
{
|
||||
return new InheritDocProvider<PsiElement[]>() {
|
||||
public Pair<PsiElement[], InheritDocProvider<PsiElement[]>> getInheritDoc() {
|
||||
Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> pair = i.getInheritDoc();
|
||||
@@ -205,6 +206,7 @@ public class JavaDocInfoGenerator {
|
||||
@Nullable
|
||||
public String generateDocInfo(List<String> docURLs) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
if (myElement instanceof PsiClass) {
|
||||
generateClassJavaDoc(buffer, (PsiClass)myElement);
|
||||
}
|
||||
@@ -545,6 +547,8 @@ public class JavaDocInfoGenerator {
|
||||
private static void appendInitializer(StringBuilder buffer, PsiVariable variable) {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
buffer.append(" = ");
|
||||
|
||||
String text = initializer.getText();
|
||||
text = text.trim();
|
||||
int index1 = text.indexOf('\n');
|
||||
@@ -553,14 +557,16 @@ public class JavaDocInfoGenerator {
|
||||
if (index2 < 0) index2 = text.length();
|
||||
int index = Math.min(index1, index2);
|
||||
boolean trunc = index < text.length();
|
||||
text = text.substring(0, index);
|
||||
buffer.append(" = ");
|
||||
text = StringUtil.replace(text, "<", "<");
|
||||
text = StringUtil.replace(text, ">", ">");
|
||||
buffer.append(text);
|
||||
if (trunc) {
|
||||
text = text.substring(0, index);
|
||||
text = StringUtil.replace(text, "<", "<");
|
||||
text = StringUtil.replace(text, ">", ">");
|
||||
buffer.append(text);
|
||||
buffer.append("...");
|
||||
}
|
||||
else {
|
||||
initializer.accept(new MyVisitor(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1762,4 +1768,45 @@ public class JavaDocInfoGenerator {
|
||||
return comment.findTagByName("return");
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyVisitor extends JavaElementVisitor {
|
||||
|
||||
@NotNull private final StringBuilder myBuffer;
|
||||
|
||||
MyVisitor(@NotNull StringBuilder buffer) {
|
||||
myBuffer = buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(PsiNewExpression expression) {
|
||||
myBuffer.append("new ");
|
||||
PsiType type = expression.getType();
|
||||
if (type != null) {
|
||||
generateType(myBuffer, type, expression);
|
||||
}
|
||||
myBuffer.append("(");
|
||||
expression.acceptChildren(this);
|
||||
myBuffer.append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionList(PsiExpressionList list) {
|
||||
String separator = ", ";
|
||||
PsiExpression[] expressions = list.getExpressions();
|
||||
for (PsiExpression expression : expressions) {
|
||||
expression.accept(this);
|
||||
myBuffer.append(separator);
|
||||
}
|
||||
if (expressions.length > 0) {
|
||||
myBuffer.setLength(myBuffer.length() - separator.length());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
myBuffer.append(expression.getMethodExpression().getText()).append("(");
|
||||
expression.getArgumentList().acceptChildren(this);
|
||||
myBuffer.append(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<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://A"><code>A</code></a></b></small><PRE>public <a href="psi_element://java.util.List"><code>List</code></a><<a href="psi_element://java.lang.String"><code>String</code></a>> <b>strings = new <a href="psi_element://java.util.ArrayList"><code>ArrayList</code></a><<a href="psi_element://java.lang.String"><code>String</code></a>>(new <a href="psi_element://java.util.ArrayList"><code>ArrayList</code></a><<a href="psi_element://java.lang.Integer"><code>Integer</code></a>>(), Collections.singleton(new <a href="psi_element://java.util.ArrayList"><code>ArrayList</code></a><<a href="psi_element://java.lang.Double"><code>Double</code></a>>()))</b></PRE></body></html>
|
||||
@@ -0,0 +1,6 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class A {
|
||||
public List<String> strings = new ArrayList<String>(new ArrayList<Integer>(), Collections.singleton(new ArrayList<Double>()));
|
||||
}
|
||||
@@ -55,6 +55,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
doTestMethod();
|
||||
}
|
||||
|
||||
public void testInitializerWithNew() throws Exception {
|
||||
doTestField();
|
||||
}
|
||||
|
||||
private void doTestField() throws Exception {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields() [0];
|
||||
|
||||
Reference in New Issue
Block a user