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.FieldInfo;
25 * utility class that can match FieldInfos against specs.
26 * if the class or name part are omitted, "*" is assumed
27 * a preceeding '!' means the match is inverted
30 * "x.y.Foo.bar : field 'bar' in class 'x.y.Foo'
31 * "x.y.Foo+.bar : all 'bar' fields in 'x.y.Foo' and all its supertypes
32 * "x.y.Foo.*" : all fields of x.y.Foo
33 * "*.myData" : all fields names 'myData'
34 * "!x.y.*" : all fields of types outside types in package x.y
36 public class FieldSpec extends FeatureSpec {
39 * factory method that includes the parser
41 public static FieldSpec createFieldSpec (String s){
42 ParseData d = new ParseData();
47 s = parseInversion(s,d);
48 parseTypeAndName(s,d);
51 return new FieldSpec(src, d.typeSpec, d.nameSpec, d.matchInverted);
52 } catch (IllegalArgumentException iax){
58 public FieldSpec (String rawSpec, String cls, String name, boolean inverted){
59 super(rawSpec,cls,name,inverted);
63 public boolean matches (Object feature){
64 if (feature instanceof FieldInfo){
65 return matches( (FieldInfo) feature);
71 public boolean matches (FieldInfo fi){
73 ClassInfo ci = fi.getClassInfo();
74 if (isMatchingType(ci)) {
75 if (nameSpec.matches(fi.getName()) != matchInverted) {
84 public String toString() {
85 StringBuilder sb = new StringBuilder();
86 sb.append("FieldSpec {");
88 sb.append("clsSpec:\"");
92 if (nameSpec != null){
93 sb.append(",nameSpec:\"");