diff --git a/src/main/java/ast/ClassNode.java b/src/main/java/ast/ClassNode.java index 7943b5a..0bf768b 100644 --- a/src/main/java/ast/ClassNode.java +++ b/src/main/java/ast/ClassNode.java @@ -17,7 +17,7 @@ public class ClassNode extends ASTNode{ public void ensureConstructor(){ if(!hasConstructor) { - ConstructorNode constructor = new ConstructorNode(new TypeNode("public"), name); + ConstructorNode constructor = new ConstructorNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), name); members.add(0,constructor); } } diff --git a/src/main/java/ast/ConstructorNode.java b/src/main/java/ast/ConstructorNode.java index 4aa194f..a824f5a 100644 --- a/src/main/java/ast/ConstructorNode.java +++ b/src/main/java/ast/ConstructorNode.java @@ -1,7 +1,7 @@ package ast; public class ConstructorNode extends MethodNode{ - public ConstructorNode(TypeNode visibility, String name) { + public ConstructorNode(AccessTypeNode visibility, String name) { super(visibility, name); } } diff --git a/src/main/java/ast/MethodNode.java b/src/main/java/ast/MethodNode.java index b8e15f2..3ab8b2a 100644 --- a/src/main/java/ast/MethodNode.java +++ b/src/main/java/ast/MethodNode.java @@ -4,22 +4,24 @@ import java.util.ArrayList; import java.util.List; public class MethodNode extends MemberNode{ - public TypeNode visibility; + public AccessTypeNode visibility; + public TypeNode type; public String name; public ParameterListNode parameters; public List statements = new ArrayList<>(); - public MethodNode(TypeNode visibility, String name, ParameterListNode parameters, + public MethodNode(AccessTypeNode visibility, TypeNode type, String name, ParameterListNode parameters, List statements){ this.visibility = visibility; + this.type = type; this.name = name; this.parameters = parameters; this.statements = statements; } - public MethodNode(TypeNode visibility, String name){ + public MethodNode(AccessTypeNode visibility, String name){ this.visibility = visibility; this.name = name; } diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index 2e5ef72..48c26a5 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -37,6 +37,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { @Override public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) { + AccessTypeNode accessType = (AccessTypeNode) visit(ctx.accessType()); TypeNode returnType = (TypeNode) visit(ctx.type()); String methodName = ctx.IDENTIFIER().getText(); ParameterListNode parameterListNode = (ParameterListNode) visit(ctx.parameterList()); @@ -45,7 +46,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { statements.add((StatementNode) visit(stmtCtx)); } - MethodNode method = new MethodNode(returnType, methodName, parameterListNode, statements); + MethodNode method = new MethodNode(accessType,returnType, methodName, parameterListNode, statements); return method; }