Package jminusminus
Class Type
java.lang.Object
jminusminus.Type
- Direct Known Subclasses:
ArrayTypeName
,TypeName
A class for representing j-- types. All types are represented underneath (in the classRep
field) by Java objects of type Class. These objects represent types in Java, so this should
ease our interfacing with existing Java classes.
Class types (reference types that are represented by the identifiers introduced in class declarations) are represented using TypeName. So for now, every TypeName represents a class. In the future, TypeName could be extended to represent interfaces or enumerations.
IdentifierTypes must be "resolved" at some point, so that all Types having the same name refer to the same Type object. The resolve() method does this.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Type
The "any" type (denotes wild expressions).static final Type
The boolean type.static final Type
The java.lang.Boolean type.static final Type
The java.lang.Character type.static final Type
The java.lang.Double type.static final Type
The java.lang.Integer type.static final Type
The java.lang.Long type.static final Type
The char type.static final Type
A type marker indicating a constructor (having no return type).static final Type
The double type.static final Type
The int type.static final Type
The long type.static final Type
The null type.static final Type
The java.lang.Object type.static final Type
The java.lang.String type.static final Type
The void type. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a list of this class' abstract methods.static String
argTypesAsString
(Type[] argTypes) Returns a string representation of an array of argument types.static boolean
argTypesMatch
(Class<?>[] argTypes1, Class<?>[] argTypes2) Returns true if the argument types match, and false otherwise.Returns a string representation for a type being appended to a StringBuffer (for the + and += operations over strings).static boolean
checkAccess
(int line, Class referencingType, Class type) Returns true if the referenced type is accessible from the referencing type, and false otherwise.boolean
checkAccess
(int line, Member member) Returns true if the member is accessible from this type, and false otherwise.boolean
checkAccess
(int line, Type targetType) Returns true if the target type is accessible from this type, and false otherwise.Class<?>
classRep()
Returns the class representation for this type.Returns an array type's component type.constructorFor
(Type[] argTypes) Finds and returns a constructor in this type having the given argument types, or null.boolean
Returns true if this type has the same descriptor as other, and false otherwise.Finds and returns a field in this type having the given name, or null.boolean
Returns true of this type is declared abstract, and false otherwise.boolean
isArray()
Returns true if this is an array type, and false otherwise.boolean
isFinal()
Returns true of this type is declared final, and false otherwise.boolean
Returns true if this is an interface type, and false otherwise.boolean
isJavaAssignableFrom
(Type that) Returns true if this is a supertype of other, and false otherwise.boolean
Returns true if this is a primitive type, and false otherwise.boolean
Returns true if this is a reference type, and false otherwise.jvmName()
Returns the JVM representation of this type's name.boolean
matchesExpected
(Type expected) Returns true if this type matches expected, and false otherwise.Finds and returns a method in this type having the given name and argument types, or null.void
mustMatchExpected
(int line, Type expectedType) An assertion that this type matches the specified type.void
mustMatchOneOf
(int line, Type... expectedTypes) An assertion that this type matches one of the specified types.Returns this type's package name.Resolves this type in the given context and returns the resolved type.void
setClassRep
(Class<?> classRep) Sets the class representation of this type to the specified partial class.static String
signatureFor
(String name, Type[] argTypes) Returns a signature for reporting unfound methods and constructors.Returns the simple (unqualified) name of this type.Returns this type's super type, or null.Returns the JVM descriptor of this type.toString()
Returns a string representation of this type.static Type
Constructs and returns a representation for a type from its (Java) class representation, making sure there is a unique representation for each unique type.
-
Field Details
-
INT
The int type. -
CHAR
The char type. -
BOOLEAN
The boolean type. -
LONG
The long type. -
DOUBLE
The double type. -
BOXED_INT
The java.lang.Integer type. -
BOXED_CHAR
The java.lang.Character type. -
BOXED_BOOLEAN
The java.lang.Boolean type. -
BOXED_LONG
The java.lang.Long type. -
BOXED_DOUBLE
The java.lang.Double type. -
STRING
The java.lang.String type. -
OBJECT
The java.lang.Object type. -
VOID
The void type. -
NULLTYPE
The null type. -
ANY
The "any" type (denotes wild expressions). -
CONSTRUCTOR
A type marker indicating a constructor (having no return type).
-
-
Constructor Details
-
Type
protected Type()This constructor is to keep the compiler happy.
-
-
Method Details
-
typeFor
Constructs and returns a representation for a type from its (Java) class representation, making sure there is a unique representation for each unique type.- Parameters:
classRep
- the Java class representation.- Returns:
- a type representation of classRep.
-
classRep
Returns the class representation for this type.- Returns:
- the class representation for this type.
-
setClassRep
Sets the class representation of this type to the specified partial class.- Parameters:
classRep
- the partial class.
-
equals
Returns true if this type has the same descriptor as other, and false otherwise.- Parameters:
other
- the other type.- Returns:
- true if this type has the same descriptor as other, and false otherwise.
-
isArray
public boolean isArray()Returns true if this is an array type, and false otherwise.- Returns:
- true if this is an array type, and false otherwise.
-
componentType
Returns an array type's component type.- Returns:
- an array type's component type.
-
superClass
Returns this type's super type, or null.- Returns:
- this type's super type, or null.
-
isPrimitive
public boolean isPrimitive()Returns true if this is a primitive type, and false otherwise.- Returns:
- true if this is a primitive type, and false otherwise.
-
isInterface
public boolean isInterface()Returns true if this is an interface type, and false otherwise.- Returns:
- true if this is an interface type, and false otherwise.
-
isReference
public boolean isReference()Returns true if this is a reference type, and false otherwise.- Returns:
- true if this is a reference type, and false otherwise.
-
isFinal
public boolean isFinal()Returns true of this type is declared final, and false otherwise.- Returns:
- true of this type is declared final, and false otherwise.
-
isAbstract
public boolean isAbstract()Returns true of this type is declared abstract, and false otherwise.- Returns:
- true of this type is declared abstract, and false otherwise.
-
isJavaAssignableFrom
Returns true if this is a supertype of other, and false otherwise.- Parameters:
that
- the candidate subtype.- Returns:
- true if this is a supertype of other, and false otherwise.
-
abstractMethods
Returns a list of this class' abstract methods.It has abstract methods if:
- Any method declared in the class is abstract or
- its superclass has an abstract method which is not overridden here.
- Returns:
- a list of this class' abstract methods.
-
mustMatchOneOf
An assertion that this type matches one of the specified types. If there is no match, an error is reported.- Parameters:
line
- the line near which the mismatch occurs.expectedTypes
- expected types.
-
mustMatchExpected
An assertion that this type matches the specified type. If there is no match, an error is reported.- Parameters:
line
- the line near which the mismatch occurs.expectedType
- type with which to match.
-
matchesExpected
Returns true if this type matches expected, and false otherwise.- Parameters:
expected
- the type that this might match.- Returns:
- true if this type matches expected, and false otherwise.
-
argTypesMatch
Returns true if the argument types match, and false otherwise.- Parameters:
argTypes1
- arguments (classReps) of one method.argTypes2
- arguments (classReps) of another method.- Returns:
- true if the argument types match, and false otherwise.
-
simpleName
Returns the simple (unqualified) name of this type.- Returns:
- the simple (unqualified) name of this type.
-
toString
Returns a string representation of this type. -
toDescriptor
Returns the JVM descriptor of this type.- Returns:
- the JVM descriptor of this type.
-
jvmName
Returns the JVM representation of this type's name.- Returns:
- the JVM representation of this type's name.
-
packageName
Returns this type's package name.- Returns:
- this type's package name.
-
argumentTypeForAppend
Returns a string representation for a type being appended to a StringBuffer (for the + and += operations over strings).- Returns:
- a string representation for a type being appended to a StringBuffer.
-
methodFor
Finds and returns a method in this type having the given name and argument types, or null.- Parameters:
name
- the method name.argTypes
- the argument types.- Returns:
- a method in this type having the given name and argument types, or null.
-
constructorFor
Finds and returns a constructor in this type having the given argument types, or null.- Parameters:
argTypes
- the argument types.- Returns:
- a constructor in this type having the given argument types, or null.
-
fieldFor
Finds and returns a field in this type having the given name, or null.- Parameters:
name
- the name of the field we want.- Returns:
- a field in this type having the given name, or null.
-
argTypesAsString
Returns a string representation of an array of argument types.- Parameters:
argTypes
- the array of argument types.- Returns:
- a string representation of an array of argument types.
-
checkAccess
Returns true if the member is accessible from this type, and false otherwise.- Parameters:
line
- the line in which the access occurs.member
- the member being accessed.- Returns:
- true if the member is accessible from this type, and false otherwise.
-
checkAccess
Returns true if the target type is accessible from this type, and false otherwise.- Parameters:
line
- line in which the access occurs.targetType
- the type being accessed.- Returns:
- true if the target type is accessible from this type, and false otherwise.
-
checkAccess
Returns true if the referenced type is accessible from the referencing type, and false otherwise.- Parameters:
line
- the line in which the access occurs.referencingType
- the type attempting the access.type
- the type that we want to access.- Returns:
- true if the referenced type is accessible from the referencing type, and false otherwise.
-
resolve
Resolves this type in the given context and returns the resolved type.- Parameters:
context
- context in which the names are resolved.- Returns:
- the resolved type.
-
signatureFor
Returns a signature for reporting unfound methods and constructors.- Parameters:
name
- the message or type name.argTypes
- the actual argument types.- Returns:
- a signature for reporting unfound methods and constructors.
-