~ubuntu-branches/ubuntu/maverick/proguard/maverick

« back to all changes in this revision

Viewing changes to src/proguard/obfuscate/MemberInfoNameConflictFilter.java

  • Committer: Bazaar Package Importer
  • Author(s): Sam Clegg
  • Date: 2005-11-13 09:42:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051113094259-432zf4yyw4890mmn
Tags: 3.4-1
* New upstream release (Closes: #338355)
* debian/control: bump standards version
* debian/copyright: update FSF address
* increase java stack size for proguard and proguardgui

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: MemberInfoNameConflictFilter.java,v 1.3 2005/06/11 13:21:35 eric Exp $
 
2
 *
 
3
 * ProGuard -- shrinking, optimization, and obfuscation of Java class files.
 
4
 *
 
5
 * Copyright (c) 2002-2005 Eric Lafortune (eric@graphics.cornell.edu)
 
6
 *
 
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)
 
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.MemberInfoVisitor;
 
25
 
 
26
import java.util.*;
 
27
 
 
28
/**
 
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.
 
32
 *
 
33
 * @see MemberInfoLinker
 
34
 * @see MemberInfoObfuscator
 
35
 *
 
36
 * @author Eric Lafortune
 
37
 */
 
38
public class MemberInfoNameConflictFilter implements MemberInfoVisitor
 
39
{
 
40
    private static final String CONFLICT = "_ CONFLICT _";
 
41
 
 
42
 
 
43
    private MemberInfoVisitor memberInfoVisitor;
 
44
 
 
45
 
 
46
    /**
 
47
     * Creates a new MemberInfoNameConflictFilter.
 
48
     * @param memberInfoVisitor the <code>MemberInfoVisitor</code> to which
 
49
     *                          visits will be delegated.
 
50
     */
 
51
    public MemberInfoNameConflictFilter(MemberInfoVisitor memberInfoVisitor)
 
52
    {
 
53
        this.memberInfoVisitor = memberInfoVisitor;
 
54
    }
 
55
 
 
56
 
 
57
    // Implementations for MemberInfoVisitor.
 
58
 
 
59
    public void visitProgramFieldInfo(ProgramClassFile programClassFile, ProgramFieldInfo programFieldInfo)
 
60
    {
 
61
        if (hasConflictingName(programFieldInfo))
 
62
        {
 
63
            memberInfoVisitor.visitProgramFieldInfo(programClassFile, programFieldInfo);
 
64
        }
 
65
    }
 
66
 
 
67
 
 
68
    public void visitProgramMethodInfo(ProgramClassFile programClassFile, ProgramMethodInfo programMethodInfo)
 
69
    {
 
70
        if (hasConflictingName(programMethodInfo))
 
71
        {
 
72
            memberInfoVisitor.visitProgramMethodInfo(programClassFile, programMethodInfo);
 
73
        }
 
74
    }
 
75
 
 
76
 
 
77
    public void visitLibraryFieldInfo(LibraryClassFile libraryClassFile, LibraryFieldInfo libraryFieldInfo) {}
 
78
    public void visitLibraryMethodInfo(LibraryClassFile libraryClassFile, LibraryMethodInfo libraryMethodInfo) {}
 
79
 
 
80
 
 
81
    // Small utility methods.
 
82
 
 
83
    /**
 
84
     * Marks the given class member as having a conflicting name.
 
85
     * @param memberInfo the class member.
 
86
     */
 
87
    static void markConflictingName(MemberInfo memberInfo)
 
88
    {
 
89
        MemberInfoObfuscator.setNewMemberName(memberInfo, CONFLICT);
 
90
    }
 
91
 
 
92
 
 
93
    /**
 
94
     * Returns whether the given class member has been marked as having a
 
95
     * conflicting name.
 
96
     * @param memberInfo the class member.
 
97
     */
 
98
    static boolean hasConflictingName(MemberInfo memberInfo)
 
99
    {
 
100
        String newName = MemberInfoObfuscator.newMemberName(memberInfo);
 
101
 
 
102
        return newName != null &&
 
103
               newName.equals(CONFLICT);
 
104
    }
 
105
}