Skip to content

Commit

Permalink
minor cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Nov 13, 2024
1 parent 3f3ebf2 commit 2a8512e
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ public static void compareGenericTypeParameterNullabilityForCall(
return;
}
Type invokedMethodType = methodSymbol.type;
// substitute class-level type arguments for instance methods
if (!methodSymbol.isStatic() && tree instanceof MethodInvocationTree) {
ExpressionTree methodSelect = ((MethodInvocationTree) tree).getMethodSelect();
Type enclosingType;
Expand All @@ -626,10 +627,10 @@ public static void compareGenericTypeParameterNullabilityForCall(
invokedMethodType = state.getTypes().memberType(enclosingType, methodSymbol);
}
}
// Handle generic methods
// substitute type arguments for generic methods
if (tree instanceof MethodInvocationTree && methodSymbol.type instanceof Type.ForAll) {
invokedMethodType =
substituteGenericTypeArgsToExplicit((MethodInvocationTree) tree, methodSymbol, state);
substituteTypeArgsInGenericMethodType((MethodInvocationTree) tree, methodSymbol, state);
}
List<Type> formalParamTypes = invokedMethodType.getParameterTypes();
int n = formalParamTypes.size();
Expand Down Expand Up @@ -820,7 +821,7 @@ public static Nullness getGenericReturnNullnessAtInvocation(
if (!invokedMethodSymbol.getTypeParameters().isEmpty()) {
// Substitute type arguments inside the return type
Type substitutedReturnType =
substituteGenericTypeArgsToExplicit(tree, invokedMethodSymbol, state).getReturnType();
substituteTypeArgsInGenericMethodType(tree, invokedMethodSymbol, state).getReturnType();
// If this condition evaluates to false, we fall through to the subsequent logic, to handle
// type variables declared on the enclosing class
if (substitutedReturnType != null
Expand Down Expand Up @@ -854,11 +855,18 @@ private static com.sun.tools.javac.util.List<Type> convertTreesToTypes(
return com.sun.tools.javac.util.List.from(types);
}

private static Type substituteGenericTypeArgsToExplicit(
MethodInvocationTree methodInvocationTreetree,
/**
* Substitutes the type arguments from a generic method invocation into the method's type.
*
* @param methodInvocationTree the method invocation tree
* @param methodSymbol symbol for the invoked generic method
* @param state the visitor state
* @return the substituted method type for the generic method
*/
private static Type substituteTypeArgsInGenericMethodType(
MethodInvocationTree methodInvocationTree,
Symbol.MethodSymbol methodSymbol,
VisitorState state) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) methodInvocationTreetree;

List<? extends Tree> typeArgumentTrees = methodInvocationTree.getTypeArguments();
com.sun.tools.javac.util.List<Type> explicitTypeArgs = convertTreesToTypes(typeArgumentTrees);
Expand Down Expand Up @@ -913,7 +921,8 @@ public static Nullness getGenericParameterNullnessAtInvocation(
// Substitute the argument types within the MethodType
// NOTE: if explicitTypeArgs is empty, this is a noop
List<Type> substitutedParamTypes =
substituteGenericTypeArgsToExplicit(tree, invokedMethodSymbol, state).getParameterTypes();
substituteTypeArgsInGenericMethodType(tree, invokedMethodSymbol, state)
.getParameterTypes();
// If this condition evaluates to false, we fall through to the subsequent logic, to handle
// type variables declared on the enclosing class
if (substitutedParamTypes != null
Expand Down

0 comments on commit 2a8512e

Please sign in to comment.