public class MethodSignature extends Signature implements MethodInfo
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 corresponding computeIfAbsent(Clazz, Method)
method, the amount of strings that need to be retained during
runtime is reduced.
Modifier and Type | Field and Description |
---|---|
@Nullable MethodDescriptor |
descriptor |
@Nullable java.lang.String |
method |
static MethodSignature |
UNKNOWN |
Constructor and 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 MethodDescriptor descriptor) |
MethodSignature(@Nullable java.lang.String internalClassName,
@Nullable java.lang.String method,
@Nullable java.lang.String descriptor) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
calculateFqn() |
protected java.lang.String |
calculatePrettyFqn() |
static void |
clearCache()
Remove all currently cached
MethodSignature objects from the cache, allowing them to be
removed by the garbage collector. |
static MethodSignature |
computeIfAbsent(Clazz clazz,
Method method)
Get the singleton
MethodSignature object for this specific Method . |
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 the
Method reference that corresponds to the method represented by this MethodSignature or null 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 two
MethodSignature objects are equal. |
static boolean |
matchesIgnoreNullAndDollar(MethodSignature signature,
MethodSignature wildcard)
Fuzzy check like
.matchesIgnoreNull(MethodSignature) but allows dollar signs in type
strings. |
compareTo, computeIfAbsent, getClassName, getExternalPackageName, getFqn, getPackageName, getPrettyFqn, getReferencedClass, hashCode, of, setCacheEnabled, toString
public static final MethodSignature UNKNOWN
@Nullable public final @Nullable java.lang.String method
@Nullable public final @Nullable MethodDescriptor descriptor
public MethodSignature(@Nullable @Nullable java.lang.String internalClassName, @Nullable @Nullable java.lang.String method, @Nullable @Nullable MethodDescriptor descriptor)
public MethodSignature(@Nullable @Nullable java.lang.String internalClassName, @Nullable @Nullable java.lang.String method, @Nullable @Nullable java.lang.String descriptor)
public MethodSignature(@NotNull @NotNull Clazz clazz, @NotNull @NotNull Method method)
public MethodSignature(@NotNull @NotNull Clazz clazz)
public MethodSignature(@Nullable @Nullable java.lang.String className)
public Method getReferencedMethod()
Method
reference that corresponds to the method represented by this MethodSignature
or null
if no reference is available (e.g. the methhod or its
class were missing).public static MethodSignature computeIfAbsent(Clazz clazz, Method method)
MethodSignature
object for this specific Method
. If it is not
yet available in the cache, it will be newly instantiated.clazz
- The class containing the target methodmethod
- The method whose signature is to be generatedMethodSignature
objectpublic boolean isIncomplete()
Signature
isIncomplete
in class Signature
protected java.lang.String calculateFqn()
calculateFqn
in class Signature
protected java.lang.String calculatePrettyFqn()
calculatePrettyFqn
in class Signature
public static void clearCache()
MethodSignature
objects from the cache, allowing them to be
removed by the garbage collector.public static boolean matchesIgnoreNull(MethodSignature signature, MethodSignature wildcard)
MethodSignature
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
wildcard MethodSignature
that e.g. matches several methods of a class that have the
same name but a different MethodDescriptor
.signature
- The MethodSignature
to be comparedwildcard
- The MethodSignature
pattern to be matched againstpublic static boolean matchesIgnoreNullAndDollar(MethodSignature signature, MethodSignature wildcard)
.matchesIgnoreNull(MethodSignature)
but allows dollar signs in type
strings. Usually the notation for inner classes is com/example/Foo$Bar
, but sometimes
external systems call this class com/example/Foo/Bar
. These two names correspond to the
same class and thus should be treated as the same if they appear in a MethodSignature
.
If it is to be expected that this situation may occur, this method should be preferred over
.matchesIgnoreNull(MethodSignature)
to avoid false negatives.signature
- The MethodSignature
to be comparedwildcard
- The MethodSignature
pattern to be matched against@Nullable public @Nullable java.lang.String getMethodName()
MethodInfo
getMethodName
in interface MethodInfo
@Nullable public @Nullable MethodDescriptor getDescriptor()
MethodInfo
getDescriptor
in interface MethodInfo