diff --git a/resources/packageTest/pkg/sub/Interface.jav b/resources/packageTest/pkg/sub/Interface.jav new file mode 100644 index 00000000..388b4249 --- /dev/null +++ b/resources/packageTest/pkg/sub/Interface.jav @@ -0,0 +1,3 @@ +package pkg.sub; + +public interface Interface {} diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 35e8f5f1..111bf11c 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -333,7 +333,7 @@ public class SyntaxTreeGenerator { private ClassOrInterface convertInterface(Java17Parser.InterfaceDeclarationContext ctx, int modifiers) { this.superClass = new RefType(new JavaClassName("java.lang.Object"), new NullToken()); - String className = this.pkgName.length() > 0 ? this.pkgName + "." : "" + ctx.identifier().getText(); + String className = (this.pkgName.length() > 0 ? this.pkgName + "." : "") + ctx.identifier().getText(); JavaClassName name = reg.getName(className); // Holt den Package Namen mit dazu if (!name.toString().equals(className)) { // Kommt die Klasse schon in einem anderen Package vor? throw new TypeinferenceException("Name " + className + " bereits vorhanden in " + reg.getName(className).toString(), ctx.getStart()); diff --git a/src/test/java/TestPackages.java b/src/test/java/TestPackages.java index 045eb739..3f5d2c56 100644 --- a/src/test/java/TestPackages.java +++ b/src/test/java/TestPackages.java @@ -34,4 +34,14 @@ public class TestPackages { cmp.generateBytecode(bytecodeDirectory); } + + @Test + public void testPackageInterface() throws Exception { + var cmp = new JavaTXCompiler( + List.of(new File("resources/packageTest/pkg/sub/Interface.jav")), + List.of(new File("resources/packageTest")) + ); + + cmp.generateBytecode(bytecodeDirectory); + } }