Class ASMTransformer
java.lang.Object
de.geolykt.starloader.transformers.ASMTransformer
- All Implemented Interfaces:
Comparable<ASMTransformer>
- Direct Known Subclasses:
ASMMixinTransformer,ReversibleAccessSetterTransformer,StarplaneAnnotationsInlineTransformer
A bytecode editing API that interfaces with objectweb ASM
ClassNodes.
This allows for harmonious runtime editing of classes without the use of agents.- Since:
- 2.1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanaccept(@NotNull org.objectweb.asm.tree.ClassNode node) Transforms the providedClassNodeto the transformer's liking.intBase implementation ofComparable.compareTo(Object)based ongetPriority().intObtains the priority of this transformer.booleanisValid()Called everytimeaccept(ClassNode)is called and returns true and is used to verify whether this transformer is still needed.abstract booleanisValidTarget(@NotNull String internalName) Checks whether the given class denoted by the internal name would be a valid potential transformation target.
-
Constructor Details
-
ASMTransformer
public ASMTransformer()
-
-
Method Details
-
accept
public abstract boolean accept(@NotNull @NotNull org.objectweb.asm.tree.ClassNode node) Transforms the providedClassNodeto the transformer's liking. Must return true if the class node has been modified, should it not returns false, then the transformation MAY be discarded, however it could also not be discarded. It is best to assume that both are equally possible events.- Parameters:
node- The node to transform- Returns:
- True if the node has been modified.
- Since:
- 2.1.0
-
compareTo
Base implementation ofComparable.compareTo(Object)based ongetPriority(). A return value of 0 indicates that both transformers have the same priority, at which point the application order may be arbitrary.- Specified by:
compareToin interfaceComparable<ASMTransformer>- Parameters:
o- The transformer to compare this transformer against. May not be null.- Returns:
- The difference in priorities.
- Since:
- 4.0.0
-
getPriority
public int getPriority()Obtains the priority of this transformer. The priority is used to note when a transformer should be applied in relation to other transformers. Should two transformers have the same priority, the order will be arbitrary.Transformers with a lower numeric priority value are run first. That is, the higher the priority of a transformer, the more "final" it's descision is.
Important transform priorities are:
- -10_010:
ReversibleAccessSetterTransformer - -10_010:
StarplaneAnnotationsInlineTransformer - -10_000:
ASMMixinTransformer - -9_900: Most SLAPI transformers
- 100: SLAPI GL transformer (intercepts GL11#glScissor calls)
- Returns:
- The priority of the transformer
- Since:
- 4.0.0
- -10_010:
-
isValidTarget
Checks whether the given class denoted by the internal name would be a valid potential transformation target. If this method returns false, thenaccept(ClassNode)should NOT be called, however if it returns true, then it may get called.accept(ClassNode)will not always return true when this method does, however that method should never return true when this method returns false.- Parameters:
internalName- The internal name of the class- Returns:
- Whether it is a potential target
- Since:
- 4.0.0
- See Also:
-
Type.getInternalName()
-
isValid
public boolean isValid()Called everytimeaccept(ClassNode)is called and returns true and is used to verify whether this transformer is still needed. Should this method returns false then the transformer is removed from the classloader's transformer pool.- Returns:
- Whether this transformer is still needed
- Since:
- 2.1.0
-