Projet

Général

Profil

MAY Best Practices » Historique » Version 5

Anonyme, 06/10/2014 13:38

1 1 Anonyme
h1. SpeADL Best Practices
2
3 2 Anonyme
h2. Typical Workflow
4 1 Anonyme
5 2 Anonyme
In the Java project, sources (Java and SpeADL) edited by the developer are in the src folder (or equivalent), and the generated Java code is in the speadl-gen folder.
6
The speadl-gen folder is not meant to be touched by hand.
7 1 Anonyme
8 2 Anonyme
Each modification of a SpeADL file is followed by the generation of its equivalent Java class.
9
10
A typical workflow for creating a component is as follow:
11
* Creation of a SpeADL file (see: [[SpeADL MAY Project SetUp]]).
12
* Description of a component.
13
* Creation of the interfaces needed by the component description.
14
* Creation of the implementation of the component extending the corresponding class.
15
* And so on...
16
17
h2. Important Artefacts for a Module
18
19
On top of component declarations, interfaces and component implementation, it is relevant to define sometimes datatypes used in the interface or as type parameters of the components used.
20
21
A software component, its declaration, its implementation and classes it relies on form altogether what is called a module.
22
23
When creating interfaces or datatypes for one or several components, it is important to ask oneself to which module (i.e., with a given component) these declarations should belong to and why.
24
25
h2. Project Organisation
26
27
For simple project, a good organisation of the src directory is as follow:
28
* Package my.project
29
** SpeADL file *myproject.speadl* with a single namespace *my.project*.
30
** Package *interfaces* containing the interfaces declarations
31
** Package *impl* containing the implementations
32
** Package *datatypes* containing extra classes needed to store data
33
** Package *exception* containing exceptions needed in the interfaces
34
35
In this case, all the modules are intermixed together.
36
37
For a more complex project, a good organisation of the src directory is as follow:
38
* Package my.project
39
** Package aComponent
40
*** SpeADL file *aComponent.speadl*
41
*** Package *interfaces* containing the interfaces declarations
42
*** Package *impl* containing the implementations
43
*** Package *datatypes* containing extra classes needed to store data
44
*** Package *exception* containing exceptions needed in the interfaces
45
** Package anotherComponent
46
*** ...
47
48
In this case each module has its own package.
49
50
h2. Exploiting the Eclipse Editor
51
52
h3. Errors
53
54
When creating a Java file to implement a component, one has to extend the Java class generated from the component declaration.
55
56 4 Anonyme
Errors are shown in the Java editor, and the Quick Fix *Add unimplemented methods* proposed by Eclipse will generate automatically the skeleton for the Java file.
57 2 Anonyme
58
From that:
59
<pre>
60
public class MySimpleComponentImpl extends MySimpleComponent {
61
}
62
</pre>
63
64
We get that:
65
<pre>
66
public class MySimpleComponentImpl extends MySimpleComponent {
67
	@Override
68
	protected AnotherJavaInterface make_p1() {
69
		// TODO Auto-generated method stub
70
		return null;
71
	}
72
}
73
</pre>
74
75
This gives the possibility to very quickly approach the implementation of a component.
76
77
h3. Completion
78
79
When implementing the *make_XXX()* method of a provided port, one can exploit completion to gain a lot of time.
80
For example in the following situation (just after using the Quick Fix):
81
<pre>
82
class MySimpleComponentImpl extends MySimpleComponent {
83
	@Override
84
	protected AnotherJavaInterface make_p1() {
85
		// TODO Auto-generated method stub
86
		return null;
87
	}
88
}
89
</pre>
90
91 5 Anonyme
Remove the _null_ after the return statement and replace it with _new AnotherJavaInterface_ and use completion (*Ctrl+Space*) by selecting *AnotherJavaInterface() Anonymous Inner Type* to generate the anonymous type declaration as well as the skeleton to implement its methods.