forked from JavaTX/JavaCompilerCore
Tests anfügen. Probleme mit Constructor beheben.
This commit is contained in:
parent
9e99a5b20b
commit
da70abf954
@ -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();
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,9 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class Matrix{
|
||||
|
||||
Matrix(){
|
||||
var;
|
||||
var = "test";
|
||||
}
|
||||
}
|
22
test/plugindevelopment/TypeInsertTests/ConstructorTest.java
Normal file
22
test/plugindevelopment/TypeInsertTests/ConstructorTest.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
12
test/plugindevelopment/TypeInsertTests/ThisTest.jav
Normal file
12
test/plugindevelopment/TypeInsertTests/ThisTest.jav
Normal file
@ -0,0 +1,12 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class Matrix{
|
||||
|
||||
Matrix(){
|
||||
this("test");
|
||||
}
|
||||
|
||||
Matrix(var){
|
||||
|
||||
}
|
||||
}
|
18
test/plugindevelopment/TypeInsertTests/ThisTest.java
Normal file
18
test/plugindevelopment/TypeInsertTests/ThisTest.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user