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

COVERAGE SUMMARY FOR SOURCE FILE [ExpressionHelper.java]

nameclass, %method, %block, %line, %
ExpressionHelper.java0%   (0/1)0%   (0/7)0%   (0/109)0%   (0/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExpressionHelper0%   (0/1)0%   (0/7)0%   (0/109)0%   (0/31)
ExpressionHelper (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getMeanValue (PCMRandomVariable): double 0%   (0/1)0%   (0/8)0%   (0/2)
getSolvedExpression (String, ContextWrapper): Expression 0%   (0/1)0%   (0/25)0%   (0/8)
getSolvedExpressionAsString (String, ContextWrapper): String 0%   (0/1)0%   (0/28)0%   (0/6)
getTypeAnnotation (Expression): HashMap 0%   (0/1)0%   (0/11)0%   (0/4)
meanValue (Expression): double 0%   (0/1)0%   (0/7)0%   (0/2)
parseToExpression (String): Expression 0%   (0/1)0%   (0/27)0%   (0/8)

1package de.uka.ipd.sdq.pcmsolver.visitors;
2 
3import java.util.HashMap;
4 
5import org.antlr.runtime.ANTLRStringStream;
6import org.antlr.runtime.CommonTokenStream;
7import org.antlr.runtime.RecognitionException;
8 
9import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
10import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.PCMStoExLexer;
11import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.PCMStoExParser;
12import de.uka.ipd.sdq.pcmsolver.transformations.ContextWrapper;
13import de.uka.ipd.sdq.pcmsolver.transformations.ExpressionToPDFWrapper;
14import de.uka.ipd.sdq.stoex.Expression;
15import de.uka.ipd.sdq.stoex.analyser.visitors.ExpressionInferTypeVisitor;
16import de.uka.ipd.sdq.stoex.analyser.visitors.StoExPrettyPrintVisitor;
17import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum;
18 
19public class ExpressionHelper {
20 
21        /**
22         * @param specification
23         */
24        public static Expression parseToExpression(String specification) {
25                Expression expression = null;
26                PCMStoExLexer lexer = new PCMStoExLexer(
27                                new ANTLRStringStream(specification));
28                PCMStoExParser parser = new PCMStoExParser(new CommonTokenStream(lexer));
29                try {
30                        expression = parser.expression();
31                } catch (RecognitionException e) {
32                        // TODO Auto-generated catch block
33                        e.printStackTrace();
34                }
35                return expression;
36        }
37        
38        public static String getSolvedExpressionAsString(String specification, ContextWrapper ctxWrp){
39                Expression solvedExpression = getSolvedExpression(specification, ctxWrp);
40                
41                StoExPrettyPrintVisitor printer = new StoExPrettyPrintVisitor();
42                String solvedExprString = (String)printer.doSwitch(solvedExpression);
43                
44                if (solvedExpression == null){
45                        throw new RuntimeException("Could not print solved expression "+specification);
46                }
47                
48                return solvedExprString;
49        }
50        
51        public static Expression getSolvedExpression(String specification,
52                        ContextWrapper ctxWrp) {
53                Expression expr = parseToExpression(specification);
54                
55                ExpressionInferTypeVisitor inferTypeVisitor = new ExpressionInferTypeVisitor();
56                inferTypeVisitor.doSwitch(expr);
57 
58                HashMap<Expression, TypeEnum> typeAnnotation = inferTypeVisitor
59                                .getTypeAnnotation();
60 
61                ExpressionParameterSolverVisitor solveVisitor = new ExpressionParameterSolverVisitor(
62                                typeAnnotation, ctxWrp);
63                
64                return (Expression) solveVisitor.doSwitch(expr);
65        }
66        
67        public static HashMap<Expression,TypeEnum> getTypeAnnotation(Expression expr){
68                ExpressionInferTypeVisitor inferTypeVisitor = 
69                        new ExpressionInferTypeVisitor();
70                inferTypeVisitor.doSwitch(expr);
71                return inferTypeVisitor.getTypeAnnotation();
72        }
73 
74        /**
75         * calculated the mean value for a solved expression
76         * @param expression
77         * @return
78         * @throws IllegalArgumentException if the passed expression has not been solved before. 
79         */
80        public static double meanValue(Expression expression) throws IllegalArgumentException {
81                ExpressionToPDFWrapper wrapper = ExpressionToPDFWrapper.createExpressionToPDFWrapper(expression);
82                return wrapper.getMeanValue();
83        }
84        
85        
86        public static double getMeanValue(PCMRandomVariable variable){
87                ExpressionToPDFWrapper expToPDF = ExpressionToPDFWrapper.createExpressionToPDFWrapper(variable.getExpression());
88                return expToPDF.getMeanValue();
89        }
90}

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