Generische Parameter einsetzen (nur Test, nicht korrekt eingesetzt)

This commit is contained in:
JanUlrich 2017-06-15 04:48:53 +02:00
parent 920eea43ad
commit cf6d9880e3
4 changed files with 45 additions and 8 deletions

View File

@ -64,7 +64,6 @@ public class JavaTXCompiler {
System.out.println("RESULT: " + result);
results.addAll(result);
}
//TODO: Hier läuft irgendwas gewaltig schief:
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
}

View File

@ -269,9 +269,7 @@ public class SyntaxTreeGenerator{
Token offset = ctx.getStart();
GenericDeclarationList genericClassParameters;
if(ctx.typeParameters() == null){
CommonToken gtvOffset = new CommonToken(ctx.Identifier().getSymbol());
gtvOffset.setCharPositionInLine(gtvOffset.getCharPositionInLine()+ctx.Identifier().getText().length());
genericClassParameters = new GenericDeclarationList(new ArrayList<>(), gtvOffset);
genericClassParameters = createEmptyGenericDeclarationList(ctx.Identifier());
}else{
genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
}
@ -479,9 +477,7 @@ public class SyntaxTreeGenerator{
if(ctx.typeParameters() != null){
genericParams = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
}else{
CommonToken gtvOffset = new CommonToken(ctx.Identifier().getSymbol());
gtvOffset.setCharPositionInLine(gtvOffset.getCharPositionInLine()+ctx.Identifier().getText().length());
genericParams = new GenericDeclarationList(new ArrayList<>(), gtvOffset);
genericParams = createEmptyGenericDeclarationList(ctx.Identifier());
}
RefType superClass = new ASTFactory(reg).createObjectClass().getType();
@ -491,6 +487,13 @@ public class SyntaxTreeGenerator{
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
}
private GenericDeclarationList createEmptyGenericDeclarationList(TerminalNode classNameIdentifier) {
CommonToken gtvOffset = new CommonToken(classNameIdentifier.getSymbol());
gtvOffset.setCharPositionInLine(gtvOffset.getCharPositionInLine()+classNameIdentifier.getText().length());
gtvOffset.setStartIndex(gtvOffset.getStopIndex()+1);
return new GenericDeclarationList(new ArrayList<>(), gtvOffset);
}
private GenericsRegistry createGenerics(Java8Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod) {
GenericsRegistry ret = new GenericsRegistry();
if(ctx == null || ctx.typeParameterList() == null)return ret;

View File

@ -173,6 +173,7 @@ public class UnifyTypeFactory {
TypePlaceholder ret = tphs.get(t.getName());
if(ret == null){ //Dieser TPH wurde vom Unifikationsalgorithmus erstellt
ret = TypePlaceholder.fresh(new NullToken());
tphs.put(t.getName(), ret);
}
return ret;
}

View File

@ -72,8 +72,42 @@ public class TypeInsertFactory {
}
}
}
//Alle Bounds finden:
Map<TypePlaceholder, TypePlaceholder> newGenerics = new HashMap<>();
Set<TypePlaceholder> additionalBoundInserts = new HashSet<>();
boolean added = true;
while(added){
added = false;
additionalInserts.addAll(additionalBoundInserts);
for(TypePlaceholder tph : additionalInserts){
boolean foundPair = false;
for(Pair pair : pairs){
if (pair.TA1.equals(tph) || pair.TA2.equals(tph)) {
newGenerics.put((TypePlaceholder) pair.TA1, (TypePlaceholder) pair.TA2);
foundPair = true;
added |= additionalBoundInserts.add((TypePlaceholder) pair.TA1);
added |= additionalBoundInserts.add((TypePlaceholder) pair.TA2);
}
}
if(foundPair == false){
newGenerics.put(tph, null);
}
}
}
//Alle TPHs die man noch als Generics anfügen muss einsetzen:
//TODO
additionalInserts.clear();
for(TypePlaceholder tph : newGenerics.values()){
if(! newGenerics.containsKey(tph)){
additionalInserts.add(tph);
}
}
for(TypePlaceholder tph : additionalInserts){
newGenerics.put(tph, null);
}
for(TypePlaceholder tph : newGenerics.keySet()){
ret.add(createGenericInsert(tph, newGenerics.get(tph), cl, m));
}
return ret;
}