org.pf.tools.cda.base.model
Class ClassInformation

java.lang.Object
  extended by org.pf.tools.cda.base.model.AModelObject
      extended by org.pf.tools.cda.base.model.AAnalyzableElement
          extended by org.pf.tools.cda.base.model.ClassInformation
All Implemented Interfaces:
java.lang.Comparable, org.pf.bif.lifecycle.IReleasable, IAnalyzableElement, IExplorableElement, IExplorableElementVisiting, IExplorationModelObject, IObjectProperties, IType

public class ClassInformation
extends AAnalyzableElement
implements java.lang.Comparable, IType

Contains all information about a class that is relevant to the dependency analyzer.

Version:
1.6
Author:
Manfred Duchrow

Field Summary
static ClassInformation[] EMPTY_ARRAY
           
 
Fields inherited from class org.pf.tools.cda.base.model.AModelObject
EMPTY_MODEL_OBJECT_ARRAY
 
Fields inherited from interface org.pfsw.odem.IType
EMPTY_TYPE_ARRAY
 
Fields inherited from interface org.pf.tools.cda.base.model.IAnalyzableElement
EMPTY_BASE_ARRAY
 
Method Summary
 boolean accept(IExplorableElementVisitor visitor)
          Implementation of the visitor pattern (GOF) for all derived interfaces if IExplorableElement.
 boolean acceptTypes(ITypesVisitor visitor)
          Invokes the visitors callback method for this type.
 void addDependency(ClassInformationDependency dependency)
          Add the given dependency to the internal dependency set.
 void addInterface(ClassInformation classInfo)
          Adds the given class information to the list of directly extended or implemented interfaces if it is not yet in the list.
 void addReferredClass(ClassInformation classInfo)
          Adds the given class information to the list of referred classes if it is not yet in the list.
 void beAnnotationType()
          Set the type to TypeClassification.ANNOTATION
 void beClassType()
          Set the type to TypeClassification.CLASS
 void beEnumType()
          Set the type to TypeClassification.ENUM
 void beInterfaceType()
          Set the type to TypeClassification.INTERFACE
 boolean canHaveDependencies()
          Returns if this object potentially has dependencies to other objects.
static ClassInformation[] collectionToArray(java.util.Collection coll)
           
 void collectReferredPackages(java.util.Collection<ClassPackage> collection)
          Adds all packages of the directly referred classes to the given collection.
 int compareTo(java.lang.Object obj)
           
 boolean equals(java.lang.Object obj)
           
 ClassInformation[] getAllContainedClasses()
          Returns all classes that are contained in this element or any of its structural sub-elements.
 AnalyzableElementType getAnalyzableElementType()
          Returns the type of the analyzable element.
 int getChildCount()
          Returns the current number of children.
 AModelObject[] getChildren()
          Returns the children (always an empty array here)
 java.lang.String getClassFileName()
          Returns the name of the file corresponding to this class (including the full sub directory path representing the package).
 ClassFileVersion getClassFileVersion()
          Returns the version of the underlying class file.
 TypeClassification getClassification()
          Returns whether is is a class an interface an enum or annotation.
 java.lang.String getClassName()
          Returns the fully qualified name of the class
 int getClassNameHash()
           
 ClassPackage getClassPackage()
          Returns the package object that contains this class
 GenericClassContainer getContainer()
          Returns the name of the container this class was found in.
 java.lang.String getContainerName()
          Returns the name of the container this class is located in
 IExplorationContext getContext()
          Returns the context of this object
 DependencySet getDependencies()
          Returns all dependencies to other types.
 ClassInformation[] getDirectlyExtendedInterfaces()
          Returns an array of all interfaces directly extended by this interface.
 ClassInformation[] getDirectlyImplementedInterfaces()
          Returns an array of all interfaces directly implemented by this class.
 ClassPackage[] getDirectReferredPackages()
          Returns all packages this class directly depends on.
 java.util.Collection<IType> getDirectReferredTypes()
          Returns all types this type directly depends on.
 long getFileSize()
           
 java.lang.String getJustClassName()
          Returns the class name without the package name
 java.lang.String[] getModifierNames()
          Returns the modifiers of this class as strings.
 int getModifiers()
          Returns the modifier bits of the class (see Modifier).
 java.lang.String getModifierString()
          Returns the modifiers as string where the separator is a blank
 java.lang.String getName()
          Returns the full qualified name of the class this object represents
 INamespace getNamespace()
          Returns the namespace this type belongs to.
 java.lang.String getPackageName()
          Returns the package name of this class.
 java.util.List<ClassInformation> getReferredClasses()
          Returns the types on which this class depends directly.
 ClassInformation[] getReferredClassesArray()
          Returns an array with all classes this class directly depends on.
 java.lang.String getStereotype()
          Returns the stereotype (e.g.
 java.lang.String getStereotypeTypeName()
          Returns the type (class, interface, annotation, enum) as stereotype name.
 ClassInformation getSuperClass()
          Returns the superclass information of this class
 java.lang.String getUnqualifiedName()
          Returns the name without the namespace
 Visibility getVisibility()
          Returns the visibility of this type.
 Workset getWorkset()
          Returns the workset in which this class information is currently hold
 boolean hasExtendedInterfaces()
          Returns true if there is information available directly implemented interfaces.
 int hashCode()
           
 boolean hasImplementedInterfaces()
          Returns true if there is information available directly implemented interfaces.
 boolean hasMainMethod()
          Returns true if this is a class with a static main( String[] args ) method.
 boolean hasSuperClass()
          Returns true if there is a superclass information available for this class or interface
 boolean isAbstract()
          Returns whether or not this class is abstract
 boolean isAnnotation()
          Returns true if this represents an annotation
 boolean isClass()
          Returns true if this represents a class
 boolean isComplete()
          Returns true if the class has been completely analyzed
 boolean isContainerClassOf(ClassInformation innerClass)
          Returns true if the given class is an inner class of this class.
 boolean isContainerClassOf(java.lang.String innerClassName)
          Returns true if the given class name specifies an inner class of this class.
 boolean isCurrentlyAnalyzed()
          Returns true if the class is currently analyzed.
 boolean isDirectExtensionOf(ClassInformation classInfo)
          Returns true if this class or interface is a direct extension of the given class or interface.
 boolean isDirectExtensionOf(IType type)
          Returns true if this type extends the given type directly.
 boolean isDirectImplementorOf(ClassInformation interfaceInfo)
          Returns true if this class directly implements the given interface.
 boolean isDirectImplementorOf(IType type)
          Returns true if this type directly implements the given type.
 boolean isEnum()
          Returns true if this represents an enum.
 boolean isExtensionOf(ClassInformation classOrInterface)
          Returns true if this class or interface is a direct or indirect extension of the given class or interface.
 boolean isFinal()
          Returns whether or not this class is final
 boolean isImplementorOf(ClassInformation interfaceInfo)
          Returns true if this class directly or indirectly implementor of the given interface.
 boolean isInnerClass()
           
 boolean isInnerClassOf(ClassInformation outerClass)
          Returns true if this class is an inner class of the given class.
 boolean isInnerClassOf(java.lang.String outerClassName)
          Returns true if this class is an inner class of the class with the given name.
 boolean isInterface()
          Returns true, if this represents an interface.
 boolean isNotFound()
          Returns true if the class has been completely analyzed
 boolean isPublic()
          Returns whether or not this class is public
 boolean isSubclassOf(ClassInformation otherClass)
          Returns true if the given class is the direct superclass of this class
 boolean isSynthetic()
          Returns whether or not this class is synthetic
 boolean isUninitialized()
          Returns true if the class is not yet analyzed at all.
 boolean knowsContainer()
          Returns true if the class already "knows" the container it was found in.
 boolean loadIfNecessary()
          If the dependencies of this class have not yet been initialized then they will be loaded now.
 boolean refersTo(IAnalyzableElement analyzableElement)
          Returns true if any of the directly referred classes is identical to the given one.
 boolean refersToClassNamed(java.lang.String name)
          Returns true if any of the referred classes has the same name as the given one.
 void release()
           
 void setClassFileVersion(ClassFileVersion newValue)
           
 void setClassification(TypeClassification javaType)
          Set the type classification of this class info.
 void setClassInitializer(IClassInitializer newValue)
           
 void setFileSize(long newValue)
           
 void setIsInnerClass(boolean newValue)
           
 void setModifiers(int newValue)
           
 void setStateAnalyzing()
           
 void setStateComplete()
           
 void setStateNotFound()
           
 void setSuperClass(ClassInformation newValue)
          Sets the superclass information of this class
 void setWithMainMethod(boolean newValue)
           
 java.lang.String toString()
           
 
Methods inherited from class org.pf.tools.cda.base.model.AAnalyzableElement
canBeAnalyzedForDependencies
 
Methods inherited from class org.pf.tools.cda.base.model.AModelObject
apply, countAllElementsRecursivly, getNumberOfAncestors, getProperty, getPropertyNames, setProperty
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pfsw.odem.IObjectProperties
getProperty, getPropertyNames, setProperty
 

Field Detail

EMPTY_ARRAY

public static final ClassInformation[] EMPTY_ARRAY
Method Detail

getClassName

public java.lang.String getClassName()
Returns the fully qualified name of the class


getClassNameHash

public int getClassNameHash()

getClassFileVersion

public ClassFileVersion getClassFileVersion()
Returns the version of the underlying class file. This version also contains the information which JRE version is needed to execute the binary code in that file.


setClassFileVersion

public void setClassFileVersion(ClassFileVersion newValue)

getReferredClasses

public java.util.List<ClassInformation> getReferredClasses()
Returns the types on which this class depends directly.


getClassification

public TypeClassification getClassification()
Returns whether is is a class an interface an enum or annotation.

Specified by:
getClassification in interface IType

getSuperClass

public ClassInformation getSuperClass()
Returns the superclass information of this class


setSuperClass

public void setSuperClass(ClassInformation newValue)
Sets the superclass information of this class


getModifiers

public int getModifiers()
Returns the modifier bits of the class (see Modifier).


setModifiers

public void setModifiers(int newValue)

getFileSize

public long getFileSize()

setFileSize

public void setFileSize(long newValue)

isInnerClass

public boolean isInnerClass()

setIsInnerClass

public void setIsInnerClass(boolean newValue)

setClassInitializer

public void setClassInitializer(IClassInitializer newValue)

setWithMainMethod

public void setWithMainMethod(boolean newValue)

collectionToArray

public static ClassInformation[] collectionToArray(java.util.Collection coll)

getName

public java.lang.String getName()
Returns the full qualified name of the class this object represents

Specified by:
getName in interface IExplorationModelObject
Specified by:
getName in class AModelObject

canHaveDependencies

public boolean canHaveDependencies()
Returns if this object potentially has dependencies to other objects. That is, it can be analyzed by CDA regarding its dependencies.

Overrides:
canHaveDependencies in class AModelObject

isComplete

public boolean isComplete()
Returns true if the class has been completely analyzed


isNotFound

public boolean isNotFound()
Returns true if the class has been completely analyzed


isUninitialized

public boolean isUninitialized()
Returns true if the class is not yet analyzed at all. That is, there was no attempt to load it from its corresponding .class file


isCurrentlyAnalyzed

public boolean isCurrentlyAnalyzed()
Returns true if the class is currently analyzed. That is the information about the class is currently gathered by an analyzer.


isClass

public boolean isClass()
Returns true if this represents a class


isInterface

public boolean isInterface()
Returns true, if this represents an interface.


isEnum

public boolean isEnum()
Returns true if this represents an enum.


isAnnotation

public boolean isAnnotation()
Returns true if this represents an annotation


isInnerClassOf

public boolean isInnerClassOf(ClassInformation outerClass)
Returns true if this class is an inner class of the given class.


isInnerClassOf

public boolean isInnerClassOf(java.lang.String outerClassName)
Returns true if this class is an inner class of the class with the given name.


isContainerClassOf

public boolean isContainerClassOf(ClassInformation innerClass)
Returns true if the given class is an inner class of this class.


isContainerClassOf

public boolean isContainerClassOf(java.lang.String innerClassName)
Returns true if the given class name specifies an inner class of this class.


hasSuperClass

public boolean hasSuperClass()
Returns true if there is a superclass information available for this class or interface


hasImplementedInterfaces

public boolean hasImplementedInterfaces()
Returns true if there is information available directly implemented interfaces.


hasExtendedInterfaces

public boolean hasExtendedInterfaces()
Returns true if there is information available directly implemented interfaces.


hasMainMethod

public boolean hasMainMethod()
Returns true if this is a class with a static main( String[] args ) method.


refersToClassNamed

public boolean refersToClassNamed(java.lang.String name)
Returns true if any of the referred classes has the same name as the given one.

Parameters:
name - The name of the class to look for

refersTo

public boolean refersTo(IAnalyzableElement analyzableElement)
Returns true if any of the directly referred classes is identical to the given one.

Specified by:
refersTo in interface IAnalyzableElement
Parameters:
analyzableElement - The class to check if this class directly refers to it

getDirectlyImplementedInterfaces

public ClassInformation[] getDirectlyImplementedInterfaces()
Returns an array of all interfaces directly implemented by this class. If this is an interface it returns an empty array.


getDirectlyExtendedInterfaces

public ClassInformation[] getDirectlyExtendedInterfaces()
Returns an array of all interfaces directly extended by this interface. If this is a class it returns an empty array.


isSubclassOf

public boolean isSubclassOf(ClassInformation otherClass)
Returns true if the given class is the direct superclass of this class


isDirectExtensionOf

public boolean isDirectExtensionOf(ClassInformation classInfo)
Returns true if this class or interface is a direct extension of the given class or interface.


isExtensionOf

public boolean isExtensionOf(ClassInformation classOrInterface)
Returns true if this class or interface is a direct or indirect extension of the given class or interface.


isDirectImplementorOf

public boolean isDirectImplementorOf(ClassInformation interfaceInfo)
Returns true if this class directly implements the given interface.


isImplementorOf

public boolean isImplementorOf(ClassInformation interfaceInfo)
Returns true if this class directly or indirectly implementor of the given interface. That is, it could be casted on the given interface.

Parameters:
interfaceInfo - The interface to be checked

setStateAnalyzing

public void setStateAnalyzing()

setStateComplete

public void setStateComplete()

setStateNotFound

public void setStateNotFound()

loadIfNecessary

public boolean loadIfNecessary()
If the dependencies of this class have not yet been initialized then they will be loaded now.

Returns:
true if the dependencies were loaded by this call, false if the class was already initialized or could not be initialized.

equals

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

hashCode

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

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class AModelObject
See Also:
Comparable.compareTo(java.lang.Object)

getClassFileName

public java.lang.String getClassFileName()
Returns the name of the file corresponding to this class (including the full sub directory path representing the package).

Example: For class "org.apache.xml.Parser" the result would be "org/apache/xml/Parser.class".


addDependency

public void addDependency(ClassInformationDependency dependency)
Add the given dependency to the internal dependency set.


addReferredClass

public void addReferredClass(ClassInformation classInfo)
Adds the given class information to the list of referred classes if it is not yet in the list.


addInterface

public void addInterface(ClassInformation classInfo)
Adds the given class information to the list of directly extended or implemented interfaces if it is not yet in the list.


getReferredClassesArray

public ClassInformation[] getReferredClassesArray()
Returns an array with all classes this class directly depends on. Never returns null.


getPackageName

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


getJustClassName

public java.lang.String getJustClassName()
Returns the class name without the package name


getContainerName

public java.lang.String getContainerName()
Returns the name of the container this class is located in


getClassPackage

public ClassPackage getClassPackage()
Returns the package object that contains this class


getContainer

public GenericClassContainer getContainer()
Returns the name of the container this class was found in.


knowsContainer

public boolean knowsContainer()
Returns true if the class already "knows" the container it was found in.


getDirectReferredPackages

public ClassPackage[] getDirectReferredPackages()
Returns all packages this class directly depends on.


collectReferredPackages

public void collectReferredPackages(java.util.Collection<ClassPackage> collection)
Adds all packages of the directly referred classes to the given collection.


beClassType

public void beClassType()
Set the type to TypeClassification.CLASS


beInterfaceType

public void beInterfaceType()
Set the type to TypeClassification.INTERFACE


beEnumType

public void beEnumType()
Set the type to TypeClassification.ENUM


beAnnotationType

public void beAnnotationType()
Set the type to TypeClassification.ANNOTATION


getModifierNames

public java.lang.String[] getModifierNames()
Returns the modifiers of this class as strings. Supported modifiers are: "public", "final", "abstract", "synthetic".


getModifierString

public java.lang.String getModifierString()
Returns the modifiers as string where the separator is a blank


isAbstract

public boolean isAbstract()
Returns whether or not this class is abstract

Specified by:
isAbstract in interface IType

isFinal

public boolean isFinal()
Returns whether or not this class is final

Specified by:
isFinal in interface IType

isPublic

public boolean isPublic()
Returns whether or not this class is public


isSynthetic

public boolean isSynthetic()
Returns whether or not this class is synthetic


getVisibility

public Visibility getVisibility()
Returns the visibility of this type.

Specified by:
getVisibility in interface IType

getStereotypeTypeName

public java.lang.String getStereotypeTypeName()
Returns the type (class, interface, annotation, enum) as stereotype name.


getStereotype

public java.lang.String getStereotype()
Returns the stereotype (e.g. "<>" or "<>").


getAnalyzableElementType

public AnalyzableElementType getAnalyzableElementType()
Returns the type of the analyzable element.

Specified by:
getAnalyzableElementType in interface IAnalyzableElement

release

public void release()
Specified by:
release in interface org.pf.bif.lifecycle.IReleasable

getWorkset

public Workset getWorkset()
Returns the workset in which this class information is currently hold

Specified by:
getWorkset in interface IAnalyzableElement
Specified by:
getWorkset in class AModelObject

getChildCount

public int getChildCount()
Returns the current number of children. Here this is always zero because classes don't have children

Specified by:
getChildCount in class AModelObject

getChildren

public AModelObject[] getChildren()
Returns the children (always an empty array here)

Specified by:
getChildren in class AModelObject

getContext

public IExplorationContext getContext()
Returns the context of this object

Specified by:
getContext in interface IExplorationModelObject

getNamespace

public INamespace getNamespace()
Returns the namespace this type belongs to.

Specified by:
getNamespace in interface IType

getUnqualifiedName

public java.lang.String getUnqualifiedName()
Returns the name without the namespace

Specified by:
getUnqualifiedName in interface IType

getDependencies

public DependencySet getDependencies()
Returns all dependencies to other types. That includes all different dependencies to the same type (fields, method signatures, inheritance etc.).
To get just the different types this type depends on use getDirectReferredTypes().

Specified by:
getDependencies in interface IType

getAllContainedClasses

public ClassInformation[] getAllContainedClasses()
Returns all classes that are contained in this element or any of its structural sub-elements. If no classes are contained, an empty array will be returned.

Specified by:
getAllContainedClasses in interface IAnalyzableElement

accept

public boolean accept(IExplorableElementVisitor visitor)
Implementation of the visitor pattern (GOF) for all derived interfaces if IExplorableElement.

Specified by:
accept in interface IExplorableElementVisiting
Parameters:
visitor - The implementor of the vistor interface to be called by this method
Returns:
true if processing should be continued, otherwise false

acceptTypes

public boolean acceptTypes(ITypesVisitor visitor)
Invokes the visitors callback method for this type.

Specified by:
acceptTypes in interface IExplorableElementVisiting
Parameters:
visitor - The implementor of the vistor interface to be called by this method
Returns:
true if processing should be continued, otherwise false

getDirectReferredTypes

public java.util.Collection<IType> getDirectReferredTypes()
Returns all types this type directly depends on. Each type must be in the result collection only once. This method never returns null. This method returns an immutable copy of the underlying dependencies.

Specified by:
getDirectReferredTypes in interface IType
Returns:
A collection zero or many referred types without duplicates

isDirectExtensionOf

public boolean isDirectExtensionOf(IType type)
Returns true if this type extends the given type directly.

Specified by:
isDirectExtensionOf in interface IType
Parameters:
type - Any type that can be extended.
Returns:
true if this type is a direct extension of the given type.
See Also:
IType.isDirectImplementorOf(IType), IType.getDependencies()

isDirectImplementorOf

public boolean isDirectImplementorOf(IType type)
Returns true if this type directly implements the given type.

Specified by:
isDirectImplementorOf in interface IType
Parameters:
type - An interface type
Returns:
true if this type is a direct implementor of the given interface type.
See Also:
IType.isDirectExtensionOf(IType), IType.getDependencies()

setClassification

public void setClassification(TypeClassification javaType)
Set the type classification of this class info.


toString

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