2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
- import java .util .Map ;
6
5
7
6
import lombok .val ;
8
- import twg2 .collections .util .ListBuilder ;
7
+ import twg2 .collections .builder .ListBuilder ;
9
8
import twg2 .parser .baseAst .AstParser ;
10
9
import twg2 .parser .baseAst .tools .AstFragType ;
11
10
import twg2 .parser .documentParser .DocumentFragmentText ;
@@ -151,7 +150,7 @@ public static TypeSig.Simple extractGenericTypes(String typeSig) {
151
150
throw new IllegalArgumentException ("cannot parse a type signature containing '" + genericMark + "' (because this is a simple parser implementation)" );
152
151
}
153
152
154
- StringBuilder sb = new StringBuilder (typeSig );
153
+ val sb = new StringBuilder (typeSig );
155
154
val genericParamSets = new ArrayList <String >();
156
155
int i = 0 ;
157
156
while (true ) {
@@ -168,14 +167,17 @@ public static TypeSig.Simple extractGenericTypes(String typeSig) {
168
167
}
169
168
170
169
// convert the generic parameters to TypeSig nested
171
- Map .Entry <String , String > rootNameAndMarker = StringSplit .firstMatchParts (sb .toString (), "#" );
172
- TypeSig .SimpleBaseImpl root = new TypeSig .SimpleBaseImpl (StringTrim .trimTrailing (rootNameAndMarker .getKey (), '?' ), rootNameAndMarker .getKey ().endsWith ("?" ));
170
+ val rootNameAndMarker = StringSplit .firstMatchParts (sb .toString (), "#" );
171
+ val paramName = StringTrim .trimTrailing (rootNameAndMarker .getKey (), '?' );
172
+ val nameAndArrayDimensions = StringTrim .countAndTrimTrailing (paramName , "[]" , true );
173
+ val isOptional = rootNameAndMarker .getKey ().endsWith ("?" );
174
+ TypeSig .SimpleBaseImpl root = new TypeSig .SimpleBaseImpl (nameAndArrayDimensions .getValue (), nameAndArrayDimensions .getKey (), isOptional );
173
175
TypeSig .Simple sig ;
174
176
175
177
int rootMarker = !StringCheck .isNullOrEmpty (rootNameAndMarker .getValue ()) ? Integer .parseInt (rootNameAndMarker .getValue ()) : -1 ;
176
178
if (rootMarker > -1 ) {
177
179
val sigChilds = expandGenericParamSet (root , rootMarker , genericParamSets );
178
- sig = new TypeSig .SimpleGenericImpl (root .getTypeName (), sigChilds , root .isNullable ());
180
+ sig = new TypeSig .SimpleGenericImpl (root .getTypeName (), sigChilds , root .getArrayDimensions (), root . isNullable ());
179
181
}
180
182
else {
181
183
sig = root ;
@@ -188,21 +190,25 @@ public static TypeSig.Simple extractGenericTypes(String typeSig) {
188
190
public static List <TypeSig .Simple > expandGenericParamSet (TypeSig .SimpleBaseImpl parent , int parentParamMarker , List <String > remainingParamSets ) {
189
191
String paramSetStr = remainingParamSets .get (parentParamMarker );
190
192
remainingParamSets .remove (parentParamMarker );
191
- List <String > params = ListBuilder .newMutable (paramSetStr .split (", " ));
192
193
List <TypeSig .Simple > paramSigs = new ArrayList <>();
194
+ List <String > params = ListBuilder .mutable (paramSetStr .split (", " ));
195
+
193
196
for (String param : params ) {
194
197
// Split the generic parameter name and possible marker indicating further nested generic type
195
- Map . Entry < String , String > paramNameAndMarker = StringSplit .firstMatchParts (param , "#" );
198
+ val paramNameAndMarker = StringSplit .firstMatchParts (param , "#" );
196
199
197
200
// Create basic generic parameter using the name
198
- TypeSig .SimpleBaseImpl paramSigInit = new TypeSig .SimpleBaseImpl (StringTrim .trimTrailing (paramNameAndMarker .getKey (), '?' ), paramNameAndMarker .getKey ().endsWith ("?" ));
201
+ val paramName = StringTrim .trimTrailing (paramNameAndMarker .getKey (), '?' );
202
+ val nameAndArrayDimensions = StringTrim .countAndTrimTrailing (paramName , "[]" , true );
203
+ val isOptional = paramNameAndMarker .getKey ().endsWith ("?" );
204
+ TypeSig .SimpleBaseImpl paramSigInit = new TypeSig .SimpleBaseImpl (nameAndArrayDimensions .getValue (), nameAndArrayDimensions .getKey (), isOptional );
199
205
TypeSig .Simple paramSig ;
200
206
201
207
// if this generic parameter has a marker, parse it's sub parameters and add them to a new compound generic type signature
202
208
int paramMarker = !StringCheck .isNullOrEmpty (paramNameAndMarker .getValue ()) ? Integer .parseInt (paramNameAndMarker .getValue ()) : -1 ;
203
209
if (paramMarker > -1 ) {
204
210
val childParams = expandGenericParamSet (paramSigInit , paramMarker , remainingParamSets );
205
- paramSig = new TypeSig .SimpleGenericImpl (paramSigInit .getTypeName (), childParams , paramSigInit .isNullable ());
211
+ paramSig = new TypeSig .SimpleGenericImpl (paramSigInit .getTypeName (), childParams , paramSigInit .getArrayDimensions (), paramSigInit . isNullable ());
206
212
}
207
213
// else just use the generic parameter's basic signature (no nested generic types)
208
214
else {
0 commit comments