Interface ClassProcessor

All Known Implementing Classes:
AccessTransformerService, BaseSimpleProcessor, FMLMixinClassProcessor, MethodRedirector, NeoForgeDevDistCleaner, ReplaceFieldComparisonWithInstanceOf, ReplaceFieldWithGetterAccess, RuntimeEnumExtender, SimpleClassProcessor, SimpleFieldProcessor, SimpleMethodProcessor, SimpleProcessorsGroup

public interface ClassProcessor
Class processors provide an API for transforming classes as they are loaded. They take care to use correctly and efficiently. The main pieces of a processor are handlesClass(SelectionContext) and processClass(TransformationContext), which allow processors to say whether they want to process a given class and allow them to transform the class. Processors are named and should have sensible namespaces; ordering is accomplished by specifying names that processors should run before or after if present.

For a simpler API, see SimpleClassProcessor, SimpleMethodProcessor, and SimpleFieldProcessor.

Class processors can be provided using the Java ServiceLoader mechanism. If you require more control, you can also implement a ClassProcessorProvider.

  • Field Details

  • Method Details

    • name

      Returns a unique identifier for this processor.
      Returns:
      a unique identifier for this processor
    • runsBefore

      default Set<ProcessorName> runsBefore()
      Returns processors that this processor must run before.
      Returns:
      processors that this processor must run before
    • runsAfter

      default Set<ProcessorName> runsAfter()
      Returns processors that this processor must run after. This should include ClassProcessorIds.COMPUTING_FRAMES if the processor returns a result requiring frame re-computation.
      Returns:
      processors that this processor must run after
    • generatesPackages

      default Set<String> generatesPackages()
      Returns packages that this processor generates classes for, that do not already exist on the game layer. Generated packages in the game layer will be in the module "net.neoforged.fml.generated".
      Returns:
      packages that this processor generates classes for, that do not already exist on the game layer
    • orderingHint

      default ClassProcessor.OrderingHint orderingHint()
      Returns a hint for how this processor should be ordered relative to other processors. Note that this is a comparatively weak hint; runsBefore() and runsAfter() take precedence, and processors don't have "phases" of any sort.
      Returns:
      a hint for how this processor should be ordered relative to other processors
    • handlesClass

      boolean handlesClass(ClassProcessor.SelectionContext context)
      Returns whether the processor wants to recieve the class.
      Parameters:
      context - the context of the class to consider
      Returns:
      whether the processor wants to recieve the class
    • processClass

      Each class that the processor has opted to recieve is passed to this method for processing.
      Parameters:
      context - the context of the class to process
      Returns:
      the ClassProcessor.ComputeFlags indicating how the class should be rewritten.
    • afterProcessing

      default void afterProcessing(ClassProcessor.AfterProcessingContext context)
      Where a class may be processed multiple times by the same processor (for example, if in addition to being loaded a later processor requests the state of the given class using a BytecodeProvider), an after-processing callback is guaranteed to run at most once per class, just before class load. A transformer will only see this context for classes it has processed.
      Parameters:
      context - the context of the class that was processed
    • link

      default void link(ClassProcessor.LinkContext context)
      Called once after a set of class processors has been linked together with a bytecode source. FML will not call transformation methods on this class processor, until it has been linked.

      FML only links providers once during startup.