Interface IJavaType
Those objects can represent exact types or wildcard (imprecise) types. They are used at both the IR and at the AST level.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSignature ofjava.lang.Class.static final StringSignature ofjava.lang.Enum.static final StringSignature ofjava.lang.Exception.static final StringSignature ofjava.lang.invoke.CallSite.static final StringSignature ofjava.lang.invoke.MethodHandle.static final StringSignature ofjava.lang.invoke.MethodType.static final StringSignature ofjava.lang.Object.static final StringSignature ofjava.lang.String.static final StringSignature ofjava.lang.Throwable. -
Method Summary
Modifier and TypeMethodDescriptionRetrieve an "extends" wildcard version of this type.Retrieve a "super" wildcard version of this type.booleancanSetType(IJavaType otherType, boolean useExternalTypeInfo) Determine whether this type could be replaced by (as in, specialized) the provided other type.Compare this type with another one and return the most precise type if it can be determined.booleanSimple comparison: are both types objects (incl.voidformat(DFormattingContext fctx) Get a programmer's representation for that type.voidformatArray(DFormattingContext fctx, IDExpression dim0) Format this type as an array type, optionally with the first-dimension expression.Get the simplest type of an array type, that is, the type of a 0-dimension array.
Example: [[[I -> IGet the type of an imaginary array with one dimension less than the current array.
Example: [[[I -> [[IintGet the dimension count of an array type.intgetName()Get the internal representation.Get the Java type name (original internal form).getSignature(boolean doNotRenderWildcard) Get the Java type name (original internal form).intThis method will throw if called on thevoidtype!booleanisArray()booleanbooleanisByte()booleanisChar()booleanbooleanbooleanbooleanisDouble()booleanbooleanWildcard type for any type whose concrete representation requires two slots.booleanisFloat()booleanbooleanisSpecificInteger()+ BOOLEAN and the generic type SMALLINT.booleanWildcard type for any object.booleanisInt()booleanConvenience method.booleanConvenience method.booleanConvenience method.booleanisLegal()booleanisLong()booleanisObject()booleanbooleanbooleanbooleanbooleanisShort()booleanbooleanWildcard type for any type whose concrete representation requires one slot.booleanbooleanWildcard type for any small integer type (byte, char, short, int).booleanbooleanbooleanDetermine whether this type can be rendered as Java source.booleanisVoid()boolean
-
Field Details
-
JAVA_LANG_OBJECT
Signature ofjava.lang.Object.- See Also:
-
JAVA_LANG_STRING
Signature ofjava.lang.String.- See Also:
-
JAVA_LANG_CLASS
Signature ofjava.lang.Class.- See Also:
-
JAVA_LANG_ENUM
Signature ofjava.lang.Enum.- See Also:
-
JAVA_LANG_EXCEPTION
Signature ofjava.lang.Exception.- See Also:
-
JAVA_LANG_THROWABLE
Signature ofjava.lang.Throwable.- See Also:
-
JAVA_LANG_INVOKE_METHODTYPE
Signature ofjava.lang.invoke.MethodType.- See Also:
-
JAVA_LANG_INVOKE_METHODHANDLE
Signature ofjava.lang.invoke.MethodHandle.- See Also:
-
JAVA_LANG_INVOKE_CALLSITE
Signature ofjava.lang.invoke.CallSite.- See Also:
-
-
Method Details
-
getFactory
IJavaTypeFactory getFactory()- Returns:
- the type factory that created this type object
-
isVoid
boolean isVoid()- Returns:
- true if this "type" is
void(i.e. not a type, or the illegal type)
-
isPrimitive
boolean isPrimitive()- Returns:
- true if this type is a primitive
-
isBoolean
boolean isBoolean()- Returns:
- true if this type is the
booleanprimitive
-
isByte
boolean isByte()- Returns:
- true if this type is the
byteprimitive
-
isChar
boolean isChar()- Returns:
- true if this type is the
charprimitive
-
isShort
boolean isShort()- Returns:
- true if this type is the
shortprimitive
-
isInt
boolean isInt()- Returns:
- true if this type is the
intprimitive
-
isLong
boolean isLong()- Returns:
- true if this type is the
longprimitive
-
isFloat
boolean isFloat()- Returns:
- true if this type is the
floatprimitive
-
isDouble
boolean isDouble()- Returns:
- true if this type is the
doubleprimitive
-
isSingleSlotWildcard
boolean isSingleSlotWildcard()Wildcard type for any type whose concrete representation requires one slot.- Returns:
- true if this type is the single-slot wildcard
-
isDoubleSlotWildcard
boolean isDoubleSlotWildcard()Wildcard type for any type whose concrete representation requires two slots.- Returns:
- true if this type is the double-slot wildcard
-
isSmallIntegerWildcard
boolean isSmallIntegerWildcard()Wildcard type for any small integer type (byte, char, short, int).- Returns:
- true if this type is the small-integer wildcard
-
isGenericObjectWildcard
boolean isGenericObjectWildcard()Wildcard type for any object.- Returns:
- true if this type is the generic object wildcard
-
isObjectWildcard
boolean isObjectWildcard()- Returns:
- true if this type is a specialization or generalization wildcard
-
isObjectWildcardExtends
boolean isObjectWildcardExtends()- Returns:
- true if this type is a specialization wildcard:
? extends SomeType
-
isObjectWildcardSuper
boolean isObjectWildcardSuper()- Returns:
- true if this type is a generalization wildcard:
? super SomeType
-
isObject
boolean isObject()- Returns:
- true if this type is an object type: could be the generic-object wildcard, a specific class or interface type, an array type
-
isClassOrInterface
boolean isClassOrInterface()- Returns:
- true if this type is a class or interface type (not an array type, not a primitive)
-
isArray
boolean isArray()- Returns:
- true if this type is an array type
-
getDimensions
int getDimensions()Get the dimension count of an array type. This method will throw if this type is not an array.- Returns:
- the number of array dimensions
-
getArrayElementType
IJavaType getArrayElementType()Get the simplest type of an array type, that is, the type of a 0-dimension array.
Example: [[[I -> I- Returns:
- the base element type
-
getArrayTypeDimensionBelow
IJavaType getArrayTypeDimensionBelow()Get the type of an imaginary array with one dimension less than the current array.
Example: [[[I -> [[I- Returns:
- the array type one dimension below this type
-
getName
String getName()Get the internal representation. Never fail. If the type is a wildcard reference, the type reference without wildcard is returned (example: on type? extends T, this method will return "T").- Returns:
- internal representation of the type name
-
getSignature
String getSignature()Get the Java type name (original internal form).- Returns:
- internal type name, using the
L.../...;form
-
getSignature
Get the Java type name (original internal form).- Parameters:
doNotRenderWildcard- true to omit wildcard markers from the returned signature- Returns:
- internal type name, using the
L.../...;form
-
isJavaLangObject
boolean isJavaLangObject()Convenience method.- Returns:
- true if this type is
java.lang.Object.
-
isJavaLangClass
boolean isJavaLangClass()Convenience method.- Returns:
- true if this type is
java.lang.Class.
-
isJavaLangString
boolean isJavaLangString()Convenience method.- Returns:
- true if this type is
java.lang.String.
-
isFloatingPointType
boolean isFloatingPointType()- Returns:
- true if
floatordouble
-
getEncodingBitsize
int getEncodingBitsize()- Returns:
- the memory bitsize required to store such a type (or type-reference, for an object type), such as 1 for a boolean, 8 for a char, 16 for a short/char32 for an int/float/ref, 64 for a long/double, etc.
-
isSingleSlot
boolean isSingleSlot()- Returns:
- true if the concrete representation of this type is stored in a single slot
-
isDoubleSlot
boolean isDoubleSlot()- Returns:
- true if the concrete representation of this type is stored in a two slots
-
isLegal
boolean isLegal()- Returns:
- true if non-void
-
isUndefined
boolean isUndefined()- Returns:
- true if void, the single-slot, or the double-slot wildcard
-
isDefined
boolean isDefined()- Returns:
- true if anything but void or the single-slot or double-slot wildcard
-
isDetermined
boolean isDetermined()- Returns:
- true if anything but void or a wildcard type
-
isWildcard
boolean isWildcard()- Returns:
- true if small-int wildcard, single-slot wildcard, double-slot wildcard, generic-object wildcard
-
asWildcardSup
IJavaType asWildcardSup()Retrieve a "super" wildcard version of this type.Watch out! For super-wildcards, this method returns the same type. For extends-wildcards, this method does NOT return the generic object type. It returns the super-wildcard of the non-wildcard type.
- Returns:
- the super-wildcard version of this type
-
asWildcardExt
IJavaType asWildcardExt()Retrieve an "extends" wildcard version of this type.Watch out! For extends-wildcards, this method returns the same type. For super-wildcards, this method does NOT return the generic object type. It returns the extends-wildcard of the non-wildcard type.
- Returns:
- the extends-wildcard version of this type
-
getSlotCount
int getSlotCount()This method will throw if called on thevoidtype!- Returns:
- 1 or 2
-
isSmallInt
boolean isSmallInt()- Returns:
- true for
BYTE, CHAR, SHORT, INTorSMALLINT(wildcard type for any of the previous small-integer types)
-
isSpecificInteger
boolean isSpecificInteger()- Returns:
- true for byte, char, short, int or long (note: the small-int wildcard is NOT a specific integer)
-
isGenericInteger
boolean isGenericInteger()isSpecificInteger()+ BOOLEAN and the generic type SMALLINT.- Returns:
- true if this type is a generic integer type
-
compareSimple
Simple comparison: are both types objects (incl. arrays) or ints, etc.Note 1: comparing a String to an ArrayList or an array of int would return true.
Note 2: comparing an int to a smallint would return false.- Parameters:
t- type to compare with this one- Returns:
- true if both types have the same simple category
-
canSetType
Determine whether this type could be replaced by (as in, specialized) the provided other type. Unless the other type is the same as this type, this method will fail if this type is not a wildcard.For objects, do not confuse this method with type hierarchy checkers. Example: if this type is
List, this method will return false if the other type is e.g.ArrayList, becauseListis already a specific type. However, if this type were to be?_extends_List, the method would return true for any type extendingList, includingListitself orArrayList.- Parameters:
otherType- another typeuseExternalTypeInfo- true to use external hierarchy/type information when available- Returns:
- success indicator
-
compareAndGetMostPrecise
Compare this type with another one and return the most precise type if it can be determined.- Parameters:
other- type to compare with this one- Returns:
- the most precise type, or null if no precise type can be selected
-
isValidForRendering
boolean isValidForRendering()Determine whether this type can be rendered as Java source.- Returns:
- true if this type is valid for rendering
-
format
Get a programmer's representation for that type. Examples:
- top-level classLcom/foo/B$la;becomescom.foo.B$la
- inner classLcom/foo/Farm$Cow;becomescom.foo.Farm.Cow- Parameters:
fctx- sink and formatting context
-
formatArray
Format this type as an array type, optionally with the first-dimension expression.- Parameters:
fctx- sink and formatting contextdim0- first-dimension expression, or null
-