Method: findIdentifiers(AMapletPatternMaplet)
1: package org.overture.interpreter.assistant.pattern;
2:
3: import java.util.List;
4: import java.util.Map.Entry;
5: import java.util.Vector;
6:
7: import org.overture.ast.analysis.AnalysisException;
8: import org.overture.ast.assistant.IAstAssistant;
9: import org.overture.ast.patterns.AIdentifierPattern;
10: import org.overture.ast.patterns.AMapletPatternMaplet;
11: import org.overture.interpreter.assistant.IInterpreterAssistantFactory;
12: import org.overture.interpreter.runtime.Context;
13: import org.overture.interpreter.values.NameValuePairList;
14: import org.overture.interpreter.values.Value;
15:
16: public class AMapPatternMapletAssistantInterpreter implements IAstAssistant
17:
18: {
19:         protected static IInterpreterAssistantFactory af;
20:         protected final String fromModule;
21:
22:         @SuppressWarnings("static-access")
23:         public AMapPatternMapletAssistantInterpreter(IInterpreterAssistantFactory af, String fromModule)
24:         {
25:                 // super(af);
26:                 this.af = af;
27:                 this.fromModule = fromModule;
28:         }
29:
30:         public List<NameValuePairList> getAllNamedValues(AMapletPatternMaplet p,
31:                         Entry<Value, Value> maplet, Context ctxt) throws AnalysisException
32:         {
33:                 List<NameValuePairList> flist = af.createPPatternAssistant(fromModule).getAllNamedValues(p.getFrom(), maplet.getKey(), ctxt);
34:                 List<NameValuePairList> tlist = af.createPPatternAssistant(fromModule).getAllNamedValues(p.getTo(), maplet.getValue(), ctxt);
35:                 List<NameValuePairList> results = new Vector<NameValuePairList>();
36:
37:                 for (NameValuePairList f : flist)
38:                 {
39:                         for (NameValuePairList t : tlist)
40:                         {
41:                                 NameValuePairList both = new NameValuePairList();
42:                                 both.addAll(f);
43:                                 both.addAll(t);
44:                                 results.add(both); // Every combination of from/to mappings
45:                         }
46:                 }
47:
48:                 return results;
49:         }
50:
51:         public List<AIdentifierPattern> findIdentifiers(AMapletPatternMaplet p)
52:         {
53:                 List<AIdentifierPattern> list = new Vector<AIdentifierPattern>();
54:
55:                 list.addAll(af.createPPatternAssistant(fromModule).findIdentifiers(p.getFrom()));
56:                 list.addAll(af.createPPatternAssistant(fromModule).findIdentifiers(p.getTo()));
57:
58:                 return list;
59:         }
60:
61: }