forked from JavaTX/JavaCompilerCore
Generische Parameter einsetzen (nur Test, nicht korrekt eingesetzt)
This commit is contained in:
parent
920eea43ad
commit
cf6d9880e3
@ -64,7 +64,6 @@ public class JavaTXCompiler {
|
|||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
//TODO: Hier läuft irgendwas gewaltig schief:
|
|
||||||
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
|
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,9 +269,7 @@ public class SyntaxTreeGenerator{
|
|||||||
Token offset = ctx.getStart();
|
Token offset = ctx.getStart();
|
||||||
GenericDeclarationList genericClassParameters;
|
GenericDeclarationList genericClassParameters;
|
||||||
if(ctx.typeParameters() == null){
|
if(ctx.typeParameters() == null){
|
||||||
CommonToken gtvOffset = new CommonToken(ctx.Identifier().getSymbol());
|
genericClassParameters = createEmptyGenericDeclarationList(ctx.Identifier());
|
||||||
gtvOffset.setCharPositionInLine(gtvOffset.getCharPositionInLine()+ctx.Identifier().getText().length());
|
|
||||||
genericClassParameters = new GenericDeclarationList(new ArrayList<>(), gtvOffset);
|
|
||||||
}else{
|
}else{
|
||||||
genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||||
}
|
}
|
||||||
@ -479,9 +477,7 @@ public class SyntaxTreeGenerator{
|
|||||||
if(ctx.typeParameters() != null){
|
if(ctx.typeParameters() != null){
|
||||||
genericParams = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
genericParams = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||||
}else{
|
}else{
|
||||||
CommonToken gtvOffset = new CommonToken(ctx.Identifier().getSymbol());
|
genericParams = createEmptyGenericDeclarationList(ctx.Identifier());
|
||||||
gtvOffset.setCharPositionInLine(gtvOffset.getCharPositionInLine()+ctx.Identifier().getText().length());
|
|
||||||
genericParams = new GenericDeclarationList(new ArrayList<>(), gtvOffset);
|
|
||||||
}
|
}
|
||||||
RefType superClass = new ASTFactory(reg).createObjectClass().getType();
|
RefType superClass = new ASTFactory(reg).createObjectClass().getType();
|
||||||
|
|
||||||
@ -491,6 +487,13 @@ public class SyntaxTreeGenerator{
|
|||||||
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
|
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) {
|
private GenericsRegistry createGenerics(Java8Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod) {
|
||||||
GenericsRegistry ret = new GenericsRegistry();
|
GenericsRegistry ret = new GenericsRegistry();
|
||||||
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||||
|
@ -173,6 +173,7 @@ public class UnifyTypeFactory {
|
|||||||
TypePlaceholder ret = tphs.get(t.getName());
|
TypePlaceholder ret = tphs.get(t.getName());
|
||||||
if(ret == null){ //Dieser TPH wurde vom Unifikationsalgorithmus erstellt
|
if(ret == null){ //Dieser TPH wurde vom Unifikationsalgorithmus erstellt
|
||||||
ret = TypePlaceholder.fresh(new NullToken());
|
ret = TypePlaceholder.fresh(new NullToken());
|
||||||
|
tphs.put(t.getName(), ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -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:
|
//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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user