Java Code Examples for com.android.dx.rop.cst.CstString

The following examples show how to use com.android.dx.rop.cst.CstString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: buck   Source File: ClassDefItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance. Its sets of members and annotations are
 * initially empty.
 *
 * @param thisClass {@code non-null;} type constant for this class
 * @param accessFlags access flags
 * @param superclass {@code null-ok;} superclass or {@code null} if
 * this class is a/the root class
 * @param interfaces {@code non-null;} list of implemented interfaces
 * @param sourceFile {@code null-ok;} source file name or
 * {@code null} if unknown
 */
public ClassDefItem(CstType thisClass, int accessFlags,
        CstType superclass, TypeList interfaces, CstString sourceFile) {
    if (thisClass == null) {
        throw new NullPointerException("thisClass == null");
    }

    /*
     * TODO: Maybe check accessFlags and superclass, at
     * least for easily-checked stuff?
     */

    if (interfaces == null) {
        throw new NullPointerException("interfaces == null");
    }

    this.thisClass = thisClass;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces =
        (interfaces.size() == 0) ? null :  new TypeListItem(interfaces);
    this.sourceFile = sourceFile;
    this.classData = new ClassDataItem(thisClass);
    this.staticValuesItem = null;
    this.annotationsDirectory = new AnnotationsDirectoryItem();
}
 
Example 2
Source Project: buck   Source File: DexFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    IndexedItem item;

    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else {
        return null;
    }
}
 
Example 3
Source Project: J2ME-Loader   Source File: LocalVariableList.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an instance which is the result of merging the two
 * given instances, where one instance should have only type
 * descriptors and the other only type signatures. The merged
 * result is identical to the one with descriptors, except that
 * any element whose {name, index, start, length} matches an
 * element in the signature list gets augmented with the
 * corresponding signature. The result is immutable.
 *
 * @param descriptorList {@code non-null;} list with descriptors
 * @param signatureList {@code non-null;} list with signatures
 * @return {@code non-null;} the merged result
 */
public static LocalVariableList mergeDescriptorsAndSignatures(
        LocalVariableList descriptorList,
        LocalVariableList signatureList) {
    int descriptorSize = descriptorList.size();
    LocalVariableList result = new LocalVariableList(descriptorSize);

    for (int i = 0; i < descriptorSize; i++) {
        Item item = descriptorList.get(i);
        Item signatureItem = signatureList.itemToLocal(item);
        if (signatureItem != null) {
            CstString signature = signatureItem.getSignature();
            item = item.withSignature(signature);
        }
        result.set(i, item);
    }

    result.setImmutable();
    return result;
}
 
Example 4
Source Project: Box   Source File: DexFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        protoIds.intern(((CstProtoRef) cst).getPrototype());
    } else if (cst instanceof CstMethodHandle) {
        methodHandles.intern((CstMethodHandle) cst);
    }
}
 
Example 5
Source Project: buck   Source File: StringIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given string, which must have been added
 * to this instance.
 *
 * @param string {@code non-null;} the string to look up
 * @return {@code >= 0;} the string's index
 */
public int indexOf(CstString string) {
    if (string == null) {
        throw new NullPointerException("string == null");
    }

    throwIfNotPrepared();

    StringIdItem s = strings.get(string);

    if (s == null) {
        throw new IllegalArgumentException("not found");
    }

    return s.getIndex();
}
 
Example 6
Source Project: J2ME-Loader   Source File: DexFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst == null) {
        throw new NullPointerException("cst == null");
    }
}
 
Example 7
Source Project: Box   Source File: BasicBlocker.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitConstant(int opcode, int offset, int length,
        Constant cst, int value) {
    visitCommon(offset, length, true);

    if (cst instanceof CstMemberRef || cst instanceof CstType ||
        cst instanceof CstString || cst instanceof CstInvokeDynamic ||
        cst instanceof CstMethodHandle || cst instanceof CstProtoRef) {
        /*
         * Instructions with these sorts of constants have the
         * possibility of throwing, so this instruction needs to
         * end its block (since it can throw, and possible-throws
         * are branch points).
         */
        visitThrowing(offset, length, true);
    }
}
 
Example 8
Source Project: buck   Source File: Annotation.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add an element to the set of (name, value) pairs for this instance.
 * It is an error to call this method if there is a preexisting element
 * with the same name.
 *
 * @param pair {@code non-null;} the (name, value) pair to add to this instance
 */
public void add(NameValuePair pair) {
    throwIfImmutable();

    if (pair == null) {
        throw new NullPointerException("pair == null");
    }

    CstString name = pair.getName();

    if (elements.get(name) != null) {
        throw new IllegalArgumentException("name already added: " + name);
    }

    elements.put(name, pair);
}
 
Example 9
Source Project: buck   Source File: OutputFinisher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #getAllConstants} which adds all the info for
 * a single {@code RegisterSpec}.
 *
 * @param result {@code non-null;} result set to add to
 * @param spec {@code null-ok;} register spec to add
 */
private static void addConstants(HashSet<Constant> result,
        RegisterSpec spec) {
    if (spec == null) {
        return;
    }

    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();

    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    }

    if (name != null) {
        result.add(name);
    }

    if (signature != null) {
        result.add(signature);
    }
}
 
Example 10
Source Project: Box   Source File: LocalVariableList.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an instance which is the result of merging the two
 * given instances, where one instance should have only type
 * descriptors and the other only type signatures. The merged
 * result is identical to the one with descriptors, except that
 * any element whose {name, index, start, length} matches an
 * element in the signature list gets augmented with the
 * corresponding signature. The result is immutable.
 *
 * @param descriptorList {@code non-null;} list with descriptors
 * @param signatureList {@code non-null;} list with signatures
 * @return {@code non-null;} the merged result
 */
public static LocalVariableList mergeDescriptorsAndSignatures(
        LocalVariableList descriptorList,
        LocalVariableList signatureList) {
    int descriptorSize = descriptorList.size();
    LocalVariableList result = new LocalVariableList(descriptorSize);

    for (int i = 0; i < descriptorSize; i++) {
        Item item = descriptorList.get(i);
        Item signatureItem = signatureList.itemToLocal(item);
        if (signatureItem != null) {
            CstString signature = signatureItem.getSignature();
            item = item.withSignature(signature);
        }
        result.set(i, item);
    }

    result.setImmutable();
    return result;
}
 
Example 11
Source Project: Box   Source File: StdAttributeFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code SourceFile} attribute.
 */
private Attribute sourceFile(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSourceFile(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "source: " + cst);
    }

    return result;
}
 
Example 12
Source Project: Box   Source File: AttConstantValue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param constantValue {@code non-null;} the constant value, which must
 * be an instance of one of: {@code CstString},
 * {@code CstInteger}, {@code CstLong},
 * {@code CstFloat}, or {@code CstDouble}
 */
public AttConstantValue(TypedConstant constantValue) {
    super(ATTRIBUTE_NAME);

    if (!((constantValue instanceof CstString) ||
           (constantValue instanceof CstInteger) ||
           (constantValue instanceof CstLong) ||
           (constantValue instanceof CstFloat) ||
           (constantValue instanceof CstDouble))) {
        if (constantValue == null) {
            throw new NullPointerException("constantValue == null");
        }
        throw new IllegalArgumentException("bad type for constantValue");
    }

    this.constantValue = constantValue;
}
 
Example 13
Source Project: Box   Source File: DexFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstEnumRef) {
        return fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else if (cst instanceof CstMethodHandle) {
        return methodHandles.get(cst);
    } else if (cst instanceof CstCallSiteRef) {
        return callSiteIds.get(cst);
    } else {
        return null;
    }
}
 
Example 14
Source Project: J2ME-Loader   Source File: AttSignature.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param signature {@code non-null;} the signature string
 */
public AttSignature(CstString signature) {
    super(ATTRIBUTE_NAME);

    if (signature == null) {
        throw new NullPointerException("signature == null");
    }

    this.signature = signature;
}
 
Example 15
Source Project: buck   Source File: AnnotationParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a single annotation.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotation
 * @return {@code non-null;} the parsed annotation
 */
private Annotation parseAnnotation(AnnotationVisibility visibility)
        throws IOException {
    requireLength(4);

    int typeIndex = input.readUnsignedShort();
    int numElements = input.readUnsignedShort();
    CstString typeString = (CstString) pool.get(typeIndex);
    CstType type = new CstType(Type.intern(typeString.getString()));

    if (observer != null) {
        parsed(2, "type: " + type.toHuman());
        parsed(2, "num_elements: " + numElements);
    }

    Annotation annotation = new Annotation(type, visibility);

    for (int i = 0; i < numElements; i++) {
        if (observer != null) {
            parsed(0, "elements[" + i + "]:");
            changeIndent(1);
        }

        NameValuePair element = parseElement();
        annotation.add(element);

        if (observer != null) {
            changeIndent(-1);
        }
    }

    annotation.setImmutable();
    return annotation;
}
 
Example 16
Source Project: J2ME-Loader   Source File: SourcePosition.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param sourceFile {@code null-ok;} name of the file of origin or
 * {@code null} if unknown
 * @param address {@code >= -1;} original bytecode address or {@code -1}
 * if unknown
 * @param line {@code >= -1;} original line number or {@code -1} if
 * unknown
 */
public SourcePosition(CstString sourceFile, int address, int line) {
    if (address < -1) {
        throw new IllegalArgumentException("address < -1");
    }

    if (line < -1) {
        throw new IllegalArgumentException("line < -1");
    }

    this.sourceFile = sourceFile;
    this.address = address;
    this.line = line;
}
 
Example 17
Source Project: Box   Source File: EscapeAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Replaces instructions that trigger an ArrayIndexOutofBounds exception
 * with an actual throw of the exception.
 *
 * @param insn {@code non-null;} instruction causing the exception
 * @param index {@code non-null;} index value that is out of bounds
 * @param deletedInsns {@code non-null;} set of instructions marked for
 * deletion
 */
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index,
                                      HashSet<SsaInsn> deletedInsns) {
    // Create a new ArrayIndexOutOfBoundsException
    CstType exception =
        new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
    insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null,
                                 RegOps.NEW_INSTANCE, exception);

    // Add a successor block with a move result pseudo for the exception
    SsaBasicBlock currBlock = insn.getBlock();
    SsaBasicBlock newBlock =
        currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
    SsaInsn newInsn = newBlock.getInsns().get(0);
    RegisterSpec newReg =
        RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
    insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg,
                              RegOps.MOVE_RESULT_PSEUDO, null);

    // Add another successor block to initialize the exception
    SsaBasicBlock newBlock2 =
        newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
    SsaInsn newInsn2 = newBlock2.getInsns().get(0);
    CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
    CstMethodRef newRef = new CstMethodRef(exception, newNat);
    insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index),
                                 null, RegOps.INVOKE_DIRECT, newRef);
    deletedInsns.add(newInsn2);

    // Add another successor block to throw the new exception
    SsaBasicBlock newBlock3 =
        newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
    SsaInsn newInsn3 = newBlock3.getInsns().get(0);
    insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null,
                                 RegOps.THROW, null);
    newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(),
                                   ssaMeth.getExitBlock().getIndex());
    deletedInsns.add(newInsn3);
}
 
Example 18
Source Project: J2ME-Loader   Source File: CstInsn.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String cstString() {
    if (constant instanceof CstString) {
        return ((CstString) constant).toQuoted();
    }
    return constant.toHuman();
}
 
Example 19
Source Project: Box   Source File: AnnotationItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write a (listing file) annotation for this instance to the given
 * output, that consumes no bytes of output. This is for annotating
 * a reference to this instance at the point of the reference.
 *
 * @param out {@code non-null;} where to output to
 * @param prefix {@code non-null;} prefix for each line of output
 */
public void annotateTo(AnnotatedOutput out, String prefix) {
    out.annotate(0, prefix + "visibility: " +
            annotation.getVisibility().toHuman());
    out.annotate(0, prefix + "type: " + annotation.getType().toHuman());

    for (NameValuePair pair : annotation.getNameValuePairs()) {
        CstString name = pair.getName();
        Constant value = pair.getValue();

        out.annotate(0, prefix + name.toHuman() + ": " +
                ValueEncoder.constantToHuman(value));
    }
}
 
Example 20
Source Project: Box   Source File: RegisterSpec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #toString} and {@link #toHuman}.
 *
 * @param human whether to be human-oriented
 * @return {@code non-null;} the string form
 */
private String toString0(boolean human) {
    StringBuilder sb = new StringBuilder(40);

    sb.append(regString());
    sb.append(":");

    if (local != null) {
        sb.append(local.toString());
    }

    Type justType = type.getType();
    sb.append(justType);

    if (justType != type) {
        sb.append("=");
        if (human && (type instanceof CstString)) {
            sb.append(((CstString) type).toQuoted());
        } else if (human && (type instanceof Constant)) {
            sb.append(type.toHuman());
        } else {
            sb.append(type);
        }
    }

    return sb.toString();
}
 
Example 21
Source Project: J2ME-Loader   Source File: TypeIdItem.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }

    out.writeInt(idx);
}
 
Example 22
Source Project: buck   Source File: DebugInfoDecoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param encoded encoded debug info
 * @param codesize size of code block in code units
 * @param regSize register size, in register units, of the register space
 * used by this method
 * @param isStatic true if method is static
 * @param ref method descriptor of method this debug info is for
 * @param file dex file this debug info will be stored in
 */
DebugInfoDecoder(byte[] encoded, int codesize, int regSize,
        boolean isStatic, CstMethodRef ref, DexFile file) {
    if (encoded == null) {
        throw new NullPointerException("encoded == null");
    }

    this.encoded = encoded;
    this.isStatic = isStatic;
    this.desc = ref.getPrototype();
    this.file = file;
    this.regSize = regSize;

    positions = new ArrayList<PositionEntry>();
    locals = new ArrayList<LocalEntry>();
    this.codesize = codesize;
    lastEntryForReg = new LocalEntry[regSize];

    int idx = -1;

    try {
        idx = file.getStringIds().indexOf(new CstString("this"));
    } catch (IllegalArgumentException ex) {
        /*
         * Silently tolerate not finding "this". It just means that
         * no method has local variable info that looks like
         * a standard instance method.
         */
    }

    thisStringIdx = idx;
}
 
Example 23
Source Project: Box   Source File: AttSignature.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param signature {@code non-null;} the signature string
 */
public AttSignature(CstString signature) {
    super(ATTRIBUTE_NAME);

    if (signature == null) {
        throw new NullPointerException("signature == null");
    }

    this.signature = signature;
}
 
Example 24
Source Project: Box   Source File: AttSourceDebugExtension.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param smapString {@code non-null;} the SMAP data from the class file.
 */
public AttSourceDebugExtension(CstString smapString) {
    super(ATTRIBUTE_NAME);

    if (smapString == null) {
        throw new NullPointerException("smapString == null");
    }

    this.smapString = smapString;
}
 
Example 25
Source Project: Box   Source File: AnnotationUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code SourceDebugExtension} annotation.
 *
 * @param smapString {@code non-null;} the SMAP string associated with
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSourceDebugExtension(CstString smapString) {
    Annotation result = new Annotation(SOURCE_DEBUG_EXTENSION_TYPE, SYSTEM);

    result.put(new NameValuePair(VALUE_STRING, smapString));
    result.setImmutable();
    return result;
}
 
Example 26
FieldId(TypeId<D> declaringType, TypeId<V> type, String name) {
    if (declaringType == null || type == null || name == null) {
        throw new NullPointerException();
    }
    this.declaringType = declaringType;
    this.type = type;
    this.name = name;
    this.nat = new CstNat(new CstString(name), new CstString(type.name));
    this.constant = new CstFieldRef(declaringType.constant, nat);
}
 
Example 27
Source Project: Box   Source File: StringDataItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the write size for a given value.
 *
 * @param value {@code non-null;} the string value
 * @return {@code >= 2}; the write size, in bytes
 */
private static int writeSize(CstString value) {
    int utf16Size = value.getUtf16Size();

    // The +1 is for the '\0' termination byte.
    return Leb128.unsignedLeb128Size(utf16Size)
        + value.getUtf8Size() + 1;
}
 
Example 28
Source Project: J2ME-Loader   Source File: AttSourceFile.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param sourceFile {@code non-null;} the name of the source file
 */
public AttSourceFile(CstString sourceFile) {
    super(ATTRIBUTE_NAME);

    if (sourceFile == null) {
        throw new NullPointerException("sourceFile == null");
    }

    this.sourceFile = sourceFile;
}
 
Example 29
Source Project: Box   Source File: LocalItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Compares two strings like String.compareTo(), excepts treats a null
 * as the least-possible string value.
 *
 * @return negative integer, zero, or positive integer in accordance
 * with Comparable.compareTo()
 */
private static int compareHandlesNulls(CstString a, CstString b) {
    if (a == b) {
        return 0;
    } else if (a == null) {
        return -1;
    } else if (b == null) {
        return 1;
    } else {
        return a.compareTo(b);
    }
}
 
Example 30
Source Project: buck   Source File: TypeIdItem.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }

    out.writeInt(idx);
}