diff --git a/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java b/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java index b24bcfce..63dd80f8 100644 --- a/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java +++ b/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java @@ -56,10 +56,10 @@ public class AssumptionGenerator { argAss.put(m, ass); System.out.println(String.format("Methodenname: %s , Arguments: %s -> ReturnType %s ", methodName, typeArg, returnType)); - } + } - - //TODO : Assumption für die eingene aktuelle Klasse + // Assumption für die eingene aktuelle Klasse + fAss.put("this", cl.getType()); diff --git a/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java b/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java index e3ad677b..4c7703bf 100644 --- a/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java +++ b/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java @@ -3,6 +3,10 @@ package de.dhbwstuttgart.strucTypes3; import java.util.List; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FieldDeclaration; +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Expression; @@ -12,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Statement; public class ToStringGenerator { - public String klasseToString(ClassOrInterface cl, AssTuple assAll) { + public static String klasseToString(ClassOrInterface cl, AssTuple assAll) { // Als nächstes muss die Expression getypt werden @@ -59,5 +63,40 @@ public class ToStringGenerator { } + public static String interface2String(ClassOrInterface face) { + + + + // Ausgabe name + String n = face.getClassName().toString(); + + // Ausgabe Generics + String generics = ""; + + //for ( GenericTypeVar f : face.getGenericDeclarationList()) { + //generics = generics + " " + f.toString(); + //} + + // Ausgabe der Felder + String felder = ""; + for (Field f : face.getFieldDecl()) { + felder = f.toString(); + } + + // Ausgabe der Methoden + String methods = ""; + for (Method m : face.getMethods()) { + String mName = m.getName() + " ( "; + //m.getParameterList().getFormalparalist().forEach((x) -> { mName.concat(x.getName().toString()); }); + for (FormalParameter fp : m.getParameterList().getFormalparalist()) { + mName = mName + " "+ fp.getName(); + } + methods = methods + mName + ") " ; + } + + return String.format(" interface: %s %s %s %s \n" , n, generics , felder, methods); + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index a69a55e3..66eb84cd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -54,6 +54,10 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith return this.name; } + public GenericDeclarationList getGenericDeclarationList() { + return this.genericClassParameters; + } + // Get modifiers public int getModifiers(){ return this.modifiers; diff --git a/test/strucTypes3/Construct.java b/test/strucTypes3/Construct.java index 52997243..97074789 100644 --- a/test/strucTypes3/Construct.java +++ b/test/strucTypes3/Construct.java @@ -46,7 +46,21 @@ public class Construct { List fielddecl = new ArrayList<>(); fielddecl.add(field); JavaClassName name = new JavaClassName(fieldConstriant.getReveiver().toString()); - ClassOrInterface face = new ClassOrInterface(0, name, fielddecl, null, null, null, null, null , null); + + + //Erstellen der Generics + List genericTypeVarList = new ArrayList<>(); + String type_of_field = fieldConstriant.getAttribut().toString(); + genericTypeVarList.add(new GenericTypeVar(type_of_field, null, new NullToken(), new NullToken())); + GenericDeclarationList genericDeclaraitonList = new GenericDeclarationList(genericTypeVarList, new NullToken()); + + + // methods + List methods = new ArrayList(); + + + ClassOrInterface face = new ClassOrInterface(0, name, fielddecl, methods, genericDeclaraitonList, null, true, null , null); + return face; } diff --git a/test/strucTypes3/GeneralParserTestConstruct.java b/test/strucTypes3/GeneralParserTestConstruct.java index a8ab15ff..d1db8b59 100644 --- a/test/strucTypes3/GeneralParserTestConstruct.java +++ b/test/strucTypes3/GeneralParserTestConstruct.java @@ -13,6 +13,7 @@ import de.dhbwstuttgart.strucTypes3.AssTuple; import de.dhbwstuttgart.strucTypes3.AssumptionGenerator; import de.dhbwstuttgart.strucTypes3.ConstraintAbstract; import de.dhbwstuttgart.strucTypes3.HelpMethoden; +import de.dhbwstuttgart.strucTypes3.ToStringGenerator; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.FormalParameter; @@ -57,6 +58,7 @@ public class GeneralParserTestConstruct { // filenames.add("FieldVarTest.jav"); filenames.add("StructuralTypesSimpleSkript.jav"); + //filenames.add("StructuralTypesMiddle.jav"); // filenames.add("StructuralTypesField.jav"); // filenames.add("Main.jav"); @@ -90,7 +92,13 @@ public class GeneralParserTestConstruct { List sf2 = new ArrayList<>(); constraints.forEach( (constraint) -> {sf2.add( Construct.constructInterfaces(constraint)); } ); + //sf2.forEach((x) -> {if (x != null ) { String y = ToStringGenerator.interface2String(x); System.out.println(y); }} ); + for (int i = 0; i < sf2.size() ; i++) { + if (sf2.get(i) != null ) { + System.out.println(ToStringGenerator.interface2String(sf2.get(i))); + } + } System.out.println(sf2.size()); diff --git a/test/strucTypes3/StructuralTypesMiddle.jav b/test/strucTypes3/StructuralTypesMiddle.jav new file mode 100644 index 00000000..4f832ff3 --- /dev/null +++ b/test/strucTypes3/StructuralTypesMiddle.jav @@ -0,0 +1,27 @@ + + + +class A { + + //Integer feld1; + + //feld2; + + + //mtNeu() { return new Integer(); } + + //mtcast(a) { return (Integer) a; } + + mfeld(r) { return r.feld; } + + + mt1(x,y,z) { return x.sub(y).add(z); } + + mt(g,h,i) { return g.div( h , i) ; } + + } + + +class Integer { +} + \ No newline at end of file