Tests anfügen. Probleme mit Constructor beheben.

This commit is contained in:
JanUlrich 2015-02-25 18:29:44 +01:00
parent 9e99a5b20b
commit da70abf954
10 changed files with 121 additions and 7 deletions

View File

@ -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();

View File

@ -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());

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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<FormalParameter> it = this.getMethod().parameterlist.formalparameter.iterator();
while(it.hasNext()){
FormalParameter fp = it.next();
ret+=fp.toString();
if(it.hasNext())ret += ",";
}
ret+=")";
return ret;
}
}

View File

@ -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

View File

@ -0,0 +1,9 @@
import java.util.Vector;
class Matrix{
Matrix(){
var;
var = "test";
}
}

View File

@ -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<String> mustContain = new Vector<String>();
//Logger.setStandardConfiguration(new LoggerConfiguration().setOutput(Section.TYPEINFERENCE, System.out));
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -0,0 +1,12 @@
import java.util.Vector;
class Matrix{
Matrix(){
this("test");
}
Matrix(var){
}
}

View File

@ -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<String> mustContain = new Vector<String>();
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}