KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
23 import java.util.LinkedList JavaDoc;
24
25 import org.apache.bcel.generic.InstructionHandle;
26
27 public class ByteCodePatternMatch {
28     private BindingSet bindingSet;
29     private PatternElementMatch lastElementMatch;
30     private LinkedList JavaDoc<PatternElementMatch> patternElementMatchList;
31
32     public ByteCodePatternMatch(BindingSet bindingSet, PatternElementMatch lastElementMatch) {
33         this.bindingSet = bindingSet;
34         this.lastElementMatch = lastElementMatch;
35         this.patternElementMatchList = new LinkedList JavaDoc<PatternElementMatch>();
36
37         // The PatternElementMatch objects are stored in reverse order.
38
// So, put them in a LinkedList to get them in the right order.
39
while (lastElementMatch != null) {
40             patternElementMatchList.addFirst(lastElementMatch);
41             lastElementMatch = lastElementMatch.getPrev();
42         }
43     }
44
45     public BindingSet getBindingSet() {
46         return bindingSet;
47     }
48
49     public Iterator JavaDoc<PatternElementMatch> patternElementMatchIterator() {
50         return patternElementMatchList.iterator();
51     }
52
53     public InstructionHandle getLabeledInstruction(String JavaDoc label) {
54         return lastElementMatch != null
55                 ? lastElementMatch.getLabeledInstruction(label)
56                 : null;
57     }
58
59     public PatternElementMatch getFirstLabeledMatch(String JavaDoc label) {
60         return lastElementMatch != null
61                 ? lastElementMatch.getFirstLabeledMatch(label)
62                 : null;
63     }
64
65     public PatternElementMatch getLastLabeledMatch(String JavaDoc label) {
66         return lastElementMatch != null
67                 ? lastElementMatch.getLastLabeledMatch(label)
68                 : null;
69     }
70 }
71
72 // vim:ts=4
73
Popular Tags