19
19
import java .io .IOException ;
20
20
import java .io .ObjectInput ;
21
21
import java .io .ObjectOutput ;
22
- import java .util .Collection ;
22
+ import java .util .ArrayList ;
23
23
import java .util .Collections ;
24
24
import java .util .List ;
25
25
import java .util .Set ;
29
29
30
30
import saker .build .thirdparty .saker .util .ObjectUtils ;
31
31
import saker .build .thirdparty .saker .util .StringUtils ;
32
- import saker .build .thirdparty .saker .util .io .SerialUtils ;
33
32
import saker .java .compiler .impl .compat .ElementKindCompatUtils ;
34
33
import saker .java .compiler .impl .compile .signature .type .impl .NoTypeSignatureImpl ;
35
34
import saker .java .compiler .impl .signature .element .AnnotationSignature ;
36
35
import saker .java .compiler .impl .signature .element .MethodParameterSignature ;
37
36
import saker .java .compiler .impl .signature .element .MethodSignature ;
38
37
import saker .java .compiler .impl .signature .type .TypeParameterSignature ;
39
38
import saker .java .compiler .impl .signature .type .TypeSignature ;
39
+ import saker .java .compiler .impl .util .ImmutableModifierSet ;
40
+ import saker .java .compiler .impl .util .JavaSerialUtils ;
40
41
41
- public final class FullMethodSignature extends MethodSignatureBase {
42
+ public class FullMethodSignature extends MethodSignatureBase {
42
43
private static final long serialVersionUID = 1L ;
43
44
44
45
protected byte elementKindIndex ;
45
46
protected TypeSignature returnType ;
46
47
protected String name ;
47
- protected List <TypeSignature > throwsTypes = Collections . emptyList () ;
48
+ protected List <TypeSignature > throwsTypes ;
48
49
49
- protected List <TypeParameterSignature > typeParameters = Collections . emptyList () ;
50
+ protected List <TypeParameterSignature > typeParameters ;
50
51
51
52
protected TypeSignature receiverParameter ;
52
- protected boolean varArg ;
53
53
protected String docComment ;
54
54
55
55
/**
@@ -60,9 +60,8 @@ public FullMethodSignature() {
60
60
61
61
public static MethodSignature create (String name , Set <Modifier > modifiers ,
62
62
List <MethodParameterSignature > parameters , List <TypeSignature > throwsTypes , TypeSignature returnType ,
63
- AnnotationSignature .Value defaultValue , ElementKind methodKind ,
64
- List <TypeParameterSignature > typeParameters , TypeSignature receiverParameter , boolean varArg ,
65
- String docComment ) {
63
+ AnnotationSignature .Value defaultValue , ElementKind methodKind , List <TypeParameterSignature > typeParameters ,
64
+ TypeSignature receiverParameter , boolean varArg , String docComment ) {
66
65
if (defaultValue != null ) {
67
66
if (docComment == null ) {
68
67
return new AnnotationAttributeMethodSignature (returnType , name , defaultValue );
@@ -98,17 +97,21 @@ public static MethodSignature create(String name, Set<Modifier> modifiers,
98
97
throwsTypes );
99
98
}
100
99
}
100
+ if (varArg ) {
101
+ return new VarArgFullMethodSignature (modifiers , parameters , returnType , name , typeParameters , throwsTypes ,
102
+ methodKind , receiverParameter , docComment );
103
+ }
101
104
return new FullMethodSignature (modifiers , parameters , returnType , name , typeParameters , throwsTypes , methodKind ,
102
- receiverParameter , varArg , docComment );
105
+ receiverParameter , docComment );
103
106
}
104
107
105
108
public static MethodSignature createDefaultConstructor (Set <Modifier > modifiers ) {
106
109
return SimpleNoArgConstructor .create (modifiers );
107
110
}
108
111
109
- private FullMethodSignature (Set <Modifier > modifiers , List <MethodParameterSignature > parameters ,
112
+ protected FullMethodSignature (Set <Modifier > modifiers , List <MethodParameterSignature > parameters ,
110
113
TypeSignature returnType , String name , List <TypeParameterSignature > typeParameters ,
111
- List <TypeSignature > throwsTypes , ElementKind methodKind , TypeSignature receiverParameter , boolean varArg ,
114
+ List <TypeSignature > throwsTypes , ElementKind methodKind , TypeSignature receiverParameter ,
112
115
String docComment ) {
113
116
super (modifiers , parameters );
114
117
this .name = name ;
@@ -117,7 +120,6 @@ private FullMethodSignature(Set<Modifier> modifiers, List<MethodParameterSignatu
117
120
this .elementKindIndex = ElementKindCompatUtils .getElementKindIndex (methodKind );
118
121
this .typeParameters = typeParameters == null ? Collections .emptyList () : typeParameters ;
119
122
this .receiverParameter = receiverParameter ;
120
- this .
F438
varArg = varArg ;
121
123
this .docComment = docComment ;
122
124
}
123
125
@@ -178,45 +180,56 @@ public TypeSignature getReceiverParameter() {
178
180
return receiverParameter ;
179
181
}
180
182
181
- @ Override
182
- public boolean isVarArg () {
183
- return varArg ;
184
- }
185
-
186
183
@ Override
187
184
public void writeExternal (ObjectOutput out ) throws IOException {
188
- super .writeExternal (out );
189
-
190
- SerialUtils .writeExternalCollection (out , throwsTypes );
191
- SerialUtils .writeExternalCollection (out , typeParameters );
192
-
193
- out .writeUTF (name );
185
+ ImmutableModifierSet .writeExternalFlag (out , modifierFlags );
186
+ JavaSerialUtils .writeOpenEndedList (parameters , out );
187
+ JavaSerialUtils .writeOpenEndedList (throwsTypes , out );
188
+ JavaSerialUtils .writeOpenEndedList (typeParameters , out );
189
+
190
+ if (receiverParameter != null ) {
191
+ //optionally written, as rarely used
192
+ out .writeObject (receiverParameter );
193
+ }
194
+ out .writeObject (name );
195
+ if (docComment != null ) {
196
+ //optionally written
197
+ out .writeObject (docComment );
198
+ }
194
199
out .writeObject (returnType );
195
200
196
201
out .writeByte (elementKindIndex );
197
-
198
- out .writeObject (receiverParameter );
199
-
200
- out .writeBoolean (varArg );
201
- out .writeObject (docComment );
202
202
}
203
203
204
204
@ Override
205
205
public void readExternal (ObjectInput in ) throws IOException , ClassNotFoundException {
206
- super .readExternal (in );
207
-
208
- throwsTypes = SerialUtils .readExternalImmutableList (in );
209
- typeParameters = SerialUtils .readExternalImmutableList (in );
210
-
211
- name = in .readUTF ();
212
- returnType = (TypeSignature ) in .readObject ();
213
-
214
- elementKindIndex = in .readByte ();
215
-
216
- receiverParameter = (TypeSignature ) in .readObject ();
206
+ this .modifierFlags = ImmutableModifierSet .readExternalFlag (in );
207
+
208
+ ArrayList <MethodParameterSignature > parameters = new ArrayList <>();
209
+ ArrayList <TypeSignature > throwstypes = new ArrayList <>();
210
+ ArrayList <TypeParameterSignature > typeparams = new ArrayList <>();
211
+ this .parameters = parameters ;
212
+ this .throwsTypes = throwstypes ;
213
+ this .typeParameters = typeparams ;
214
+
215
+ Object next = JavaSerialUtils .readOpenEndedList (MethodParameterSignature .class , parameters , in );
216
+ next = JavaSerialUtils .readOpenEndedList (next , TypeSignature .class , throwstypes , in );
217
+ next = JavaSerialUtils .readOpenEndedList (next , TypeParameterSignature .class , typeparams , in );
218
+ if (next instanceof TypeSignature ) {
219
+ //receiver parameter is optionally present
220
+ this .receiverParameter = (TypeSignature ) next ;
221
+ next = in .readObject ();
222
+ }
223
+ this .name = (String ) next ;
224
+ next = in .readObject ();
225
+ if (next instanceof String ) {
226
+ //optional
227
+ this .docComment = (String ) next ;
228
+ next = in .readObject ();
229
+ }
230
+ this .returnType = (TypeSignature ) next ;
217
231
218
- varArg = in .readBoolean ();
219
- docComment = (String ) in .readObject ();
232
+ this .elementKindIndex = in .readByte ();
220
233
}
221
234
222
235
@ Override
@@ -260,8 +273,6 @@ public boolean equals(Object obj) {
260
273
return false ;
261
274
} else if (!typeParameters .equals (other .typeParameters ))
262
275
return false ;
263
- if (varArg != other .varArg )
264
- return false ;
265
276
return true ;
266
277
}
267
278
0 commit comments