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.JPF;
22 import gov.nasa.jpf.vm.ClassInfo;
25 * common base class for MethodSpec and FieldSpec
27 public abstract class FeatureSpec {
29 static JPFLogger logger = JPF.getLogger("gov.nasa.jpf.util");
31 static class ParseData {
32 boolean matchInverted;
33 boolean matchSuperTypes;
38 protected static final char SUB = '+';
39 protected static final char INVERTED = '!';
44 // those can be wildcard expressions
45 protected StringMatcher clsSpec;
46 protected StringMatcher nameSpec;
48 protected boolean matchInverted; // matches everything that does NOT conform to the specs
49 protected boolean matchSuperTypes; // matches supertypes of the specified one
52 protected static String parseInversion (String s, ParseData d){
54 if (s.charAt(0) == INVERTED){
55 d.matchInverted = true;
56 s = s.substring(1).trim();
62 protected static String parseType (String s, ParseData d){
67 protected static String parseTypeAndName (String s, ParseData d){
68 int i = s.lastIndexOf('.'); // beginning of name
73 d.typeSpec = s.substring(0, i);
76 d.nameSpec = s.substring(i+1);
77 if (d.nameSpec.length() == 0){
81 } else { // no name, all fields
93 protected FeatureSpec (String rawSpec, String cls, String name, boolean inverted){
95 matchInverted = inverted;
97 int l = cls.length()-1;
98 if (cls.charAt(l) == SUB){
99 cls = cls.substring(0, l);
100 matchSuperTypes = true;
103 clsSpec = new StringMatcher(cls);
106 nameSpec = new StringMatcher(name);
110 public String getSource() {
114 public StringMatcher getClassSpec() {
118 public StringMatcher getNameSpec() {
122 public boolean matchSuperTypes() {
123 return matchSuperTypes;
126 public boolean isMatchingType (Class cls){
127 if (clsSpec.matches(cls.getName())){
131 if (matchSuperTypes){
132 for (Class c = cls.getSuperclass(); c != null; c = c.getSuperclass()){
133 if (clsSpec.matches(c.getName())){
139 for (Class ifc : cls.getInterfaces()){
140 if (clsSpec.matches(ifc.getName())) {
148 public boolean isMatchingType(ClassInfo ci){
149 if (clsSpec.matches(ci.getName())){ // also takes care of '*'
153 if (matchSuperTypes){
154 // check all superclasses
155 for (ClassInfo sci = ci.getSuperClass(); sci != null; sci = sci.getSuperClass()){
156 if (clsSpec.matches(sci.getName())){
162 // check interfaces (regardless of 'override' - interfaces make no sense otherwise
163 for (ClassInfo ifc : ci.getAllInterfaces()) {
164 if (clsSpec.matches(ifc.getName())) {
172 public abstract boolean matches (Object feature);