forked from JavaTX/JavaCompilerCore
Consider nested type variables for signature (usage)
This commit is contained in:
parent
a9f69ead5c
commit
dabe7f269c
@ -72,6 +72,10 @@ public class ASTToTargetAST {
|
|||||||
} else if (type instanceof RefType refType) {
|
} else if (type instanceof RefType refType) {
|
||||||
for (var t : refType.getParaList())
|
for (var t : refType.getParaList())
|
||||||
result.addAll(findTypeVariables(t));
|
result.addAll(findTypeVariables(t));
|
||||||
|
} else if (type instanceof ExtendsWildcardType wildcardType) {
|
||||||
|
result.addAll(findTypeVariables(wildcardType.getInnerType()));
|
||||||
|
} else if (type instanceof SuperWildcardType wildcardType) {
|
||||||
|
result.addAll(findTypeVariables(wildcardType.getInnerType()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -126,7 +130,6 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
HashSet<TypePlaceholder> typeVariables = new HashSet<>();
|
HashSet<TypePlaceholder> typeVariables = new HashSet<>();
|
||||||
HashSet<TypePlaceholder> typeVariablesOfFields = new HashSet<>();
|
HashSet<TypePlaceholder> typeVariablesOfFields = new HashSet<>();
|
||||||
HashSet<TypePlaceholder> typeVariablesOfLocals = new HashSet<>();
|
|
||||||
|
|
||||||
for (var field : owner.getFieldDecl()) {
|
for (var field : owner.getFieldDecl()) {
|
||||||
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
|
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
|
||||||
@ -140,9 +143,7 @@ public class ASTToTargetAST {
|
|||||||
method.block.accept(new TracingStatementVisitor() {
|
method.block.accept(new TracingStatementVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
var tphs = findTypeVariables(localVarDecl.getType());
|
typeVariables.addAll(findTypeVariables(localVarDecl.getType()));
|
||||||
typeVariablesOfLocals.addAll(tphs);
|
|
||||||
typeVariables.addAll(tphs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -463,13 +464,12 @@ public class ASTToTargetAST {
|
|||||||
usedTPHsOfMethods.put(method, typeVariables);
|
usedTPHsOfMethods.put(method, typeVariables);
|
||||||
|
|
||||||
// For eliminating inner type variables we need to figure out which ones are actually used
|
// For eliminating inner type variables we need to figure out which ones are actually used
|
||||||
|
// TODO Maybe don't do this twice?
|
||||||
var typeVariablesOfSignature = new HashSet<TypePlaceholder>();
|
var typeVariablesOfSignature = new HashSet<TypePlaceholder>();
|
||||||
for (var param : method.getParameterList().getFormalparalist()) {
|
for (var param : method.getParameterList().getFormalparalist()) {
|
||||||
if (param.getType() instanceof TypePlaceholder tph)
|
typeVariablesOfSignature.addAll(findTypeVariables(param.getType()));
|
||||||
typeVariablesOfSignature.add(equality.getOrDefault(tph, tph));
|
|
||||||
}
|
}
|
||||||
if (method.getReturnType() instanceof TypePlaceholder tph)
|
typeVariablesOfSignature.addAll(findTypeVariables(method.getReturnType()));
|
||||||
typeVariablesOfSignature.add(equality.getOrDefault(tph, tph));
|
|
||||||
|
|
||||||
eliminateInnerTypeVariables(typeVariablesOfSignature, result);
|
eliminateInnerTypeVariables(typeVariablesOfSignature, result);
|
||||||
System.out.println(method.name + ": " + result);
|
System.out.println(method.name + ": " + result);
|
||||||
|
Loading…
Reference in New Issue
Block a user