Represents a field (member variable)
| 30 | * Represents a field (member variable) |
| 31 | */ |
| 32 | public class FieldNode extends AnnotatedNode implements Variable { |
| 33 | |
| 34 | private String name; |
| 35 | private int modifiers; |
| 36 | private ClassNode type; |
| 37 | private ClassNode owner; |
| 38 | private Expression initialValueExpression; |
| 39 | private boolean dynamicTyped; |
| 40 | private boolean holder; |
| 41 | private ClassNode originType; |
| 42 | |
| 43 | /** |
| 44 | * Creates a new FieldNode wrapping a reflection Field from a Java class. |
| 45 | * Extracts type information from the reflected field and creates an AST representation |
| 46 | * with public static access modifiers matching the source field. |
| 47 | * |
| 48 | * @param theClass the class containing the reflected field |
| 49 | * @param name the field name |
| 50 | * @return a new FieldNode representing the reflected field |
| 51 | * @throws SecurityException if field access is denied |
| 52 | * @throws NoSuchFieldException if the field does not exist |
| 53 | */ |
| 54 | public static FieldNode newStatic(Class theClass, String name) throws SecurityException, NoSuchFieldException { |
| 55 | Field field = theClass.getField(name); |
| 56 | ClassNode fldType = ClassHelper.make(field.getType()); |
| 57 | return new FieldNode(name, ACC_PUBLIC | ACC_STATIC, fldType, ClassHelper.make(theClass), null); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a field node representing a class member variable. |
| 62 | * The field's type can be dynamically determined based on the provided ClassNode. |
| 63 | * |
| 64 | * @param name the field name |
| 65 | * @param modifiers ASM modifier flags (public, static, final, etc.) |
| 66 | * @param type the field's {@link ClassNode} type |
| 67 | * @param owner the {@link ClassNode} that declares this field |
| 68 | * @param initialValueExpression optional initial value expression (null for no initializer) |
| 69 | */ |
| 70 | public FieldNode(String name, int modifiers, ClassNode type, ClassNode owner, Expression initialValueExpression) { |
| 71 | this.name = name; |
| 72 | this.modifiers = modifiers; |
| 73 | this.setType(type); |
| 74 | this.owner = owner; |
| 75 | this.initialValueExpression = initialValueExpression; |
| 76 | } |
| 77 | |
| 78 | protected FieldNode() {} |
| 79 | |
| 80 | /** |
| 81 | * Returns the initial value expression for this field. |
| 82 | * The expression is evaluated when the field is initialized. |
| 83 | * Returns null if no initializer is present. |
| 84 | * |
| 85 | * @return the {@link Expression} providing the initial value, or null |
| 86 | */ |
| 87 | @Override |
| 88 | public Expression getInitialExpression() { |
| 89 | return initialValueExpression; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…