diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index f1bccbb..a1c1dcd 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -56,7 +56,7 @@ public class TypedClass implements TypedNode { typedDeclarations.add(new TypedDeclaration(typedProgram, declaration)); } for (Constructor constructor : c.constructors()) { - typedConstructors.add(new TypedConstructor(typedProgram, constructor)); + typedConstructors.add(new TypedConstructor(typedProgram, constructor, this.className)); } for (Method method : c.methods()) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java index 6546d7c..f081087 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java @@ -32,9 +32,14 @@ public class TypedConstructor implements TypedNode { this.typedParameters = typedParameters; this.typedBlock = typedBlock; } + public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) { + convertToTypedConstructor(typedProgram, unTypedConstructor, className); + } - - public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) { + public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String 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(typedProgram, unTypedConstructor.params()); type = Type.VOID; @@ -59,9 +64,7 @@ public class TypedConstructor implements TypedNode { return type; } - public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) { - convertToTypedConstructor(typedProgram, unTypedConstructor); - } + public boolean isLocalVariablePresent(String localVarName) { return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName));