From 09d1acab933bde30108a3e7f63f4ed93aacf7ec4 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 5 Dec 2014 17:11:22 +0100 Subject: [PATCH] =?UTF-8?q?Testf=C3=A4lle=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/.gitignore | 4 -- src/de/dhbwstuttgart/parser/JavaParser.java | 14 +++--- src/de/dhbwstuttgart/parser/JavaParser.jay | 16 +++---- .../dhbwstuttgart/syntaxtree/SourceFile.java | 4 +- .../statement/LambdaExpression.java | 6 ++- .../syntaxtree/type/ExtendsWildcardType.java | 2 + .../syntaxtree/type/RefType.java | 8 +++- .../dhbwstuttgart/syntaxtree/type/Type.java | 2 +- .../assumptions/TypeAssumptions.java | 3 ++ .../KarthesischesProduktTest.java | 43 +++++++++++++++++++ .../TypeInsertTests/WildcardTestForLambda.jav | 7 +++ .../WildcardTestForLambda.java | 19 ++++++++ 12 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 test/plugindevelopment/KarthesischesProduktTest.java create mode 100644 test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.jav create mode 100644 test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.java diff --git a/bin/.gitignore b/bin/.gitignore index 56a30e6a..34ddca33 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,6 +1,2 @@ -/bytecode/ /de/ -/mycompiler/ -/parser/ /plugindevelopment/ -/syntaxTree/ diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index 333bcb08..f915c2b2 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -1194,11 +1194,11 @@ case 64: // line 664 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { /*PL 05-07-30 eingefuegt containedTypes ANFANG*/ - RefType RT = new RefType(null,-1); + RefType RT = new RefType(((UsedId)yyVals[0+yyTop]).get_Name_1Element(),null,-1); /*RT.set_UsedId($1);*/ /*RT.setName(RT.get_UsedId().get_Name_1Element());*/ RT.set_ParaList(((UsedId)yyVals[0+yyTop]).get_RealParaList()); - RT.setName(((UsedId)yyVals[0+yyTop]).get_Name_1Element()); + //RT.setName(); containedTypes.addElement(RT); /*PL 05-07-30 eingefuegt containedTypes ENDE*/ @@ -1868,9 +1868,9 @@ case 148: case 149: // line 1239 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - RefType RT = new RefType(null,-1); - RT.set_UsedId(((UsedId)yyVals[0+yyTop])); - RT.setName(RT.get_UsedId().get_Name_1Element()); + RefType RT = new RefType(((UsedId)yyVals[0+yyTop]).get_Name_1Element(),null,-1); + //RT.set_UsedId(((UsedId)yyVals[0+yyTop])); + //RT.setName(RT.get_UsedId().get_Name_1Element()); yyVal=RT; } break; @@ -1940,7 +1940,7 @@ case 155: /*((UsedId)$1).vParaOrg = new Vector( $2.get_ParaList() );*/ } UsedId uid = ((UsedId)yyVals[-1+yyTop]); - RefType RT = new RefType(null,uid.getOffset()); + RefType RT = new RefType(uid.getQualifiedName(),null,uid.getOffset()); RT.set_ParaList(uid.get_RealParaList()); RT.setName(uid.getQualifiedName()); @@ -1957,7 +1957,7 @@ case 156: // line 1317 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->referenctype: " + ((UsedId)yyVals[0+yyTop]), Section.PARSER); - RefType RT = new RefType(null,((UsedId)yyVals[0+yyTop]).getOffset()); + RefType RT = new RefType(((UsedId)yyVals[0+yyTop]).getQualifiedName().toString(),null,((UsedId)yyVals[0+yyTop]).getOffset()); /*ausgetauscht PL 05-07-30*/ /*RT.set_UsedId($1); */ diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index e9df4020..077e6004 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -663,11 +663,11 @@ modifier : PUBLIC classtype : classorinterfacetype { //PL 05-07-30 eingefuegt containedTypes ANFANG - RefType RT = new RefType(null,-1); + RefType RT = new RefType($1.get_Name_1Element(),null,-1); //RT.set_UsedId($1); //RT.setName(RT.get_UsedId().get_Name_1Element()); RT.set_ParaList($1.get_RealParaList()); - RT.setName($1.get_Name_1Element()); + //RT.setName($1.get_Name_1Element()); containedTypes.addElement(RT); //PL 05-07-30 eingefuegt containedTypes ENDE @@ -1237,9 +1237,9 @@ explicitconstructorinvocation : THIS '(' ')' ';' classtypelist : classtype { - RefType RT = new RefType(null,-1); + RefType RT = new RefType(RT.get_UsedId().get_Name_1Element(),null,-1); RT.set_UsedId($1); - RT.setName(RT.get_UsedId().get_Name_1Element()); + //RT.setName(RT.get_UsedId().get_Name_1Element()); $$=RT; } | classtypelist ',' classtype @@ -1300,10 +1300,10 @@ referencelongtype : typename parameter //((UsedId)$1).vParaOrg = new Vector( $2.get_ParaList() ); } UsedId uid = $1; - RefType RT = new RefType(null,uid.getOffset()); + RefType RT = new RefType(uid.getQualifiedName(),null,uid.getOffset()); RT.set_ParaList(uid.get_RealParaList()); - RT.setName(uid.getQualifiedName()); + //RT.setName(uid.getQualifiedName()); //PL 05-07-30 eingefuegt containedTypes ANFANG @@ -1316,13 +1316,13 @@ referencelongtype : typename parameter referencetype :classorinterfacetype { de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->referenctype: " + $1, Section.PARSER); - RefType RT = new RefType(null,$1.getOffset()); + RefType RT = new RefType($1.getQualifiedName(),null,$1.getOffset()); //ausgetauscht PL 05-07-30 //RT.set_UsedId($1); //RT.setName(RT.get_UsedId().get_Name_1Element()); RT.set_ParaList($1.get_RealParaList()); - RT.setName($1.getQualifiedName()); + //RT.setName($1.getQualifiedName()); //PL 05-07-30 eingefuegt containedTypes ANFANG diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index d3d35cde..a6e8a699 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -397,7 +397,7 @@ public class SourceFile // Parameter des rechten Typausdrucks des betrachteten Paars extrahieren Vector vPara = ((RefType)(PTypKonst.TA2)).get_ParaList(); - RefType Subst = null; // Substitution + Integer Subst = null; // Substitution int nSubstStelle = 0; inferencelog.debug("nSubstStelleStart" + nSubstStelle + " " + n, Section.FINITECLOSURE); @@ -412,7 +412,7 @@ public class SourceFile if( vPara.elementAt(nSubstStelle) instanceof RefType && ((RefType)vPara.elementAt(nSubstStelle)).get_ParaList() != null ) { // Typkonstruktor gefunden -> wird nun als Substitution verwendet - Subst = new RefType( (RefType)vPara.elementAt(nSubstStelle) ,-1); + Subst = 1;//new RefType( (RefType)vPara.elementAt(nSubstStelle) ,-1); inferencelog.debug( "Ausgangstyp:" + ((RefType)PTypKonst.TA2).getName() , Section.FINITECLOSURE); inferencelog.debug( "RefType = " + ((RefType)vPara.elementAt(nSubstStelle)).getName() , Section.FINITECLOSURE); break; // Einschraenkung - nur fuer ein RefType wird eine Substitution gesucht diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index f20a6161..20ffdba6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -15,6 +15,7 @@ import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.DoubleType; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; @@ -148,7 +149,10 @@ public class LambdaExpression extends Expr{ this.setType(TypePlaceholder.fresh(this)); //ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys: ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression - ret.add(new SingleConstraint(new FunN(method_body.getType(), paramTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); + + Type retType = method_body.getType(); + ExtendsWildcardType extRetType = new ExtendsWildcardType(retType.getOffset(), retType); + ret.add(new SingleConstraint(new FunN(extRetType, paramTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index ed154e20..8531ee81 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.syntaxtree.type; +import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; @@ -25,6 +26,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, { super(extendsType.getParent(), offset); this.extendsType = extendsType; + this.name = new JavaClassName(this.toString()); } /** diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 95be24c7..132f751b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -64,7 +64,7 @@ public class RefType extends Type implements IMatchable // ino.method.RefType.26634.definition - public RefType(SyntaxTreeNode parent, int offset) + protected RefType(SyntaxTreeNode parent, int offset) // ino.end // ino.method.RefType.26634.body { @@ -124,7 +124,11 @@ public class RefType extends Type implements IMatchable //this.parameter = null; } - // ino.method.Type2Key.26646.definition + public RefType(JavaClassName jName, SyntaxTreeNode parent, int offset) { + this(jName.toString(), parent, offset); + } + + // ino.method.Type2Key.26646.definition public String Type2Key() // ino.end // ino.method.Type2Key.26646.body diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index fb2240f2..eacb438a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -45,7 +45,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset // ino.end // ino.method.Type.26732.definition - public Type(SyntaxTreeNode parent,int offset) + protected Type(SyntaxTreeNode parent,int offset) // ino.end // ino.method.Type.26732.body { diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index ddfa44c7..a0d935fb 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.ConstraintType; import de.dhbwstuttgart.typeinference.FunN; import de.dhbwstuttgart.typeinference.FunNInterface; import de.dhbwstuttgart.typeinference.FunNMethod; +import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; /** @@ -325,6 +326,8 @@ public class TypeAssumptions { return new ConstraintType(ass.getAssumedType()); } } + + if(t.getName() == null)throw new DebugException(t.toString()); //Spezialfälle bei char, int, boolean, .... String name = t.getName().toString(); switch(name){ diff --git a/test/plugindevelopment/KarthesischesProduktTest.java b/test/plugindevelopment/KarthesischesProduktTest.java new file mode 100644 index 00000000..4665f29e --- /dev/null +++ b/test/plugindevelopment/KarthesischesProduktTest.java @@ -0,0 +1,43 @@ +package plugindevelopment; + +import java.util.Vector; + +import org.junit.Test; + +import de.dhbwstuttgart.typeinference.ConstraintPair; +import de.dhbwstuttgart.typeinference.ConstraintType; +import de.dhbwstuttgart.typeinference.ConstraintsSet; +import de.dhbwstuttgart.typeinference.KarthesischesProdukt; +import de.dhbwstuttgart.typeinference.OderConstraint; +import de.dhbwstuttgart.typeinference.SingleConstraint; + +public class KarthesischesProduktTest { + + @Test + public void test(){ + Vector> testV = new Vector<>(); + Vector dummy = new Vector<>(); + dummy.add("1"); + dummy.add("2"); + dummy.add("3"); + testV.add(dummy); + testV.add(dummy); + + ConstraintsSet cs = new ConstraintsSet(); + OderConstraint oc = new OderConstraint(); + //oc.addConstraint(new SingleConstraint(new RefType(""))); + cs.add(oc); + + Vector out = new KarthesischesProdukt().berechneKarthesischesProdukt(testV); + System.out.println(out); + } + +} +class TestConstraintPair extends ConstraintPair{ + + public TestConstraintPair(ConstraintType t1, ConstraintType t2) { + super(t1, t2); + // TODO Auto-generated constructor stub + } + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.jav b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.jav new file mode 100644 index 00000000..c5e8292d --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.jav @@ -0,0 +1,7 @@ +class LambdaTest{ + +methode(){ + return (Integer i)-> i; +} + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.java b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.java new file mode 100644 index 00000000..04d7872f --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda.java @@ -0,0 +1,19 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class WildcardTestForLambda { + + private static final String TEST_FILE = "WildcardTestForLambda.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + + //mustContain.add("Fun0>> op"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +}