net.sf.rej.java
Class JavaType

java.lang.Object
  extended by net.sf.rej.java.JavaType
Direct Known Subclasses:
JavaType.ImmutableJavaType

public class JavaType
extends java.lang.Object

The JavaType class represents a java type that is either primitive (int, long, char, double, etc) or a class/interface type. In either case the type may possibly contain several dimensions.

Author:
Sami Koivu

Nested Class Summary
static class JavaType.ImmutableJavaType
           
 
Field Summary
static JavaType INT
          An immutable constant for the primitive type int (with no dimensions)
static JavaType JAVA_LANG_OBJECT
          An immutable constant for the type java.lang.Object (with no dimensions)
 
Constructor Summary
JavaType(java.lang.String def)
          Instantiates a new JavaType from the given definition String.
JavaType(java.lang.String typeName, int dimensions)
          Instantiates a new JavaType specifying explicitly the name and the number of dimensions.
 
Method Summary
 void dropDimension()
          Decreases the dimension count by one.
 boolean equals(java.lang.Object obj)
           
 int getDimensionCount()
          Returns the number of dimensions.
 java.lang.String getDimensions()
          Returns the dimension part of a type.
 java.lang.String getRaw()
          Returns a raw representation of this type, ie.
 java.lang.String getType()
          Returns the type of the instance.
 int hashCode()
           
 boolean isPrimitive()
          Returns true if the type denoted by this instance if a primitive type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INT

public static final JavaType INT
An immutable constant for the primitive type int (with no dimensions)


JAVA_LANG_OBJECT

public static final JavaType JAVA_LANG_OBJECT
An immutable constant for the type java.lang.Object (with no dimensions)

Constructor Detail

JavaType

public JavaType(java.lang.String def)
Instantiates a new JavaType from the given definition String. The parameter is expected to be a FQN in the Java source syntax. For example:
java.lang.String
or:
byte[]

Parameters:
def - a string defining the type.

JavaType

public JavaType(java.lang.String typeName,
                int dimensions)
Instantiates a new JavaType specifying explicitly the name and the number of dimensions.

Parameters:
typeName - the name of the type (without dimensions).
dimensions - the number of dimensions.
Method Detail

getType

public java.lang.String getType()
Returns the type of the instance. For a string array this method would return "java.lang.String".

Returns:
the type.

getDimensions

public java.lang.String getDimensions()
Returns the dimension part of a type. For a type with no dimensions this method will return an empty String, for a type with one dimension it will return "[]" and so on.

Returns:
the dimension part of this type.

isPrimitive

public boolean isPrimitive()
Returns true if the type denoted by this instance if a primitive type.

Returns:
true if type is primitive.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getDimensionCount

public int getDimensionCount()
Returns the number of dimensions. Returns 0 if the type has no dimensions.

Returns:
number of dimensions.

getRaw

public java.lang.String getRaw()
Returns a raw representation of this type, ie. the way the types are written in .class files. Primitive types become a one character corresponding code and class references are encoded into, for example in the case of java.lang.String:
Ljava/lang/String;

Returns:
A "raw" string reprentation of this type.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

dropDimension

public void dropDimension()
Decreases the dimension count by one.