2424import java .util .List ;
2525import java .util .Map ;
2626import java .util .Optional ;
27+ import java .util .function .BiConsumer ;
2728import java .util .regex .Matcher ;
2829import java .util .regex .Pattern ;
2930import java .util .stream .Collectors ;
@@ -45,15 +46,15 @@ public class DocCollector extends VoidVisitorAdapter<Context> {
4546
4647 private static final Pattern SPLITTER = Pattern .compile ("\\ s+\\ *" );
4748
48- private static final Pattern PARAM = Pattern .compile ("(@param)\\ s+([^\\ s]+)([^@]+)" );
49-
5049 private static final String RETURNS = "@return" ;
5150
51+ private static final String PARAM = "@param" ;
52+
53+ private static final String THROWS = "@throws" ;
54+
5255 private static final Pattern CODE = Pattern
5356 .compile ("<code>\\ s*(\\ d+)\\ s*(=\\ s*([^<]+))?\\ s*</code>" );
5457
55- private static final Pattern TYPE = Pattern .compile ("\\ {@link\\ s+([^\\ }]+)\\ }" );
56-
5758 private Map <String , Object > doc = new HashMap <>();
5859
5960 public Map <String , Object > accept (final Node node , final String method , final Context ctx ) {
@@ -126,10 +127,8 @@ private Map<String, Object> doc(final Node node, final Context ctx) {
126127 Map <Integer , String > codes = Collections .emptyMap ();
127128 String tail = clean .substring (Math .max (0 , at ));
128129 // params
129- Matcher pmatcher = PARAM .matcher (tail );
130- while (pmatcher .find ()) {
131- hash .put (pmatcher .group (2 ).trim (), pmatcher .group (3 ).trim ());
132- }
130+ params (tail , hash ::put );
131+
133132 // returns
134133 String returnText = returnText (tail );
135134 codes = new LinkedHashMap <>();
@@ -142,17 +141,40 @@ private Map<String, Object> doc(final Node node, final Context ctx) {
142141 codes .put (status .value (), message );
143142 }
144143
145- Matcher tmatcher = TYPE .matcher (returnText );
146- if (tmatcher .find ()) {
147- ctx .resolveType (node , tmatcher .group (1 ).trim ()).ifPresent (t -> hash .put ("@type" , t ));
148- }
144+ TypeFromDoc .parse (node , ctx , returnText ).ifPresent (type -> hash .put ("@type" , type ));
149145 }
150146 hash .put ("@statusCodes" , codes );
151147 hash .put ("@text" , text );
152148 }
153149 return hash ;
154150 }
155151
152+ private void params (final String text , final BiConsumer <String , String > callback ) {
153+ int at = text .indexOf (PARAM );
154+ while (at != -1 ) {
155+ int start = at + PARAM .length ();
156+ int end = firstOf (text , start , PARAM , RETURNS , THROWS );
157+ String raw = text .substring (start , end ).trim ();
158+ int space = raw .indexOf (" " );
159+ if (space != -1 ) {
160+ String name = raw .substring (0 , space ).trim ();
161+ String desc = raw .substring (space ).trim ();
162+ callback .accept (name , desc );
163+ }
164+ at = text .indexOf (PARAM , end );
165+ }
166+ }
167+
168+ private int firstOf (final String text , final int start , final String ... tokens ) {
169+ for (String token : tokens ) {
170+ int pos = text .indexOf (token , start );
171+ if (pos != -1 ) {
172+ return pos ;
173+ }
174+ }
175+ return text .length ();
176+ }
177+
156178 private String returnText (final String doc ) {
157179 int retIdx = doc .indexOf (RETURNS );
158180 if (retIdx >= 0 ) {
0 commit comments