public void intern(@Nonnull ClassDef classDef) {
PoolClassDef poolClassDef = new PoolClassDef(classDef);
PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
if (prev != null) {
throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
}
typePool.intern(poolClassDef.getType());
typePool.internNullable(poolClassDef.getSuperclass());
typeListPool.intern(poolClassDef.getInterfaces());
stringPool.internNullable(poolClassDef.getSourceFile());
HashSet<String> fields = new HashSet<String>();
for (Field field: poolClassDef.getFields()) {
String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
if (!fields.add(fieldDescriptor)) {
throw new ExceptionWithContext("Multiple definitions for field %s->%s",
poolClassDef.getType(), fieldDescriptor);
}
fieldPool.intern(field);
EncodedValue initialValue = field.getInitialValue();
if (initialValue != null) {
DexPool.internEncodedValue(initialValue, stringPool, typePool, fieldPool, methodPool);
}
annotationSetPool.intern(field.getAnnotations());
}
HashSet<String> methods = new HashSet<String>();
for (PoolMethod method: poolClassDef.getMethods()) {
String methodDescriptor = ReferenceUtil.getMethodDescriptor(method, true);
if (!methods.add(methodDescriptor)) {
throw new ExceptionWithContext("Multiple definitions for method %s->%s",
poolClassDef.getType(), methodDescriptor);
}
methodPool.intern(method);
internCode(method);
internDebug(method);