aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/proxies/FieldProxy.java
blob: 72a4e40b6966e8057364dc0472193c3a9d7af3ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ftbsc.lll.proxies;

import org.objectweb.asm.Type;

import java.lang.reflect.Field;

/**
 * A container for information about class fields to be used
 * in ASM patching.
 * @since 0.3.0
 */
public class FieldProxy extends AbstractProxy {
   /**
    * A public constructor, builds a proxy from a {@link Field}
    * obtained from reflection.
    * @param f the {@link Field} object corresponding to this.
    */
   public FieldProxy(Field f) {
      super(f.getName(), Type.getType(f.getType()), f.getModifiers(), Type.getInternalName(f.getDeclaringClass()));
   }

   /**
    * Protected constructor, called only from the builder.
    * @param name the name of the field
    * @param type the {@link Type} of the field
    * @param modifiers the modifiers of the field
    * @param parent the FQN of the parent class of the field
    */
   protected FieldProxy(String name, Type type, int modifiers, String parent) {
      super(name, type, modifiers, parent);
   }

   /**
    * Returns a new instance of {@link FieldProxy.Builder}.
    * @param name the name of the field
    * @return the builder object for field proxies
    */
   public static Builder builder(String name) {
      return new Builder(name);
   }

   /**
    * A builder object for {@link FieldProxy}.
    */
   public static class Builder extends AbstractProxy.Builder<FieldProxy> {
      /**
       * The constructor of the builder, used only internally.
       * @param name the name of the field
       */
      Builder(String name) {
         super(name);
      }

      /**
       * Builds a {@link FieldProxy} of the given kind.
       * @return the built {@link FieldProxy}
       */
      @Override
      public FieldProxy build() {
         return new FieldProxy(this.name, this.type, this.modifiers, this.parent);
      }
   }
}