2222
2323import java .lang .reflect .Field ;
2424import java .lang .reflect .Method ;
25- import java .util .ArrayList ;
2625import java .util .List ;
27- import java .util .stream .Collectors ;
2826
29- import com .github .therapi .runtimejavadoc .ClassJavadoc ;
3027import com .github .therapi .runtimejavadoc .CommentFormatter ;
3128import com .github .therapi .runtimejavadoc .FieldJavadoc ;
3229import com .github .therapi .runtimejavadoc .MethodJavadoc ;
@@ -53,7 +50,7 @@ public class SpringDocJavadocProvider implements JavadocProvider {
5350 */
5451 @ Override
5552 public String getMethodJavadocDescription (Method method ) {
56- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
53+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
5754 return formatter .format (methodJavadoc .getComment ());
5855 }
5956
@@ -65,7 +62,7 @@ public String getMethodJavadocDescription(Method method) {
6562 */
6663 @ Override
6764 public String getMethodJavadocReturn (Method method ) {
68- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
65+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
6966 return formatter .format (methodJavadoc .getReturns ());
7067 }
7168
@@ -78,7 +75,7 @@ public String getMethodJavadocReturn(Method method) {
7875 */
7976 @ Override
8077 public String getParamJavadoc (Method method , String name ) {
81- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
78+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
8279 List <ParamJavadoc > paramsDoc = methodJavadoc .getParams ();
8380 return paramsDoc .stream ().filter (paramJavadoc1 -> name .equals (paramJavadoc1 .getName ())).findAny ()
8481 .map (paramJavadoc1 -> formatter .format (paramJavadoc1 .getComment ())).orElse (null );
@@ -96,61 +93,4 @@ public String getFieldJavadoc(Field field) {
9693 return formatter .format (fieldJavadoc .getComment ());
9794 }
9895
99- /**
100- * Find method javadoc method javadoc.
101- *
102- * @param method the method
103- * @return the method javadoc
104- */
105- private MethodJavadoc findMethodJavadoc (Method method ) {
106- ClassJavadoc classJavadoc = RuntimeJavadoc .getJavadoc (method .getDeclaringClass ());
107- List <MethodJavadoc > methodDocs = classJavadoc .getMethods ();
108- // filter by method name
109- List <MethodJavadoc > methodDocByMethodName = methodDocs .stream ().filter (methodJavadoc -> methodJavadoc .getName ().equals (method .getName ())).collect (Collectors .toList ());
110- if (methodDocByMethodName .size () == 1 )
111- return methodDocByMethodName .get (0 );
112- // filter by parameters
113- if (methodDocByMethodName .size () > 1 ) {
114- List <MethodJavadoc > methodDocByParamType = methodDocByMethodName .stream ().filter (methodJavadoc -> paramsMatch (method .getParameterTypes (), methodJavadoc .getParamTypes ())).collect (Collectors .toList ());
115- if (methodDocByParamType .size () == 1 )
116- return methodDocByParamType .get (0 );
117- }
118- return MethodJavadoc .createEmpty (method );
119- }
120-
121- /**
122- * Params match boolean.
123- *
124- * @param paramTypesClass the param types class
125- * @param paramTypes the param types
126- * @return the boolean
127- */
128- private boolean paramsMatch (Class <?>[] paramTypesClass , List <String > paramTypes ) {
129- List <String > paramTypesJavadoc = new ArrayList <>();
130- for (int i = 0 ; i < paramTypes .size (); i ++) {
131- if (paramTypes .get (i ).contains ("::" )) {
132- String [] paramTypeArray = paramTypes .get (i ).split ("::" );
133- String paramType = paramTypeArray [paramTypeArray .length - 1 ].trim ().replace (")" , "" );
134- paramTypesJavadoc .add (paramType );
135- }
136- else
137- paramTypesJavadoc .add (paramTypes .get (i ));
138- }
139- return getCanonicalNames (paramTypesClass ).equals (paramTypesJavadoc );
140- }
141-
142- /**
143- * Gets canonical names.
144- *
145- * @param paramTypes the param types
146- * @return the canonical names
147- */
148- private List <String > getCanonicalNames (Class <?>[] paramTypes ) {
149- List <String > methodParamsTypes = new ArrayList <>();
150- for (Class <?> aClass : paramTypes ) {
151- methodParamsTypes .add (aClass .getCanonicalName ());
152- }
153- return methodParamsTypes ;
154- }
155-
15696}
0 commit comments