@Override public Field getField(String name) { // TODO: add static java.lang.reflect.Field field; try { field = existing.getField(name); } catch (NoSuchFieldException e) { return null; } catch (SecurityException e) { return null; } if (field != null) { return new Field(MemberFlags.fromReflection(field), existing(field.getType()), field.getName()); } return null; }
public void visit(FieldAccessType fieldAccessType) { Field field = fieldAccessType.getField(); if (field.isStatic()) { Type expressionType = evalExp(); methodByteCodeContext.handleConversion(expressionType, field.getType()); methodByteCodeContext.addInstruction(new FieldInsnNode(PUTSTATIC, methodContext.getClassIdentifier(), field.getName(), field.getSignature()), "set static", setStatement.getTo()); } else { methodByteCodeContext.loadThis("set", setStatement.getTo()); Type expressionType = evalExp(); methodByteCodeContext.handleConversion(expressionType, field.getType()); methodByteCodeContext.addInstruction(new FieldInsnNode(PUTFIELD, methodContext.getClassIdentifier(), field.getName(), field.getSignature()), "set", setStatement.getTo()); } } public void visit(LocalVariableAccessType localVariableAccessType) {
for (Field field : fields) { classNode.fields.add(new FieldNode( MethodByteCodeContext.getAccess(field.getFlags()), field.getName(), field.getSignature(), null, null)); for (Field field : staticFields) { classNode.fields.add(new FieldNode( MethodByteCodeContext.getAccess(field.getFlags()), field.getName(), field.getSignature(), null, null));
public void visit(FieldAccessType fieldAccessType) { Field field = fieldAccessType.getField(); if (field.isStatic()) { methodByteCodeContext.addInstruction( new FieldInsnNode(GETSTATIC, methodContext.getType().getClassIdentifier(), getExpression.getFieldName(), field.getSignature()), "get static field", getExpression.getFieldName()); } else { methodByteCodeContext.loadThis("get field", getExpression.getFieldName(), "on this"); methodByteCodeContext.addInstruction( new FieldInsnNode(GETFIELD, methodContext.getType().getClassIdentifier(), getExpression.getFieldName(), field.getSignature()), "get field", getExpression.getFieldName()); } lastExpressionType = field.getType(); } public void visit(ParameterAccessType parameterAccessType) {
private Field getField(ImmutableList<Field> fields, String varName) { for (Field field : fields) { if (field.getName().equals(varName)) { return field; } } return null; }
private ClassBuilder addField(Protection protection, Type type, String name, boolean isStatic) { ImmutableList<Field> newFields = this.fields; ImmutableList<Field> newStaticFields = this.staticFields; final Field newField = new Field(new MemberFlags(isStatic, false, protection), type, name); if (isStatic) { newStaticFields = newStaticFields.append(newField); } else { newFields = newFields.append(newField); } return newClassBuilder( newFields, newStaticFields, this.methods, this.staticMethods, this.constructors); }