Method: getVariableNamesBaseCase(PPattern)

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.assistant.pattern;
23:
24: import java.util.HashSet;
25: import java.util.Set;
26:
27: import org.overture.ast.analysis.AnalysisException;
28: import org.overture.ast.assistant.IAstAssistant;
29: import org.overture.ast.assistant.IAstAssistantFactory;
30: import org.overture.ast.intf.lex.ILexNameToken;
31: import org.overture.ast.lex.LexNameList;
32: import org.overture.ast.patterns.PPattern;
33:
34: public class PPatternAssistant implements IAstAssistant
35: {
36:         protected static IAstAssistantFactory af;
37:         protected final String fromModule;
38:
39:         @SuppressWarnings("static-access")
40:         public PPatternAssistant(IAstAssistantFactory af, String fromModule)
41:         {
42:                 this.af = af;
43:                 this.fromModule = fromModule;
44:         }
45:
46:         public LexNameList getAllVariableNames(PPattern pattern)
47:         {
48:                 try
49:                 {
50:                         return pattern.apply(af.getAllVariableNameLocator(fromModule));
51:                 }
52:                 catch (AnalysisException e)
53:                 {
54:                         return null;
55:                 }
56:         }
57:         
58:         public LexNameList getVariableNames(PPattern pattern)
59:         {
60:                 return af.createPPatternAssistant(pattern.getLocation().getModule()).getVariableNamesBaseCase(pattern);
61:         }
62:
63:         public LexNameList getVariableNamesBaseCase(PPattern pattern)
64:         {
65:                 Set<ILexNameToken> set = new HashSet<ILexNameToken>();
66:                 set.addAll(af.createPPatternAssistant(pattern.getLocation().getModule()).getAllVariableNames(pattern));
67:                 LexNameList list = new LexNameList();
68:                 list.addAll(set);
69:                 return list;
70:         }
71:
72: }