1 | package de.uka.ipd.sdq.pcm.transformations.builder.util; |
2 | |
3 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
4 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
5 | import de.uka.ipd.sdq.pcm.repository.ParameterModifier; |
6 | import de.uka.ipd.sdq.pcm.repository.PrimitiveTypeEnum; |
7 | import de.uka.ipd.sdq.pcm.transformations.BytesizeComputationForSignature.Modifier; |
8 | |
9 | public class NumberOfElementsComputationForSignature { |
10 | |
11 | public static String countAmount( |
12 | OperationSignature currentSignature, |
13 | PrimitiveTypeEnum type, |
14 | Modifier modifier) { |
15 | |
16 | String result = null; |
17 | for (Parameter p : currentSignature.getParameters__OperationSignature()) { |
18 | if (matchesModifier(p,modifier)){ |
19 | String stoex = countForParameter(p, type); |
20 | result = appendStoEx(result, stoex); |
21 | } |
22 | } |
23 | if (currentSignature.getReturnType__OperationSignature() != null && modifier == Modifier.OUT){ |
24 | TypesCountingVisitor visitor = new TypesCountingVisitor("RETURN",type); |
25 | String stoex = visitor.doSwitch(currentSignature.getReturnType__OperationSignature()); |
26 | result = appendStoEx(result, stoex); |
27 | } |
28 | return result; |
29 | } |
30 | |
31 | private static String appendStoEx(String result, String stoex) { |
32 | if (stoex != null){ |
33 | if (result == null) { |
34 | result = stoex; |
35 | } else { |
36 | result += " + (" + stoex + ")"; |
37 | } |
38 | } |
39 | return result; |
40 | } |
41 | |
42 | private static boolean matchesModifier(Parameter p, Modifier modifier) { |
43 | ParameterModifier parMod = p.getModifier__Parameter(); |
44 | switch(modifier){ |
45 | case IN: |
46 | if (parMod == ParameterModifier.IN || |
47 | parMod == ParameterModifier.INOUT || |
48 | parMod == ParameterModifier.NONE) |
49 | return true; |
50 | break; |
51 | case OUT: |
52 | if (parMod == ParameterModifier.INOUT || |
53 | parMod == ParameterModifier.OUT) |
54 | return true; |
55 | break; |
56 | } |
57 | return false; |
58 | } |
59 | |
60 | private static String countForParameter(Parameter p, PrimitiveTypeEnum type) { |
61 | TypesCountingVisitor visitor = new TypesCountingVisitor(p,type); |
62 | return visitor.doSwitch(p.getDataType__Parameter()); |
63 | } |
64 | |
65 | } |