KickJava   Java API By Example, From Geeks To Geeks.

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


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.annotations.SuppressWarnings;
26 import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
27 import edu.umd.cs.findbugs.ba.Edge;
28 import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
29
30 /**
31  * A "meta" PatternElement that matches any of a list of other child PatternElements.
32  * An example of how this is useful is that you might want to match invocations of any
33  * of a number of different methods. To do this, you can create a MatchAny
34  * with some number of Invoke elements as children.
35  * <p/>
36  * <p> Note that the minOccur() and maxOccur() counts of the child PatternElements
37  * are ignored. A MatchAny element always matches exactly one instruction.
38  *
39  * @author David Hovemeyer
40  * @see PatternElement
41  */

42 public class MatchAny extends PatternElement {
43     private PatternElement[] childList;
44
45     /**
46      * Constructor.
47      *
48      * @param childList list of child PatternElements
49      */

50     @SuppressWarnings JavaDoc("EI2")
51     public MatchAny(PatternElement[] childList) {
52         this.childList = childList;
53     }
54
55     @Override JavaDoc
56          public PatternElement label(String JavaDoc label) {
57         for (PatternElement aChildList : childList) {
58             aChildList.label(label);
59         }
60         return this;
61     }
62
63     @Override JavaDoc
64          public PatternElement setAllowTrailingEdges(boolean allowTrailingEdges) {
65         // Just forward this on to all children,
66
// since it is the children that the PatternMatcher will ask
67
// about edges.
68
for (PatternElement aChildList : childList)
69             aChildList.setAllowTrailingEdges(allowTrailingEdges);
70
71         return this;
72     }
73
74     @Override JavaDoc
75          public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg,
76                              ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException {
77
78         for (PatternElement child : childList) {
79             MatchResult matchResult = child.match(handle, cpg, before, after, bindingSet);
80             if (matchResult != null)
81                 return matchResult;
82         }
83
84         return null;
85
86     }
87
88     @Override JavaDoc
89          public boolean acceptBranch(Edge edge, InstructionHandle source) {
90         // Note: when selecting branch instructions, only the actual
91
// (child) PatternElement should be used.
92
throw new IllegalStateException JavaDoc("shouldn't happen");
93     }
94
95     @Override JavaDoc
96          public int minOccur() {
97         return 1;
98     }
99
100     @Override JavaDoc
101          public int maxOccur() {
102         return 1;
103     }
104 }
105
106 // vim:ts=4
107
Popular Tags