@@ -1165,12 +1165,17 @@ static class QualifiedMethodExpr implements Expr {
1165
1165
private final String methodName ;
1166
1166
private final MethodKind kind ;
1167
1167
private final Class tagClass ;
1168
+ private final StaticFieldExpr fieldOverload ;
1168
1169
1169
1170
private enum MethodKind {
1170
1171
CTOR , INSTANCE , STATIC
1171
1172
}
1172
1173
1173
- public QualifiedMethodExpr (Class methodClass , Symbol sym ){
1174
+ public QualifiedMethodExpr (Class methodClass , Symbol sym ) {
1175
+ this (methodClass , sym , null );
1176
+ }
1177
+
1178
+ public QualifiedMethodExpr (Class methodClass , Symbol sym , StaticFieldExpr fieldOL ) {
1174
1179
c = methodClass ;
1175
1180
methodSymbol = sym ;
1176
1181
tagClass = tagOf (sym ) != null ? HostExpr .tagToClass (tagOf (sym )) : AFn .class ;
@@ -1187,18 +1192,28 @@ else if(sym.name.equals("new")) {
1187
1192
kind = MethodKind .STATIC ;
1188
1193
methodName = sym .name ;
1189
1194
}
1195
+ fieldOverload = fieldOL ;
1190
1196
}
1191
1197
1192
1198
// Expr impl - invocation, convert to fn expr
1199
+ private boolean overloadsField () {
1200
+ return fieldOverload != null && paramTagsOf (methodSymbol ) == null ;
1201
+ }
1193
1202
1194
1203
@ Override
1195
1204
public Object eval () {
1196
- return buildThunk (C .EVAL , this ).eval ();
1205
+ if (overloadsField ())
1206
+ return fieldOverload .eval ();
1207
+ else
1208
+ return buildThunk (C .EVAL , this ).eval ();
1197
1209
}
1198
1210
1199
1211
@ Override
1200
1212
public void emit (C context , ObjExpr objx , GeneratorAdapter gen ) {
1201
- buildThunk (context , this ).emit (context , objx , gen );
1213
+ if (overloadsField ())
1214
+ fieldOverload .emit (context , objx , gen );
1215
+ else
1216
+ buildThunk (context , this ).emit (context , objx , gen );
1202
1217
}
1203
1218
1204
1219
// Expr impl - method value, always an AFn
@@ -1258,18 +1273,9 @@ private static Set aritySet(Class c, String methodName, MethodKind kind) {
1258
1273
return res ;
1259
1274
}
1260
1275
1261
- // Returns a list of methods or ctors matching the name and kind given.
1262
- // Otherwise, will throw if the information provided results in no matches
1263
- public static List <Executable > methodsWithName (Class c , String methodName , MethodKind kind ) {
1264
- if (kind == MethodKind .CTOR ) {
1265
- List <Executable > ctors = Arrays .asList (c .getConstructors ());
1266
- if (ctors .isEmpty ())
1267
- throw noMethodWithNameException (c , methodName , kind );
1268
- return ctors ;
1269
- }
1270
-
1276
+ public static List <Executable > methodOverloads (Class c , String methodName , MethodKind kind ) {
1271
1277
final Executable [] methods = c .getMethods ();
1272
- List < Executable > res = Arrays .stream (methods )
1278
+ return Arrays .stream (methods )
1273
1279
.filter (m -> m .getName ().equals (methodName ))
1274
1280
.filter (m -> {
1275
1281
switch (kind ) {
@@ -1279,6 +1285,19 @@ public static List<Executable> methodsWithName(Class c, String methodName, Metho
1279
1285
}
1280
1286
})
1281
1287
.collect (Collectors .toList ());
1288
+ }
1289
+
1290
+ // Returns a list of methods or ctors matching the name and kind given.
1291
+ // Otherwise, will throw if the information provided results in no matches
1292
+ private static List <Executable > methodsWithName (Class c , String methodName , MethodKind kind ) {
1293
+ if (kind == MethodKind .CTOR ) {
1294
+ List <Executable > ctors = Arrays .asList (c .getConstructors ());
1295
+ if (ctors .isEmpty ())
1296
+ throw noMethodWithNameException (c , methodName , kind );
1297
+ return ctors ;
1298
+ }
1299
+
1300
+ List <Executable > res = methodOverloads (c , methodName , kind );
1282
1301
1283
1302
if (res .isEmpty ())
1284
1303
throw noMethodWithNameException (c , methodName , kind );
@@ -4115,7 +4134,7 @@ static Object sigTag(int argcount, Var v){
4115
4134
return tagOf (sig );
4116
4135
}
4117
4136
return null ;
4118
- }
4137
+ }
4119
4138
4120
4139
public InvokeExpr (String source , int line , int column , Symbol tag , Expr fexpr , IPersistentVector args , boolean tailPosition ) {
4121
4140
this .source = source ;
@@ -4359,27 +4378,18 @@ static public Expr parse(C context, ISeq form) {
4359
4378
(KeywordExpr ) fexpr , target );
4360
4379
}
4361
4380
4381
+ // Preserving the existing static field bug that replaces a reference in parens with
4382
+ // the field itself rather than trying to invoke the value in the field. This is
4383
+ // an exception to the uniform Class/member qualification per CLJ-2806 ticket.
4384
+ if (fexpr instanceof StaticFieldExpr )
4385
+ return fexpr ;
4386
+
4362
4387
PersistentVector args = PersistentVector .EMPTY ;
4363
4388
for (ISeq s = RT .seq (form .next ()); s != null ; s = s .next ())
4364
4389
{
4365
4390
args = args .cons (analyze (context , s .first ()));
4366
4391
}
4367
4392
4368
- if (fexpr instanceof StaticFieldExpr ) {
4369
- Class c = ((StaticFieldExpr ) fexpr ).c ;
4370
- String name = ((StaticFieldExpr ) fexpr ).fieldName ;
4371
-
4372
- // Preserving the existing static field bug that replaces a reference in parens with
4373
- // the field itself rather than trying to invoke the value in the field. This is
4374
- // an exception to the uniform Class/member qualification per CLJ-2806 ticket.
4375
- if (RT .count (args ) == 0 && QualifiedMethodExpr .methodsWithName (c , name , QualifiedMethodExpr .MethodKind .STATIC ).isEmpty ())
4376
- return fexpr ;
4377
- else {
4378
- Symbol sym = Symbol .intern (c .getName (), name );
4379
- return toHostExpr (new QualifiedMethodExpr (c , sym ), (String ) SOURCE .deref (), lineDeref (), columnDeref (), tagOf (form ), tailPosition , args );
4380
- }
4381
- }
4382
-
4383
4393
if (fexpr instanceof QualifiedMethodExpr )
4384
4394
return toHostExpr ((QualifiedMethodExpr )fexpr , (String ) SOURCE .deref (), lineDeref (), columnDeref (), tagOf (form ), tailPosition , args );
4385
4395
@@ -7838,8 +7848,15 @@ private static Expr analyzeSymbol(Symbol sym) {
7838
7848
Class c = HostExpr .maybeClass (nsSym , false );
7839
7849
if (c != null )
7840
7850
{
7841
- if ((paramTagsOf (sym ) == null ) && (Reflector .getField (c , sym .name , true ) != null ))
7842
- return new StaticFieldExpr (lineDeref (), columnDeref (), c , sym .name , tag );
7851
+ if (Reflector .getField (c , sym .name , true ) != null )
7852
+ {
7853
+ List <Executable > maybeOverloads = QualifiedMethodExpr .methodOverloads (c , sym .name , QualifiedMethodExpr .MethodKind .STATIC );
7854
+
7855
+ if (maybeOverloads .isEmpty ())
7856
+ return new StaticFieldExpr (lineDeref (), columnDeref (), c , sym .name , tag );
7857
+ else
7858
+ return new QualifiedMethodExpr (c , sym , new StaticFieldExpr (lineDeref (), columnDeref (), c , sym .name , tag ));
7859
+ }
7843
7860
else
7844
7861
return new QualifiedMethodExpr (c , sym );
7845
7862
}
0 commit comments