diff --git a/src/main/java/semantic/Scope.java b/src/main/java/semantic/Scope.java index 06647ec..b6b40c4 100644 --- a/src/main/java/semantic/Scope.java +++ b/src/main/java/semantic/Scope.java @@ -1,7 +1,7 @@ package semantic; import ast.type.type.*; -import semantic.exceptions.AlreadyDeclearedException; +import semantic.exceptions.AlreadyDeclaredException; import java.util.HashMap; import java.util.Stack; @@ -16,7 +16,7 @@ public class Scope { public void addLocalVar(String name, ITypeNode type) { if (this.contains(name)) { - throw new AlreadyDeclearedException("Variable " + name + " already exists in this scope"); + throw new AlreadyDeclaredException("Variable " + name + " already exists in this scope"); } localVars.peek().put(name, type); } diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index f4461eb..958a444 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -117,7 +117,7 @@ public class SemanticAnalyzer implements SemanticVisitor { if (Objects.equals(otherMethod, methodNode)) break; if (otherMethod.isSame(methodNode)) { - errors.add(new AlreadyDeclearedException( + errors.add(new AlreadyDeclaredException( "Method " + methodNode.getIdentifier() + " is already defined in class " + currentClass.identifier)); valid = false; @@ -130,8 +130,8 @@ public class SemanticAnalyzer implements SemanticVisitor { valid = valid && result.isValid(); try { currentScope.addLocalVar(parameter.identifier, parameter.type); - } catch (AlreadyDeclearedException e) { - errors.add(new AlreadyDeclearedException(parameter.identifier)); + } catch (AlreadyDeclaredException e) { + errors.add(new AlreadyDeclaredException(parameter.identifier)); } } @@ -165,7 +165,7 @@ public class SemanticAnalyzer implements SemanticVisitor { @Override public TypeCheckResult analyze(FieldNode toCheck) { if (currentFields.get(toCheck.identifier) != null) { - errors.add(new AlreadyDeclearedException("Already declared " + toCheck.identifier)); + errors.add(new AlreadyDeclaredException("Already declared " + toCheck.identifier)); return new TypeCheckResult(false, null); } else { currentFields.put(toCheck.identifier, toCheck.type); @@ -362,7 +362,7 @@ public class SemanticAnalyzer implements SemanticVisitor { } else if(currentFields.get(unary.identifier) != null) { return new TypeCheckResult(valid, currentFields.get(unary.identifier)); } else { - errors.add(new NotDeclearedException("Var is not Decleared")); + errors.add(new NotDeclaredException("Var is not Declared")); } return new TypeCheckResult(valid, null); } diff --git a/src/main/java/semantic/exceptions/AlreadyDeclaredException.java b/src/main/java/semantic/exceptions/AlreadyDeclaredException.java new file mode 100644 index 0000000..c59e104 --- /dev/null +++ b/src/main/java/semantic/exceptions/AlreadyDeclaredException.java @@ -0,0 +1,9 @@ +package semantic.exceptions; + +public class AlreadyDeclaredException extends RuntimeException { + + public AlreadyDeclaredException(String message) { + super(message); + } + +} diff --git a/src/main/java/semantic/exceptions/AlreadyDeclearedException.java b/src/main/java/semantic/exceptions/AlreadyDeclearedException.java deleted file mode 100644 index d7ffccc..0000000 --- a/src/main/java/semantic/exceptions/AlreadyDeclearedException.java +++ /dev/null @@ -1,9 +0,0 @@ -package semantic.exceptions; - -public class AlreadyDeclearedException extends RuntimeException { - - public AlreadyDeclearedException(String message) { - super(message); - } - -} diff --git a/src/main/java/semantic/exceptions/NotDeclaredException.java b/src/main/java/semantic/exceptions/NotDeclaredException.java new file mode 100644 index 0000000..307a55d --- /dev/null +++ b/src/main/java/semantic/exceptions/NotDeclaredException.java @@ -0,0 +1,9 @@ +package semantic.exceptions; + +public class NotDeclaredException extends RuntimeException { + + public NotDeclaredException(String message) { + super(message); + } + +} diff --git a/src/main/java/semantic/exceptions/NotDeclearedException.java b/src/main/java/semantic/exceptions/NotDeclearedException.java deleted file mode 100644 index af1924f..0000000 --- a/src/main/java/semantic/exceptions/NotDeclearedException.java +++ /dev/null @@ -1,9 +0,0 @@ -package semantic.exceptions; - -public class NotDeclearedException extends RuntimeException { - - public NotDeclearedException(String message) { - super(message); - } - -} diff --git a/src/test/java/semantic/SemanticTest.java b/src/test/java/semantic/SemanticTest.java index 7680e8a..a4039ac 100644 --- a/src/test/java/semantic/SemanticTest.java +++ b/src/test/java/semantic/SemanticTest.java @@ -22,7 +22,7 @@ public class SemanticTest { // ASTNode typedAst = SemanticAnalyzer.generateTast(programNode); // // assertEquals(1, SemanticAnalyzer.errors.size()); -// assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst()); +// assertInstanceOf(AlreadyDeclaredException.class, SemanticAnalyzer.errors.getFirst()); // assertNull(typedAst); // } // diff --git a/src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDecleared.java b/src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDeclared.java similarity index 73% rename from src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDecleared.java rename to src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDeclared.java index 3a1ff04..9b268e4 100644 --- a/src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDecleared.java +++ b/src/test/resources/input/typedAstExceptionsTests/FieldAlreadyDeclared.java @@ -1,4 +1,4 @@ -// @expected: AlreadyDeclearedException +// @expected: AlreadyDeclaredException public class Example { public int a; diff --git a/src/test/resources/input/typedAstExceptionsTests/NotDecleared.java b/src/test/resources/input/typedAstExceptionsTests/NotDeclared.java similarity index 73% rename from src/test/resources/input/typedAstExceptionsTests/NotDecleared.java rename to src/test/resources/input/typedAstExceptionsTests/NotDeclared.java index acafa5b..948fe91 100644 --- a/src/test/resources/input/typedAstExceptionsTests/NotDecleared.java +++ b/src/test/resources/input/typedAstExceptionsTests/NotDeclared.java @@ -1,4 +1,4 @@ -// @expected: NotDeclearedException +// @expected: NotDeclaredException public class Test { public static int testMethod(int x){ int a = b; diff --git a/src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDecleared.java b/src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDeclared.java similarity index 66% rename from src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDecleared.java rename to src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDeclared.java index 7de53e0..25854c1 100644 --- a/src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDecleared.java +++ b/src/test/resources/input/typedAstExceptionsTests/ParameterAlreadyDeclared.java @@ -1,4 +1,4 @@ -// @expected: AlreadyDeclearedException +// @expected: AlreadyDeclaredException public class Example { public static int testMethod(char a, int a){