From 336d60ba06fff1a0b59eaa906425adf81c0e5423 Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:15:38 -0600 Subject: [PATCH] Add the possibility that a class does not have a package. --- .../classcontainer/ClassFileContainer.java | 5 +++- .../parser/visitors/MyVoidVisitor.java | 5 +++- .../parser/visitors/ParserUtil.java | 23 +++++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index 9707c83b..34c47003 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -95,7 +95,10 @@ public class ClassFileContainer public String getName() { - return this.className.substring(this.className.lastIndexOf('/') + 1, this.className.lastIndexOf('.')); + if (this.className.contains("/")) + return this.className.substring(this.className.lastIndexOf('/') + 1, this.className.lastIndexOf('.')); + else + return this.className.substring(0, this.className.lastIndexOf('.')); } public String getDecompiler() diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/MyVoidVisitor.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/MyVoidVisitor.java index 4817934b..1bb6f44a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/MyVoidVisitor.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/MyVoidVisitor.java @@ -339,7 +339,10 @@ public class MyVoidVisitor extends VoidVisitorAdapter return; String qualifiedName = referenceType.getQualifiedName(); - String packagePath = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/'); + String packagePath = ""; + if (qualifiedName.contains(".")) + packagePath = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/'); + this.classFileContainer.putClassReference(classValue.name, new ClassReferenceLocation(getOwner(classFileContainer), packagePath, "", "reference", classValue.line, classValue.columnStart, classValue.columnEnd + 1)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ParserUtil.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ParserUtil.java index e8bdaa3b..265410b8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ParserUtil.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ParserUtil.java @@ -127,8 +127,7 @@ class ParserUtil * @param scopeValue The scope value * @param fieldValue The field value */ - static void putClassResolvedValues(ClassFileContainer container, Expression visitedExpr, - Expression resolveExpr, + static void putClassResolvedValues(ClassFileContainer container, Expression visitedExpr, Expression resolveExpr, Value scopeValue, Value fieldValue) { ResolvedType resolvedType = visitedExpr.getSymbolResolver().calculateType(resolveExpr); @@ -137,10 +136,12 @@ class ParserUtil String qualifiedName = resolvedType.asReferenceType().getQualifiedName(); String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); - String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')); - container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), - packageName.replace('.', '/'), fieldValue.name, "reference", scopeValue.line, scopeValue.columnStart, - scopeValue.columnEnd + 1)); + String packageName = ""; + if (qualifiedName.contains(".")) + packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/'); + + container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), packageName + , fieldValue.name, "reference", scopeValue.line, scopeValue.columnStart, scopeValue.columnEnd + 1)); container.putField(fieldValue.name, new ClassFieldLocation(scopeValue.name, "reference", fieldValue.line, fieldValue.columnStart, fieldValue.columnEnd + 1)); } @@ -166,10 +167,12 @@ class ParserUtil String qualifiedName = referenceType.getQualifiedName(); String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); - String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')); - container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), - packageName.replace('.', '/'), "", "reference", scopeValue.line, scopeValue.columnStart, - scopeValue.columnEnd + 1)); + String packageName = ""; + if (qualifiedName.contains(".")) + packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/'); + + container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), packageName + , "", "reference", scopeValue.line, scopeValue.columnStart, scopeValue.columnEnd + 1)); } /**