Added two attributes in TypedClass

and some methods
This commit is contained in:
ahmad 2024-05-11 13:51:42 +02:00
parent 47ecd27fef
commit 5cad5992f2

View File

@ -25,11 +25,53 @@ public class TypedClass implements TypedNode {
private List<TypedField> typedFields = new ArrayList<>(); private List<TypedField> typedFields = new ArrayList<>();
private List<TypedMethod> typedMethods = new ArrayList<>(); private List<TypedMethod> typedMethods = new ArrayList<>();
private List<TypedConstructor> typedConstructors = new ArrayList<>(); private List<TypedConstructor> typedConstructors = new ArrayList<>();
private TypedMethod currentMethod;
private TypedConstructor currentConstructor;
private Type type; private Type type;
public TypedClass(Map<String, Type> localVar, Class c) { public TypedClass(Map<String, Type> localVar, Class c) {
convertToTypedClass(localVar, 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<String, Type> localVar, Class c) { public void convertToTypedClass(Map<String, Type> localVar, Class c) {
className = c.classname(); className = c.classname();
@ -41,14 +83,17 @@ public class TypedClass implements TypedNode {
for (Constructor constructor : c.constructors()) { for (Constructor constructor : c.constructors()) {
typedConstructors.add(new TypedConstructor(localVar, this, constructor)); typedConstructors.add(new TypedConstructor(localVar, this, constructor));
enterConstructor(typedConstructors.get(typedConstructors.size() - 1));
typedConstructors.get(typedConstructors.size() - 1).convertToBlock(localVar, this, constructor); typedConstructors.get(typedConstructors.size() - 1).convertToBlock(localVar, this, constructor);
exitConstructor();
} }
for (Method method : c.methods()) { for (Method method : c.methods()) {
typedMethods.add(new TypedMethod(localVar, this, method)); typedMethods.add(new TypedMethod(localVar, this, method));
enterMethod(typedMethods.get(typedMethods.size() - 1));
typedMethods.get(typedMethods.size() - 1).convertToTypedBlock(localVar, this, method); typedMethods.get(typedMethods.size() - 1).convertToTypedBlock(localVar, this, method);
exitMethod();
} }
System.out.println("TypedClass: " + this.toString());
} }
@Override @Override
@ -86,8 +131,18 @@ public class TypedClass implements TypedNode {
} }
return false; 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 (TypedMethod m : typedMethods) {
for (TypedParameter p : m.getTypedParameters()) { for (TypedParameter p : m.getTypedParameters()) {
if (p.getParaName().equals(parameterName)) { if (p.getParaName().equals(parameterName)) {
@ -97,6 +152,14 @@ public class TypedClass implements TypedNode {
} }
return null; 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) { public boolean isThereField(String fieldName) {