Skip to content

Commit

Permalink
Fix review comments and design
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaroclapp committed Aug 21, 2023
1 parent 8e84507 commit 1b4c6fe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public static Handler buildDefault(Config config) {
handlerListBuilder.add(libraryModelsHandler);
handlerListBuilder.add(StreamNullabilityPropagatorFactory.getRxStreamNullabilityPropagator());
handlerListBuilder.add(StreamNullabilityPropagatorFactory.getJavaStreamNullabilityPropagator());
handlerListBuilder.add(libraryModelsHandler.getStreamNullabilityPropagatorFromModels());
handlerListBuilder.add(
StreamNullabilityPropagatorFactory.fromSpecs(
libraryModelsHandler.getStreamNullabilitySpecs()));
handlerListBuilder.add(new ContractHandler(config));
handlerListBuilder.add(new ApacheThriftIsSetHandler());
handlerListBuilder.add(new GrpcHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,22 @@ private void setUnconditionalArgumentNullness(
}

/**
* Generate a StreamNullabilityPropagator handler based on all the stream specifications loaded
* from any of our library models.
* Get all the stream specifications loaded from any of our library models.
*
* <p>This handler must be registered in Handlers.java separatedly from the LibraryModelsHandler
* itself.
* <p>This is used in Handlers.java to create a StreamNullabilityPropagator handler, which gets
* registered independently of this LibraryModelsHandler itself.
*
* <p>LibraryModelsHandler is responsible from reading the library models for stream specs, but
* beyond that, checking of the specs falls under the responsibility of the generated
* StreamNullabilityPropagator handler.
*
* @return The list of all stream specifications loaded from any of our library models.
*/
public StreamNullabilityPropagator getStreamNullabilityPropagatorFromModels() {
public ImmutableList<StreamTypeRecord> getStreamNullabilitySpecs() {
// Note: Currently, OptimizedLibraryModels doesn't carry the information about stream type
// records,
// it is not clear what it means to "optimize" lookup for those and they get access only once:
// here.
return new StreamNullabilityPropagator(libraryModels.customStreamNullabilitySpecs());
// records, it is not clear what it means to "optimize" lookup for those and they get accessed
// only once by calling this method during handler setup in Handlers.java.
return libraryModels.customStreamNullabilitySpecs();
}

private static LibraryModels loadLibraryModels(Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.uber.nullaway.handlers.stream.StreamTypeRecord;

public class StreamNullabilityPropagatorFactory {

/** Returns a handler for the standard Java 8 stream APIs. */
public static StreamNullabilityPropagator getJavaStreamNullabilityPropagator() {
ImmutableList<StreamTypeRecord> streamModels =
StreamModelBuilder.start()
Expand Down Expand Up @@ -78,6 +80,7 @@ public static StreamNullabilityPropagator getJavaStreamNullabilityPropagator() {
return new StreamNullabilityPropagator(streamModels);
}

/** Returns a handler for io.reactivex.* stream APIs */
public static StreamNullabilityPropagator getRxStreamNullabilityPropagator() {
ImmutableList<StreamTypeRecord> rxModels =
StreamModelBuilder.start()
Expand Down Expand Up @@ -137,4 +140,19 @@ public static StreamNullabilityPropagator getRxStreamNullabilityPropagator() {

return new StreamNullabilityPropagator(rxModels);
}

/**
* Create a new StreamNullabilityPropagator from a list of StreamTypeRecord specs.
*
* <p>This is used to create a new StreamNullabilityPropagator based on stream API specs provided
* by library models.
*
* @param streamNullabilitySpecs the list of StreamTypeRecord objects defining one or more stream
* APIs (from {@link StreamModelBuilder}).
* @return A handler corresponding to the stream APIs defined by the given specs.
*/
public static StreamNullabilityPropagator fromSpecs(
ImmutableList<StreamTypeRecord> streamNullabilitySpecs) {
return new StreamNullabilityPropagator(streamNullabilitySpecs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public StreamModelBuilder addStreamType(TypePredicate tp) {
return this;
}

/**
* Add a stream type to our models based on the type's fully qualified name.
*
* @param fullyQualifiedName the FQN of the class/interface in our stream-based API.
* @return This builder (for chaining).
*/
public StreamModelBuilder addStreamTypeFromName(String fullyQualifiedName) {
return this.addStreamType(new DescendantOf(Suppliers.typeFromString(fullyQualifiedName)));
}
Expand Down

0 comments on commit 1b4c6fe

Please sign in to comment.