Package dev.denwav.hypo.mappings
Class LorenzUtil
java.lang.Object
dev.denwav.hypo.mappings.LorenzUtil
General utility for interacting with the Lorenz API. This utility class helps with easing the interactions with
Optional
and it provides utilities to help with modifying MappingSet
models outside of what the
standard Lorenz API allows.-
Method Summary
Modifier and TypeMethodDescription(package private) static @NotNull MappingSetImpl
checkType(@NotNull MappingSet mappingSet)
Verify theMappingSet
is aMappingSetImpl
.(package private) static @NotNull AbstractClassMappingImpl<?,?>
checkType(@NotNull ClassMapping<?,?> mapping)
Verify theClassMapping
is anAbstractClassMappingImpl
.(package private) static @NotNull MethodMappingImpl
checkType(@NotNull MethodMapping mapping)
Verify theMethodMapping
is anMethodMappingImpl
.static @NotNull MethodDescriptor
convertDesc(MethodDescriptor desc)
Convert a BombeMethodDescriptor
into a HypoMethodDescriptor
.convertType(Type type)
findField(@NotNull ClassData classData, @NotNull FieldMapping mapping)
Find the set ofFieldData
the obfuscated name of the givenFieldMapping
refers to in the givenClassData
object.static @Nullable MethodData
findMethod(@NotNull ClassData classData, @NotNull MethodMapping mapping)
FindMethodData
the obfuscated name of the givenMethodMapping
refers to in the givenClassData
object.static @Nullable ClassMapping<?,?>
getClassMapping(@NotNull MappingSet mappings, @NotNull String obfuscatedName)
static @Nullable FieldMapping
getFieldMapping(@NotNull ClassMapping<?,?> mapping, @NotNull String name)
static @Nullable FieldMapping
getFieldMapping(@NotNull ClassMapping<?,?> mapping, @NotNull FieldSignature sig)
static @NotNull Map<String,FieldMapping>
getFieldsByNameMap(@NotNull ClassMapping<?,?> mapping)
Get the internal map which stores field mappings by name from the givenClassMapping
.static @NotNull Map<FieldSignature,FieldMapping>
getFieldsMap(@NotNull ClassMapping<?,?> mapping)
Get the internal map which stores field mappings by signature from the givenClassMapping
.static @NotNull Map<String,InnerClassMapping>
getInnerClassesMap(@NotNull ClassMapping<?,?> mapping)
Get the internal map which stores inner class mappings from the givenClassMapping
.static @Nullable MethodMapping
getMethodMapping(@NotNull ClassMapping<?,?> mapping, @NotNull String name, @NotNull String desc)
static @NotNull Map<MethodSignature,MethodMapping>
getMethodsMap(@NotNull ClassMapping<?,?> mapping)
Get the internal map which stores method mappings from the givenClassMapping
.static @Nullable MethodParameterMapping
getParameterMapping(@NotNull MethodMapping mapping, int index)
static @NotNull Map<Integer,MethodParameterMapping>
getParamsMap(@NotNull MethodMapping mapping)
Get the internal map which stores parameter mappings from the givenMethodMapping
.static @NotNull Map<String,TopLevelClassMapping>
getTopLevelClassesMap(@NotNull MappingSet mappingSet)
Get the internal map which stores top level class mappings from the givenMappingSet
.getType(@NotNull FieldMapping mapping)
TheNullable
form ofFieldMapping.getType()
.(package private) static <T> T
Verifyt
is not null, throwing aNullPointerException
specifying the field which is null using the givenfieldName
.static void
removeClassMapping(@NotNull ClassMapping<?,?> mapping)
Remove the givenClassMapping
from its parent.static void
removeFieldMapping(@NotNull FieldMapping mapping)
Remove the givenFieldMapping
from its parent.static void
removeFieldMapping(@NotNull FieldMapping fieldMapping, @NotNull ClassMapping<?,?> mapping)
Remove the givenFieldMapping
from the givenClassMapping
.static void
removeInnerClassMapping(@NotNull ClassMapping<?,?> innerClassMapping, @NotNull ClassMapping<?,?> mapping)
Remove the givenInnerClassMapping
from the givenClassMapping
.static void
removeMethodMapping(@NotNull MethodMapping mapping)
Remove the givenMethodMapping
from its parent.static void
removeMethodMapping(@NotNull MethodMapping methodMapping, @NotNull ClassMapping<?,?> mapping)
Remove the givenMethodMapping
from the givenClassMapping
.static void
removeParamMapping(@NotNull MethodParameterMapping mapping)
Remove the givenMethodParameterMapping
from its parent.static void
removeParamMapping(@NotNull MethodParameterMapping paramMappings, @NotNull MethodMapping mapping)
Remove the givenMethodParameterMapping
from the givenMethodMapping
.static void
removeTopLevelClassMapping(@NotNull ClassMapping<?,?> topLevelClassMapping, @NotNull MappingSet mappingSet)
Remove the givenTopLevelClassMapping
from the givenMappingSet
.static <T> T
-
Method Details
-
unwrap
Return aNullable
version of what the givenOptional
contains. This is just a cleaner way of callingorElse(null)
.- Type Parameters:
T
- The type of the optional.- Parameters:
opt
- The optional to unwrap.- Returns:
- The value the optional contains, or
null
if it isempty
.
-
findMethod
@Contract(pure=true) @Nullable public static @Nullable MethodData findMethod(@NotNull @NotNull ClassData classData, @NotNull @NotNull MethodMapping mapping)FindMethodData
the obfuscated name of the givenMethodMapping
refers to in the givenClassData
object.- Parameters:
classData
- The class data to find the method in.mapping
- The mapping to determine the reference from.- Returns:
- The
MethodData
ornull
if not found.
-
findField
@Contract(pure=true) @NotNull public static @NotNull Set<@NotNull FieldData> findField(@NotNull @NotNull ClassData classData, @NotNull @NotNull FieldMapping mapping)Find the set ofFieldData
the obfuscated name of the givenFieldMapping
refers to in the givenClassData
object.- Parameters:
classData
- The class data to find the method in.mapping
- The mapping to determine the reference from.- Returns:
- The set of
FieldData
.
-
convertDesc
Convert a BombeMethodDescriptor
into a HypoMethodDescriptor
.- Parameters:
desc
- The Bombe descriptor to convert.- Returns:
- The same descriptor, but in the Hypo model.
-
convertType
- Parameters:
type
- The Bombe type to convert.- Returns:
- The same type, but in the Hypo model.
-
getClassMapping
@Nullable public static @Nullable ClassMapping<?,?> getClassMapping(@NotNull @NotNull MappingSet mappings, @NotNull @NotNull String obfuscatedName)- Parameters:
mappings
- The mapping set to call.obfuscatedName
- The class name to search for.- Returns:
- The
ClassMapping
, ornull
if not found. - See Also:
unwrap(Optional)
-
getMethodMapping
@Nullable public static @Nullable MethodMapping getMethodMapping(@NotNull @NotNull ClassMapping<?,?> mapping, @NotNull @NotNull String name, @NotNull @NotNull String desc)- Parameters:
mapping
- The class mapping to call.name
- The method name to search for.desc
- The method descriptor to search for.- Returns:
- The
MethodMapping
, ornull
if not found. - See Also:
unwrap(Optional)
-
getFieldMapping
@Nullable public static @Nullable FieldMapping getFieldMapping(@NotNull @NotNull ClassMapping<?,?> mapping, @NotNull @NotNull String name)- Parameters:
mapping
- The class mapping to call.name
- The field name to search for.- Returns:
- The
FieldMapping
ornull
if not found. - See Also:
unwrap(Optional)
-
getFieldMapping
@Nullable public static @Nullable FieldMapping getFieldMapping(@NotNull @NotNull ClassMapping<?,?> mapping, @NotNull @NotNull FieldSignature sig)- Parameters:
mapping
- The class mapping to call.sig
- TheFieldSignature
to search for.- Returns:
- The
FieldMapping
ornull
if not found. - See Also:
unwrap(Optional)
-
getParameterMapping
@Nullable public static @Nullable MethodParameterMapping getParameterMapping(@NotNull @NotNull MethodMapping mapping, int index)- Parameters:
mapping
- The method mapping to call.index
- The parameter index to search for.- Returns:
- The
MethodParameterMapping
, ornull
if not found. - See Also:
unwrap(Optional)
-
getType
TheNullable
form ofFieldMapping.getType()
.- Parameters:
mapping
- The field mapping to call.- Returns:
- The
FieldType
ornull
if not found. - See Also:
unwrap(Optional)
-
removeClassMapping
Remove the givenClassMapping
from its parent.- Parameters:
mapping
- The class mapping to remove.
-
removeMethodMapping
Remove the givenMethodMapping
from its parent.- Parameters:
mapping
- The method mapping to remove.
-
removeFieldMapping
Remove the givenFieldMapping
from its parent.- Parameters:
mapping
- The field mapping to remove.
-
removeParamMapping
Remove the givenMethodParameterMapping
from its parent.- Parameters:
mapping
- The method parameter mapping to remove.
-
removeTopLevelClassMapping
public static void removeTopLevelClassMapping(@NotNull @NotNull ClassMapping<?,?> topLevelClassMapping, @NotNull @NotNull MappingSet mappingSet)Remove the givenTopLevelClassMapping
from the givenMappingSet
.This method does nothing if
topLevelClassMapping
is not aTopLevelClassMapping
.- Parameters:
topLevelClassMapping
- The class mapping to remove.mappingSet
- The mapping set to remove the class from.
-
removeInnerClassMapping
public static void removeInnerClassMapping(@NotNull @NotNull ClassMapping<?,?> innerClassMapping, @NotNull @NotNull ClassMapping<?,?> mapping)Remove the givenInnerClassMapping
from the givenClassMapping
.This method does nothing if
innerClassMapping
is not aInnerClassMapping
.- Parameters:
innerClassMapping
- The class mapping to remove.mapping
- The class mapping to remove the class from.
-
removeFieldMapping
public static void removeFieldMapping(@NotNull @NotNull FieldMapping fieldMapping, @NotNull @NotNull ClassMapping<?,?> mapping)Remove the givenFieldMapping
from the givenClassMapping
.- Parameters:
fieldMapping
- The field mapping to remove.mapping
- The class mapping to remove the field from.
-
removeMethodMapping
public static void removeMethodMapping(@NotNull @NotNull MethodMapping methodMapping, @NotNull @NotNull ClassMapping<?,?> mapping)Remove the givenMethodMapping
from the givenClassMapping
.- Parameters:
methodMapping
- The method mapping to remove.mapping
- The class mapping to remove the method from.
-
removeParamMapping
public static void removeParamMapping(@NotNull @NotNull MethodParameterMapping paramMappings, @NotNull @NotNull MethodMapping mapping)Remove the givenMethodParameterMapping
from the givenMethodMapping
.- Parameters:
paramMappings
- The method parameter mapping to remove.mapping
- The method mapping to remove the parameter from.
-
getTopLevelClassesMap
@Contract(pure=true) @NotNull public static @NotNull Map<String,TopLevelClassMapping> getTopLevelClassesMap(@NotNull @NotNull MappingSet mappingSet)Get the internal map which stores top level class mappings from the givenMappingSet
.- Parameters:
mappingSet
- The mapping set to retrieve the map from.- Returns:
- The internal map of top level class mappings.
-
getInnerClassesMap
@Contract(pure=true) @NotNull public static @NotNull Map<String,InnerClassMapping> getInnerClassesMap(@NotNull @NotNull ClassMapping<?,?> mapping)Get the internal map which stores inner class mappings from the givenClassMapping
.- Parameters:
mapping
- The class mapping to retrieve the map from.- Returns:
- The internal map of inner class mappings.
-
getFieldsMap
@Contract(pure=true) @NotNull public static @NotNull Map<FieldSignature,FieldMapping> getFieldsMap(@NotNull @NotNull ClassMapping<?,?> mapping)Get the internal map which stores field mappings by signature from the givenClassMapping
.- Parameters:
mapping
- The class mapping to retrieve the map from.- Returns:
- The internal map of field mappings by signature.
-
getFieldsByNameMap
@Contract(pure=true) @NotNull public static @NotNull Map<String,FieldMapping> getFieldsByNameMap(@NotNull @NotNull ClassMapping<?,?> mapping)Get the internal map which stores field mappings by name from the givenClassMapping
.- Parameters:
mapping
- The class mapping to retrieve the map from.- Returns:
- The internal map of field mappings by name.
-
getMethodsMap
@Contract(pure=true) @NotNull public static @NotNull Map<MethodSignature,MethodMapping> getMethodsMap(@NotNull @NotNull ClassMapping<?,?> mapping)Get the internal map which stores method mappings from the givenClassMapping
.- Parameters:
mapping
- The class mapping to retrieve the map from.- Returns:
- The internal map of method mappings.
-
getParamsMap
@Contract(pure=true) @NotNull public static @NotNull Map<Integer,MethodParameterMapping> getParamsMap(@NotNull @NotNull MethodMapping mapping)Get the internal map which stores parameter mappings from the givenMethodMapping
.- Parameters:
mapping
- The method mapping to retrieve the map from.- Returns:
- The internal map of parameter mappings.
-
checkType
@Contract(value="_ -> param1", pure=true) @NotNull static @NotNull MappingSetImpl checkType(@NotNull @NotNull MappingSet mappingSet)Verify theMappingSet
is aMappingSetImpl
.- Parameters:
mappingSet
- TheMappingSet
to verify.- Returns:
- The same mapping set, cast to
MappingSetImpl
.
-
checkType
@Contract(value="_ -> param1", pure=true) @NotNull static @NotNull AbstractClassMappingImpl<?,?> checkType(@NotNull @NotNull ClassMapping<?,?> mapping)Verify theClassMapping
is anAbstractClassMappingImpl
.- Parameters:
mapping
- TheClassMapping
to verify.- Returns:
- The same mapping, cast to
AbstractClassMappingImpl
.
-
checkType
@Contract(value="_ -> param1", pure=true) @NotNull static @NotNull MethodMappingImpl checkType(@NotNull @NotNull MethodMapping mapping)Verify theMethodMapping
is anMethodMappingImpl
.- Parameters:
mapping
- TheMethodMapping
to verify.- Returns:
- The same mapping, cast to
MethodMappingImpl
.
-
notNull
@Contract(value="null, _ -> fail; !null, _ -> param1", pure=true) @NotNull static <T> T notNull(@Nullable T t, String fieldName)Verifyt
is not null, throwing aNullPointerException
specifying the field which is null using the givenfieldName
.- Type Parameters:
T
- The type of the field.- Parameters:
t
- The value to verify is not null.fieldName
- The name of the field the value came from.- Returns:
- The given value as non-null.
-