Skip to content

Commit ba2f031

Browse files
committed
Fix opening .class files
1 parent af9ee8e commit ba2f031

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public ClassNode loadClassFile(String filename) {
3636

3737
public String findClassfile(String className) {
3838
String candidate = className + ".class";
39+
if (name.endsWith(".class")) { // this is a single .class file. we need to strip the package path out.
40+
candidate = JDA.getClassName(candidate);
41+
}
3942
if (files.containsKey(candidate))
4043
return candidate;
4144
return "";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ public static String getClassFilePath(String fileName) {
270270
return fileName.replace(File.separator, "/").substring(0, fileName.length() - ".class".length());
271271
}
272272

273+
/**
274+
* Returns the last part of a fully qualified name, e.g. the class name.
275+
* @param fullyQualifiedName a fully qualified name like "java/lang/String"
276+
* @return just the name without the package name, e.g. "String"
277+
*/
273278
public static String getClassName(String fullyQualifiedName) {
274279
return fullyQualifiedName.substring(fullyQualifiedName.lastIndexOf('/') + 1);
275280
}

0 commit comments

Comments
 (0)