Class MemberInfo
- All Implemented Interfaces:
ITargetSelector,ITargetSelectorByName,ITargetSelectorConstructor,ITargetSelectorRemappable
Struct which defines an Explcit Target selector, See
ITargetSelector for other supported selector types. This struct is
also used as a general-purpose information bundle about a member (method or
field) parsed from a String token in another annotation, this is used where
target members need to be specified as Strings in order to parse the String
representation to something useful.
In general a MemberInfo consists of 4 parts, owner, name, quantifier and descriptor, all of which are optional:
| Owner | Name | Quantifier | Descriptor | Resulting selector string | ||
|---|---|---|---|---|---|---|
| Method | Lfully/qualified/OwnerClass; | methodName | {1,3} | (III)V | Lfully/qualified/OwnerClass;methodName{1,3}(III)V | |
| Field | Lfully/qualified/OwnerClass; | fieldName | * | : | Ljava/lang/String; | Lfully/qualified/OwnerClass;fieldName*:Ljava/lang/String; |
Any part of the selector can be omitted, though they must appear in the correct order. Some examples:
// selects a method or field called func_1234_a, if there are multiple
// members with the same signature, matches the first occurrence
func_1234_a
// selects a method or field called func_1234_a, if there are multiple
// members with matching name, matches all occurrences
func_1234_a*
// selects a method or field called func_1234_a, if there are multiple
// members with matching name, matches all occurrences, matching less than 1
// occurrence is an error condition
func_1234_a+
// selects a method or field called func_1234_a, if there are multiple
// members with matching name, matches up to 3 occurrences
func_1234_a{,3}
// selects a method or field called func_1234_a, if there are multiple
// members with matching name, matches exactly 3 occurrences, matching fewer
// than 3 occurrences is an error condition
func_1234_a{3}
// selects a method or field called func_1234_a, if there are multiple
// members with matching name, matches at least 3 occurrences, matching fewer
// than 3 occurrences is an error condition
func_1234_a{3,}
// selects all members of any type and descriptor
*
// selects the first member of any type and descriptor
{1}
// selects all methods which take 3 ints and return a bool
*(III)Z
// selects the first 2 methods which take a bool and return void
{2}(Z)V
// selects a method called func_1234_a which takes 3 ints and returns a
bool
func_1234_a(III)Z
// selects a field called field_5678_z which is a String
field_5678_z:Ljava/lang/String;
// selects a ctor which takes a single String argument
<init>(Ljava/lang/String;)V
// selects a method called func_1234_a in class foo.bar.Baz
Lfoo/bar/Baz;func_1234_a
// selects a field called field_5678_z in class com.example.Dave
Lcom/example/Dave;field_5678_z
// selects a field called field_5678_z in class com.example.Dave
// which is of type String
Lcom/example/Dave;field_5678_z:Ljava/lang/String;
// selects a method called func_1234_a in class foo.bar.Baz which
// takes three doubles and returns void
Lfoo/bar/Baz;func_1234_a(DDD)V
// alternate syntax for the same
foo.bar.Baz.func_1234_a(DDD)V
Notes
- All whitespace in the selector string is stripped before the selector is parsed.
- Quantifiers for selectors can be used as a form of early validation (prior to injector require directives) that an injection point has matched a required number of targets or to limit the number of matches it can return.
- The syntax for quantifiers is based on the
syntax for quantifiers in regular expressions, though more
limited. In particular:
- No quantifer is equivalent to the regex ? quantifier, in that undecorated selectors can match {0,1}, this is for backward compatibility reasons. Likewise ? is not supported since it's implied. To require exactly one match use {1}.
- The quantifiers * and + work the same as their regex counterparts.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
ITargetSelector.Configure -
Constructor Summary
ConstructorsConstructorDescriptionMemberInfo(String name, String owner, String desc) ctorMemberInfo(String name, String owner, String desc, Quantifier matches) ctorMemberInfo(String name, String owner, String desc, Quantifier matches, String tail) ctorMemberInfo(String name, String owner, String desc, Quantifier matches, String tail, String input) ctorMemberInfo(String name, String owner, Quantifier matches) ctorMemberInfo(String name, Quantifier matches) ctorMemberInfo(org.objectweb.asm.tree.AbstractInsnNode insn) Initialise a MemberInfo using the supplied insn which must be an instance of MethodInsnNode or FieldInsnNode.MemberInfo(IMapping<?> mapping) Initialise a MemberInfo using the supplied mapping object -
Method Summary
Modifier and TypeMethodDescriptionReturns this MemberInfo as a mapping fieldIMapping<?> Returns this MemberInfo as aMappingFieldorMappingMethodReturns this MemberInfo as a mapping methodattach(ISelectorContext context) Attach this selector to the specified context.configure(ITargetSelector.Configure request, String... args) Configure and return a modified version of this selector by consuming the supplied arguments.booleanstatic MemberInfofromMapping(IMapping<?> mapping) Return the supplied mapping parsed as a MemberInfogetDesc()Get the member descriptor, can be nullintMaximum number of candidates this selector can matchintMinimum number of candidates this selector must matchgetName()Get the member name, can be nullgetOwner()Get the member owner, can be nullinthashCode()booleanGet whether this member represents a class initialiserbooleanGet whether this member represents a constructorbooleanisField()Get whether this MemberInfo is definitely a field, the output of this method is undefined ifisFullyQualified()returns false.booleanGet whether this reference is fully qualifiedbooleanGet whether this member represents a constructor or class initialiser<TNode> MatchResultmatch(ElementNode<TNode> node) Test whether this selector matches the supplied element nodeTest whether this selector matches the supplied values.Create a new version of this member with a different ownernext()Get the next target selector in this path (or null if this selector is the last selector in the chain.static MemberInfoparse(String input, ISelectorContext context) Parse a MemberInfo from a stringremapUsing(MappingMethod srgMethod, boolean setOwner) Create a remapped version of this member using the supplied method dataReturns the constructor descriptor represented by this MemberInfo, returns null if no descriptor is present.Returns the constructor type represented by this MemberInfoReturns this MemberInfo as a java-style descriptortoSrg()Deprecated.use m.asMethodMapping().serialise() insteadtoString()Create a new version of this member with a different descriptorvalidate()Perform ultra-simple validation of the descriptor, checks that the parts of the descriptor are basically sane.
-
Constructor Details
-
MemberInfo
ctor- Parameters:
name- Member name, must not be nullmatches- Quantifier specifying the number of matches required
-
MemberInfo
ctor- Parameters:
name- Member name, must not be nullowner- Member owner, can be null otherwise must be in internal form without L;matches- Quantifier specifying the number of matches required
-
MemberInfo
ctor- Parameters:
name- Member name, must not be nullowner- Member owner, can be null otherwise must be in internal form without L;desc- Member descriptor, can be null
-
MemberInfo
ctor- Parameters:
name- Member name, must not be nullowner- Member owner, can be null otherwise must be in internal form without L;desc- Member descriptor, can be nullmatches- Quantifier specifying the number of matches required
-
MemberInfo
ctor- Parameters:
name- Member name, must not be nullowner- Member owner, can be null otherwise must be in internal form without L;desc- Member descriptor, can be nullmatches- Quantifier specifying the number of matches required
-
MemberInfo
public MemberInfo(String name, String owner, String desc, Quantifier matches, String tail, String input) ctor- Parameters:
name- Member name, must not be nullowner- Member owner, can be null otherwise must be in internal form without L;desc- Member descriptor, can be nullmatches- Quantifier specifying the number of matches required
-
MemberInfo
public MemberInfo(org.objectweb.asm.tree.AbstractInsnNode insn) Initialise a MemberInfo using the supplied insn which must be an instance of MethodInsnNode or FieldInsnNode.- Parameters:
insn- instruction node to copy values from
-
MemberInfo
Initialise a MemberInfo using the supplied mapping object- Parameters:
mapping- Mapping object to copy values from
-
-
Method Details
-
next
Description copied from interface:ITargetSelectorGet the next target selector in this path (or null if this selector is the last selector in the chain. Called at recurse points in the subject in order to match against the child subject.Can return null
- Specified by:
nextin interfaceITargetSelector
-
getOwner
Description copied from interface:ITargetSelectorByNameGet the member owner, can be null- Specified by:
getOwnerin interfaceITargetSelectorByName
-
getName
Description copied from interface:ITargetSelectorByNameGet the member name, can be null- Specified by:
getNamein interfaceITargetSelectorByName
-
getDesc
Description copied from interface:ITargetSelectorByNameGet the member descriptor, can be null- Specified by:
getDescin interfaceITargetSelectorByName
-
getMinMatchCount
public int getMinMatchCount()Description copied from interface:ITargetSelectorMinimum number of candidates this selector must match- Specified by:
getMinMatchCountin interfaceITargetSelector
-
getMaxMatchCount
public int getMaxMatchCount()Description copied from interface:ITargetSelectorMaximum number of candidates this selector can match- Specified by:
getMaxMatchCountin interfaceITargetSelector
-
toString
-
toSrg
Deprecated.use m.asMethodMapping().serialise() insteadReturn this MemberInfo as an SRG mapping- Returns:
- SRG representation of this MemberInfo
-
toDescriptor
Returns this MemberInfo as a java-style descriptor- Specified by:
toDescriptorin interfaceITargetSelectorByName
-
toCtorType
Returns the constructor type represented by this MemberInfo- Specified by:
toCtorTypein interfaceITargetSelectorConstructor
-
toCtorDesc
Returns the constructor descriptor represented by this MemberInfo, returns null if no descriptor is present.- Specified by:
toCtorDescin interfaceITargetSelectorConstructor
-
asMapping
Returns this MemberInfo as aMappingFieldorMappingMethod- Specified by:
asMappingin interfaceITargetSelectorRemappable
-
asMethodMapping
Returns this MemberInfo as a mapping method- Specified by:
asMethodMappingin interfaceITargetSelectorRemappable
-
asFieldMapping
Returns this MemberInfo as a mapping field- Specified by:
asFieldMappingin interfaceITargetSelectorRemappable
-
isFullyQualified
public boolean isFullyQualified()Description copied from interface:ITargetSelectorRemappableGet whether this reference is fully qualified- Specified by:
isFullyQualifiedin interfaceITargetSelectorRemappable- Returns:
- true if all components of this reference are non-null
-
isField
public boolean isField()Get whether this MemberInfo is definitely a field, the output of this method is undefined ifisFullyQualified()returns false.- Specified by:
isFieldin interfaceITargetSelectorRemappable- Returns:
- true if this is definitely a field
-
isConstructor
public boolean isConstructor()Get whether this member represents a constructor- Specified by:
isConstructorin interfaceITargetSelectorRemappable- Returns:
- true if member name is <init>
-
isClassInitialiser
public boolean isClassInitialiser()Get whether this member represents a class initialiser- Specified by:
isClassInitialiserin interfaceITargetSelectorRemappable- Returns:
- true if member name is <clinit>
-
isInitialiser
public boolean isInitialiser()Get whether this member represents a constructor or class initialiser- Specified by:
isInitialiserin interfaceITargetSelectorRemappable- Returns:
- true if member name is <init> or <clinit>
-
validate
Perform ultra-simple validation of the descriptor, checks that the parts of the descriptor are basically sane.- Specified by:
validatein interfaceITargetSelector- Returns:
- fluent
- Throws:
InvalidSelectorException- if any validation check fails
-
match
Description copied from interface:ITargetSelectorTest whether this selector matches the supplied element node- Specified by:
matchin interfaceITargetSelector- Type Parameters:
TNode- node type- Parameters:
node- node node to test- Returns:
- true if this selector can match the supplied field
-
matches
Description copied from interface:ITargetSelectorByNameTest whether this selector matches the supplied values. Null values are ignored.- Specified by:
matchesin interfaceITargetSelectorByName- Parameters:
owner- Owner to compare with, null to skipname- Name to compare with, null to skipdesc- Signature to compare with, null to skip- Returns:
- true if all non-null values in this reference match non-null arguments supplied to this method
-
equals
-
hashCode
public int hashCode() -
configure
Description copied from interface:ITargetSelectorConfigure and return a modified version of this selector by consuming the supplied arguments. Results from this method should be idempotent in terms of the configuration of the returned object, but do not have to necessarily return the same object if the callee already matches the supplied configuration, or if the requested mutation is not supported by the selector, though this is generally the case.In other words, calling configure(Configure.ORPHAN) when this object is already an orphan or does not support orphaning, may simply return this object, or might return an identically-configured copy.
Must not return null, defaults to returning unmodified selector.
- Specified by:
configurein interfaceITargetSelector- Parameters:
request- Requested operationargs- Configuration arguments- Returns:
- Configured selector, may return this selector if the specified condition is already satisfied
-
attach
Description copied from interface:ITargetSelectorAttach this selector to the specified context. Should return this selector unmodified if all is well, or a new selector to be used for further processing of the supplied context. If the supplied context is invalid, anInvalidSelectorExceptionis thrown.- Specified by:
attachin interfaceITargetSelector- Parameters:
context- Context to attach to- Returns:
- Attached selector
- Throws:
InvalidSelectorException
-
move
Create a new version of this member with a different owner- Specified by:
movein interfaceITargetSelectorRemappable- Parameters:
newOwner- New owner for this member
-
transform
Create a new version of this member with a different descriptor- Specified by:
transformin interfaceITargetSelectorRemappable- Parameters:
newDesc- New descriptor for this member
-
remapUsing
Create a remapped version of this member using the supplied method data- Specified by:
remapUsingin interfaceITargetSelectorRemappable- Parameters:
srgMethod- SRG method data to usesetOwner- True to set the owner as well as the name- Returns:
- New MethodInfo with remapped values
-
parse
Parse a MemberInfo from a string- Parameters:
input- String to parse MemberInfo fromcontext- Selector context for this parse request- Returns:
- parsed MemberInfo
-
fromMapping
Return the supplied mapping parsed as a MemberInfo- Parameters:
mapping- mapping to parse- Returns:
- new MemberInfo
-