diff --git a/src/de/dhbwstuttgart/strucTypes3/AssTuple.java b/src/de/dhbwstuttgart/strucTypes3/AssTuple.java new file mode 100644 index 00000000..c32e35f9 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/AssTuple.java @@ -0,0 +1,64 @@ +package de.dhbwstuttgart.strucTypes3; + +import java.util.Map; + +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + +public class AssTuple { + + private Map fAss; + private Map mAss; + private Map> argAss; + + public AssTuple(Map fAss, + Map mAss, + Map> argAss) { + super(); + this.fAss = fAss; + this.mAss = mAss; + this.argAss = argAss; + } + + public RefTypeOrTPHOrWildcardOrGeneric getTypeOfLocalVar(String name , Method method) { + + // Schaue als erstes in den Argumenten dann in den Feldvariablen der Klasse + Map argAssMethod = argAss.get(method); + if (argAssMethod.containsKey(name)) { + return argAssMethod.get(name); + } + else if (fAss.containsKey(name)) { + return fAss.get(name); + } + else { + System.err.println("Fehler: Typ nicht bekannt"); + return null; + } + + + } + + public Map getfAss() { + return fAss; + } + + public void setfAss(Map fAss) { + this.fAss = fAss; + } + + public Map getmAss() { + return mAss; + } + + public void setmAss(Map mAss) { + this.mAss = mAss; + } + + public Map> getArgAss() { + return argAss; + } + + public void setArgAss(Map> argAss) { + this.argAss = argAss; + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java b/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java new file mode 100644 index 00000000..1ec57122 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/AssumptionGenerator.java @@ -0,0 +1,69 @@ +package de.dhbwstuttgart.strucTypes3; + +import java.util.HashMap; +import java.util.Map; + +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + +public class AssumptionGenerator { + + /* + * Generiert die Assumptions einer Klasse + */ + public static AssTuple generateAssumptions(ClassOrInterface cl) { + + // Erstellen der Assumptions + // (Assumption für die Argumente der Methode werden gleich + // miterstellt) + + // Assumptions + Map fAss = new HashMap<>(); + Map mAss = new HashMap<>(); + // Assumptions für die MethodenParameter + Map> argAss = new HashMap<>(); + + AssTuple assAll = new AssTuple(fAss, mAss, argAss); + + // Extraktion aller Typen der Methoden + + // Assumptions für Felder + for (Field f : cl.getFieldDecl()) { + String fieldname = f.getName(); + String type = f.getType().toString(); + fAss.put(fieldname, f.getType()); + System.out.println(String.format("Feldname: %s Typ: %s", fieldname, type)); + } + + + // Assumptions für Methoden + for (Method m : cl.getMethods()) { + String methodName = m.getName(); + String returnType = m.getType().toString(); + mAss.put(methodName, m.getType()); + + String typeArg = ""; + Map ass = new HashMap<>(); + for (FormalParameter p : m.getParameterList().getFormalparalist()) { + String pName = p.getName(); + String pType = p.getType().toString(); + typeArg = typeArg + String.format("%s : %s", pName, pType); + ass.put(p.getName(), p.getType()); + } + 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 + + + + return assAll; + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes3/ConstraintAbstract.java b/src/de/dhbwstuttgart/strucTypes3/ConstraintAbstract.java new file mode 100644 index 00000000..a6b28eaf --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/ConstraintAbstract.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.strucTypes3; + +public class ConstraintAbstract { + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes3/FieldConstraint.java b/src/de/dhbwstuttgart/strucTypes3/FieldConstraint.java new file mode 100644 index 00000000..67b4feaa --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/FieldConstraint.java @@ -0,0 +1,49 @@ +package de.dhbwstuttgart.strucTypes3; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + + +class FieldConstraint extends ConstraintAbstract { + + private RefTypeOrTPHOrWildcardOrGeneric reveiver; + private String name_of_field; + private RefTypeOrTPHOrWildcardOrGeneric attribut; + + public FieldConstraint(RefTypeOrTPHOrWildcardOrGeneric receiver, String name_of_field, + RefTypeOrTPHOrWildcardOrGeneric attribut) { + super(); + this.reveiver = receiver; + this.name_of_field = name_of_field; + this.attribut = attribut; + } + + public String toString() { + return String.format("FieldConstraint(%s , %s , %s)" , reveiver, name_of_field, attribut ); + } + + public RefTypeOrTPHOrWildcardOrGeneric getReveiver() { + return reveiver; + } + + public void setReveiver(RefTypeOrTPHOrWildcardOrGeneric reveiver) { + this.reveiver = reveiver; + } + + public String getName_of_field() { + return name_of_field; + } + + public void setName_of_field(String name_of_field) { + this.name_of_field = name_of_field; + } + + public RefTypeOrTPHOrWildcardOrGeneric getAttribut() { + return attribut; + } + + public void setAttribut(RefTypeOrTPHOrWildcardOrGeneric attribut) { + this.attribut = attribut; + } + + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes3/GleichConstraint.java b/src/de/dhbwstuttgart/strucTypes3/GleichConstraint.java new file mode 100644 index 00000000..d83a61e7 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/GleichConstraint.java @@ -0,0 +1,45 @@ +package de.dhbwstuttgart.strucTypes3; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + + +public class GleichConstraint extends ConstraintAbstract { + + private RefTypeOrTPHOrWildcardOrGeneric a; + private RefTypeOrTPHOrWildcardOrGeneric b; + + // Type A ist Type B + public GleichConstraint(RefTypeOrTPHOrWildcardOrGeneric a, RefTypeOrTPHOrWildcardOrGeneric b) { + this.a = a; + this.b = b; + } + + + public String toString() { + return String.format("GleichConstraint( %s , %s )" , a.toString(), b.toString()); + } + + + public RefTypeOrTPHOrWildcardOrGeneric getA() { + return a; + } + + + public void setA(RefTypeOrTPHOrWildcardOrGeneric a) { + this.a = a; + } + + + public RefTypeOrTPHOrWildcardOrGeneric getB() { + return b; + } + + + public void setB(RefTypeOrTPHOrWildcardOrGeneric b) { + this.b = b; + } + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes3/HelpMethoden.java b/src/de/dhbwstuttgart/strucTypes3/HelpMethoden.java new file mode 100644 index 00000000..e0ad99cc --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/HelpMethoden.java @@ -0,0 +1,209 @@ +package de.dhbwstuttgart.strucTypes3; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.FieldVar; +import de.dhbwstuttgart.syntaxtree.statement.LocalVar; +import de.dhbwstuttgart.syntaxtree.statement.MethodCall; +import de.dhbwstuttgart.syntaxtree.statement.Receiver; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.strucTypes3.AssTuple; +import de.dhbwstuttgart.strucTypes3.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes3.FieldConstraint; +import de.dhbwstuttgart.strucTypes3.GleichConstraint; +import de.dhbwstuttgart.strucTypes3.MethodConstraint; + +public class HelpMethoden { + + public static String expression2String(Expression expression) { + + // LocalVar + if (expression.getClass().equals(LocalVar.class)) { + String resultStr = ""; + LocalVar lvar = (LocalVar) expression; + resultStr = resultStr + lvar.get_expression(); + return resultStr; + } + // FeldVar + else if (expression.getClass().equals(FieldVar.class)) { + FieldVar fieldVar = (FieldVar) expression; + Expression receiver = fieldVar.getReceiver(); + String result = HelpMethoden.expression2String(receiver); + result = result + "." + fieldVar.getFieldVarName(); + return result; + } + // MethodCall + else if (expression.getClass().equals(MethodCall.class)) { + MethodCall methodCall = (MethodCall) expression; + + // nur bei MethodCall reciever = Typ Reciver mit eigenem TPH + Expression receiver = methodCall.get_Receiver(); + + String result; + if (receiver.getClass().equals(Receiver.class)) { + Receiver r_cast = (Receiver) receiver; + result = HelpMethoden.expression2String(r_cast.get_Expression()); + } else { + result = HelpMethoden.expression2String(receiver); + } + + // Jetzt muss noch die ArgumentListe ermittelt werden + // Problem, Diese kann alles enthalten + String argumentsStr = ""; + List arguments = methodCall.get_ArgList().getArguments(); + for (Expression arg : arguments) { + argumentsStr = argumentsStr + " " + HelpMethoden.expression2String(arg); + } + + result = String.format("%s.%s(%s)", result, methodCall.get_Name(), argumentsStr); + return result; + } else { + System.err.println("Fehler"); + return null; + } + } + + public static String expression_typed2String(Expression expression) { + + // LocalVar + if (expression.getClass().equals(LocalVar.class)) { + String resultStr = ""; + LocalVar lvar = (LocalVar) expression; + resultStr = resultStr + lvar.get_expression() + ":" + lvar.getType().toString(); + return resultStr; + } + // FeldVar + else if (expression.getClass().equals(FieldVar.class)) { + FieldVar fieldVar = (FieldVar) expression; + Expression receiver = fieldVar.getReceiver(); + String result = HelpMethoden.expression_typed2String(receiver); + result = result + "." + fieldVar.getFieldVarName() + ":" + fieldVar.getType().toString(); + return result; + } + // MethodCall + else if (expression.getClass().equals(MethodCall.class)) { + MethodCall methodCall = (MethodCall) expression; + + // nur bei MethodCall reciever = Typ Reciver mit eigenem TPH + Expression receiver = methodCall.get_Receiver(); + + String result; + if (receiver.getClass().equals(Receiver.class)) { + Receiver r_cast = (Receiver) receiver; + result = HelpMethoden.expression_typed2String(r_cast.get_Expression()); + } else { + result = HelpMethoden.expression_typed2String(receiver) + ":" + receiver.getType().toString(); + } + + // Jetzt muss noch die ArgumentListe ermittelt werden + // Problem, Diese kann alles enthalten + String argumentsStr = ""; + List arguments = methodCall.get_ArgList().getArguments(); + for (Expression arg : arguments) { + argumentsStr = argumentsStr + " " + HelpMethoden.expression_typed2String(arg) ;//+ arg.getType(); + } + + result = String.format("%s.%s(%s)", result, methodCall.get_Name(), argumentsStr); + return result; + } else { + System.err.println("Fehler"); + return null; + } + } + + + // Diese Methode übernimmt die Berechnung der Typen + public static List TypeExpr(AssTuple ass, Expression expression, Method method, ClassOrInterface cl) { + + // LocalVar (Constraints für den Algo, Constraints für die Interfaces + // usw. ) + // LocalVar + if (expression.getClass().equals(LocalVar.class)) { + LocalVar lvar = (LocalVar) expression; + List constraints = new ArrayList(); + RefTypeOrTPHOrWildcardOrGeneric type = ass.getTypeOfLocalVar(lvar.get_expression(), method); + GleichConstraint constraint = new GleichConstraint(lvar.getType(), type); + constraints.add(constraint); + return constraints; + } + // FeldVar + else if (expression.getClass().equals(FieldVar.class)) { + FieldVar fieldVar = (FieldVar) expression; + Expression receiver = fieldVar.getReceiver(); + List constraints = HelpMethoden.TypeExpr(ass, receiver, method, cl); + + // Hier muss der Constraint angelegt werden. Der Type receiver X besitzt ein feld mit dem Typen Y + // constriant(c,f,c') + // constraint(TypeKlasse, feldname, typdesfelde) + // constriant(typReveier , besitzt ein feld mit dem typen , typdesfeldes); + // constriant(typReceiver, name des Feldes , TypDesFeldes). + FieldConstraint constraint = new FieldConstraint(receiver.getType(), fieldVar.getFieldVarName() , fieldVar.getType()); + constraints.add(constraint); + return constraints; + + } + // MethodCall + else if (expression.getClass().equals(MethodCall.class)) { + MethodCall methodCall = (MethodCall) expression; + + // nur bei MethodCall reciever = Typ Reciver mit eigenem TPH + Expression receiver = methodCall.get_Receiver(); + + List constraints; + if (receiver.getClass().equals(Receiver.class)) { + Receiver r_cast = (Receiver) receiver; + constraints = HelpMethoden.TypeExpr(ass, r_cast.get_Expression(), method, cl); + } else { + constraints = HelpMethoden.TypeExpr(ass, receiver, method, cl); + } + + // An dieser Stelle wird der Methoden Constraint erstellt + List argumentTypesVars = new ArrayList<>(); + List argumentTypes = new ArrayList<>(); + for (Expression arg : methodCall.get_ArgList().getArguments()) { + argumentTypesVars.add(arg.getType()); + constraints.addAll(HelpMethoden.TypeExpr(ass, arg, method, cl)); + } + + // Es wird der Typ des übergabeparameter erstellt + List puffer = new ArrayList<>(); + for (RefTypeOrTPHOrWildcardOrGeneric type : argumentTypesVars) { + for (ConstraintAbstract c : constraints) { + if (c.getClass().equals(GleichConstraint.class)) { + GleichConstraint gc = (GleichConstraint) c; + if (gc.getA().equals(type)) { + argumentTypes.add(gc.getB()); + + // subtype + puffer.add(new SubTypeConstraint(gc.getB() , gc.getA() )); + } + } + } + } + + constraints.addAll(puffer); + + + + + + + MethodConstraint methodConstraint = new MethodConstraint(receiver.getType(), methodCall.get_Name(), argumentTypes, methodCall.getType(), argumentTypesVars ); + + constraints.add(methodConstraint); + return constraints; + + + + } else { + System.err.println("Fehler"); + return null; + } + + } + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes3/MethodConstraint.java b/src/de/dhbwstuttgart/strucTypes3/MethodConstraint.java new file mode 100644 index 00000000..12679f26 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/MethodConstraint.java @@ -0,0 +1,33 @@ +package de.dhbwstuttgart.strucTypes3; + +import java.util.List; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + + +class MethodConstraint extends ConstraintAbstract { + + /* Der MethodConstraint + * constraint( typ_receiver, methodname, arguments_typen ( return_type , typvar von argumenttypen ) + */ + + private RefTypeOrTPHOrWildcardOrGeneric receiver; + private String methodName; + private List argumentTypes; + private RefTypeOrTPHOrWildcardOrGeneric returnType; + private List argumentTypeVars; + + public MethodConstraint(RefTypeOrTPHOrWildcardOrGeneric receiver, String methodName, + List argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType, + List argumentTypeVars) { + super(); + this.receiver = receiver; + this.methodName = methodName; + this.argumentTypes = argumentTypes; + this.returnType = returnType; + this.argumentTypeVars = argumentTypeVars; + } + + public String toString() { + return String.format("MethodConstraint( %s, %s , %s (%s , %s ))" , receiver.toString() , methodName, argumentTypes.toString() , returnType.toString() , argumentTypeVars.toString() ); + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes3/SubTypeConstraint.java b/src/de/dhbwstuttgart/strucTypes3/SubTypeConstraint.java new file mode 100644 index 00000000..2c194853 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/SubTypeConstraint.java @@ -0,0 +1,45 @@ +package de.dhbwstuttgart.strucTypes3; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + +public class SubTypeConstraint extends ConstraintAbstract { + + private RefTypeOrTPHOrWildcardOrGeneric basisKlasse; + private RefTypeOrTPHOrWildcardOrGeneric subTypeKlasse; + + public SubTypeConstraint(RefTypeOrTPHOrWildcardOrGeneric basisKlasse, + RefTypeOrTPHOrWildcardOrGeneric subTypeKlasse) { + super(); + this.basisKlasse = basisKlasse; + this.subTypeKlasse = subTypeKlasse; + } + + + public String toString() { + return String.format("SubType( %s <* %s ) " ,basisKlasse, subTypeKlasse); + } + + public RefTypeOrTPHOrWildcardOrGeneric getBasisKlasse() { + return basisKlasse; + } + + public void setBasisKlasse(RefTypeOrTPHOrWildcardOrGeneric basisKlasse) { + this.basisKlasse = basisKlasse; + } + + public RefTypeOrTPHOrWildcardOrGeneric getSubTypeKlasse() { + return subTypeKlasse; + } + + public void setSubTypeKlasse(RefTypeOrTPHOrWildcardOrGeneric subTypeKlasse) { + this.subTypeKlasse = subTypeKlasse; + } + + + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java b/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java new file mode 100644 index 00000000..e3ad677b --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes3/ToStringGenerator.java @@ -0,0 +1,63 @@ +package de.dhbwstuttgart.strucTypes3; + +import java.util.List; + +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.statement.Block; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.Return; +import de.dhbwstuttgart.syntaxtree.statement.Statement; + + +public class ToStringGenerator { + + public String klasseToString(ClassOrInterface cl, AssTuple assAll) { + + // Als nächstes muss die Expression getypt werden + + for (Method m : cl.getMethods()) { + Block block = m.get_Block(); + + /* + * Wahrscheinlich ist der TPH des Blocks der wahre Typ und der Typ + * der methode kann auch kleiner sein + */ + System.out.println("Block" + block.getType().toString()); + + // ein block hat einen TPH und eine Statement Liste + // davon wird das erste statement genommen welches ein + // Return Statement ist + + // TODO: check get 0 + Statement statement = block.getStatements().get(0); + + if (statement.getClass().equals(Return.class)) { + Return rStatement = (Return) statement; + Expression expression = rStatement.get_Expression(); + + // An dieser Stelle muss ein Rekursiver Aufruf + // möglich werden + String exp = HelpMethoden.expression2String(expression); + System.out.println("Expression: " + exp); + + String exp_t = HelpMethoden.expression_typed2String(expression); + System.out.println("Expression_typed: " + exp_t); + + List constraints = HelpMethoden.TypeExpr(assAll, expression, m, cl); + for (ConstraintAbstract c : constraints) { + System.out.println(c.toString()); + } + + } else { + System.err.println("Problem"); + } + + } + + return null; + } + + + +} diff --git a/test/strucTypes/StructuralTypesSimple3.jav b/test/strucTypes/StructuralTypesSimple3.jav index 0fdb8aef..b4538074 100644 --- a/test/strucTypes/StructuralTypesSimple3.jav +++ b/test/strucTypes/StructuralTypesSimple3.jav @@ -10,7 +10,7 @@ class A { mt2(x2) { return x2.feld_von_x ; } - mt3(x,y,z) { return x.sub(y).add(z); } + mt3(xaver,y,z) { return xaver.sub(y).add(z); } mt4(x,y,z) { return x.f.add(y.sub(z,x)); } diff --git a/test/strucTypes2/GeneralParserTest2.java b/test/strucTypes2/GeneralParserTest2.java index 34b03f70..6df73531 100644 --- a/test/strucTypes2/GeneralParserTest2.java +++ b/test/strucTypes2/GeneralParserTest2.java @@ -9,17 +9,12 @@ import java.util.List; import java.util.Map; import de.dhbwstuttgart.parser.JavaTXParser; -import de.dhbwstuttgart.strucTypes.AS_Abstract; -import de.dhbwstuttgart.strucTypes.TC_Abstract; -import de.dhbwstuttgart.strucTypes.Algo_Type; -import de.dhbwstuttgart.strucTypes.Algo_TypeExpr; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.statement.Block; -import de.dhbwstuttgart.syntaxtree.statement.CastExpr; import de.dhbwstuttgart.syntaxtree.statement.Expression; import de.dhbwstuttgart.syntaxtree.statement.FieldVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; @@ -144,8 +139,7 @@ public class GeneralParserTest2 { List constraints = HelpMethoden.TypeExpr(assAll, expression, m, cl); for (ConstraintAbstract c : constraints) { System.out.println(c.toString()); - } - + } @@ -254,7 +248,7 @@ class HelpMethoden { String argumentsStr = ""; List arguments = methodCall.get_ArgList().getArguments(); for (Expression arg : arguments) { - argumentsStr = argumentsStr + " " + HelpMethoden.expression_typed2String(arg) + arg.getType(); + argumentsStr = argumentsStr + " " + HelpMethoden.expression_typed2String(arg) ;//+ arg.getType(); } result = String.format("%s.%s(%s)", result, methodCall.get_Name(), argumentsStr); @@ -438,7 +432,4 @@ class MethodConstraint extends ConstraintAbstract { public String toString() { return String.format("MethodConstraint( %s, %s , %s (%s , %s ))" , receiver.toString() , methodName, "arg" , returnType.toString() , argumentTypeVars.toString() ); } - - - } \ No newline at end of file diff --git a/test/strucTypes3/GeneralParserTest2.java b/test/strucTypes3/GeneralParserTest2.java new file mode 100644 index 00000000..18ebfa3b --- /dev/null +++ b/test/strucTypes3/GeneralParserTest2.java @@ -0,0 +1,100 @@ +package strucTypes3; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.parser.JavaTXParser; +import de.dhbwstuttgart.strucTypes3.AssTuple; +import de.dhbwstuttgart.strucTypes3.AssumptionGenerator; +import de.dhbwstuttgart.strucTypes3.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes3.HelpMethoden; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.statement.Block; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.FieldVar; +import de.dhbwstuttgart.syntaxtree.statement.LocalVar; +import de.dhbwstuttgart.syntaxtree.statement.MethodCall; +import de.dhbwstuttgart.syntaxtree.statement.Receiver; +import de.dhbwstuttgart.syntaxtree.statement.Return; +import de.dhbwstuttgart.syntaxtree.statement.Statement; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import org.junit.Test; + +/** + * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der + * dabei erstellte Syntaxbaum wird nicht kontrolliert. + * + * @author janulrich + * + */ +public class GeneralParserTest2 { + private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes3/"; + + @Test + public void run() { + + /* + * Auflistung aller Files die getestet werden sollen + */ + List filenames = new ArrayList(); + // filenames.add("FieldInitializationTest.jav"); + // filenames.add("ImportTest.jav"); + // filenames.add("StatementsTest.jav"); + // filenames.add("ImportTestGeneric.jav"); + // filenames.add("BoundedParameter.jav"); + // filenames.add("GenericFieldVarTest.jav"); + // filenames.add("FieldVarTest.jav"); + + filenames.add("StructuralTypesSimpleSkript.jav"); + // filenames.add("StructuralTypesField.jav"); + // filenames.add("Main.jav"); + + JavaTXParser parser = new JavaTXParser(); + try { + for (String filename : filenames) { + + System.out.println("Teste: " + filename); + + SourceFile sf = parser.parse(new File(rootDirectory + filename)); + + SourceFile sfdebug = sf; + + ClassOrInterface aktClass = sf.getClasses().get(0); + AssTuple ass = AssumptionGenerator.generateAssumptions(aktClass); + + List constraints = new ArrayList<>(); + for (Method m : aktClass.getMethods()) { + Return rt = (Return) m.get_Block().statements.get(0); + Expression ex = (Expression) rt.get_Expression(); + constraints.addAll(HelpMethoden.TypeExpr(ass, ex, m, aktClass)); + } + + constraints.forEach( (x) -> {System.out.println(x); }); + + + + + + + + + } + + } catch (Exception exc) { + exc.printStackTrace(); + fail(); + } + assertTrue("Tests durchlaufen", filenames.size() > 0); + } +} diff --git a/test/strucTypes3/StructuralTypesSimple3.jav b/test/strucTypes3/StructuralTypesSimple3.jav new file mode 100644 index 00000000..b4538074 --- /dev/null +++ b/test/strucTypes3/StructuralTypesSimple3.jav @@ -0,0 +1,20 @@ + +class A { + + A f1; + + f2; + + + mt1(x1) { return x1; } + + mt2(x2) { return x2.feld_von_x ; } + + mt3(xaver,y,z) { return xaver.sub(y).add(z); } + + mt4(x,y,z) { return x.f.add(y.sub(z,x)); } + + + +} + diff --git a/test/strucTypes3/StructuralTypesSimpleSkript.jav b/test/strucTypes3/StructuralTypesSimpleSkript.jav new file mode 100644 index 00000000..70c53673 --- /dev/null +++ b/test/strucTypes3/StructuralTypesSimpleSkript.jav @@ -0,0 +1,10 @@ + +class A { + + + mt(x,y,z) { return x.sub(y).add(z); } + + + +} +