Package: AllVariableNameLocator

AllVariableNameLocator

nameinstructionbranchcomplexitylinemethod
AllVariableNameLocator(IAstAssistantFactory, String)
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%
caseAConcatenationPattern(AConcatenationPattern)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseAIdentifierPattern(AIdentifierPattern)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAObjectPattern(AObjectPattern)
M: 29 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
caseARecordPattern(ARecordPattern)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
caseASeqPattern(ASeqPattern)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
caseASetPattern(ASetPattern)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
caseATuplePattern(ATuplePattern)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
caseAUnionPattern(AUnionPattern)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
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)
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%
defaultPPattern(PPattern)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The Overture Abstract Syntax Tree
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.ast.util.pattern;
23:
24: import org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.AnswerAdaptor;
26: import org.overture.ast.assistant.IAstAssistantFactory;
27: import org.overture.ast.lex.LexNameList;
28: import org.overture.ast.node.INode;
29: import org.overture.ast.patterns.AConcatenationPattern;
30: import org.overture.ast.patterns.AIdentifierPattern;
31: import org.overture.ast.patterns.ANamePatternPair;
32: import org.overture.ast.patterns.AObjectPattern;
33: import org.overture.ast.patterns.ARecordPattern;
34: import org.overture.ast.patterns.ASeqPattern;
35: import org.overture.ast.patterns.ASetPattern;
36: import org.overture.ast.patterns.ATuplePattern;
37: import org.overture.ast.patterns.AUnionPattern;
38: import org.overture.ast.patterns.PPattern;
39:
40: /**
41: * Locates all variable names in a pattern and add them to a list.
42: *
43: * @author gkanos
44: */
45: public class AllVariableNameLocator extends AnswerAdaptor<LexNameList>
46: {
47:         protected final IAstAssistantFactory af;
48:         protected final String fromModule;
49:
50:         public AllVariableNameLocator(IAstAssistantFactory af, String fromModule)
51:         {
52:                 this.af = af;
53:                 this.fromModule = fromModule;
54:         }
55:
56:         @Override
57:         public LexNameList caseAConcatenationPattern(AConcatenationPattern pattern)
58:                         throws AnalysisException
59:         {
60:                 LexNameList list = new LexNameList();
61:
62:                 list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(pattern.getLeft()));
63:                 list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(pattern.getRight()));
64:
65:                 return list;
66:         }
67:
68:         @Override
69:         public LexNameList caseAIdentifierPattern(AIdentifierPattern pattern)
70:                         throws AnalysisException
71:         {
72:                 LexNameList list = new LexNameList();
73:                 list.add(pattern.getName());
74:                 return list;
75:         }
76:
77:         @Override
78:         public LexNameList caseARecordPattern(ARecordPattern pattern)
79:                         throws AnalysisException
80:         {
81:                 LexNameList list = new LexNameList();
82:
83:•                for (PPattern p : pattern.getPlist())
84:                 {
85:                         list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(p));
86:                 }
87:
88:                 return list;
89:         }
90:
91:         @Override
92:         public LexNameList caseASeqPattern(ASeqPattern pattern)
93:                         throws AnalysisException
94:         {
95:                 LexNameList list = new LexNameList();
96:
97:•                for (PPattern p : pattern.getPlist())
98:                 {
99:                         list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(p));
100:                 }
101:
102:                 return list;
103:         }
104:
105:         @Override
106:         public LexNameList caseASetPattern(ASetPattern pattern)
107:                         throws AnalysisException
108:         {
109:                 LexNameList list = new LexNameList();
110:
111:•                for (PPattern p : pattern.getPlist())
112:                 {
113:                         list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(p));
114:                 }
115:
116:                 return list;
117:         }
118:
119:         @Override
120:         public LexNameList caseATuplePattern(ATuplePattern pattern)
121:                         throws AnalysisException
122:         {
123:                 LexNameList list = new LexNameList();
124:
125:•                for (PPattern p : pattern.getPlist())
126:                 {
127:                         list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(p));
128:                 }
129:
130:                 return list;
131:         }
132:
133:         @Override
134:         public LexNameList caseAUnionPattern(AUnionPattern pattern)
135:                         throws AnalysisException
136:         {
137:                 LexNameList list = new LexNameList();
138:
139:                 list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(pattern.getLeft()));
140:                 list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(pattern.getRight()));
141:
142:                 return list;
143:         }
144:
145:         @Override
146:         public LexNameList caseAObjectPattern(AObjectPattern pattern)
147:                         throws AnalysisException
148:         {
149:                 LexNameList list = new LexNameList();
150:
151:•                for (ANamePatternPair npp : pattern.getFields())
152:                 {
153:                         list.addAll(af.createPPatternAssistant(fromModule).getAllVariableNames(npp.getPattern()));
154:                 }
155:
156:                 return list;
157:         }
158:
159:         @Override
160:         public LexNameList defaultPPattern(PPattern pattern)
161:                         throws AnalysisException
162:         {
163:                 return new LexNameList();
164:         }
165:
166:         @Override
167:         public LexNameList createNewReturnValue(INode node)
168:                         throws AnalysisException
169:         {
170:                 // TODO Auto-generated method stub
171:                 return null;
172:         }
173:
174:         @Override
175:         public LexNameList createNewReturnValue(Object node)
176:                         throws AnalysisException
177:         {
178:                 // TODO Auto-generated method stub
179:                 return null;
180:         }
181:
182: }