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 32 package org.jf.dexlib2.iface; 33 34 import org.jf.dexlib2.iface.reference.TypeReference; 35 36 import javax.annotation.Nonnull; 37 import javax.annotation.Nullable; 38 import java.util.List; 39 import java.util.Set; 40 41 /** 42 * This class represents a class definition. 43 * 44 * It also acts as a TypeReference to itself. Any equality/comparison is based on its identity as a TypeReference, 45 * and shouldn't take into account anything other than the type of this class. 46 */ 47 public interface ClassDef extends TypeReference, Annotatable { 48 /** 49 * Gets the class type. 50 * 51 * This will be a type descriptor per the dex file specification. 52 * 53 * @return The class type 54 */ getType()55 @Override @Nonnull String getType(); 56 57 /** 58 * Gets the access flags for this class. 59 * 60 * This will be a combination of the AccessFlags.* flags that are marked as compatible for use with a class. 61 * 62 * @return The access flags for this class 63 */ getAccessFlags()64 int getAccessFlags(); 65 66 /** 67 * Gets the superclass of this class. 68 * 69 * This will only be null if this is the base java.lang.Object class. 70 * 71 * @return The superclass of this class 72 */ getSuperclass()73 @Nullable String getSuperclass(); 74 75 /** 76 * Gets a list of the interfaces that this class implements. 77 * 78 * @return A list of the interfaces that this class implements 79 */ getInterfaces()80 @Nonnull List<String> getInterfaces(); 81 82 /** 83 * Gets the name of the primary source file that this class is defined in, if available. 84 * 85 * This will be the default source file associated with all methods defined in this class. This can be overridden 86 * for sections of an individual method with the SetSourceFile debug item. 87 * 88 * @return The name of the primary source file for this class, or null if not available 89 */ getSourceFile()90 @Nullable String getSourceFile(); 91 92 /** 93 * Gets a set of the annotations that are applied to this class. 94 * 95 * The annotations in the returned set are guaranteed to have unique types. 96 * 97 * @return A set of the annotations that are applied to this class 98 */ getAnnotations()99 @Override @Nonnull Set<? extends Annotation> getAnnotations(); 100 101 /** 102 * Gets the static fields that are defined by this class. 103 * 104 * The static fields that are returned must have no duplicates. 105 * 106 * @return The static fields that are defined by this class 107 */ getStaticFields()108 @Nonnull Iterable<? extends Field> getStaticFields(); 109 110 /** 111 * Gets the instance fields that are defined by this class. 112 * 113 * The instance fields that are returned must have no duplicates. 114 * 115 * @return The instance fields that are defined by this class 116 */ getInstanceFields()117 @Nonnull Iterable<? extends Field> getInstanceFields(); 118 119 /** 120 * Gets all the fields that are defined by this class. 121 * 122 * This is a convenience method that combines getStaticFields() and getInstanceFields() 123 * 124 * The returned fields may be in any order. I.e. It's not safe to assume that all instance fields will come after 125 * all static fields. 126 * 127 * Note that there typically should not be any duplicate fields between the two, but some versions of 128 * dalvik inadvertently allow duplicate static/instance fields, and are supported here for completeness 129 * 130 * @return A set of the fields that are defined by this class 131 */ getFields()132 @Nonnull Iterable<? extends Field> getFields(); 133 134 /** 135 * Gets the direct methods that are defined by this class. 136 * 137 * The direct methods that are returned must have no duplicates. 138 * 139 * @return The direct methods that are defined by this class. 140 */ getDirectMethods()141 @Nonnull Iterable<? extends Method> getDirectMethods(); 142 143 /** 144 * Gets the virtual methods that are defined by this class. 145 * 146 * The virtual methods that are returned must have no duplicates. 147 * 148 * @return The virtual methods that are defined by this class. 149 */ getVirtualMethods()150 @Nonnull Iterable<? extends Method> getVirtualMethods(); 151 152 /** 153 * Gets all the methods that are defined by this class. 154 * 155 * This is a convenience method that combines getDirectMethods() and getVirtualMethods(). 156 * 157 * The returned methods may be in any order. I.e. It's not safe to assume that all virtual methods will come after 158 * all direct methods. 159 * 160 * Note that there typically should not be any duplicate methods between the two, but some versions of 161 * dalvik inadvertently allow duplicate direct/virtual methods, and are supported here for completeness 162 * 163 * @return An iterable of the methods that are defined by this class. 164 */ getMethods()165 @Nonnull Iterable<? extends Method> getMethods(); 166 } 167