summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/proxies/AbstractProxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ftbsc/lll/proxies/AbstractProxy.java')
-rw-r--r--src/main/java/ftbsc/lll/proxies/AbstractProxy.java118
1 files changed, 72 insertions, 46 deletions
diff --git a/src/main/java/ftbsc/lll/proxies/AbstractProxy.java b/src/main/java/ftbsc/lll/proxies/AbstractProxy.java
index 4c57e20..ff320f0 100644
--- a/src/main/java/ftbsc/lll/proxies/AbstractProxy.java
+++ b/src/main/java/ftbsc/lll/proxies/AbstractProxy.java
@@ -1,68 +1,71 @@
package ftbsc.lll.proxies;
import java.lang.reflect.Modifier;
+import org.objectweb.asm.Type;
/**
- * Abstract proxy class, implementing common aspects
- * of {@link MethodProxy} and {@link FieldProxy}.
+ * Abstract proxy class, implementing common aspects.
* @since 0.3.0
*/
public abstract class AbstractProxy {
/**
- * The name of the corresponding class member.
+ * Which type of proxy this is.
*/
- private final String name;
+ public final ProxyType proxyType;
/**
- * The fully qualified name (i.e. java.lang.String) of
- * the parent class.
+ * The name of the corresponding element.
*/
- private final String parent;
+ public final String name;
/**
- * The modifiers of the member, as a packed int.
- * @see java.lang.reflect.Modifier
+ * The descriptor for this element.
*/
- private final int modifiers;
+ public final String descriptor;
/**
- * @return the name of the item
+ * The fully qualified name (i.e. java.lang.String) of
+ * the parent class.
*/
- public String getName() {
- return this.name;
- }
+ public final QualifiableProxy parent;
/**
- * @return the modifiers of the member, as a packed int
+ * The modifiers of the member, as a packed int
* @see Modifier
*/
- public int getModifiers() {
- return this.modifiers;
- }
-
- /**
- * @return the fully qualified name of the parent class
- */
- public String getParent() {
- return this.parent;
- }
-
- /**
- * @return the descriptor of the member
- */
- public abstract String getDescriptor();
+ public final int modifiers;
/**
* The private constructor, should be called by all classes extending this in theirs.
- * @param name the name of the member
+ * @param name the name of the element
+ * @param descriptor the descriptor for the element
* @param modifiers the modifiers, as a packed int
* @param parent the FQN of the parent class
+ * @param proxyType the {@link ProxyType} being represented here
*/
- protected AbstractProxy(String name, int modifiers, String parent) {
+ protected AbstractProxy(String name, String descriptor, int modifiers, QualifiableProxy parent, ProxyType proxyType) {
this.name = name;
+ this.descriptor = descriptor;
this.modifiers = modifiers;
this.parent = parent;
+ this.proxyType = proxyType;
+ }
+
+ /**
+ * 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) {
+ if(obj instanceof AbstractProxy) {
+ AbstractProxy p = (AbstractProxy) obj;
+ return p.parent.equals(this.parent)
+ && p.name.equals(this.name)
+ && p.modifiers == this.modifiers
+ && p.descriptor.equals(this.descriptor);
+ } else return false;
}
/**
@@ -72,23 +75,28 @@ public abstract class AbstractProxy {
public abstract static class Builder<T extends AbstractProxy> {
/**
- * The name of the member.
+ * The name of the element.
*/
- protected final String name;
+ protected String name;
/**
- * The modifiers of the member, as a packed int.
+ * The modifiers of the element, as a packed int.
*/
protected int modifiers;
/**
* The fully qualified name of the parent.
*/
- protected String parent;
+ protected QualifiableProxy parent;
+
+ /**
+ * The descriptor of the element.
+ */
+ protected String descriptor;
/**
* The constructor.
- * @param name the name of the member
+ * @param name the name of the element
*/
protected Builder(String name) {
this.name = name;
@@ -96,33 +104,51 @@ public abstract class AbstractProxy {
}
/**
- * @param parentFQN the fully qualified name of the parent
+ * @param newModifier the modifier to add
* @return the current state of the builder
*/
- public Builder<T> setParent(String parentFQN) {
- this.parent = parentFQN;
+ public Builder<T> addModifier(int newModifier) {
+ this.modifiers |= newModifier;
return this;
}
/**
- * @param newModifier the modifier to add
+ * @param newModifier the new modifier value
* @return the current state of the builder
*/
- public Builder<T> addModifier(int newModifier) {
- this.modifiers |= newModifier;
+ public Builder<T> setModifiers(int newModifier) {
+ this.modifiers = newModifier;
return this;
}
/**
- * @param newModifier the new modifier value
+ * @param parent the {@link QualifiableProxy} representing the parent
* @return the current state of the builder
*/
- public Builder<T> setModifier(int newModifier) {
- this.modifiers = newModifier;
+ public Builder<T> setParent(QualifiableProxy parent) {
+ this.parent = parent;
return this;
}
/**
+ * Sets {@link Type} for this element from the descriptor, passed as a {@link String}.
+ * @param descriptor the descriptor passed as a {@link String}
+ * @return the builder's state after the change
+ */
+ public Builder<T> setDescriptor(String descriptor) {
+ this.descriptor = descriptor;
+ return this;
+ }
+
+ /**
+ * @param type the {@link Type} corresponding to the element
+ * @return the current state of the builder
+ */
+ public Builder<T> setType(Type type) {
+ return this.setDescriptor(type.getDescriptor());
+ }
+
+ /**
* @return the built proxy object
*/
public abstract T build();