KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > bcp > Wild


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.ba.bcp;
21
22 import org.apache.bcel.generic.ConstantPoolGen;
23 import org.apache.bcel.generic.InstructionHandle;
24
25 import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
26 import edu.umd.cs.findbugs.ba.Edge;
27 import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
28
29 /**
30  * A wildcard PatternElement, which matches any kind of instruction
31  * indiscriminately.
32  *
33  * @author David Hovemeyer
34  * @see PatternElement
35  */

36 public class Wild extends PatternElement {
37     private int min, max;
38
39     /**
40      * Default constructor.
41      * Creates a wildcard that matches from 0 to Integer.MAX_VALUE instructions.
42      */

43     public Wild() {
44         this.min = 0;
45         this.max = Integer.MAX_VALUE;
46     }
47
48     /**
49      * Constructor. Matches any number of instructions from 0 to the maximum specified.
50      *
51      * @param max the maximum number of instructions the wildcard may match
52      */

53     public Wild(int max) {
54         this.min = 0;
55         this.max = max;
56     }
57
58     /**
59      * Constructor.
60      *
61      * @param min minimum number of times the wildcard must match
62      * @param max maximum number of times the wildcard may match
63      */

64     public Wild(int min, int max) {
65         this.min = min;
66         this.max = max;
67     }
68
69     /**
70      * Set min and max values.
71      *
72      * @param min minimum number of times the wildcard must match
73      * @param max maximum number of times the wildcard may match
74      */

75     public void setMinAndMax(int min, int max) {
76         this.min = min;
77         this.max = max;
78     }
79
80     @Override JavaDoc
81          public int minOccur() {
82         return min;
83     }
84
85     @Override JavaDoc
86          public int maxOccur() {
87         return max;
88     }
89
90     @Override JavaDoc
91          public boolean acceptBranch(Edge edge, InstructionHandle source) {
92         return true;
93     }
94
95     @Override JavaDoc
96          public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg,
97                              ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException {
98         return new MatchResult(this, bindingSet);
99     }
100 }
101
102 // vim:ts=4
103
Popular Tags