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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* $Id: ClassSpecification.java,v 1.4 2005/06/11 13:13:15 eric Exp $
 *
 * ProGuard -- shrinking, optimization, and obfuscation of Java class files.
 *
 * Copyright (c) 2002-2005 Eric Lafortune (eric@graphics.cornell.edu)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package proguard;

import java.util.*;


/**
 * This class stores a specification of classes and possibly class members.
 * The specification is template-based: the class names and class member names
 * and descriptors can contain wildcards. Classes can be specified explicitly,
 * or as extensions or implementations in the class hierarchy.
 *
 * @author Eric Lafortune
 */
public class ClassSpecification implements Cloneable
{
    public int     requiredSetAccessFlags;
    public int     requiredUnsetAccessFlags;
    public String  className;
    public String  extendsClassName;
    public boolean markClassFiles;
    public boolean markConditionally;
    public String  comments;

    public List    fieldSpecifications;
    public List    methodSpecifications;


    /**
     * Creates a new option to keep all possible class(es).
     * The option doesn't have comments.
     */
    public ClassSpecification()
    {
        this(0,
             0,
             null,
             null,
             true,
             false);
    }


    /**
     * Creates a new option to keep the specified class(es).
     * The option doesn't have comments.
     *
     * @param requiredSetAccessFlags   the class access flags that must be set
     *                                 in order for the class to apply.
     * @param requiredUnsetAccessFlags the class access flags that must be unset
     *                                 in order for the class to apply.
     * @param className                the class name. The name may be null to
     *                                 specify any class, or it may contain
     *                                 "**", "*", or "?" wildcards.
     * @param extendsClassName         the name of the class that the class must
     *                                 extend or implement in order to apply.
     *                                 The name may be null to specify any class.
     * @param markClassFiles           specifies whether to mark the class files.
     *                                 If false, only class members are marked.
     *                                 If true, the class files are marked as
     *                                 well.
     * @param markConditionally        specifies whether to mark the class files
     *                                 and class members conditionally.
     *                                 If true, class files and class members
     *                                 are marked, on the condition that all
     *                                 specified class members are present.
     */
    public ClassSpecification(int     requiredSetAccessFlags,
                               int     requiredUnsetAccessFlags,
                               String  className,
                               String  extendsClassName,
                               boolean markClassFiles,
                               boolean markConditionally)
    {
        this(requiredSetAccessFlags,
             requiredUnsetAccessFlags,
             className,
             extendsClassName,
             markClassFiles,
             markConditionally,
             null);
    }


    /**
     * Creates a new option to keep the specified class(es).
     *
     * @param requiredSetAccessFlags   the class access flags that must be set
     *                                 in order for the class to apply.
     * @param requiredUnsetAccessFlags the class access flags that must be unset
     *                                 in order for the class to apply.
     * @param className                the class name. The name may be null to
     *                                 specify any class, or it may contain
     *                                 "**", "*", or "?" wildcards.
     * @param extendsClassName         the name of the class that the class must
     *                                 extend or implement in order to apply.
     *                                 The name may be null to specify any class.
     * @param markClassFiles           specifies whether to mark the class files.
     *                                 If false, only class members are marked.
     *                                 If true, the class files are marked as
     *                                 well.
     * @param markConditionally        specifies whether to mark the class files
     *                                 and class members conditionally.
     *                                 If true, class files and class members
     *                                 are marked, on the condition that all
     *                                 specified class members are present.
     * @param comments                 provides optional comments on this option.
     */
    public ClassSpecification(int     requiredSetAccessFlags,
                               int     requiredUnsetAccessFlags,
                               String  className,
                               String  extendsClassName,
                               boolean markClassFiles,
                               boolean markConditionally,
                               String  comments)
    {
        this.requiredSetAccessFlags   = requiredSetAccessFlags;
        this.requiredUnsetAccessFlags = requiredUnsetAccessFlags;
        this.className                = className;
        this.extendsClassName         = extendsClassName;
        this.markClassFiles           = markClassFiles;
        this.markConditionally        = markConditionally;
        this.comments                 = comments;
    }


    /**
     * Specifies to keep the specified field(s) of this option's class(es).
     *
     * @param fieldSpecification the field specification.
     */
    public void addField(ClassMemberSpecification fieldSpecification)
    {
        if (fieldSpecifications == null)
        {
            fieldSpecifications = new ArrayList();
        }

        fieldSpecifications.add(fieldSpecification);
    }


    /**
     * Specifies to keep the specified method(s) of this option's class(es).
     *
     * @param methodSpecification the method specification.
     */
    public void addMethod(ClassMemberSpecification methodSpecification)
    {
        if (methodSpecifications == null)
        {
            methodSpecifications = new ArrayList();
        }

        methodSpecifications.add(methodSpecification);
    }



    // Implementations for Object.

    public boolean equals(Object object)
    {
        if (this.getClass() != object.getClass())
        {
            return false;
        }

        ClassSpecification other = (ClassSpecification)object;
        return
            (this.requiredSetAccessFlags   == other.requiredSetAccessFlags  ) &&
            (this.requiredUnsetAccessFlags == other.requiredUnsetAccessFlags) &&
            (this.markClassFiles           == other.markClassFiles          ) &&
            (this.markConditionally        == other.markConditionally       ) &&
            (this.className            == null ? other.className            == null : this.className.equals(other.className))                     &&
            (this.extendsClassName     == null ? other.extendsClassName     == null : this.extendsClassName.equals(other.extendsClassName))       &&
            (this.fieldSpecifications  == null ? other.fieldSpecifications  == null : this.fieldSpecifications.equals(other.fieldSpecifications)) &&
            (this.methodSpecifications == null ? other.methodSpecifications == null : this.methodSpecifications.equals(other.methodSpecifications));
    }

    public int hashCode()
    {
        return
            requiredSetAccessFlags                                               ^
            requiredUnsetAccessFlags                                             ^
            (className            == null ? 0 : className.hashCode()           ) ^
            (extendsClassName     == null ? 0 : extendsClassName.hashCode()    ) ^
            (markClassFiles               ? 0 : 1                              ) ^
            (markConditionally            ? 0 : 2                              ) ^
            (fieldSpecifications  == null ? 0 : fieldSpecifications.hashCode() ) ^
            (methodSpecifications == null ? 0 : methodSpecifications.hashCode());
    }

    public Object clone()
    {
        try
        {
            return super.clone();
        }
        catch (CloneNotSupportedException e)
        {
            return null;
        }
    }
}