umbrello: JavaWriter Class Reference

umbrello 2.39.1 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
JavaWriter Class Reference

`#include <javawriter.h>`

Inheritance diagram for JavaWriter:

## Public Member Functions
| JavaWriter ()
virtual | ~JavaWriter ()
virtual void | writeClass (UMLClassifier *c)
virtual Uml::ProgrammingLanguage::Enum | language () const
QStringList | defaultDatatypes () const
Public Member Functions inherited from SimpleCodeGenerator
| SimpleCodeGenerator (bool createDirHierarchyForPackages=true)
virtual | ~SimpleCodeGenerator ()
void | writeCodeToFile (UMLClassifierList &concepts)
void | writeCodeToFile ()
Public Member Functions inherited from CodeGenerator
| CodeGenerator ()
virtual | ~CodeGenerator ()
bool | addCodeDocument (CodeDocument *add_object)
bool | removeCodeDocument (CodeDocument *remove_object)
CodeDocumentList * | getCodeDocumentList ()
QString | getUniqueID (CodeDocument *codeDoc)
virtual void | saveToXMI (QXmlStreamWriter &writer)
CodeDocument * | findCodeDocumentByID (const QString &id)
void | setIncludeHeadings (bool i)
bool | includeHeadings () const
void | setHeadingFileDir (const QString &)
QString | headingFileDir () const
void | setForceDoc (bool f)
bool | forceDoc () const
void | setSectionCommentPolicy (CodeGenerationPolicy::WriteSectionCommentsPolicy f)
bool | forceSections () const
virtual QString | getHeadingFile (const QString &file)
QString | findFileName (CodeDocument *codeDocument)
virtual void | loadFromXMI (QDomElement &element)
CodeDocument * | findCodeDocumentByClassifier (UMLClassifier *classifier)
virtual bool | isReservedKeyword (const QString &keyword)
virtual QStringList | reservedKeywords () const
virtual void | createDefaultStereotypes ()

## Private Member Functions
void | writeClassDecl (UMLClassifier *c, QTextStream &java)
void | writeConstructor (UMLClassifier *c, QTextStream &java)
void | getSuperImplementedOperations (UMLClassifier *c, UMLOperationList &yetImplementedOpList, UMLOperationList &toBeImplementedOpList, bool noClassInPath=true)
void | getInterfacesOperationsToBeImplemented (UMLClassifier *c, UMLOperationList &opl)
void | writeOperations (UMLClassifier *c, QTextStream &j)
void | writeOperations (UMLOperationList &oplist, QTextStream &j)
void | writeAttributeDecls (UMLAttributeList &atpub, UMLAttributeList &atprot, UMLAttributeList &atpriv, QTextStream &java)
void | writeAssociationDecls (UMLAssociationList associations, Uml::ID::Type id, QTextStream &java)
void | writeAssociationRoleDecl (QString fieldClassName, QString roleName, QString multi, QString doc, Uml::Visibility::Enum visib, QTextStream &java)
void | writeAttributeMethods (UMLAttributeList &atpub, Uml::Visibility::Enum visibility, QTextStream &java)
void | writeAssociationMethods (UMLAssociationList associations, UMLClassifier *thisClass, QTextStream &java)
void | writeAssociationRoleMethod (QString fieldClassName, QString roleName, QString multi, QString description, Uml::Visibility::Enum visib, Uml::Changeability::Enum change, QTextStream &java)
void | writeSingleAttributeAccessorMethods (QString fieldClassName, QString fieldVarName, QString fieldName, QString description, Uml::Visibility::Enum visibility, Uml::Changeability::Enum change, bool isFinal, QTextStream &java)
void | writeVectorAttributeAccessorMethods (QString fieldClassName, QString fieldVarName, QString fieldName, QString description, Uml::Visibility::Enum visibility, Uml::Changeability::Enum change, QTextStream &java)
void | writeComment (const QString &text, const QString &indent, QTextStream &java, bool javaDocStyle=false)
void | writeDocumentation (QString header, QString body, QString end, QString indent, QTextStream &java)
QString | getUMLObjectName (UMLObject *obj)
QString | fixTypeName (const QString &string)
QString | fixInitialStringDeclValue (const QString &val, const QString &type)
void | writeBlankLine (QTextStream &java)

## Static Private Member Functions
static bool | compareJavaMethod (UMLOperation *op1, UMLOperation *op2)
static bool | javaMethodInList (UMLOperation *umlOp, UMLOperationList &opl)

## Private Attributes
QString | m_startline
| a , used at the end of each line
bool | m_isInterface
| whether or not this concept is an interface

## Additional Inherited Members
Public Types inherited from CodeGenerator
enum | GenerationState { Generated , Failed , Skipped }
Public Slots inherited from SimpleCodeGenerator
virtual void | syncCodeToDocument ()
Public Slots inherited from CodeGenerator
virtual void | syncCodeToDocument ()
Signals inherited from CodeGenerator
void | codeGenerated (UMLClassifier *classifier, bool generated)
void | codeGenerated (UMLClassifier *classifier, CodeGenerator::GenerationState result)
void | showGeneratedFile (const QString &filename)
Static Public Member Functions inherited from CodeGenerator
static QString | cleanName (const QString &name)
static QString | formatDoc (const QString &text, const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80)
static QString | formatFullDocBlock (const QString &text, const QString &blockHeader=QStringLiteral("/* "), const QString &blockFooter=QStringLiteral(" */"), const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80)
static QString | formatSourceCode (const QString &code, const QString &indentation)
static void | findObjectsRelated (UMLClassifier *c, UMLPackageList &cList)
Protected Member Functions inherited from SimpleCodeGenerator
QString | findFileName (UMLPackage *classifier, const QString &ext)
QString | overwritableName (UMLPackage *classifier, const QString &name, const QString &ext)
bool | hasDefaultValueAttr (UMLClassifier *c)
bool | hasAbstractOps (UMLClassifier *c)
QString | indent ()
virtual void | initFromParentDocument ()
Protected Member Functions inherited from CodeGenerator
QString | overwritableName (const QString &name, const QString &extension)
bool | openFile (QFile &file, const QString &name)
void | writeListedCodeDocsToFile (CodeDocumentList *docs)
virtual void | finalizeRun ()
Protected Attributes inherited from SimpleCodeGenerator
QString | className_
QString | fileName_
QMap< UMLPackage *, QString > | m_fileMap
bool | m_createDirHierarchyForPackages
QString | m_indentation
int | m_indentLevel
QString | m_endl
Protected Attributes inherited from CodeGenerator
QHash< QString, CodeDocument * > | m_codeDocumentDictionary
bool | m_applyToAllRemaining
UMLDoc * | m_document

## Detailed Description

Class JavaWriter is a code generator for UMLClassifier objects. Create an instance of this class, and feed it a UMLClassifier when calling writeClass and it will generate a java source file for that concept. This is the "old" code generator that does not support code editing in the Modeller but uses significantly less file space because the source code is not replicated in the XMI file.

## Constructor & Destructor Documentation

## ◆ JavaWriter()

JavaWriter::JavaWriter | ( |  | ) |

Constructor, initialises a couple of variables.

## ◆ ~JavaWriter()

JavaWriter::~JavaWriter | ( |  | ) |
| virtual

Destructor, empty.

## Member Function Documentation

## ◆ compareJavaMethod()

bool JavaWriter::compareJavaMethod | ( | UMLOperation * | op1,
|  | UMLOperation * | op2 )
| staticprivate

Return true if the two operations have the same name and the same parameters.

Parameters

  op1 | first operation to be compared
  op2 | second operation to be compared

## ◆ defaultDatatypes()

QStringList JavaWriter::defaultDatatypes | ( |  | ) | const
| virtual

Overrides method from class CodeGenerator.

Returns
  the list of default datatypes

Reimplemented from CodeGenerator.

## ◆ fixInitialStringDeclValue()

QString JavaWriter::fixInitialStringDeclValue | ( | const QString & | val,
|  | const QString & | type )
| private

Check that initial values of strings have quotes around them.

## ◆ fixTypeName()

QString JavaWriter::fixTypeName | ( | const QString & | string | ) |
| private

Replaces `string' with `String' and `bool' with `boolean'. IF the type is "string" we need to declare it as the Java Object "String" (there is no string primitive in Java). Same thing again for "bool" to "boolean".

## ◆ getInterfacesOperationsToBeImplemented()

void JavaWriter::getInterfacesOperationsToBeImplemented | ( | UMLClassifier * | c,
|  | UMLOperationList & | opList )
| private

Get all operations which a given class inherit from all its super interfaces and that should be implemented.

Parameters

  c | the class for which we are generating code
  opList | the list of operations used to append the operations

## ◆ getSuperImplementedOperations()

void JavaWriter::getSuperImplementedOperations | ( | UMLClassifier * | c,
|  | UMLOperationList & | yetImplementedOpList,
|  | UMLOperationList & | toBeImplementedOpList,
|  | bool | noClassInPath = true )
| private

Get all operations which a given class inherit from all its super interfaces and get all operations which this given class inherit from all its super classes.

Parameters

  c | the class for which we are generating code
  yetImplementedOpList | the list of yet implemented operations
  toBeImplementedOpList | the list of to be implemented operations
  noClassInPath | tells if there is a class between the base class and the current interface

## ◆ getUMLObjectName()

QString JavaWriter::getUMLObjectName | ( | UMLObject * | obj | ) |
| private

Returns the name of the given object (if it exists).

## ◆ javaMethodInList()

bool JavaWriter::javaMethodInList | ( | UMLOperation * | umlOp,
|  | UMLOperationList & | opl )
| staticprivate

Return true if the operation is in the list.

Parameters

  umlOp | operation to be searched
  opl | list of operations

## ◆ language()

Uml::ProgrammingLanguage::Enum JavaWriter::language | ( |  | ) | const
| virtual

Returns "Java".

Returns
  the programming language identifier

Implements CodeGenerator.

## ◆ writeAssociationDecls()

void JavaWriter::writeAssociationDecls | ( | UMLAssociationList | associations,
|  | Uml::ID::Type | id,
|  | QTextStream & | java )
| private

Searches a list of associations for appropriate ones to write out as attributes.

## ◆ writeAssociationMethods()

void JavaWriter::writeAssociationMethods | ( | UMLAssociationList | associations,
|  | UMLClassifier * | thisClass,
|  | QTextStream & | java )
| private

Calls writeAssociationRoleMethod() on each of the associations in the given list.

## ◆ writeAssociationRoleDecl()

void JavaWriter::writeAssociationRoleDecl | ( | QString | fieldClassName,
|  | QString | roleName,
|  | QString | multi,
|  | QString | doc,
|  | Uml::Visibility::Enum | visib,
|  | QTextStream & | java )
| private

Writes out an association as an attribute using Vector.

## ◆ writeAssociationRoleMethod()

void JavaWriter::writeAssociationRoleMethod | ( | QString | fieldClassName,
|  | QString | roleName,
|  | QString | multi,
|  | QString | description,
|  | Uml::Visibility::Enum | visib,
|  | Uml::Changeability::Enum | change,
|  | QTextStream & | java )
| private

Calls writeSingleAttributeAccessorMethods() or writeVectorAttributeAccessorMethods() on the association role.

## ◆ writeAttributeDecls()

void JavaWriter::writeAttributeDecls | ( | UMLAttributeList & | atpub,
|  | UMLAttributeList & | atprot,
|  | UMLAttributeList & | atpriv,
|  | QTextStream & | java )
| private

Writes the Attribute declarations.

Parameters

  atpub | list of public attributes
  atprot | list of protected attributes
  atpriv | list of private attributes
  java | text stream

## ◆ writeAttributeMethods()

void JavaWriter::writeAttributeMethods | ( | UMLAttributeList & | atpub,
|  | Uml::Visibility::Enum | visibility,
|  | QTextStream & | java )
| private

Calls writeSingleAttributeAccessorMethods() on each of the attributes in atpub.

## ◆ writeBlankLine()

void JavaWriter::writeBlankLine | ( | QTextStream & | java | ) |
| private

Write a blank line. Note: Methods like this _shouldn't_ be needed IF we properly did things thruought the code.

## ◆ writeClass()

void JavaWriter::writeClass | ( | UMLClassifier * | c | ) |
| virtual

Call this method to generate java code for a UMLClassifier.

Parameters

  c | the class to generate code for

Implements SimpleCodeGenerator.

## ◆ writeClassDecl()

void JavaWriter::writeClassDecl | ( | UMLClassifier * | c,
|  | QTextStream & | java )
| private

Writes class's documentation then the class header "public abstract class Foo extents {".

## ◆ writeComment()

void JavaWriter::writeComment | ( | const QString & | comment,
|  | const QString & | myIndent,
|  | QTextStream & | java,
|  | bool | javaDocStyle = false )
| private

Writes a // style comment.

## ◆ writeConstructor()

void JavaWriter::writeConstructor | ( | UMLClassifier * | c,
|  | QTextStream & | java )
| private

Writes the comment and class constructor.

## ◆ writeDocumentation()

void JavaWriter::writeDocumentation | ( | QString | header,
|  | QString | body,
|  | QString | end,
|  | QString | indent,
|  | QTextStream & | java )
| private

Writes a documentation comment.

## ◆ writeOperations() [1/2]

void JavaWriter::writeOperations | ( | UMLClassifier * | c,
|  | QTextStream & | java )
| private

Write all operations for a given class.

Parameters

  c | the class for which we are generating code
  java | the stream associated with the output file

## ◆ writeOperations() [2/2]

void JavaWriter::writeOperations | ( | UMLOperationList & | oplist,
|  | QTextStream & | java )
| private

Write a list of operations for a given class.

Parameters

  oplist | the list of operations you want to write
  java | the stream associated with the output file

## ◆ writeSingleAttributeAccessorMethods()

void JavaWriter::writeSingleAttributeAccessorMethods | ( | QString | fieldClassName,
|  | QString | fieldVarName,
|  | QString | fieldName,
|  | QString | description,
|  | Uml::Visibility::Enum | visibility,
|  | Uml::Changeability::Enum | change,
|  | bool | isFinal,
|  | QTextStream & | java )
| private

Writes getFoo() and setFoo() accessor methods for the attribute.

## ◆ writeVectorAttributeAccessorMethods()

void JavaWriter::writeVectorAttributeAccessorMethods | ( | QString | fieldClassName,
|  | QString | fieldVarName,
|  | QString | fieldName,
|  | QString | description,
|  | Uml::Visibility::Enum | visibility,
|  | Uml::Changeability::Enum | changeType,
|  | QTextStream & | java )
| private

Writes addFoo() and removeFoo() accessor methods for the Vector attribute.

## Member Data Documentation

## ◆ m_isInterface

bool JavaWriter::m_isInterface
| private

whether or not this concept is an interface

## ◆ m_startline

QString JavaWriter::m_startline
| private

a
, used at the end of each line

The documentation for this class was generated from the following files:

- umbrello/codegenerators/java/javawriter.h
- umbrello/codegenerators/java/javawriter.cpp