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 PluggableNotation, 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
protected  boolean _lfBeforeCurly
           
protected  boolean _verboseDocs
           
static java.lang.String ANY_RANGE
           
 
Fields inherited from class org.argouml.uml.generator.Generator
INDENT, TEST_SUFFIX
 
Fields inherited from interface org.argouml.application.api.Pluggable
PLUGIN_PREFIX, PLUGIN_TITLE, PLUGIN_VENDOR
 
Fields inherited from interface org.argouml.application.api.ArgoModule
cat, MODULEFILENAME, MODULEFILENAME_ALTERNATE
 
Fields inherited from interface org.argouml.uml.generator.FileGenerator
FILE_SEPARATOR
 
Constructor Summary
protected GeneratorJava()
           
 
Method Summary
 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(ru.novosoft.uml.foundation.core.MOperation op)
          Generate "abstract" keyword for an abstract operation.
 java.lang.String generateAction(ru.novosoft.uml.behavior.common_behavior.MAction m)
           
 java.lang.String generateAscEndName(ru.novosoft.uml.foundation.core.MAssociationEnd ae)
           
 java.lang.String generateAssociation(ru.novosoft.uml.foundation.core.MAssociation a)
           
 java.lang.String generateAssociationEnd(ru.novosoft.uml.foundation.core.MAssociationEnd ae)
           
 java.lang.String generateAssociationFrom(ru.novosoft.uml.foundation.core.MAssociation a, ru.novosoft.uml.foundation.core.MAssociationEnd ae)
           
 java.lang.String generateAssociationRole(ru.novosoft.uml.behavior.collaborations.MAssociationRole m)
           
 java.lang.String generateAttribute(ru.novosoft.uml.foundation.core.MAttribute attr, boolean documented)
           
 java.lang.String generateChangability(ru.novosoft.uml.foundation.core.MStructuralFeature sf)
           
 java.lang.String generateChangeability(ru.novosoft.uml.foundation.core.MOperation op)
          Generate "final" keyword for final operations.
 java.lang.String generateClassifier(ru.novosoft.uml.foundation.core.MClassifier cls)
          Generates code for a classifier.
protected  java.lang.StringBuffer generateClassifierBody(ru.novosoft.uml.foundation.core.MClassifier cls)
          Generates the body of a class or interface.
protected  java.lang.StringBuffer generateClassifierEnd(ru.novosoft.uml.foundation.core.MClassifier cls)
           
 java.lang.String generateClassList(java.util.Collection classifiers)
           
 java.lang.String generateConcurrency(ru.novosoft.uml.foundation.core.MOperation op)
          Generates "synchronized" keyword for guarded operations.
 java.lang.String generateConstraint(ru.novosoft.uml.foundation.core.MConstraint c)
           
static java.lang.String generateConstraintEnrichedDocComment(ru.novosoft.uml.foundation.core.MModelElement 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 generateConstraintEnrichedDocComment(ru.novosoft.uml.foundation.core.MModelElement me, ru.novosoft.uml.foundation.core.MAssociationEnd ae)
          Enhance/Create the doccomment for the given model element, including tags for any OCL constraints connected to the model element.
 java.lang.String generateConstraints(ru.novosoft.uml.foundation.core.MModelElement me)
           
 java.lang.String generateCoreAssociationEnd(ru.novosoft.uml.foundation.core.MAssociationEnd ae)
           
 java.lang.String generateCoreAttribute(ru.novosoft.uml.foundation.core.MAttribute attr)
           
 java.lang.String generateDefaultReturnStatement(ru.novosoft.uml.foundation.core.MClassifier cls)
           
 java.lang.String generateExtensionPoint(ru.novosoft.uml.behavior.use_cases.MExtensionPoint ep)
          Generate code for an extension point. Provided to comply with the interface, but returns null since no code will be generated.
 java.lang.String GenerateFile(java.lang.Object me, java.lang.String path)
          Generates a file for the classifier.
 java.lang.String generateGeneralization(java.util.Collection generalizations)
           
 java.lang.String generateGuard(ru.novosoft.uml.behavior.state_machines.MGuard m)
           
 java.lang.String generateHeader(ru.novosoft.uml.foundation.core.MClassifier cls, java.lang.String pathname, java.lang.String packagePath)
           
 java.lang.String generateImports(ru.novosoft.uml.foundation.core.MClassifier cls, java.lang.String packagePath)
           
 java.lang.String generateImportType(ru.novosoft.uml.foundation.core.MClassifier type, java.lang.String exclude)
           
 java.lang.String generateMessage(ru.novosoft.uml.behavior.collaborations.MMessage m)
           
 java.lang.String generateMethodBody(ru.novosoft.uml.foundation.core.MOperation op)
          Generate the body of a method associated with the given operation.
 java.lang.String generateMultiplicity(ru.novosoft.uml.foundation.data_types.MMultiplicity m)
           
 java.lang.String generateMultiplicityRange(ru.novosoft.uml.foundation.data_types.MMultiplicityRange mr)
           
 java.lang.String generateOperation(ru.novosoft.uml.foundation.core.MOperation op, boolean documented)
           
 java.lang.String generatePackage(ru.novosoft.uml.model_management.MPackage p)
           
 java.lang.String generateParameter(ru.novosoft.uml.foundation.core.MParameter param)
           
 java.lang.String generateScope(ru.novosoft.uml.foundation.core.MFeature f)
           
 java.lang.String generateSpecification(ru.novosoft.uml.foundation.core.MClass cls)
           
 java.lang.String generateState(ru.novosoft.uml.behavior.state_machines.MState m)
           
 java.lang.String generateStateBody(ru.novosoft.uml.behavior.state_machines.MState m)
           
 java.lang.String generateTaggedValue(ru.novosoft.uml.foundation.extension_mechanisms.MTaggedValue tv)
           
 java.lang.String generateTaggedValues(ru.novosoft.uml.foundation.core.MModelElement e)
           
 java.lang.String generateTransition(ru.novosoft.uml.behavior.state_machines.MTransition m)
           
 java.lang.String generateVisibility(ru.novosoft.uml.foundation.core.MFeature f)
           
 java.lang.String generateVisibility(ru.novosoft.uml.foundation.data_types.MVisibilityKind vis)
           
static GeneratorJava getInstance()
           
 java.lang.String getModuleAuthor()
           
 java.lang.String getModuleDescription()
          Textual description of the module.
 java.lang.String getModuleKey()
           
 java.lang.String getModuleName()
          Display name of the module.
 java.lang.String getModuleVersion()
           
 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 isLfBeforeCurly()
          Returns the _lfBeforeCurly.
 boolean isVerboseDocs()
          Returns the _verboseDocs.
 void setLfBeforeCurly(boolean _lfBeforeCurly)
          Sets the _lfBeforeCurly.
 void setVerboseDocs(boolean _verboseDocs)
          Sets the _verboseDocs.
protected static void update(ru.novosoft.uml.foundation.core.MClassifier mClassifier, java.io.File file)
          Update a source code file.
 
Methods inherited from class org.argouml.uml.generator.Generator
generate, generateClassifierRef, generateExpression, generateExpression, generateName, generateStereotype, generateUninterpreted, getCodePath, getGenerator, getModulePopUpActions, getNotation, inContext, initializeModule, isModuleEnabled, isTestModus, setModuleEnabled, setTestModus, shutdownModule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.argouml.application.api.Pluggable
inContext
 
Methods inherited from interface org.argouml.application.api.ArgoModule
getModulePopUpActions, initializeModule, isModuleEnabled, setModuleEnabled, shutdownModule
 

Field Detail

_verboseDocs

protected boolean _verboseDocs

_lfBeforeCurly

protected boolean _lfBeforeCurly

ANY_RANGE

public static final java.lang.String ANY_RANGE
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 me,
                                     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(ru.novosoft.uml.foundation.core.MClassifier cls,
                                       java.lang.String pathname,
                                       java.lang.String packagePath)

generateImports

public java.lang.String generateImports(ru.novosoft.uml.foundation.core.MClassifier cls,
                                        java.lang.String packagePath)

generateImportType

public java.lang.String generateImportType(ru.novosoft.uml.foundation.core.MClassifier type,
                                           java.lang.String exclude)

generateExtensionPoint

public java.lang.String generateExtensionPoint(ru.novosoft.uml.behavior.use_cases.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.

Overrides:
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(ru.novosoft.uml.behavior.collaborations.MAssociationRole m)

generateOperation

public java.lang.String generateOperation(ru.novosoft.uml.foundation.core.MOperation op,
                                          boolean documented)
Overrides:
generateOperation in class Generator

generateAttribute

public java.lang.String generateAttribute(ru.novosoft.uml.foundation.core.MAttribute attr,
                                          boolean documented)
Overrides:
generateAttribute in class Generator

generateCoreAttribute

public java.lang.String generateCoreAttribute(ru.novosoft.uml.foundation.core.MAttribute attr)

generateParameter

public java.lang.String generateParameter(ru.novosoft.uml.foundation.core.MParameter param)
Overrides:
generateParameter in class Generator

generatePackage

public java.lang.String generatePackage(ru.novosoft.uml.model_management.MPackage p)
Overrides:
generatePackage in class Generator

generateClassifierEnd

protected java.lang.StringBuffer generateClassifierEnd(ru.novosoft.uml.foundation.core.MClassifier cls)

generateClassifier

public java.lang.String generateClassifier(ru.novosoft.uml.foundation.core.MClassifier cls)
Generates code for a classifier. In case of Java code is generated for classes and interfaces only at the moment.
Overrides:
generateClassifier in class Generator
See Also:
NotationProvider.generateClassifier(MClassifier)

generateClassifierBody

protected java.lang.StringBuffer generateClassifierBody(ru.novosoft.uml.foundation.core.MClassifier cls)
Generates the body of a class or interface.
Parameters:
cls -  
Returns:
StringBuffer

generateMethodBody

public java.lang.String generateMethodBody(ru.novosoft.uml.foundation.core.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(ru.novosoft.uml.foundation.core.MClassifier cls)

generateTaggedValues

public java.lang.String generateTaggedValues(ru.novosoft.uml.foundation.core.MModelElement e)

generateTaggedValue

public java.lang.String generateTaggedValue(ru.novosoft.uml.foundation.extension_mechanisms.MTaggedValue tv)
Overrides:
generateTaggedValue in class Generator

generateConstraintEnrichedDocComment

public java.lang.String generateConstraintEnrichedDocComment(ru.novosoft.uml.foundation.core.MModelElement me,
                                                             ru.novosoft.uml.foundation.core.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(ru.novosoft.uml.foundation.core.MModelElement 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(ru.novosoft.uml.foundation.core.MModelElement me)

generateConstraint

public java.lang.String generateConstraint(ru.novosoft.uml.foundation.core.MConstraint c)

generateAssociationFrom

public java.lang.String generateAssociationFrom(ru.novosoft.uml.foundation.core.MAssociation a,
                                                ru.novosoft.uml.foundation.core.MAssociationEnd ae)

generateAssociation

public java.lang.String generateAssociation(ru.novosoft.uml.foundation.core.MAssociation a)
Overrides:
generateAssociation in class Generator

generateAssociationEnd

public java.lang.String generateAssociationEnd(ru.novosoft.uml.foundation.core.MAssociationEnd ae)
Overrides:
generateAssociationEnd in class Generator

generateCoreAssociationEnd

public java.lang.String generateCoreAssociationEnd(ru.novosoft.uml.foundation.core.MAssociationEnd ae)

generateGeneralization

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

generateSpecification

public java.lang.String generateSpecification(ru.novosoft.uml.foundation.core.MClass cls)

generateClassList

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

generateVisibility

public java.lang.String generateVisibility(ru.novosoft.uml.foundation.data_types.MVisibilityKind vis)

generateVisibility

public java.lang.String generateVisibility(ru.novosoft.uml.foundation.core.MFeature f)

generateScope

public java.lang.String generateScope(ru.novosoft.uml.foundation.core.MFeature f)

generateAbstractness

public java.lang.String generateAbstractness(ru.novosoft.uml.foundation.core.MOperation op)
Generate "abstract" keyword for an abstract operation.

generateChangeability

public java.lang.String generateChangeability(ru.novosoft.uml.foundation.core.MOperation op)
Generate "final" keyword for final operations.

generateChangability

public java.lang.String generateChangability(ru.novosoft.uml.foundation.core.MStructuralFeature sf)

generateConcurrency

public java.lang.String generateConcurrency(ru.novosoft.uml.foundation.core.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(ru.novosoft.uml.foundation.data_types.MMultiplicity m)
Overrides:
generateMultiplicity in class Generator

generateMultiplicityRange

public java.lang.String generateMultiplicityRange(ru.novosoft.uml.foundation.data_types.MMultiplicityRange mr)

generateState

public java.lang.String generateState(ru.novosoft.uml.behavior.state_machines.MState m)
Overrides:
generateState in class Generator

generateStateBody

public java.lang.String generateStateBody(ru.novosoft.uml.behavior.state_machines.MState m)

generateTransition

public java.lang.String generateTransition(ru.novosoft.uml.behavior.state_machines.MTransition m)
Overrides:
generateTransition in class Generator

generateAction

public java.lang.String generateAction(ru.novosoft.uml.behavior.common_behavior.MAction m)
Overrides:
generateAction in class Generator

generateGuard

public java.lang.String generateGuard(ru.novosoft.uml.behavior.state_machines.MGuard m)
Overrides:
generateGuard in class Generator

generateMessage

public java.lang.String generateMessage(ru.novosoft.uml.behavior.collaborations.MMessage m)
Overrides:
generateMessage in class Generator

generateAscEndName

public java.lang.String generateAscEndName(ru.novosoft.uml.foundation.core.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(ru.novosoft.uml.foundation.core.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.

canParse

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

canParse

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

getModuleName

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

getModuleDescription

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

getModuleAuthor

public java.lang.String getModuleAuthor()
Specified by:
getModuleAuthor in interface ArgoModule

getModuleVersion

public java.lang.String getModuleVersion()
Specified by:
getModuleVersion in interface ArgoModule

getModuleKey

public java.lang.String getModuleKey()
Specified by:
getModuleKey in interface ArgoModule

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


ArgoUML (c) 1996-2002
ArgoUML Project Home
ArgoUML Cookbook