MemberSpecification.java revision b72c5c2e5482cf10117b2b25f642f7616b2326c3
1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2009 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 */
21package proguard;
22
23
24/**
25 * This class stores a specification of class members. The specification is
26 * template-based: the class member names and descriptors can contain wildcards.
27 *
28 * @author Eric Lafortune
29 */
30public class MemberSpecification
31{
32    public int    requiredSetAccessFlags;
33    public int    requiredUnsetAccessFlags;
34    public final String annotationType;
35    public final String name;
36    public final String descriptor;
37
38
39    /**
40     * Creates a new option to keep all possible class members.
41     */
42    public MemberSpecification()
43    {
44        this(0,
45             0,
46             null,
47             null,
48             null);
49    }
50
51
52    /**
53     * Creates a new option to keep the specified class member(s).
54     *
55     * @param requiredSetAccessFlags   the class access flags that must be set
56     *                                 in order for the class to apply.
57     * @param requiredUnsetAccessFlags the class access flags that must be unset
58     *                                 in order for the class to apply.
59     * @param annotationType           the name of the class that must be an
60     *                                 annotation in order for the class member
61     *                                 to apply. The name may be null to specify
62     *                                 that no annotation is required.
63     * @param name                     the class member name. The name may be
64     *                                 null to specify any class member or it
65     *                                 may contain "*" or "?" wildcards.
66     * @param descriptor               the class member descriptor. The
67     *                                 descriptor may be null to specify any
68     *                                 class member or it may contain
69     *                                 "**", "*", or "?" wildcards.
70     */
71    public MemberSpecification(int    requiredSetAccessFlags,
72                               int    requiredUnsetAccessFlags,
73                               String annotationType,
74                               String name,
75                               String descriptor)
76    {
77        this.requiredSetAccessFlags   = requiredSetAccessFlags;
78        this.requiredUnsetAccessFlags = requiredUnsetAccessFlags;
79        this.annotationType           = annotationType;
80        this.name                     = name;
81        this.descriptor               = descriptor;
82    }
83
84
85
86    // Implementations for Object.
87
88    public boolean equals(Object object)
89    {
90        if (object == null ||
91            this.getClass() != object.getClass())
92        {
93            return false;
94        }
95
96        MemberSpecification other = (MemberSpecification)object;
97        return
98            (this.requiredSetAccessFlags   == other.requiredSetAccessFlags                                                                      ) &&
99            (this.requiredUnsetAccessFlags == other.requiredUnsetAccessFlags                                                                    ) &&
100            (this.annotationType == null ? other.annotationType == null : this.annotationType.equals(other.annotationType)) &&
101            (this.name           == null ? other.name           == null : this.name.equals(other.name)                    ) &&
102            (this.descriptor     == null ? other.descriptor     == null : this.descriptor.equals(other.descriptor)        );
103    }
104
105    public int hashCode()
106    {
107        return
108            (requiredSetAccessFlags                                ) ^
109            (requiredUnsetAccessFlags                              ) ^
110            (annotationType == null ? 0 : annotationType.hashCode()) ^
111            (name           == null ? 0 : name.hashCode()          ) ^
112            (descriptor     == null ? 0 : descriptor.hashCode()    );
113    }
114}
115