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