-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Jadx plugin extraction of method code #2305
Comments
Sure. I will add this method. private String cutMethodCode(MethodNode mth, ICodeInfo codeInfo) {
int startPos = getCommentStartPos(codeInfo, mth.getDefPosition());
int stopPos = getMethodEnd(mth, codeInfo);
return codeInfo.getCodeStr().substring(startPos, stopPos);
}
protected int getCommentStartPos(ICodeInfo codeInfo, int pos) {
String emptyLine = "\n\n";
int emptyLinePos = codeInfo.getCodeStr().lastIndexOf(emptyLine, pos);
return emptyLinePos == -1 ? pos : emptyLinePos + emptyLine.length();
}
private int getMethodEnd(MethodNode mth, ICodeInfo codeInfo) {
// skip nested nodes DEF/END until first unpaired END annotation (end of this method)
Integer end = codeInfo.getCodeMetadata().searchDown(mth.getDefPosition() + 1, new BiFunction<>() {
int nested = 0;
@Override
public Integer apply(Integer pos, ICodeAnnotation ann) {
switch (ann.getAnnType()) {
case DECLARATION:
ICodeNodeRef node = ((NodeDeclareRef) ann).getNode();
switch (node.getAnnType()) {
case CLASS:
case METHOD:
nested++;
break;
}
break;
case END:
if (nested == 0) {
return pos;
}
nested--;
break;
}
return null;
}
});
return end != null ? end : codeInfo.getCodeStr().length();
} |
Thank you! @skylot |
Done. Added Although, it will not work for plugins running in |
Thanks very much @skylot, this works for my usecase. Another issue I noticed is that the
|
Describe your idea
Hello,
I am working on a Jadx plugin and I require extraction of method code alone. Similar to the
((JavaClass) node).getCode()
a((JavaMethod) node).getCode()
or addition of a((JavaMethod) node).getDefEndPos()
would be helpful. Please let me know if there are any alternatives that I am not aware of which I could use.Thanks
The text was updated successfully, but these errors were encountered: