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.obfuscate;
22:
23: import proguard.classfile.*;
24: import proguard.classfile.visitor.*;
25:
26: /**
27: * This <code>ClassVisitor</code> and <code>MemberVisitor</code>
28: * marks names of the classes and class members it visits. The marked names
29: * will remain unchanged in the obfuscation step.
30: *
31: * @see ClassObfuscator
32: * @see MemberObfuscator
33: *
34: * @author Eric Lafortune
35: */
36: class NameMarker implements ClassVisitor, MemberVisitor {
37: // Implementations for ClassVisitor.
38:
39: public void visitProgramClass(ProgramClass programClass) {
40: keepClassName(programClass);
41: }
42:
43: public void visitLibraryClass(LibraryClass libraryClass) {
44: keepClassName(libraryClass);
45: }
46:
47: // Implementations for MemberVisitor.
48:
49: public void visitProgramField(ProgramClass programClass,
50: ProgramField programField) {
51: keepFieldName(programClass, programField);
52: }
53:
54: public void visitProgramMethod(ProgramClass programClass,
55: ProgramMethod programMethod) {
56: keepMethodName(programClass, programMethod);
57: }
58:
59: public void visitLibraryField(LibraryClass libraryClass,
60: LibraryField libraryField) {
61: keepFieldName(libraryClass, libraryField);
62: }
63:
64: public void visitLibraryMethod(LibraryClass libraryClass,
65: LibraryMethod libraryMethod) {
66: keepMethodName(libraryClass, libraryMethod);
67: }
68:
69: // Small utility method.
70:
71: /**
72: * Ensures the name of the given class name will be kept.
73: */
74: public void keepClassName(Clazz clazz) {
75: ClassObfuscator.setNewClassName(clazz, clazz.getName());
76: }
77:
78: /**
79: * Ensures the name of the given field name will be kept.
80: */
81: private void keepFieldName(Clazz clazz, Field field) {
82: MemberObfuscator.setFixedNewMemberName(field, field
83: .getName(clazz));
84: }
85:
86: /**
87: * Ensures the name of the given method name will be kept.
88: */
89: private void keepMethodName(Clazz clazz, Method method) {
90: String name = method.getName(clazz);
91:
92: if (!name.equals(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)
93: && !name
94: .equals(ClassConstants.INTERNAL_METHOD_NAME_INIT)) {
95: MemberObfuscator.setFixedNewMemberName(method, method
96: .getName(clazz));
97: }
98: }
99: }
|