| 1167 | // In value position, will emit as a multi-arity method thunk with |
| 1168 | // params matching the arity set of the named method |
| 1169 | static class QualifiedMethodExpr implements Expr { |
| 1170 | private final Class c; |
| 1171 | private final List<Class> hintedSig; |
| 1172 | private final Symbol methodSymbol; |
| 1173 | private final String methodName; |
| 1174 | private final MethodKind kind; |
| 1175 | private final Class tagClass; |
| 1176 | private final StaticFieldExpr fieldOverload; |
| 1177 | |
| 1178 | private enum MethodKind { |
| 1179 | CTOR, INSTANCE, STATIC |
| 1180 | } |
| 1181 | |
| 1182 | public QualifiedMethodExpr(Class methodClass, Symbol sym) { |
| 1183 | this(methodClass, sym, null); |
| 1184 | } |
| 1185 | |
| 1186 | public QualifiedMethodExpr(Class methodClass, Symbol sym, StaticFieldExpr fieldOL) { |
| 1187 | c = methodClass; |
| 1188 | methodSymbol = sym; |
| 1189 | tagClass = tagOf(sym) != null ? HostExpr.tagToClass(tagOf(sym)) : AFn.class; |
| 1190 | hintedSig = tagsToClasses(paramTagsOf(sym)); |
| 1191 | if(sym.name.startsWith(".")) { |
| 1192 | kind = MethodKind.INSTANCE; |
| 1193 | methodName = sym.name.substring(1); |
| 1194 | } |
| 1195 | else if(sym.name.equals("new")) { |
| 1196 | kind = MethodKind.CTOR; |
| 1197 | methodName = sym.name; |
| 1198 | } |
| 1199 | else { |
| 1200 | kind = MethodKind.STATIC; |
| 1201 | methodName = sym.name; |
| 1202 | } |
| 1203 | fieldOverload = fieldOL; |
| 1204 | } |
| 1205 | |
| 1206 | private boolean preferOverloadedField() { |
| 1207 | return fieldOverload != null && paramTagsOf(methodSymbol) == null; |
| 1208 | } |
| 1209 | |
| 1210 | // Expr impl - invocation, convert to fn expr |
| 1211 | |
| 1212 | @Override |
| 1213 | public Object eval() { |
| 1214 | if(preferOverloadedField()) |
| 1215 | return fieldOverload.eval(); |
| 1216 | else |
| 1217 | return buildThunk(C.EVAL, this).eval(); |
| 1218 | } |
| 1219 | |
| 1220 | @Override |
| 1221 | public void emit(C context, ObjExpr objx, GeneratorAdapter gen) { |
| 1222 | if(preferOverloadedField()) |
| 1223 | fieldOverload.emit(context, objx, gen); |
| 1224 | else |
| 1225 | buildThunk(context, this).emit(context, objx, gen); |
| 1226 | } |
nothing calls this directly
no outgoing calls
no test coverage detected