Adding ParameterizedTypeImpl to getGenericSuperclass method.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / ClassPath.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
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
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
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.
17  */
18
19 package gov.nasa.jpf.vm;
20
21 import gov.nasa.jpf.JPF;
22 import gov.nasa.jpf.util.JPFLogger;
23
24 import java.io.File;
25 import java.util.ArrayList;
26
27 /**
28  * this is a lookup mechanism for class files that is based on an ordered
29  * list of directory or jar entries
30  */
31 public class ClassPath implements Restorable<ClassPath>{
32
33   static class CPMemento implements Memento<ClassPath> {
34     ClassPath cp;
35     ArrayList<ClassFileContainer> pathElements;
36
37     CPMemento (ClassPath cp){
38       this.cp = cp;
39       this.pathElements = new ArrayList<ClassFileContainer>(cp.pathElements);
40     }
41
42     @Override
43     public ClassPath restore (ClassPath ignored) {
44       cp.pathElements = this.pathElements;
45       return cp;
46     }
47   }
48
49   
50   static JPFLogger logger = JPF.getLogger("gov.nasa.jpf.jvm.classfile");
51   
52   protected ArrayList<ClassFileContainer> pathElements;
53
54
55   public ClassPath(){
56     pathElements = new ArrayList<ClassFileContainer>();
57   }
58   
59   @Override
60   public Memento<ClassPath> getMemento (MementoFactory factory) {
61     return factory.getMemento(this);
62   }
63
64   public Memento<ClassPath> getMemento(){
65     return new CPMemento(this);
66   }
67
68   public void addClassFileContainer (ClassFileContainer pathElement){
69     assert pathElement != null;
70     pathElements.add(pathElement);
71   }
72
73
74   public String[] getPathNames(){
75     String[] pn = new String[pathElements.size()];
76
77     for (int i=0; i<pn.length; i++){
78       pn[i] = pathElements.get(i).getName();
79     }
80
81     return pn;
82   }
83
84   @Override
85   public String toString(){
86     StringBuilder sb = new StringBuilder();
87     int len = pathElements.size();
88     int i=0;
89
90     for (ClassFileContainer e : pathElements){
91       sb.append(e.getName());
92       if (++i < len){
93         sb.append(File.pathSeparator);
94       }
95     }
96     return sb.toString();
97   }
98
99   protected static void error(String msg) throws ClassParseException {
100     throw new ClassParseException(msg);
101   }
102
103   public ClassFileMatch findMatch (String clsName) throws ClassParseException {
104     for (ClassFileContainer container : pathElements){
105       ClassFileMatch match = container.getMatch(clsName);
106       if (match != null){
107         logger.fine("found ", clsName, " in ", container.getName());
108         return match;
109       }
110     }
111
112     return null;    
113   }
114
115 }