1 | package de.uka.ipd.sdq.pcm.transformations.builder.seff; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | import java.util.List; |
6 | |
7 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
8 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisationType; |
9 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
10 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
11 | import de.uka.ipd.sdq.pcm.transformations.BytesizeComputationForSignature; |
12 | import de.uka.ipd.sdq.pcm.transformations.BytesizeComputationForSignature.Modifier; |
13 | |
14 | /** |
15 | * Adjust a single variable usage by adding the bytesize characterisations of the current signature |
16 | * The bytesize information is added to the first bytesize variable characterisation of the passed |
17 | * VariableUsage. |
18 | * |
19 | * @author martens |
20 | * |
21 | */ |
22 | public class BytesizeAddingSetVariableActionDescriptor extends |
23 | SetVariableActionDescriptor implements ISignatureDependentAction { |
24 | |
25 | private OperationSignature currentSignature; |
26 | |
27 | private Modifier modifier; |
28 | |
29 | private VariableUsage variableUsage; |
30 | |
31 | // public BytesizeAddingSetVariableActionDescriptor(String variableName, |
32 | // VariableCharacterisationType varCharacterisation, String specification, |
33 | // Modifier modifier) { |
34 | // // not nice here, but I cannot create the variable usage yet |
35 | // super(ParameterFactory.eINSTANCE.createVariableUsage()); |
36 | // |
37 | // this.variableName = variableName; |
38 | // this.variableCharacterisation = varCharacterisation; |
39 | // this.specification = specification; |
40 | // this.modifier = modifier; |
41 | // } |
42 | |
43 | public BytesizeAddingSetVariableActionDescriptor( |
44 | VariableUsage variableUsage, Modifier modifier) { |
45 | super(variableUsage); |
46 | this.variableUsage = variableUsage; |
47 | this.modifier = modifier; |
48 | } |
49 | |
50 | public void setCurrentSignature(OperationSignature sig) { |
51 | this.currentSignature = sig; |
52 | |
53 | } |
54 | |
55 | @Override |
56 | protected Collection<? extends VariableUsage> getVariableUsages() { |
57 | return getSignatureDependentVariableUsages(this.currentSignature); |
58 | } |
59 | |
60 | protected Collection<? extends VariableUsage> getSignatureDependentVariableUsages(OperationSignature currentSignature){ |
61 | String byteSizeString = getBytesizeString(this.currentSignature, this.modifier); |
62 | |
63 | VariableCharacterisation bytesizeCharacterisation = null; |
64 | for (VariableCharacterisation vc : this.variableUsage.getVariableCharacterisation_VariableUsage()) { |
65 | if (vc.getType().equals(VariableCharacterisationType.BYTESIZE)){ |
66 | bytesizeCharacterisation = vc; |
67 | break; |
68 | } |
69 | } |
70 | if (bytesizeCharacterisation != null){ |
71 | String oldSpec = bytesizeCharacterisation.getSpecification_VariableCharacterisation().getSpecification(); |
72 | bytesizeCharacterisation.getSpecification_VariableCharacterisation().setSpecification(oldSpec + " + "+byteSizeString); |
73 | } |
74 | List<VariableUsage> result = new ArrayList<VariableUsage>(1); |
75 | result.add(this.variableUsage); |
76 | return result; |
77 | |
78 | } |
79 | |
80 | private String getBytesizeString(OperationSignature currentSignature, Modifier modifier){ |
81 | String specification = BytesizeComputationForSignature.getBytesizeForSignature(currentSignature, modifier); |
82 | return specification; |
83 | } |
84 | |
85 | } |