org.argouml.language.java.generator
Class GeneratorJava

java.lang.Object
  extended byorg.argouml.uml.generator.Generator2
      extended byorg.argouml.language.java.generator.GeneratorJava
All Implemented Interfaces:
ArgoModule, FileGenerator, NotationProvider2, Pluggable, PluggableNotation

public class GeneratorJava
extends Generator2
implements FileGenerator

Generator2 subclass to generate text for display in diagrams and 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 other languages. This code is just a placeholder for future development, I expect it to be totally replaced.


Field Summary
private static String ANY_RANGE
           
private static boolean isFileGeneration
          true when GenerateFile.
private static boolean isInUpdateMode
          true if GenerateFile in Update Mode.
private static Set JAVA_TYPES
           
private static String LANG_PACKAGE
           
private  boolean lfBeforeCurly
           
private static String LINE_SEPARATOR
           
private static Logger LOG
          Logger.
private static GeneratorJava SINGLETON
           
private static boolean VERBOSE_DOCS
           
private  boolean verboseDocs
           
 
Fields inherited from class org.argouml.uml.generator.Generator2
INDENT
 
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()
          Constructor.
 
Method Summary
(package private)  StringBuffer appendClassifierEnd(StringBuffer sbPrefix, Object cls)
          Append the classifier end sequence to the prefix text specified.
private  String generateAbstractness(Object op)
          Generate "abstract" keyword for an abstract operation.
 String generateAction(Object m)
          Generate the String representation for an Action.
 String generateActionState(Object actionState)
          Generate the String representation for an Action State.
(package private)  String generateAscEndName(Object ae)
           
 String generateAssociation(Object a)
          Generate the String representation for an Association.
 String generateAssociationEnd(Object ae)
          Generate the String representation for an AssociationEnd.
private  String generateAssociationFrom(Object a, Object associationEnd)
           
 String generateAssociationRole(Object m)
          Generate the String representation for an AssociationRole.
 String generateAttribute(Object attr, boolean documented)
          Generate the String representation for an Attribute.
private  String generateChangability(Object sf)
           
private  String generateChangeability(Object op)
          Generate "final" keyword for final operations.
 String generateClassifier(Object cls)
          Generates code for a classifier.
private  StringBuffer generateClassifierBody(Object cls)
          Generates the body of a class or interface.
private  StringBuffer generateClassifierEnd(Object cls)
           
(package private)  StringBuffer generateClassifierStart(Object cls)
          Generate the start sequence for a classifier.
private  String generateClassList(Collection classifiers)
           
private  String generateConcurrency(Object op)
          Generates "synchronized" keyword for guarded operations.
static String generateConstraintEnrichedDocComment(Object me, boolean documented, String indent)
          Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element.
 String generateConstraintEnrichedDocComment(Object me, Object ae)
          Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element.
(package private)  String generateCoreAssociationEnd(Object ae)
           
(package private)  String generateCoreAttribute(Object attr)
           
private  String generateDefaultReturnStatement(Object cls)
           
 String generateEvent(Object m)
          Generates the text for a (trigger) event.
 String generateExtensionPoint(Object ep)
          Generate code for an extension point.
 String generateFile2(Object modelElement, String path)
          Generates a file for the classifier.
private  String generateGeneralization(Collection generalizations)
           
 String generateGuard(Object m)
          Generate the String representation for a Guard.
private  String generateHeader(Object cls, String pathname, String packagePath)
           
private  String generateImports(Object cls, String packagePath)
           
private  String generateImportType(Object type, String exclude)
           
 String generateMessage(Object m)
          Generate the String representation for a Message.
private  String generateMethodBody(Object op)
          Generate the body of a method associated with the given operation.
 String generateMultiplicity(Object m)
          Generates a String representation of a Multiplicity.
private  String generateMultiplicityRange(Object mr)
           
 String generateObjectFlowState(Object m)
          Generate the String representation for a ObjectFlowState.
 String generateOperation(Object op, boolean documented)
          Generate the String representation for an Operation.
 String generatePackage(Object p)
          Generate the String representation for a Package.
 String generateParameter(Object parameter)
          Generate the String representation for a Parameter.
private  String generateScope(Object f)
           
private  String generateSpecification(Object cls)
           
 String generateState(Object m)
          Generate the String representation for a State.
 String generateStateBody(Object m)
          Generate the String representation for a StateBody.
 String generateSubmachine(Object m)
          Generate the String representation for a Submachine.
 String generateTaggedValue(Object tv)
          Generate the String representation for a TaggedValue.
private  String generateTaggedValues(Object e)
           
 String generateTransition(Object m)
          Generate the String representation for a Transition.
 String generateVisibility(Object o)
          Returns a visibility String eihter for a MVisibilityKind (according to the definition in NotationProvider2), but also for a model element, because if it is a MFeature, then the tag 'src_visibility' is to be taken into account for generating language dependent visibilities.
static GeneratorJava getInstance()
          Get the generator.
 String getModuleAuthor()
          The module author.
 String getModuleDescription()
          Textual description of the module.
 String getModuleKey()
          The module identifying key.
 String getModuleName()
          Display name of the module.
 String getModuleVersion()
          The module version.
 String getPackageName(Object namespace)
          Gets the Java package name for a given namespace, ignoring the root namespace (which is the model).
 boolean inContext(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 beforeCurl)
          Sets the lfBeforeCurly.
 void setVerboseDocs(boolean verbose)
          Sets the verboseDocs.
private static void update(Object mClassifier, File file)
          Update a source code file.
 
Methods inherited from class org.argouml.uml.generator.Generator2
generate, generateClassifierRef, generateExpression, generateName, generateStereotype, generateUninterpreted, getCodePath, getGenerator, getModulePopUpActions, getNotation, initializeModule, setModuleEnabled, shutdownModule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG
Logger.


ANY_RANGE

private static final String ANY_RANGE
See Also:
Constant Field Values

verboseDocs

private boolean verboseDocs

lfBeforeCurly

private boolean lfBeforeCurly

VERBOSE_DOCS

private static final boolean VERBOSE_DOCS
See Also:
Constant Field Values

LINE_SEPARATOR

private static final String LINE_SEPARATOR

LANG_PACKAGE

private static final String LANG_PACKAGE
See Also:
Constant Field Values

JAVA_TYPES

private static final Set JAVA_TYPES

isFileGeneration

private static boolean isFileGeneration
true when GenerateFile.


isInUpdateMode

private static boolean isInUpdateMode
true if GenerateFile in Update Mode.


SINGLETON

private static final GeneratorJava SINGLETON
Constructor Detail

GeneratorJava

protected GeneratorJava()
Constructor.

Method Detail

getInstance

public static GeneratorJava getInstance()
Get the generator.

Returns:
The singleton.

generateFile2

public String generateFile2(Object modelElement,
                            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. Returns the full path name of the the generated file or null if no file can be generated.

Specified by:
generateFile2 in interface FileGenerator
Parameters:
modelElement - the node
path - the path
Returns:
filename the generated file
See Also:
FileGenerator.generateFile2( java.lang.Object, java.lang.String)

generateHeader

private String generateHeader(Object cls,
                              String pathname,
                              String packagePath)

generateImports

private String generateImports(Object cls,
                               String packagePath)

generateImportType

private String generateImportType(Object type,
                                  String exclude)

generateExtensionPoint

public String generateExtensionPoint(Object 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 NotationProvider2
Specified by:
generateExtensionPoint in class Generator2
Parameters:
ep - The extension point to generate for
Returns:
The generated code string. Always empty in this implementation.
See Also:
NotationProvider2.generateExtensionPoint(Object)

generateAssociationRole

public String generateAssociationRole(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for an AssociationRole.

Specified by:
generateAssociationRole in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateAssociationRole(java.lang.Object)

generateOperation

public String generateOperation(Object op,
                                boolean documented)
Description copied from interface: NotationProvider2
Generate the String representation for an Operation.

Specified by:
generateOperation in interface NotationProvider2
Specified by:
generateOperation in class Generator2
See Also:
NotationProvider2.generateOperation( java.lang.Object, boolean)

generateAttribute

public String generateAttribute(Object attr,
                                boolean documented)
Description copied from interface: NotationProvider2
Generate the String representation for an Attribute.

Specified by:
generateAttribute in interface NotationProvider2
Specified by:
generateAttribute in class Generator2
See Also:
NotationProvider2.generateAttribute( java.lang.Object, boolean)

generateCoreAttribute

String generateCoreAttribute(Object attr)

generateParameter

public String generateParameter(Object parameter)
Description copied from interface: NotationProvider2
Generate the String representation for a Parameter.

Specified by:
generateParameter in interface NotationProvider2
Specified by:
generateParameter in class Generator2
See Also:
NotationProvider2.generateParameter(java.lang.Object)

generatePackage

public String generatePackage(Object p)
Description copied from interface: NotationProvider2
Generate the String representation for a Package.

Specified by:
generatePackage in interface NotationProvider2
Specified by:
generatePackage in class Generator2
See Also:
NotationProvider2.generatePackage(java.lang.Object)

generateClassifierStart

StringBuffer generateClassifierStart(Object 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

private StringBuffer generateClassifierEnd(Object cls)

appendClassifierEnd

StringBuffer appendClassifierEnd(StringBuffer sbPrefix,
                                 Object cls)
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.
Returns:
the complete classifier code, i.e., sbPrefix plus the classifier end sequence

generateClassifier

public String generateClassifier(Object 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 NotationProvider2
Specified by:
generateClassifier in class Generator2
See Also:
NotationProvider2.generateClassifier( Object)

generateClassifierBody

private StringBuffer generateClassifierBody(Object cls)
Generates the body of a class or interface.

Parameters:
cls -
Returns:
StringBuffer

generateMethodBody

private String generateMethodBody(Object 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

private String generateDefaultReturnStatement(Object cls)

generateTaggedValues

private String generateTaggedValues(Object e)

generateTaggedValue

public String generateTaggedValue(Object tv)
Description copied from interface: NotationProvider2
Generate the String representation for a TaggedValue.

Specified by:
generateTaggedValue in interface NotationProvider2
Specified by:
generateTaggedValue in class Generator2
See Also:
NotationProvider2.generateTaggedValue(java.lang.Object)

generateConstraintEnrichedDocComment

public String generateConstraintEnrichedDocComment(Object me,
                                                   Object 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 String generateConstraintEnrichedDocComment(Object me,
                                                          boolean documented,
                                                          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

generateAssociationFrom

private String generateAssociationFrom(Object a,
                                       Object associationEnd)

generateAssociation

public String generateAssociation(Object a)
Description copied from interface: NotationProvider2
Generate the String representation for an Association.

Specified by:
generateAssociation in interface NotationProvider2
Specified by:
generateAssociation in class Generator2
See Also:
NotationProvider2.generateAssociation(java.lang.Object)

generateAssociationEnd

public String generateAssociationEnd(Object ae)
Description copied from interface: NotationProvider2
Generate the String representation for an AssociationEnd.

Specified by:
generateAssociationEnd in interface NotationProvider2
Specified by:
generateAssociationEnd in class Generator2
See Also:
NotationProvider2.generateAssociationEnd(java.lang.Object)

generateCoreAssociationEnd

String generateCoreAssociationEnd(Object ae)

generateGeneralization

private String generateGeneralization(Collection generalizations)

generateSpecification

private String generateSpecification(Object cls)

generateClassList

private String generateClassList(Collection classifiers)

generateVisibility

public String generateVisibility(Object o)
Returns a visibility String eihter for a MVisibilityKind (according to the definition in NotationProvider2), but also for a model element, because if it is a MFeature, then the tag 'src_visibility' is to be taken into account for generating language dependent visibilities.

Specified by:
generateVisibility in interface NotationProvider2
Specified by:
generateVisibility in class Generator2
See Also:
NotationProvider2.generateVisibility(java.lang.Object)

generateScope

private String generateScope(Object f)

generateAbstractness

private String generateAbstractness(Object op)
Generate "abstract" keyword for an abstract operation.


generateChangeability

private String generateChangeability(Object op)
Generate "final" keyword for final operations.


generateChangability

private String generateChangability(Object sf)

generateConcurrency

private String generateConcurrency(Object op)
Generates "synchronized" keyword for guarded operations.

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

generateMultiplicity

public String generateMultiplicity(Object m)
Generates a String representation of a Multiplicity.

Specified by:
generateMultiplicity in interface NotationProvider2
Specified by:
generateMultiplicity in class Generator2
Parameters:
m - the Multiplicity.
Returns:
a human readable String.
See Also:
ANY_RANGE, generateMultiplicityRange(Object)

generateMultiplicityRange

private String generateMultiplicityRange(Object mr)

generateState

public String generateState(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a State.

Specified by:
generateState in interface NotationProvider2
Specified by:
generateState in class Generator2
See Also:
NotationProvider2.generateState(java.lang.Object)

generateSubmachine

public String generateSubmachine(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Submachine.

Specified by:
generateSubmachine in interface NotationProvider2
Specified by:
generateSubmachine in class Generator2
See Also:
NotationProvider2.generateSubmachine(java.lang.Object)

generateObjectFlowState

public String generateObjectFlowState(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a ObjectFlowState.

Specified by:
generateObjectFlowState in interface NotationProvider2
Specified by:
generateObjectFlowState in class Generator2
See Also:
NotationProvider2.generateObjectFlowState(java.lang.Object)

generateStateBody

public String generateStateBody(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a StateBody.

Specified by:
generateStateBody in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateStateBody(java.lang.Object)

generateTransition

public String generateTransition(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Transition.

Specified by:
generateTransition in interface NotationProvider2
Specified by:
generateTransition in class Generator2
See Also:
NotationProvider2.generateTransition(java.lang.Object)

generateAction

public String generateAction(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for an Action.

Specified by:
generateAction in interface NotationProvider2
Specified by:
generateAction in class Generator2
See Also:
NotationProvider2.generateAction(java.lang.Object)

generateGuard

public String generateGuard(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Guard.

Specified by:
generateGuard in interface NotationProvider2
Specified by:
generateGuard in class Generator2
See Also:
NotationProvider2.generateGuard(java.lang.Object)

generateMessage

public String generateMessage(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Message.

Specified by:
generateMessage in interface NotationProvider2
Specified by:
generateMessage in class Generator2
See Also:
NotationProvider2.generateMessage(java.lang.Object)

generateEvent

public String generateEvent(Object m)
Generates the text for a (trigger) event.

Specified by:
generateEvent in interface NotationProvider2
Specified by:
generateEvent in class Generator2
Parameters:
m - Object of any MEvent kind
Returns:
The generated event (as a String).
See Also:
NotationProvider2.generateEvent(Object)

generateAscEndName

String generateAscEndName(Object ae)

getPackageName

public String getPackageName(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

private static void update(Object mClassifier,
                           File file)
                    throws IOException,
                           antlr.ANTLRException
Update a source code file.

Parameters:
mClassifier - The classifier to update from.
file - The file to update.
Throws:
IOException
antlr.ANTLRException

getModuleName

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

Specified by:
getModuleName in interface ArgoModule
Returns:
the module name
See Also:
ArgoModule.getModuleName()

getModuleDescription

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

Specified by:
getModuleDescription in interface ArgoModule
Returns:
the module description
See Also:
ArgoModule.getModuleDescription()

getModuleAuthor

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

Specified by:
getModuleAuthor in interface ArgoModule
Returns:
a string containing the module author
See Also:
ArgoModule.getModuleAuthor()

getModuleVersion

public 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
See Also:
ArgoModule.getModuleVersion()

getModuleKey

public 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
See Also:
ArgoModule.getModuleKey()

isLfBeforeCurly

public boolean isLfBeforeCurly()
Returns the _lfBeforeCurly.

Returns:
boolean

isVerboseDocs

public boolean isVerboseDocs()
Returns the _verboseDocs.

Returns:
boolean

setLfBeforeCurly

public void setLfBeforeCurly(boolean beforeCurl)
Sets the lfBeforeCurly.

Parameters:
beforeCurl - The new value.

setVerboseDocs

public void setVerboseDocs(boolean verbose)
Sets the verboseDocs.

Parameters:
verbose - The new value.

inContext

public boolean inContext(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 Generator2
See Also:
Pluggable.inContext(java.lang.Object[])

isModuleEnabled

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

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

generateActionState

public String generateActionState(Object actionState)
Description copied from interface: NotationProvider2
Generate the String representation for an Action State.

Specified by:
generateActionState in interface NotationProvider2
Parameters:
actionState - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateActionState(java.lang.Object)


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