Class ASMMixinTransformer
- All Implemented Interfaces:
Comparable<ASMTransformer>,CodeTransformer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(@NotNull org.objectweb.asm.tree.ClassNode source) Transforms the providedClassNodeto the transformer's liking.intObtains the priority of this transformer.booleanisValid()Called everytimeASMTransformer.accept(ClassNode)is called and returns true and is used to verify whether this transformer is still needed.booleanisValidTarget(@NotNull String internalName) Checks whether the given class denoted by the internal name would be a valid potential transformation target.booleanisValidTarget(@NotNull String internalName, @Nullable URI codeSourceURI) Obtains whether thisCodeTransformerinstance is interested in transforming the given class.booleantransformClass(@NotNull org.objectweb.asm.tree.ClassNode node, @Nullable URI codeSourceURI) Optionally transforms a class, returningtrueif the inputnodewas modified,falseotherwise.Methods inherited from class de.geolykt.starloader.transformers.ASMTransformer
compareTo
-
Constructor Details
-
ASMMixinTransformer
-
-
Method Details
-
accept
public boolean accept(@NotNull @NotNull org.objectweb.asm.tree.ClassNode source) Description copied from class:ASMTransformerTransforms 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.- Specified by:
acceptin classASMTransformer- Parameters:
source- The node to transform- Returns:
- True if the node has been modified.
-
isValidTarget
public boolean isValidTarget(@NotNull @NotNull String internalName, @Nullable @Nullable URI codeSourceURI) Description copied from interface:CodeTransformerObtains whether thisCodeTransformerinstance is interested in transforming the given class. Returnstrueif the class with the given internal name is of interest to this transformer,falseotherwise.The caller of this method must not call
CodeTransformer.transformClass(ClassNode, URI)for classes with the same name as the one used in a call to this method if that call returnedfalse. This is a performance-saving measure and is very much akin toASMTransformer.isValidTarget(String), except that is also exposes the codeSourceURI of the class.If no transformers mark a class as a valid target, then the bytecode of the class does not need to be transformed into a ClassNode, saving some CPU cycles (meaning faster startup times).
The code source property ought not be confused with the
ClassNode.sourceFileproperty of a class. Instead it corresponds toCodeSource.getLocation(), hinting at the location of the compiled bytecode.- Specified by:
isValidTargetin interfaceCodeTransformer- Parameters:
internalName- The internal name of the class, as perType.getInternalName().codeSourceURI- A URI representing the location of the class source code. This URI will correspond to the JAR in which the class is located in, or the "base" directory of the class as per the classpath. This argument may benullif the caller does not know (or rather - cannot determine) the location of the class bytecode.- Returns:
- True if the target is to be transformed, false otherwise.
- See Also:
-
isValidTarget
Description copied from class:ASMTransformerChecks whether the given class denoted by the internal name would be a valid potential transformation target. If this method returns false, thenASMTransformer.accept(ClassNode)should NOT be called, however if it returns true, then it may get called.ASMTransformer.accept(ClassNode)will not always return true when this method does, however that method should never return true when this method returns false.- Specified by:
isValidTargetin classASMTransformer- Parameters:
internalName- The internal name of the class- Returns:
- Whether it is a potential target
- See Also:
-
Type.getInternalName()
-
isValid
public boolean isValid()Description copied from class:ASMTransformerCalled everytimeASMTransformer.accept(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.- Overrides:
isValidin classASMTransformer- Returns:
- Whether this transformer is still needed
-
getPriority
public int getPriority()Description copied from class:ASMTransformerObtains 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)
- Overrides:
getPriorityin classASMTransformer- Returns:
- The priority of the transformer
- -10_010:
-
transformClass
public boolean transformClass(@NotNull @NotNull org.objectweb.asm.tree.ClassNode node, @Nullable @Nullable URI codeSourceURI) Description copied from interface:CodeTransformerOptionally transforms a class, returningtrueif the inputnodewas modified,falseotherwise.If the node was transformed while this method returned
false, the applied transformations may get discarded, or may also not get discarded. The exact behaviour will likely depend on the behaviour of other classes. Please be aware that debugging such edge case behaviour is extremely difficult as the cause and effects will likely seem to be completely disconnected to the average programmer, and will further not be reproducible in every environment. The return flag mainly exists for performance reasons as convertingClassNodeintobyte[]isn't exactly free.The transformation occurs in-situ, meaning that the input
ClassNodeis transformed as-is without any cloning. Thus the input node is also the output node in some sense.- Specified by:
transformClassin interfaceCodeTransformer- Parameters:
node- The input and outputClassNodeto transform.codeSourceURI- TheURIwhere this class is located in, following the paradigms ofCodeSource.getLocation(). For classes located inside JARs, the URI of the jar will be used. For classes within directories, the URI of the directory is used (i.e.file://bin/forfile://bin/com/example/Main.class). If the location of the class file is unknown or cannot be represented as anURI,nullshould be used.- Returns:
trueif the input node was transformed,falseotherwise.
-