diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index bad91cbc3..9bf64ff5d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -1170,7 +1170,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I @Override public void parserPostProcessing(SyntaxTreeNode parent) { - //Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object: if(superclassid == null || superclassid.get_Name().size()<1){ int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset(); diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index fbc7893f0..e0e6b3f5e 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -18,6 +18,7 @@ import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; +import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; @@ -31,9 +32,37 @@ public class Constructor extends Method { * Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab. */ public Constructor(Method methode){ - super(methode.get_Method_Name(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset()); + super(methode.get_Method_Name(), methode.getType(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset()); + } + @Override + public TypeAssumptions createTypeAssumptions(Class classmember) { + this.parent = classmember; + Class parentClass = this.getParentClass(); + TypeAssumptions ret = new TypeAssumptions(); + ret.addAssumption(new ConstructorAssumption(this, parentClass)); + return ret; + } + @Override + public void parserPostProcessing(SyntaxTreeNode parent){ + if(this.parameterlist != null){ + for(FormalParameter fp : this.parameterlist){ + fp.parserPostProcessing(this); + } + } + for(GenericTypeVar gtv : this.getGenericParameter()){ + gtv.parserPostProcessing(this); + } + } + @Override + public ConstraintsSet TYPE(TypeAssumptions ass) { + super.setType(new RefType(this.getParentClass().getName().toString(), this, this.getOffset())); + return super.TYPE(ass); + } + @Override + public void setType(Type t) { + throw new TypeinferenceException("Einem Konstruktor kann kein Typ zugewiesen werden", this); + //this.methode.setType(t); } - /* public Constructor(Method methode){ super(methode.getOffset()); diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 819490c1f..aa45cb3e8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -98,7 +98,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable super(offset); } - public Method(String name, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset){ + public Method(String name, Type returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset){ this(offset); /* if(parameterList != null)parameterList.parserPostProcessing(this); @@ -109,6 +109,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable this.setParameterList(parameterList); this.set_Block(block); this.setGenericParameter(gtvDeclarations); + this.setReturnType(returnType); } /* @@ -680,11 +681,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable @Override public void parserPostProcessing(SyntaxTreeNode parent){ - super.parserPostProcessing(parent); if(this.getType()==null)this.setType(TypePlaceholder.fresh(this)); //Bei dem Elterntyp der Methode darf es sich nur um eine Klasse handeln, daher Cast ohne Prüfung: //Class parentClass = (Class)parent; if(this.returntype == null)this.returntype = TypePlaceholder.fresh(this); + super.parserPostProcessing(parent); + /* this.returntype.parserPostProcessing(this); if(this.parameterlist != null){ for(FormalParameter fp : this.parameterlist){ @@ -694,6 +696,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable for(GenericTypeVar gtv : this.getGenericParameter()){ gtv.parserPostProcessing(this); } + */ } @Override @@ -702,6 +705,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable ret.add(this.block); ret.add(this.parameterlist); ret.addAll(this.getGenericParameter()); + ret.add(this.returntype); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 429371e57..46ab32207 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -1327,6 +1327,7 @@ public class SourceFile } method.setParameterList(parameterList); //basicAssumptions.addMethodIntersectionType(new CIntersectionType(method)); + parentClass.addField(method); //} @@ -1349,7 +1350,9 @@ public class SourceFile } //basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); constructorMethod.parameterlist = paraList; - parentClass.addField(new Constructor(constructorMethod)); + Constructor constructor = new Constructor(constructorMethod); + constructor.parserPostProcessing(parentClass); + parentClass.addField(constructor); } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/ConstructorAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/ConstructorAssumption.java index 8bc393bb5..68f6112f3 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/ConstructorAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/ConstructorAssumption.java @@ -1,7 +1,10 @@ package de.dhbwstuttgart.typeinference.assumptions; +import java.util.Iterator; + import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.statement.ArgumentList; @@ -17,5 +20,16 @@ public class ConstructorAssumption extends MethodAssumption{ return super.equals(obj); } - + public String toString(){ + String ret = "ConstructorAssumption: "; + ret += this.getMethodName()+"("; + Iterator it = this.getMethod().parameterlist.formalparameter.iterator(); + while(it.hasNext()){ + FormalParameter fp = it.next(); + ret+=fp.toString(); + if(it.hasNext())ret += ","; + } + ret+=")"; + return ret; + } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 30645adb5..4d1d3f69e 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -26,6 +26,10 @@ public class MethodAssumption extends FieldAssumption { return this.method.getParameterCount(); } + protected Method getMethod(){ + return method; + } + /** * Liefert den Typ des i-ten Parameters dieser Method-Assumption * @param i diff --git a/test/plugindevelopment/TypeInsertTests/ConstructorTest.jav b/test/plugindevelopment/TypeInsertTests/ConstructorTest.jav new file mode 100644 index 000000000..b92a7a3be --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/ConstructorTest.jav @@ -0,0 +1,9 @@ +import java.util.Vector; + +class Matrix{ + + Matrix(){ + var; + var = "test"; + } +} diff --git a/test/plugindevelopment/TypeInsertTests/ConstructorTest.java b/test/plugindevelopment/TypeInsertTests/ConstructorTest.java new file mode 100644 index 000000000..d8f9e9ab3 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/ConstructorTest.java @@ -0,0 +1,22 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; + +public class ConstructorTest { + + private static final String TEST_FILE = "ConstructorTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + //Logger.setStandardConfiguration(new LoggerConfiguration().setOutput(Section.TYPEINFERENCE, System.out)); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +} diff --git a/test/plugindevelopment/TypeInsertTests/ThisTest.jav b/test/plugindevelopment/TypeInsertTests/ThisTest.jav new file mode 100644 index 000000000..c0316b9f5 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/ThisTest.jav @@ -0,0 +1,12 @@ +import java.util.Vector; + +class Matrix{ + + Matrix(){ + this("test"); + } + + Matrix(var){ + + } +} diff --git a/test/plugindevelopment/TypeInsertTests/ThisTest.java b/test/plugindevelopment/TypeInsertTests/ThisTest.java new file mode 100644 index 000000000..5412e721c --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/ThisTest.java @@ -0,0 +1,18 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class ThisTest { + + private static final String TEST_FILE = "ThisTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +}