forked from JavaTX/JavaCompilerCore
Einsetzen von Generics korrigieren
This commit is contained in:
parent
c272688b2d
commit
2c25e56a76
@ -96,9 +96,8 @@ public class TypeInsertFactory {
|
|||||||
for(TypePlaceholder tph : additionalInserts){
|
for(TypePlaceholder tph : additionalInserts){
|
||||||
newGenerics.add(new Pair(tph, null));
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -123,21 +122,51 @@ public class TypeInsertFactory {
|
|||||||
return insert;
|
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:
|
//Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt:
|
||||||
|
//Offset zum Einstzen bestimmen:
|
||||||
Token offset;
|
Token offset;
|
||||||
String insert = "";
|
String insert = "";
|
||||||
String end =" ";
|
String end =" ";
|
||||||
if(cl.getGenerics().iterator().hasNext()){
|
if(cl.getGenerics().iterator().hasNext()){
|
||||||
offset = cl.getGenerics().iterator().next().getOffset();
|
offset = cl.getGenerics().iterator().next().getOffset();
|
||||||
|
insert+=",";
|
||||||
}else{
|
}else{
|
||||||
offset = cl.getGenerics().getOffset();
|
offset = cl.getGenerics().getOffset();
|
||||||
insert += "<";
|
insert += "<";
|
||||||
end = ">";
|
end = ">";
|
||||||
}
|
}
|
||||||
insert += tph.getName();
|
|
||||||
if(bound != null){
|
//Alle einzusetzenden Generics und deren Bounds bestimmen:
|
||||||
insert += " extends " + bound.getName();
|
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();
|
||||||
|
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);
|
return new TypeInsertPoint(offset, insert + end);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user