本文整理汇总了Java中org.jf.dexlib2.dexbacked.DexBackedMethodImplementation类的典型用法代码示例。如果您正苦于以下问题:Java DexBackedMethodImplementation类的具体用法?Java DexBackedMethodImplementation怎么用?Java DexBackedMethodImplementation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DexBackedMethodImplementation类属于org.jf.dexlib2.dexbacked包,在下文中一共展示了DexBackedMethodImplementation类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyze
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
private void analyze(@Nonnull DexBackedMethodImplementation implementation) {
cyclomaticComplexity = calculateComplexity(implementation);
registerCount = implementation.getRegisterCount();
tryCatchCount = implementation.getTryBlocks().size();
debugItemCount = Utils.makeCollection(implementation.getDebugItems()).size();
for (Instruction instruction : implementation.getInstructions()) {
instructionCount++;
Opcode op = instruction.getOpcode();
opCounts.adjustOrPutValue(op, 1, 1);
if (instruction instanceof ReferenceInstruction) {
ReferenceInstruction refInstr = (ReferenceInstruction) instruction;
switch (op.referenceType) {
case ReferenceType.METHOD:
MethodReference methodRef = (MethodReference) refInstr.getReference();
if (fullMethodSignatures) {
apiCounts.adjustOrPutValue(methodRef, 1, 1);
} else {
ShortMethodReference shortMethodRef = new ShortMethodReference(methodRef);
apiCounts.adjustOrPutValue(shortMethodRef, 1, 1);
}
break;
case ReferenceType.FIELD:
FieldReference fieldRef = (FieldReference) refInstr.getReference();
fieldReferenceCounts.adjustOrPutValue(fieldRef, 1, 1);
break;
case ReferenceType.STRING:
StringReference stringRef = (StringReference) refInstr.getReference();
stringReferenceCounts.adjustOrPutValue(stringRef, 1, 1);
break;
}
}
}
}
示例2: methodImplementionToCode
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
/**
* 将方法的实现转换为smali代码
*
* @param dexBackedMethodImplementation
* @param withLineNo 是否包含行号
* @return
*/
public static String methodImplementionToCode(DexBackedMethodImplementation dexBackedMethodImplementation, boolean withLineNo) {
if (null == dexBackedMethodImplementation) {
return null;
}
StringWriter stringWriter = new StringWriter();
IndentingWriter writer = new IndentingWriter(stringWriter);
MethodDefinition methodDefinition = new MethodDefinition(toClassDefinition(dexBackedMethodImplementation),
dexBackedMethodImplementation.method,
dexBackedMethodImplementation);
try {
methodDefinition.writeTo(writer);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (withLineNo) {
return stringWriter.toString();
} else {
List<String> codes = Lists.newArrayList();
String[] lines = StringUtils.split(stringWriter.toString(), "\n");
for (String line : lines) {
if (StringUtils.isNoneBlank(line) && !line.matches("\\s+\\.line\\s+[0-9]+$")) {
codes.add(line);
}
}
return StringUtils.join(codes, "\n");
}
}
示例3: compareMethod
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
/**
* 判断2个方法的实现是否equal
*
* @param baseMethod
* @param newMethod
* @return
*/
public static boolean compareMethod(DexBackedMethodImplementation baseMethod, DexBackedMethodImplementation newMethod) {
String baseMethodStr = SmaliCodeUtils.methodImplementionToCode(baseMethod, false);
String newMethodStr = SmaliCodeUtils.methodImplementionToCode(newMethod, false);
if (StringUtils.equals(baseMethodStr, newMethodStr)) {
return true;
} else {
return false;
}
// if (null != baseMethod && null != newMethod) {
// List< Instruction> a = Lists.newArrayList();
// List<Instruction> b = Lists.newArrayList();
// for(Instruction instruction:baseMethod.getInstructions()){
// a.add(instruction);
// }
// for(Instruction instruction:newMethod.getInstructions()){
// b.add(instruction);
// }
//
// return baseMethod.getRegisterCount() == newMethod.getRegisterCount()
// && equalTryBlocks(baseMethod.getTryBlocks(), newMethod.getTryBlocks()) && equalsInstruction(a,b);
// } else if (null == baseMethod && null == newMethod) {
// return true;
// } else {
// return false;
// }
}
示例4: newOrEmpty
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
public static DebugInfo newOrEmpty(@Nonnull DexBackedDexFile dexFile, int debugInfoOffset,
@Nonnull DexBackedMethodImplementation methodImpl) {
if (debugInfoOffset == 0) {
return EmptyDebugInfo.INSTANCE;
}
return new DebugInfoImpl(dexFile, debugInfoOffset, methodImpl);
}
示例5: DebugInfoImpl
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
public DebugInfoImpl(@Nonnull DexBackedDexFile dexFile,
int debugInfoOffset,
@Nonnull DexBackedMethodImplementation methodImpl) {
this.dexFile = dexFile;
this.debugInfoOffset = debugInfoOffset;
this.methodImpl = methodImpl;
}
示例6: newOrEmpty
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
public static DebugInfo newOrEmpty( DexBackedDexFile dexFile, int debugInfoOffset,
DexBackedMethodImplementation methodImpl) {
if (debugInfoOffset == 0) {
return EmptyDebugInfo.INSTANCE;
}
return new DebugInfoImpl(dexFile, debugInfoOffset, methodImpl);
}
示例7: DebugInfoImpl
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
public DebugInfoImpl( DexBackedDexFile dexFile,
int debugInfoOffset,
DexBackedMethodImplementation methodImpl) {
this.dexFile = dexFile;
this.debugInfoOffset = debugInfoOffset;
this.methodImpl = methodImpl;
}
示例8: DebugInfoImpl
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
public DebugInfoImpl(@Nonnull DexBackedDexFile dexFile,
int debugInfoOffset,
@Nonnull DexBackedMethodImplementation methodImpl) {
this.dexFile = dexFile;
this.debugInfoOffset = debugInfoOffset;
this.methodImpl = methodImpl;
}
示例9: calculateComplexity
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
private static int calculateComplexity(@Nonnull DexBackedMethodImplementation implementation) {
// Cyclomatic complexity = <branches> - <exits> + 2
int branches = 0;
int exits = 0;
for (Instruction instruction : implementation.getInstructions()) {
switch (instruction.getOpcode()) {
case IF_EQ:
case IF_EQZ:
case IF_GE:
case IF_GEZ:
case IF_GT:
case IF_GTZ:
case IF_LE:
case IF_LEZ:
case IF_LT:
case IF_LTZ:
case IF_NE:
case IF_NEZ:
branches += 2;
break;
case PACKED_SWITCH_PAYLOAD:
branches += ((PackedSwitchPayload) instruction).getSwitchElements().size();
break;
case RETURN:
case RETURN_OBJECT:
case RETURN_VOID:
case RETURN_VOID_BARRIER:
case RETURN_VOID_NO_BARRIER:
case RETURN_WIDE:
exits += 1;
break;
case SPARSE_SWITCH_PAYLOAD:
branches += ((SparseSwitchPayload) instruction).getSwitchElements().size();
break;
case THROW:
case THROW_VERIFICATION_ERROR:
exits += 1;
break;
}
}
return branches - exits + 2;
}
示例10: toClassDefinition
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation; //导入依赖的package包/类
private static ClassDefinition toClassDefinition(DexBackedMethodImplementation dexBackedMethodImplementation) {
ClassDefinition classDefinition = new ClassDefinition(createBaksmaliOptions(dexBackedMethodImplementation.method.classDef),
dexBackedMethodImplementation.method.classDef);
return classDefinition;
}