fix(gui): rename class while rename constructor (#1441)

This commit is contained in:
Skylot
2022-04-08 13:45:27 +01:00
parent 92faa569be
commit 83decc2473
2 changed files with 18 additions and 1 deletions
@@ -103,6 +103,9 @@ public class JMethod extends JNode {
@Override
public boolean canRename() {
if (mth.isClassInit()) {
return false;
}
return !mth.getMethodNode().contains(AFlag.DONT_RENAME);
}
@@ -87,10 +87,24 @@ public class RenameDialog extends JDialog {
this.mainWindow = mainWindow;
this.cache = mainWindow.getCacheObject();
this.source = source;
this.node = node;
this.node = replaceNode(node);
initUI();
}
private JNode replaceNode(JNode node) {
if (node instanceof JMethod) {
JavaMethod javaMethod = ((JMethod) node).getJavaMethod();
if (javaMethod.isClassInit()) {
throw new JadxRuntimeException("Can't rename class init method: " + node);
}
if (javaMethod.isConstructor()) {
// rename class instead constructor
return node.getJParent();
}
}
return node;
}
private void rename() {
try {
updateCodeRenames(set -> processRename(node, renameField.getText(), set));