AccessType Fix

This commit is contained in:
Purplumbi 2024-05-08 14:47:41 +02:00
parent 8fbe7d0800
commit 5529704693
4 changed files with 9 additions and 6 deletions

View File

@ -17,7 +17,7 @@ public class ClassNode extends ASTNode{
public void ensureConstructor(){ public void ensureConstructor(){
if(!hasConstructor) { if(!hasConstructor) {
ConstructorNode constructor = new ConstructorNode(new TypeNode("public"), name); ConstructorNode constructor = new ConstructorNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), name);
members.add(0,constructor); members.add(0,constructor);
} }
} }

View File

@ -1,7 +1,7 @@
package ast; package ast;
public class ConstructorNode extends MethodNode{ public class ConstructorNode extends MethodNode{
public ConstructorNode(TypeNode visibility, String name) { public ConstructorNode(AccessTypeNode visibility, String name) {
super(visibility, name); super(visibility, name);
} }
} }

View File

@ -4,22 +4,24 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MethodNode extends MemberNode{ public class MethodNode extends MemberNode{
public TypeNode visibility; public AccessTypeNode visibility;
public TypeNode type;
public String name; public String name;
public ParameterListNode parameters; public ParameterListNode parameters;
public List<StatementNode> statements = new ArrayList<>(); public List<StatementNode> statements = new ArrayList<>();
public MethodNode(TypeNode visibility, String name, ParameterListNode parameters, public MethodNode(AccessTypeNode visibility, TypeNode type, String name, ParameterListNode parameters,
List<StatementNode> statements){ List<StatementNode> statements){
this.visibility = visibility; this.visibility = visibility;
this.type = type;
this.name = name; this.name = name;
this.parameters = parameters; this.parameters = parameters;
this.statements = statements; this.statements = statements;
} }
public MethodNode(TypeNode visibility, String name){ public MethodNode(AccessTypeNode visibility, String name){
this.visibility = visibility; this.visibility = visibility;
this.name = name; this.name = name;
} }

View File

@ -37,6 +37,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) { public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
AccessTypeNode accessType = (AccessTypeNode) visit(ctx.accessType());
TypeNode returnType = (TypeNode) visit(ctx.type()); TypeNode returnType = (TypeNode) visit(ctx.type());
String methodName = ctx.IDENTIFIER().getText(); String methodName = ctx.IDENTIFIER().getText();
ParameterListNode parameterListNode = (ParameterListNode) visit(ctx.parameterList()); ParameterListNode parameterListNode = (ParameterListNode) visit(ctx.parameterList());
@ -45,7 +46,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
statements.add((StatementNode) visit(stmtCtx)); statements.add((StatementNode) visit(stmtCtx));
} }
MethodNode method = new MethodNode(returnType, methodName, parameterListNode, statements); MethodNode method = new MethodNode(accessType,returnType, methodName, parameterListNode, statements);
return method; return method;
} }