From 5cad5992f20fc1335b7765dea1494590d512b5b2 Mon Sep 17 00:00:00 2001 From: ahmad Date: Sat, 11 May 2024 13:51:42 +0200 Subject: [PATCH] Added two attributes in TypedClass and some methods --- .../typedast/typedclass/TypedClass.java | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index d7edc53..626818b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -25,11 +25,53 @@ public class TypedClass implements TypedNode { private List typedFields = new ArrayList<>(); private List typedMethods = new ArrayList<>(); private List typedConstructors = new ArrayList<>(); + private TypedMethod currentMethod; + private TypedConstructor currentConstructor; private Type type; public TypedClass(Map localVar, Class c) { convertToTypedClass(localVar, c); } + public void enterMethod(TypedMethod method) { + currentMethod = method; + } + public void exitMethod() { + currentMethod = null; + } + public void enterConstructor(TypedConstructor constructor) { + currentConstructor = constructor; + } + public void exitConstructor() { + currentConstructor = null; + } + public boolean isCurrentMethodPresent() { + return currentMethod != null; + } + public boolean isCurrentConstructorPresent() { + return currentConstructor != null; + } + public boolean isParameterNameInCurrentMethod(String parameterName) { + if (currentMethod == null) { + return false; + } + for (TypedParameter p : currentMethod.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return true; + } + } + return false; + } + public boolean isParameterNameInCurrentConstructor(String parameterName) { + if (currentConstructor == null) { + return false; + } + for (TypedParameter p : currentConstructor.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return true; + } + } + return false; + } public void convertToTypedClass(Map localVar, Class c) { className = c.classname(); @@ -41,14 +83,17 @@ public class TypedClass implements TypedNode { for (Constructor constructor : c.constructors()) { typedConstructors.add(new TypedConstructor(localVar, this, constructor)); + enterConstructor(typedConstructors.get(typedConstructors.size() - 1)); typedConstructors.get(typedConstructors.size() - 1).convertToBlock(localVar, this, constructor); + exitConstructor(); } for (Method method : c.methods()) { typedMethods.add(new TypedMethod(localVar, this, method)); + enterMethod(typedMethods.get(typedMethods.size() - 1)); typedMethods.get(typedMethods.size() - 1).convertToTypedBlock(localVar, this, method); + exitMethod(); } - System.out.println("TypedClass: " + this.toString()); } @Override @@ -86,8 +131,18 @@ public class TypedClass implements TypedNode { } return false; } + public boolean isParameterWitNameInConstructor(String parameterName) { + for (TypedConstructor c : typedConstructors) { + for (TypedParameter p : c.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return true; + } + } + } + return false; + } - public Type getParameterType(String parameterName) { + public Type getParameterTypeInCurrentMethod(String parameterName) { for (TypedMethod m : typedMethods) { for (TypedParameter p : m.getTypedParameters()) { if (p.getParaName().equals(parameterName)) { @@ -97,6 +152,14 @@ public class TypedClass implements TypedNode { } return null; } + public Type getParameterTypeInCurrentConstructor(String parameterName) { + for (TypedParameter p : currentConstructor.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return p.getType(); + } + } + return null; + } public boolean isThereField(String fieldName) {