public sealed interface ElementSignature
Signature of a
TypedElementInfo
.
The TypedElementInfoBlueprint.signature()
is intended to compare
fields, methods, and constructors across type hierarchy - for example when looking for a method
that we override.
The following information is used for equals and hash-code:
- Field: field name
- Constructor: parameter types
- Method: method name, parameter types
- Parameter: this signature is not useful, as we cannot depend on parameter names
hashCode
and equals
methods,
so it can be safely used as a key in a Map
.
This interface is sealed, an instance can only be obtained
from TypedElementInfoBlueprint.signature()
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ElementSignature
createConstructor
(List<TypeName> parameters) A constructor signature.static ElementSignature
createField
(TypeName type, String name) A field signature.static ElementSignature
createMethod
(TypeName returnType, String name, List<TypeName> parameters) A method signature.name()
Name of the element.Types of parameters if this represents a method or a constructor, emptyList
otherwise.text()
A text representation of this signature.type()
Type of the element.
-
Method Details
-
createField
A field signature.- Parameters:
type
- type of the fieldname
- name of the field- Returns:
- a new field signature
-
createConstructor
A constructor signature.- Parameters:
parameters
- list of types of parameters- Returns:
- a new constructor signature
-
createMethod
A method signature.- Parameters:
returnType
- return type of the methodname
- name of the methodparameters
- parameter types of the method- Returns:
- a new method signature
-
type
TypeName type()Type of the element. Resolves as follows:- Field: type of the field
- Constructor: void
- Method: method return type
- Parameter: parameter type
- Returns:
- type of this element, never used for equals or hashCode
-
name
String name()Name of the element. For constructor, this always returns<init>
, for parameters, this method may return the real parameter name or an index parameter name depending on the source of the information (during annotation processing, this would be the actual parameter name, when classpath scanning, this would be something likeparam0
.- Returns:
- name of this element
-
parameterTypes
Types of parameters if this represents a method or a constructor, emptyList
otherwise.- Returns:
- parameter types
-
text
String text()A text representation of this signature.- Field: field name (such as
myNiceField
- Constructor: comma separated parameter types (no generics) in parentheses (such as
(java.lang.String,java.util.List)
) - Method: method name, parameter types (no generics) in parentheses (such as
methodName(java.lang.String,java.util.List)
- Parameter: parameter name (such as
myParameter
orparam0
- not very useful, as parameter names are not carried over to compiled code in Java
- Returns:
- text representation
- Field: field name (such as
-