Package aQute.bnd.compatibility
Class Signatures
java.lang.Object
aQute.bnd.compatibility.Signatures
This class can convert a Class, Field, Method or constructor to a generic
signature and it can normalize a signature. Both are methods. Normalized
signatures can be string compared and match even if the type variable names
differ.
- Version:
- $Id: d9bcbd3da7e14f43f4fe3db7e1f6ef4c27ff122c $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Helper class to track an index in a string. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
Handles the assignment of type variables to index names so that we have a normalized name for each type var.private void
body
(StringBuilder sb, Map<String, String> map, Signatures.Rover rover) Because classes can be nested the body handles the part that can be nested, the reference handles the enclosing L ...private void
Classes, Methods, or Constructors can have a declaration that provides nested a scope for type variables.private void
declare
(StringBuilder sb, Map<String, String> map, Signatures.Rover rover) Handle the declaration part.getSignature
(Class<?> c) Calculate the generic signature of a Class.Calculate the generic signature of a Class,Method,Field, or Constructor.getSignature
(Constructor<?> c) Calculate the generic signature of a Constructor.Calculate the generic signature of a Field.Calculate the generic signature of a Method.private boolean
isInterface
(Type type) Verify that the type is an interface.Normalize a signature to make sure the name of the variables are always the same.private void
Creates the signature for a Parameterized Type.private char
Handle primitives, these need to be translated to a single char.private void
reference
(StringBuilder sb, Type t) This is the heart of the signature builder.private void
reference
(StringBuilder sb, Map<String, String> map, Signatures.Rover rover, boolean primitivesAllowed) The heart of the routine.
-
Constructor Details
-
Signatures
public Signatures()
-
-
Method Details
-
getSignature
Calculate the generic signature of a Class,Method,Field, or Constructor.- Throws:
Exception
-
getSignature
Calculate the generic signature of a Class. A Class consists of:class ::= declaration? reference reference*
- Throws:
Exception
-
getSignature
Calculate the generic signature of a Method. A Method consists of:method ::= declaration? '(' reference* ')' reference
- Throws:
Exception
-
getSignature
Calculate the generic signature of a Constructor. A Constructor consists of:constructor ::= declaration? '(' reference* ')V'
- Parameters:
c
-- Throws:
Exception
-
getSignature
Calculate the generic signature of a Field. A Field consists of:constructor ::= reference
- Throws:
Exception
-
declaration
Classes, Methods, or Constructors can have a declaration that provides nested a scope for type variables. A Method/Constructor inherits the type variables from its class and a class inherits its type variables from its outer class. The declaration consists of the following syntax:declarations ::= '<' declaration ( ',' declaration )* '>' declaration ::= identifier ':' declare declare ::= types | variable types ::= ( 'L' class ';' )? ( ':' 'L' interface ';' )* variable ::= 'T' id ';'
- Parameters:
sb
-gd
-- Throws:
Exception
-
isInterface
Verify that the type is an interface.- Parameters:
type
- the type to check.- Returns:
- true if this is a class that is an interface or a Parameterized Type that is an interface
- Throws:
Exception
-
reference
This is the heart of the signature builder. A reference is used in a lot of places. It referes to another type.reference ::= array | class | primitive | variable array ::= '[' reference class ::= 'L' body ( '.' body )* ';' body ::= id ( '<' ( wildcard | reference )* '>' )? variable ::= 'T' id ';' primitive ::= PRIMITIVE
- Parameters:
sb
-t
-- Throws:
Exception
-
parameterizedType
Creates the signature for a Parameterized Type. A Parameterized Type has a raw class and a set of type variables.- Parameters:
sb
-pt
-- Throws:
Exception
-
primitive
Handle primitives, these need to be translated to a single char.- Parameters:
type
- the primitive class- Returns:
- the single char associated with the primitive
-
normalize
Normalize a signature to make sure the name of the variables are always the same. We change the names of the type variables to _n, where n is an integer. n is incremented for every new name and already used names are replaced with the _n name.- Returns:
- a normalized signature
-
reference
private void reference(StringBuilder sb, Map<String, String> map, Signatures.Rover rover, boolean primitivesAllowed) The heart of the routine. Handle a reference to a type. Can be an array, a class, a type variable, or a primitive.- Parameters:
sb
-map
-rover
-primitivesAllowed
-
-
body
Because classes can be nested the body handles the part that can be nested, the reference handles the enclosing L ... ;- Parameters:
sb
-map
-rover
-
-
declare
Handle the declaration part.- Parameters:
sb
-map
-rover
-
-
assign
Handles the assignment of type variables to index names so that we have a normalized name for each type var.- Parameters:
map
- the map with variables.name
- The name of the variable- Returns:
- the index name, like _1
-