Package de.geolykt.starloader.launcher

# Class ASMMixinTransformer

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

All Implemented Interfaces:
  `Comparable<ASMTransformer>`, `CodeTransformer`

public final class ASMMixinTransformer extends ASMTransformer implements CodeTransformer

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ASMMixinTransformer(SLMixinService service)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `accept(@NotNull org.objectweb.asm.tree.ClassNode source)`
  Transforms the provided `ClassNode` to the transformer's liking.
  `int`
  `getPriority()`
  Obtains the priority of this transformer.
  `boolean`
  `isValid()`
  Called everytime `ASMTransformer.accept(ClassNode)` is called and returns true and is used to verify whether this transformer is still needed.
  `boolean`
  `isValidTarget(@NotNull String internalName)`
  Checks whether the given class denoted by the internal name would be a valid potential transformation target.
  `boolean`
  `isValidTarget(@NotNull String internalName, @Nullable URI codeSourceURI)`
  Obtains whether this `CodeTransformer` instance is interested in transforming the given class.
  `boolean`
  `transformClass(@NotNull org.objectweb.asm.tree.ClassNode node, @Nullable URI codeSourceURI)`
  Optionally transforms a class, returning `true` if the input `node` was modified, `false` otherwise.

  ### Methods inherited from class de.geolykt.starloader.transformers.ASMTransformer

  `compareTo`

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

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

- ## Constructor Details

  - ### ASMMixinTransformer

    public ASMMixinTransformer(SLMixinService service)

- ## Method Details

  - ### accept

    public boolean accept(@NotNull @NotNull org.objectweb.asm.tree.ClassNode source)
    Description copied from class: `ASMTransformer`
    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.
    Specified by:
      `accept` in class `ASMTransformer`
    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: `CodeTransformer`
    Obtains whether this `CodeTransformer` instance is interested in transforming the given class. Returns `true` if the class with the given internal name is of interest to this transformer, `false` otherwise.

    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 returned `false`. This is a performance-saving measure and is very much akin to `ASMTransformer.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.sourceFile` property of a class. Instead it corresponds to `CodeSource.getLocation()`, hinting at the location of the compiled bytecode.

    Specified by:
      `isValidTarget` in interface `CodeTransformer`
    Parameters:
      `internalName` - The internal name of the class, as per `Type.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 be `null` if 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:
      - `CodeSource`

  - ### isValidTarget

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

  - ### getPriority

    public int getPriority()
    Description copied from class: `ASMTransformer`
    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)
    Overrides:
      `getPriority` in class `ASMTransformer`
    Returns:
      The priority of the transformer

  - ### transformClass

    public boolean transformClass(@NotNull @NotNull org.objectweb.asm.tree.ClassNode node, @Nullable @Nullable URI codeSourceURI)
    Description copied from interface: `CodeTransformer`
    Optionally transforms a class, returning `true` if the input `node` was modified, `false` otherwise.

    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 converting `ClassNode` into `byte[]` isn't exactly free.

    The transformation occurs in-situ, meaning that the input `ClassNode` is transformed as-is without any cloning. Thus the input node is also the output node in some sense.

    Specified by:
      `transformClass` in interface `CodeTransformer`
    Parameters:
      `node` - The input and output `ClassNode` to transform.
      `codeSourceURI` - The `URI` where this class is located in, following the paradigms of `CodeSource.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/` for `file://bin/com/example/Main.class`). If the location of the class file is unknown or cannot be represented as an `URI`, `null` should be used.
    Returns:
      `true` if the input node was transformed, `false` otherwise.