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

Create com.uber.nullaway.generics package #855

Merged
merged 2 commits into from Nov 15, 2023

Conversation

msridhar
Copy link
Collaborator

@msridhar msridhar commented Nov 5, 2023

Fixes #817. This is a refactoring with no semantic changes.

@msridhar msridhar requested a review from yuxincs November 5, 2023 16:36
@msridhar msridhar enabled auto-merge (squash) November 5, 2023 16:37
Copy link

codecov bot commented Nov 5, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (4af912d) 86.95% compared to head (5a4654b) 86.95%.

Files Patch % Lines
...r/nullaway/generics/CompareNullabilityVisitor.java 77.77% 4 Missing and 4 partials ⚠️
...way/generics/GenericTypePrettyPrintingVisitor.java 77.77% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #855      +/-   ##
============================================
- Coverage     86.95%   86.95%   -0.01%     
- Complexity     1890     1919      +29     
============================================
  Files            74       77       +3     
  Lines          6216     6215       -1     
  Branches       1209     1209              
============================================
- Hits           5405     5404       -1     
  Misses          405      405              
  Partials        406      406              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@msridhar
Copy link
Collaborator Author

msridhar commented Nov 5, 2023

There is no reduction in code coverage due to this PR; it's just @codecov getting a bit confused since code is moving around into new files.

Copy link
Collaborator

@yuxincs yuxincs left a comment

Choose a reason for hiding this comment

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

Refactors LGTM :) Just had a question due to my unfamiliarity with the rest of the codebase

@@ -92,7 +92,7 @@ public class ErrorBuilder {
* expression into a @NonNull target, and this parameter is the Symbol for that target.
* @return the error description
*/
Description createErrorDescription(
public Description createErrorDescription(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this is for future uses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is because the PR moves the generics code into its own new package, so it cannot see this method anymore (default visibility for Java methods is "package private").

Comment on lines +10 to +11
* Visitor that checks equality of nullability annotations for all nested generic type arguments
* within a type. Compares the Type it is called upon, i.e. the LHS type and the Type passed as an
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 the only part that got updated, where the rest of the code is copied verbatim from the original file.

Makes sense to me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, exactly, we extracted this nested class to a new source file

* <p>This code is a modified and extended version of code in {@link
* com.google.errorprone.util.Signatures}
*/
final class GenericTypePrettyPrintingVisitor extends Types.DefaultTypeVisitor<String, Void> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, I think this is strictly extracting code from the original file. LGTM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, no code changes, just moving code to a top-level source file

Comment on lines +41 to +43
static final String NULLABLE_NAME = "org.jspecify.annotations.Nullable";

private static final Supplier<Type> NULLABLE_TYPE_SUPPLIER =
Suppliers.typeFromString(NULLABLE_NAME);
static final Supplier<Type> NULLABLE_TYPE_SUPPLIER = Suppliers.typeFromString(NULLABLE_NAME);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be me not too familiar with the rest of the codebase, but shouldn't these two actually be shared across NullAway?

Also, I think NullAway supports more than one nullable type suppliers, so this confuses me a little (that we should just rely on whatever set of suppliers we already have in the rest of NullAway instead of defining it again here)

But I think I'm missing something 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So this code is about getting a Type object for org.jspecify.annotations.Nullable. Some code in this file specifically checks for @org.jspecify.annotations.Nullable annotations, and only implements JSpecify behavior if that exact annotation is present. This was to be conservative; I think it's still an open question as to how we will handle other type use annotations and also declaration annotations (see #853). I will rename these variables and add some comments to indicate what is going on here.

And, BTW, the reason we code in this manner is to avoid comparing Types by their String representation, see this Error Prone check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I'll do those changes in a follow up to keep this PR simple

@msridhar msridhar merged commit 60648a9 into uber:master Nov 15, 2023
8 of 10 checks passed
@msridhar msridhar deleted the generics-package branch November 15, 2023 01:32
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.

Create a new com.uber.nullaway.generics package with generics-checking-related code
2 participants