Skip to content

Commit 5f92c49

Browse files
authored
Merge pull request #538 from oraveczandrew/classfilecontainer-fix
bugfix to the broken search
2 parents a626bc4 + 9123064 commit 5f92c49

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public void openPath(TreePath path)
356356
}
357357

358358
//display via name
359-
BytecodeViewer.viewer.workPane.addClassResource(container, name);
359+
BytecodeViewer.viewer.workPane.addClassResource(container, name.substring(0, name.length() - ".class".length()));
360360
}
361361
catch (Exception e)
362362
{

src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ public void processDisplay()
110110
else
111111
{
112112
final Decompiler decompiler = bytecodeViewPanel.decompiler;
113-
final String workingDecompilerName = viewer.resource.workingName + "-" + decompiler.getDecompilerName();
113+
String decompilerName = decompiler.getDecompilerName();
114+
final String workingDecompilerName = viewer.resource.workingName + "-" + decompilerName;
114115

115116
//perform decompiling inside of this thread
116117
final String decompiledSource = decompiler.getDecompiler().decompileClassNode(viewer.resource.getResourceClassNode(), classBytes);
117118

118-
ClassFileContainer container = new ClassFileContainer(workingDecompilerName, decompiledSource, viewer.resource.container);
119+
ClassFileContainer container = new ClassFileContainer(
120+
viewer.resource.workingName,
121+
decompilerName,
122+
decompiledSource,
123+
viewer.resource.container
124+
);
119125

120126
if (!BytecodeViewer.viewer.workPane.classFiles.containsKey(workingDecompilerName))
121127
{

src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package the.bytecode.club.bytecodeviewer.resources.classcontainer;
22

3-
import com.github.javaparser.*;
3+
import com.github.javaparser.JavaParser;
4+
import com.github.javaparser.ParseResult;
45
import com.github.javaparser.ast.CompilationUnit;
56
import com.github.javaparser.resolution.TypeSolver;
67
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
@@ -12,7 +13,6 @@
1213
import the.bytecode.club.bytecodeviewer.resources.classcontainer.locations.*;
1314
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.MyVoidVisitor;
1415

15-
import java.io.IOException;
1616
import java.util.ArrayList;
1717
import java.util.List;
1818
import java.util.NavigableMap;
@@ -27,6 +27,7 @@
2727
*/
2828
public class ClassFileContainer
2929
{
30+
3031
public transient NavigableMap<String, ArrayList<ClassFieldLocation>> fieldMembers = new TreeMap<>();
3132
public transient NavigableMap<String, ArrayList<ClassParameterLocation>> methodParameterMembers = new TreeMap<>();
3233
public transient NavigableMap<String, ArrayList<ClassLocalVariableLocation>> methodLocalMembers = new TreeMap<>();
@@ -35,13 +36,15 @@ public class ClassFileContainer
3536

3637
public boolean hasBeenParsed = false;
3738
public final String className;
39+
public final String decompiler;
3840
private final String content;
3941
private final String parentContainer;
4042
private final String path;
4143

42-
public ClassFileContainer(String className, String content, ResourceContainer resourceContainer)
44+
public ClassFileContainer(String className, String decompiler, String content, ResourceContainer resourceContainer)
4345
{
4446
this.className = className;
47+
this.decompiler = decompiler;
4548
this.content = content;
4649
this.parentContainer = resourceContainer.name;
4750
this.path = resourceContainer.file.getAbsolutePath();
@@ -95,15 +98,19 @@ public boolean shouldParse()
9598

9699
public String getName()
97100
{
98-
if (this.className.contains("/"))
99-
return this.className.substring(this.className.lastIndexOf('/') + 1, this.className.lastIndexOf('.'));
100-
else
101-
return this.className.substring(0, this.className.lastIndexOf('.'));
101+
int from = className.lastIndexOf('/') + 1;
102+
103+
int until = className.lastIndexOf('.');
104+
if (until == -1 || until < from) {
105+
until = className.length();
106+
}
107+
108+
return className.substring(from, until);
102109
}
103110

104111
public String getDecompiler()
105112
{
106-
return this.className.substring(this.className.lastIndexOf('-') + 1);
113+
return decompiler;
107114
}
108115

109116
public String getParentContainer()

src/main/java/the/bytecode/club/bytecodeviewer/searching/impl/MethodCallSearch.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public JPanel getPanel()
9191
@Override
9292
public void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact)
9393
{
94-
final Iterator<MethodNode> methods = node.methods.iterator();
95-
9694
String searchOwner = mOwner.getText();
9795
if (searchOwner.isEmpty())
9896
searchOwner = null;
@@ -105,6 +103,11 @@ public void search(ResourceContainer container, String resourceWorkingName, Clas
105103
if (searchDesc.isEmpty())
106104
searchDesc = null;
107105

106+
if (searchName == null && searchOwner == null && searchDesc == null)
107+
return;
108+
109+
final Iterator<MethodNode> methods = node.methods.iterator();
110+
108111
while (methods.hasNext())
109112
{
110113
final MethodNode method = methods.next();
@@ -116,9 +119,6 @@ public void search(ResourceContainer container, String resourceWorkingName, Clas
116119
{
117120
final MethodInsnNode min = (MethodInsnNode) insnNode;
118121

119-
if (searchName == null && searchOwner == null && searchDesc == null)
120-
continue;
121-
122122
if (exact)
123123
{
124124
if (searchName != null && !searchName.equals(min.name))

0 commit comments

Comments
 (0)