diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/FieldAlreadyDeclaredException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/FieldAlreadyDeclaredException.java index 57d4323..ba1c0da 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/FieldAlreadyDeclaredException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/FieldAlreadyDeclaredException.java @@ -1,6 +1,6 @@ package de.maishai.typedast.ExceptionHandler; -public class FieldAlreadyDeclaredException extends RuntimeException{ +public class FieldAlreadyDeclaredException extends RuntimeException { public FieldAlreadyDeclaredException(String name) { super("Field " + name + " already declared"); diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/ImproperFieldAccessException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/ImproperFieldAccessException.java index abcfc69..0d09fa6 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/ImproperFieldAccessException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/ImproperFieldAccessException.java @@ -1,8 +1,8 @@ package de.maishai.typedast.ExceptionHandler; -public class ImproperFieldAccessException extends RuntimeException{ +public class ImproperFieldAccessException extends RuntimeException { - public ImproperFieldAccessException(String name) { - super("Field Variable "+ name+ " should be used with `thisĀ“"); - } + public ImproperFieldAccessException(String name) { + super("Field Variable " + name + " should be used with `thisĀ“"); + } } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/LocalVariableAlreadDeclaredException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/LocalVariableAlreadDeclaredException.java index a11a7ab..90bd575 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/LocalVariableAlreadDeclaredException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/LocalVariableAlreadDeclaredException.java @@ -1,7 +1,7 @@ package de.maishai.typedast.ExceptionHandler; public class LocalVariableAlreadDeclaredException extends RuntimeException { - public LocalVariableAlreadDeclaredException(String name){ + public LocalVariableAlreadDeclaredException(String name) { super("local Variable " + name + " already declared"); } } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/NonStaticUsageInMainException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/NonStaticUsageInMainException.java index 0a5016a..36f0983 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/NonStaticUsageInMainException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/NonStaticUsageInMainException.java @@ -1,7 +1,7 @@ package de.maishai.typedast.ExceptionHandler; -public class NonStaticUsageInMainException extends RuntimeException{ - public NonStaticUsageInMainException(){ +public class NonStaticUsageInMainException extends RuntimeException { + public NonStaticUsageInMainException() { super("Main Method, is not allowed to have fields, they are not static"); } } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/NotMatchConstructorException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/NotMatchConstructorException.java index d0474c0..681df0f 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/NotMatchConstructorException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/NotMatchConstructorException.java @@ -2,10 +2,6 @@ package de.maishai.typedast.ExceptionHandler; public class NotMatchConstructorException extends RuntimeException { - public NotMatchConstructorException(String constructorName) { - super(constructorName); - } - public NotMatchConstructorException() { super("Not matching constructor found"); } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/OperatorException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/OperatorException.java index b6a7fd3..7c20933 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/OperatorException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/OperatorException.java @@ -1,8 +1,8 @@ package de.maishai.typedast.ExceptionHandler; -public class OperatorException extends RuntimeException{ +public class OperatorException extends RuntimeException { - public OperatorException(String operator, String type){ + public OperatorException(String operator, String type) { super(operator + " operator must be applied to " + type); } } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/ParameterAlreadyExistsException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/ParameterAlreadyExistsException.java index 4d9a6d8..bf93edb 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/ParameterAlreadyExistsException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/ParameterAlreadyExistsException.java @@ -1,14 +1,8 @@ package de.maishai.typedast.ExceptionHandler; -public class ParameterAlreadyExistsException extends RuntimeException{ +public class ParameterAlreadyExistsException extends RuntimeException { public ParameterAlreadyExistsException(String paraName) { super("Parameter '" + paraName + "' already exists"); } - public ParameterAlreadyExistsException(String paraName, String methodOrConstructorName) { - super("Parameter '" + paraName + "' already exists in " + methodOrConstructorName); - } - public ParameterAlreadyExistsException() { - super("Parameter already exists"); - } } \ No newline at end of file diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/TypeMismatchException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/TypeMismatchException.java index 30b7c05..b0eaa69 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/TypeMismatchException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/TypeMismatchException.java @@ -1,6 +1,6 @@ package de.maishai.typedast.ExceptionHandler; -public class TypeMismatchException extends RuntimeException{ +public class TypeMismatchException extends RuntimeException { public TypeMismatchException(String operator) { super("Type mismatch in operator: " + operator); diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/TypeOfReturnNotMatchException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/TypeOfReturnNotMatchException.java index 64c93dc..5bf89e5 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/TypeOfReturnNotMatchException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/TypeOfReturnNotMatchException.java @@ -1,17 +1,13 @@ package de.maishai.typedast.ExceptionHandler; -import de.maishai.typedast.Type; -public class TypeOfReturnNotMatchException extends RuntimeException{ +public class TypeOfReturnNotMatchException extends RuntimeException { - public TypeOfReturnNotMatchException(String excepted, String actual, String name){ + public TypeOfReturnNotMatchException(String excepted, String actual, String name) { super("Mismatched return type: " + " Expected: " + excepted + " Actual: " + actual + " Method name: " + name ); } - public TypeOfReturnNotMatchException(String name){ - super("Constructor " + name + " must not have a return"); - } } diff --git a/src/main/java/de/maishai/typedast/ExceptionHandler/VariableNotDeclaredException.java b/src/main/java/de/maishai/typedast/ExceptionHandler/VariableNotDeclaredException.java index 72c7a13..6994183 100644 --- a/src/main/java/de/maishai/typedast/ExceptionHandler/VariableNotDeclaredException.java +++ b/src/main/java/de/maishai/typedast/ExceptionHandler/VariableNotDeclaredException.java @@ -1,10 +1,11 @@ package de.maishai.typedast.ExceptionHandler; -public class VariableNotDeclaredException extends RuntimeException{ +public class VariableNotDeclaredException extends RuntimeException { public VariableNotDeclaredException(String variableName) { super("Variable '" + variableName + "' not declared"); } + public VariableNotDeclaredException(String variableName, String constrOrMethod) { super("Variable '" + variableName + "' not declared in'" + constrOrMethod + "'"); } diff --git a/src/main/java/de/maishai/typedast/Util/TypedExpressionUtil.java b/src/main/java/de/maishai/typedast/Util/TypedExpressionUtil.java index 4618846..62325ff 100644 --- a/src/main/java/de/maishai/typedast/Util/TypedExpressionUtil.java +++ b/src/main/java/de/maishai/typedast/Util/TypedExpressionUtil.java @@ -1,8 +1,24 @@ package de.maishai.typedast.Util; -import de.maishai.ast.records.*; +import de.maishai.ast.records.CharLiteral; +import de.maishai.ast.records.Expression; +import de.maishai.ast.records.IntLiteral; +import de.maishai.ast.records.BoolLiteral; +import de.maishai.ast.records.Binary; +import de.maishai.ast.records.FieldVarAccess; +import de.maishai.ast.records.MethodCall; +import de.maishai.ast.records.New; +import de.maishai.ast.records.Unary; import de.maishai.typedast.TypedExpression; -import de.maishai.typedast.typedclass.*; +import de.maishai.typedast.typedclass.TypedBoolLiteral; +import de.maishai.typedast.typedclass.TypedCharLiteral; +import de.maishai.typedast.typedclass.TypedIntLiteral; +import de.maishai.typedast.typedclass.TypedBinary; +import de.maishai.typedast.typedclass.TypedFieldVarAccess; +import de.maishai.typedast.typedclass.TypedMethodCall; +import de.maishai.typedast.typedclass.TypedNew; +import de.maishai.typedast.typedclass.TypedUnary; +import de.maishai.typedast.typedclass.TypedProgram; public class TypedExpressionUtil { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index f18c3f3..01dbc32 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -6,7 +6,6 @@ import de.maishai.ast.records.Declaration; import de.maishai.ast.records.Method; import de.maishai.typedast.ClassContext; import de.maishai.typedast.Type; -import de.maishai.typedast.TypedExpression; import de.maishai.typedast.TypedNode; import lombok.AllArgsConstructor; import lombok.Data; @@ -138,21 +137,21 @@ public class TypedClass implements TypedNode { } public Type getParameterTypeInCurrentMethod(String parameterName) { - if(parameterName == null) { + if (parameterName == null) { throw new RuntimeException("Parameter name is null"); } return getCurrentMethod().getTypedParameters().stream().filter(parameter -> parameter.getParaName().equals(parameterName)).findFirst().get().getType(); } public Type getParameterTypeInCurrentConstructor(String parameterName) { - if(parameterName == null) { + if (parameterName == null) { throw new RuntimeException("Parameter name is null"); } return getCurrentConstructor().getTypedParameters().stream().filter(parameter -> parameter.getParaName().equals(parameterName)).findFirst().get().getType(); } public boolean isMethodOfCurrentClass(String methodName) { - if(methodName == null) { + if (methodName == null) { return false; } @@ -165,7 +164,7 @@ public class TypedClass implements TypedNode { } public Type getMethodType(String methodName) { - if(methodName == null) { + if (methodName == null) { throw new RuntimeException("Method name is null"); } @@ -178,7 +177,7 @@ public class TypedClass implements TypedNode { } public boolean isThereField(String fieldName) { - if(fieldName == null) { + if (fieldName == null) { return false; } @@ -191,7 +190,7 @@ public class TypedClass implements TypedNode { } public Type getFieldType(String fieldName) { - if(fieldName == null) { + if (fieldName == null) { throw new RuntimeException("Field name is null"); } for (TypedDeclaration f : typedDeclarations) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java index d70aa51..8bb5fff 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java @@ -33,13 +33,14 @@ public class TypedConstructor implements TypedNode { this.typedParameters = typedParameters; this.typedBlock = typedBlock; } + public TypedConstructor(Constructor unTypedConstructor, String className) { convertToTypedConstructor(unTypedConstructor, className); } private void convertToTypedConstructor(Constructor unTypedConstructor, String className) { - if(!unTypedConstructor.className().equals(className)) { - throw new RuntimeException("Constructor name "+ unTypedConstructor.className() +" must be the same as class name" + className); + if (!unTypedConstructor.className().equals(className)) { + throw new RuntimeException("Constructor name " + unTypedConstructor.className() + " must be the same as class name" + className); } name = unTypedConstructor.className(); convertToTypedParameter(unTypedConstructor.params()); @@ -47,7 +48,7 @@ public class TypedConstructor implements TypedNode { } private void convertToTypedParameter(List params) { - if(params.isEmpty()) { + if (params.isEmpty()) { return; } @@ -75,22 +76,22 @@ public class TypedConstructor implements TypedNode { } public boolean isLocalVariablePresent(String localVarName) { - if(localVarName == null) { - return false; - } + if (localVarName == null) { + return false; + } return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName)); } public boolean isParameterPresent(String parameterName) { - if(parameterName == null) { + if (parameterName == null) { return false; } return typedParameters.stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName)); } public boolean isLocalVariableInConstructor(String localVarName) { - if(localVarName == null) { + if (localVarName == null) { return false; } @@ -98,7 +99,7 @@ public class TypedConstructor implements TypedNode { } public Type getLocalVariableType(String localVarName) { - if(localVarName == null) { + if (localVarName == null) { throw new RuntimeException("Local variable name is null"); } @@ -106,7 +107,7 @@ public class TypedConstructor implements TypedNode { } private void checkIfParameterExists(String paraName) { - if(paraName == null) { + if (paraName == null) { throw new RuntimeException("Parameter name is null"); } @@ -116,7 +117,7 @@ public class TypedConstructor implements TypedNode { } public void deleteLocalVariableInConstructor(String localVarName) { - if(localVarName == null) { + if (localVarName == null) { throw new RuntimeException("Local variable name is null"); } localVariables.removeIf(localVariable -> localVariable.getName().equals(localVarName)); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java b/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java index e7c7678..7039786 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java @@ -33,7 +33,7 @@ public final class TypedDeclaration implements TypedNode { TypedClass currentClass = typedProgram.getCurrentClass(); if (type.getReference() != null && !currentClass.getClassName().equals(type.getReference()) && !typedProgram.isTypedClassPresent(type.getReference())) { - throw new RuntimeException("Type " + type.getReference() + " not found"); + throw new RuntimeException("Type " + type.getReference() + " not found"); } if (currentClass.isThereField(name)) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java b/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java index 45d0d49..e84ba75 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java @@ -1,7 +1,10 @@ package de.maishai.typedast.typedclass; -import de.maishai.ast.records.*; -import de.maishai.typedast.*; +import de.maishai.ast.records.DoWhile; +import de.maishai.typedast.MethodContext; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedExpression; +import de.maishai.typedast.TypedStatement; import lombok.AllArgsConstructor; import lombok.Data; import org.objectweb.asm.Label; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFor.java b/src/main/java/de/maishai/typedast/typedclass/TypedFor.java index 03998ee..92b0f3d 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFor.java @@ -1,7 +1,10 @@ package de.maishai.typedast.typedclass; -import de.maishai.ast.records.*; -import de.maishai.typedast.*; +import de.maishai.ast.records.For; +import de.maishai.typedast.MethodContext; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedExpression; +import de.maishai.typedast.TypedStatement; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java b/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java index dbca1cb..d9f50cf 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java @@ -1,7 +1,10 @@ package de.maishai.typedast.typedclass; -import de.maishai.ast.records.*; -import de.maishai.typedast.*; +import de.maishai.ast.records.IfElse; +import de.maishai.typedast.MethodContext; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedExpression; +import de.maishai.typedast.TypedStatement; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java index 15c8eb8..96468d5 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java @@ -2,8 +2,13 @@ package de.maishai.typedast.typedclass; import de.maishai.ast.records.Method; import de.maishai.ast.records.Parameter; -import de.maishai.typedast.*; +import de.maishai.typedast.CodeGenUtils; import de.maishai.typedast.ExceptionHandler.ParameterAlreadyExistsException; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedNode; +import de.maishai.typedast.TypedStatement; +import de.maishai.typedast.MethodContext; +import de.maishai.typedast.ClassContext; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedNew.java b/src/main/java/de/maishai/typedast/typedclass/TypedNew.java index bc82f63..77bbd16 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedNew.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedNew.java @@ -2,8 +2,12 @@ package de.maishai.typedast.typedclass; import de.maishai.ast.records.Expression; import de.maishai.ast.records.New; -import de.maishai.typedast.*; +import de.maishai.typedast.MethodContext; import de.maishai.typedast.ExceptionHandler.NotMatchConstructorException; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedExpression; +import de.maishai.typedast.TypedStatement; +import de.maishai.typedast.CodeGenUtils; import lombok.AllArgsConstructor; import lombok.Data; import org.objectweb.asm.Opcodes; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedParameter.java b/src/main/java/de/maishai/typedast/typedclass/TypedParameter.java index 2503c5b..cdd45c7 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedParameter.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedParameter.java @@ -16,6 +16,7 @@ public class TypedParameter implements TypedNode { public TypedParameter(Parameter unTypedParameter) { convertToTypedParameter(unTypedParameter); } + private void convertToTypedParameter(Parameter unTypedParameter) { paraName = unTypedParameter.name(); type = unTypedParameter.type(); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java b/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java index 5a90854..717b599 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java @@ -1,7 +1,11 @@ package de.maishai.typedast.typedclass; import de.maishai.ast.records.Print; -import de.maishai.typedast.*; +import de.maishai.typedast.MethodContext; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedExpression; +import de.maishai.typedast.TypedStatement; +import de.maishai.typedast.CodeGenUtils; import lombok.AllArgsConstructor; import org.objectweb.asm.Opcodes; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java index c6ebbd4..48bde7e 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java @@ -45,7 +45,7 @@ public class TypedProgram { } public boolean isClassWithNamePresent(String className) { - if(className == null){ + if (className == null) { return false; } @@ -53,34 +53,35 @@ public class TypedProgram { } public Type getTypeOfFieldNameInClass(String className, String fieldName) { - if(className == null || fieldName == null){ + if (className == null || fieldName == null) { return null; } return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName); } + public Type getTypeOfFieldOrMethodNameInClass(String className, String fieldName) { - if(className == null || fieldName == null){ + if (className == null || fieldName == null) { return null; } TypedClass c = typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get(); - if(c.isThereField(fieldName)){ + if (c.isThereField(fieldName)) { return c.getFieldType(fieldName); - }else if(c.isMethodOfCurrentClass(fieldName)){ + } else if (c.isMethodOfCurrentClass(fieldName)) { return c.getMethodType(fieldName); } return null; } public TypedClass getTypedClass(String className) { - if(className == null){ + if (className == null) { return null; } return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get(); } public boolean isTypedClassPresent(String className) { - if(className == null){ + if (className == null) { return false; } return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className)); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java index 37adb9d..05531d7 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java @@ -42,8 +42,8 @@ public class TypedReturn implements TypedStatement { if (currentClass.isCurrentMethodPresent() && currentMethod.getReturnType().getKind() != this.type.getKind()) { throw new TypeOfReturnNotMatchException(currentMethod.getReturnType().getKind().name(), - this.type.getKind().name(), currentMethod.getName()); - } + this.type.getKind().name(), currentMethod.getName()); + } return type; }