| 1420 | } |
| 1421 | |
| 1422 | static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ |
| 1423 | public final Expr target; |
| 1424 | public final Class targetClass; |
| 1425 | public final java.lang.reflect.Field field; |
| 1426 | public final String fieldName; |
| 1427 | public final int line; |
| 1428 | public final int column; |
| 1429 | public final Symbol tag; |
| 1430 | public final boolean requireField; |
| 1431 | final static Method invokeNoArgInstanceMember = Method.getMethod("Object invokeNoArgInstanceMember(Object,String,boolean)"); |
| 1432 | final static Method setInstanceFieldMethod = Method.getMethod("Object setInstanceField(Object,String,Object)"); |
| 1433 | |
| 1434 | Class jc; |
| 1435 | |
| 1436 | public InstanceFieldExpr(int line, int column, Expr target, String fieldName, Symbol tag, boolean requireField) { |
| 1437 | this.target = target; |
| 1438 | this.targetClass = target.hasJavaClass() ? target.getJavaClass() : null; |
| 1439 | this.field = targetClass != null ? Reflector.getField(targetClass, fieldName, false) : null; |
| 1440 | this.fieldName = fieldName; |
| 1441 | this.line = line; |
| 1442 | this.column = column; |
| 1443 | this.tag = tag; |
| 1444 | this.requireField = requireField; |
| 1445 | if(field == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) |
| 1446 | { |
| 1447 | if(targetClass == null) |
| 1448 | { |
| 1449 | RT.errPrintWriter() |
| 1450 | .format("Reflection warning, %s:%d:%d - reference to field %s can't be resolved.\n", |
| 1451 | SOURCE_PATH.deref(), line, column, fieldName); |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | RT.errPrintWriter() |
| 1456 | .format("Reflection warning, %s:%d:%d - reference to field %s on %s can't be resolved.\n", |
| 1457 | SOURCE_PATH.deref(), line, column, fieldName, targetClass.getName()); |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | public Object eval() { |
| 1463 | return Reflector.invokeNoArgInstanceMember(target.eval(), fieldName, requireField); |
| 1464 | } |
| 1465 | |
| 1466 | public boolean canEmitPrimitive(){ |
| 1467 | return targetClass != null && field != null && |
| 1468 | Util.isPrimitive(field.getType()); |
| 1469 | } |
| 1470 | |
| 1471 | public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ |
| 1472 | if(targetClass != null && field != null) |
| 1473 | { |
| 1474 | target.emit(C.EXPRESSION, objx, gen); |
| 1475 | gen.visitLineNumber(line, gen.mark()); |
| 1476 | gen.checkCast(getType(targetClass)); |
| 1477 | gen.getField(getType(targetClass), fieldName, Type.getType(field.getType())); |
| 1478 | } |
| 1479 | else |