From 2cb84f9e2bda17a92250a6ab090e13f72c7f6c9e Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Wed, 13 Mar 2024 11:29:17 +0100 Subject: [PATCH] Ignore annotations in STG, fix #288 --- resources/bytecode/javFiles/Annotation.jav | 8 ++++++++ .../parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java | 2 ++ src/test/java/TestComplete.java | 7 +++++++ 3 files changed, 17 insertions(+) create mode 100644 resources/bytecode/javFiles/Annotation.jav diff --git a/resources/bytecode/javFiles/Annotation.jav b/resources/bytecode/javFiles/Annotation.jav new file mode 100644 index 00000000..520eb314 --- /dev/null +++ b/resources/bytecode/javFiles/Annotation.jav @@ -0,0 +1,8 @@ +class Base { + public void foo() {} +} + +public class Annotation extends Base { + @Override + public void foo() {} +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 40d2a323..925a7b05 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -294,6 +294,8 @@ public class SyntaxTreeGenerator { member = (MemberdeclContext) classBody; Integer membermodifiers = 0; for (ModifierContext mod : member.modifier()) { + if (mod.classOrInterfaceModifier() != null && mod.classOrInterfaceModifier().annotation() != null) + continue; // TODO don't eat annotations membermodifiers += allmodifiers.get(mod.getText()); } switch (member.memberDeclaration()) { diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index 3a5485d3..fd8c3188 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -874,6 +874,13 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); } + @Test + public void testAnnotation() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Annotation.jav"); + var clazz = classFiles.get("Annotation"); + var instance = clazz.getDeclaredConstructor().newInstance(); + } + @Test public void testBug122() throws Exception { var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");