Java源码示例:com.android.dx.rop.cst.CstFieldRef

示例1
/** {@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);
}
 
示例2
/** {@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;
}
 
示例3
/**
 * 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;
}
 
示例4
/**
 * 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();
}
 
示例5
/**
 * 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);
    }
}
 
示例6
/**
 * 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;
    }
}
 
示例7
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()));
    }
}
 
示例8
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));
            }
        }
    }
}
 
示例9
/** {@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);
}
 
示例10
/** {@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;
}
 
示例11
/**
 * 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;
}
 
示例12
/**
 * 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();
}
 
示例13
/**
 * 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);
    }
}
 
示例14
/**
 * 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;
    }
}
 
示例15
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()));
    }
}
 
示例16
/** {@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);
}
 
示例17
/** {@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;
}
 
示例18
/**
 * 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;
}
 
示例19
/**
 * 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();
}
 
示例20
/**
 * 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;
    }
}
 
示例21
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));
                }
            }
        }
    }
 
示例22
/** {@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);
}
 
示例23
/** {@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;
}
 
示例24
/**
 * 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;
}
 
示例25
/**
 * 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();
}
 
示例26
/**
 * 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");
    }
}
 
示例27
/**
 * 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;
    }
}
 
示例28
/**
 * 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)));
}
 
示例29
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");
    }
}
 
示例30
/**
 * 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;
}