From 80917ec222824f84e4b62c088982a81c5e269879 Mon Sep 17 00:00:00 2001 From: Jochen Seyfried Date: Thu, 9 May 2024 14:41:07 +0200 Subject: [PATCH] Fixed nullPointer Exception for missing class name --- Source/Compiler.java | 2 +- Source/abstractSyntaxTree/Class/RefType.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Compiler.java b/Source/Compiler.java index cbc4625..8ba724a 100644 --- a/Source/Compiler.java +++ b/Source/Compiler.java @@ -15,7 +15,7 @@ public class Compiler { Program abstractSyntaxTree = new Program(new ArrayList<>()); List emptyFieldDecl = new ArrayList<>(); List emptyMethodDecl = new ArrayList<>(); - abstractSyntaxTree.classes.add(new RefType(emptyFieldDecl, emptyMethodDecl, null, null)); + abstractSyntaxTree.classes.add(new RefType(emptyFieldDecl, emptyMethodDecl, null, null, "MyClass")); abstractSyntaxTree.typeCheck(); diff --git a/Source/abstractSyntaxTree/Class/RefType.java b/Source/abstractSyntaxTree/Class/RefType.java index 79a4a22..3018ec7 100644 --- a/Source/abstractSyntaxTree/Class/RefType.java +++ b/Source/abstractSyntaxTree/Class/RefType.java @@ -26,7 +26,8 @@ public class RefType extends AbstractType implements IClass { public RefType(List fieldDecls, List methodDecls, HashMap> typeContext, - HashMap>>> methodContext){ + HashMap>>> methodContext, String name){ + this.name = name; this.fieldDecls = fieldDecls; this.methodDecls = methodDecls; this.typeContext = typeContext; @@ -36,7 +37,8 @@ public class RefType extends AbstractType implements IClass { @Override - public TypeCheckResult typeCheck(HashMap>>> methodContext, HashMap> typeContext, List fieldsOrMethods) throws Exception { + public TypeCheckResult typeCheck(HashMap>>> methodContext, + HashMap> typeContext, List fieldsOrMethods) throws Exception { TypeCheckResult result = new TypeCheckResult(); for (FieldDecl fieldDecl : fieldDecls) {