use of org.jf.baksmali.Adaptors.MethodDefinition in project atlas by alibaba.
the class SmaliCodeUtils method methodImplementionToCode.
/**
* 将方法的实现转换为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");
}
}
Aggregations