AbstractTypVar durch RefTypeORTPHOrWildcardOrGeneric ersetzt

This commit is contained in:
Martin Plümicke 2017-05-04 15:35:55 +02:00
parent dfabf8ad71
commit f48bb2ac0c
49 changed files with 321 additions and 288 deletions

View File

@ -5,7 +5,7 @@ import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Field; import de.dhbwstuttgart.strucTypes4.syntaxtree.Field;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Method; import de.dhbwstuttgart.strucTypes4.syntaxtree.Method;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,7 +19,7 @@ import java.util.Map;
public class Start { public class Start {
Map<String, TypeVarAbstract> assumptionsGlobal = new HashMap<>(); Map<String, RefTypeOrTPHOrWildcardOrGeneric> assumptionsGlobal = new HashMap<>();
List<Class> results = new ArrayList<>(); List<Class> results = new ArrayList<>();

View File

@ -1,27 +1,27 @@
package de.dhbwstuttgart.strucTypes4.algo; package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 09.04.17. * Created by sebastian on 09.04.17.
*/ */
public class ConstraintField extends ConstraintAbstract { public class ConstraintField extends ConstraintAbstract {
TypeVarAbstract receiver; RefTypeOrTPHOrWildcardOrGeneric receiver;
String nameField; String nameField;
TypeVarAbstract caller; RefTypeOrTPHOrWildcardOrGeneric caller;
public ConstraintField(TypeVarAbstract receiver, String nameField, TypeVarAbstract caller) { public ConstraintField(RefTypeOrTPHOrWildcardOrGeneric receiver, String nameField, RefTypeOrTPHOrWildcardOrGeneric caller) {
this.receiver = receiver; this.receiver = receiver;
this.nameField = nameField; this.nameField = nameField;
this.caller = caller; this.caller = caller;
} }
public TypeVarAbstract getReceiver() { public RefTypeOrTPHOrWildcardOrGeneric getReceiver() {
return receiver; return receiver;
} }
public void setReceiver(TypeVarAbstract receiver) { public void setReceiver(RefTypeOrTPHOrWildcardOrGeneric receiver) {
this.receiver = receiver; this.receiver = receiver;
} }
@ -33,11 +33,11 @@ public class ConstraintField extends ConstraintAbstract {
this.nameField = nameField; this.nameField = nameField;
} }
public TypeVarAbstract getCaller() { public RefTypeOrTPHOrWildcardOrGeneric getCaller() {
return caller; return caller;
} }
public void setCaller(TypeVarAbstract caller) { public void setCaller(RefTypeOrTPHOrWildcardOrGeneric caller) {
this.caller = caller; this.caller = caller;
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.strucTypes4.algo; package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -9,13 +9,13 @@ import java.util.List;
*/ */
public class ConstraintMethod extends ConstraintAbstract { public class ConstraintMethod extends ConstraintAbstract {
TypeVarAbstract receiver; RefTypeOrTPHOrWildcardOrGeneric receiver;
String methodName; String methodName;
List<TypeVarAbstract> argsTypes; List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
TypeVarAbstract returnType; RefTypeOrTPHOrWildcardOrGeneric returnType;
List<TypeVarAbstract> argsBetaTypes; List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes;
public ConstraintMethod(TypeVarAbstract receiver, String methodName, List<TypeVarAbstract> argsTypes, TypeVarAbstract returnType, List<TypeVarAbstract> argsBetaTypes) { public ConstraintMethod(RefTypeOrTPHOrWildcardOrGeneric receiver, String methodName, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes, RefTypeOrTPHOrWildcardOrGeneric returnType, List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes) {
this.receiver = receiver; this.receiver = receiver;
this.methodName = methodName; this.methodName = methodName;
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
@ -24,11 +24,11 @@ public class ConstraintMethod extends ConstraintAbstract {
} }
public TypeVarAbstract getReceiver() { public RefTypeOrTPHOrWildcardOrGeneric getReceiver() {
return receiver; return receiver;
} }
public void setReceiver(TypeVarAbstract receiver) { public void setReceiver(RefTypeOrTPHOrWildcardOrGeneric receiver) {
this.receiver = receiver; this.receiver = receiver;
} }
@ -40,27 +40,27 @@ public class ConstraintMethod extends ConstraintAbstract {
this.methodName = methodName; this.methodName = methodName;
} }
public List<TypeVarAbstract> getArgsTypes() { public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
return argsTypes; return argsTypes;
} }
public void setArgsTypes(List<TypeVarAbstract> argsTypes) { public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
} }
public TypeVarAbstract getReturnType() { public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return returnType; return returnType;
} }
public void setReturnType(TypeVarAbstract returnType) { public void setReturnType(RefTypeOrTPHOrWildcardOrGeneric returnType) {
this.returnType = returnType; this.returnType = returnType;
} }
public List<TypeVarAbstract> getArgsBetaTypes() { public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsBetaTypes() {
return argsBetaTypes; return argsBetaTypes;
} }
public void setArgsBetaTypes(List<TypeVarAbstract> argsBetaTypes) { public void setArgsBetaTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes) {
this.argsBetaTypes = argsBetaTypes; this.argsBetaTypes = argsBetaTypes;
} }

View File

@ -1,16 +1,16 @@
package de.dhbwstuttgart.strucTypes4.algo; package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 09.04.17. * Created by sebastian on 09.04.17.
*/ */
public class ConstraintSubType extends ConstraintAbstract { public class ConstraintSubType extends ConstraintAbstract {
TypeVarAbstract typeKleiner; RefTypeOrTPHOrWildcardOrGeneric typeKleiner;
TypeVarAbstract typeGroeßer; RefTypeOrTPHOrWildcardOrGeneric typeGroeßer;
public ConstraintSubType(TypeVarAbstract typeKleiner, TypeVarAbstract typeGroeßer) { public ConstraintSubType(RefTypeOrTPHOrWildcardOrGeneric typeKleiner, RefTypeOrTPHOrWildcardOrGeneric typeGroeßer) {
this.typeKleiner = typeKleiner; this.typeKleiner = typeKleiner;
this.typeGroeßer = typeGroeßer; this.typeGroeßer = typeGroeßer;
} }
@ -19,19 +19,19 @@ public class ConstraintSubType extends ConstraintAbstract {
public TypeVarAbstract getTypeKleiner() { public RefTypeOrTPHOrWildcardOrGeneric getTypeKleiner() {
return typeKleiner; return typeKleiner;
} }
public void setTypeKleiner(TypeVarAbstract typeKleiner) { public void setTypeKleiner(RefTypeOrTPHOrWildcardOrGeneric typeKleiner) {
this.typeKleiner = typeKleiner; this.typeKleiner = typeKleiner;
} }
public TypeVarAbstract getTypeGroeßer() { public RefTypeOrTPHOrWildcardOrGeneric getTypeGroeßer() {
return typeGroeßer; return typeGroeßer;
} }
public void setTypeGroeßer(TypeVarAbstract typeGroeßer) { public void setTypeGroeßer(RefTypeOrTPHOrWildcardOrGeneric typeGroeßer) {
this.typeGroeßer = typeGroeßer; this.typeGroeßer = typeGroeßer;
} }

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.strucTypes4.algo; package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -10,11 +10,11 @@ import java.util.List;
*/ */
public class ConstraintSubTypeInterface extends ConstraintAbstract{ public class ConstraintSubTypeInterface extends ConstraintAbstract{
TypeVarAbstract kleiner; RefTypeOrTPHOrWildcardOrGeneric kleiner;
TypeVarAbstract strucType; RefTypeOrTPHOrWildcardOrGeneric strucType;
List<TypeVarAbstract> generics; List<RefTypeOrTPHOrWildcardOrGeneric> generics;
public ConstraintSubTypeInterface(TypeVarAbstract kleiner, TypeVarAbstract strucType, List<TypeVarAbstract> generics) { public ConstraintSubTypeInterface(RefTypeOrTPHOrWildcardOrGeneric kleiner, RefTypeOrTPHOrWildcardOrGeneric strucType, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.kleiner = kleiner; this.kleiner = kleiner;
this.strucType = strucType; this.strucType = strucType;
this.generics = generics; this.generics = generics;

View File

@ -25,7 +25,7 @@ public class Construct2 {
List<Interface> interfaceList = new ArrayList<>(); List<Interface> interfaceList = new ArrayList<>();
// Sammeln der Constriants // Sammeln der Constriants
Map<TypeVarAbstract,List<ConstraintAbstract>> sortetConstr = sortiereConstraints(constraints); Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> sortetConstr = sortiereConstraints(constraints);
// Erstellen der Interfaces // Erstellen der Interfaces
@ -41,8 +41,8 @@ public class Construct2 {
for (ConstraintAbstract constraint : constraints) { for (ConstraintAbstract constraint : constraints) {
if (constraint.getClass().equals(ConstraintSubType.class)) { if (constraint.getClass().equals(ConstraintSubType.class)) {
ConstraintSubType constraintSubType = (ConstraintSubType) constraint; ConstraintSubType constraintSubType = (ConstraintSubType) constraint;
TypeVarAbstract kleiner = mapAN.getNeu(constraintSubType.getTypeKleiner()); RefTypeOrTPHOrWildcardOrGeneric kleiner = mapAN.getNeu(constraintSubType.getTypeKleiner());
TypeVarAbstract groeßer = mapAN.getNeu(constraintSubType.getTypeGroeßer()); RefTypeOrTPHOrWildcardOrGeneric groeßer = mapAN.getNeu(constraintSubType.getTypeGroeßer());
ConstraintSubType cNeu = new ConstraintSubType(kleiner,groeßer); ConstraintSubType cNeu = new ConstraintSubType(kleiner,groeßer);
constraintsNeu.add(cNeu); constraintsNeu.add(cNeu);
} }
@ -58,7 +58,7 @@ public class Construct2 {
// Erstelle constraints + Interfaces für den strukturellen Typen // Erstelle constraints + Interfaces für den strukturellen Typen
for (TypeVarAbstract typeVar : sortetConstr.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric typeVar : sortetConstr.keySet()) {
ConstructInterfaceForType2 constructInterfaceForType2 = new ConstructInterfaceForType2(sortetConstr.get(typeVar),typeVar,mapAN.getNeu(typeVar) , mapAN); ConstructInterfaceForType2 constructInterfaceForType2 = new ConstructInterfaceForType2(sortetConstr.get(typeVar),typeVar,mapAN.getNeu(typeVar) , mapAN);
interfaceList.add(constructInterfaceForType2.getResultInterface()); interfaceList.add(constructInterfaceForType2.getResultInterface());
constraintsNeu.addAll(constructInterfaceForType2.getResultConstraints()); constraintsNeu.addAll(constructInterfaceForType2.getResultConstraints());
@ -75,13 +75,13 @@ public class Construct2 {
// Sortieren der Constriants nach Strukturellem Typ // Sortieren der Constriants nach Strukturellem Typ
private Map<TypeVarAbstract,List<ConstraintAbstract>> sortiereConstraints(List<ConstraintAbstract> constraints) { private Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> sortiereConstraints(List<ConstraintAbstract> constraints) {
Map<TypeVarAbstract,List<ConstraintAbstract>> constraintMap = new ConcurrentHashMap<>(); Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> constraintMap = new ConcurrentHashMap<>();
for (ConstraintAbstract con : constraints) { for (ConstraintAbstract con : constraints) {
TypeVarAbstract receiver = null; RefTypeOrTPHOrWildcardOrGeneric receiver = null;
// Suche den Receiver der Metohde oder des Feldes // Suche den Receiver der Metohde oder des Feldes
if (con.getClass().equals(ConstraintMethod.class)) { if (con.getClass().equals(ConstraintMethod.class)) {
@ -118,14 +118,14 @@ class ConstructInterfaceForType2 {
private List<ConstraintAbstract> resultConstraints; private List<ConstraintAbstract> resultConstraints;
public ConstructInterfaceForType2(List<ConstraintAbstract> constraints , TypeVarAbstract receiverAlt , TypeVarAbstract receiverNeu , MappingAltNeu altNeu) { public ConstructInterfaceForType2(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric receiverAlt , RefTypeOrTPHOrWildcardOrGeneric receiverNeu , MappingAltNeu altNeu) {
resultConstraints = new ArrayList<>(); resultConstraints = new ArrayList<>();
List<FieldInterface> fields = new ArrayList<>(); List<FieldInterface> fields = new ArrayList<>();
List<MethodInterface> methods = new ArrayList<>(); List<MethodInterface> methods = new ArrayList<>();
List<TypeVarAbstract> genericsInterface = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsInterface = new ArrayList<>();
// Erstelle Felder sowie Methoden des Interfaces // Erstelle Felder sowie Methoden des Interfaces
@ -142,10 +142,10 @@ class ConstructInterfaceForType2 {
// Erstelle Methoden // Erstelle Methoden
if (constraint.getClass().equals(ConstraintMethod.class)) { if (constraint.getClass().equals(ConstraintMethod.class)) {
ConstraintMethod constraintMethod = (ConstraintMethod) constraint; ConstraintMethod constraintMethod = (ConstraintMethod) constraint;
TypeVarAbstract rtType = TypeVarFactory.makeTypeVar(); RefTypeOrTPHOrWildcardOrGeneric rtType = TypeVarFactory.makeTypeVar();
List<TypeVarAbstract> neueArgsTV = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> neueArgsTV = new ArrayList<>();
for (TypeVarAbstract tv : constraintMethod.getArgsTypes()) { for (RefTypeOrTPHOrWildcardOrGeneric tv : constraintMethod.getArgsTypes()) {
neueArgsTV.add(TypeVarFactory.makeTypeVar()); neueArgsTV.add(TypeVarFactory.makeTypeVar());
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.strucTypes4.algo; package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,10 +12,10 @@ import java.util.List;
public class MappingAltNeu { public class MappingAltNeu {
List<TypeVarAbstract> altList = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> altList = new ArrayList<>();
List<TypeVarAbstract> neuList = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> neuList = new ArrayList<>();
public void addTypeVar(TypeVarAbstract alt, TypeVarAbstract neu) { public void addTypeVar(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
altList.add(alt); altList.add(alt);
// Versuch bereits bekannte Typen mitzunehmen // Versuch bereits bekannte Typen mitzunehmen
@ -28,7 +28,7 @@ public class MappingAltNeu {
} }
} }
public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) { public RefTypeOrTPHOrWildcardOrGeneric getNeu (RefTypeOrTPHOrWildcardOrGeneric altTypeVar) {
// Wenn typ bereits bekannt ist // Wenn typ bereits bekannt ist
if (altTypeVar.getClass().equals(TypeVarType.class)) { if (altTypeVar.getClass().equals(TypeVarType.class)) {

View File

@ -2,7 +2,7 @@ package de.dhbwstuttgart.strucTypes4.algo;
import de.dhbwstuttgart.strucTypes4.syntaxtree.*; import de.dhbwstuttgart.strucTypes4.syntaxtree.*;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
@ -15,7 +15,7 @@ import java.util.Map;
*/ */
public class TypeExpr { public class TypeExpr {
public static List<ConstraintAbstract> typeExpr(ExpressionAbstract exp, Map<String, TypeVarAbstract> ass , TypeVarAbstract rec , TypeVarAbstract returnType , TypeVarStore typeVarStore) { public static List<ConstraintAbstract> typeExpr(ExpressionAbstract exp, Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass , RefTypeOrTPHOrWildcardOrGeneric rec , RefTypeOrTPHOrWildcardOrGeneric returnType , TypeVarStore typeVarStore) {
if (exp.getClass().equals(ExprVar.class )) { if (exp.getClass().equals(ExprVar.class )) {
ExprVar exprVar = (ExprVar) exp; ExprVar exprVar = (ExprVar) exp;
@ -38,8 +38,8 @@ public class TypeExpr {
// Reihenfolge wichtig wg Rekursiven aufrufen und TypVariablen !!! // Reihenfolge wichtig wg Rekursiven aufrufen und TypVariablen !!!
constraints.addAll(typeExpr(expression.getReceiver(), ass, null ,null , typeVarStore)); constraints.addAll(typeExpr(expression.getReceiver(), ass, null ,null , typeVarStore));
TypeVarAbstract tvReceiver = typeVarStore.storeTPH(expression.getReceiver().getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tvReceiver = typeVarStore.storeTPH(expression.getReceiver().getTypePlaceHolder());
TypeVarAbstract tvThis = typeVarStore.storeTPH(expression.getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tvThis = typeVarStore.storeTPH(expression.getTypePlaceHolder());
constraints.addAll(typeExpr(expression.getCaller(),ass, tvReceiver , tvThis , typeVarStore)); constraints.addAll(typeExpr(expression.getCaller(),ass, tvReceiver , tvThis , typeVarStore));
return constraints; return constraints;
} }
@ -52,7 +52,7 @@ public class TypeExpr {
String klassenname = exprNew.getClassType(); String klassenname = exprNew.getClassType();
String assumptionKey = "$" + klassenname; String assumptionKey = "$" + klassenname;
TypeVarAbstract tv = ass.get(assumptionKey); RefTypeOrTPHOrWildcardOrGeneric tv = ass.get(assumptionKey);
Class typeClass = ((TypeVarType) tv).getTypeClass(); Class typeClass = ((TypeVarType) tv).getTypeClass();
typeVarStore.addTuple(new TypeVarType(typeClass) , exprNew.getTypePlaceHolder()); typeVarStore.addTuple(new TypeVarType(typeClass) , exprNew.getTypePlaceHolder());
@ -66,7 +66,7 @@ public class TypeExpr {
//constriants.forEach((ConstraintAbstract cs) -> cs.replace(new TPH(gen) , new TPH(generic.get(gen)) )); //constriants.forEach((ConstraintAbstract cs) -> cs.replace(new TPH(gen) , new TPH(generic.get(gen)) ));
String typeVar = key; String typeVar = key;
String klasse = generic.get(key); String klasse = generic.get(key);
TypeVarAbstract klasseType = ass.get("$" + klasse); RefTypeOrTPHOrWildcardOrGeneric klasseType = ass.get("$" + klasse);
TypeVarType klasseTypeCast = (TypeVarType) klasseType; TypeVarType klasseTypeCast = (TypeVarType) klasseType;
} }

View File

@ -12,7 +12,7 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker;
import de.dhbwstuttgart.strucTypes4.syntaxtree.*; import de.dhbwstuttgart.strucTypes4.syntaxtree.*;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.*; import java.util.*;
@ -43,7 +43,7 @@ public class Parser {
// Quellcode wird geparst. Evtl. bekannte Klassen müssen über die Assumptions mitgegeben werden // Quellcode wird geparst. Evtl. bekannte Klassen müssen über die Assumptions mitgegeben werden
public Class parseCode(String quellcode , Map<String,TypeVarAbstract> ass ) { public Class parseCode(String quellcode , Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass ) {
SourceFile sf = parse(quellcode); SourceFile sf = parse(quellcode);
TI typeinference = new TI(ass,sf.getClassList().get(0)); TI typeinference = new TI(ass,sf.getClassList().get(0));
return typeinference.getResultClassTypedWithInterfaces(); return typeinference.getResultClassTypedWithInterfaces();
@ -59,7 +59,7 @@ class TI {
Class resultClassTypedWithInterfaces; Class resultClassTypedWithInterfaces;
public TI (Map<String,TypeVarAbstract> ass, Class aClass) { public TI (Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, Class aClass) {
Type type = new Type(ass,aClass); Type type = new Type(ass,aClass);
@ -114,10 +114,10 @@ class Type {
Class resultClassTyped; Class resultClassTyped;
List<ConstraintAbstract> resultConstraintSet = new ArrayList<>(); List<ConstraintAbstract> resultConstraintSet = new ArrayList<>();
public Type(Map<String,TypeVarAbstract> ass, Class aClass) { public Type(Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, Class aClass) {
// 1. Erstellen der Assumptions für die Klasse // 1. Erstellen der Assumptions für die Klasse
Map<String, TypeVarAbstract> fass_mass = aClass.makeAssumptions(); Map<String, RefTypeOrTPHOrWildcardOrGeneric> fass_mass = aClass.makeAssumptions();
// ToDo Vereinigen der Assumptions // ToDo Vereinigen der Assumptions
fass_mass.putAll(ass); fass_mass.putAll(ass);
@ -134,7 +134,7 @@ class Type {
// AssAll Ass und fass und mass und this:A // AssAll Ass und fass und mass und this:A
// ToDo this:a // ToDo this:a
Map<String,TypeVarAbstract> assMethod = method.makeAssumptions(aClass.typeVarStore); Map<String,RefTypeOrTPHOrWildcardOrGeneric> assMethod = method.makeAssumptions(aClass.typeVarStore);
assMethod.putAll(fass_mass); assMethod.putAll(fass_mass);
resultConstraintSet.addAll(method.typeExpr(assMethod , aClass.typeVarStore)); resultConstraintSet.addAll(method.typeExpr(assMethod , aClass.typeVarStore));

View File

@ -2,7 +2,7 @@ package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract; import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
import java.util.HashMap; import java.util.HashMap;
@ -32,24 +32,24 @@ public class Class extends SyntaxNode{
} }
public Map<String,TypeVarAbstract> makeAssumptions() { public Map<String,RefTypeOrTPHOrWildcardOrGeneric> makeAssumptions() {
// Name bei Feldern feld, name bei methoden methode() // Name bei Feldern feld, name bei methoden methode()
Map<String, TypeVarAbstract> ass = new HashMap<>(); Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass = new HashMap<>();
// felder // felder
for (Field f : felder) { for (Field f : felder) {
TypeVarAbstract tv = typeVarStore.storeTPH(f.getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(f.getTypePlaceHolder());
ass.put(f.getVar_name() , tv); ass.put(f.getVar_name() , tv);
} }
// methoden // methoden
for (Method m : methoden) { for (Method m : methoden) {
TypeVarAbstract tv = typeVarStore.storeTPH(m.getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(m.getTypePlaceHolder());
ass.put(m.getName()+"()", tv); ass.put(m.getName()+"()", tv);
} }
// This einfügen // This einfügen
TypeVarAbstract tv = typeVarStore.storeTPH(getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(getTypePlaceHolder());
ass.put("this" , tv); ass.put("this" , tv);
return ass; return ass;

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.strucTypes4.syntaxtree; package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.algo.*; import de.dhbwstuttgart.strucTypes4.algo.*;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
@ -23,7 +23,7 @@ public class ExprMCall extends ExpressionAbstract {
} }
public List<ConstraintAbstract> typeExpr (Map<String, TypeVarAbstract> ass , TypeVarAbstract receiver , TypeVarAbstract returnType, TypeVarStore typeVarStore) { public List<ConstraintAbstract> typeExpr (Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass , RefTypeOrTPHOrWildcardOrGeneric receiver , RefTypeOrTPHOrWildcardOrGeneric returnType, TypeVarStore typeVarStore) {
List<ConstraintAbstract> constraints = new ArrayList<>(); List<ConstraintAbstract> constraints = new ArrayList<>();
@ -38,7 +38,7 @@ public class ExprMCall extends ExpressionAbstract {
List<Argument> arguments = m.getArgs(); List<Argument> arguments = m.getArgs();
List<TypeVarAbstract> typeVars = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> typeVars = new ArrayList<>();
// Ermitteln der TypeVars der alten Klasse // Ermitteln der TypeVars der alten Klasse
for (Argument argument : arguments ) { for (Argument argument : arguments ) {
typeVars.add(c.getTypeVarStore().getTypeVarByTPH(argument.getTypePlaceHolder())); typeVars.add(c.getTypeVarStore().getTypeVarByTPH(argument.getTypePlaceHolder()));
@ -51,8 +51,8 @@ public class ExprMCall extends ExpressionAbstract {
// Hinzufügen von Constraints // Hinzufügen von Constraints
for (int i = 0; i < args.size() ; i++) { for (int i = 0; i < args.size() ; i++) {
TypeVarAbstract tvInNewKlasse = typeVars.get(i); RefTypeOrTPHOrWildcardOrGeneric tvInNewKlasse = typeVars.get(i);
TypeVarAbstract typeInAktKlasse = typeVarStore.getTypeVarByTPH(args.get(i).getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric typeInAktKlasse = typeVarStore.getTypeVarByTPH(args.get(i).getTypePlaceHolder());
constraints.add(new ConstraintSubType(tvInNewKlasse , typeInAktKlasse)); constraints.add(new ConstraintSubType(tvInNewKlasse , typeInAktKlasse));
} }
@ -68,11 +68,11 @@ public class ExprMCall extends ExpressionAbstract {
args.forEach(x -> constraints.addAll( TypeExpr.typeExpr( x,ass,null,null,typeVarStore) )); args.forEach(x -> constraints.addAll( TypeExpr.typeExpr( x,ass,null,null,typeVarStore) ));
// Liste mit Typen der Argumente der Methode sammeln // Liste mit Typen der Argumente der Methode sammeln
List<TypeVarAbstract> types = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> types = new ArrayList<>();
args.forEach(x -> types.add(typeVarStore.getTypeVarByTPH(x.getTypePlaceHolder()))); args.forEach(x -> types.add(typeVarStore.getTypeVarByTPH(x.getTypePlaceHolder())));
// Neue Liste mit neuen Beta - Argumenten erstellen // Neue Liste mit neuen Beta - Argumenten erstellen
List<TypeVarAbstract> betaTypes = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> betaTypes = new ArrayList<>();
args.forEach(x -> betaTypes.add( typeVarStore.makeFreshTypeVar() )); args.forEach(x -> betaTypes.add( typeVarStore.makeFreshTypeVar() ));

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.strucTypes4.syntaxtree; package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract; import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,10 +16,10 @@ public class ExprVar extends ExpressionAbstract {
String name; String name;
public List<ConstraintAbstract> typeExpr(Map<String, TypeVarAbstract> ass, TypeVarStore typeVarStore) { public List<ConstraintAbstract> typeExpr(Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass, TypeVarStore typeVarStore) {
List<ConstraintAbstract> constriants = new ArrayList<>(); List<ConstraintAbstract> constriants = new ArrayList<>();
TypeVarAbstract tv = ass.get(name); RefTypeOrTPHOrWildcardOrGeneric tv = ass.get(name);
typeVarStore.addTuple(tv,getTypePlaceHolder()); typeVarStore.addTuple(tv,getTypePlaceHolder());
return constriants; return constriants;
} }

View File

@ -1,26 +1,26 @@
package de.dhbwstuttgart.strucTypes4.syntaxtree; package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 09.04.17. * Created by sebastian on 09.04.17.
*/ */
public class FieldInterface { public class FieldInterface {
TypeVarAbstract type; RefTypeOrTPHOrWildcardOrGeneric type;
String name; String name;
public FieldInterface(TypeVarAbstract type, String name) { public FieldInterface(RefTypeOrTPHOrWildcardOrGeneric type, String name) {
this.type = type; this.type = type;
this.name = name; this.name = name;
} }
public TypeVarAbstract getType() { public RefTypeOrTPHOrWildcardOrGeneric getType() {
return type; return type;
} }
public void setType(TypeVarAbstract type) { public void setType(RefTypeOrTPHOrWildcardOrGeneric type) {
this.type = type; this.type = type;
} }

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.strucTypes4.syntaxtree; package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -11,13 +11,13 @@ import java.util.List;
*/ */
public class Interface { public class Interface {
TypeVarAbstract strucType; RefTypeOrTPHOrWildcardOrGeneric strucType;
List<FieldInterface> fields; List<FieldInterface> fields;
List<MethodInterface> methods; List<MethodInterface> methods;
List<TypeVarAbstract> generics; List<RefTypeOrTPHOrWildcardOrGeneric> generics;
public Interface(TypeVarAbstract strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<TypeVarAbstract> generics) { public Interface(RefTypeOrTPHOrWildcardOrGeneric strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.strucType = strucType; this.strucType = strucType;
this.fields = fields; this.fields = fields;
this.methods = methods; this.methods = methods;
@ -40,11 +40,11 @@ public class Interface {
this.methods = methods; this.methods = methods;
} }
public List<TypeVarAbstract> getGenerics() { public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
return generics; return generics;
} }
public void setGenerics(List<TypeVarAbstract> generics) { public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.generics = generics; this.generics = generics;
} }

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract; import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes4.algo.TypeExpr; import de.dhbwstuttgart.strucTypes4.algo.TypeExpr;
import de.dhbwstuttgart.strucTypes4.typePlaceHolder.TPH; import de.dhbwstuttgart.strucTypes4.typePlaceHolder.TPH;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
import java.util.HashMap; import java.util.HashMap;
@ -29,16 +29,16 @@ public class Method extends SyntaxNode {
} }
public Map<String, TypeVarAbstract> makeAssumptions(TypeVarStore typeVarStore) { public Map<String, RefTypeOrTPHOrWildcardOrGeneric> makeAssumptions(TypeVarStore typeVarStore) {
Map<String, TypeVarAbstract> assLokal = new HashMap<>(); Map<String, RefTypeOrTPHOrWildcardOrGeneric> assLokal = new HashMap<>();
for (Argument arg : args ) { for (Argument arg : args ) {
TypeVarAbstract tv = typeVarStore.storeTPH(arg.getTypePlaceHolder()); RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(arg.getTypePlaceHolder());
assLokal.put(arg.getName(), tv ); assLokal.put(arg.getName(), tv );
} }
return assLokal; return assLokal;
} }
public List<ConstraintAbstract> typeExpr(Map<String,TypeVarAbstract> ass, TypeVarStore typeVarStore) { public List<ConstraintAbstract> typeExpr(Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, TypeVarStore typeVarStore) {
return TypeExpr.typeExpr(expression,ass,null , null , typeVarStore); return TypeExpr.typeExpr(expression,ass,null , null , typeVarStore);
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.strucTypes4.syntaxtree; package de.dhbwstuttgart.strucTypes4.syntaxtree;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract; import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -10,11 +10,11 @@ import java.util.List;
public class MethodInterface { public class MethodInterface {
String name; String name;
TypeVarAbstract rtType; RefTypeOrTPHOrWildcardOrGeneric rtType;
List<TypeVarAbstract> argsTypes; List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
public MethodInterface(String name, TypeVarAbstract rtType, List<TypeVarAbstract> argsTypes) { public MethodInterface(String name, RefTypeOrTPHOrWildcardOrGeneric rtType, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
this.name = name; this.name = name;
this.rtType = rtType; this.rtType = rtType;
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
@ -29,19 +29,19 @@ public class MethodInterface {
this.name = name; this.name = name;
} }
public TypeVarAbstract getRtType() { public RefTypeOrTPHOrWildcardOrGeneric getRtType() {
return rtType; return rtType;
} }
public void setRtType(TypeVarAbstract rtType) { public void setRtType(RefTypeOrTPHOrWildcardOrGeneric rtType) {
this.rtType = rtType; this.rtType = rtType;
} }
public List<TypeVarAbstract> getArgsTypes() { public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
return argsTypes; return argsTypes;
} }
public void setArgsTypes(List<TypeVarAbstract> argsTypes) { public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
} }

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.typeVars;
/** /**
* Created by sebastian on 14.04.17. * Created by sebastian on 14.04.17.
*/ */
public abstract class TypeVarAbstract { public abstract class RefTypeOrTPHOrWildcardOrGeneric {

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.typeVars;
/** /**
* Created by sebastian on 14.04.17. * Created by sebastian on 14.04.17.
*/ */
public class TypeVar extends TypeVarAbstract { public class TypeVar extends RefTypeOrTPHOrWildcardOrGeneric {
private String id; private String id;

View File

@ -14,11 +14,11 @@ import java.util.List;
public class TypeVarStore { public class TypeVarStore {
private HashMap<TypeVarAbstract, List<TPH>> map = new HashMap<>(); private HashMap<RefTypeOrTPHOrWildcardOrGeneric, List<TPH>> map = new HashMap<>();
public TypeVarAbstract storeTPH(TPH tph) { public RefTypeOrTPHOrWildcardOrGeneric storeTPH(TPH tph) {
if (getTypeVarByTPH(tph) == null) { if (getTypeVarByTPH(tph) == null) {
TypeVar tvNeu = TypeVarFactory.makeTypeVar(); TypeVar tvNeu = TypeVarFactory.makeTypeVar();
@ -31,7 +31,7 @@ public class TypeVarStore {
} }
public TypeVarAbstract makeFreshTypeVar() { public RefTypeOrTPHOrWildcardOrGeneric makeFreshTypeVar() {
TypeVar neu = TypeVarFactory.makeTypeVar(); TypeVar neu = TypeVarFactory.makeTypeVar();
List<TPH> tphList = new ArrayList<>(); List<TPH> tphList = new ArrayList<>();
map.put(neu,tphList); map.put(neu,tphList);
@ -40,7 +40,7 @@ public class TypeVarStore {
public void addTuple(TypeVarAbstract tv, TPH tph) { public void addTuple(RefTypeOrTPHOrWildcardOrGeneric tv, TPH tph) {
// TypVar bereits vorhandne // TypVar bereits vorhandne
@ -65,13 +65,13 @@ public class TypeVarStore {
} }
public List<TPH> getTPHByTypeVar(TypeVarAbstract tv) { public List<TPH> getTPHByTypeVar(RefTypeOrTPHOrWildcardOrGeneric tv) {
return map.get(tv); return map.get(tv);
} }
public TypeVarAbstract getTypeVarByTPH(TPH tph) { public RefTypeOrTPHOrWildcardOrGeneric getTypeVarByTPH(TPH tph) {
// TPH ist bereits einer TypVar zugeordnet // TPH ist bereits einer TypVar zugeordnet
for (TypeVarAbstract typeVar : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric typeVar : map.keySet()) {
if (map.get(typeVar).contains(tph)) { if (map.get(typeVar).contains(tph)) {
return typeVar; return typeVar;
} }
@ -87,7 +87,7 @@ public class TypeVarStore {
public TypeVarStore freshVariables() { public TypeVarStore freshVariables() {
TypeVarStore typeVarStore = new TypeVarStore(); TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
TypeVar tvNew = TypeVarFactory.makeTypeVar(); TypeVar tvNew = TypeVarFactory.makeTypeVar();
typeVarStore.map.put(tvNew,map.get(tvarOld)); typeVarStore.map.put(tvNew,map.get(tvarOld));
} }
@ -101,11 +101,11 @@ public class TypeVarStore {
TypeVarStore typeVarStore = new TypeVarStore(); TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
// Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt. // Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt.
if (tvarOld.getClass().equals(TypeVarType.class)) { if (tvarOld.getClass().equals(TypeVarType.class)) {
TypeVarAbstract tvNew = tvarOld; RefTypeOrTPHOrWildcardOrGeneric tvNew = tvarOld;
typeVarStore.map.put(tvNew,map.get(tvarOld)); typeVarStore.map.put(tvNew,map.get(tvarOld));
mappingAltNeu.addTypeVar(tvarOld,tvNew); mappingAltNeu.addTypeVar(tvarOld,tvNew);
} }
@ -121,7 +121,7 @@ public class TypeVarStore {
public boolean replaceTypeVar(TypeVarAbstract old, TypeVarAbstract neu) { public boolean replaceTypeVar(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu) {
if (map.containsKey(old)) { if (map.containsKey(old)) {
List<TPH> tphList = map.get(old); List<TPH> tphList = map.get(old);
@ -139,7 +139,7 @@ public class TypeVarStore {
@Override @Override
public String toString() { public String toString() {
String res = "--- TypeVarStore ---\n"; String res = "--- TypeVarStore ---\n";
for (TypeVarAbstract tvar : map.keySet() ) { for (RefTypeOrTPHOrWildcardOrGeneric tvar : map.keySet() ) {
res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n"; res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n";
} }
return String.format(res); return String.format(res);

View File

@ -6,7 +6,7 @@ import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
/** /**
* Created by sebastian on 14.04.17. * Created by sebastian on 14.04.17.
*/ */
public class TypeVarType extends TypeVarAbstract { public class TypeVarType extends RefTypeOrTPHOrWildcardOrGeneric {
private Class typeClass; private Class typeClass;

View File

@ -12,7 +12,7 @@ import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.MethodInterface; import de.dhbwstuttgart.strucTypes5.interfaceTemplates.MethodInterface;
import de.dhbwstuttgart.strucTypes5.typeVars.*; import de.dhbwstuttgart.strucTypes5.typeVars.*;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.*; import java.util.*;
@ -107,8 +107,8 @@ public class ConstructInterfaceTemplates {
List<FieldInterface> fields = new ArrayList<>(); List<FieldInterface> fields = new ArrayList<>();
List<MethodInterface> methods = new ArrayList<>(); List<MethodInterface> methods = new ArrayList<>();
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
List<TypeVarAbstract> genericsForConstraint = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsForConstraint = new ArrayList<>();
for (ConstraintAbstract constraint : constraintSet) { for (ConstraintAbstract constraint : constraintSet) {
@ -127,7 +127,7 @@ public class ConstructInterfaceTemplates {
} }
// Erstelle Generic für neuen Typvariablen für das Interface // Erstelle Generic für neuen Typvariablen für das Interface
List<TypeVarAbstract> args = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> args = new ArrayList<>();
for (TypeVar tv : cm.getArgumentTypes()) { for (TypeVar tv : cm.getArgumentTypes()) {
TypeVar generic = typeVarStore.makeFreshTypeVar(); TypeVar generic = typeVarStore.makeFreshTypeVar();
args.add(generic); args.add(generic);
@ -151,8 +151,8 @@ public class ConstructInterfaceTemplates {
TypeVar neuerTypeReveiver = (TypeVar) mappingAltNeu.getNeu(receiver); TypeVar neuerTypeReveiver = (TypeVar) mappingAltNeu.getNeu(receiver);
InterfaceForConstraint interfaceForConstraint = new InterfaceForConstraint(receiver, genericsForConstraint); InterfaceForConstraint interfaceForConstraint = new InterfaceForConstraint(receiver, genericsForConstraint);
TypeVarAbstract tSub = neuerTypeReveiver; RefTypeOrTPHOrWildcardOrGeneric tSub = neuerTypeReveiver;
TypeVarAbstract tSuper = TypeVarFactory.makeTypeVar(interfaceForConstraint); RefTypeOrTPHOrWildcardOrGeneric tSuper = TypeVarFactory.makeTypeVar(interfaceForConstraint);
ConstraintSubType newConstraint = new ConstraintSubType(tSub, tSuper); ConstraintSubType newConstraint = new ConstraintSubType(tSub, tSuper);
remainingConstraints.add(newConstraint); remainingConstraints.add(newConstraint);

View File

@ -11,11 +11,12 @@ import de.dhbwstuttgart.strucTypes5.constraints.OldConstraints;
import de.dhbwstuttgart.strucTypes5.solve.Rules; import de.dhbwstuttgart.strucTypes5.solve.Rules;
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple; import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
import java.util.ArrayList; import java.util.ArrayList;
@ -58,7 +59,7 @@ public class TI {
// Generiere Generics für die Klasse // Generiere Generics für die Klasse
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
for (Method m : cl.getMethods()) { for (Method m : cl.getMethods()) {
generics.add(tp.getTypeVarStore().getTypeVarByTPH(m.getType())); generics.add(tp.getTypeVarStore().getTypeVarByTPH(m.getType()));
for (FormalParameter fp : m.getParameterList().getFormalparalist()) { for (FormalParameter fp : m.getParameterList().getFormalparalist()) {
@ -151,12 +152,12 @@ public class TI {
if (rc instanceof ConstraintSubType) { if (rc instanceof ConstraintSubType) {
ConstraintSubType cSub = (ConstraintSubType) rc; ConstraintSubType cSub = (ConstraintSubType) rc;
TypeVarAbstract tSubNeu = null; RefTypeOrTPHOrWildcardOrGeneric tSubNeu = null;
TypeVarAbstract tSuperNeu = null; RefTypeOrTPHOrWildcardOrGeneric tSuperNeu = null;
// Check for Klasse // Check for Klasse
TypeVarAbstract tSub = cSub.getSubtype(); RefTypeOrTPHOrWildcardOrGeneric tSub = cSub.getSubtype();
TypeVarAbstract tSuper = cSub.getSuperType(); RefTypeOrTPHOrWildcardOrGeneric tSuper = cSub.getSuperType();
if (tSub instanceof TypeVar) { if (tSub instanceof TypeVar) {
tSubNeu = typeVarStore.isType((TypeVar) tSub); tSubNeu = typeVarStore.isType((TypeVar) tSub);

View File

@ -7,7 +7,7 @@ import de.dhbwstuttgart.strucTypes5.assumptions.ChangeTypeVars;
import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String; import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String;
import de.dhbwstuttgart.strucTypes5.constraints.*; import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
@ -38,7 +38,7 @@ public class TypeExpr {
Return rt = (Return) method.get_Block().getStatements().get(0); Return rt = (Return) method.get_Block().getStatements().get(0);
// Adds the Relation TypVariable Method == TypVariable Return Expression // Adds the Relation TypVariable Method == TypVariable Return Expression
TypeVarAbstract typeVarMethod = typeVarStore.getTypeVarByTPH(method.getType()); RefTypeOrTPHOrWildcardOrGeneric typeVarMethod = typeVarStore.getTypeVarByTPH(method.getType());
typeVarStore.addTuple(typeVarMethod, rt.getType()); typeVarStore.addTuple(typeVarMethod, rt.getType());
@ -69,7 +69,7 @@ public class TypeExpr {
LocalVar localVar = (LocalVar) expression; LocalVar localVar = (LocalVar) expression;
// Erstellung keines Constriants // Erstellung keines Constriants
// Lediglich eintrag in TypeVarStore // Lediglich eintrag in TypeVarStore
TypeVarAbstract typeVar = assumptionMap.getVarAssumption(localVar.get_expression()); RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
typeVarStore.addTuple(typeVar,localVar.getType()); typeVarStore.addTuple(typeVar,localVar.getType());
List<ConstraintAbstract> result = new ArrayList<>(); List<ConstraintAbstract> result = new ArrayList<>();
return result; return result;

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.strucTypes5.assumptions; package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
/** /**
* Created by sebastian on 20.04.17. * * Created by sebastian on 20.04.17. *
@ -11,9 +13,9 @@ import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
public class AssumptionArgument extends AssumptionAbstract { public class AssumptionArgument extends AssumptionAbstract {
private String nameOfArgument; private String nameOfArgument;
private TypeVarAbstract typeOfArgument; private RefTypeOrTPHOrWildcardOrGeneric typeOfArgument;
public AssumptionArgument(String nameOfArgument, TypeVarAbstract typeOfArgument) { public AssumptionArgument(String nameOfArgument, RefTypeOrTPHOrWildcardOrGeneric typeOfArgument) {
this.nameOfArgument = nameOfArgument; this.nameOfArgument = nameOfArgument;
this.typeOfArgument = typeOfArgument; this.typeOfArgument = typeOfArgument;
} }
@ -27,11 +29,11 @@ public class AssumptionArgument extends AssumptionAbstract {
this.nameOfArgument = nameOfArgument; this.nameOfArgument = nameOfArgument;
} }
public TypeVarAbstract getTypeOfArgument() { public RefTypeOrTPHOrWildcardOrGeneric getTypeOfArgument() {
return typeOfArgument; return typeOfArgument;
} }
public void setTypeOfArgument(TypeVarAbstract typeOfArgument) { public void setTypeOfArgument(RefTypeOrTPHOrWildcardOrGeneric typeOfArgument) {
this.typeOfArgument = typeOfArgument; this.typeOfArgument = typeOfArgument;
} }

View File

@ -4,9 +4,10 @@ package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract; import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface; import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -21,13 +22,13 @@ public class AssumptionClass extends AssumptionAbstract {
private AssumptionMap assumptionMap; private AssumptionMap assumptionMap;
private List<ConstraintAbstract> constraints; private List<ConstraintAbstract> constraints;
private List<Interface> generatedinterfaces; private List<Interface> generatedinterfaces;
private List<TypeVarAbstract> genericsForClass; private List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass;
public AssumptionClass() { public AssumptionClass() {
} }
public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, AssumptionMap assumptionMap, List<ConstraintAbstract> constraints, List<Interface> generatedinterfaces, List<TypeVarAbstract> genericsForClass) { public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, AssumptionMap assumptionMap, List<ConstraintAbstract> constraints, List<Interface> generatedinterfaces, List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass) {
this.cl = cl; this.cl = cl;
this.typeVarStore = typeVarStore; this.typeVarStore = typeVarStore;
this.assumptionMap = assumptionMap; this.assumptionMap = assumptionMap;
@ -77,11 +78,11 @@ public class AssumptionClass extends AssumptionAbstract {
this.generatedinterfaces = generatedinterfaces; this.generatedinterfaces = generatedinterfaces;
} }
public List<TypeVarAbstract> getGenericsForClass() { public List<RefTypeOrTPHOrWildcardOrGeneric> getGenericsForClass() {
return genericsForClass; return genericsForClass;
} }
public void setGenericsForClass(List<TypeVarAbstract> genericsForClass) { public void setGenericsForClass(List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass) {
this.genericsForClass = genericsForClass; this.genericsForClass = genericsForClass;
} }

View File

@ -1,12 +1,13 @@
package de.dhbwstuttgart.strucTypes5.assumptions; package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -56,7 +57,7 @@ public class AssumptionFactory {
public static AssumptionArgument makeArgumentAssumption(FormalParameter formalParameter , TypeVarStore typeVarStore) { public static AssumptionArgument makeArgumentAssumption(FormalParameter formalParameter , TypeVarStore typeVarStore) {
TypeVarAbstract typeVar = typeVarStore.storeTPH(formalParameter.getType()); RefTypeOrTPHOrWildcardOrGeneric typeVar = typeVarStore.storeTPH(formalParameter.getType());
return new AssumptionArgument(formalParameter.getName(), typeVar); return new AssumptionArgument(formalParameter.getName(), typeVar);
} }

View File

@ -1,7 +1,8 @@
package de.dhbwstuttgart.strucTypes5.assumptions; package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -55,7 +56,7 @@ public class AssumptionMap {
} }
public TypeVarAbstract getVarAssumption(String name) { public RefTypeOrTPHOrWildcardOrGeneric getVarAssumption(String name) {
// gibt lokale Var zurück. wenn nicht vorhanden gloable. wenn nicht vorhanden null // gibt lokale Var zurück. wenn nicht vorhanden gloable. wenn nicht vorhanden null
if (argAss.containsKey(name)) { if (argAss.containsKey(name)) {
@ -77,7 +78,7 @@ public class AssumptionMap {
return true; return true;
} }
public TypeVarAbstract getThisVar(String name) { public RefTypeOrTPHOrWildcardOrGeneric getThisVar(String name) {
return fass.get(name).getTypeVar(); return fass.get(name).getTypeVar();
} }

View File

@ -6,7 +6,8 @@ import de.dhbwstuttgart.strucTypes5.constraints.ConstraintSubType;
import de.dhbwstuttgart.strucTypes5.typeVars.MappingAltNeu; import de.dhbwstuttgart.strucTypes5.typeVars.MappingAltNeu;
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple; import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,11 +39,11 @@ public class ChangeTypeVars {
if (c instanceof ConstraintSubType) { if (c instanceof ConstraintSubType) {
ConstraintSubType csub = (ConstraintSubType) c; ConstraintSubType csub = (ConstraintSubType) c;
TypeVarAbstract tsub = csub.getSubtype(); RefTypeOrTPHOrWildcardOrGeneric tsub = csub.getSubtype();
TypeVarAbstract tsuper = csub.getSuperType(); RefTypeOrTPHOrWildcardOrGeneric tsuper = csub.getSuperType();
TypeVarAbstract newTSub = mappingAltNeu.getNeu(tsub); RefTypeOrTPHOrWildcardOrGeneric newTSub = mappingAltNeu.getNeu(tsub);
TypeVarAbstract newTsuper = mappingAltNeu.getNeu(tsuper); RefTypeOrTPHOrWildcardOrGeneric newTsuper = mappingAltNeu.getNeu(tsuper);
ConstraintSubType newC = new ConstraintSubType(newTSub , newTsuper); ConstraintSubType newC = new ConstraintSubType(newTSub , newTsuper);
newConstraints.add(newC); newConstraints.add(newC);
@ -59,8 +60,8 @@ public class ChangeTypeVars {
// Tausche Generics aus // Tausche Generics aus
List<TypeVarAbstract> genericsneu = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsneu = new ArrayList<>();
for (TypeVarAbstract tv : oldAssClass.getGenericsForClass()) { for (RefTypeOrTPHOrWildcardOrGeneric tv : oldAssClass.getGenericsForClass()) {
if (tv instanceof TypeVar) { if (tv instanceof TypeVar) {
TypeVar genericNeu = (TypeVar) mappingAltNeu.getNeu(tv); TypeVar genericNeu = (TypeVar) mappingAltNeu.getNeu(tv);
genericsneu.add(genericNeu); genericsneu.add(genericNeu);

View File

@ -1,20 +1,21 @@
package de.dhbwstuttgart.strucTypes5.constraints; package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 20.04.17. * Created by sebastian on 20.04.17.
*/ */
public abstract class ConstraintAbstract { public abstract class ConstraintAbstract {
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) { public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
return false; return false;
} }
public static TypeVarAbstract helpChange(TypeVarAbstract old, TypeVarAbstract neu, TypeVarAbstract inFrage) { public static RefTypeOrTPHOrWildcardOrGeneric helpChange(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu, RefTypeOrTPHOrWildcardOrGeneric inFrage) {
if (inFrage instanceof TypeVarInterface) { if (inFrage instanceof TypeVarInterface) {
((TypeVarInterface) inFrage).getInterfaceForConstraint().replaceTypeVarAbstract(old,neu); ((TypeVarInterface) inFrage).getInterfaceForConstraint().replaceTypeVarAbstract(old,neu);
return inFrage; return inFrage;
@ -25,7 +26,7 @@ public abstract class ConstraintAbstract {
} }
public static boolean helpChange2(TypeVarAbstract old, TypeVarAbstract neu, TypeVarAbstract inFrage) { public static boolean helpChange2(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu, RefTypeOrTPHOrWildcardOrGeneric inFrage) {
if (inFrage instanceof TypeVarInterface) { if (inFrage instanceof TypeVarInterface) {
ConstraintAbstract.helpChange(old,neu,inFrage); ConstraintAbstract.helpChange(old,neu,inFrage);
return true; return true;

View File

@ -1,34 +1,35 @@
package de.dhbwstuttgart.strucTypes5.constraints; package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 02.05.17. * Created by sebastian on 02.05.17.
*/ */
public class ConstraintInterface extends ConstraintAbstract { public class ConstraintInterface extends ConstraintAbstract {
private TypeVarAbstract SubType; private RefTypeOrTPHOrWildcardOrGeneric SubType;
private TypeVarAbstract SuperType; private RefTypeOrTPHOrWildcardOrGeneric SuperType;
public ConstraintInterface(TypeVarAbstract subType, TypeVarAbstract superType) { public ConstraintInterface(RefTypeOrTPHOrWildcardOrGeneric subType, RefTypeOrTPHOrWildcardOrGeneric superType) {
SubType = subType; SubType = subType;
SuperType = superType; SuperType = superType;
} }
public TypeVarAbstract getSubType() { public RefTypeOrTPHOrWildcardOrGeneric getSubType() {
return SubType; return SubType;
} }
public void setSubType(TypeVarAbstract subType) { public void setSubType(RefTypeOrTPHOrWildcardOrGeneric subType) {
SubType = subType; SubType = subType;
} }
public TypeVarAbstract getSuperType() { public RefTypeOrTPHOrWildcardOrGeneric getSuperType() {
return SuperType; return SuperType;
} }
public void setSuperType(TypeVarAbstract superType) { public void setSuperType(RefTypeOrTPHOrWildcardOrGeneric superType) {
SuperType = superType; SuperType = superType;
} }

View File

@ -1,24 +1,25 @@
package de.dhbwstuttgart.strucTypes5.constraints; package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 01.05.17. * Created by sebastian on 01.05.17.
*/ */
public class ConstraintShouldEqual extends ConstraintAbstract{ public class ConstraintShouldEqual extends ConstraintAbstract{
private TypeVarAbstract t1; private RefTypeOrTPHOrWildcardOrGeneric t1;
private TypeVarAbstract t2; private RefTypeOrTPHOrWildcardOrGeneric t2;
public ConstraintShouldEqual(TypeVarAbstract t1, TypeVarAbstract t2) { public ConstraintShouldEqual(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2) {
this.t1 = t1; this.t1 = t1;
this.t2 = t2; this.t2 = t2;
} }
@Override @Override
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) { public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
if (t1.equals(alt)) { if (t1.equals(alt)) {
t1 = ConstraintAbstract.helpChange(alt,neu,t1); t1 = ConstraintAbstract.helpChange(alt,neu,t1);
} }
@ -30,19 +31,19 @@ public class ConstraintShouldEqual extends ConstraintAbstract{
return true; return true;
} }
public TypeVarAbstract getT1() { public RefTypeOrTPHOrWildcardOrGeneric getT1() {
return t1; return t1;
} }
public void setT1(TypeVarAbstract t1) { public void setT1(RefTypeOrTPHOrWildcardOrGeneric t1) {
this.t1 = t1; this.t1 = t1;
} }
public TypeVarAbstract getT2() { public RefTypeOrTPHOrWildcardOrGeneric getT2() {
return t2; return t2;
} }
public void setT2(TypeVarAbstract t2) { public void setT2(RefTypeOrTPHOrWildcardOrGeneric t2) {
this.t2 = t2; this.t2 = t2;
} }

View File

@ -2,7 +2,8 @@ package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 20.04.17. * Created by sebastian on 20.04.17.
@ -13,17 +14,17 @@ public class ConstraintSubType extends ConstraintAbstract{
// TODO Hier muss ich mir das noch überlegen wie es geht. Evtl ist eine TypeVarType nicht notwenidg // TODO Hier muss ich mir das noch überlegen wie es geht. Evtl ist eine TypeVarType nicht notwenidg
// Eine Typvariable kann TypVar sein, ein Typ kann auch eine TypVar sein , ein Interface kann was sein ? // Eine Typvariable kann TypVar sein, ein Typ kann auch eine TypVar sein , ein Interface kann was sein ?
private TypeVarAbstract subtype; private RefTypeOrTPHOrWildcardOrGeneric subtype;
private TypeVarAbstract superType; private RefTypeOrTPHOrWildcardOrGeneric superType;
public ConstraintSubType(TypeVarAbstract subtype, TypeVarAbstract superType) { public ConstraintSubType(RefTypeOrTPHOrWildcardOrGeneric subtype, RefTypeOrTPHOrWildcardOrGeneric superType) {
this.subtype = subtype; this.subtype = subtype;
this.superType = superType; this.superType = superType;
} }
@Override @Override
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) { public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
if (subtype.equals(alt)) { if (subtype.equals(alt)) {
subtype = ConstraintAbstract.helpChange(alt,neu,subtype); subtype = ConstraintAbstract.helpChange(alt,neu,subtype);
} }
@ -36,19 +37,19 @@ public class ConstraintSubType extends ConstraintAbstract{
} }
public TypeVarAbstract getSubtype() { public RefTypeOrTPHOrWildcardOrGeneric getSubtype() {
return subtype; return subtype;
} }
public void setSubtype(TypeVarAbstract subtype) { public void setSubtype(RefTypeOrTPHOrWildcardOrGeneric subtype) {
this.subtype = subtype; this.subtype = subtype;
} }
public TypeVarAbstract getSuperType() { public RefTypeOrTPHOrWildcardOrGeneric getSuperType() {
return superType; return superType;
} }
public void setSuperType(TypeVarAbstract superType) { public void setSuperType(RefTypeOrTPHOrWildcardOrGeneric superType) {
this.superType = superType; this.superType = superType;
} }

View File

@ -1,33 +1,34 @@
package de.dhbwstuttgart.strucTypes5.constraints; package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 01.05.17. * Created by sebastian on 01.05.17.
*/ */
public class ConstraintSubstitution extends ConstraintAbstract { public class ConstraintSubstitution extends ConstraintAbstract {
private TypeVarAbstract t1; private RefTypeOrTPHOrWildcardOrGeneric t1;
private TypeVarAbstract t2; private RefTypeOrTPHOrWildcardOrGeneric t2;
public ConstraintSubstitution(TypeVarAbstract t1, TypeVarAbstract t2) { public ConstraintSubstitution(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2) {
this.t1 = t1; this.t1 = t1;
this.t2 = t2; this.t2 = t2;
} }
public TypeVarAbstract getT1() { public RefTypeOrTPHOrWildcardOrGeneric getT1() {
return t1; return t1;
} }
public void setT1(TypeVarAbstract t1) { public void setT1(RefTypeOrTPHOrWildcardOrGeneric t1) {
this.t1 = t1; this.t1 = t1;
} }
public TypeVarAbstract getT2() { public RefTypeOrTPHOrWildcardOrGeneric getT2() {
return t2; return t2;
} }
public void setT2(TypeVarAbstract t2) { public void setT2(RefTypeOrTPHOrWildcardOrGeneric t2) {
this.t2 = t2; this.t2 = t2;
} }

View File

@ -1,7 +1,8 @@
package de.dhbwstuttgart.strucTypes5.constraints; package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.algo.Type; import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -11,21 +12,21 @@ import java.util.List;
*/ */
public class InterfaceForConstraint { public class InterfaceForConstraint {
private TypeVarAbstract strucType; private RefTypeOrTPHOrWildcardOrGeneric strucType;
private List<TypeVarAbstract> generics; private List<RefTypeOrTPHOrWildcardOrGeneric> generics;
public InterfaceForConstraint(TypeVarAbstract strucType, List<TypeVarAbstract> generics) { public InterfaceForConstraint(RefTypeOrTPHOrWildcardOrGeneric strucType, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.strucType = strucType; this.strucType = strucType;
this.generics = generics; this.generics = generics;
} }
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) { public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
List<TypeVarAbstract> genericsneu = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsneu = new ArrayList<>();
for (TypeVarAbstract tv : generics) { for (RefTypeOrTPHOrWildcardOrGeneric tv : generics) {
if (tv.equals(alt)) { if (tv.equals(alt)) {
genericsneu.add(neu); genericsneu.add(neu);
} }
@ -40,19 +41,19 @@ public class InterfaceForConstraint {
public TypeVarAbstract getStrucType() { public RefTypeOrTPHOrWildcardOrGeneric getStrucType() {
return strucType; return strucType;
} }
public void setStrucType(TypeVarAbstract strucType) { public void setStrucType(RefTypeOrTPHOrWildcardOrGeneric strucType) {
this.strucType = strucType; this.strucType = strucType;
} }
public List<TypeVarAbstract> getGenerics() { public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
return generics; return generics;
} }
public void setGenerics(List<TypeVarAbstract> generics) { public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.generics = generics; this.generics = generics;
} }

View File

@ -1,26 +1,27 @@
package de.dhbwstuttgart.strucTypes5.interfaceTemplates; package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 09.04.17. * Created by sebastian on 09.04.17.
*/ */
public class FieldInterface { public class FieldInterface {
TypeVarAbstract type; RefTypeOrTPHOrWildcardOrGeneric type;
String name; String name;
public FieldInterface(TypeVarAbstract type, String name) { public FieldInterface(RefTypeOrTPHOrWildcardOrGeneric type, String name) {
this.type = type; this.type = type;
this.name = name; this.name = name;
} }
public TypeVarAbstract getType() { public RefTypeOrTPHOrWildcardOrGeneric getType() {
return type; return type;
} }
public void setType(TypeVarAbstract type) { public void setType(RefTypeOrTPHOrWildcardOrGeneric type) {
this.type = type; this.type = type;
} }

View File

@ -3,7 +3,8 @@ package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -13,13 +14,13 @@ import java.util.List;
*/ */
public class Interface { public class Interface {
TypeVarAbstract strucType; RefTypeOrTPHOrWildcardOrGeneric strucType;
List<FieldInterface> fields; List<FieldInterface> fields;
List<MethodInterface> methods; List<MethodInterface> methods;
List<TypeVarAbstract> generics; List<RefTypeOrTPHOrWildcardOrGeneric> generics;
public Interface(TypeVarAbstract strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<TypeVarAbstract> generics) { public Interface(RefTypeOrTPHOrWildcardOrGeneric strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.strucType = strucType; this.strucType = strucType;
this.fields = fields; this.fields = fields;
this.methods = methods; this.methods = methods;
@ -42,11 +43,11 @@ public class Interface {
this.methods = methods; this.methods = methods;
} }
public List<TypeVarAbstract> getGenerics() { public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
return generics; return generics;
} }
public void setGenerics(List<TypeVarAbstract> generics) { public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
this.generics = generics; this.generics = generics;
} }

View File

@ -2,7 +2,8 @@ package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List; import java.util.List;
@ -12,11 +13,11 @@ import java.util.List;
public class MethodInterface { public class MethodInterface {
String name; String name;
TypeVarAbstract rtType; RefTypeOrTPHOrWildcardOrGeneric rtType;
List<TypeVarAbstract> argsTypes; List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
public MethodInterface(String name, TypeVarAbstract rtType, List<TypeVarAbstract> argsTypes) { public MethodInterface(String name, RefTypeOrTPHOrWildcardOrGeneric rtType, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
this.name = name; this.name = name;
this.rtType = rtType; this.rtType = rtType;
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
@ -31,19 +32,19 @@ public class MethodInterface {
this.name = name; this.name = name;
} }
public TypeVarAbstract getRtType() { public RefTypeOrTPHOrWildcardOrGeneric getRtType() {
return rtType; return rtType;
} }
public void setRtType(TypeVarAbstract rtType) { public void setRtType(RefTypeOrTPHOrWildcardOrGeneric rtType) {
this.rtType = rtType; this.rtType = rtType;
} }
public List<TypeVarAbstract> getArgsTypes() { public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
return argsTypes; return argsTypes;
} }
public void setArgsTypes(List<TypeVarAbstract> argsTypes) { public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
this.argsTypes = argsTypes; this.argsTypes = argsTypes;
} }

View File

@ -5,9 +5,10 @@ package de.dhbwstuttgart.strucTypes5.solve;
import de.dhbwstuttgart.strucTypes5.algo.Type; import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.constraints.*; import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; //import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
@ -78,8 +79,8 @@ public class Rules {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
if (cs instanceof ConstraintShouldEqual) { if (cs instanceof ConstraintShouldEqual) {
ConstraintShouldEqual csse = (ConstraintShouldEqual) cs; ConstraintShouldEqual csse = (ConstraintShouldEqual) cs;
TypeVarAbstract theta = csse.getT1(); RefTypeOrTPHOrWildcardOrGeneric theta = csse.getT1();
TypeVarAbstract typeVar = csse.getT2(); RefTypeOrTPHOrWildcardOrGeneric typeVar = csse.getT2();
if (theta instanceof TypeVarRefType && typeVar instanceof TypeVar) { if (theta instanceof TypeVarRefType && typeVar instanceof TypeVar) {
csse.setT1(typeVar); csse.setT1(typeVar);
csse.setT2(theta); csse.setT2(theta);
@ -100,8 +101,8 @@ public class Rules {
public void subst(List<ConstraintAbstract> constraints) { public void subst(List<ConstraintAbstract> constraints) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
if (cs instanceof ConstraintShouldEqual) { if (cs instanceof ConstraintShouldEqual) {
TypeVarAbstract t1 = ((ConstraintShouldEqual) cs).getT1(); RefTypeOrTPHOrWildcardOrGeneric t1 = ((ConstraintShouldEqual) cs).getT1();
TypeVarAbstract t2 = ((ConstraintShouldEqual) cs).getT2(); RefTypeOrTPHOrWildcardOrGeneric t2 = ((ConstraintShouldEqual) cs).getT2();
if (t1 instanceof TypeVar) { if (t1 instanceof TypeVar) {
if (t2 instanceof TypeVarRefType || t2 instanceof TypeVarInterface) { if (t2 instanceof TypeVarRefType || t2 instanceof TypeVarInterface) {
@ -132,7 +133,7 @@ public class Rules {
public void replaceAll(List<ConstraintAbstract> constraints , TypeVarAbstract alt , TypeVarAbstract neu ) { public void replaceAll(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric alt , RefTypeOrTPHOrWildcardOrGeneric neu ) {
System.out.println(String.format("Replace All: %s -> %s" , alt , neu )); System.out.println(String.format("Replace All: %s -> %s" , alt , neu ));
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
@ -243,10 +244,10 @@ public class Rules {
ConstraintSubType css = (ConstraintSubType) cs; ConstraintSubType css = (ConstraintSubType) cs;
if (css.getSubtype() instanceof TypeVarRefType && css.getSuperType() instanceof TypeVar) { if (css.getSubtype() instanceof TypeVarRefType && css.getSuperType() instanceof TypeVar) {
List<TypeVarAbstract> reflect = reflectNext(constraints, css.getSubtype(), (TypeVar) css.getSuperType()); List<RefTypeOrTPHOrWildcardOrGeneric> reflect = reflectNext(constraints, css.getSubtype(), (TypeVar) css.getSuperType());
if (reflect != null) { if (reflect != null) {
System.out.println("Reflect für " + reflect + css.getSubtype()); System.out.println("Reflect für " + reflect + css.getSubtype());
for (TypeVarAbstract tv : reflect) { for (RefTypeOrTPHOrWildcardOrGeneric tv : reflect) {
substitutions.add(new ConstraintSubstitution(tv , css.getSubtype())); substitutions.add(new ConstraintSubstitution(tv , css.getSubtype()));
// Todo Unsauber wg // Todo Unsauber wg
constraints.remove(cs); constraints.remove(cs);
@ -259,20 +260,20 @@ public class Rules {
} }
} }
public List<TypeVarAbstract> reflectNext(List<ConstraintAbstract> constraints , TypeVarAbstract startValue ,TypeVar nextPoint) { public List<RefTypeOrTPHOrWildcardOrGeneric> reflectNext(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric startValue ,TypeVar nextPoint) {
ConstraintSubType next = next(nextPoint,constraints); ConstraintSubType next = next(nextPoint,constraints);
if (next != null) { if (next != null) {
if (next.getSuperType().equals(startValue)) { if (next.getSuperType().equals(startValue)) {
List<TypeVarAbstract> result = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> result = new ArrayList<>();
result.add(next.getSubtype()); result.add(next.getSubtype());
constraints.remove(next); // ?? Sauber? constraints.remove(next); // ?? Sauber?
return result; return result;
} }
else if (next.getSuperType() instanceof TypeVar ) { else if (next.getSuperType() instanceof TypeVar ) {
List<TypeVarAbstract> result = reflectNext(constraints,startValue,(TypeVar) next.getSuperType()); List<RefTypeOrTPHOrWildcardOrGeneric> result = reflectNext(constraints,startValue,(TypeVar) next.getSuperType());
if (result != null) { if (result != null) {
result.add(next.getSubtype()); result.add(next.getSubtype());
constraints.remove(next); // ? Sauber constraints.remove(next); // ? Sauber
@ -321,8 +322,8 @@ public class Rules {
// Erstelle neue Constraints // Erstelle neue Constraints
for (int i = 0 ; i < if1.getGenerics().size() ; i++) { for (int i = 0 ; i < if1.getGenerics().size() ; i++) {
TypeVarAbstract tnX = if1.getGenerics().get(i); RefTypeOrTPHOrWildcardOrGeneric tnX = if1.getGenerics().get(i);
TypeVarAbstract tnY = if2.getGenerics().get(i); RefTypeOrTPHOrWildcardOrGeneric tnY = if2.getGenerics().get(i);
// Ergebnis an ConstraintList // Ergebnis an ConstraintList
constraints.add(new ConstraintShouldEqual(tnX,tnY)); constraints.add(new ConstraintShouldEqual(tnX,tnY));
@ -358,7 +359,7 @@ public class Rules {
} }
private ConstraintInterface sucheInterface( TypeVarAbstract tvSub , TypeVarAbstract tvSuper ) { private ConstraintInterface sucheInterface( RefTypeOrTPHOrWildcardOrGeneric tvSub , RefTypeOrTPHOrWildcardOrGeneric tvSuper ) {
for (ConstraintInterface cs : constraintInterfaces) { for (ConstraintInterface cs : constraintInterfaces) {
if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) { if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) {
@ -408,7 +409,7 @@ public class Rules {
} }
public List<ConstraintAbstract> adapt2Next(TypeVarAbstract start , TypeVarAbstract last , List<ConstraintAbstract> constraints, List<ConstraintAbstract> newConstraints) { public List<ConstraintAbstract> adapt2Next(RefTypeOrTPHOrWildcardOrGeneric start , RefTypeOrTPHOrWildcardOrGeneric last , List<ConstraintAbstract> constraints, List<ConstraintAbstract> newConstraints) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
@ -433,8 +434,8 @@ public class Rules {
TypeVarInterface iFGiven = (TypeVarInterface) constraintInterface.getSuperType(); TypeVarInterface iFGiven = (TypeVarInterface) constraintInterface.getSuperType();
TypeVarInterface iFthis = (TypeVarInterface) css.getSuperType(); TypeVarInterface iFthis = (TypeVarInterface) css.getSuperType();
List<TypeVarAbstract> iFGivenGenerics = iFGiven.getInterfaceForConstraint().getGenerics(); List<RefTypeOrTPHOrWildcardOrGeneric> iFGivenGenerics = iFGiven.getInterfaceForConstraint().getGenerics();
List<TypeVarAbstract> iFthisGenerics = iFthis.getInterfaceForConstraint().getGenerics(); List<RefTypeOrTPHOrWildcardOrGeneric> iFthisGenerics = iFthis.getInterfaceForConstraint().getGenerics();
if (iFGivenGenerics.size() == iFthisGenerics.size()) { if (iFGivenGenerics.size() == iFthisGenerics.size()) {
for (int i = 0 ; i < iFGivenGenerics.size() ; i++ ) { for (int i = 0 ; i < iFGivenGenerics.size() ; i++ ) {

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint; import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,10 +13,10 @@ import java.util.List;
public class MappingAltNeu { public class MappingAltNeu {
List<TypeVarAbstract> altList = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> altList = new ArrayList<>();
List<TypeVarAbstract> neuList = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> neuList = new ArrayList<>();
public void addTypeVar(TypeVarAbstract alt, TypeVarAbstract neu) { public void addTypeVar(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
altList.add(alt); altList.add(alt);
// Versuch bereits bekannte Typen mitzunehmen // Versuch bereits bekannte Typen mitzunehmen
@ -28,7 +29,7 @@ public class MappingAltNeu {
} }
} }
public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) { public RefTypeOrTPHOrWildcardOrGeneric getNeu (RefTypeOrTPHOrWildcardOrGeneric altTypeVar) {
// Wenn der Typ bereits bekannt ist gebe ihn zurück // Wenn der Typ bereits bekannt ist gebe ihn zurück
if (altTypeVar instanceof TypeVarRefType) { if (altTypeVar instanceof TypeVarRefType) {
@ -36,10 +37,10 @@ public class MappingAltNeu {
} }
else if (altTypeVar instanceof TypeVarInterface) { else if (altTypeVar instanceof TypeVarInterface) {
TypeVarInterface strucType = (TypeVarInterface) altTypeVar; TypeVarInterface strucType = (TypeVarInterface) altTypeVar;
TypeVarAbstract name = strucType.getInterfaceForConstraint().getStrucType(); RefTypeOrTPHOrWildcardOrGeneric name = strucType.getInterfaceForConstraint().getStrucType();
List<TypeVarAbstract> neueGenerics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> neueGenerics = new ArrayList<>();
List<TypeVarAbstract> alteGenerics = strucType.getInterfaceForConstraint().getGenerics(); List<RefTypeOrTPHOrWildcardOrGeneric> alteGenerics = strucType.getInterfaceForConstraint().getGenerics();
for (TypeVarAbstract tv : alteGenerics) { for (RefTypeOrTPHOrWildcardOrGeneric tv : alteGenerics) {
neueGenerics.add(this.getNeu(tv)); neueGenerics.add(this.getNeu(tv));
} }

View File

@ -1,13 +1,18 @@
package de.dhbwstuttgart.strucTypes5.typeVars; package de.dhbwstuttgart.strucTypes5.typeVars;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 14.04.17. * Created by sebastian on 14.04.17.
*/ */
public class TypeVar extends TypeVarAbstract { public class TypeVar extends RefTypeOrTPHOrWildcardOrGeneric {
private String id; private String id;
public TypeVar(String id) { public TypeVar(String id) {
super();
this.id = id; this.id = id;
} }

View File

@ -1,11 +1,12 @@
package de.dhbwstuttgart.strucTypes5.typeVars; package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint; import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 30.04.17. * Created by sebastian on 30.04.17.
*/ */
public class TypeVarInterface extends TypeVarAbstract { public class TypeVarInterface extends RefTypeOrTPHOrWildcardOrGeneric {
private InterfaceForConstraint interfaceForConstraint; private InterfaceForConstraint interfaceForConstraint;
@ -40,7 +41,7 @@ public class TypeVarInterface extends TypeVarAbstract {
// Equal_for_Unify // Equal_for_Unify
public boolean equalsForUnify(TypeVarAbstract tv) { public boolean equalsForUnify(RefTypeOrTPHOrWildcardOrGeneric tv) {
if (tv instanceof TypeVarInterface) { if (tv instanceof TypeVarInterface) {
String name = ((TypeVarInterface) tv).getInterfaceForConstraint().getStrucType().toString(); String name = ((TypeVarInterface) tv).getInterfaceForConstraint().getStrucType().toString();

View File

@ -1,11 +1,12 @@
package de.dhbwstuttgart.strucTypes5.typeVars; package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 30.04.17. * Created by sebastian on 30.04.17.
*/ */
public class TypeVarRefType extends TypeVarAbstract { public class TypeVarRefType extends RefTypeOrTPHOrWildcardOrGeneric {
private RefType refType; private RefType refType;

View File

@ -14,11 +14,11 @@ import java.util.List;
public class TypeVarStore { public class TypeVarStore {
private HashMap<TypeVarAbstract, List<RefTypeOrTPHOrWildcardOrGeneric>> map = new HashMap<>(); private HashMap<RefTypeOrTPHOrWildcardOrGeneric, List<RefTypeOrTPHOrWildcardOrGeneric>> map = new HashMap<>();
public TypeVarAbstract storeTPH(RefTypeOrTPHOrWildcardOrGeneric tph) { public RefTypeOrTPHOrWildcardOrGeneric storeTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
if (getTypeVarByTPH(tph) == null) { if (getTypeVarByTPH(tph) == null) {
TypeVar tvNeu = TypeVarFactory.makeTypeVar(); TypeVar tvNeu = TypeVarFactory.makeTypeVar();
@ -41,7 +41,7 @@ public class TypeVarStore {
public void addTuple(TypeVarAbstract tv, RefTypeOrTPHOrWildcardOrGeneric tph) { public void addTuple(RefTypeOrTPHOrWildcardOrGeneric tv, RefTypeOrTPHOrWildcardOrGeneric tph) {
// TypVar bereits vorhandne // TypVar bereits vorhandne
@ -66,13 +66,13 @@ public class TypeVarStore {
} }
public List<RefTypeOrTPHOrWildcardOrGeneric> getTPHByTypeVar(TypeVarAbstract tv) { public List<RefTypeOrTPHOrWildcardOrGeneric> getTPHByTypeVar(RefTypeOrTPHOrWildcardOrGeneric tv) {
return map.get(tv); return map.get(tv);
} }
public TypeVarAbstract getTypeVarByTPH(RefTypeOrTPHOrWildcardOrGeneric tph) { public RefTypeOrTPHOrWildcardOrGeneric getTypeVarByTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
// TPH ist bereits einer TypVar zugeordnet // TPH ist bereits einer TypVar zugeordnet
for (TypeVarAbstract typeVar : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric typeVar : map.keySet()) {
if (map.get(typeVar).contains(tph)) { if (map.get(typeVar).contains(tph)) {
return typeVar; return typeVar;
} }
@ -88,7 +88,7 @@ public class TypeVarStore {
public TypeVarStore freshVariables() { public TypeVarStore freshVariables() {
TypeVarStore typeVarStore = new TypeVarStore(); TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
TypeVar tvNew = TypeVarFactory.makeTypeVar(); TypeVar tvNew = TypeVarFactory.makeTypeVar();
typeVarStore.map.put(tvNew,map.get(tvarOld)); typeVarStore.map.put(tvNew,map.get(tvarOld));
} }
@ -103,11 +103,11 @@ public class TypeVarStore {
TypeVarStore typeVarStore = new TypeVarStore(); TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) { for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
// Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt. // Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt.
if (tvarOld instanceof TypeVarType) { if (tvarOld instanceof TypeVarType) {
TypeVarAbstract tvNew = tvarOld; RefTypeOrTPHOrWildcardOrGeneric tvNew = tvarOld;
typeVarStore.map.put(tvNew,map.get(tvarOld)); typeVarStore.map.put(tvNew,map.get(tvarOld));
mappingAltNeu.addTypeVar(tvarOld,tvNew); mappingAltNeu.addTypeVar(tvarOld,tvNew);
} }
@ -123,7 +123,7 @@ public class TypeVarStore {
public boolean replaceTypeVar(TypeVarAbstract old, TypeVarAbstract neu) { public boolean replaceTypeVar(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu) {
if (map.containsKey(old)) { if (map.containsKey(old)) {
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(old); List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(old);
@ -137,7 +137,7 @@ public class TypeVarStore {
} }
public TypeVarAbstract isType(TypeVar testVar) { public RefTypeOrTPHOrWildcardOrGeneric isType(TypeVar testVar) {
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(testVar); List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(testVar);
if (tphList == null) { if (tphList == null) {
@ -160,7 +160,7 @@ public class TypeVarStore {
@Override @Override
public String toString() { public String toString() {
String res = "--- TypeVarStore ---\n"; String res = "--- TypeVarStore ---\n";
for (TypeVarAbstract tvar : map.keySet() ) { for (RefTypeOrTPHOrWildcardOrGeneric tvar : map.keySet() ) {
res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n"; res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n";
} }
return String.format(res); return String.format(res);

View File

@ -2,11 +2,12 @@ package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Created by sebastian on 14.04.17. * Created by sebastian on 14.04.17.
*/ */
public class TypeVarType extends TypeVarAbstract { public class TypeVarType extends RefTypeOrTPHOrWildcardOrGeneric {
private Class typeClass; private Class typeClass;

View File

@ -11,6 +11,10 @@ import org.antlr.v4.runtime.misc.Pair;
public abstract class SyntaxTreeNode implements IItemWithOffset{ public abstract class SyntaxTreeNode implements IItemWithOffset{
private final Token offset; private final Token offset;
public SyntaxTreeNode() {
super();
offset = null;
}
public SyntaxTreeNode(Token offset){ public SyntaxTreeNode(Token offset){
this.offset = offset; this.offset = offset;
} }

View File

@ -4,6 +4,9 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
public class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{ public class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
public RefTypeOrTPHOrWildcardOrGeneric(){
super();
}
public RefTypeOrTPHOrWildcardOrGeneric(Token offset) { public RefTypeOrTPHOrWildcardOrGeneric(Token offset) {
super(offset); super(offset);
} }

View File

@ -64,14 +64,14 @@ public class SolveTest {
// Generate Interfaces Give // Generate Interfaces Give
TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger"); TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger");
TypeVarAbstract v2 = getTypeVar(ti1.resultConstraints , "TVar_2"); RefTypeOrTPHOrWildcardOrGeneric v2 = getTypeVar(ti1.resultConstraints , "TVar_2");
TypeVarAbstract v5 = getTypeVar(ti1.resultConstraints , "TVar_5"); RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5");
System.out.println(myInteger.toString()); System.out.println(myInteger.toString());
System.out.println(v2.toString()); System.out.println(v2.toString());
System.out.println(v5.toString()); System.out.println(v5.toString());
// Generiere Interface 1 // Generiere Interface 1
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
InterfaceForConstraint if1 = new InterfaceForConstraint(v2, generics); InterfaceForConstraint if1 = new InterfaceForConstraint(v2, generics);
@ -81,7 +81,7 @@ public class SolveTest {
// Generiere Interface 2 // Generiere Interface 2
List<TypeVarAbstract> generics2 = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics2 = new ArrayList<>();
generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
InterfaceForConstraint if2 = new InterfaceForConstraint(v5, generics); InterfaceForConstraint if2 = new InterfaceForConstraint(v5, generics);
@ -147,7 +147,7 @@ public class SolveTest {
assertTrue("Tests durchlaufen", filenames.size() > 0); assertTrue("Tests durchlaufen", filenames.size() > 0);
} }
private TypeVarAbstract getTypeVar(List<ConstraintAbstract> constraints , String name) { private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List<ConstraintAbstract> constraints , String name) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
if (cs instanceof ConstraintSubType) { if (cs instanceof ConstraintSubType) {
ConstraintSubType css = (ConstraintSubType) cs; ConstraintSubType css = (ConstraintSubType) cs;

View File

@ -66,15 +66,15 @@ public class SolveTestMyList {
TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger"); TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger");
TypeVarRefType myList = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyList"); TypeVarRefType myList = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyList");
TypeVarAbstract v2 = getTypeVar(ti1.resultConstraints , "TVar_2"); RefTypeOrTPHOrWildcardOrGeneric v2 = getTypeVar(ti1.resultConstraints , "TVar_2");
TypeVarAbstract v5 = getTypeVar(ti1.resultConstraints , "TVar_5"); RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5");
System.out.println(myInteger.toString()); System.out.println(myInteger.toString());
System.out.println(myList.toString()); System.out.println(myList.toString());
System.out.println(v2.toString()); System.out.println(v2.toString());
// System.out.println(v5.toString()); // System.out.println(v5.toString());
// Generiere Interface 1 // Generiere Interface 1
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
generics.add(TypeVarFactory.makeTypeVar(myList.getRefType())); generics.add(TypeVarFactory.makeTypeVar(myList.getRefType()));
generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
@ -85,7 +85,7 @@ public class SolveTestMyList {
// Generiere Interface 2 // Generiere Interface 2
List<TypeVarAbstract> generics2 = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics2 = new ArrayList<>();
generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType()));
InterfaceForConstraint if2 = new InterfaceForConstraint(v5, generics); InterfaceForConstraint if2 = new InterfaceForConstraint(v5, generics);
@ -127,7 +127,7 @@ public class SolveTestMyList {
assertTrue("Tests durchlaufen", filenames.size() > 0); assertTrue("Tests durchlaufen", filenames.size() > 0);
} }
private TypeVarAbstract getTypeVar(List<ConstraintAbstract> constraints , String name) { private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List<ConstraintAbstract> constraints , String name) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
if (cs instanceof ConstraintSubType) { if (cs instanceof ConstraintSubType) {
ConstraintSubType css = (ConstraintSubType) cs; ConstraintSubType css = (ConstraintSubType) cs;

View File

@ -183,7 +183,7 @@ public class SolveTest_Dev {
TypeVar t1 = TypeVarFactory.makeTypeVar(); TypeVar t1 = TypeVarFactory.makeTypeVar();
// Erstelle Interface 1 // Erstelle Interface 1
List<TypeVarAbstract> genericsA = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsA = new ArrayList<>();
TypeVar t2 = TypeVarFactory.makeTypeVar(); TypeVar t2 = TypeVarFactory.makeTypeVar();
TypeVar t3 = TypeVarFactory.makeTypeVar(); TypeVar t3 = TypeVarFactory.makeTypeVar();
genericsA.add(t3); genericsA.add(t3);
@ -192,7 +192,7 @@ public class SolveTest_Dev {
// Erstelle Interface 2 // Erstelle Interface 2
List<TypeVarAbstract> genericsB = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsB = new ArrayList<>();
TypeVarRefType refType1 = TypeVarFactory.makeTypeVar(myInteger); TypeVarRefType refType1 = TypeVarFactory.makeTypeVar(myInteger);
TypeVarRefType refType2 = TypeVarFactory.makeTypeVar(myInteger); TypeVarRefType refType2 = TypeVarFactory.makeTypeVar(myInteger);
genericsB.add(refType1); genericsB.add(refType1);
@ -216,10 +216,10 @@ public class SolveTest_Dev {
System.out.println("Adapt1 Test"); System.out.println("Adapt1 Test");
// gemeinsamer Typ // gemeinsamer Typ
TypeVarAbstract t1 = TypeVarFactory.makeTypeVar(); RefTypeOrTPHOrWildcardOrGeneric t1 = TypeVarFactory.makeTypeVar();
// implements Interface myInteger implements Interface // implements Interface myInteger implements Interface
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
generics.add(TypeVarFactory.makeTypeVar(myInteger)); generics.add(TypeVarFactory.makeTypeVar(myInteger));
generics.add(TypeVarFactory.makeTypeVar(myInteger)); generics.add(TypeVarFactory.makeTypeVar(myInteger));
InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics); InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics);
@ -228,7 +228,7 @@ public class SolveTest_Dev {
interfaces.add(constraintInterface); interfaces.add(constraintInterface);
// Erstelle zu testenden Constraint // Erstelle zu testenden Constraint
List<TypeVarAbstract> genericsA = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsA = new ArrayList<>();
TypeVar t2 = TypeVarFactory.makeTypeVar(); TypeVar t2 = TypeVarFactory.makeTypeVar();
TypeVar t3 = TypeVarFactory.makeTypeVar(); TypeVar t3 = TypeVarFactory.makeTypeVar();
genericsA.add(t3); genericsA.add(t3);
@ -262,16 +262,16 @@ public class SolveTest_Dev {
System.out.println("Adapt2 Test"); System.out.println("Adapt2 Test");
// gemeinsamer Typ // gemeinsamer Typ
TypeVarAbstract t1 = TypeVarFactory.makeTypeVar(); RefTypeOrTPHOrWildcardOrGeneric t1 = TypeVarFactory.makeTypeVar();
// extend // extend
TypeVarAbstract text1 = TypeVarFactory.makeTypeVar(); RefTypeOrTPHOrWildcardOrGeneric text1 = TypeVarFactory.makeTypeVar();
TypeVarAbstract text2 = TypeVarFactory.makeTypeVar(); RefTypeOrTPHOrWildcardOrGeneric text2 = TypeVarFactory.makeTypeVar();
ConstraintSubType csub = new ConstraintSubType(text1,text2); ConstraintSubType csub = new ConstraintSubType(text1,text2);
// implements Interface myInteger implements Interface // implements Interface myInteger implements Interface
List<TypeVarAbstract> generics = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
generics.add(TypeVarFactory.makeTypeVar(myInteger)); generics.add(TypeVarFactory.makeTypeVar(myInteger));
generics.add(TypeVarFactory.makeTypeVar(myInteger)); generics.add(TypeVarFactory.makeTypeVar(myInteger));
InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics); InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics);
@ -280,7 +280,7 @@ public class SolveTest_Dev {
interfaces.add(constraintInterface); interfaces.add(constraintInterface);
// Erstelle zu testenden Constraint // Erstelle zu testenden Constraint
List<TypeVarAbstract> genericsA = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> genericsA = new ArrayList<>();
TypeVar t2 = TypeVarFactory.makeTypeVar(); TypeVar t2 = TypeVarFactory.makeTypeVar();
TypeVar t3 = TypeVarFactory.makeTypeVar(); TypeVar t3 = TypeVarFactory.makeTypeVar();
genericsA.add(t3); genericsA.add(t3);