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 (Geoffroy.jonathan.gmail.com moved page Java code eneration to Java Code Generation)
Line 2: Line 2:
  
 
== Generate a class source from a class diagram. ==
 
== Generate a class source from a class diagram. ==
 
 
Open a class diagram, and choose a UML class by clicking on it.   
 
Open a class diagram, and choose a UML class by clicking on it.   
 
Right clicking, and choose Java -> Generate Java code.   
 
Right clicking, and choose Java -> Generate Java code.   
Line 9: Line 8:
 
Moreover, the generation process also create all needed classes, like associations or fields.
 
Moreover, the generation process also create all needed classes, like associations or fields.
  
[[File:GenerateJavaCode.jpg]]
+
[[Image:GenerateJavaCode.jpg]]
  
 
== Change generation preferences ==
 
== Change generation preferences ==
 
 
You can change the generation preferences using the eclipse preferences menu, and choose Papyrus -> Java classes Generation.
 
You can change the generation preferences using the eclipse preferences menu, and choose Papyrus -> Java classes Generation.
 
Available options are:
 
Available options are:
  
 
*stop generation on first error (enabled by default),     
 
*stop generation on first error (enabled by default),     
*implement methods of inheres interfaces and abstractt class (enabled by default),     
+
*implement methods of inheres interfaces and abstract class (enabled by default),     
 
*generate getters & setters (enabled by default),   
 
*generate getters & setters (enabled by default),   
 
*manage packages to not include into generation,     
 
*manage packages to not include into generation,     
Line 24: Line 22:
 
== Change project name for generation ==
 
== Change project name for generation ==
  
 +
=== By Using Stereotype ===
 
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.   
 
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:
 
First, add the java profile to your model:
Line 41: Line 40:
 
*you now can change the project name into the JavaSrcFolder stereotype
 
*you now can change the project name into the JavaSrcFolder stereotype
 
[[File:changeProjectName.jpg]]
 
[[File:changeProjectName.jpg]]
 +
 +
 +
=== From Eclipse Preferences ===
 +
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:
 +
*Open Eclipse preferences,
 +
*Search for ''Papyrus'' section,
 +
*Choose ''Java Classes Generation'' sub-section,
 +
*Change ''default source folder name value''
 +
 +
[[Image:JavaCodeGenerationEclipsePreferencesDefaultSourceFolderName.png]]

Revision as of 05:34, 6 August 2014

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.

Generate a class source from a class diagram.

Open a class diagram, and choose a UML class by clicking on it. Right clicking, and choose Java -> Generate Java code. A Java class while be created on a project, which has the same name that you model. Note that you can also generate java code source for multiple classes, or generate packages. Moreover, the generation process also create all needed classes, like associations or fields.

GenerateJavaCode.jpg

Change generation preferences

You can change the generation preferences using the eclipse preferences menu, and choose Papyrus -> Java classes Generation. Available options are:

  • stop generation on first error (enabled by default),
  • implement methods of inheres interfaces and abstract class (enabled by default),
  • generate getters & setters (enabled by default),
  • manage packages to not include into generation,
  • choose the generic classe to use for association (java.util.List by default).

Change project name for generation

By Using Stereotype

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),
  • in the Properties view, choose the Profile tab,
  • click on Apply registered profile,

ApplyRegisteredProfile.jpg

  • into the opened pop-up, choose Java

JavaRegisteredProfile.jpg

You now can change the default project name by adding a profile into your model

  • on Properties View, Profile tab, click on Apply stereotypes,
  • on the opened pop-up choose JavaSrcFolder, and add it into Applied Stereotypes, and close the pop-up by clicking on Ok button.

JavaSrcFolder.jpg

  • you now can change the project name into the JavaSrcFolder stereotype

ChangeProjectName.jpg


From Eclipse Preferences

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:

  • Open Eclipse preferences,
  • Search for Papyrus section,
  • Choose Java Classes Generation sub-section,
  • Change default source folder name value

JavaCodeGenerationEclipsePreferencesDefaultSourceFolderName.png

Back to the top