forked from JavaTX/JavaCompilerCore
TypeInsert Fehler beheben
This commit is contained in:
parent
1023ed8557
commit
bbc61c67a9
26
src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java
Normal file
26
src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -65,14 +65,14 @@ public class TypeInsertFactory {
|
||||
}
|
||||
|
||||
//Alle Bounds finden:
|
||||
Set<Pair> newGenerics = new HashSet<>();
|
||||
Set<GenericInsertPair> 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<Pair> toInsert, ClassOrInterface cl, Method m){
|
||||
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> 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<TypePlaceholder, HashSet<TypePlaceholder>> genericsAndBounds = new HashMap<>();
|
||||
for(Pair p : toInsert){
|
||||
for(GenericInsertPair p : toInsert){
|
||||
if(!genericsAndBounds.containsKey(p.TA1)){
|
||||
genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user