Einsetzen von Generics korrigieren

This commit is contained in:
JanUlrich 2017-06-20 14:50:27 +02:00
parent c272688b2d
commit 2c25e56a76

View File

@ -96,9 +96,8 @@ public class TypeInsertFactory {
for(TypePlaceholder tph : additionalInserts){
newGenerics.add(new Pair(tph, null));
}
for(Pair subtyping : newGenerics){
ret.add(createGenericInsert((TypePlaceholder)subtyping.TA1, (TypePlaceholder)subtyping.TA2, cl, m));
}
ret.add(createGenericInsert(newGenerics, cl, m));
return ret;
}
@ -123,21 +122,51 @@ public class TypeInsertFactory {
return insert;
}
private static TypeInsertPoint createGenericInsert(TypePlaceholder tph, TypePlaceholder bound, ClassOrInterface cl, Method m){
private static TypeInsertPoint createGenericInsert(Set<Pair> toInsert, ClassOrInterface cl, Method m){
//Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt:
//Offset zum Einstzen bestimmen:
Token offset;
String insert = "";
String end =" ";
if(cl.getGenerics().iterator().hasNext()){
offset = cl.getGenerics().iterator().next().getOffset();
insert+=",";
}else{
offset = cl.getGenerics().getOffset();
insert += "<";
end = ">";
}
//Alle einzusetzenden Generics und deren Bounds bestimmen:
HashMap<TypePlaceholder, HashSet<TypePlaceholder>> genericsAndBounds = new HashMap<>();
for(Pair p : toInsert){
if(!genericsAndBounds.containsKey(p.TA1)){
genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>());
}
if(p.TA2 != null){
genericsAndBounds.get(p.TA1).add((TypePlaceholder) p.TA2);
if(!genericsAndBounds.containsKey(p.TA2)){
genericsAndBounds.put((TypePlaceholder) p.TA2, new HashSet<>());
}
}
}
//String zum Einsetzen (Generics mit bounds) generieren:
Iterator<TypePlaceholder> it = genericsAndBounds.keySet().iterator();
while(it.hasNext()){
TypePlaceholder tph = it.next();
insert += tph.getName();
if(bound != null){
insert += " extends " + bound.getName();
Set<TypePlaceholder> bounds = genericsAndBounds.get(tph);
if(bounds.size() > 0){
insert += " extends ";
Iterator<TypePlaceholder> boundIt = bounds.iterator();
while(boundIt.hasNext()){
TypePlaceholder bound = boundIt.next();
insert += bound.getName();
if(boundIt.hasNext())insert += " & ";
}
}
if(it.hasNext())insert+=",";
}
return new TypeInsertPoint(offset, insert + end);
}