Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NotationUtilityJava |
|
| 5.7272727272727275;5.727 |
1 | /* $Id: NotationUtilityJava.java 17827 2010-01-12 18:52:31Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2006-2009 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.notation.providers.java; | |
40 | ||
41 | import java.util.Map; | |
42 | import java.util.Stack; | |
43 | ||
44 | import org.argouml.model.Model; | |
45 | import org.argouml.notation.NotationProvider; | |
46 | ||
47 | /** | |
48 | * This class is a utility for the Java notation. | |
49 | * | |
50 | * @author michiel | |
51 | */ | |
52 | public class NotationUtilityJava { | |
53 | ||
54 | /** | |
55 | * The constructor - nothing to construct. | |
56 | */ | |
57 | 0 | NotationUtilityJava() { |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Returns a visibility String either for a VisibilityKind, but also | |
62 | * for a model element, | |
63 | * because if it is a Feature, then the tag 'src_visibility' is to be | |
64 | * taken into account for generating language dependent visibilities. | |
65 | * | |
66 | * @param o the object which may be a VisibilityKind or a ModelElelement | |
67 | * @return the generated visibility string | |
68 | */ | |
69 | static String generateVisibility(Object o) { | |
70 | 0 | if (Model.getFacade().isAFeature(o)) { |
71 | // TODO: The src_visibility tag doesn't appear to be created | |
72 | // anywhere by ArgoUML currently | |
73 | 0 | Object tv = Model.getFacade().getTaggedValue(o, "src_visibility"); |
74 | 0 | if (tv != null) { |
75 | 0 | Object tvValue = Model.getFacade().getValue(tv); |
76 | /* Not all taggedvalues are string - see issue 4322: */ | |
77 | 0 | if (tvValue instanceof String) { |
78 | 0 | String tagged = (String) tvValue; |
79 | 0 | if (tagged != null) { |
80 | 0 | if (tagged.trim().equals("") |
81 | || tagged.trim().toLowerCase().equals("package") | |
82 | || tagged.trim().toLowerCase().equals("default")) { | |
83 | 0 | return ""; |
84 | } | |
85 | 0 | return tagged + " "; |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
90 | 0 | if (Model.getFacade().isAModelElement(o)) { |
91 | 0 | if (Model.getFacade().isPublic(o)) { |
92 | 0 | return "public "; |
93 | } | |
94 | 0 | if (Model.getFacade().isPrivate(o)) { |
95 | 0 | return "private "; |
96 | } | |
97 | 0 | if (Model.getFacade().isProtected(o)) { |
98 | 0 | return "protected "; |
99 | } | |
100 | 0 | if (Model.getFacade().isPackage(o)) { |
101 | 0 | return ""; |
102 | } | |
103 | } | |
104 | 0 | if (Model.getFacade().isAVisibilityKind(o)) { |
105 | 0 | if (Model.getVisibilityKind().getPublic().equals(o)) { |
106 | 0 | return "public "; |
107 | } | |
108 | 0 | if (Model.getVisibilityKind().getPrivate().equals(o)) { |
109 | 0 | return "private "; |
110 | } | |
111 | 0 | if (Model.getVisibilityKind().getProtected().equals(o)) { |
112 | 0 | return "protected "; |
113 | } | |
114 | 0 | if (Model.getVisibilityKind().getPackage().equals(o)) { |
115 | 0 | return ""; |
116 | } | |
117 | } | |
118 | 0 | return ""; |
119 | } | |
120 | ||
121 | static String generateScope(Object f) { | |
122 | 0 | if (Model.getFacade().isStatic(f)) { |
123 | 0 | return "static "; |
124 | } | |
125 | 0 | return ""; |
126 | } | |
127 | ||
128 | /** | |
129 | * Generate "final" keyword for final operations or attributes. | |
130 | */ | |
131 | static String generateChangeability(Object obj) { | |
132 | 0 | if (Model.getFacade().isAAttribute(obj)) { |
133 | 0 | if (Model.getFacade().isReadOnly(obj)) { |
134 | 0 | return "final "; |
135 | } | |
136 | } else { | |
137 | 0 | if (Model.getFacade().isAOperation(obj)) { |
138 | 0 | if (Model.getFacade().isLeaf(obj)) { |
139 | 0 | return "final "; |
140 | } | |
141 | } | |
142 | } | |
143 | 0 | return ""; |
144 | } | |
145 | ||
146 | static String generateClassifierRef(Object cls) { | |
147 | 0 | if (cls == null) { |
148 | 0 | return ""; |
149 | } | |
150 | 0 | return Model.getFacade().getName(cls); |
151 | } | |
152 | ||
153 | static String generateExpression(Object expr) { | |
154 | 0 | if (Model.getFacade().isAExpression(expr)) { |
155 | 0 | return generateUninterpreted( |
156 | (String) Model.getFacade().getBody(expr)); | |
157 | 0 | } else if (Model.getFacade().isAConstraint(expr)) { |
158 | 0 | return generateExpression(Model.getFacade().getBody(expr)); |
159 | } | |
160 | 0 | return ""; |
161 | } | |
162 | ||
163 | static String generateUninterpreted(String un) { | |
164 | 0 | if (un == null) { |
165 | 0 | return ""; |
166 | } | |
167 | 0 | return un; |
168 | } | |
169 | ||
170 | static String generateParameter(Object parameter) { | |
171 | 0 | StringBuffer sb = new StringBuffer(20); |
172 | //TODO: qualifiers (e.g., const) | |
173 | //TODO: stereotypes... | |
174 | 0 | sb.append(generateClassifierRef(Model.getFacade().getType(parameter))); |
175 | 0 | sb.append(' '); |
176 | 0 | sb.append(Model.getFacade().getName(parameter)); |
177 | //TODO: initial value | |
178 | 0 | return sb.toString(); |
179 | } | |
180 | ||
181 | /** | |
182 | * @param modelElement the UML element | |
183 | * @param args a set of arguments that may influence | |
184 | * the generated notation | |
185 | * @return a string which represents abstractness | |
186 | */ | |
187 | static String generateAbstract(Object modelElement) { | |
188 | 0 | if (Model.getFacade().isAbstract(modelElement)) { |
189 | 0 | return "abstract "; |
190 | } | |
191 | 0 | return ""; |
192 | } | |
193 | ||
194 | /** | |
195 | * @param modelElement the UML element | |
196 | * @param args a set of arguments that may influence | |
197 | * the generated notation | |
198 | * @return a string which represents leaf | |
199 | */ | |
200 | static String generateLeaf(Object modelElement) { | |
201 | 0 | if (Model.getFacade().isLeaf(modelElement)) { |
202 | 0 | return "final "; |
203 | } | |
204 | 0 | return ""; |
205 | } | |
206 | ||
207 | static String generatePath(Object modelElement) { | |
208 | 0 | StringBuilder s = new StringBuilder(); |
209 | 0 | Stack<String> stack = new Stack<String>(); |
210 | 0 | Object ns = Model.getFacade().getNamespace(modelElement); |
211 | // TODO: Use Model.getModelManagementHelper().getPathList(modelElement); | |
212 | // TODO: This will fail with nested Models | |
213 | 0 | while (ns != null && !Model.getFacade().isAModel(ns)) { |
214 | 0 | stack.push(Model.getFacade().getName(ns)); |
215 | 0 | ns = Model.getFacade().getNamespace(ns); |
216 | } | |
217 | 0 | while (!stack.isEmpty()) { |
218 | 0 | s.append(stack.pop()).append("."); |
219 | } | |
220 | ||
221 | 0 | if (s.length() > 0 && !(s.lastIndexOf(".") == s.length() - 1)) { |
222 | 0 | s.append("."); |
223 | } | |
224 | 0 | return s.toString(); |
225 | } | |
226 | ||
227 | /** | |
228 | * @param modelElement the UML element | |
229 | * @param settings settings which influence the generated notation | |
230 | * @return a string which represents the visibility | |
231 | */ | |
232 | // static String generateVisibility(Object modelElement, | |
233 | // NotationSettings settings) { | |
234 | // String s = ""; | |
235 | // if (settings.isShowVisibility()) { | |
236 | // s = NotationUtilityJava.generateVisibility(modelElement); | |
237 | // } | |
238 | // return s; | |
239 | // } | |
240 | } |