Class ReplaceFieldComparisonWithInstanceOf
java.lang.Object
net.neoforged.neoforgespi.transformation.BaseSimpleProcessor
net.neoforged.neoforgespi.transformation.SimpleMethodProcessor
net.neoforged.neoforge.coremods.ReplaceFieldComparisonWithInstanceOf
- All Implemented Interfaces:
ClassProcessor
Replaces code such as
itemstack.getItem() == Items.CROSSBOW with instanceof checks such
as itemstack.getItem() instanceof CrossbowItem.
This transformer targets a set of methods to replace the occurrence of a single field-comparison.-
Nested Class Summary
Nested classes/interfaces inherited from class SimpleMethodProcessor
SimpleMethodProcessor.TargetNested classes/interfaces inherited from interface ClassProcessor
ClassProcessor.AfterProcessingContext, ClassProcessor.ComputeFlags, ClassProcessor.LinkContext, ClassProcessor.OrderingHint, ClassProcessor.SelectionContext, ClassProcessor.TransformationContext -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate final Stringprivate static final org.slf4j.Loggerprivate final Stringprivate final Set<SimpleMethodProcessor.Target> Fields inherited from interface ClassProcessor
GENERATED_PACKAGE_MODULE -
Constructor Summary
ConstructorsConstructorDescriptionReplaceFieldComparisonWithInstanceOf(String fieldOwner, String fieldName, String replacementClassName, List<SimpleMethodProcessor.Target> methodsToScan) -
Method Summary
Modifier and TypeMethodDescriptionname()Returns a unique identifier for this processor.targets()Returns the methods targeted by this processor.voidtransform(org.objectweb.asm.tree.MethodNode methodNode, SimpleTransformationContext context) Applies transformations to a targeted method.Methods inherited from class SimpleMethodProcessor
handlesClass, processClassMethods inherited from class BaseSimpleProcessor
afterProcessing, link, runsAfterMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ClassProcessor
generatesPackages, orderingHint, runsBefore
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
targets
-
fieldOwner
-
fieldName
-
replacementClassName
-
-
Constructor Details
-
ReplaceFieldComparisonWithInstanceOf
public ReplaceFieldComparisonWithInstanceOf(String fieldOwner, String fieldName, String replacementClassName, List<SimpleMethodProcessor.Target> methodsToScan) - Parameters:
fieldOwner- The class that ownsfieldNamefieldName- The name of a field infieldOwnerreplacementClassName- Reference comparisons againstfieldNameinfieldOwnerare replaced by instanceof checks against this class.methodsToScan- The methods to scan
-
-
Method Details
-
name
Description copied from interface:ClassProcessorReturns a unique identifier for this processor.- Returns:
- a unique identifier for this processor
-
targets
Description copied from class:SimpleMethodProcessorReturns the methods targeted by this processor.- Specified by:
targetsin classSimpleMethodProcessor- Returns:
- the methods targeted by this processor
-
transform
public void transform(org.objectweb.asm.tree.MethodNode methodNode, SimpleTransformationContext context) Description copied from class:SimpleMethodProcessorApplies transformations to a targeted method.- Specified by:
transformin classSimpleMethodProcessor- Parameters:
methodNode- The ASM input node, which can be mutated directly
-