diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index 9b25c6e..d7edc53 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -25,6 +25,7 @@ public class TypedClass implements TypedNode { private List typedFields = new ArrayList<>(); private List typedMethods = new ArrayList<>(); private List typedConstructors = new ArrayList<>(); + private Type type; public TypedClass(Map localVar, Class c) { convertToTypedClass(localVar, c); @@ -32,6 +33,7 @@ public class TypedClass implements TypedNode { public void convertToTypedClass(Map localVar, Class c) { className = c.classname(); + type = Type.REFERENCE(className); for (Declaration field : c.fieldDeclarations()) { typedFields.add(new TypedField(localVar, this, field)); @@ -46,7 +48,7 @@ public class TypedClass implements TypedNode { typedMethods.add(new TypedMethod(localVar, this, method)); typedMethods.get(typedMethods.size() - 1).convertToTypedBlock(localVar, this, method); } - + System.out.println("TypedClass: " + this.toString()); } @Override @@ -74,6 +76,61 @@ public class TypedClass implements TypedNode { return new TypedClass(local, c); } + public boolean isParameterWitNameInMethod(String parameterName) { + for (TypedMethod m : typedMethods) { + for (TypedParameter p : m.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return true; + } + } + } + return false; + } + + public Type getParameterType(String parameterName) { + for (TypedMethod m : typedMethods) { + for (TypedParameter p : m.getTypedParameters()) { + if (p.getParaName().equals(parameterName)) { + return p.getType(); + } + } + } + return null; + } + + public boolean isThereField(String fieldName) { + + for (TypedField f : typedFields) { + if (f.getVarName().equals(getFieldNameWithOutThis(fieldName))) { + return true; + } + } + return false; + } + private String getFieldNameWithOutThis(String fieldName) { + if(fieldName.startsWith("this.")){ + fieldName = fieldName.substring(5); + } + return fieldName; + } + public Type getFieldType(String fieldName) { + for (TypedField f : typedFields) { + if (f.getVarName().equals(getFieldNameWithOutThis(fieldName))) { + return f.getType(); + } + } + return null; + } + public Type getMethodType(String methodName) { + for (TypedMethod m : typedMethods) { + if (m.getName().equals(methodName)) { + return m.getReturnType(); + } + } + return null; + } + + public byte[] codeGen() { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", null);