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.vm.choice;
21 import gov.nasa.jpf.util.Invocation;
22 import gov.nasa.jpf.vm.ChoiceGenerator;
23 import gov.nasa.jpf.vm.ChoiceGeneratorBase;
25 import java.io.PrintWriter;
26 import java.util.List;
27 import java.util.ListIterator;
30 * ChoiceGenerator that represents method calls
32 public class InvocationCG extends ChoiceGeneratorBase<Invocation> {
34 protected List<Invocation> invokes;
35 protected Invocation cur;
36 protected ListIterator<Invocation> it;
38 public InvocationCG (String id, List<Invocation> invokes){
41 this.invokes = invokes;
43 it = invokes.listIterator();
47 public Invocation getChoice (int idx){
48 if (idx >=0 && idx < invokes.size()){
49 return invokes.get(idx);
51 throw new IllegalArgumentException("choice index out of range: " + idx);
56 public void advance () {
61 public Class<Invocation> getChoiceType () {
62 return Invocation.class;
66 public Invocation getNextChoice () {
71 public int getProcessedNumberOfChoices () {
72 return it.nextIndex();
76 public int getTotalNumberOfChoices () {
77 return invokes.size();
81 public boolean hasMoreChoices () {
86 public ChoiceGenerator<Invocation> randomize () {
92 public String toString() {
93 StringBuilder sb = new StringBuilder(getClass().getName());
95 int n = invokes.size();
96 for (int i=0; i<n; i++) {
97 if (i > 0) sb.append(',');
98 Invocation inv = invokes.get(i);
105 return sb.toString();
108 public void printOn (PrintWriter pw) {
109 pw.print(toString());
113 public void reset () {
115 it = invokes.listIterator();