com.android.dx.rop.cst.CstInterfaceMethodRef Java Examples
The following examples show how to use
com.android.dx.rop.cst.CstInterfaceMethodRef.
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 File: MethodHandleItem.java From Box with Apache License 2.0 | 5 votes |
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 #2
Source File: MethodHandleItem.java From Box with Apache License 2.0 | 5 votes |
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 #3
Source File: CfTranslator.java From Box with Apache License 2.0 | 4 votes |
/** * Performs the main act of translation. This method is separated * from {@link #translate} just to keep things a bit simpler in * terms of exception handling. * * * @param context {@code non-null;} the state global to this invocation. * @param cf {@code non-null;} the class file * @param bytes {@code non-null;} contents of the file * @param cfOptions options for class translation * @param dexOptions options for dex output * @param dexFile {@code non-null;} dex output * @return {@code non-null;} the translated class */ private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) { context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile); // Build up a class to output. CstType thisClass = cf.getThisClass(); int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER; CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile(); ClassDefItem out = new ClassDefItem(thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile); Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions); if (classAnnotations.size() != 0) { out.setClassAnnotations(classAnnotations, dexFile); } FieldIdsSection fieldIdsSection = dexFile.getFieldIds(); MethodIdsSection methodIdsSection = dexFile.getMethodIds(); MethodHandlesSection methodHandlesSection = dexFile.getMethodHandles(); CallSiteIdsSection callSiteIds = dexFile.getCallSiteIds(); processFields(cf, out, dexFile); processMethods(context, cf, cfOptions, dexOptions, out, dexFile); // intern constant pool method, field and type references ConstantPool constantPool = cf.getConstantPool(); int constantPoolSize = constantPool.size(); for (int i = 0; i < constantPoolSize; i++) { Constant constant = constantPool.getOrNull(i); if (constant instanceof CstMethodRef) { methodIdsSection.intern((CstBaseMethodRef) constant); } else if (constant instanceof CstInterfaceMethodRef) { methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef()); } else if (constant instanceof CstFieldRef) { fieldIdsSection.intern((CstFieldRef) constant); } else if (constant instanceof CstEnumRef) { fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef()); } else if (constant instanceof CstMethodHandle) { methodHandlesSection.intern((CstMethodHandle) constant); } else if (constant instanceof CstInvokeDynamic) { CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) constant; int index = cstInvokeDynamic.getBootstrapMethodIndex(); BootstrapMethodsList.Item bootstrapMethod = cf.getBootstrapMethods().get(index); CstCallSite callSite = CstCallSite.make(bootstrapMethod.getBootstrapMethodHandle(), cstInvokeDynamic.getNat(), bootstrapMethod.getBootstrapMethodArguments()); cstInvokeDynamic.setDeclaringClass(cf.getThisClass()); cstInvokeDynamic.setCallSite(callSite); for (CstCallSiteRef ref : cstInvokeDynamic.getReferences()) { callSiteIds.intern(ref); } } } return out; }
Example #4
Source File: CfTranslator.java From Box with Apache License 2.0 | 4 votes |
/** * Performs the main act of translation. This method is separated * from {@link #translate} just to keep things a bit simpler in * terms of exception handling. * * * @param context {@code non-null;} the state global to this invocation. * @param cf {@code non-null;} the class file * @param bytes {@code non-null;} contents of the file * @param cfOptions options for class translation * @param dexOptions options for dex output * @param dexFile {@code non-null;} dex output * @return {@code non-null;} the translated class */ private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) { context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile); // Build up a class to output. CstType thisClass = cf.getThisClass(); int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER; CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile(); ClassDefItem out = new ClassDefItem(thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile); Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions); if (classAnnotations.size() != 0) { out.setClassAnnotations(classAnnotations, dexFile); } FieldIdsSection fieldIdsSection = dexFile.getFieldIds(); MethodIdsSection methodIdsSection = dexFile.getMethodIds(); MethodHandlesSection methodHandlesSection = dexFile.getMethodHandles(); CallSiteIdsSection callSiteIds = dexFile.getCallSiteIds(); processFields(cf, out, dexFile); processMethods(context, cf, cfOptions, dexOptions, out, dexFile); // intern constant pool method, field and type references ConstantPool constantPool = cf.getConstantPool(); int constantPoolSize = constantPool.size(); for (int i = 0; i < constantPoolSize; i++) { Constant constant = constantPool.getOrNull(i); if (constant instanceof CstMethodRef) { methodIdsSection.intern((CstBaseMethodRef) constant); } else if (constant instanceof CstInterfaceMethodRef) { methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef()); } else if (constant instanceof CstFieldRef) { fieldIdsSection.intern((CstFieldRef) constant); } else if (constant instanceof CstEnumRef) { fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef()); } else if (constant instanceof CstMethodHandle) { methodHandlesSection.intern((CstMethodHandle) constant); } else if (constant instanceof CstInvokeDynamic) { CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) constant; int index = cstInvokeDynamic.getBootstrapMethodIndex(); BootstrapMethodsList.Item bootstrapMethod = cf.getBootstrapMethods().get(index); CstCallSite callSite = CstCallSite.make(bootstrapMethod.getBootstrapMethodHandle(), cstInvokeDynamic.getNat(), bootstrapMethod.getBootstrapMethodArguments()); cstInvokeDynamic.setDeclaringClass(cf.getThisClass()); cstInvokeDynamic.setCallSite(callSite); for (CstCallSiteRef ref : cstInvokeDynamic.getReferences()) { callSiteIds.intern(ref); } } } return out; }
Example #5
Source File: CfTranslator.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Performs the main act of translation. This method is separated * from {@link #translate} just to keep things a bit simpler in * terms of exception handling. * * * @param context {@code non-null;} the state global to this invocation. * @param cf {@code non-null;} the class file * @param bytes {@code non-null;} contents of the file * @param cfOptions options for class translation * @param dexOptions options for dex output * @param dexFile {@code non-null;} dex output * @return {@code non-null;} the translated class */ private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) { context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile); // Build up a class to output. CstType thisClass = cf.getThisClass(); int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER; CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile(); ClassDefItem out = new ClassDefItem(thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile); Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions); if (classAnnotations.size() != 0) { out.setClassAnnotations(classAnnotations, dexFile); } FieldIdsSection fieldIdsSection = dexFile.getFieldIds(); MethodIdsSection methodIdsSection = dexFile.getMethodIds(); processFields(cf, out, dexFile); processMethods(context, cf, cfOptions, dexOptions, out, dexFile); // intern constant pool method, field and type references ConstantPool constantPool = cf.getConstantPool(); int constantPoolSize = constantPool.size(); for (int i = 0; i < constantPoolSize; i++) { Constant constant = constantPool.getOrNull(i); if (constant instanceof CstMethodRef) { methodIdsSection.intern((CstBaseMethodRef) constant); } else if (constant instanceof CstInterfaceMethodRef) { methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef()); } else if (constant instanceof CstFieldRef) { fieldIdsSection.intern((CstFieldRef) constant); } else if (constant instanceof CstEnumRef) { fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef()); } } return out; }
Example #6
Source File: CfTranslator.java From buck with Apache License 2.0 | 4 votes |
/** * Performs the main act of translation. This method is separated * from {@link #translate} just to keep things a bit simpler in * terms of exception handling. * * * @param context * @param cf {@code non-null;} the class file * @param bytes {@code non-null;} contents of the file * @param cfOptions options for class translation * @param dexOptions options for dex output * @param dexFile {@code non-null;} dex output * @return {@code non-null;} the translated class */ private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) { context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile); // Build up a class to output. CstType thisClass = cf.getThisClass(); int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER; CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile(); ClassDefItem out = new ClassDefItem(thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile); Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions); if (classAnnotations.size() != 0) { out.setClassAnnotations(classAnnotations, dexFile); } FieldIdsSection fieldIdsSection = dexFile.getFieldIds(); MethodIdsSection methodIdsSection = dexFile.getMethodIds(); processFields(cf, out, dexFile); processMethods(context, cf, cfOptions, dexOptions, out, dexFile); // intern constant pool method, field and type references ConstantPool constantPool = cf.getConstantPool(); int constantPoolSize = constantPool.size(); for (int i = 0; i < constantPoolSize; i++) { Constant constant = constantPool.getOrNull(i); if (constant instanceof CstMethodRef) { methodIdsSection.intern((CstBaseMethodRef) constant); } else if (constant instanceof CstInterfaceMethodRef) { methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef()); } else if (constant instanceof CstFieldRef) { fieldIdsSection.intern((CstFieldRef) constant); } else if (constant instanceof CstEnumRef) { fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef()); } } return out; }