本文整理汇总了Java中org.jf.dexlib2.dexbacked.DexBackedMethodImplementation.getInstructions方法的典型用法代码示例。如果您正苦于以下问题:Java DexBackedMethodImplementation.getInstructions方法的具体用法?Java DexBackedMethodImplementation.getInstructions怎么用?Java DexBackedMethodImplementation.getInstructions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jf.dexlib2.dexbacked.DexBackedMethodImplementation
的用法示例。
在下文中一共展示了DexBackedMethodImplementation.getInstructions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}