summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-25 20:53:09 +0100
committer zaaarf <zaaarf@proton.me>2023-03-25 20:53:09 +0100
commitb8cd398fd5be79bbe5add01b6b6b998881a1bb46 (patch)
tree237a6bd5fb75c75bc636c666eeeaf102c893d4f8 /src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java
parentc1cb2184aa1b86dd1624a3b7c98b51f89af587eb (diff)
parent17a0b4d0172c0b3399fb5ed0ef1f89b41a1fc67f (diff)
Merge branch 'version4' into dev
Diffstat (limited to 'src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java')
-rw-r--r--src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java b/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java
new file mode 100644
index 0000000..ceb8277
--- /dev/null
+++ b/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java
@@ -0,0 +1,98 @@
+package ftbsc.lll.proxies.impl;
+
+import ftbsc.lll.proxies.AbstractProxy;
+import ftbsc.lll.proxies.ProxyType;
+import ftbsc.lll.proxies.QualifiableProxy;
+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 {
+ /**
+ * Protected constructor, called only from the builder.
+ * @param name the name of the field
+ * @param descriptor the descriptor of the field
+ * @param modifiers the modifiers of the field
+ * @param parent the {@link QualifiableProxy} for the parent
+ */
+ protected FieldProxy(String name, String descriptor, int modifiers, QualifiableProxy parent) {
+ super(name, descriptor, modifiers, parent, ProxyType.FIELD);
+ }
+
+ /**
+ * 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) {
+ this(f.getName(), Type.getDescriptor(f.getType()), f.getModifiers(), TypeProxy.from(f.getDeclaringClass()));
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Indicates whether the given object is a proxy for the same element as this.
+ * @param obj the object to perform
+ * @return true if it's equal
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof FieldProxy && super.equals(obj);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Sets the parent class of this field to the one described by the
+ * fully qualified name and with the given modifiers.
+ * @param parentFQN the fully qualified name of the parent
+ * @param modifiers the modifiers of the parent
+ * @return the builder's state after the change
+ */
+ public Builder setParent(String parentFQN, int modifiers) {
+ super.setParent(TypeProxy.from(parentFQN, 0, modifiers));
+ return this;
+ }
+
+ /**
+ * Sets the parent class of this field to the one described by the
+ * fully qualified name.
+ * @param parentFQN the fully qualified name of the parent
+ * @return the builder's state after the change
+ */
+ public Builder setParent(String parentFQN) {
+ return this.setParent(parentFQN, 0);
+ }
+
+ /**
+ * Builds a {@link FieldProxy} of the given kind.
+ * @return the built {@link FieldProxy}
+ */
+ @Override
+ public FieldProxy build() {
+ return new FieldProxy(this.name, this.descriptor, this.modifiers, this.parent);
+ }
+ }
+}