javadoc: inherit parameter documentation from base class doc comment when method in this class has no doc comment (IDEA-89925)

This commit is contained in:
Dmitry Jemerov
2015-01-20 18:50:50 +01:00
parent e75f498956
commit 6349e5cb35
4 changed files with 33 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -873,14 +873,13 @@ public class JavaDocInfoGenerator {
if (method instanceof PsiMethod) {
final PsiDocComment docComment = getDocComment((PsiMethod)method);
if (docComment != null) {
final Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> tagInfoProvider =
findDocTag(docComment.getTags(), parameter.getName(), (PsiMethod)method);
final PsiDocTag[] localTags = docComment != null ? docComment.getTags() : PsiDocTag.EMPTY_ARRAY;
final Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> tagInfoProvider =
findDocTag(localTags, parameter.getName(), (PsiMethod)method);
if (tagInfoProvider != null) {
PsiElement[] elements = tagInfoProvider.first.getDataElements();
if (elements.length != 0) generateOneParameter(elements, buffer, tagInfoProvider);
}
if (tagInfoProvider != null) {
PsiElement[] elements = tagInfoProvider.first.getDataElements();
if (elements.length != 0) generateOneParameter(elements, buffer, tagInfoProvider);
}
}

View File

@@ -0,0 +1 @@
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><PRE><a href="psi_element://java.lang.String"><code>String</code></a> <b>s</b></PRE><DD><code>s</code> - String parameter.</body></html>

View File

@@ -0,0 +1,14 @@
public class Outer {
public static interface Inner {
/**
* Method.
* @param s String parameter.
*/
void foo(String s);
}
public static class Impl implements Inner {
public void foo(String s) {
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -170,7 +170,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
}
public void testLambdaParameter() throws Exception {
doTestLamabdaParameter();
doTestLambdaParameter();
}
private void doTestField() throws Exception {
@@ -185,7 +185,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
verifyJavaDoc(method);
}
private void doTestLamabdaParameter() throws Exception {
private void doTestLambdaParameter() throws Exception {
PsiClass psiClass = getTestClass();
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.findChildOfType(psiClass, PsiLambdaExpression.class);
assertNotNull(lambdaExpression);
@@ -214,6 +214,14 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), StringUtil.convertLineSeparators(info.trim()));
}
public void testInheritedParameter() throws Exception {
configureByFile("/codeInsight/javadocIG/" + getTestName(true) + ".java");
PsiClass outerClass = ((PsiJavaFile) myFile).getClasses()[0];
PsiClass innerClass = outerClass.findInnerClassByName("Impl", false);
PsiParameter parameter = innerClass.getMethods()[0].getParameterList().getParameters()[0];
verifyJavaDoc(parameter);
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();