Package de.geolykt.starloader.transformers

# Class ASMTransformer

java.lang.Object
de.geolykt.starloader.transformers.ASMTransformer

All Implemented Interfaces:
  `Comparable<ASMTransformer>`

Direct Known Subclasses:
  `ASMMixinTransformer`, `ReversibleAccessSetterTransformer`, `StarplaneAnnotationsInlineTransformer`

public abstract class ASMTransformer extends Object implements Comparable<ASMTransformer>
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
  Constructor
  Description
  `ASMTransformer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract boolean`
  `accept(@NotNull org.objectweb.asm.tree.ClassNode node)`
  Transforms the provided `ClassNode` to the transformer's liking.
  `int`
  `compareTo(ASMTransformer o)`
  Base implementation of `Comparable.compareTo(Object)` based on `getPriority()`.
  `int`
  `getPriority()`
  Obtains the priority of this transformer.
  `boolean`
  `isValid()`
  Called everytime `accept(ClassNode)` is called and returns true and is used to verify whether this transformer is still needed.
  `abstract boolean`
  `isValidTarget(@NotNull String internalName)`
  Checks whether the given class denoted by the internal name would be a valid potential transformation target.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ASMTransformer

    public ASMTransformer()

- ## Method Details

  - ### accept

    public abstract boolean accept(@NotNull @NotNull org.objectweb.asm.tree.ClassNode node)
    Transforms the provided `ClassNode` to 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

    public int compareTo(ASMTransformer o)
    Base implementation of `Comparable.compareTo(Object)` based on `getPriority()`. A return value of 0 indicates that both transformers have the same priority, at which point the application order may be arbitrary.
    Specified by:
      `compareTo` in interface `Comparable<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

  - ### isValidTarget

    public abstract boolean isValidTarget(@NotNull @NotNull String internalName)
    Checks whether the given class denoted by the internal name would be a valid potential transformation target. If this method returns false, then `accept(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 everytime `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.
    Returns:
      Whether this transformer is still needed
    Since:
      2.1.0