1
/* $Id: MemberInfoNameConflictFilter.java,v 1.3 2005/06/11 13:21:35 eric Exp $
3
* ProGuard -- shrinking, optimization, and obfuscation of Java class files.
5
* Copyright (c) 2002-2005 Eric Lafortune (eric@graphics.cornell.edu)
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the Free
9
* Software Foundation; either version 2 of the License, or (at your option)
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
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
21
package proguard.obfuscate;
23
import proguard.classfile.*;
24
import proguard.classfile.visitor.MemberInfoVisitor;
29
* This <code>MemberInfoVisitor</code> delegates its visits to another given
30
* <code>MemberInfoVisitor</code>, but only when the visited member has been
31
* marked as having a conflicting name.
33
* @see MemberInfoLinker
34
* @see MemberInfoObfuscator
36
* @author Eric Lafortune
38
public class MemberInfoNameConflictFilter implements MemberInfoVisitor
40
private static final String CONFLICT = "_ CONFLICT _";
43
private MemberInfoVisitor memberInfoVisitor;
47
* Creates a new MemberInfoNameConflictFilter.
48
* @param memberInfoVisitor the <code>MemberInfoVisitor</code> to which
49
* visits will be delegated.
51
public MemberInfoNameConflictFilter(MemberInfoVisitor memberInfoVisitor)
53
this.memberInfoVisitor = memberInfoVisitor;
57
// Implementations for MemberInfoVisitor.
59
public void visitProgramFieldInfo(ProgramClassFile programClassFile, ProgramFieldInfo programFieldInfo)
61
if (hasConflictingName(programFieldInfo))
63
memberInfoVisitor.visitProgramFieldInfo(programClassFile, programFieldInfo);
68
public void visitProgramMethodInfo(ProgramClassFile programClassFile, ProgramMethodInfo programMethodInfo)
70
if (hasConflictingName(programMethodInfo))
72
memberInfoVisitor.visitProgramMethodInfo(programClassFile, programMethodInfo);
77
public void visitLibraryFieldInfo(LibraryClassFile libraryClassFile, LibraryFieldInfo libraryFieldInfo) {}
78
public void visitLibraryMethodInfo(LibraryClassFile libraryClassFile, LibraryMethodInfo libraryMethodInfo) {}
81
// Small utility methods.
84
* Marks the given class member as having a conflicting name.
85
* @param memberInfo the class member.
87
static void markConflictingName(MemberInfo memberInfo)
89
MemberInfoObfuscator.setNewMemberName(memberInfo, CONFLICT);
94
* Returns whether the given class member has been marked as having a
96
* @param memberInfo the class member.
98
static boolean hasConflictingName(MemberInfo memberInfo)
100
String newName = MemberInfoObfuscator.newMemberName(memberInfo);
102
return newName != null &&
103
newName.equals(CONFLICT);