xjavadoc

Class SourceClass

Implemented Interfaces:
Comparable, Named, XClass, XProgramElement, XType

public final class SourceClass
extends AbstractClass

This class represents a class for which the source code is available XJavaDocFil
Author:
Aslak Helles?y

Field Summary

private SimpleNode
_compilationUnit
The root node of the AST
private boolean
_dirty
doe we nees saving?
private Reader
_in
private boolean
_isExtraClass
private Map
_qualifiedClasses
private AbstractFile
_sourceFile
Keep a ref to the file in case of warning reporting
private List
_tagsForValidation
static int
instanceCount

Fields inherited from class xjavadoc.AbstractClass

_allInterfaces, _allSubclasses, _constructors, _containingPackage, _declaredInterfaces, _directSubclasses, _extendingInterfaces, _fields, _hash, _implementingClasses, _importedClassNames, _importedClasses, _importedPackages, _innerClasses, _isAnonymous, _isInterface, _methods, _name, _namedConstructors, _namedMethods, _qualifiedName, _superclass, _transformedName, _transformedQualifiedName

Fields inherited from class xjavadoc.AbstractProgramElement

EMPTY_LIST, _containingClass, _doc, _javadocToken, _modifierString, _modifiers, _tagFactory, _token, _xJavaDoc

Constructor Summary

SourceClass(SourceClass mainClass, int dummy, XTagFactory tagFactory)
Constructor to use for "extra" classes, that is, secondary classes that figure in the same source.
SourceClass(SourceClass containingClass, XTagFactory tagFactory)
Constructor to use for inner classes.
SourceClass(XJavaDoc xJavaDoc, File sourceFile, boolean useNodeParser, XTagFactory tagFactory)
SourceClass(XJavaDoc xJavaDoc, File sourceFile, XTagFactory tagFactory)
Constructor to use for outer classes
SourceClass(XJavaDoc xJavaDoc, Reader sourceFile, XTagFactory tagFactory)
Constructor to use for outer classes
SourceClass(XJavaDoc xJavaDoc, AbstractFile sourceFile, boolean useNodeParser, XTagFactory tagFactory, String encoding)
Constructor to use for outer classes

Method Summary

void
addTagForValidation(DefaultXTag tag)
SimpleNode
getCompilationUnit()
AbstractFile
getFile()
static String
getFileName(String qualifiedName)
Describe what the method does
String
getNextAnonymousClassName()
Returns "1", "2", etc., depending on how many inner classes we have.
Reader
getReader()
Returns a reader for the source code.
boolean
isExtraClass()
private boolean
isOuterClass()
Gets the OuterClass attribute of the SourceClass object
boolean
isPrimitive()
Returns true if this class is a primitive.
boolean
isWriteable()
Gets the Writeable attribute of the SourceClass object
long
lastModified()
Describe what the method does
private void
parse(boolean useNodeParser)
Describe what the method does
void
print(Writer out)
Prints this class to a stream
XClass
qualify(String unqualifiedClassName)
Returns fully qualified name of a class.
void
reset()
String
save(File rootDir)
Saves the class at root dir rootDir.
boolean
saveNeeded()
whether class needs saving
void
setCompilationUnit(SimpleNode compilationUnit)
Called by JavaParser at the end of the parsing
void
setDirty()
say this class is dirty and needs saving propagate to outer class ( if any )
private String
unqualifiedNameInImportedClasses(String unqualifiedClassName)
private XClass
unqualifiedNameInImportedClassesInnerClasses(String unqualifiedClassName)
private String
unqualifiedNameInImportedPackages(String unqualifiedClassName)
Describe what the method does
private String
unqualifiedNameInInnerClasses(String unqualifiedClassName)
Describe what the method does
private String
unqualifiedNameInInnerClassesOfSuperClass(String unqualifiedClassName)
Resolves Inner classes that exist in the super class hierarchy.
private String
unqualifiedNameInInnerInterface(String unqualifiedClassName)
Resolves Inner interfaces that exist in current class.
private String
unqualifiedNameInJavaDotLang(String unqualifiedClassName)
Returns the fully qualified class name if it's found in java.lang, otherwise null.
private String
unqualifiedNameInTheSameClassAsAnInnerClass(String unqualifiedClassName)
private String
unqualifiedNameInTheSamePackage(String unqualifiedClassName)
Describe what the method does
void
validateTags()
Called by XJavaDoc after the entire source is parsed, but only if validation is on.

Methods inherited from class xjavadoc.AbstractClass

addConstructor, addField, addImportedClass, addImportedPackage, addInnerClass, addInterface, addMethod, compareTo, equals, getAllSubclasses, getConstructor, getConstructors, getContainingPackage, getDeclaredInterfaces, getDirectSubclasses, getExtendingInterfaces, getField, getFields, getFields, getFields, getImplementingClasses, getImportedClasses, getImportedPackages, getInnerClasses, getInterfaces, getMembers, getMethod, getMethod, getMethodTags, getMethods, getMethods, getMethods, getName, getQualifiedName, getSuperElement, getSuperInterfaceElements, getSuperclass, getTransformedName, getTransformedQualifiedName, getType, hasImportedClasses, hasImportedPackages, hasInnerClasses, hashCode, initializeNamedConstructorsHashMap, initializeNamedMethodsHashMap, isA, isA, isAnonymous, isImplementingInterface, isImplementingInterface, isInner, isInterface, isSubclassOf, isSubclassOf, lastModified, qualify, reset, resolveImportedClasses, save, setContainingPackage, setInterface, setName, setQualifiedName, setRealised, setSuperclass, toString, updateDoc, validate

Methods inherited from class xjavadoc.AbstractProgramElement

addModifier, compareTo, getContainingAbstractClass, getContainingClass, getContainingPackage, getDoc, getModifierSpecifier, getModifiers, getTagFactory, getXJavaDoc, isAbstract, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, reset, setJavaDoc, setToken, updateDoc

Field Details

_compilationUnit

private SimpleNode _compilationUnit
The root node of the AST

_dirty

private boolean _dirty
doe we nees saving?

_in

private Reader _in

_isExtraClass

private final boolean _isExtraClass

_qualifiedClasses

private final Map _qualifiedClasses

_sourceFile

private AbstractFile _sourceFile
Keep a ref to the file in case of warning reporting

_tagsForValidation

private final List _tagsForValidation

instanceCount

public static int instanceCount

Constructor Details

SourceClass

public SourceClass(SourceClass mainClass,
                   int dummy,
                   XTagFactory tagFactory)
Constructor to use for "extra" classes, that is, secondary classes that figure in the same source.
Parameters:
mainClass - The containing class. Or rather the "main" class in the source.
dummy -

SourceClass

public SourceClass(SourceClass containingClass,
                   XTagFactory tagFactory)
Constructor to use for inner classes.
Parameters:
containingClass - The containing class;

SourceClass

public SourceClass(XJavaDoc xJavaDoc,
                   File sourceFile,
                   boolean useNodeParser,
                   XTagFactory tagFactory)
Parameters:
sourceFile -
useNodeParser -

SourceClass

public SourceClass(XJavaDoc xJavaDoc,
                   File sourceFile,
                   XTagFactory tagFactory)
Constructor to use for outer classes
Parameters:
sourceFile - The file containing the source

SourceClass

public SourceClass(XJavaDoc xJavaDoc,
                   Reader sourceFile,
                   XTagFactory tagFactory)
Constructor to use for outer classes
Parameters:
sourceFile - The file containing the source

SourceClass

public SourceClass(XJavaDoc xJavaDoc,
                   AbstractFile sourceFile,
                   boolean useNodeParser,
                   XTagFactory tagFactory,
                   String encoding)
Constructor to use for outer classes
Parameters:
sourceFile - The file containing the source
useNodeParser -

Method Details

addTagForValidation

public void addTagForValidation(DefaultXTag tag)

getCompilationUnit

public SimpleNode getCompilationUnit()

getFile

public AbstractFile getFile()

getFileName

public static String getFileName(String qualifiedName)
Describe what the method does
Parameters:
qualifiedName - Describe what the parameter does
Returns:
Describe the return value

getNextAnonymousClassName

public String getNextAnonymousClassName()
Returns "1", "2", etc., depending on how many inner classes we have.
Returns:
String containing number of next anonymous inner class

getReader

public Reader getReader()
Returns a reader for the source code.
Returns:
a reader for the source code.

isExtraClass

public boolean isExtraClass()

isOuterClass

private boolean isOuterClass()
Gets the OuterClass attribute of the SourceClass object
Returns:
The OuterClass value

isPrimitive

public boolean isPrimitive()
Returns true if this class is a primitive. That is, one of the following:
  • boolean
  • byte
  • char
  • double
  • float
  • int
  • long
  • short
  • java.lang.Boolean
  • java.lang.Byte
  • java.lang.Character
  • java.lang.Double
  • java.lang.Float
  • java.lang.Integer
  • java.lang.Long
  • java.lang.Short
  • java.lang.String
Specified by:
isPrimitive in interface XClass
Returns:
true if a primitive

isWriteable

public boolean isWriteable()
Gets the Writeable attribute of the SourceClass object
Specified by:
isWriteable in interface XClass
Returns:
The Writeable value

lastModified

public long lastModified()
Describe what the method does
Specified by:
lastModified in interface XClass
Overrides:
lastModified in interface AbstractClass
Returns:
Describe the return value

parse

private void parse(boolean useNodeParser)
Describe what the method does
Parameters:
useNodeParser - Describe what the parameter does

print

public void print(Writer out)
Prints this class to a stream
Parameters:
out - Describe what the parameter does

qualify

public XClass qualify(String unqualifiedClassName)
Returns fully qualified name of a class. 1: check for "." 2: if "." it's already qualified 3: if no ".", must try with all imported packages or classes
Specified by:
qualify in interface XClass
Overrides:
qualify in interface AbstractClass
Parameters:
unqualifiedClassName - Describe what the parameter does
Returns:
Describe the return value

reset

public void reset()
Overrides:
reset in interface AbstractClass

save

public String save(File rootDir)
            throws IOException
Saves the class at root dir rootDir. The actual java file is derived from tha package name. If no root dir is specified, save where it was loaded from
Specified by:
save in interface XClass
Overrides:
save in interface AbstractClass
Parameters:
rootDir - the root directory.
Returns:
the relative fileName to which the file was saved.

saveNeeded

public boolean saveNeeded()
whether class needs saving
Specified by:
saveNeeded in interface XClass
Returns:
true if save needed

setCompilationUnit

public void setCompilationUnit(SimpleNode compilationUnit)
Called by JavaParser at the end of the parsing
Parameters:
compilationUnit - The new CompilationUnit value

setDirty

public void setDirty()
say this class is dirty and needs saving propagate to outer class ( if any )
Specified by:
setDirty in interface XClass

unqualifiedNameInImportedClasses

private final String unqualifiedNameInImportedClasses(String unqualifiedClassName)

unqualifiedNameInImportedClassesInnerClasses

private final XClass unqualifiedNameInImportedClassesInnerClasses(String unqualifiedClassName)

unqualifiedNameInImportedPackages

private final String unqualifiedNameInImportedPackages(String unqualifiedClassName)
Describe what the method does
Parameters:
unqualifiedClassName - Describe what the parameter does
Returns:
Describe the return value

unqualifiedNameInInnerClasses

private final String unqualifiedNameInInnerClasses(String unqualifiedClassName)
Describe what the method does
Parameters:
unqualifiedClassName - Describe what the parameter does
Returns:
Describe the return value

unqualifiedNameInInnerClassesOfSuperClass

private final String unqualifiedNameInInnerClassesOfSuperClass(String unqualifiedClassName)
Resolves Inner classes that exist in the super class hierarchy.
Parameters:
unqualifiedClassName - Name of the class to resolve
Returns:
The qualified name of the inner class.

unqualifiedNameInInnerInterface

private final String unqualifiedNameInInnerInterface(String unqualifiedClassName)
Resolves Inner interfaces that exist in current class. This catches inner classes as well because isInterface() does not indicate if it's an interface.
Parameters:
unqualifiedClassName - Name of the class to resolve
Returns:
The qualified name of the inner class.

unqualifiedNameInJavaDotLang

private final String unqualifiedNameInJavaDotLang(String unqualifiedClassName)
Returns the fully qualified class name if it's found in java.lang, otherwise null.
Parameters:
unqualifiedClassName -
Returns:
fully qualified class name, or null

unqualifiedNameInTheSameClassAsAnInnerClass

private final String unqualifiedNameInTheSameClassAsAnInnerClass(String unqualifiedClassName)

unqualifiedNameInTheSamePackage

private final String unqualifiedNameInTheSamePackage(String unqualifiedClassName)
Describe what the method does
Parameters:
unqualifiedClassName - Describe what the parameter does
Returns:
Describe the return value

validateTags

public void validateTags()
            throws TagValidationException
Called by XJavaDoc after the entire source is parsed, but only if validation is on.