Projet

Général

Profil

MAY Best Practices » Historique » Version 15

Anonyme, 06/10/2014 13:47

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