2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.util.script;
21 import java.util.ArrayList;
22 import java.util.LinkedHashMap;
23 import java.util.List;
27 class SingleChoice extends CG {
30 SingleChoice (Event e) {
34 public String toString() {
35 return event.toString();
39 class SetChoice extends CG {
40 ArrayList<Event> choices = new ArrayList<Event>();
42 public void add(Event e) {
47 public String toString() {
48 StringBuilder sb = new StringBuilder();
50 int i=0, n = choices.size();
51 for (Event e : choices) {
53 if (++i < n) sb.append(',');
61 * that's mostly a test class to see what a script would be expanded to w/o
62 * having any side effects in the ElementProcessor
64 public class StringSetGenerator implements ElementProcessor {
65 LinkedHashMap<String,ArrayList<CG>> sections;
68 StringSetGenerator() {
69 sections = new LinkedHashMap<String,ArrayList<CG>>();
70 queue = new ArrayList<CG>();
71 sections.put("default", queue);
75 public void process (Section sec) {
76 queue = new ArrayList<CG>();
77 sec.processChildren(this);
79 for (String id : sec.getIds()) {
80 sections.put(id,queue);
85 public void process (Event e) {
86 for (Event ee : e.expand()) {
87 queue.add( new SingleChoice(ee));
92 public void process (Alternative a) {
93 SetChoice cg = new SetChoice();
94 for (ScriptElement e = a.getFirstChild(); e != null; e = e.getNextSibling()) {
95 if (e instanceof Event) {
96 for (Event ee : ((Event)e).expand()) {
106 public void process (Repetition r) {
107 int n = r.getRepeatCount();
108 for (int i=0; i<n; i++) {
109 r.processChildren(this);
113 public LinkedHashMap<String,ArrayList<CG>> getSections () {
117 public List<CG> getCGQueue() {