check valueOf signature before use synthetic javadoc (IDEA-81701)

This commit is contained in:
anna
2012-02-22 20:11:46 +01:00
parent 2d474a043f
commit 519ccb6024
4 changed files with 26 additions and 3 deletions

View File

@@ -759,11 +759,15 @@ public class JavaDocInfoGenerator {
private PsiDocComment getMethodDocComment(final PsiMethod method) {
final PsiClass parentClass = method.getContainingClass();
if (parentClass != null && parentClass.isEnum()) {
if (method.getName().equals("values") && method.getParameterList().getParametersCount() == 0) {
final PsiParameterList parameterList = method.getParameterList();
if (method.getName().equals("values") && parameterList.getParametersCount() == 0) {
return loadSyntheticDocComment(method, "/javadoc/EnumValues.java.template");
}
if (method.getName().equals("valueOf") && method.getParameterList().getParametersCount() == 1) {
return loadSyntheticDocComment(method, "/javadoc/EnumValueOf.java.template");
if (method.getName().equals("valueOf") && parameterList.getParametersCount() == 1) {
final PsiType psiType = parameterList.getParameters()[0].getType();
if (psiType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return loadSyntheticDocComment(method, "/javadoc/EnumValueOf.java.template");
}
}
}
return getDocComment(method);

View File

@@ -0,0 +1,3 @@
<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://En"><code>En</code></a></b></small><PRE>static&nbsp;int&nbsp;<b>valueOf</b>(int&nbsp;i)</PRE>
myjavadoc
<DD><DL><DT><b>Parameters:</b><DD><code>i</code> - </DD></DL></DD><DD><DL><DT><b>Returns:</b><DD></DD></DL></DD></body></html>

View File

@@ -0,0 +1,12 @@
enum En {
;
/**
* myjavadoc
* @param i
* @return
*/
static int valueOf(int i) {
return i;
}
}

View File

@@ -50,6 +50,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
public void testClassTypeParameter() throws Exception {
verifyJavaDoc(getTestClass());
}
public void testEnumValueOf() throws Exception {
doTestMethod();
}
private void doTestField() throws Exception {
PsiClass psiClass = getTestClass();