diff --git a/src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java b/src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java new file mode 100644 index 00000000..9377c063 --- /dev/null +++ b/src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java @@ -0,0 +1,26 @@ +package de.dhbwstuttgart.typedeployment; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.Pair; + +public class GenericInsertPair { + public TypePlaceholder TA1; + public TypePlaceholder TA2; + + public GenericInsertPair(TypePlaceholder additionalTPH, TypePlaceholder superType) { + TA1 = additionalTPH; + TA2 = superType; + } + + public GenericInsertPair(Pair pair) { + TA1 = (TypePlaceholder) pair.TA1; + TA2 = (TypePlaceholder) pair.TA2; + } + + public boolean contains(TypePlaceholder additionalTPH) { + if(TA1.equals(additionalTPH))return true; + if(TA2.equals(additionalTPH))return true; + return false; + } +} diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index 846134de..13c2f152 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -65,14 +65,14 @@ public class TypeInsertFactory { } //Alle Bounds finden: - Set newGenerics = new HashSet<>(); + Set newGenerics = new HashSet<>(); boolean added = true; while(added){ //Fügt alle TPHs an, welche mit den additionalInserts in Verbindung stehen. added = false; for(Pair pair : pairs){ if (additionalInserts.contains(pair.TA1) || additionalInserts.contains(pair.TA2)) { - newGenerics.add(pair); + newGenerics.add(new GenericInsertPair(pair)); added |= additionalInserts.add((TypePlaceholder) pair.TA1); added |= additionalInserts.add((TypePlaceholder) pair.TA2); } @@ -82,27 +82,15 @@ public class TypeInsertFactory { //Fügt noch die Additional Inserts an, welche mit nichts in Verbindung stehen: for(TypePlaceholder additionalTPH : additionalInserts){ boolean inside = false; - for(Pair p :newGenerics){ - if(p.TA2.equals(additionalTPH) || p.TA1.equals(additionalTPH)){ + for(GenericInsertPair p :newGenerics){ + if(p.contains(additionalTPH)){ inside = true; break; } } - if(! inside)newGenerics.add(new Pair(additionalTPH, additionalTPH)); + if(! inside)newGenerics.add(new GenericInsertPair(additionalTPH, null)); } - /* - //Alle TPHs die man noch als Generics anfügen muss einsetzen: - additionalInserts.clear(); - for(Pair subtypings : newGenerics){ - if(additionalInserts.contains(subtypings.TA1)){ - additionalInserts.remove(subtypings.TA1); - } - } - for(TypePlaceholder tph : additionalInserts){ - newGenerics.add(new Pair(tph, null)); - } - */ ret.add(createGenericInsert(newGenerics, cl, m)); //return ret; @@ -133,7 +121,7 @@ public class TypeInsertFactory { return insert; } - private static TypeInsertPoint createGenericInsert(Set toInsert, ClassOrInterface cl, Method m){ + private static TypeInsertPoint createGenericInsert(Set toInsert, ClassOrInterface cl, Method m){ //Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt: //Offset zum Einstzen bestimmen: Token offset; @@ -151,7 +139,7 @@ public class TypeInsertFactory { //Alle einzusetzenden Generics und deren Bounds bestimmen: HashMap> genericsAndBounds = new HashMap<>(); - for(Pair p : toInsert){ + for(GenericInsertPair p : toInsert){ if(!genericsAndBounds.containsKey(p.TA1)){ genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>()); }