xref: /aosp_15_r20/dalvik/dx/src/com/android/dex/MethodId.java (revision 055d459012065f78d96b68be8421640240ddf631)
1*055d4590SKeyi Gui /*
2*055d4590SKeyi Gui  * Copyright (C) 2011 The Android Open Source Project
3*055d4590SKeyi Gui  *
4*055d4590SKeyi Gui  * Licensed under the Apache License, Version 2.0 (the "License");
5*055d4590SKeyi Gui  * you may not use this file except in compliance with the License.
6*055d4590SKeyi Gui  * You may obtain a copy of the License at
7*055d4590SKeyi Gui  *
8*055d4590SKeyi Gui  *      http://www.apache.org/licenses/LICENSE-2.0
9*055d4590SKeyi Gui  *
10*055d4590SKeyi Gui  * Unless required by applicable law or agreed to in writing, software
11*055d4590SKeyi Gui  * distributed under the License is distributed on an "AS IS" BASIS,
12*055d4590SKeyi Gui  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*055d4590SKeyi Gui  * See the License for the specific language governing permissions and
14*055d4590SKeyi Gui  * limitations under the License.
15*055d4590SKeyi Gui  */
16*055d4590SKeyi Gui 
17*055d4590SKeyi Gui package com.android.dex;
18*055d4590SKeyi Gui 
19*055d4590SKeyi Gui import com.android.dex.util.Unsigned;
20*055d4590SKeyi Gui 
21*055d4590SKeyi Gui public final class MethodId implements Comparable<MethodId> {
22*055d4590SKeyi Gui     private final Dex dex;
23*055d4590SKeyi Gui     private final int declaringClassIndex;
24*055d4590SKeyi Gui     private final int protoIndex;
25*055d4590SKeyi Gui     private final int nameIndex;
26*055d4590SKeyi Gui 
MethodId(Dex dex, int declaringClassIndex, int protoIndex, int nameIndex)27*055d4590SKeyi Gui     public MethodId(Dex dex, int declaringClassIndex, int protoIndex, int nameIndex) {
28*055d4590SKeyi Gui         this.dex = dex;
29*055d4590SKeyi Gui         this.declaringClassIndex = declaringClassIndex;
30*055d4590SKeyi Gui         this.protoIndex = protoIndex;
31*055d4590SKeyi Gui         this.nameIndex = nameIndex;
32*055d4590SKeyi Gui     }
33*055d4590SKeyi Gui 
getDeclaringClassIndex()34*055d4590SKeyi Gui     public int getDeclaringClassIndex() {
35*055d4590SKeyi Gui         return declaringClassIndex;
36*055d4590SKeyi Gui     }
37*055d4590SKeyi Gui 
getProtoIndex()38*055d4590SKeyi Gui     public int getProtoIndex() {
39*055d4590SKeyi Gui         return protoIndex;
40*055d4590SKeyi Gui     }
41*055d4590SKeyi Gui 
getNameIndex()42*055d4590SKeyi Gui     public int getNameIndex() {
43*055d4590SKeyi Gui         return nameIndex;
44*055d4590SKeyi Gui     }
45*055d4590SKeyi Gui 
46*055d4590SKeyi Gui     @Override
compareTo(MethodId other)47*055d4590SKeyi Gui     public int compareTo(MethodId other) {
48*055d4590SKeyi Gui         if (declaringClassIndex != other.declaringClassIndex) {
49*055d4590SKeyi Gui             return Unsigned.compare(declaringClassIndex, other.declaringClassIndex);
50*055d4590SKeyi Gui         }
51*055d4590SKeyi Gui         if (nameIndex != other.nameIndex) {
52*055d4590SKeyi Gui             return Unsigned.compare(nameIndex, other.nameIndex);
53*055d4590SKeyi Gui         }
54*055d4590SKeyi Gui         return Unsigned.compare(protoIndex, other.protoIndex);
55*055d4590SKeyi Gui     }
56*055d4590SKeyi Gui 
writeTo(Dex.Section out)57*055d4590SKeyi Gui     public void writeTo(Dex.Section out) {
58*055d4590SKeyi Gui         out.writeUnsignedShort(declaringClassIndex);
59*055d4590SKeyi Gui         out.writeUnsignedShort(protoIndex);
60*055d4590SKeyi Gui         out.writeInt(nameIndex);
61*055d4590SKeyi Gui     }
62*055d4590SKeyi Gui 
63*055d4590SKeyi Gui     @Override
toString()64*055d4590SKeyi Gui     public String toString() {
65*055d4590SKeyi Gui         if (dex == null) {
66*055d4590SKeyi Gui             return declaringClassIndex + " " + protoIndex + " " + nameIndex;
67*055d4590SKeyi Gui         }
68*055d4590SKeyi Gui         return dex.typeNames().get(declaringClassIndex)
69*055d4590SKeyi Gui                 + "." + dex.strings().get(nameIndex)
70*055d4590SKeyi Gui                 + dex.readTypeList(dex.protoIds().get(protoIndex).getParametersOffset());
71*055d4590SKeyi Gui     }
72*055d4590SKeyi Gui }
73