Package: NewPrettyPrinter

NewPrettyPrinter

nameinstructionbranchcomplexitylinemethod
NewPrettyPrinter(ISymbolTable)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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%
defaultPExp(PExp, IndentTracker)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
newInstance()
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%
prettyPrint(INode)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
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%

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.PExp;
27: import org.overture.ast.node.INode;
28:
29: /**
30: * The Class PrettyPrinter is the main visitor for the VDM pretty printer package. It handles dispatching of nodes and
31: * can be safely applied to any node in the AST. <br>
32: * <br>
33: * The general operating principle is that when applied to any node, the visitor will return the corresponding string of
34: * the syntax block of that node. Indentation is controlled internally and always starts at 0 levels (the discipline is
35: * caller increments/decrements). <br>
36: * However, due to extensibility concerns, direct application of the class requires users to feed it ausers are advised
37: * to instead use the public utility method available at: .
38: */
39: public class NewPrettyPrinter extends
40:                 QuestionAnswerAdaptor<IndentTracker, String> implements IPrettyPrinter
41: {
42:
43:         private static final String NODE_NOT_FOUND_ERROR = "ERROR: Node Not Found.";
44:
45:         /**
46:          * The attribute table for handling non abstract syntax such as separators.
47:          */
48:         ISymbolTable mytable;
49:         ExpressionNpp expPrinter;
50:
51:         // PatternNpp
52:         // BindNpp...
53:
54:         /**
55:          * Creates a VDM-syntax pretty printer. <br>
56:          * <b>Warning:</b> this method pre-loads {@link VdmSymbolTable} attributes. Extensions should use
57:          * {@link #NewPrettyPrinter(ISymbolTable)} and configure it instead.
58:          *
59:          * @return a new instance of {@link NewPrettyPrinter}
60:          */
61:         public static NewPrettyPrinter newInstance()
62:         {
63:                 return new NewPrettyPrinter(VdmSymbolTable.getInstance());
64:         }
65:
66:         public static String prettyPrint(INode node) throws AnalysisException
67:         {
68:                 String s = node.apply(newInstance(), new IndentTracker());
69:                 return s.replace("\t", " ");
70:         }
71:
72:         /**
73:          * Instantiates a new pretty printer for base ASTs.
74:          *
75:          * @param nsTable
76:          * the attributes table for the printer
77:          */
78:         public NewPrettyPrinter(ISymbolTable nsTable)
79:         {
80:                 mytable = nsTable;
81:                 expPrinter = new ExpressionNpp(this, nsTable);
82:
83:         }
84:
85:         /*
86:          * (non-Javadoc)
87:          * @see org.overture.core.npp.IPrettyPrinter#setInsTable(org.overture.core.npp .InsTable)
88:          */
89:         @Override
90:         public void setInsTable(ISymbolTable it)
91:         {
92:                 mytable = it;
93:         }
94:
95:
96:         @Override
97:         public String defaultPExp(PExp node, IndentTracker question) throws AnalysisException
98:         {
99:                 return node.apply(expPrinter, question);
100:         }
101:
102:         
103:
104:         @Override
105:         public String createNewReturnValue(INode node, IndentTracker question)
106:                         throws AnalysisException
107:         {
108:                 return NODE_NOT_FOUND_ERROR;
109:         }
110:
111:         @Override
112:         public String createNewReturnValue(Object node, IndentTracker question)
113:                         throws AnalysisException
114:         {
115:                 return NODE_NOT_FOUND_ERROR;
116:         }
117:
118: }