From ca327375c8b1ee447f93c73cec6fba61242c888c Mon Sep 17 00:00:00 2001 From: luca9913 Date: Thu, 2 Feb 2023 06:38:30 +0100 Subject: [PATCH] Konvertierung von Methoden begonnen --- .../parser/SyntaxTreeGenerator/ASTGen.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java index 35f0fcd0..37da5728 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java @@ -21,11 +21,16 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassBodyDeclarationContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassOrInterfaceModifierContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassorinterfacedeclContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.GenericDeclarationListContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.GenericmethodContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberclassorinterfaceContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberconstructorContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberdeclContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberfieldContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MembermethodContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodDeclarationContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodHeaderContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.MethoddeclContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ModifierContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.NoclassorinterfaceContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext; @@ -180,6 +185,7 @@ public class ASTGen { for (ModifierContext mod : member.modifier()) { membermodifiers += allmodifiers.get(mod.getText()); } + String membername; switch (member.memberDeclaration()) { case MemberclassorinterfaceContext memberclsoif: { break; @@ -189,7 +195,7 @@ public class ASTGen { break; } case MembermethodContext membermethod: { - // TODO: parse methods + methods.add(convert(membermodifiers, membermethod.method(), name, superClass, generics)); break; } case MemberconstructorContext memberconstructor: { @@ -230,7 +236,6 @@ public class ASTGen { Optional.of(this.generatePseudoConstructor(ctx.identifier().getText(), name, superClass, genericClassParameters, offset)), methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); - } /** @@ -289,8 +294,33 @@ public class ASTGen { return ret; } - public Method convert(Java17Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, + public Method convert(int modifiers, Java17Parser.MethodContext methodContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) { + GenericsRegistry localgenerics = generics; + MethodDeclarationContext methoddeclaration; + GenericDeclarationListContext genericdeclarations;GenericDeclarationList gtvDeclarations; + MethodHeaderContext header; + String name; + if(methodContext instanceof GenericmethodContext){ + GenericmethodContext gmc = new GenericmethodContext(methodContext); + genericdeclarations = gmc.genericMethodDeclaration().genericDeclarationList(); + methoddeclaration = gmc.genericMethodDeclaration().methodDeclaration(); + header = methoddeclaration.methodHeader(); + name = header.identifier().getText(); + localgenerics.putAll(createGenerics(genericdeclarations, parentClass, name, reg, generics)); + gtvDeclarations = TypeGenerator.convert(genericdeclarations, parentClass, name, reg, localgenerics); + }else{ + MethoddeclContext mdc = new MethoddeclContext(methodContext); + methoddeclaration = mdc.methodDeclaration(); + header = methoddeclaration.methodHeader(); + gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart()); + } + + RefTypeOrTPHOrWildcardOrGeneric retType; + if(header.refType() != null){ + retType = TypeGenerator.convert(header.refType()) + } + return null; }