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;
24 * utility class that can be used by InstructionFactory implementations to
25 * selectively replace bytecodes for specified class sets.
27 * Filtering is based on include/exclude name patterns (e.g. for packages) and/or
28 * on inheritance (both down- and upwards)
30 public class ClassInfoFilter {
32 // filter using an explicit set of class names (can be used for one-pass load)
33 protected StringSetMatcher includes; // included classes that should use them
34 protected StringSetMatcher excludes; // excluded classes (that should NOT use them)
36 // filter using base/derived class sets (only useful in subsequent pass)
40 public ClassInfoFilter (String[] includeCls, String[] excludeCls,
41 ClassInfo rootCls, ClassInfo leafCls) {
42 includes = StringSetMatcher.getNonEmpty(includeCls);
43 excludes = StringSetMatcher.getNonEmpty(excludeCls);
50 public boolean isPassing (ClassInfo ci){
53 // <??> not clear what to do in this case, since we have nothing to
54 // filter on. Since all reflection calls come in here, it's probably
55 // better to instrument by default (until we have a better mechanism)
59 String clsName = ci.getName();
61 if (StringSetMatcher.isMatch(clsName, includes, excludes)){
62 if (ciLeaf == null || ciLeaf.isInstanceOf(ci)){
63 if (ciRoot == null || ci.isInstanceOf(ciRoot)){