mirror of
https://github.com/skylot/jadx.git
synced 2024-11-26 22:20:50 +00:00
fix(gui): allow to reset variable name, fix renames for inner classes
This commit is contained in:
parent
4483533417
commit
61be1d8b0a
@ -79,6 +79,7 @@ public class JavaVariable implements JavaNode {
|
||||
|
||||
@Override
|
||||
public void removeAlias() {
|
||||
varNode.setName(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,7 @@
|
||||
package jadx.api.plugins.events.types;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.api.metadata.ICodeNodeRef;
|
||||
import jadx.api.plugins.events.IJadxEvent;
|
||||
import jadx.api.plugins.events.JadxEventType;
|
||||
@ -14,7 +16,12 @@ public class NodeRenamedByUser implements IJadxEvent {
|
||||
/**
|
||||
* Optional JRenameNode instance
|
||||
*/
|
||||
private Object renameNode;
|
||||
private @Nullable Object renameNode;
|
||||
|
||||
/**
|
||||
* Request reset name to original
|
||||
*/
|
||||
private boolean resetName = false;
|
||||
|
||||
public NodeRenamedByUser(ICodeNodeRef node, String oldName, String newName) {
|
||||
this.node = node;
|
||||
@ -42,6 +49,14 @@ public class NodeRenamedByUser implements IJadxEvent {
|
||||
this.renameNode = renameNode;
|
||||
}
|
||||
|
||||
public boolean isResetName() {
|
||||
return resetName;
|
||||
}
|
||||
|
||||
public void setResetName(boolean resetName) {
|
||||
this.resetName = resetName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JadxEventType<NodeRenamedByUser> getType() {
|
||||
return JadxEvents.NODE_RENAMED_BY_USER;
|
||||
@ -49,6 +64,9 @@ public class NodeRenamedByUser implements IJadxEvent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NodeRenamedByUser{" + node + ", '" + oldName + "' -> '" + newName + "'}";
|
||||
return "NodeRenamedByUser{" + node
|
||||
+ ", '" + oldName + "' -> '" + newName + '\''
|
||||
+ (resetName ? ", reset name" : "")
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class CodeRenameVisitor extends AbstractVisitor {
|
||||
if (clsRenamesMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ICodeRename> clsComments = clsRenamesMap.get(cls.getClassInfo().getFullName());
|
||||
List<ICodeRename> clsComments = clsRenamesMap.get(cls.getClassInfo().getRawName());
|
||||
if (clsComments == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class RenameService {
|
||||
try {
|
||||
LOG.debug("Applying rename event: {}", event);
|
||||
JRenameNode node = getRenameNode(event);
|
||||
updateCodeRenames(set -> processRename(node, event.getNewName(), set));
|
||||
updateCodeRenames(set -> processRename(node, event, set));
|
||||
refreshState(node);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Rename failed", e);
|
||||
@ -85,10 +85,10 @@ public class RenameService {
|
||||
throw new JadxRuntimeException("Failed to resolve node: " + event.getNode());
|
||||
}
|
||||
|
||||
private void processRename(JRenameNode node, String newName, Set<ICodeRename> renames) {
|
||||
ICodeRename rename = node.buildCodeRename(newName, renames);
|
||||
private void processRename(JRenameNode node, NodeRenamedByUser event, Set<ICodeRename> renames) {
|
||||
ICodeRename rename = node.buildCodeRename(event.getNewName(), renames);
|
||||
renames.remove(rename);
|
||||
if (newName.isEmpty()) {
|
||||
if (event.isResetName() || event.getNewName().isEmpty()) {
|
||||
node.removeAlias();
|
||||
} else {
|
||||
renames.add(rename);
|
||||
|
@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import jadx.api.metadata.ICodeNodeRef;
|
||||
import jadx.api.plugins.events.types.NodeRenamedByUser;
|
||||
import jadx.core.utils.Utils;
|
||||
import jadx.gui.treemodel.JClass;
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.treemodel.JPackage;
|
||||
@ -98,19 +99,23 @@ public class RenameDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
String oldName = node.getName();
|
||||
if (newName.isEmpty()) {
|
||||
String newNodeName;
|
||||
boolean reset = newName.isEmpty();
|
||||
if (reset) {
|
||||
node.removeAlias();
|
||||
sendRenameEvent(oldName, node.getJavaNode().getName());
|
||||
newNodeName = Utils.getOrElse(node.getJavaNode().getName(), "");
|
||||
} else {
|
||||
sendRenameEvent(oldName, newName);
|
||||
newNodeName = newName;
|
||||
}
|
||||
sendRenameEvent(oldName, newNodeName, reset);
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void sendRenameEvent(String oldName, String newName) {
|
||||
private void sendRenameEvent(String oldName, String newName, boolean reset) {
|
||||
ICodeNodeRef nodeRef = node.getJavaNode().getCodeNodeRef();
|
||||
NodeRenamedByUser event = new NodeRenamedByUser(nodeRef, oldName, newName);
|
||||
event.setRenameNode(node);
|
||||
event.setResetName(reset);
|
||||
mainWindow.events().send(event);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user