1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
2 | |
3 | import java.util.Iterator; |
4 | |
5 | import org.eclipse.emf.common.util.EList; |
6 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
7 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
8 | |
9 | import de.uka.ipd.sdq.pcm.repository.DataType; |
10 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
11 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
12 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
13 | |
14 | /** |
15 | * Responsibly for representation different Signature property (ReturnType, |
16 | * Parameters, Exceptions), as string |
17 | * |
18 | * @author Roman Andrej |
19 | */ |
20 | public class ParameterRepresentation { |
21 | |
22 | /** |
23 | * Represents DataType in accordance with Palladio styles |
24 | */ |
25 | public static String dataTypeToString(DataType returnType) { |
26 | |
27 | String result = ""; |
28 | |
29 | ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(); |
30 | adapterFactory |
31 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
32 | |
33 | PalladioItemProviderAdapterFactory decoratedFactory = new PalladioItemProviderAdapterFactory( |
34 | adapterFactory); |
35 | |
36 | if (returnType != null) { |
37 | IItemLabelProvider datatypeProvider = (IItemLabelProvider) decoratedFactory |
38 | .adapt((Object) returnType, IItemLabelProvider.class); |
39 | result = datatypeProvider.getText(returnType); |
40 | } |
41 | |
42 | return result; |
43 | } |
44 | |
45 | /** |
46 | * The method create the string list of parameter (parameter1, parameter2, ...) |
47 | */ |
48 | public static String parametersToString(EList<Parameter> parameters) { |
49 | String result = ""; |
50 | |
51 | for (Iterator<Parameter> it = parameters.iterator(); it.hasNext();) { |
52 | result += it.next().getParameterName() + ", "; |
53 | } |
54 | return deleteComma(result); |
55 | } |
56 | |
57 | /** |
58 | * Comma of the sentence deletes ends |
59 | */ |
60 | private static String deleteComma(String result) { |
61 | if (!result.equals("")) { |
62 | result = result.substring(0, result.length() - 2); |
63 | } |
64 | return result; |
65 | } |
66 | } |