mirror of
https://github.com/zaaarf/lillero.git
synced 2024-11-21 23:14:51 +01:00
chore: reorganize, add ProxyType enum
This commit is contained in:
parent
7e0b4e58dd
commit
17a0b4d017
10 changed files with 57 additions and 31 deletions
|
@ -3,12 +3,16 @@ package ftbsc.lll.proxies;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract proxy class, implementing common aspects
|
* Abstract proxy class, implementing common aspects.
|
||||||
* of {@link MethodProxy} and {@link FieldProxy}.
|
|
||||||
* @since 0.3.0
|
* @since 0.3.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractProxy {
|
public abstract class AbstractProxy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which type of proxy this is.
|
||||||
|
*/
|
||||||
|
public final ProxyType proxyType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the corresponding element.
|
* The name of the corresponding element.
|
||||||
*/
|
*/
|
||||||
|
@ -37,12 +41,14 @@ public abstract class AbstractProxy {
|
||||||
* @param descriptor the descriptor for the element
|
* @param descriptor the descriptor for the element
|
||||||
* @param modifiers the modifiers, as a packed int
|
* @param modifiers the modifiers, as a packed int
|
||||||
* @param parent the FQN of the parent class
|
* @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.name = name;
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
this.proxyType = proxyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
11
src/main/java/ftbsc/lll/proxies/ProxyType.java
Normal file
11
src/main/java/ftbsc/lll/proxies/ProxyType.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package ftbsc.lll.proxies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum listing the various proxies.
|
||||||
|
*/
|
||||||
|
public enum ProxyType {
|
||||||
|
FIELD,
|
||||||
|
METHOD,
|
||||||
|
TYPE,
|
||||||
|
PACKAGE
|
||||||
|
}
|
|
@ -1,11 +1,7 @@
|
||||||
package ftbsc.lll.proxies;
|
package ftbsc.lll.proxies;
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container for information about an element which has a fully-qualified name.
|
* A proxy for elements who have a fully-qualified name.
|
||||||
* @see TypeProxy
|
|
||||||
* @see PackageProxy
|
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
public abstract class QualifiableProxy extends AbstractProxy {
|
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 modifiers the modifiers, as a packed int
|
||||||
* @param parent the {@link QualifiableProxy} representing the parent of this element
|
* @param parent the {@link QualifiableProxy} representing the parent of this element
|
||||||
* @param fullyQualifiedName the FQN of the 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) {
|
protected QualifiableProxy(String descriptor, int modifiers, QualifiableProxy parent, String fullyQualifiedName, ProxyType proxyType) {
|
||||||
super(extractSimpleNameFromFQN(fullyQualifiedName), descriptor, modifiers, parent);
|
super(extractSimpleNameFromFQN(fullyQualifiedName), descriptor, modifiers, parent, proxyType);
|
||||||
this.fullyQualifiedName = fullyQualifiedName;
|
this.fullyQualifiedName = fullyQualifiedName;
|
||||||
this.internalName = this.fullyQualifiedName.replace('.', '/');
|
this.internalName = this.fullyQualifiedName.replace('.', '/');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -10,15 +13,6 @@ import java.lang.reflect.Field;
|
||||||
* @since 0.3.0
|
* @since 0.3.0
|
||||||
*/
|
*/
|
||||||
public class FieldProxy extends AbstractProxy {
|
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.
|
* Protected constructor, called only from the builder.
|
||||||
* @param name the name of the field
|
* @param name the name of the field
|
||||||
|
@ -27,7 +21,16 @@ public class FieldProxy extends AbstractProxy {
|
||||||
* @param parent the {@link QualifiableProxy} for the parent
|
* @param parent the {@link QualifiableProxy} for the parent
|
||||||
*/
|
*/
|
||||||
protected FieldProxy(String name, String descriptor, int modifiers, QualifiableProxy 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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -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 org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -35,7 +38,7 @@ public class MethodProxy extends AbstractProxy {
|
||||||
* @param returnType the return type of the method
|
* @param returnType the return type of the method
|
||||||
*/
|
*/
|
||||||
protected MethodProxy(String name, int modifiers, QualifiableProxy parent, Type[] parameters, Type returnType) {
|
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)
|
this.parameters = Arrays.stream(parameters)
|
||||||
.map(t -> TypeProxy.from(t, 0))
|
.map(t -> TypeProxy.from(t, 0))
|
||||||
.toArray(TypeProxy[]::new);
|
.toArray(TypeProxy[]::new);
|
|
@ -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.
|
* 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
|
* @param fqn the fully-qualified name of this package
|
||||||
*/
|
*/
|
||||||
protected PackageProxy(PackageProxy parent, String fqn) {
|
protected PackageProxy(PackageProxy parent, String fqn) {
|
||||||
super(null, 0, parent, fqn);
|
super(null, 0, parent, fqn, ProxyType.PACKAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -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 org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -26,7 +29,7 @@ public class TypeProxy extends QualifiableProxy {
|
||||||
* @param primitive whether the proxy is a primitive
|
* @param primitive whether the proxy is a primitive
|
||||||
*/
|
*/
|
||||||
protected TypeProxy(String name, String descriptor, int modifiers, String parent, boolean 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;
|
this.primitive = primitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +42,7 @@ public class TypeProxy extends QualifiableProxy {
|
||||||
* @param containerClass the FQN of the parent class of the class
|
* @param containerClass the FQN of the parent class of the class
|
||||||
*/
|
*/
|
||||||
protected TypeProxy(String name, String descriptor, int modifiers, QualifiableProxy containerClass, boolean primitive) {
|
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;
|
this.primitive = primitive;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ftbsc.lll.tools.nodes;
|
package ftbsc.lll.tools.nodes;
|
||||||
|
|
||||||
import ftbsc.lll.proxies.FieldProxy;
|
import ftbsc.lll.proxies.impl.FieldProxy;
|
||||||
import org.objectweb.asm.tree.FieldInsnNode;
|
import org.objectweb.asm.tree.FieldInsnNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ftbsc.lll.tools.nodes;
|
package ftbsc.lll.tools.nodes;
|
||||||
|
|
||||||
import ftbsc.lll.proxies.MethodProxy;
|
import ftbsc.lll.proxies.impl.MethodProxy;
|
||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ftbsc.lll.tools.nodes;
|
package ftbsc.lll.tools.nodes;
|
||||||
|
|
||||||
import ftbsc.lll.proxies.TypeProxy;
|
import ftbsc.lll.proxies.impl.TypeProxy;
|
||||||
import org.objectweb.asm.tree.TypeInsnNode;
|
import org.objectweb.asm.tree.TypeInsnNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue