Class HierarchyAwareMappingDelegator<T extends MappingLookup & MappingSink>
- Type Parameters:
T- The type ofMappingLookupto use as a the delegate (it must implementMappingSink, too)
- All Implemented Interfaces:
MappingLookup,MappingSink
- Direct Known Subclasses:
SimpleHierarchyAwareMappingLookup
HierarchyAwareMappingDelegator is an implementation of MappingLookup that binds mappings of class members
provided by MappingSink.remapMember(MemberRef, String) to their top level definition. The actual storage of mappings
are handled by a defined delegated MappingLookup (which also implements the MappingSink instance) of type
T.
The main point in using this delegator is in ensuring that disjointed method overrides do not happen, although this
MappingLookup still allows for name collisions to occur (unless the delegate prohibits it - read up on the
behaviour of delegates)
Thread safety and concurrency
The thread safety and concurrency guarantees are only as strong as the components of the instance of the class. If theHierarchyAwareMappingDelegator.TopLevelMemberLookup and the used delegate are both thread-safe, then this class is thread-safe, too.
In case of doubt, don't use instances of this class in an concurrent environment.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for obtaining the root definition of a member. -
Constructor Summary
ConstructorsConstructorDescriptionHierarchyAwareMappingDelegator(T lookupDelegate, @NotNull HierarchyAwareMappingDelegator.TopLevelMemberLookup definitionLookup) Creates aHierarchyAwareMappingDelegatorwith the delegatelookupDelegateof type T and a givenHierarchyAwareMappingDelegator.TopLevelMemberLookup. -
Method Summary
Modifier and TypeMethodDescription@NotNull StringgetRemappedClassName(@NotNull String srcName) Obtains the name of the class in the destination namespace (or in laymen's terms the remapped name).@Nullable StringgetRemappedClassNameFast(@NotNull String srcName) Obtains the name of the class in the destination namespace (or in laymen's terms the remapped name).@NotNull StringgetRemappedFieldName(@NotNull String srcOwner, @NotNull String srcName, @NotNull String srcDesc) Obtains the name of a field in the destination namespace (or the mapped name).@NotNull StringgetRemappedMethodName(@NotNull String srcOwner, @NotNull String srcName, @NotNull String srcDesc) Obtains the name of a field in the destination namespace (or the mapped name).@Nullable StringgetRemappedParameterName(@NotNull String srcOwner, @NotNull String srcName, @NotNull String srcDesc, int paramIndex, boolean isStatic) Obtains the name of the parameter in the destination namespace (or in laymen's terms the remapped name of the parameter).@NotNull HierarchyAwareMappingDelegator<T>remapClass(@NotNull String srcName, @NotNull String dstName) Remaps a specific class.@NotNull HierarchyAwareMappingDelegator<T>remapMember(@NotNull MemberRef srcRef, @NotNull String dstName) Remaps a class member - that is either a field or a method.@NotNull MappingSinkremapParameter(@NotNull String srcOwner, @NotNull String srcMethodName, @NotNull String srcDesc, int paramIndex, @NotNull String destParamName) Remaps a method parameter.
-
Constructor Details
-
HierarchyAwareMappingDelegator
public HierarchyAwareMappingDelegator(@NotNull T lookupDelegate, @NotNull @NotNull HierarchyAwareMappingDelegator.TopLevelMemberLookup definitionLookup) Creates aHierarchyAwareMappingDelegatorwith the delegatelookupDelegateof type T and a givenHierarchyAwareMappingDelegator.TopLevelMemberLookup.- Parameters:
lookupDelegate- The object to which all lookup and sink calls are delegated to.definitionLookup- The lookup that is used to acquire the top-level definition of a class member.
-
-
Method Details
-
getRemappedClassName
Description copied from interface:MappingLookupObtains the name of the class in the destination namespace (or in laymen's terms the remapped name). If the class name in the source namespace is equal to the name in the destination namespace (e.g. because there is no mapping), then the name in the source namespace must be returned.It is valid to have
MappingLookup.getRemappedClassNameFast(String)andMappingLookup.getRemappedClassName(String)be the same implementation for as long asMappingLookup.getRemappedClassName(String)never returns null, however doing so might incur a slight performance reduction.srcName and the returned value are in the same format as
Type.getInternalName().- Specified by:
getRemappedClassNamein interfaceMappingLookup- Parameters:
srcName- The name of the class in the source namespace- Returns:
- The mapped name in the destination namespace, or the name in the source namespace if no mapping exists.
-
getRemappedClassNameFast
Description copied from interface:MappingLookupObtains the name of the class in the destination namespace (or in laymen's terms the remapped name). If the class name in the source namespace is equal to the name in the destination namespace (e.g. because there is no mapping), then null can be returned for performance reasons.This is especially done when some string manipulation can be skipped if the source name equals the destination name.
It is valid to have
MappingLookup.getRemappedClassNameFast(String)andMappingLookup.getRemappedClassName(String)be the same implementation for as long asMappingLookup.getRemappedClassName(String)never returns null, however doing so might incur a slight performance reduction.srcName and the returned value are in the same format as
Type.getInternalName().- Specified by:
getRemappedClassNameFastin interfaceMappingLookup- Parameters:
srcName- The name of the class in the source namespace- Returns:
- The name in the destination namespace, or null if the name is the same as the source namespace
-
getRemappedFieldName
@NotNull public @NotNull String getRemappedFieldName(@NotNull @NotNull String srcOwner, @NotNull @NotNull String srcName, @NotNull @NotNull String srcDesc) Description copied from interface:MappingLookupObtains the name of a field in the destination namespace (or the mapped name). If the field is not known or if no mapping exists for the field, then the name in the source namespace must be returned (that is the srcName parameter).srcOwner is in the same format as
Type.getInternalName().Implementations of this interface are encouraged to not throw if possible.
- Specified by:
getRemappedFieldNamein interfaceMappingLookup- Parameters:
srcOwner- The name of the owner of the member in the source namespacesrcName- The name of the member in the source namespacesrcDesc- The descriptor of the member (where as classes are all in the source namespace)- Returns:
- The mapped name in the destination namespace, or the name in the source namespace if no mapping exists.
-
getRemappedMethodName
@NotNull public @NotNull String getRemappedMethodName(@NotNull @NotNull String srcOwner, @NotNull @NotNull String srcName, @NotNull @NotNull String srcDesc) Description copied from interface:MappingLookupObtains the name of a field in the destination namespace (or the mapped name). If the field is not known or if no mapping exists for the field, then the name in the source namespace must be returned (that is the srcName parameter).srcOwner is in the same format as
Type.getInternalName().Implementations of this interface are encouraged to not throw if possible.
- Specified by:
getRemappedMethodNamein interfaceMappingLookup- Parameters:
srcOwner- The name of the owner of the member in the source namespacesrcName- The name of the member in the source namespacesrcDesc- The descriptor of the member (where as classes are all in the source namespace)- Returns:
- The mapped name in the destination namespace, or the name in the source namespace if no mapping exists.
-
getRemappedParameterName
@Nullable public @Nullable String getRemappedParameterName(@NotNull @NotNull String srcOwner, @NotNull @NotNull String srcName, @NotNull @NotNull String srcDesc, int paramIndex, boolean isStatic) Description copied from interface:MappingLookupObtains the name of the parameter in the destination namespace (or in laymen's terms the remapped name of the parameter). Should the name of the parameter not be known in the destination namespace, thennullis returned. This is the default behaviour of this method.The
paramIndexargument is 0-indexed. It does not distinguish between computational categories. Or in other words, for both(IZ)Vand(JZ)Vthe boolean parameter corresponds to aparamIndexvalue of 1, while the integer and long have a value of 0.Callers may throw an
IndexOutOfBoundsExceptionifparamIndexis below 0 or above the amount of parameters as discernible bysrcDesc. As such, this method cannot be used to remap LVT entries, even though they are quite similar in structure. This is because LVT entries can be reused. By default this method does not do any checks whetherparamIndexis a valid value. This is done for performance reasons.Implementations of this method are encouraged to not throw if possible, unless for reasons described above. While it theoretically makes sense to throw an exception in cases where a method is known to not exist, this is generally rarely the case.
If this
MappingLookupinstance does not support remapping parameters, thennullshould be returned unconditionally, without throwing outside of aforementioned reasons.- Specified by:
getRemappedParameterNamein interfaceMappingLookup- Parameters:
srcOwner- The name of the owner of the member in the source namespace.srcName- The name of the member in the source namespace.srcDesc- The descriptor of the member (where as classes are all in the source namespace).paramIndex- The index of the parameter, excluding the impliedthisparameter.isStatic- Whether the method is static. Used when working with mappings formats such as Enigma, TINYv2, or TSRG.- Returns:
- The name of the parameter in the destination namespace, or
nullif not applicable.
-
remapClass
@NotNull public @NotNull HierarchyAwareMappingDelegator<T> remapClass(@NotNull @NotNull String srcName, @NotNull @NotNull String dstName) Description copied from interface:MappingSinkRemaps a specific class. Do note that this makes no promises on inner classes. That is using the dollar ('$') sign or a dot ('.') has no effect on the internal arrangement of inner class nodes. Inner classes are as of now not handled by theRemapperimplementation and if implemented would be independent of this method.Class names are defined via the
internal nameof a class - that is forward slashes ('/') are used instead of dots ('.'). Usage of dots or semicolons (';') are completely forbidden as they are not allowed in the JVMS within internal names of classes.Implementations are not required to ensure that the class names make sense or are valid - the burden of verification falls upon the caller.
- Specified by:
remapClassin interfaceMappingSink- Parameters:
srcName- The name of the member in the source namespace (that is the unmapped name)dstName- The name of the member in the destination namespace (that is the mapped name)- Returns:
- The current
MappingSinkinstance (i.e. this), for chaining
-
remapMember
@NotNull public @NotNull HierarchyAwareMappingDelegator<T> remapMember(@NotNull @NotNull MemberRef srcRef, @NotNull @NotNull String dstName) Description copied from interface:MappingSinkRemaps a class member - that is either a field or a method. Whether the member is a field or a method can be easily discerned by looking at the first character of thedescriptorof theMemberRef. If the first character is a '(', then it is a method - otherwise it is a field.As no non-method descriptor can start with '(', this check suffices and reduces the work required for bridging between stianloader-remapper and other mapping formats or software.
- Specified by:
remapMemberin interfaceMappingSink- Parameters:
srcRef- The reference of the member in the source namespace (i.e. the unmapped member)dstName- The name of the member in the target namespace (i.e. the mapped member name)- Returns:
- The current
MappingSinkinstance, for chaining
-
remapParameter
@NotNull public @NotNull MappingSink remapParameter(@NotNull @NotNull String srcOwner, @NotNull @NotNull String srcMethodName, @NotNull @NotNull String srcDesc, int paramIndex, @NotNull @NotNull String destParamName) Description copied from interface:MappingSinkRemaps a method parameter.The
paramIndexargument is 0-indexed. It does not distinguish between computational categories. Or in other words, for both(IZ)Vand(JZ)Vthe boolean parameter corresponds to aparamIndexvalue of 1, while the integer and long have a value of 0.Callers may throw an
IndexOutOfBoundsExceptionifparamIndexis below 0 or above the amount of parameters as discernible bysrcDesc. As such, this method cannot be used to remap LVT entries, even though they are quite similar in structure. This is because LVT entries can be reused. By default this method does not do any checks whetherparamIndexis a valid value. This is done for performance reasons.If this
MappingSinkinstance does not support remapping method parameters then anUnsupportedOperationExceptionshould be thrown. In cases where libraries are used that link against an older version of stianloader-remapper (namely 0.1.X and earlier), anAbstractMethodErrormay be thrown when attempting to call this method.- Specified by:
remapParameterin interfaceMappingSink- Parameters:
srcOwner- The name of the owner of the method in the source namespace.srcMethodName- The name of the method in the source namespace.srcDesc- The descriptor of the method in the source namespace.paramIndex- The index of the parameter, excluding the impliedthisargument on non-static methods.destParamName- The name of the parameter in the destination namespace.- Returns:
- The current
MappingSinkinstance, for chaining.
-