Skip to content

Commit 0b741d1

Browse files
committed
Horribly hacked together xref feature
1 parent 08dcc0c commit 0b741d1

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

src/main/java/club/bytecode/the/jda/FileContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public FileContainer(File f) {
2424

2525
public HashMap<String, byte[]> files = new HashMap<>(); // this is assigned outside the class?!
2626

27-
public ClassNode loadClass(String name) {
28-
byte[] bytes = files.get(name);
27+
public ClassNode loadClassFile(String filename) {
28+
byte[] bytes = files.get(filename);
2929
if (bytes == null)
3030
return null;
3131
ClassReader reader = new ClassReader(bytes);

src/main/java/club/bytecode/the/jda/decompilers/FernflowerDecompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public String decompileClassNode(FileContainer container, final ClassNode cn) {
7373
if (classCache.containsKey(className)) {
7474
requestedCn = classCache.get(className);
7575
} else {
76-
requestedCn = container.loadClass(container.findClassfile(className));
76+
requestedCn = container.loadClassFile(container.findClassfile(className));
7777
if (requestedCn == null) {
7878
System.err.println("Couldn't load " + externalPath);
7979
throw new IOException(container + "$" + cn + " is missing");
@@ -139,7 +139,7 @@ public void closeArchive(String s, String s1) {
139139
if (classCache.containsKey(innerClass.name)) {
140140
innerCn = classCache.get(innerClass.name);
141141
} else {
142-
innerCn = container.loadClass(container.findClassfile(innerClass.name));
142+
innerCn = container.loadClassFile(container.findClassfile(innerClass.name));
143143
if (innerCn != null) {
144144
applyFilters(innerCn);
145145
classCache.put(innerCn.name, innerCn);

src/main/java/club/bytecode/the/jda/decompilers/bytecode/BytecodeDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected PrefixedStringBuilder decompile(PrefixedStringBuilder sb, ArrayList<St
8888
String innerClassName = innerClassNode.name;
8989
if ((innerClassName != null) && !decompiledClasses.contains(innerClassName)) {
9090
decompiledClasses.add(innerClassName);
91-
ClassNode cn1 = container.loadClass(container.findClassfile(innerClassName));
91+
ClassNode cn1 = container.loadClassFile(container.findClassfile(innerClassName));
9292
applyFilters(cn1);
9393
if (cn1 != null) {
9494
sb.appendPrefix(" ");

src/main/java/club/bytecode/the/jda/gui/fileviewer/DecompileThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void run() {
3838
try {
3939
String decompileResult;
4040

41-
ClassNode cn = viewer.getFile().container.loadClass(viewer.getFile().name);
41+
ClassNode cn = viewer.getFile().container.loadClassFile(viewer.getFile().name);
4242
if (cn == null) {
4343
decompileResult = "// The file was removed during the reload.";
4444
} else {

src/main/java/club/bytecode/the/jda/gui/fileviewer/JDATextArea.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package club.bytecode.the.jda.gui.fileviewer;
22

3+
import club.bytecode.the.jda.FileContainer;
4+
import club.bytecode.the.jda.JDA;
35
import club.bytecode.the.jda.settings.Settings;
6+
import net.miginfocom.swing.MigLayout;
47
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
58
import org.fife.ui.rsyntaxtextarea.Token;
69
import org.fife.ui.rsyntaxtextarea.TokenTypes;
10+
import org.mapleir.stdlib.util.Pair;
711

812
import javax.swing.*;
913
import javax.swing.event.CaretEvent;
@@ -123,6 +127,46 @@ private void setComment(int line, String comment) {
123127
resetLine(line);
124128
}
125129

130+
private void search(String needle) {
131+
List<ViewerFile> matches = new ArrayList<>();
132+
for (FileContainer fc : JDA.getOpenFiles()) {
133+
for (Map.Entry<String, byte[]> e : fc.getFiles().entrySet()) {
134+
if (e.getKey().endsWith(".class")) {
135+
try {
136+
// ClassNode cn = fc.loadClassFile(e.getKey());
137+
String fileBytes = new String(e.getValue());
138+
if (fileBytes.contains(needle)) {
139+
matches.add(new ViewerFile(fc, e.getKey()));
140+
}
141+
} catch (Exception ex) {
142+
ex.printStackTrace();
143+
}
144+
}
145+
}
146+
}
147+
final JDialog frame = new JDialog(new JFrame(), "Search Results", true);
148+
Container pane = frame.getContentPane();
149+
pane.setLayout(new MigLayout());
150+
pane.add(new JLabel(needle + "found in:"), "spanx, grow, wrap, align center");
151+
JList<Pair<FileContainer, String>> list = new JList(matches.toArray());
152+
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
153+
list.setLayoutOrientation(JList.VERTICAL);
154+
list.addMouseListener(new MouseAdapter() {
155+
public void mouseClicked(MouseEvent evt) {
156+
JList list = (JList)evt.getSource();
157+
if (evt.getClickCount() == 2) {
158+
int index = list.locationToIndex(evt.getPoint());
159+
ViewerFile vf = matches.get(index);
160+
JDA.viewer.navigator.openClassFileToWorkSpace(vf);
161+
}
162+
}
163+
});
164+
JScrollPane listScroller = new JScrollPane(list);
165+
pane.add(listScroller);
166+
frame.pack();
167+
frame.setVisible(true);
168+
}
169+
126170
private void resetLine(int line) {
127171
if (line > lines.size())
128172
return;
@@ -144,7 +188,9 @@ private boolean isIdentifierSelected() {
144188
private void doXrefDialog() {
145189
if (!isIdentifierSelected())
146190
return;
147-
JOptionPane.showMessageDialog(this, "Not implemented");
191+
String oldName = currentlySelectedToken.getLexeme();
192+
search(oldName);
193+
// JOptionPane.showMessageDialog(this, "Not implemented");
148194
}
149195

150196
private void doRenameDialog() {

0 commit comments

Comments
 (0)