/** * Returns a <code>TypeListItem</code> for the given values, and that has been interned into * the given <code>DexFile</code> * @param dexFile The <code>DexFile</code> that this item belongs to * @param typeList A list of the types that this <code>TypeListItem</code> represents * @return a <code>TypeListItem</code> for the given values, and that has been interned into * the given <code>DexFile</code> */ public static TypeListItem internTypeListItem(DexFile dexFile, List<TypeIdItem> typeList) { TypeIdItem[] typeArray = new TypeIdItem[typeList.size()]; typeList.toArray(typeArray); TypeListItem typeListItem = new TypeListItem(dexFile, typeArray); return dexFile.TypeListsSection.intern(typeListItem); }
@Override public int hashCode() { //there's a small possibility that the actual hash code will be 0. If so, we'll //just end up recalculating it each time if (hashCode == 0) calcHashCode(); return hashCode; }
/** {@inheritDoc} */ public int compareTo(ProtoIdItem o) { int result = returnType.compareTo(o.returnType); if (result != 0) { return result; } if (parameters == null) { if (o.parameters == null) { return 0; } return -1; } else if (o.parameters == null) { return 1; } return parameters.compareTo(o.parameters); }
private static RegisterType[] getParameterTypes(TypeListItem typeListItem, int parameterRegisterCount) { assert typeListItem != null; assert parameterRegisterCount == typeListItem.getRegisterCount(); RegisterType[] registerTypes = new RegisterType[parameterRegisterCount]; int registerNum = 0; for (TypeIdItem type: typeListItem.getTypes()) { if (type.getRegisterCount() == 2) { registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, true); registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, false); } else { registerTypes[registerNum++] = RegisterType.getRegisterTypeForTypeIdItem(type); } } return registerTypes; }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, "shorty_descriptor: " + shortyDescriptor.getStringValue()); out.annotate(4, "return_type: " + returnType.getTypeDescriptor()); if (parameters == null) { out.annotate(4, "parameters:"); } else { out.annotate(4, "parameters: " + parameters.getTypeListString("")); } } out.writeInt(shortyDescriptor.getIndex()); out.writeInt(returnType.getIndex()); out.writeInt(parameters == null?0:parameters.getOffset()); }
/** * Helper method to allow easier "inline" retrieval of of the list of TypeIdItems * @param typeListItem the typeListItem to return the types of (can be null) * @return an array of the <code>TypeIdItems</code> in the specified <code>TypeListItem</code>, or null if the * TypeListItem is null */ public static List<TypeIdItem> getTypes(TypeListItem typeListItem) { return typeListItem==null?null:typeListItem.getTypes(); }
/** {@inheritDoc} */ public String getConciseIdentity() { return "type_list: " + getTypeListString(""); }
/** * calculate and cache the hashcode */ private void calcHashCode() { hashCode = returnType.hashCode(); hashCode = 31 * hashCode + (parameters==null?0:parameters.hashCode()); }
/** * @return the number of registers required for the parameters of this <code>ProtoIdItem</code> */ public int getParameterRegisterCount() { if (parameters == null) { return 0; } else { return parameters.getRegisterCount(); } }
/** * Creates a new <code>ProtoIdItem</code> with the given values * @param dexFile The <code>DexFile</code> that this item belongs to * @param returnType the return type * @param parameters a <code>TypeListItem</code> containing a list of the parameter types */ private ProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) { this(dexFile); String shortyString = returnType.toShorty(); if (parameters != null) { shortyString += parameters.getShortyString(); } this.shortyDescriptor = StringIdItem.internStringIdItem(dexFile, shortyString); this.returnType = returnType; this.parameters = parameters; }
paramListItem = TypeListItem.lookupTypeListItem(dexFile, paramList); if (paramListItem == null) { return null;
methodParameterRegisterCount = 0; } else { methodParameterRegisterCount = typeListItem.getRegisterCount(); List<TypeIdItem> parameterTypes = typeListItem.getTypes(); int parameterTypeIndex = 0; while (!registers.pastEnd()) {
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, "class_type: " + classType.getTypeDescriptor()); out.annotate(4, "access_flags: " + AccessFlags.formatAccessFlagsForClass(accessFlags)); out.annotate(4, "superclass_type: " + (superType==null?"":superType.getTypeDescriptor())); out.annotate(4, "interfaces: " + (implementedInterfaces==null?"":implementedInterfaces.getTypeListString(" "))); out.annotate(4, "source_file: " + (sourceFile==null?"":sourceFile.getStringValue())); out.annotate(4, "annotations_off: " + (annotations==null?"":"0x"+Integer.toHexString(annotations.getOffset()))); out.annotate(4, "class_data_off:" + (classData==null?"":"0x"+Integer.toHexString(classData.getOffset()))); out.annotate(4, "static_values_off: " + (staticFieldInitializers==null?"":"0x"+Integer.toHexString(staticFieldInitializers.getOffset()))); } out.writeInt(classType.getIndex()); out.writeInt(accessFlags); out.writeInt(superType==null?-1:superType.getIndex()); out.writeInt(implementedInterfaces==null?0:implementedInterfaces.getOffset()); out.writeInt(sourceFile==null?-1:sourceFile.getIndex()); out.writeInt(annotations==null?0:annotations.getOffset()); out.writeInt(classData==null?0:classData.getOffset()); out.writeInt(staticFieldInitializers==null?0:staticFieldInitializers.getOffset()); }
private String[] loadInterfaces(ClassDefItem classDefItem) { TypeListItem typeList = classDefItem.getInterfaces(); if (typeList != null) { List<TypeIdItem> types = typeList.getTypes(); if (types != null && types.size() > 0) { String[] interfaces = new String[types.size()]; for (int i=0; i<interfaces.length; i++) { interfaces[i] = types.get(i).getTypeDescriptor(); } return interfaces; } } return null; }
/** * @return a string in the format (TTTT..)R where TTTT.. are the parameter types and R is the return type */ public String getPrototypeString() { if (cachedPrototypeString == null) { StringBuilder sb = new StringBuilder("("); if (parameters != null) { sb.append(parameters.getTypeListString("")); } sb.append(")"); sb.append(returnType.getTypeDescriptor()); cachedPrototypeString = sb.toString(); } return cachedPrototypeString; }
/** * calculate and cache the hashcode */ private void calcHashCode() { hashCode = returnType.hashCode(); hashCode = 31 * hashCode + (parameters==null?0:parameters.hashCode()); }
/** * @return the number of registers required for the parameters of this <code>ProtoIdItem</code> */ public int getParameterRegisterCount() { if (parameters == null) { return 0; } else { return parameters.getRegisterCount(); } }
/** * Creates a new <code>ProtoIdItem</code> with the given values * @param dexFile The <code>DexFile</code> that this item belongs to * @param returnType the return type * @param parameters a <code>TypeListItem</code> containing a list of the parameter types */ private ProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) { this(dexFile); String shortyString = returnType.toShorty(); if (parameters != null) { shortyString += parameters.getShortyString(); } this.shortyDescriptor = StringIdItem.internStringIdItem(dexFile, shortyString); this.returnType = returnType; this.parameters = parameters; }
paramListItem = TypeListItem.lookupTypeListItem(dexFile, paramList); if (paramListItem == null) { return null;
private static RegisterType[] getParameterTypes(TypeListItem typeListItem, int parameterRegisterCount) { assert typeListItem != null; assert parameterRegisterCount == typeListItem.getRegisterCount(); RegisterType[] registerTypes = new RegisterType[parameterRegisterCount]; int registerNum = 0; for (TypeIdItem type: typeListItem.getTypes()) { if (type.getRegisterCount() == 2) { registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, true); registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, false); } else { registerTypes[registerNum++] = RegisterType.getRegisterTypeForTypeIdItem(type); } } return registerTypes; }