01: /*
02: * ProGuard -- shrinking, optimization, obfuscation, and preverification
03: * of Java bytecode.
04: *
05: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the Free
09: * Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful, but WITHOUT
13: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15: * more details.
16: *
17: * You should have received a copy of the GNU General Public License along
18: * with this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: package proguard.classfile.visitor;
22:
23: import proguard.classfile.*;
24:
25: /**
26: * This MemberVisitor delegates all visits to each MemberVisitor
27: * in a given list.
28: *
29: * @author Eric Lafortune
30: */
31: public class MultiMemberVisitor implements MemberVisitor {
32: private static final int ARRAY_SIZE_INCREMENT = 5;
33:
34: private MemberVisitor[] memberVisitors;
35: private int memberVisitorCount;
36:
37: public MultiMemberVisitor() {
38: }
39:
40: public MultiMemberVisitor(MemberVisitor[] memberVisitors) {
41: this .memberVisitors = memberVisitors;
42: this .memberVisitorCount = memberVisitors.length;
43: }
44:
45: public void addMemberVisitor(MemberVisitor memberVisitor) {
46: ensureArraySize();
47:
48: memberVisitors[memberVisitorCount++] = memberVisitor;
49: }
50:
51: private void ensureArraySize() {
52: if (memberVisitors == null) {
53: memberVisitors = new MemberVisitor[ARRAY_SIZE_INCREMENT];
54: } else if (memberVisitors.length == memberVisitorCount) {
55: MemberVisitor[] newMemberVisitors = new MemberVisitor[memberVisitorCount
56: + ARRAY_SIZE_INCREMENT];
57: System.arraycopy(memberVisitors, 0, newMemberVisitors, 0,
58: memberVisitorCount);
59: memberVisitors = newMemberVisitors;
60: }
61: }
62:
63: public void visitProgramField(ProgramClass programClass,
64: ProgramField programField) {
65: for (int index = 0; index < memberVisitorCount; index++) {
66: memberVisitors[index].visitProgramField(programClass,
67: programField);
68: }
69: }
70:
71: public void visitProgramMethod(ProgramClass programClass,
72: ProgramMethod programMethod) {
73: for (int index = 0; index < memberVisitorCount; index++) {
74: memberVisitors[index].visitProgramMethod(programClass,
75: programMethod);
76: }
77: }
78:
79: public void visitLibraryField(LibraryClass libraryClass,
80: LibraryField libraryField) {
81: for (int index = 0; index < memberVisitorCount; index++) {
82: memberVisitors[index].visitLibraryField(libraryClass,
83: libraryField);
84: }
85: }
86:
87: public void visitLibraryMethod(LibraryClass libraryClass,
88: LibraryMethod libraryMethod) {
89: for (int index = 0; index < memberVisitorCount; index++) {
90: memberVisitors[index].visitLibraryMethod(libraryClass,
91: libraryMethod);
92: }
93: }
94: }
|