• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 package com.android.tools.r8.dex;
5 
6 import com.android.tools.r8.graph.DexCallSite;
7 import com.android.tools.r8.graph.DexField;
8 import com.android.tools.r8.graph.DexItem;
9 import com.android.tools.r8.graph.DexMethod;
10 import com.android.tools.r8.graph.DexMethodHandle;
11 import com.android.tools.r8.graph.DexProgramClass;
12 import com.android.tools.r8.graph.DexProto;
13 import com.android.tools.r8.graph.DexString;
14 import com.android.tools.r8.graph.DexType;
15 import com.android.tools.r8.graph.IndexedDexItem;
16 
17 /**
18  * Common interface for constant pools.
19  *
20  * <p>This is semantically a wrapper around a number of sets for all subtypes of
21  * {@link IndexedDexItem}. <b>Items should not be added directly to this collection.</b> Instead see
22  * {@link DexItem#collectIndexedItems}.
23  *
24  * <p>Note that the various add methods of this class are not transitive, i.e., they do not add
25  * components of the {@link IndexedDexItem} itself. Use a call to
26  * {@link IndexedDexItem#collectIndexedItems} for this.
27  */
28 public interface IndexedItemCollection {
29 
30   /**
31    * Adds the given class to the collection.
32    *
33    * <p>Does not add the class' components.
34    *
35    * @return true if the class was not in the pool before.
36    */
addClass(DexProgramClass dexProgramClass)37   boolean addClass(DexProgramClass dexProgramClass);
38 
39   /**
40    * Adds the given field to the collection.
41    *
42    * <p>Does not add the field's components.
43    *
44    * @return true if the field was not in the pool before.
45    */
addField(DexField field)46   boolean addField(DexField field);
47 
48   /**
49    * Adds the given method to the collection.
50    *
51    * <p>Does not add the method's components.
52    *
53    * @return true if the method was not in the pool before.
54    */
addMethod(DexMethod method)55   boolean addMethod(DexMethod method);
56 
57   /**
58    * Adds the given class to the collection.
59    *
60    * <p>Does not add the classes components.
61    *
62    * @return true if the class was not in the pool before.
63    */
addString(DexString string)64   boolean addString(DexString string);
65 
66   /**
67    * Adds the given proto to the collection.
68    *
69    * <p>Does not add the proto's components.
70    *
71    * @return true if the proto was not in the pool before.
72    */
addProto(DexProto proto)73   boolean addProto(DexProto proto);
74 
75   /**
76    * Adds the given type to the collection.
77    *
78    * <p>Does not add the type's components.
79    *
80    * @return true if the type was not in the pool before.
81    */
addType(DexType type)82   boolean addType(DexType type);
83 
84   /**
85    * Adds the given call site to the collection.
86    *
87    * <p>Does not add the call site's components.
88    *
89    * @return true if the call site was not in the pool before.
90    */
addCallSite(DexCallSite callSite)91   boolean addCallSite(DexCallSite callSite);
92 
93   /**
94    * Adds the given method handle to the collection.
95    *
96    * <p>Does not add the method handle site's components.
97    *
98    * @return true if the method handle was not in the pool before.
99    */
addMethodHandle(DexMethodHandle methodHandle)100   boolean addMethodHandle(DexMethodHandle methodHandle);
101 
getRenamedName(DexMethod method)102   default DexString getRenamedName(DexMethod method) {
103     return method.name;
104   }
105 
getRenamedName(DexField field)106   default DexString getRenamedName(DexField field) {
107     return field.name;
108   }
109 
getRenamedDescriptor(DexType type)110   default DexString getRenamedDescriptor(DexType type) {
111     return type.descriptor;
112   }
113 }
114