001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba.bcp;
021:
022: import org.apache.bcel.generic.ConstantPoolGen;
023: import org.apache.bcel.generic.InstructionHandle;
024:
025: import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
026: import edu.umd.cs.findbugs.ba.Edge;
027: import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
028:
029: /**
030: * A wildcard PatternElement, which matches any kind of instruction
031: * indiscriminately.
032: *
033: * @author David Hovemeyer
034: * @see PatternElement
035: */
036: public class Wild extends PatternElement {
037: private int min, max;
038:
039: /**
040: * Default constructor.
041: * Creates a wildcard that matches from 0 to Integer.MAX_VALUE instructions.
042: */
043: public Wild() {
044: this .min = 0;
045: this .max = Integer.MAX_VALUE;
046: }
047:
048: /**
049: * Constructor. Matches any number of instructions from 0 to the maximum specified.
050: *
051: * @param max the maximum number of instructions the wildcard may match
052: */
053: public Wild(int max) {
054: this .min = 0;
055: this .max = max;
056: }
057:
058: /**
059: * Constructor.
060: *
061: * @param min minimum number of times the wildcard must match
062: * @param max maximum number of times the wildcard may match
063: */
064: public Wild(int min, int max) {
065: this .min = min;
066: this .max = max;
067: }
068:
069: /**
070: * Set min and max values.
071: *
072: * @param min minimum number of times the wildcard must match
073: * @param max maximum number of times the wildcard may match
074: */
075: public void setMinAndMax(int min, int max) {
076: this .min = min;
077: this .max = max;
078: }
079:
080: @Override
081: public int minOccur() {
082: return min;
083: }
084:
085: @Override
086: public int maxOccur() {
087: return max;
088: }
089:
090: @Override
091: public boolean acceptBranch(Edge edge, InstructionHandle source) {
092: return true;
093: }
094:
095: @Override
096: public MatchResult match(InstructionHandle handle,
097: ConstantPoolGen cpg, ValueNumberFrame before,
098: ValueNumberFrame after, BindingSet bindingSet)
099: throws DataflowAnalysisException {
100: return new MatchResult(this , bindingSet);
101: }
102: }
103:
104: // vim:ts=4
|