mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:08:03 +00:00
Added two attributes in TypedClass
and some methods
This commit is contained in:
parent
47ecd27fef
commit
5cad5992f2
@ -25,11 +25,53 @@ public class TypedClass implements TypedNode {
|
||||
private List<TypedField> typedFields = new ArrayList<>();
|
||||
private List<TypedMethod> typedMethods = new ArrayList<>();
|
||||
private List<TypedConstructor> typedConstructors = new ArrayList<>();
|
||||
private TypedMethod currentMethod;
|
||||
private TypedConstructor currentConstructor;
|
||||
private Type type;
|
||||
|
||||
public TypedClass(Map<String, Type> 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<String, Type> 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) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user