1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.notation.providers.java; |
40 | |
|
41 | |
import java.util.ArrayList; |
42 | |
import java.util.Collection; |
43 | |
import java.util.Iterator; |
44 | |
import java.util.List; |
45 | |
|
46 | |
import org.apache.log4j.Logger; |
47 | |
import org.argouml.application.events.ArgoEventPump; |
48 | |
import org.argouml.application.events.ArgoEventTypes; |
49 | |
import org.argouml.application.events.ArgoHelpEvent; |
50 | |
import org.argouml.model.Model; |
51 | |
import org.argouml.notation.NotationSettings; |
52 | |
import org.argouml.notation.providers.OperationNotation; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public class OperationNotationJava extends OperationNotation { |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | private static final Logger LOG = |
65 | |
Logger.getLogger(OperationNotationJava.class); |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public OperationNotationJava(Object operation) { |
73 | 0 | super(operation); |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public void parse(Object modelElement, String text) { |
80 | 0 | ArgoEventPump.fireEvent(new ArgoHelpEvent( |
81 | |
ArgoEventTypes.HELP_CHANGED, this, |
82 | |
"Parsing in Java not yet supported")); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public String getParsingHelp() { |
89 | 0 | return "Parsing in Java not yet supported"; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public String toString(Object modelElement, NotationSettings settings) { |
94 | 0 | return toString(modelElement); |
95 | |
} |
96 | |
|
97 | |
private String toString(Object modelElement) { |
98 | 0 | StringBuffer sb = new StringBuffer(80); |
99 | 0 | String nameStr = null; |
100 | 0 | boolean constructor = false; |
101 | |
|
102 | 0 | Iterator its = |
103 | |
Model.getFacade().getStereotypes(modelElement).iterator(); |
104 | 0 | String name = ""; |
105 | 0 | while (its.hasNext()) { |
106 | 0 | Object o = its.next(); |
107 | 0 | name = Model.getFacade().getName(o); |
108 | 0 | if ("create".equals(name)) { |
109 | 0 | break; |
110 | |
} |
111 | 0 | } |
112 | 0 | if ("create".equals(name)) { |
113 | |
|
114 | 0 | nameStr = Model.getFacade().getName( |
115 | |
Model.getFacade().getOwner(modelElement)); |
116 | 0 | constructor = true; |
117 | |
} else { |
118 | 0 | nameStr = Model.getFacade().getName(modelElement); |
119 | |
} |
120 | |
|
121 | 0 | boolean isReception = Model.getFacade().isAReception(modelElement); |
122 | |
|
123 | 0 | if (! isReception) { |
124 | 0 | sb.append(generateConcurrency(modelElement)); |
125 | |
} |
126 | 0 | sb.append(generateAbstractness(modelElement)); |
127 | 0 | sb.append(NotationUtilityJava.generateChangeability(modelElement)); |
128 | 0 | sb.append(NotationUtilityJava.generateScope(modelElement)); |
129 | 0 | sb.append(NotationUtilityJava.generateVisibility(modelElement)); |
130 | |
|
131 | |
|
132 | 0 | Collection returnParams = |
133 | |
Model.getCoreHelper().getReturnParameters(modelElement); |
134 | |
Object rp; |
135 | 0 | if (returnParams.size() == 0) { |
136 | 0 | rp = null; |
137 | |
} else { |
138 | 0 | rp = returnParams.iterator().next(); |
139 | |
} |
140 | 0 | if (returnParams.size() > 1) { |
141 | 0 | LOG.warn("Java generator only handles one return parameter" |
142 | |
+ " - Found " + returnParams.size() |
143 | |
+ " for " + Model.getFacade().getName(modelElement)); |
144 | |
} |
145 | 0 | if (rp != null && !constructor) { |
146 | 0 | Object returnType = Model.getFacade().getType(rp); |
147 | 0 | if (returnType == null) { |
148 | 0 | sb.append("void "); |
149 | |
} else { |
150 | 0 | sb.append(NotationUtilityJava.generateClassifierRef(returnType)) |
151 | |
.append(' '); |
152 | |
} |
153 | |
} |
154 | |
|
155 | |
|
156 | 0 | List params = new ArrayList( |
157 | |
Model.getFacade().getParameters(modelElement)); |
158 | 0 | params.remove(rp); |
159 | |
|
160 | 0 | sb.append(nameStr).append('('); |
161 | |
|
162 | 0 | if (params != null) { |
163 | 0 | for (int i = 0; i < params.size(); i++) { |
164 | 0 | if (i > 0) { |
165 | 0 | sb.append(", "); |
166 | |
} |
167 | 0 | sb.append(NotationUtilityJava.generateParameter( |
168 | |
params.get(i))); |
169 | |
} |
170 | |
} |
171 | |
|
172 | 0 | sb.append(')'); |
173 | |
|
174 | 0 | Collection c = Model.getFacade().getRaisedSignals(modelElement); |
175 | 0 | if (!c.isEmpty()) { |
176 | 0 | Iterator it = c.iterator(); |
177 | 0 | boolean first = true; |
178 | 0 | while (it.hasNext()) { |
179 | 0 | Object signal = it.next(); |
180 | |
|
181 | 0 | if (!Model.getFacade().isAException(signal)) { |
182 | 0 | continue; |
183 | |
} |
184 | |
|
185 | 0 | if (first) { |
186 | 0 | sb.append(" throws "); |
187 | |
} else { |
188 | 0 | sb.append(", "); |
189 | |
} |
190 | |
|
191 | 0 | sb.append(Model.getFacade().getName(signal)); |
192 | 0 | first = false; |
193 | 0 | } |
194 | |
} |
195 | |
|
196 | 0 | return sb.toString(); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
private static String generateConcurrency(Object op) { |
206 | 0 | if (Model.getFacade().getConcurrency(op) != null |
207 | |
&& Model.getConcurrencyKind().getGuarded().equals( |
208 | |
Model.getFacade().getConcurrency(op))) { |
209 | 0 | return "synchronized "; |
210 | |
} |
211 | 0 | return ""; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
private static String generateAbstractness(Object op) { |
221 | 0 | if (Model.getFacade().isAbstract(op)) { |
222 | 0 | return "abstract "; |
223 | |
} |
224 | 0 | return ""; |
225 | |
} |
226 | |
} |