The YAKINDU EA-Bridge contains an example feature that can optionally be installed. It provides several example projects to demonstrate the core functionality and two example scenarios how the YAKINDU EA-Bridge can be used.
Please note that the example feature installs Xtend because it is used for code generation in the examples.
Once installed, the examples are available via the examples wizard: File - New - Example... - YAKINDU EA-Bridge Examples.
The New YAKINDU EA-Bridge Example Project wizard creates a new simple project in your workspace called YAKINDU EA-Bridge Example Project which contains the following files:
The main purpose of this example project is to provide a model and illustrate some of the features of the YAKINDU EA-Bridge:
Disclaimer: The YAKINDU EA-Bridge provides an extensive API to load, access, and partially also to modify EA models. This example is only one (very simplified) demonstration to generate some code from EA models that are loaded with the YAKINDU EA-Bridge. This example does neither have proper error handling, nor does scale in size and performance! If you want to create a proper code generator, you should rather access the resource from your own plugins or in a JUnit Plugin test.
The New YAKINDU EA-Bridge Live Codegen Example Project wizard creates a new plugin project in your workspace called YAKINDU EA-Bridge Live Codegen Example which contains the following files, amongst others:
The main purpose of this project is to illustrate the easy access of EA-models for generating code:
The templates make use of two annotations which demonstrate how code can be generated:
@EACodegen(<file-extension>) public String <method name>(<UML type> <parameter name>)
All operations annotated with @EACodegen
are called for all model elements of the parameter's type, triggered by an Eclipse builder provided with the YAKINDU EA-Bridge example plugin.
<UML type> must be a subtype of PackageableElement
and it must have a name (because it is used as target file name)!
You can either use plain Java for your code generation logic, or you can use Xtend - which provides so-called template expressions to generate Strings:
@EACodegen("java") def generate(Class c) ''' ... '''
This example collects all UML elements of type Class within eap-files of the enclosing project and stores the result in files that are named like the UML classes with the extension java.
By default, the generated files are saved inside the same project in a sub-folder called src-gen.
In many cases, it is desirable to use a different target location for the generated files, e.g. another Java project.
The optional annotation @EACodegenFile
can be used to change the target location of generated files within a template:
@EACodegenFile public IFile <method name>(<UML type> <parameter name>, IFile <parameter name>)
The example below takes the original path from the enclosing project and replaces the project name with another one.
@EACodegenFile public IFile mapGeneratedFilePath(PackageableElement element, IFile genFile) { String exampleProjectPath = genFile.getFullPath().toString(); String javaProjectPath = exampleProjectPath.replace(genFile.getProject().getName(), "LibraryInJava"); return (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(javaProjectPath); }
Disclaimer: The YAKINDU EA-Bridge provides an extensive API to load, access, and partially also to modify EA models. This example is only one (very simplified) demonstration to check constraints on EA models that are loaded with the YAKINDU EA-Bridge. This example does neither have proper error handling, nor does scale in size and performance! If you want proper model validation, you should rather access the resource from your own plugins.
The New YAKINDU EA-Bridge Live Validation Project wizard creates a new project in your workspace called YAKINDU EA-Bridge Live Validation Example which contains the following files:
The main purpose of this example project is to illustrate model validation capabilities enabled by the YAKINDU EA-Bridge:
The syntax of the annotation @EAValidation
which defines the validation methods is defined as follows.
@EAValidation(severity = <severity>) public String <method name>(<UML type> <parameter name>)
All operations annotated like this are called for all model elements of the parameter's type, triggered by an Eclipse builder provided with the YAKINDU EA-Bridge example plugin.
The return value is the error message, or null
if the model element is valid.
Please see the example below:
@EAValidation(severity = Severity.warning) public String validateAttributeTypes(Element element) { if (element instanceof Property) { if (((Property) element).getType() == null) { // return message will be the validation message shown in Problems view return String.format("Attribute '%s' is missing a type!", ((NamedElement) element).getName()); } } return null; // return null if there is no violation }
The builder collects all eap-files in the enclosing project and calls operation validateAttribuetTypes
for all model elements.
If the model element is of UML type Property
and its type is not set, a validation message is returned that will be reported as a warning on that model element.
It would be nice if the parameter type could be used to filter the model elements already (as it is the case for the code generation annotations below), but this is technically not possible.
The EMF validation framework is used to collect the elements and to promote the validation results, and to cover all possible UML types, the highest common UML supertype Element
is used.
The New YAKINDU EA-Bridge Example Plugin Project wizard creates a new plugin project in your workspace called com.yakindu.ea.examples.plugin which contains the following files, amongst others:
This plugin could be the starting point if you intend to process your EA models in a professional way. Please consult the Eclipse Help to learn how to develop and deploy your own Eclipse plugins.
The New YAKINDU EA-Bridge Test Plugin Project wizard creates a new JUnit test plugin project in your workspace called com.yakindu.ea.examples.tests which contains the following files, amongst others:
plugin.xml
.plugin.xml
.To run the tests, launch class LoadAndSaveModelTest
as JUnit Plug-in Test:
Run - Run Configurations... - select LoadAndSaveModelTest - press Run.
This project can be used as starting point for your own tests.
The New YAKINDU EA-Bridge Variants Codegen Example Project wizard creates a set of new projects to demonstrate how different variants can be generated from the same model:
(Please note that the hbase-plugins are only enabled if you did not skip the JDK selection option because HBase requires a library that cannot be downloaded by maven.)
To generate the sources, the Eclipse auto-build should be enabled. However, you can also trigger the build manually via Project - Build Project or Build All.
If some the hbase- or jpa-projects still have errors, you could try to re-run maven on them: right click a project - Maven - Update Project... - Select All - OK.
Please see com.yakindu.ea.examples.orderingsoftware.template/readme.txt for more details about the project. This project can be used as starting point for your own code generator.