1/*
2 * Copyright 2012, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package org.jf.dexlib2.iface;
33
34import org.jf.dexlib2.iface.reference.TypeReference;
35
36import javax.annotation.Nonnull;
37import javax.annotation.Nullable;
38import java.util.Set;
39
40/**
41 * This class represents a class definition.
42 *
43 * It also acts as a TypeReference to itself. Any equality/comparison is based on its identity as a TypeReference,
44 * and shouldn't take into account anything other than the type of this class.
45 */
46public interface ClassDef extends TypeReference {
47    /**
48     * Gets the class type.
49     *
50     * This will be a type descriptor per the dex file specification.
51     *
52     * @return The class type
53     */
54    @Override @Nonnull String getType();
55
56    /**
57     * Gets the access flags for this class.
58     *
59     * This will be a combination of the AccessFlags.* flags that are marked as compatible for use with a class.
60     *
61     * @return The access flags for this class
62     */
63    int getAccessFlags();
64
65    /**
66     * Gets the superclass of this class.
67     *
68     * This will only be null if this is the base java.lang.Object class.
69     *
70     * @return The superclass of this class
71     */
72    @Nullable String getSuperclass();
73
74    /**
75     * Gets a set of the interfaces that this class implements.
76     *
77     * @return A set of the interfaces that this class implements
78     */
79    @Nonnull Set<String> getInterfaces();
80
81    /**
82     * Gets the name of the primary source file that this class is defined in, if available.
83     *
84     * This will be the default source file associated with all methods defined in this class. This can be overridden
85     * for sections of an individual method with the SetSourceFile debug item.
86     *
87     * @return The name of the primary source file for this class, or null if not available
88     */
89    @Nullable String getSourceFile();
90
91    /**
92     * Gets a set of the annotations that are applied to this class.
93     *
94     * The annotations in the returned set are guaranteed to have unique types.
95     *
96     * @return A set of the annotations that are applied to this class
97     */
98    @Nonnull Set<? extends Annotation> getAnnotations();
99
100    /**
101     * Gets the static fields that are defined by this class.
102     *
103     * The static fields that are returned must have no duplicates.
104     *
105     * @return The static fields that are defined by this class
106     */
107    @Nonnull Iterable<? extends Field> getStaticFields();
108
109    /**
110     * Gets the instance fields that are defined by this class.
111     *
112     * The instance fields that are returned must have no duplicates.
113     *
114     * @return The instance fields that are defined by this class
115     */
116    @Nonnull Iterable<? extends Field> getInstanceFields();
117
118    /**
119     * Gets all the fields that are defined by this class.
120     *
121     * This is a convenience method that combines getStaticFields() and getInstanceFields()
122     *
123     * The returned fields may be in any order. I.e. It's not safe to assume that all instance fields will come after
124     * all static fields.
125     *
126     * Note that there typically should not be any duplicate fields between the two, but some versions of
127     * dalvik inadvertently allow duplicate static/instance fields, and are supported here for completeness
128     *
129     * @return A set of the fields that are defined by this class
130     */
131    @Nonnull Iterable<? extends Field> getFields();
132
133    /**
134     * Gets the direct methods that are defined by this class.
135     *
136     * The direct methods that are returned must have no duplicates.
137     *
138     * @return The direct methods that are defined by this class.
139     */
140    @Nonnull Iterable<? extends Method> getDirectMethods();
141
142    /**
143     * Gets the virtual methods that are defined by this class.
144     *
145     * The virtual methods that are returned must have no duplicates.
146     *
147     * @return The virtual methods that are defined by this class.
148     */
149    @Nonnull Iterable<? extends Method> getVirtualMethods();
150
151    /**
152     * Gets all the methods that are defined by this class.
153     *
154     * This is a convenience method that combines getDirectMethods() and getVirtualMethods().
155     *
156     * The returned methods may be in any order. I.e. It's not safe to assume that all virtual methods will come after
157     * all direct methods.
158     *
159     * Note that there typically should not be any duplicate methods between the two, but some versions of
160     * dalvik inadvertently allow duplicate direct/virtual methods, and are supported here for completeness
161     *
162     * @return An iterable of the methods that are defined by this class.
163     */
164    @Nonnull Iterable<? extends Method> getMethods();
165}
166