• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, Google LLC
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google LLC nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 package com.android.tools.smali.dexlib2.iface;
32 
33 import javax.annotation.Nonnull;
34 import javax.annotation.Nullable;
35 import java.util.Set;
36 
37 /**
38  * This class represents a specific instance of an annotation applied to a class/field/method/parameter
39  */
40 public interface Annotation extends BasicAnnotation, Comparable<Annotation> {
41     /**
42      * Gets the visibility of this annotation.
43      *
44      * This will be one of the AnnotationVisibility.* constants.
45      *
46      * @return The visibility of this annotation
47      */
getVisibility()48     int getVisibility();
49 
50     /**
51      * Gets the type of this annotation.
52      *
53      * This will be the type descriptor of the class that defines this annotation.
54      *
55      * @return The type of this annotation
56      */
getType()57     @Nonnull @Override String getType();
58 
59     /**
60      * Gets a set of the name/value elements associated with this annotation.
61      *
62      * The elements in the returned set will be unique with respect to the element name.
63      *
64      * @return A set of AnnotationElements
65      */
getElements()66     @Nonnull @Override Set<? extends AnnotationElement> getElements();
67 
68     /**
69      * Returns a hashcode for this Annotation.
70      *
71      * This hashCode is defined to be the following:
72      *
73      * <pre>
74      * {@code
75      * int hashCode = getVisibility();
76      * hashCode = hashCode*31 + getType().hashCode();
77      * hashCode = hashCode*31 + getElements().hashCode();
78      * }</pre>
79      *
80      * @return The hash code value for this Annotation
81      */
hashCode()82     @Override int hashCode();
83 
84     /**
85      * Compares this Annotation to another Annotation for equality.
86      *
87      * This Annotation is equal to another Annotation if all of it's "fields" are equal. That is, if the return values
88      * of getVisibility(), getType(), and getElements() are all equal.
89      *
90      * @param o The object to be compared for equality with this Annotation
91      * @return true if the specified object is equal to this Annotation
92      */
equals(@ullable Object o)93     @Override boolean equals(@Nullable Object o);
94 
95     /**
96      * Compares this Annotation to another Annotation.
97      *
98      * The comparison is based on the value of getVisibility(), getType() and getElements(), in that order. When
99      * comparing the set of elements, the comparison is done with the semantics of
100      * com.android.tools.smali.util.CollectionUtils.compareAsSet(), using the natural ordering of AnnotationElement.
101      *
102      * @param o The Annotation to compare with this Annotation
103      * @return An integer representing the result of the comparison
104      */
compareTo(Annotation o)105     @Override int compareTo(Annotation o);
106 }
107