Overloading-Algorithmus in Klasse MethodCall auslagern

This commit is contained in:
JanUlrich 2015-03-03 11:34:42 +01:00
parent a8a7ad564b
commit 8e59e46d57
4 changed files with 32 additions and 77 deletions

View File

@ -229,6 +229,7 @@ public class MethodCall extends Expr
if(!(this.type instanceof TypePlaceholder) && !this.type.equals(methodAssumption.getAssumedType()))break;
oCons.addConstraint(constraintsFromMethodAssumption(methodAssumption, assumptions));
}
ret.add(oCons);
return ret;
}
@ -251,7 +252,7 @@ public class MethodCall extends Expr
public UndConstraint constraintsFromMethodAssumption(MethodAssumption methodAssumption, TypeAssumptions assumptions){
UndConstraint methodConstraint = new UndConstraint();
//Ein Constraint für den ReturnType der Methode...
methodConstraint.addConstraint(methodAssumption.getAssumedType().TYPE(assumptions, this), type.TYPE(assumptions, this));
methodConstraint.addConstraint(methodAssumption.getAssumedType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this));
//Ein Constraint für die Parameter der Methode...
for(int i=0; i<methodAssumption.getParaCount();i++){
//Type der Argument Expressions <. AssumedType der Parameter

View File

@ -1,76 +0,0 @@
package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
/**
*
* @author Andreas Stadelmeier, a10023
*
*/
public class Overloading{
private TypeAssumptions assumptions;
private MethodCall methodCall;
private Type type;
/**
* methodCall : type
* @param ass
* @param method
* @param type - eine Typ-Assumption/oder Typ für den Rückgabetyp des MethodCall
*/
public Overloading(TypeAssumptions ass, MethodCall method, Type type){
assumptions = ass.clone();
methodCall = method;
this.type = type;
}
/**
* Vereinfachte Version von Overloading...
* Es darf nur die erste gefundene Assumption verwendet werden, sonst widersprüchliche constraints
*
* Spezifikation:
* overloading determines for all possible overloadings and overridings
* of a method the constraints, where constraints itself forms
* the constraints from the receiver type, the argument types, the return
* type and a given type assumption for the method. If it is a
* method from a class, which is not the actual class (this), all type
* variables are replaced by fresh type variables (fresh), as different
* instances can occur. sargs determines all type assumptions of a
* method, where the argument types are supertypes of a minimal type
* assumption.
*
* @TODO: wenn es sich um eine Methode einer anderen Klasse handelt, müssen neue TPH vergeben werden und nicht die der Assumption verwendet werden.
*
* @return
public OderConstraint generateConsstraints_old(){
OderConstraint ret = new OderConstraint();
Vector<Type> parameterList = new Vector<Type>();
for(Expr argument : methodCall.getArgumentList().expr){
parameterList.add(argument.getType());
}
Vector<MethodAssumption> methodAssumptions = assumptions.getMethodAssumptions(methodCall.getName(), parameterList);
if(methodAssumptions.size()==0)throw new TypeinferenceException("Eine Methode "+methodCall.get_Name()+" ist in den Assumptions nicht vorhanden", methodCall);
//Alle möglichen Methoden durchgehen:
for(MethodAssumption methodAssumption : methodAssumptions){
//Constraint nicht erstellen, falls Rückgabetyp von vorne herein nicht übereinstimmt:
if(!(this.type instanceof TypePlaceholder) && !this.type.equals(methodAssumption.getAssumedType()))break;
ret.addConstraint(constraintsFromMethodAssumption(methodAssumption));
}
return ret;
}
*/
}

View File

@ -0,0 +1,12 @@
import java.util.Vector;
class Klasse1{
Klasse1(var){}
}
class Klass2 extends Klasse1{
Klass2(){
super(this);
}
}

View File

@ -0,0 +1,18 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class SuperTest {
private static final String TEST_FILE = "SuperTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}