EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcm.transformations]

COVERAGE SUMMARY FOR SOURCE FILE [BytesizeComputationForSignature.java]

nameclass, %method, %block, %line, %
BytesizeComputationForSignature.java0%   (0/2)0%   (0/7)0%   (0/280)0%   (0/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BytesizeComputationForSignature0%   (0/1)0%   (0/3)0%   (0/230)0%   (0/44)
BytesizeComputationForSignature (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getBytesizeForSignature (OperationSignature, BytesizeComputationForSignature$... 0%   (0/1)0%   (0/93)0%   (0/23)
getCharacterisationString (DataType, String): String 0%   (0/1)0%   (0/134)0%   (0/20)
     
class BytesizeComputationForSignature$Modifier0%   (0/1)0%   (0/4)0%   (0/50)0%   (0/4)
<static initializer> 0%   (0/1)0%   (0/24)0%   (0/3)
BytesizeComputationForSignature$Modifier (String, int): void 0%   (0/1)0%   (0/5)0%   (0/1)
valueOf (String): BytesizeComputationForSignature$Modifier 0%   (0/1)0%   (0/5)0%   (0/1)
values (): BytesizeComputationForSignature$Modifier [] 0%   (0/1)0%   (0/16)0%   (0/1)

1package de.uka.ipd.sdq.pcm.transformations;
2 
3import org.eclipse.emf.common.util.EList;
4 
5import de.uka.ipd.sdq.pcm.repository.CollectionDataType;
6import de.uka.ipd.sdq.pcm.repository.CompositeDataType;
7import de.uka.ipd.sdq.pcm.repository.DataType;
8import de.uka.ipd.sdq.pcm.repository.InnerDeclaration;
9import de.uka.ipd.sdq.pcm.repository.OperationSignature;
10import de.uka.ipd.sdq.pcm.repository.Parameter;
11import de.uka.ipd.sdq.pcm.repository.ParameterModifier;
12import de.uka.ipd.sdq.pcm.repository.PrimitiveDataType;
13 
14/**
15 * Responsible for determining a bytesize characterisation string for parameters in a signature. 
16 * @author Steffen
17 *
18 */
19public class BytesizeComputationForSignature {
20        
21        /**
22         * @author   Snowball
23         */
24        public enum Modifier{
25                IN,
26                OUT
27        }
28        
29        /**
30         * Composes a String, which includes the sum of BYTESIZE 
31         * characterisation strings for all the parameters of a given signature.
32         * For example: 
33         * <code>void foo(int bar, File blub)</code>
34         * would be tranformed into
35         * <code>"bar.BYTESIZE + blub.BYTESIZE"</code>
36         * 
37         * @param sig
38         * @param mod
39         * @return
40         */
41        public static String getBytesizeForSignature(OperationSignature sig, Modifier mod){
42                StringBuffer result = new StringBuffer();
43                
44                EList<Parameter> params = sig.getParameters__OperationSignature();
45                for (Parameter param : params){
46                        DataType dataType = param.getDataType__Parameter();
47                        ParameterModifier parMod = param.getModifier__Parameter();
48                        if (mod == Modifier.IN){
49                                if (parMod == ParameterModifier.IN || 
50                                        parMod == ParameterModifier.INOUT || 
51                                        parMod == ParameterModifier.NONE){
52                                        result.append(getCharacterisationString(dataType, param.getParameterName()));
53                                }
54                        } else {
55                                if (parMod == ParameterModifier.INOUT || 
56                                        parMod == ParameterModifier.OUT){
57                                        result.append(getCharacterisationString(dataType, param.getParameterName()));
58                                }
59                        }
60                }
61 
62                if (mod == Modifier.OUT){
63                        DataType returnType = sig.getReturnType__OperationSignature();        
64                        if (returnType != null){
65                                result.append(getCharacterisationString(returnType, "RETURN"));        
66                        }
67                }
68                
69                int length = result.length();
70                if (length > 0) 
71                        result.delete(length-3, length); // remove last " + "
72                else if (length == 0)
73                        result.append("0");
74 
75                return result.toString();
76        }
77 
78        /**
79         * Composes the characterisation string for a single parameter. For collection types and composite types, the inner declarations are respected. 
80         * For example
81         * 
82         * <code>int bar</code> would be tranformed into <code>"bar.BYTESIZE"</code>
83         * <code>int[] myIntArray</code> would be tranformed into <code>"myIntArray.BYTESIZE + myIntArray.NUMBER_OF_ELEMENTS * myIntArray.INNER.BYTESIZE"</code>
84         * With a composite data type <code>Compositum {int a; String b}</code> <code>Compositum myCompositum</code> would be transformed into <code>"myCompositum.BYTESIZE + myCompositum.a.BYTESIZE + myCompositum.b.BYTESIZE"</code>
85         * 
86         * The method calls itself recursively for non-primitive data types. 
87         * 
88         * @param dataType The data type of the parameter for that the characterisation string is created
89         * @param name  The name of the parameter for that the characterisation string is created
90         * @return A String with the proper BYTESIZE characterisations for the given type and name of parameter  
91         */
92        private static String getCharacterisationString(DataType dataType, String name){
93                StringBuffer result = new StringBuffer();
94                if (dataType instanceof PrimitiveDataType){
95                        result.append(name+".BYTESIZE + ");
96                } else if (dataType instanceof CollectionDataType){
97                        CollectionDataType collDataType = (CollectionDataType)dataType;
98                        result.append(name+".BYTESIZE + ");
99                        DataType innerDataType = collDataType.getInnerType_CollectionDataType();
100                        String innerSize = getCharacterisationString(innerDataType, name + ".INNER");
101                        result.append(name+".NUMBER_OF_ELEMENTS * "+ innerSize);
102                } else if (dataType instanceof CompositeDataType){
103                        CompositeDataType compDataType = (CompositeDataType)dataType;
104                        EList<InnerDeclaration> innerList = compDataType.getInnerDeclaration_CompositeDataType();
105                        result.append("(");
106                        result.append(name+".BYTESIZE + ");
107                        for (InnerDeclaration decl : innerList){
108                                DataType innerDataType = decl.getDatatype_InnerDeclaration();
109                                result.append(getCharacterisationString(innerDataType, name+"."+decl.getEntityName()));
110                        }
111                        result.delete(result.length()-3, result.length());
112                        result.append(") + ");
113                }
114                return result.toString();
115        }
116}

[all classes][de.uka.ipd.sdq.pcm.transformations]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov