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;
21 import gov.nasa.jpf.vm.ClassInfo;
22 import gov.nasa.jpf.vm.ElementInfo;
23 import gov.nasa.jpf.vm.MJIEnv;
24 import gov.nasa.jpf.vm.VM;
25 import gov.nasa.jpf.vm.MethodInfo;
26 import gov.nasa.jpf.vm.ObjRef;
29 * a record that includes all information to perform a call
31 public class Invocation {
33 Object[] args; // includes 'this' for instance methods
36 public Invocation (MethodInfo mi, Object[] args, Object[] attrs){
42 public MethodInfo getMethodInfo () {
46 public Object[] getExplicitArguments () {
48 Object[] a = new Object[args.length-1];
49 System.arraycopy(args,1,a,0,a.length);
56 public String[] getArgumentTypeNames() {
57 return mi.getArgumentTypeNames();
60 public String getArgumentValueLiteral(Object a) {
61 Class<?> cls = a.getClass();
63 if (cls == Boolean.class) return ((Boolean)a).toString();
64 if (cls == Byte.class) return ((Byte)a).toString();
65 if (cls == Character.class) return ((Character)a).toString();
66 if (cls == Short.class) return ((Short)a).toString();
67 if (cls == Integer.class) return ((Integer)a).toString();
68 if (cls == Long.class) return ((Long)a).toString();
69 if (cls == Float.class) return ((Float)a).toString();
70 if (cls == Double.class) return ((Double)a).toString();
72 if (cls == ObjRef.class) {
73 int ref = ((ObjRef)a).getReference();
75 if (ref != MJIEnv.NULL){
76 ElementInfo ei = VM.getVM().getElementInfo(ref);
77 ClassInfo ci = ei.getClassInfo();
78 String cname = ci.getName();
79 if (cname.equals("java.lang.String")){
80 return "\"" + ei.asString() + '"';
82 // <2do> we could probably do some more literals for java.lang.Class etc.
88 return null; // no literal representation
91 public Object[] getArguments() {
95 public Object[] getAttrs() {
100 public String toString() {
101 StringBuilder sb = new StringBuilder();
103 sb.append("INVOKE[");
104 sb.append(mi.getName());
106 for (int i=0; i<args.length; i++){
114 return sb.toString();