Merge pull request 'Constructor Fix' (#18) from NewParser into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

Reviewed-on: #18
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
This commit is contained in:
Johannes Ehlert 2024-07-02 12:51:46 +00:00
commit 903e87901e

View File

@ -75,7 +75,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
ConstructorNode constructorNode;
if(ctx.AccessModifier() != null) {
constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
} else {
constructorNode = new ConstructorNode(null, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
}
if(ctx.parameterList() != null) {
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter));