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

The following examples show how to use com.android.dx.rop.cst.CstFieldRef. 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: Box   Source File: Form22c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example 2
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = fieldIds.get((CstFieldRef) cst);

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

    return result;
}
 
Example 3
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param field {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized FieldIdItem intern(CstFieldRef field) {
    if (field == null) {
        throw new NullPointerException("field == null");
    }

    throwIfPrepared();

    FieldIdItem result = fieldIds.get(field);

    if (result == null) {
        result = new FieldIdItem(field);
        fieldIds.put(field, result);
    }

    return result;
}
 
Example 4
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstFieldRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    FieldIdItem item = fieldIds.get(ref);

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

    return item.getIndex();
}
 
Example 5
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 6
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 7
Source Project: Box   Source File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example 8
Source Project: buck   Source File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDependencies(ConstantPool pool) {
    for (Constant constant : pool.getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType());
        } else if (constant instanceof CstMethodRef) {
            Prototype proto = ((CstMethodRef) constant).getPrototype();
            checkDescriptor(proto.getReturnType());
            StdTypeList args = proto.getParameterTypes();
            for (int i = 0; i < args.size(); i++) {
                checkDescriptor(args.get(i));
            }
        }
    }
}
 
Example 9
Source Project: Box   Source File: Form22c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example 10
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = fieldIds.get((CstFieldRef) cst);

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

    return result;
}
 
Example 11
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param field {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized FieldIdItem intern(CstFieldRef field) {
    if (field == null) {
        throw new NullPointerException("field == null");
    }

    throwIfPrepared();

    FieldIdItem result = fieldIds.get(field);

    if (result == null) {
        result = new FieldIdItem(field);
        fieldIds.put(field, result);
    }

    return result;
}
 
Example 12
Source Project: Box   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstFieldRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    FieldIdItem item = fieldIds.get(ref);

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

    return item.getIndex();
}
 
Example 13
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 14
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 15
Source Project: Box   Source File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example 16
Source Project: J2ME-Loader   Source File: Form22c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example 17
Source Project: J2ME-Loader   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = fieldIds.get((CstFieldRef) cst);

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

    return result;
}
 
Example 18
Source Project: J2ME-Loader   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param field {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized FieldIdItem intern(CstFieldRef field) {
    if (field == null) {
        throw new NullPointerException("field == null");
    }

    throwIfPrepared();

    FieldIdItem result = fieldIds.get(field);

    if (result == null) {
        result = new FieldIdItem(field);
        fieldIds.put(field, result);
    }

    return result;
}
 
Example 19
Source Project: J2ME-Loader   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstFieldRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    FieldIdItem item = fieldIds.get(ref);

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

    return item.getIndex();
}
 
Example 20
Source Project: J2ME-Loader   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 CstProtoRef) {
        return protoIds.get(cst);
    } else {
        return null;
    }
}
 
Example 21
Source Project: RocooFix   Source File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
private void addDependencies(ConstantPool pool) {

        for (Constant constant : pool.getEntries()) {
            if (constant instanceof CstType) {
                checkDescriptor(((CstType) constant).getClassType());
            } else if (constant instanceof CstFieldRef) {
                checkDescriptor(((CstFieldRef) constant).getType());
            } else if (constant instanceof CstMethodRef) {
                Prototype proto = ((CstMethodRef) constant).getPrototype();
                checkDescriptor(proto.getReturnType());
                StdTypeList args = proto.getParameterTypes();
                for (int i = 0; i < args.size(); i++) {
                    checkDescriptor(args.get(i));
                }
            }
        }
    }
 
Example 22
Source Project: buck   Source File: Form22c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example 23
Source Project: buck   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = fieldIds.get((CstFieldRef) cst);

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

    return result;
}
 
Example 24
Source Project: buck   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param field {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized FieldIdItem intern(CstFieldRef field) {
    if (field == null) {
        throw new NullPointerException("field == null");
    }

    throwIfPrepared();

    FieldIdItem result = fieldIds.get(field);

    if (result == null) {
        result = new FieldIdItem(field);
        fieldIds.put(field, result);
    }

    return result;
}
 
Example 25
Source Project: buck   Source File: FieldIdsSection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstFieldRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    FieldIdItem item = fieldIds.get(ref);

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

    return item.getIndex();
}
 
Example 26
Source Project: buck   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 27
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 28
Source Project: Box   Source File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a field annotations item to this instance.
 *
 * @param field {@code non-null;} field in question
 * @param annotations {@code non-null;} associated annotations to add
 * @param dexFile {@code non-null;} dex output
 */
public void addFieldAnnotations(CstFieldRef field,
        Annotations annotations, DexFile dexFile) {
    if (fieldAnnotations == null) {
        fieldAnnotations = new ArrayList<FieldAnnotationStruct>();
    }

    fieldAnnotations.add(new FieldAnnotationStruct(field,
                    new AnnotationSetItem(annotations, dexFile)));
}
 
Example 29
Source Project: Box   Source File: MethodHandleItem.java    License: Apache License 2.0 5 votes vote down vote up
private int getTargetIndex(DexFile file) {
    Constant ref = methodHandle.getRef();
    if (methodHandle.isAccessor()) {
        FieldIdsSection fieldIds = file.getFieldIds();
        return fieldIds.indexOf((CstFieldRef) ref);
    } else if (methodHandle.isInvocation()) {
        if (ref instanceof CstInterfaceMethodRef) {
            ref = ((CstInterfaceMethodRef)ref).toMethodRef();
        }
        MethodIdsSection methodIds = file.getMethodIds();
        return methodIds.indexOf((CstBaseMethodRef) ref);
    } else {
        throw new IllegalStateException("Unhandled invocation type");
    }
}
 
Example 30
Source Project: Box   Source File: EncodedField.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param field {@code non-null;} constant for the field
 * @param accessFlags access flags
 */
public EncodedField(CstFieldRef field, int accessFlags) {
    super(accessFlags);

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

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

    this.field = field;
}