Skip to content

Commit ddf39d8

Browse files
committed
fix ClassFileContainer.getName
1 parent a355a61 commit ddf39d8

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

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()

0 commit comments

Comments
 (0)