22
22
23
23
import java .lang .reflect .Field ;
24
24
import java .lang .reflect .Method ;
25
- import java .util .ArrayList ;
26
25
import java .util .List ;
27
- import java .util .stream .Collectors ;
28
26
29
- import com .github .therapi .runtimejavadoc .ClassJavadoc ;
30
27
import com .github .therapi .runtimejavadoc .CommentFormatter ;
31
28
import com .github .therapi .runtimejavadoc .FieldJavadoc ;
32
29
import com .github .therapi .runtimejavadoc .MethodJavadoc ;
@@ -53,7 +50,7 @@ public class SpringDocJavadocProvider implements JavadocProvider {
53
50
*/
54
51
@ Override
55
52
public String getMethodJavadocDescription (Method method ) {
56
- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
53
+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
57
54
return formatter .format (methodJavadoc .getComment ());
58
55
}
59
56
@@ -65,7 +62,7 @@ public String getMethodJavadocDescription(Method method) {
65
62
*/
66
63
@ Override
67
64
public String getMethodJavadocReturn (Method method ) {
68
- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
65
+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
69
66
return formatter .format (methodJavadoc .getReturns ());
70
67
}
71
68
@@ -78,7 +75,7 @@ public String getMethodJavadocReturn(Method method) {
78
75
*/
79
76
@ Override
80
77
public String getParamJavadoc (Method method , String name ) {
81
- MethodJavadoc methodJavadoc = findMethodJavadoc (method );
78
+ MethodJavadoc methodJavadoc = RuntimeJavadoc . getJavadoc (method );
82
79
List <ParamJavadoc > paramsDoc = methodJavadoc .getParams ();
83
80
return paramsDoc .stream ().filter (paramJavadoc1 -> name .equals (paramJavadoc1 .getName ())).findAny ()
84
81
.map (paramJavadoc1 -> formatter .format (paramJavadoc1 .getComment ())).orElse (null );
@@ -96,61 +93,4 @@ public String getFieldJavadoc(Field field) {
96
93
return formatter .format (fieldJavadoc .getComment ());
97
94
}
98
95
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
-
156
96
}
0 commit comments