• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.Dex.Section;
20 import com.android.dex.util.Unsigned;
21 
22 /**
23  * A call_site_id_item: https://source.android.com/devices/tech/dalvik/dex-format#call-site-id-item
24  */
25 public class CallSiteId implements Comparable<CallSiteId> {
26 
27     private final Dex dex;
28     private final int offset;
29 
CallSiteId(Dex dex, int offset)30     public CallSiteId(Dex dex, int offset) {
31         this.dex = dex;
32         this.offset = offset;
33     }
34 
35     @Override
compareTo(CallSiteId o)36     public int compareTo(CallSiteId o) {
37         return Unsigned.compare(offset, o.offset);
38     }
39 
getCallSiteOffset()40     public int getCallSiteOffset() {
41         return offset;
42     }
43 
writeTo(Section out)44     public void writeTo(Section out) {
45         out.writeInt(offset);
46     }
47 
48     @Override
toString()49     public String toString() {
50         if (dex == null) {
51             return String.valueOf(offset);
52         }
53         return dex.protoIds().get(offset).toString();
54     }
55 }
56