show javadoc for getters/setters copied from field (IDEA-60161)

This commit is contained in:
Anna Kozlova
2017-05-22 10:04:57 +03:00
parent 1bc7dbd1be
commit 237f4e0f7e
5 changed files with 39 additions and 0 deletions
@@ -44,6 +44,7 @@ import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.javadoc.*;
import com.intellij.psi.search.EverythingGlobalScope;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.psi.util.PsiTreeUtil;
@@ -1343,6 +1344,26 @@ public class JavaDocInfoGenerator {
buffer.append("</DD></DL></DD>");
}
}
else {
PsiField field = PropertyUtil.getFieldOfGetter(method);
if (field == null) {
field = PropertyUtil.getFieldOfSetter(method);
}
if (field != null) {
PsiDocComment fieldDocComment = field.getDocComment();
if (fieldDocComment != null && !isEmptyDescription(fieldDocComment)) {
buffer.append("<DD><DL>");
buffer.append("<DT><b>");
buffer.append(CodeInsightBundle.message("javadoc.description.copied.from.field"));
buffer.append("</b>&nbsp;");
generateLink(buffer, field, field.getName(), false);
buffer.append(BR_TAG);
generateValue(buffer, fieldDocComment.getDescriptionElements(), ourEmptyElementsProvider);
buffer.append("</DD></DL></DD>");
}
}
}
}
private void generateValue(StringBuilder buffer, PsiElement[] elements, InheritDocProvider<PsiElement[]> provider) {
@@ -0,0 +1,3 @@
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://FooBar"><code>FooBar</code></a></b></small><PRE>public&nbsp;<a href="psi_element://java.lang.String"><code>String</code></a>&nbsp;<b>getMyFoo</b>()</PRE><DD><DL><DT><b>Description copied from field:</b>&nbsp;<a href="psi_element://FooBar#myFoo"><code>myFoo</code></a><br>
foo bar baz
</DD></DL></DD></body></html>
@@ -0,0 +1,10 @@
class FooBar {
/**
* foo bar baz
*/
private String myFoo;
public String get<caret>MyFoo() {
return myFoo;
}
}
@@ -405,6 +405,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestAtCaret();
}
public void testDocumentationForGetterByField() throws Exception {
doTestAtCaret();
}
public void testDumbMode() throws Exception {
DumbServiceImpl.getInstance(myProject).setDumb(true);
try {
@@ -275,6 +275,7 @@ templates.postfix.settings.category.before=The sample code featuring selected te
templates.postfix.settings.category.after=Postfix completion invocation result will be shown here.
javadoc.description.copied.from.interface=Description copied from interface:
javadoc.description.copied.from.class=Description copied from class:
javadoc.description.copied.from.field=Description copied from field:
javadoc.deprecated=Deprecated
javadoc.since=Since:
javadoc.see.also=See Also: