Skip to content

Commit

Permalink
fix(gui): rename class while rename constructor (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Apr 8, 2022
1 parent 92faa56 commit 83decc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public String getSyntaxName() {

@Override
public boolean canRename() {
if (mth.isClassInit()) {
return false;
}
return !mth.getMethodNode().contains(AFlag.DONT_RENAME);
}

Expand Down
16 changes: 15 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,24 @@ private RenameDialog(MainWindow mainWindow, JNode source, JNode node) {
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));
Expand Down

0 comments on commit 83decc2

Please sign in to comment.