Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GenericsChecks methods static #805

Merged
merged 60 commits into from
Aug 16, 2023

Conversation

msridhar
Copy link
Collaborator

Previously, some methods in GenericsChecks were static methods and some were instance methods. We did not get much of any benefit from the instance methods, as it would be painful to create a single GenericsChecks object and thread it everywhere it is needed. So, this PR just converts all GenericsChecks methods to be static and passes parameters as needed (which isn't too painful).

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc nits only, but quite a few of them...

public void checkTypeParameterNullnessForFunctionReturnType(
ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol) {
if (!config.isJSpecifyMode()) {
public static void checkTypeParameterNullnessForFunctionReturnType(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public method, so... javadoc?

@@ -237,7 +239,7 @@ private void reportInvalidOverridingMethodParamTypeError(
* @return Type of the tree with preserved annotations.
*/
@Nullable
private Type getTreeType(Tree tree) {
private static Type getTreeType(Tree tree, VisitorState state) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -267,8 +269,9 @@ private Type getTreeType(Tree tree) {
* @param tree the tree to check, which must be either an {@link AssignmentTree} or a {@link
* VariableTree}
*/
public void checkTypeParameterNullnessForAssignability(Tree tree) {
if (!config.isJSpecifyMode()) {
public static void checkTypeParameterNullnessForAssignability(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -334,7 +340,8 @@ public void checkTypeParameterNullnessForFunctionReturnType(
* @param lhsType type for the lhs of the assignment
* @param rhsType type for the rhs of the assignment
*/
private boolean compareNullabilityAnnotations(Type.ClassType lhsType, Type.ClassType rhsType) {
private static boolean compareNullabilityAnnotations(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -395,7 +402,8 @@ private boolean compareNullabilityAnnotations(Type.ClassType lhsType, Type.Class
* @param tree A parameterized typed tree for which we need class type with preserved annotations.
* @return A Type with preserved annotations.
*/
private Type.ClassType typeWithPreservedAnnotations(ParameterizedTypeTree tree) {
private static Type.ClassType typeWithPreservedAnnotations(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -686,15 +704,20 @@ public static Nullness getGenericReturnNullnessAtInvocation(
* @return Nullness of parameter at {@code paramIndex}, or {@code NONNULL} if the call does not
* invoke an instance method
*/
public Nullness getGenericParameterNullnessAtInvocation(
int paramIndex, Symbol.MethodSymbol invokedMethodSymbol, MethodInvocationTree tree) {
public static Nullness getGenericParameterNullnessAtInvocation(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -726,8 +749,12 @@ public Nullness getGenericParameterNullnessAtInvocation(
* @return nullability of the relevant parameter type of {@code method} in the context of {@code
* enclosingType}
*/
public Nullness getGenericMethodParameterNullness(
int parameterIndex, Symbol.MethodSymbol method, Type enclosingType) {
public static Nullness getGenericMethodParameterNullness(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -741,8 +768,8 @@ public Nullness getGenericMethodParameterNullness(
* @param tree tree for overriding method
* @param overriddenMethodType type of the overridden method
*/
private void checkTypeParameterNullnessForOverridingMethodParameterType(
MethodTree tree, Type overriddenMethodType) {
private static void checkTypeParameterNullnessForOverridingMethodParameterType(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -771,18 +801,20 @@ private void checkTypeParameterNullnessForOverridingMethodParameterType(
* @param tree tree for overriding method
* @param overriddenMethodType type of the overridden method
*/
private void checkTypeParameterNullnessForOverridingMethodReturnType(
MethodTree tree, Type overriddenMethodType) {
private static void checkTypeParameterNullnessForOverridingMethodReturnType(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs to be updated with the new @params.

@@ -2414,6 +2413,10 @@ public ErrorBuilder getErrorBuilder() {
return errorBuilder;
}

public Config getConfig() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if this is unbelievably pedantic but: public method -> javadoc 😅 (Also, as a getter, maybe worth moving further up within this file? Closer to the field unless that breaks GJF rules?)

@msridhar
Copy link
Collaborator Author

Thanks for helping keep our docs in a decent shape 🙂 @lazaroclapp this is ready for another look when you can

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@msridhar msridhar merged commit 540eaa9 into uber:master Aug 16, 2023
7 checks passed
@msridhar msridhar deleted the make-generics-checks-methods-static branch August 16, 2023 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants