• 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.reference;
32 
33 import javax.annotation.Nonnull;
34 import javax.annotation.Nullable;
35 import java.util.List;
36 
37 /**
38  * This class represents a reference to a method.
39  */
40 public interface MethodReference extends Reference, Comparable<MethodReference> {
41     /**
42      * Gets the type of the class that defines the referenced method.
43      *
44      * @return The type of the class that defines the referenced method
45      */
getDefiningClass()46     @Nonnull String getDefiningClass();
47 
48     /**
49      * Gets the name of the referenced method.
50      *
51      * @return The name of the referenced method
52      */
getName()53     @Nonnull String getName();
54 
55     /**
56      * Gets a list of the types of the parameters of this method.
57      *
58      * @return A list of the parameter types of this method, as strings.
59      */
getParameterTypes()60     @Nonnull List<? extends CharSequence> getParameterTypes();
61 
62     /**
63      * Gets the return type of the referenced method.
64      *
65      * @return The return type of the referenced method.
66      */
getReturnType()67     @Nonnull String getReturnType();
68 
69     /**
70      * Returns a hashcode for this MethodReference.
71      *
72      * This hashCode is defined to be the following:
73      *
74      * <pre>
75      * {@code
76      * int hashCode =  getDefiningClass().hashCode();
77      * hashCode = hashCode*31 + getName().hashCode();
78      * hashCode = hashCode*31 + getReturnType().hashCode();
79      * hashCode = hashCode*31 + CharSequenceUtils.listHashCode(getParameters());
80      * }</pre>
81      *
82      * @return The hash code value for this MethodReference
83      */
hashCode()84     @Override int hashCode();
85 
86     /**
87      * Compares this MethodReference to another MethodReference for equality.
88      *
89      * This MethodReference is equal to another MethodReference if all of it's "fields" are equal. That is, if
90      * the return values of getDefiningClass(), getName(), getReturnType() and getParameterTypes() are all equal.
91      *
92      * Equality for getParameters() should be tested by comparing the string representation of each element. I.e.
93      * CharSequenceUtils.listEquals(this.getParameterTypes(), other.getParameterTypes())
94      *
95      * @param o The object to be compared for equality with this MethodReference
96      * @return true if the specified object is equal to this MethodReference
97      */
equals(@ullable Object o)98     @Override boolean equals(@Nullable Object o);
99 
100     /**
101      * Compare this MethodReference to another MethodReference.
102      *
103      * The comparison is based on the comparison of the return values of getDefiningClass(), getName(),
104      * getReturnType() and getParameters(), in that order. getParameters() should be compared using the semantics
105      * of com.android.tools.smali.util.CollectionUtils.compareAsList()
106      *
107      * @param o The MethodReference to compare with this MethodReference
108      * @return An integer representing the result of the comparison
109      */
compareTo(@onnull MethodReference o)110     @Override int compareTo(@Nonnull MethodReference o);
111 }
112