Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Java Code Generation"

m (Change generation preferences)
(Change project name for generation)
Line 35: Line 35:
 
[[File:JavaCodegenPrefs.png]]
 
[[File:JavaCodegenPrefs.png]]
  
== Change project name for generation ==
+
== Java profile and library ==
  
=== By Using Stereotype ===
+
The installed Java feature, of Papyrus Software Designer, comes with a Java profile and a Java library. Furthermore, it also installs a generic code generation profile for meta-information (e.g. project name modeling).
By default, the generator use the name of the model as Java project name for generation. To change the default project name, you can use the profiles system.
+
First, add the java profile to your model:
+
  
*click on your model (on the Model Explorer view),
+
=== Java profile ===
*in the Properties view, choose the Profile tab,
+
The Java profile adds stereotypes to model specific Java elements that otherwise cannot be modeled in UML. The stereotypes can be seen as tags to put on UML elements. To apply the Java profile:
*click on Apply registered profile,
+
 
 +
* Click on your model (in the Model Explorer view)
 +
* In the Properties view, choose the Profile tab
 +
* Click on Apply registered profile:
 
[[File:applyRegisteredProfile.jpg]]
 
[[File:applyRegisteredProfile.jpg]]
*into the opened pop-up, choose Java
+
* In the dialog that opens, choose the Java profile:
 
[[File:javaRegisteredProfile.jpg]]
 
[[File:javaRegisteredProfile.jpg]]
  
You now can change the default project name by adding a profile into your model
+
=== Java library ===
 +
The Java library provides Java primitives and their wrapper classes. To import, this library:
  
*on Properties View, Profile tab, click on Apply stereotypes,
+
* Right click on your model (in the Model Explorer view)
*on the opened pop-up choose JavaSrcFolder, and add it into Applied Stereotypes, and close the pop-up by clicking on Ok button.
+
* Import > Import Registered Package
[[File:JavaSrcFolder.jpg]]
+
[[File:importPackage.png]]
*you now can change the project name into the JavaSrcFolder stereotype
+
* Choose the JavaLibrary package
[[File:changeProjectName.jpg]]
+
[[File:javaLibrary.png]]
  
 +
=== Common code generation profile ===
 +
Papyrus Software Designer also offers a common code generation profile, that can be used for Java code generation. This profile lets the user model meta-information, e.g. path where code is generated.
  
=== From Eclipse Preferences ===
+
To use this feature, first the Papyrus code generation profile must be applied:
Papyrus provides eclipse preferences to change the default source folder name. This preferences  value is used for all generation, if nothing is provided by a stereotype:
+
[[File:codeGenerationProfile.png]]
*Open Eclipse preferences,
+
*Search for ''Papyrus'' section,
+
*Choose ''Java Classes Generation'' sub-section,
+
*Change ''default source folder name value''
+
  
[[Image:JavaCodeGenerationEclipsePreferencesDefaultSourceFolderName.png]]
+
Then you can apply the <<Project>> stereotype to your model (root element). This stereotype lets you
 +
* Generation mode: either batch or incremental
 +
* Name of the JDT project (can be an existing one in the workspace)
 +
* Source folder
 +
* Prefix for all packages
 +
[[File:swDesignerProjectStereotype.png]]
  
 
[[Category:Modeling]]
 
[[Category:Modeling]]
 
[[Category:Papyrus]]
 
[[Category:Papyrus]]
[[Category:Papyrus-Designer]]
+
[[Category:Papyrus-Software-Designer]]

Revision as of 09:55, 19 October 2016

The Java code generation is available in the extra plugins of Papyrus. It can be used by installing the latest version of Papyrus. It allows to create Java source code from a class diagram.

Installation instructions

The Java features of Papyrus are available as part of the Papyrus Software Designer extra feature.

You can install it by using the Papyrus Software Designer update-site:

Or you can use the nightly build update site (paste following url in eclipse update site):

Then select "Papyrus Java profile, library and code generation (Incubation)" feature. You need JDT installed (which comes with most Eclipse packages).

InstallSWDesignerJavaFeature.png

Code generation from UML elements

You can generate code for a specific classifier or package in your UML model. To generate code, do the following:

  • Right click on classifier or package, either in a diagram or in the model explorer
  • Designer > Generate Java code
  • Follow the JDT dialogs that let you create a new JDT project in Eclipse, where code will be generated, if there is no JDT project associated with your model (e.g. the first time you generate code from your model)

When you generate code from a classifier, its required classifiers are also generated. Required classifiers are classifiers related for the generated classifier, e.g. typing one of its attributes, inheritance relationship, dependency relationship. When you generate code from a package (e.g. the root of your model), all of its classifiers, and their required classifiers, will be generated.

GenerateJavaCode.jpg

Change generation preferences

You can change the Java code generation preferences using the Eclipse preferences menu, and choose Papyrus > Java code generation. Available options are:

  • Extension for Java files
  • Prefix for name of created JDT project (if unspecified in the model, see below)
  • Header for generated files

JavaCodegenPrefs.png

Java profile and library

The installed Java feature, of Papyrus Software Designer, comes with a Java profile and a Java library. Furthermore, it also installs a generic code generation profile for meta-information (e.g. project name modeling).

Java profile

The Java profile adds stereotypes to model specific Java elements that otherwise cannot be modeled in UML. The stereotypes can be seen as tags to put on UML elements. To apply the Java profile:

  • Click on your model (in the Model Explorer view)
  • In the Properties view, choose the Profile tab
  • Click on Apply registered profile:

ApplyRegisteredProfile.jpg

  • In the dialog that opens, choose the Java profile:

JavaRegisteredProfile.jpg

Java library

The Java library provides Java primitives and their wrapper classes. To import, this library:

  • Right click on your model (in the Model Explorer view)
  • Import > Import Registered Package

ImportPackage.png

  • Choose the JavaLibrary package

JavaLibrary.png

Common code generation profile

Papyrus Software Designer also offers a common code generation profile, that can be used for Java code generation. This profile lets the user model meta-information, e.g. path where code is generated.

To use this feature, first the Papyrus code generation profile must be applied: CodeGenerationProfile.png

Then you can apply the <<Project>> stereotype to your model (root element). This stereotype lets you

  • Generation mode: either batch or incremental
  • Name of the JDT project (can be an existing one in the workspace)
  • Source folder
  • Prefix for all packages

SwDesignerProjectStereotype.png

Copyright © Eclipse Foundation, Inc. All Rights Reserved.