org.argouml.language.java.generator
Class GeneratorJava

java.lang.Object
  |
  +--org.argouml.uml.generator.Generator
        |
        +--org.argouml.language.java.generator.GeneratorJava
All Implemented Interfaces:
ArgoModule, FileGenerator, NotationProvider, Pluggable, PluggableNotation

public class GeneratorJava
extends Generator
implements FileGenerator

Generator subclass to generate text for display in diagrams in in text fields in the Argo/UML user interface. The generated code looks a lot like (invalid) Java. The idea is that other generators could be written for outher languages. This code is just a placeholder for future development, I expect it to be totally replaced.


Field Summary
private static boolean _isFileGeneration
          true when GenerateFile
private static boolean _isInUpdateMode
          true if GenerateFile in Update Mode
protected  boolean _lfBeforeCurly
           
protected  boolean _verboseDocs
           
static java.lang.String ANY_RANGE
           
private static Logger cat
          logger
private static java.lang.String LINE_SEPARATOR
           
private static GeneratorJava SINGLETON
           
private static boolean VERBOSE_DOCS
           
 
Fields inherited from class org.argouml.uml.generator.Generator
INDENT, TEST_SUFFIX
 
Fields inherited from interface org.argouml.uml.generator.FileGenerator
FILE_SEPARATOR
 
Fields inherited from interface org.argouml.application.api.Pluggable
PLUGIN_PREFIX, PLUGIN_TITLE, PLUGIN_VENDOR
 
Fields inherited from interface org.argouml.application.api.ArgoModule
MODULEFILENAME, MODULEFILENAME_ALTERNATE
 
Constructor Summary
protected GeneratorJava()
           
 
Method Summary
(package private)  java.lang.StringBuffer appendClassifierEnd(java.lang.StringBuffer sbPrefix, java.lang.Object cls, boolean fPlain)
          Append the classifier end sequence to the prefix text specified.
 boolean canParse()
          Can the notation be parsed at all?
 boolean canParse(java.lang.Object o)
          Can the notation be parsed for this object?
static java.lang.String Generate(java.lang.Object o)
           
 java.lang.String generateAbstractness(MOperation op)
          Generate "abstract" keyword for an abstract operation.
 java.lang.String generateAction(java.lang.Object m)
           
 java.lang.String generateAscEndName(MAssociationEnd ae)
           
 java.lang.String generateAssociation(MAssociation a)
           
 java.lang.String generateAssociationEnd(MAssociationEnd ae)
           
 java.lang.String generateAssociationFrom(MAssociation a, MAssociationEnd associationEnd)
           
 java.lang.String generateAssociationRole(MAssociationRole m)
           
 java.lang.String generateAttribute(MAttribute attr, boolean documented)
           
 java.lang.String generateChangability(MStructuralFeature sf)
           
 java.lang.String generateChangeability(MOperation op)
          Generate "final" keyword for final operations.
 java.lang.String generateClassifier(MClassifier cls)
          Generates code for a classifier.
protected  java.lang.StringBuffer generateClassifierBody(MClassifier cls)
          Generates the body of a class or interface.
protected  java.lang.StringBuffer generateClassifierEnd(MClassifier cls)
           
(package private)  java.lang.StringBuffer generateClassifierStart(MClassifier cls)
          Generate the start sequence for a classifier.
 java.lang.String generateClassList(java.util.Collection classifiers)
           
 java.lang.String generateConcurrency(MOperation op)
          Generates "synchronized" keyword for guarded operations.
 java.lang.String generateConstraint(MConstraint c)
           
 java.lang.String generateConstraintEnrichedDocComment(MModelElement me, MAssociationEnd ae)
          Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element.
static java.lang.String generateConstraintEnrichedDocComment(java.lang.Object me, boolean documented, java.lang.String indent)
          Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element.
 java.lang.String generateConstraints(MModelElement me)
           
 java.lang.String generateCoreAssociationEnd(MAssociationEnd ae)
           
 java.lang.String generateCoreAttribute(MAttribute attr)
           
 java.lang.String generateDefaultReturnStatement(MClassifier cls)
           
 java.lang.String generateExtensionPoint(MExtensionPoint ep)
          Generate code for an extension point.
 java.lang.String GenerateFile(java.lang.Object modelElement, java.lang.String path)
          Generates a file for the classifier.
 java.lang.String generateGeneralization(java.util.Collection generalizations)
           
 java.lang.String generateGuard(MGuard m)
           
 java.lang.String generateHeader(MClassifier cls, java.lang.String pathname, java.lang.String packagePath)
           
 java.lang.String generateImports(MClassifier cls, java.lang.String packagePath)
           
 java.lang.String generateImportType(java.lang.Object type, java.lang.String exclude)
           
 java.lang.String generateMessage(MMessage m)
           
 java.lang.String generateMethodBody(MOperation op)
          Generate the body of a method associated with the given operation.
 java.lang.String generateMultiplicity(MMultiplicity m)
           
 java.lang.String generateMultiplicityRange(MMultiplicityRange mr)
           
 java.lang.String generateOperation(MOperation op, boolean documented)
           
 java.lang.String generatePackage(MPackage p)
           
 java.lang.String generateParameter(MParameter parameter)
           
 java.lang.String generateScope(MFeature f)
           
 java.lang.String generateSpecification(MClass cls)
           
 java.lang.String generateState(MState m)
           
 java.lang.String generateStateBody(MState m)
           
 java.lang.String generateTaggedValue(MTaggedValue tv)
           
 java.lang.String generateTaggedValues(MModelElement e)
           
 java.lang.String generateTransition(MTransition m)
           
 java.lang.String generateVisibility(MVisibilityKind vis)
           
static GeneratorJava getInstance()
           
 java.lang.String getModuleAuthor()
          The module author.
 java.lang.String getModuleDescription()
          Textual description of the module.
 java.lang.String getModuleKey()
          The module identifying key
 java.lang.String getModuleName()
          Display name of the module.
 java.lang.String getModuleVersion()
          The module version.
 java.lang.String getPackageName(java.lang.Object namespace)
          Gets the Java package name for a given namespace, ignoring the root namespace (which is the model).
 boolean inContext(java.lang.Object[] o)
          A function which allows a plug-in to decide if it is available under a specific context.
 boolean isLfBeforeCurly()
          Returns the _lfBeforeCurly.
 boolean isModuleEnabled()
          The default for any Generator is to be enabled.
 boolean isVerboseDocs()
          Returns the _verboseDocs.
 void setLfBeforeCurly(boolean _lfBeforeCurly)
          Sets the _lfBeforeCurly.
 void setVerboseDocs(boolean _verboseDocs)
          Sets the _verboseDocs.
protected static void update(MClassifier mClassifier, java.io.File file)
          Update a source code file.
 
Methods inherited from class org.argouml.uml.generator.Generator
generate, generateClassifierRef, generateExpression, generateName, generateStereotype, generateUninterpreted, getCodePath, getGenerator, getModulePopUpActions, getNotation, initializeModule, isTestModus, setModuleEnabled, setTestModus, shutdownModule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cat

private static final Logger cat
logger


_verboseDocs

protected boolean _verboseDocs

_lfBeforeCurly

protected boolean _lfBeforeCurly

VERBOSE_DOCS

private static final boolean VERBOSE_DOCS
See Also:
Constant Field Values

LINE_SEPARATOR

private static final java.lang.String LINE_SEPARATOR

_isFileGeneration

private static boolean _isFileGeneration
true when GenerateFile


_isInUpdateMode

private static boolean _isInUpdateMode
true if GenerateFile in Update Mode


SINGLETON

private static GeneratorJava SINGLETON

ANY_RANGE

public static final java.lang.String ANY_RANGE
See Also:
Constant Field Values
Constructor Detail

GeneratorJava

protected GeneratorJava()
Method Detail

getInstance

public static GeneratorJava getInstance()

Generate

public static java.lang.String Generate(java.lang.Object o)

GenerateFile

public java.lang.String GenerateFile(java.lang.Object modelElement,
                                     java.lang.String path)
Generates a file for the classifier. This method could have been static if it where not for the need to call it through the Generatorinterface.

Specified by:
GenerateFile in interface FileGenerator
Returns:
the full path name of the the generated file or null if no file can be generated.

generateHeader

public java.lang.String generateHeader(MClassifier cls,
                                       java.lang.String pathname,
                                       java.lang.String packagePath)

generateImports

public java.lang.String generateImports(MClassifier cls,
                                        java.lang.String packagePath)

generateImportType

public java.lang.String generateImportType(java.lang.Object type,
                                           java.lang.String exclude)

generateExtensionPoint

public java.lang.String generateExtensionPoint(MExtensionPoint ep)

Generate code for an extension point.

Provided to comply with the interface, but returns null since no code will be generated. This should prevent a source tab being shown.

Specified by:
generateExtensionPoint in interface NotationProvider
Specified by:
generateExtensionPoint in class Generator
Parameters:
ep - The extension point to generate for
Returns:
The generated code string. Always empty in this implementation.

generateAssociationRole

public java.lang.String generateAssociationRole(MAssociationRole m)
Specified by:
generateAssociationRole in interface NotationProvider

generateOperation

public java.lang.String generateOperation(MOperation op,
                                          boolean documented)
Specified by:
generateOperation in interface NotationProvider
Specified by:
generateOperation in class Generator

generateAttribute

public java.lang.String generateAttribute(MAttribute attr,
                                          boolean documented)
Specified by:
generateAttribute in interface NotationProvider
Specified by:
generateAttribute in class Generator

generateCoreAttribute

public java.lang.String generateCoreAttribute(MAttribute attr)

generateParameter

public java.lang.String generateParameter(MParameter parameter)
Specified by:
generateParameter in interface NotationProvider
Specified by:
generateParameter in class Generator

generatePackage

public java.lang.String generatePackage(MPackage p)
Specified by:
generatePackage in interface NotationProvider
Specified by:
generatePackage in class Generator

generateClassifierStart

java.lang.StringBuffer generateClassifierStart(MClassifier cls)
Generate the start sequence for a classifier. The start sequence is everything from the preceding javadoc comment to the opening curly brace. Start sequences are non-empty for classes and interfaces only. This method is intented for package internal usage only.

Parameters:
cls - the classifier for which to generate the start sequence
Returns:
the generated start sequence

generateClassifierEnd

protected java.lang.StringBuffer generateClassifierEnd(MClassifier cls)

appendClassifierEnd

java.lang.StringBuffer appendClassifierEnd(java.lang.StringBuffer sbPrefix,
                                           java.lang.Object cls,
                                           boolean fPlain)
Append the classifier end sequence to the prefix text specified. The classifier end sequence is the closing curly brace together with any comments marking the end of the classifier. This method is intented for package internal usage.

Parameters:
sbPrefix - the prefix text to be amended. It is OK to call append on this parameter.
cls - the classifier for which to generate the classifier end sequence. Only classes and interfaces have a classifier end sequence.
fPlain - if true, only the closing brace is generated. Otherwise, this may also generate some comments.
Returns:
the complete classifier code, i.e., sbPrefix plus the classifier end sequence

generateClassifier

public java.lang.String generateClassifier(MClassifier cls)
Generates code for a classifier. In case of Java code is generated for classes and interfaces only at the moment.

Specified by:
generateClassifier in interface NotationProvider
Specified by:
generateClassifier in class Generator
See Also:
NotationProvider.generateClassifier(MClassifier)

generateClassifierBody

protected java.lang.StringBuffer generateClassifierBody(MClassifier cls)
Generates the body of a class or interface.

Parameters:
cls -
Returns:
StringBuffer

generateMethodBody

public java.lang.String generateMethodBody(MOperation op)
Generate the body of a method associated with the given operation. This assumes there's at most one method associated! If no method is associated with the operation, a default method body will be generated.


generateDefaultReturnStatement

public java.lang.String generateDefaultReturnStatement(MClassifier cls)

generateTaggedValues

public java.lang.String generateTaggedValues(MModelElement e)

generateTaggedValue

public java.lang.String generateTaggedValue(MTaggedValue tv)
Specified by:
generateTaggedValue in interface NotationProvider
Specified by:
generateTaggedValue in class Generator

generateConstraintEnrichedDocComment

public java.lang.String generateConstraintEnrichedDocComment(MModelElement me,
                                                             MAssociationEnd ae)
Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element. The tags generated are suitable for use with the ocl injector which is part of the Dresden OCL Toolkit and are in detail:  @invariant for each invariant specified  @precondition for each precondition specified  @postcondition for each postcondition specified  @key-type specifying the class of the keys of a mapped association   Currently mapped associations are not supported yet...  @element-type specifying the class referenced in an association

Parameters:
me - the model element for which the documentation comment is needed
ae - the association end which is represented by the model element
Returns:
the documentation comment for the specified model element, either enhanced or completely generated
Since:
2001-09-26 ArgoUML 0.9.3

generateConstraintEnrichedDocComment

public static java.lang.String generateConstraintEnrichedDocComment(java.lang.Object me,
                                                                    boolean documented,
                                                                    java.lang.String indent)
Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element. The tags generated are suitable for use with the ocl injector which is part of the Dresden OCL Toolkit and are in detail:  @invariant for each invariant specified  @precondition for each precondition specified  @postcondition for each postcondition specified

Parameters:
me - the model element for which the documentation comment is needed
documented - if existing tagged values should be generated in addition to javadoc
indent - indent String (usually blanks) for indentation of generated comments
Returns:
the documentation comment for the specified model element, either enhanced or completely generated
Since:
2001-09-26 ArgoUML 0.9.3

generateConstraints

public java.lang.String generateConstraints(MModelElement me)

generateConstraint

public java.lang.String generateConstraint(MConstraint c)

generateAssociationFrom

public java.lang.String generateAssociationFrom(MAssociation a,
                                                MAssociationEnd associationEnd)

generateAssociation

public java.lang.String generateAssociation(MAssociation a)
Specified by:
generateAssociation in interface NotationProvider
Specified by:
generateAssociation in class Generator

generateAssociationEnd

public java.lang.String generateAssociationEnd(MAssociationEnd ae)
Specified by:
generateAssociationEnd in interface NotationProvider
Specified by:
generateAssociationEnd in class Generator

generateCoreAssociationEnd

public java.lang.String generateCoreAssociationEnd(MAssociationEnd ae)

generateGeneralization

public java.lang.String generateGeneralization(java.util.Collection generalizations)

generateSpecification

public java.lang.String generateSpecification(MClass cls)

generateClassList

public java.lang.String generateClassList(java.util.Collection classifiers)

generateVisibility

public java.lang.String generateVisibility(MVisibilityKind vis)
Specified by:
generateVisibility in interface NotationProvider
Specified by:
generateVisibility in class Generator

generateScope

public java.lang.String generateScope(MFeature f)

generateAbstractness

public java.lang.String generateAbstractness(MOperation op)
Generate "abstract" keyword for an abstract operation.


generateChangeability

public java.lang.String generateChangeability(MOperation op)
Generate "final" keyword for final operations.


generateChangability

public java.lang.String generateChangability(MStructuralFeature sf)

generateConcurrency

public java.lang.String generateConcurrency(MOperation op)
Generates "synchronized" keyword for guarded operations.

Parameters:
op - The operation
Returns:
String The synchronized keyword if the operation is guarded, else "".

generateMultiplicity

public java.lang.String generateMultiplicity(MMultiplicity m)
Specified by:
generateMultiplicity in interface NotationProvider
Specified by:
generateMultiplicity in class Generator

generateMultiplicityRange

public java.lang.String generateMultiplicityRange(MMultiplicityRange mr)

generateState

public java.lang.String generateState(MState m)
Specified by:
generateState in interface NotationProvider
Specified by:
generateState in class Generator

generateStateBody

public java.lang.String generateStateBody(MState m)
Specified by:
generateStateBody in interface NotationProvider

generateTransition

public java.lang.String generateTransition(MTransition m)
Specified by:
generateTransition in interface NotationProvider
Specified by:
generateTransition in class Generator

generateAction

public java.lang.String generateAction(java.lang.Object m)
Specified by:
generateAction in interface NotationProvider
Specified by:
generateAction in class Generator

generateGuard

public java.lang.String generateGuard(MGuard m)
Specified by:
generateGuard in interface NotationProvider
Specified by:
generateGuard in class Generator

generateMessage

public java.lang.String generateMessage(MMessage m)
Specified by:
generateMessage in interface NotationProvider
Specified by:
generateMessage in class Generator

generateAscEndName

public java.lang.String generateAscEndName(MAssociationEnd ae)

getPackageName

public java.lang.String getPackageName(java.lang.Object namespace)
Gets the Java package name for a given namespace, ignoring the root namespace (which is the model).

Parameters:
namespace - the namespace
Returns:
the Java package name

update

protected static void update(MClassifier mClassifier,
                             java.io.File file)
                      throws java.lang.Exception
Update a source code file.

Parameters:
mClassifier - The classifier to update from.
file - The file to update.
java.lang.Exception

canParse

public boolean canParse()
Description copied from interface: NotationProvider
Can the notation be parsed at all?

Specified by:
canParse in interface NotationProvider

canParse

public boolean canParse(java.lang.Object o)
Description copied from interface: NotationProvider
Can the notation be parsed for this object?

Specified by:
canParse in interface NotationProvider

getModuleName

public java.lang.String getModuleName()
Description copied from interface: ArgoModule
Display name of the module.

Specified by:
getModuleName in interface ArgoModule
Returns:
the module name

getModuleDescription

public java.lang.String getModuleDescription()
Description copied from interface: ArgoModule
Textual description of the module.

Specified by:
getModuleDescription in interface ArgoModule
Returns:
the module description

getModuleAuthor

public java.lang.String getModuleAuthor()
Description copied from interface: ArgoModule
The module author.

Specified by:
getModuleAuthor in interface ArgoModule
Returns:
a string containing the module author

getModuleVersion

public java.lang.String getModuleVersion()
Description copied from interface: ArgoModule
The module version. There is no specified format.

Specified by:
getModuleVersion in interface ArgoModule
Returns:
a string containing the module version

getModuleKey

public java.lang.String getModuleKey()
Description copied from interface: ArgoModule
The module identifying key

Specified by:
getModuleKey in interface ArgoModule
Returns:
the string key the module uses to identify itself

isLfBeforeCurly

public boolean isLfBeforeCurly()
Returns the _lfBeforeCurly.

Returns:
boolean

isVerboseDocs

public boolean isVerboseDocs()
Returns the _verboseDocs.

Returns:
boolean

setLfBeforeCurly

public void setLfBeforeCurly(boolean _lfBeforeCurly)
Sets the _lfBeforeCurly.

Parameters:
_lfBeforeCurly - The _lfBeforeCurly to set

setVerboseDocs

public void setVerboseDocs(boolean _verboseDocs)
Sets the _verboseDocs.

Parameters:
_verboseDocs - The _verboseDocs to set

inContext

public boolean inContext(java.lang.Object[] o)
Description copied from interface: Pluggable
A function which allows a plug-in to decide if it is available under a specific context. One example of a plugin with multiple criteria is the PluggableMenu. PluggableMenu requires the first context to be a JMenuItem which wants the PluggableMenu attached to as the context, so that it can determine that it would attach to a menu. The second context is an internal (non-localized) description of the menu such as "File" or "View" so that the plugin can further decide.

Specified by:
inContext in interface Pluggable
Overrides:
inContext in class Generator
Parameters:
o - An identification of the context. The interpretation of criteria is specific to the plug-in type, but must be consistent across that type. The plug-in must want to be exposed to all contexts.
Returns:
True if the plug-in wants to make itself available for this context, otherwise false.
See Also:
Pluggable.inContext(java.lang.Object[])

isModuleEnabled

public boolean isModuleEnabled()
Description copied from class: Generator
The default for any Generator is to be enabled.

Specified by:
isModuleEnabled in interface ArgoModule
Overrides:
isModuleEnabled in class Generator
Returns:
that this module is enabled.
See Also:
ArgoModule.isModuleEnabled()


ArgoUML © 1996-2004 (20040306)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook