Package proguard.classfile
Class MethodSignature
- java.lang.Object
-
- proguard.classfile.Signature
-
- proguard.classfile.MethodSignature
-
- All Implemented Interfaces:
java.lang.Comparable<Signature>
,MethodInfo
public class MethodSignature extends Signature implements MethodInfo
Represents a Method signature containing a class, method and a descriptor.In order to avoid a huge blow-up in memory consumption for analyses that rely heavily on method signatures, e.g. the creation of a call graph, this class provides the ability to cache signatures belonging to concrete
Method
objects. By using the correspondingcomputeIfAbsent(Clazz, Method)
method, the amount of strings that need to be retained during runtime is reduced.
-
-
Field Summary
Fields Modifier and Type Field Description @Nullable MethodDescriptor
descriptor
@Nullable java.lang.String
method
static MethodSignature
UNKNOWN
-
Constructor Summary
Constructors Constructor Description MethodSignature(@NotNull Clazz clazz)
MethodSignature(@NotNull Clazz clazz, @NotNull Method method)
MethodSignature(@Nullable java.lang.String className)
MethodSignature(@Nullable java.lang.String internalClassName, @Nullable java.lang.String method, @Nullable java.lang.String descriptor)
MethodSignature(@Nullable java.lang.String internalClassName, @Nullable java.lang.String method, @Nullable MethodDescriptor descriptor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
calculateFqn()
protected java.lang.String
calculatePrettyFqn()
static void
clearCache()
Remove all currently cachedMethodSignature
objects from the cache, allowing them to be removed by the garbage collector.static MethodSignature
computeIfAbsent(Clazz clazz, Method method)
Get the singletonMethodSignature
object for this specificMethod
.boolean
equals(java.lang.Object o)
@Nullable MethodDescriptor
getDescriptor()
Returns the method's descriptor.@Nullable java.lang.String
getMethodName()
Returns the method's name.Method
getReferencedMethod()
Returns theMethod
reference that corresponds to the method represented by thisMethodSignature
ornull
if no reference is available (e.g.boolean
isIncomplete()
Check if this signature is missing information.static boolean
matchesIgnoreNull(MethodSignature signature, MethodSignature wildcard)
Fuzzy check if twoMethodSignature
objects are equal.static boolean
matchesIgnoreNullAndDollar(MethodSignature signature, MethodSignature wildcard)
Fuzzy check like {@link .matchesIgnoreNull(MethodSignature)} but allows dollar signs in type strings.-
Methods inherited from class proguard.classfile.Signature
compareTo, computeIfAbsent, getClassName, getExternalPackageName, getFqn, getPackageName, getPrettyFqn, getReferencedClass, hashCode, of, setCacheEnabled, toString
-
-
-
-
Field Detail
-
UNKNOWN
public static final MethodSignature UNKNOWN
-
method
@Nullable public final @Nullable java.lang.String method
-
descriptor
@Nullable public final @Nullable MethodDescriptor descriptor
-
-
Constructor Detail
-
MethodSignature
public MethodSignature(@Nullable @Nullable java.lang.String internalClassName, @Nullable @Nullable java.lang.String method, @Nullable @Nullable MethodDescriptor descriptor)
-
MethodSignature
public MethodSignature(@Nullable @Nullable java.lang.String internalClassName, @Nullable @Nullable java.lang.String method, @Nullable @Nullable java.lang.String descriptor)
-
MethodSignature
public MethodSignature(@NotNull @NotNull Clazz clazz, @NotNull @NotNull Method method)
-
MethodSignature
public MethodSignature(@NotNull @NotNull Clazz clazz)
-
MethodSignature
public MethodSignature(@Nullable @Nullable java.lang.String className)
-
-
Method Detail
-
getReferencedMethod
public Method getReferencedMethod()
Returns theMethod
reference that corresponds to the method represented by thisMethodSignature
ornull
if no reference is available (e.g. the methhod or its class were missing).
-
computeIfAbsent
public static MethodSignature computeIfAbsent(Clazz clazz, Method method)
Get the singletonMethodSignature
object for this specificMethod
. If it is not yet available in the cache, it will be newly instantiated.- Parameters:
clazz
- The class containing the target methodmethod
- The method whose signature is to be generated- Returns:
- The cached or newly generated
MethodSignature
object
-
isIncomplete
public boolean isIncomplete()
Description copied from class:Signature
Check if this signature is missing information.- Specified by:
isIncomplete
in classSignature
-
calculateFqn
protected java.lang.String calculateFqn()
- Specified by:
calculateFqn
in classSignature
-
calculatePrettyFqn
protected java.lang.String calculatePrettyFqn()
- Specified by:
calculatePrettyFqn
in classSignature
-
clearCache
public static void clearCache()
Remove all currently cachedMethodSignature
objects from the cache, allowing them to be removed by the garbage collector.
-
matchesIgnoreNull
public static boolean matchesIgnoreNull(MethodSignature signature, MethodSignature wildcard)
Fuzzy check if twoMethodSignature
objects are equal. If any pattern field is null, its value in the matched object does not influence the check result, providing a way to create a wildcardMethodSignature
that e.g. matches several methods of a class that have the same name but a differentMethodDescriptor
.- Parameters:
signature
- TheMethodSignature
to be comparedwildcard
- TheMethodSignature
pattern to be matched against- Returns:
- true if the two objects match
-
matchesIgnoreNullAndDollar
public static boolean matchesIgnoreNullAndDollar(MethodSignature signature, MethodSignature wildcard)
Fuzzy check like {@link .matchesIgnoreNull(MethodSignature)} but allows dollar signs in type strings. Usually the notation for inner classes iscom/example/Foo$Bar
, but sometimes external systems call this classcom/example/Foo/Bar
. These two names correspond to the same class and thus should be treated as the same if they appear in aMethodSignature
. If it is to be expected that this situation may occur, this method should be preferred over {@link .matchesIgnoreNull(MethodSignature)} to avoid false negatives.- Parameters:
signature
- TheMethodSignature
to be comparedwildcard
- TheMethodSignature
pattern to be matched against- Returns:
- true if the two objects match
-
getMethodName
@Nullable public @Nullable java.lang.String getMethodName()
Description copied from interface:MethodInfo
Returns the method's name.- Specified by:
getMethodName
in interfaceMethodInfo
-
getDescriptor
@Nullable public @Nullable MethodDescriptor getDescriptor()
Description copied from interface:MethodInfo
Returns the method's descriptor.- Specified by:
getDescriptor
in interfaceMethodInfo
-
-