diff options
author | zaaarf <zaaarf@proton.me> | 2023-03-21 18:46:23 +0100 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-03-21 18:46:23 +0100 |
commit | 17a0b4d0172c0b3399fb5ed0ef1f89b41a1fc67f (patch) | |
tree | 3f76c814475a4bef2c8fd04d6e50e6eb03287dd4 /src/main | |
parent | 7e0b4e58dd9cf0c3d2f1b120ce21fe986d417f82 (diff) |
chore: reorganize, add ProxyType enum
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/AbstractProxy.java | 12 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/ProxyType.java | 11 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/QualifiableProxy.java | 11 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java (renamed from src/main/java/ftbsc/lll/proxies/FieldProxy.java) | 25 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/impl/MethodProxy.java (renamed from src/main/java/ftbsc/lll/proxies/MethodProxy.java) | 7 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/impl/PackageProxy.java (renamed from src/main/java/ftbsc/lll/proxies/PackageProxy.java) | 7 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/proxies/impl/TypeProxy.java (renamed from src/main/java/ftbsc/lll/proxies/TypeProxy.java) | 9 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java | 2 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java | 2 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/tools/nodes/TypeProxyInsnNode.java | 2 |
10 files changed, 57 insertions, 31 deletions
diff --git a/src/main/java/ftbsc/lll/proxies/AbstractProxy.java b/src/main/java/ftbsc/lll/proxies/AbstractProxy.java index d60f3d5..054cef9 100644 --- a/src/main/java/ftbsc/lll/proxies/AbstractProxy.java +++ b/src/main/java/ftbsc/lll/proxies/AbstractProxy.java @@ -3,13 +3,17 @@ package ftbsc.lll.proxies; 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 { /** + * Which type of proxy this is. + */ + public final ProxyType proxyType; + + /** * The name of the corresponding element. */ public final String name; @@ -37,12 +41,14 @@ public abstract class AbstractProxy { * @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, String descriptor, int modifiers, QualifiableProxy 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; } /** diff --git a/src/main/java/ftbsc/lll/proxies/ProxyType.java b/src/main/java/ftbsc/lll/proxies/ProxyType.java new file mode 100644 index 0000000..1fd8169 --- /dev/null +++ b/src/main/java/ftbsc/lll/proxies/ProxyType.java @@ -0,0 +1,11 @@ +package ftbsc.lll.proxies; + +/** + * An enum listing the various proxies. + */ +public enum ProxyType { + FIELD, + METHOD, + TYPE, + PACKAGE +} diff --git a/src/main/java/ftbsc/lll/proxies/QualifiableProxy.java b/src/main/java/ftbsc/lll/proxies/QualifiableProxy.java index 885ddc8..d245124 100644 --- a/src/main/java/ftbsc/lll/proxies/QualifiableProxy.java +++ b/src/main/java/ftbsc/lll/proxies/QualifiableProxy.java @@ -1,11 +1,7 @@ package ftbsc.lll.proxies; -import org.objectweb.asm.Type; - /** - * A container for information about an element which has a fully-qualified name. - * @see TypeProxy - * @see PackageProxy + * A proxy for elements who have a fully-qualified name. * @since 0.4.0 */ public abstract class QualifiableProxy extends AbstractProxy { @@ -26,9 +22,10 @@ public abstract class QualifiableProxy extends AbstractProxy { * @param modifiers the modifiers, as a packed int * @param parent the {@link QualifiableProxy} representing the parent of this element * @param fullyQualifiedName the FQN of the element + * @param proxyType the {@link ProxyType} being represented here */ - protected QualifiableProxy(String descriptor, int modifiers, QualifiableProxy parent, String fullyQualifiedName) { - super(extractSimpleNameFromFQN(fullyQualifiedName), descriptor, modifiers, parent); + protected QualifiableProxy(String descriptor, int modifiers, QualifiableProxy parent, String fullyQualifiedName, ProxyType proxyType) { + super(extractSimpleNameFromFQN(fullyQualifiedName), descriptor, modifiers, parent, proxyType); this.fullyQualifiedName = fullyQualifiedName; this.internalName = this.fullyQualifiedName.replace('.', '/'); } diff --git a/src/main/java/ftbsc/lll/proxies/FieldProxy.java b/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java index 8732997..ceb8277 100644 --- a/src/main/java/ftbsc/lll/proxies/FieldProxy.java +++ b/src/main/java/ftbsc/lll/proxies/impl/FieldProxy.java @@ -1,5 +1,8 @@ -package ftbsc.lll.proxies; +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; @@ -11,15 +14,6 @@ import java.lang.reflect.Field; */ 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.getDescriptor(f.getType()), f.getModifiers(), TypeProxy.from(f.getDeclaringClass())); - } - - /** * Protected constructor, called only from the builder. * @param name the name of the field * @param descriptor the descriptor of the field @@ -27,7 +21,16 @@ public class FieldProxy extends AbstractProxy { * @param parent the {@link QualifiableProxy} for the parent */ protected FieldProxy(String name, String descriptor, int modifiers, QualifiableProxy parent) { - super(name, descriptor, modifiers, 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())); } /** diff --git a/src/main/java/ftbsc/lll/proxies/MethodProxy.java b/src/main/java/ftbsc/lll/proxies/impl/MethodProxy.java index c906ec7..3710d36 100644 --- a/src/main/java/ftbsc/lll/proxies/MethodProxy.java +++ b/src/main/java/ftbsc/lll/proxies/impl/MethodProxy.java @@ -1,5 +1,8 @@ -package ftbsc.lll.proxies; +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.Method; @@ -35,7 +38,7 @@ public class MethodProxy extends AbstractProxy { * @param returnType the return type of the method */ protected MethodProxy(String name, int modifiers, QualifiableProxy parent, Type[] parameters, Type returnType) { - super(name, Type.getMethodDescriptor(returnType, parameters), modifiers, parent); + super(name, Type.getMethodDescriptor(returnType, parameters), modifiers, parent, ProxyType.METHOD); this.parameters = Arrays.stream(parameters) .map(t -> TypeProxy.from(t, 0)) .toArray(TypeProxy[]::new); diff --git a/src/main/java/ftbsc/lll/proxies/PackageProxy.java b/src/main/java/ftbsc/lll/proxies/impl/PackageProxy.java index fbfe6c0..5989da3 100644 --- a/src/main/java/ftbsc/lll/proxies/PackageProxy.java +++ b/src/main/java/ftbsc/lll/proxies/impl/PackageProxy.java @@ -1,4 +1,7 @@ -package ftbsc.lll.proxies; +package ftbsc.lll.proxies.impl; + +import ftbsc.lll.proxies.ProxyType; +import ftbsc.lll.proxies.QualifiableProxy; /** * A container for information about a package. @@ -17,7 +20,7 @@ public class PackageProxy extends QualifiableProxy { * @param fqn the fully-qualified name of this package */ protected PackageProxy(PackageProxy parent, String fqn) { - super(null, 0, parent, fqn); + super(null, 0, parent, fqn, ProxyType.PACKAGE); } /** diff --git a/src/main/java/ftbsc/lll/proxies/TypeProxy.java b/src/main/java/ftbsc/lll/proxies/impl/TypeProxy.java index f828f11..9f613b0 100644 --- a/src/main/java/ftbsc/lll/proxies/TypeProxy.java +++ b/src/main/java/ftbsc/lll/proxies/impl/TypeProxy.java @@ -1,5 +1,8 @@ -package ftbsc.lll.proxies; +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.Modifier; @@ -26,7 +29,7 @@ public class TypeProxy extends QualifiableProxy { * @param primitive whether the proxy is a primitive */ protected TypeProxy(String name, String descriptor, int modifiers, String parent, boolean primitive) { - super(descriptor, modifiers, PackageProxy.from(parent), String.format("%s.%s", name, parent)); + super(descriptor, modifiers, PackageProxy.from(parent), String.format("%s.%s", name, parent), ProxyType.TYPE); this.primitive = primitive; } @@ -39,7 +42,7 @@ public class TypeProxy extends QualifiableProxy { * @param containerClass the FQN of the parent class of the class */ protected TypeProxy(String name, String descriptor, int modifiers, QualifiableProxy containerClass, boolean primitive) { - super(descriptor, modifiers, containerClass, String.format("%s$%s", name, containerClass.fullyQualifiedName)); + super(descriptor, modifiers, containerClass, String.format("%s$%s", name, containerClass.fullyQualifiedName), ProxyType.TYPE); this.primitive = primitive; } diff --git a/src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java b/src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java index 068ade0..d1ac595 100644 --- a/src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java +++ b/src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java @@ -1,6 +1,6 @@ package ftbsc.lll.tools.nodes; -import ftbsc.lll.proxies.FieldProxy; +import ftbsc.lll.proxies.impl.FieldProxy; import org.objectweb.asm.tree.FieldInsnNode; /** diff --git a/src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java b/src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java index 01549a8..73a26d7 100644 --- a/src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java +++ b/src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java @@ -1,6 +1,6 @@ package ftbsc.lll.tools.nodes; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import org.objectweb.asm.tree.MethodInsnNode; /** diff --git a/src/main/java/ftbsc/lll/tools/nodes/TypeProxyInsnNode.java b/src/main/java/ftbsc/lll/tools/nodes/TypeProxyInsnNode.java index e5b5f2a..9e78dc9 100644 --- a/src/main/java/ftbsc/lll/tools/nodes/TypeProxyInsnNode.java +++ b/src/main/java/ftbsc/lll/tools/nodes/TypeProxyInsnNode.java @@ -1,6 +1,6 @@ package ftbsc.lll.tools.nodes; -import ftbsc.lll.proxies.TypeProxy; +import ftbsc.lll.proxies.impl.TypeProxy; import org.objectweb.asm.tree.TypeInsnNode; /** |