Package: ExpressionNpp

ExpressionNpp

nameinstructionbranchcomplexitylinemethod
ExpressionNpp(NewPrettyPrinter, ISymbolTable)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseADivNumericBinaryExp(ADivNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseADivideNumericBinaryExp(ADivideNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseAImpliesBooleanBinaryExp(AImpliesBooleanBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseAIntLiteralExp(AIntLiteralExp, IndentTracker)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAModNumericBinaryExp(AModNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseAPlusNumericBinaryExp(APlusNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseARealLiteralExp(ARealLiteralExp, IndentTracker)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseASubtractNumericBinaryExp(ASubtractNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseATimesNumericBinaryExp(ATimesNumericBinaryExp, IndentTracker)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseAVariableExp(AVariableExp, IndentTracker)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createNewReturnValue(INode, IndentTracker)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object, IndentTracker)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setInsTable(ISymbolTable)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * New Pretty Printer
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.core.npp;
23:
24: import org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.QuestionAnswerAdaptor;
26: import org.overture.ast.expressions.ADivNumericBinaryExp;
27: import org.overture.ast.expressions.ADivideNumericBinaryExp;
28: import org.overture.ast.expressions.AImpliesBooleanBinaryExp;
29: import org.overture.ast.expressions.AIntLiteralExp;
30: import org.overture.ast.expressions.AModNumericBinaryExp;
31: import org.overture.ast.expressions.APlusNumericBinaryExp;
32: import org.overture.ast.expressions.ARealLiteralExp;
33: import org.overture.ast.expressions.ASubtractNumericBinaryExp;
34: import org.overture.ast.expressions.ATimesNumericBinaryExp;
35: import org.overture.ast.expressions.AVariableExp;
36: import org.overture.ast.node.INode;
37:
38: class ExpressionNpp extends QuestionAnswerAdaptor<IndentTracker, String>
39:                 implements IPrettyPrinter
40: {
41:
42:         ISymbolTable mytable;
43:         IPrettyPrinter rootNpp;
44:
45:         private static String EXPRESSION_NOT_FOUND = "ERROR: Expression Node not found";
46:         private static String space = " ";
47:
48:         public ExpressionNpp(NewPrettyPrinter root, ISymbolTable nst)
49:         {
50:                 rootNpp = root;
51:                 mytable = nst;
52:         }
53:
54:         @Override
55:         public void setInsTable(ISymbolTable it)
56:         {
57:                 mytable = it;
58:         }
59:
60:         @Override
61:         public String caseAPlusNumericBinaryExp(APlusNumericBinaryExp node,
62:                         IndentTracker question) throws AnalysisException
63:         {
64:                 String l = node.getLeft().apply(THIS, question);
65:                 String r = node.getRight().apply(THIS, question);
66:                 String op = mytable.getPLUS();
67:
68:                 StringBuilder sb = new StringBuilder();
69:
70:                 sb.append(l);
71:                 sb.append(space);
72:                 sb.append(op);
73:                 sb.append(space);
74:                 sb.append(r);
75:
76:                 return Utilities.wrap(sb.toString());
77:         }
78:         
79:         @Override
80:         public String caseASubtractNumericBinaryExp(ASubtractNumericBinaryExp node,
81:                         IndentTracker question) throws AnalysisException
82:         {
83:                 String l = node.getLeft().apply(THIS, question);
84:                 String r = node.getRight().apply(THIS, question);
85:                 String op = mytable.getMINUS();
86:                 
87:                 StringBuilder sb = new StringBuilder();
88:                 
89:                 sb.append(l);
90:                 sb.append(space);
91:                 sb.append(op);
92:                 sb.append(space);
93:                 sb.append(r);
94:                 
95:                 return Utilities.wrap(sb.toString());
96:         }
97:         
98:         @Override
99:         public String caseATimesNumericBinaryExp(ATimesNumericBinaryExp node,
100:                         IndentTracker question) throws AnalysisException
101:         {
102:                 String l = node.getLeft().apply(THIS, question);
103:                 String r = node.getRight().apply(THIS,question);
104:                 String op = mytable.getTIMES();
105:                 
106:                 StringBuilder sb = new StringBuilder();
107:                 
108:                 sb.append(l);
109:                 sb.append(space);
110:                 sb.append(op);
111:                 sb.append(space);
112:                 sb.append(r);
113:                 
114:                 return Utilities.wrap(sb.toString());
115:         }
116:         
117:         @Override
118:         public String caseADivideNumericBinaryExp(ADivideNumericBinaryExp node,
119:                         IndentTracker question) throws AnalysisException
120:         {
121:                 String l = node.getLeft().apply(THIS, question);
122:                 String r = node.getRight().apply(THIS,question);
123:                 String op = mytable.getDIVIDE();
124:                 
125:                 StringBuilder sb = new StringBuilder();
126:                 
127:                 sb.append(l);
128:                 sb.append(space);
129:                 sb.append(op);
130:                 sb.append(space);
131:                 sb.append(r);
132:                 
133:                 return Utilities.wrap(sb.toString());
134:         }
135:         
136:         @Override
137:         public String caseAModNumericBinaryExp(AModNumericBinaryExp node,
138:                         IndentTracker question) throws AnalysisException
139:         {
140:                 String l = node.getLeft().apply(THIS, question);
141:                 String r = node.getRight().apply(THIS,question);
142:                 String op = mytable.getMOD();
143:                 
144:                 StringBuilder sb = new StringBuilder();
145:                 
146:                 sb.append(l);
147:                 sb.append(space);
148:                 sb.append(op);
149:                 sb.append(space);
150:                 sb.append(r);
151:                 
152:                 return Utilities.wrap(sb.toString());
153:         }
154:         
155:         @Override
156:         public String caseADivNumericBinaryExp(ADivNumericBinaryExp node,
157:                         IndentTracker question) throws AnalysisException
158:         {
159:                 String l = node.getLeft().apply(THIS, question);
160:                 String r = node.getRight().apply(THIS,question);
161:                 String op = mytable.getDIV();
162:                 
163:                 StringBuilder sb = new StringBuilder();
164:                 
165:                 sb.append(l);
166:                 sb.append(space);
167:                 sb.append(op);
168:                 sb.append(space);
169:                 sb.append(r);
170:                 
171:                 return Utilities.wrap(sb.toString());
172:         }
173:         
174:         @Override
175:         public String caseAImpliesBooleanBinaryExp(AImpliesBooleanBinaryExp node,
176:                         IndentTracker question) throws AnalysisException
177:         {
178:                 String l = node.getLeft().apply(THIS, question);
179:                 String r = node.getRight().apply(THIS,question);
180:                 String op = mytable.getIMPLIES();
181:                 
182:                 StringBuilder sb = new StringBuilder();
183:                 
184:                 sb.append(l);
185:                 sb.append(space);
186:                 sb.append(op);
187:                 sb.append(space);
188:                 sb.append(r);
189:                 
190:                 return        Utilities.wrap(sb.toString());
191:         }
192:         
193:         @Override
194:         public String caseAIntLiteralExp(AIntLiteralExp node, IndentTracker question)
195:                         throws AnalysisException
196:         {
197:                 return Long.toString(node.getValue().getValue());
198:         }
199:         
200:         @Override
201:         public String caseARealLiteralExp(ARealLiteralExp node,
202:                         IndentTracker question) throws AnalysisException
203:         {
204:                 return Double.toString(node.getValue().getValue());
205:         }
206:         
207:         @Override
208:         public String caseAVariableExp(AVariableExp node, IndentTracker question)
209:                         throws AnalysisException
210:         {
211:                 String var = node.getOriginal();
212:                 
213:                 return var;
214:                 
215:         }
216:
217:         @Override
218:         public String createNewReturnValue(INode node, IndentTracker question)
219:                         throws AnalysisException
220:         {
221:                 return EXPRESSION_NOT_FOUND;
222:         }
223:
224:         @Override
225:         public String createNewReturnValue(Object node, IndentTracker question)
226:                         throws AnalysisException
227:         {
228:                 return EXPRESSION_NOT_FOUND;
229:         }
230:
231: }