org.fuin.srcgen4javassist
Class SgClass

java.lang.Object
  extended by org.fuin.srcgen4javassist.SgClass

public final class SgClass
extends java.lang.Object

A class. TODO Add annotation handling


Field Summary
static SgClass BOOLEAN
          Simple "boolean" type.
static SgClass BYTE
          Simple "byte" type.
static SgClass CHAR
          Simple "char" type.
static SgClass DOUBLE
          Simple "double" type.
static SgClass FLOAT
          Simple "float" type.
static SgClass INT
          Simple "int" type.
static SgClass LONG
          Simple "long" type.
static SgClass OBJECT
          Base "Object" type.
static SgClass SHORT
          Simple "short" type.
static SgClass VOID
          Simple "void" type.
 
Constructor Summary
SgClass(java.lang.String packageName, java.lang.String simpleName)
          Basic constructor.
SgClass(java.lang.String modifiers, java.lang.String packageName, java.lang.String simpleName, boolean isinterface, SgClass enclosingClass)
          Constructor without super class.
SgClass(java.lang.String modifiers, java.lang.String packageName, java.lang.String simpleName, SgClass superClass, boolean isinterface, SgClass enclosingClass)
          Constructor with super class.
 
Method Summary
 void addAnnotation(SgAnnotation annotation)
          Adds an annotation.
 void addAnnotations(java.util.List<SgAnnotation> annotations)
          Adds a list of annotations.
 void addClass(SgClass clasz)
          Adds an inner to this class.
 void addConstructor(SgConstructor constructor)
          Adds a constructor to the class.
 void addField(SgField field)
          Adds a field to the class.
 void addInterface(SgClass intf)
          Add an interface to the class.
 void addMethod(SgMethod method)
          Adds a method to the class.
static SgClass create(SgClassPool pool, java.lang.Class clasz)
          Creates a model class by analyzing the "real" class.
static SgClass create(SgClassPool pool, java.lang.String className)
          Creates a model class by loading the "real" class with Class.forName(..)
 SgClass findClassByName(java.lang.String name)
          Find an inner class by it's name.
 SgField findFieldByName(java.lang.String name)
          Find a field by it's name.
 SgMethod findMethodByName(java.lang.String name)
          Find a method by it's name.
 java.util.List<SgAnnotation> getAnnotations()
          Returns the annotations for this class.
 java.util.List<SgClass> getClasses()
          Returns a list of all inner class.
 java.util.List<SgConstructor> getConstructors()
          Returns a list of constructors.
 SgClass getEnclosingClass()
          Returns the enclosing class.
 java.util.List<SgField> getFields()
          Returns a list of all fields.
 java.util.List<SgClass> getInterfaces()
          Returns a list of all interfaces.
 java.lang.String getInterfacesCommaSeparated()
          Returns all (fully qualified) interface names.
 java.util.List<SgMethod> getMethods()
          Returns a list of all methods.
 java.lang.String getModifiers()
          Returns the modifiers as text.
 java.lang.String getName()
          Returns the name of the class.
 java.lang.String getNameAsBinFilename()
          Returns the package and name as a class filename.
 java.lang.String getNameAsFilename()
          Returns the package and name as a filename without extension.
 java.lang.String getNameAsSrcFilename()
          Returns the package and name as a source filename.
static SgClass getNonPrimitiveClass(SgClassPool pool, SgClass primitive)
          Returns the corresponding class for a primitive.
 java.lang.String getPackageName()
          Returns the package of the class.
 java.lang.String getSimpleName()
          Returns the simple name of the class.
 java.lang.String getSimpleNameAsPackage()
          Returns the simple name of the class with an "underscore" inserted before all upper case characters and all characters converted to lower case.
 java.lang.String getSourceName()
          Returns the name of the class for use in source codes.
 SgClass getSuperClass()
          Returns the super class.
static java.lang.String getToPrimitiveMethod(SgClass clasz)
          Returns the name of the conversion method to return a primitive type value from the following types: Boolean, Byte, Character, Short, Integer, Long, Float or Double.
 boolean hasAnnotation(java.lang.String name)
          Checks if a given annotation is in the list.
 boolean hasInterface(SgClass intf)
          Checks if this class or any of it's super classes has a given interface.
 boolean isBaseType()
          Determines if the class represents a basic type (String , Boolean, Byte, Character, Short, Integer , Long, Float, Double, BigDecimal or BigInteger).
 boolean isInterface()
          Returns if this is an interface.
 boolean isPrimitive()
          Determines if the class represents a primitive type (VOID, BOOLEAN, BYTE, CHAR, SHORT, INT , LONG, FLOAT or DOUBLE).
 java.lang.String toString()
          
 java.lang.String toString(boolean showAnnotations)
          Creates the class source with or without annotations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VOID

public static final SgClass VOID
Simple "void" type.


BOOLEAN

public static final SgClass BOOLEAN
Simple "boolean" type.


BYTE

public static final SgClass BYTE
Simple "byte" type.


CHAR

public static final SgClass CHAR
Simple "char" type.


SHORT

public static final SgClass SHORT
Simple "short" type.


INT

public static final SgClass INT
Simple "int" type.


LONG

public static final SgClass LONG
Simple "long" type.


FLOAT

public static final SgClass FLOAT
Simple "float" type.


DOUBLE

public static final SgClass DOUBLE
Simple "double" type.


OBJECT

public static final SgClass OBJECT
Base "Object" type.

Constructor Detail

SgClass

public SgClass(java.lang.String packageName,
               java.lang.String simpleName)
Basic constructor.

Parameters:
packageName - Name of the package - Cannot be null.
simpleName - Name (without package) of the class - Cannot be null.

SgClass

public SgClass(java.lang.String modifiers,
               java.lang.String packageName,
               java.lang.String simpleName,
               boolean isinterface,
               SgClass enclosingClass)
Constructor without super class.

Parameters:
modifiers - Modifier names separated with space - Cannot be null.
packageName - Name of the package - Cannot be null.
simpleName - Name (without package) of the class - Cannot be null.
isinterface - Is this an interface?
enclosingClass - Enclosing class if this is an inner class - Null is allowed.

SgClass

public SgClass(java.lang.String modifiers,
               java.lang.String packageName,
               java.lang.String simpleName,
               SgClass superClass,
               boolean isinterface,
               SgClass enclosingClass)
Constructor with super class.

Parameters:
modifiers - Modifier names separated with space - Cannot be null.
packageName - Name of the package - Cannot be null.
simpleName - Name (without package) of the class - Cannot be null.
superClass - Super class or null.
isinterface - Is this an interface?
enclosingClass - Enclosing class if this is an inner class - Null is allowed
Method Detail

getAnnotations

public final java.util.List<SgAnnotation> getAnnotations()
Returns the annotations for this class.

Returns:
List of annotations - Always non-null and is unmodifiable

addAnnotation

public final void addAnnotation(SgAnnotation annotation)
Adds an annotation.

Parameters:
annotation - Annotation to add - Cannot be null.

addAnnotations

public final void addAnnotations(java.util.List<SgAnnotation> annotations)
Adds a list of annotations. The internal list will not be cleared! The annotations will simply be added with addAll(..).

Parameters:
annotations - Annotations to add - Cannot be null.

hasAnnotation

public final boolean hasAnnotation(java.lang.String name)
Checks if a given annotation is in the list.

Parameters:
name - Name of the annotation to find - Cannot be null.
Returns:
If it's found true else false.

getSuperClass

public final SgClass getSuperClass()
Returns the super class.

Returns:
Super class or null.

getSimpleNameAsPackage

public final java.lang.String getSimpleNameAsPackage()
Returns the simple name of the class with an "underscore" inserted before all upper case characters and all characters converted to lower case.

Returns:
Name usable as a package - Always non-null.

getConstructors

public final java.util.List<SgConstructor> getConstructors()
Returns a list of constructors.

Returns:
Constructor list - Always non-null and is unmodifiable.

addConstructor

public final void addConstructor(SgConstructor constructor)
Adds a constructor to the class. Does nothing if the constructor is already in the list of constructors. You will never need to use this method in your code! A constructor is added automatically to the owning class when it's constructed!

Parameters:
constructor - Constructor to add - Cannot be null.

isInterface

public final boolean isInterface()
Returns if this is an interface.

Returns:
If it's an interface true else false.

getMethods

public final java.util.List<SgMethod> getMethods()
Returns a list of all methods.

Returns:
Method list - Always non-null and is unmodifiable.

addMethod

public final void addMethod(SgMethod method)
Adds a method to the class. Does nothing if the method is already in the list of methods. You will never need to use this method in your code! A method is added automatically to the owning class when it's constructed!

Parameters:
method - Method to add - Cannot be null.

getName

public final java.lang.String getName()
Returns the name of the class.

Returns:
Name with inner classes separated with "$".

getSourceName

public final java.lang.String getSourceName()
Returns the name of the class for use in source codes.

Returns:
Name with inner classes separated with ".".

getNameAsFilename

public final java.lang.String getNameAsFilename()
Returns the package and name as a filename without extension.

Returns:
Relative path and filename.

getNameAsSrcFilename

public final java.lang.String getNameAsSrcFilename()
Returns the package and name as a source filename.

Returns:
Relative path and filename with extension ".java".

getNameAsBinFilename

public final java.lang.String getNameAsBinFilename()
Returns the package and name as a class filename.

Returns:
Relative path and filename with extension ".class".

getPackageName

public final java.lang.String getPackageName()
Returns the package of the class.

Returns:
Package name.

getSimpleName

public final java.lang.String getSimpleName()
Returns the simple name of the class.

Returns:
Name without package.

getInterfaces

public final java.util.List<SgClass> getInterfaces()
Returns a list of all interfaces.

Returns:
List of interfaces - Always non-null and unmodifiable.

addInterface

public final void addInterface(SgClass intf)
Add an interface to the class.

Parameters:
intf - Interface to add - Cannot be null.

getInterfacesCommaSeparated

public final java.lang.String getInterfacesCommaSeparated()
Returns all (fully qualified) interface names.

Returns:
Names separated by a comma - Always non-null.

getFields

public final java.util.List<SgField> getFields()
Returns a list of all fields.

Returns:
List of fields - Always non-null and is unmodifiable

addField

public final void addField(SgField field)
Adds a field to the class. Does nothing if the field is already in the list of fields. You will never need to use this method in your code! A field is added automatically to the owning class when it's constructed!

Parameters:
field - Field to add - Cannot be null.

getClasses

public final java.util.List<SgClass> getClasses()
Returns a list of all inner class.

Returns:
List of inner classes - Always non-null and is unmodifiable.

addClass

public final void addClass(SgClass clasz)
Adds an inner to this class. Does nothing if the class is already in the list of inner classes.

Parameters:
clasz - Inner class to add - Cannot be null.

getEnclosingClass

public final SgClass getEnclosingClass()
Returns the enclosing class.

Returns:
Enclosing class or null.

findClassByName

public final SgClass findClassByName(java.lang.String name)
Find an inner class by it's name.

Parameters:
name - Full qualified name of the class to find - Cannot be null.
Returns:
Class or null if it's not found.

findMethodByName

public final SgMethod findMethodByName(java.lang.String name)
Find a method by it's name.

Parameters:
name - Name of the method to find - Cannot be null.
Returns:
Method or null if it's not found.

findFieldByName

public final SgField findFieldByName(java.lang.String name)
Find a field by it's name.

Parameters:
name - Name of the field to find - Cannot be null.
Returns:
Field or null if it's not found.

getModifiers

public final java.lang.String getModifiers()
Returns the modifiers as text.

Returns:
Modifier names.

isPrimitive

public final boolean isPrimitive()
Determines if the class represents a primitive type (VOID, BOOLEAN, BYTE, CHAR, SHORT, INT , LONG, FLOAT or DOUBLE).

Returns:
true if and only if this class represents a primitive type

isBaseType

public final boolean isBaseType()
Determines if the class represents a basic type (String , Boolean, Byte, Character, Short, Integer , Long, Float, Double, BigDecimal or BigInteger).

Returns:
true if and only if this class represents one of those types.

hasInterface

public final boolean hasInterface(SgClass intf)
Checks if this class or any of it's super classes has a given interface.

Parameters:
intf - Interface to find - Cannot be null.
Returns:
If the class implements the interface true else false.

toString

public final java.lang.String toString()

Overrides:
toString in class java.lang.Object

toString

public final java.lang.String toString(boolean showAnnotations)
Creates the class source with or without annotations.

Parameters:
showAnnotations - To include annotations true else true.
Returns:
Source code of the class.

create

public static SgClass create(SgClassPool pool,
                             java.lang.String className)
Creates a model class by loading the "real" class with Class.forName(..) and analyzing it. Throws an IllegalArgumentException if the class cannot be constructed with "forName".

Parameters:
pool - Pool to use.
className - Full qualified name.
Returns:
Class.

create

public static SgClass create(SgClassPool pool,
                             java.lang.Class clasz)
Creates a model class by analyzing the "real" class.

Parameters:
pool - Pool to use.
clasz - Class to analyze.
Returns:
Class.

getNonPrimitiveClass

public static final SgClass getNonPrimitiveClass(SgClassPool pool,
                                                 SgClass primitive)
Returns the corresponding class for a primitive.

Parameters:
pool - Pool to use.
primitive - Primitive class to convert. A call to isPrimitive() on this argument must return true and a call to equals(SgClass.VOID) returns false else an IllegalArgumentException will be thrown.
Returns:
Non primitive class.

getToPrimitiveMethod

public static final java.lang.String getToPrimitiveMethod(SgClass clasz)
Returns the name of the conversion method to return a primitive type value from the following types: Boolean, Byte, Character, Short, Integer, Long, Float or Double. If this class is not one of the above types a IllegalArgumentException will be thrown.

Parameters:
clasz - Class to return a conversion method from.
Returns:
Name of the no argument conversion method (like "intValue" for converting an Integer into an int ).


Copyright © 2011 Future Invent Informationsmanagement GmbH. All Rights Reserved.