Skip to content

Commit

Permalink
renaming and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Mar 22, 2024
1 parent 96d057f commit cad63a0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
import com.uber.nullaway.dataflow.AccessPathNullnessAnalysis;
import com.uber.nullaway.dataflow.NullnessStore;
import com.uber.nullaway.handlers.stream.CollectlikeMethodRecord;
import com.uber.nullaway.handlers.stream.MapOrCollectLikeMethodRecord;
import com.uber.nullaway.handlers.stream.MapOrCollectMethodToFilterInstanceRecord;
import com.uber.nullaway.handlers.stream.MaplikeMethodRecord;
import com.uber.nullaway.handlers.stream.StreamMethodRecord;
import com.uber.nullaway.handlers.stream.StreamMethodToFilterInstanceRecord;
import com.uber.nullaway.handlers.stream.StreamTypeRecord;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -123,7 +123,7 @@ class StreamNullabilityPropagator extends BaseNoOpHandler {

// Map from map method (or lambda) to corresponding previous filter method (e.g. B.apply =>
// A.filter)
private final Map<Tree, StreamMethodToFilterInstanceRecord> streamRecordToFilterMap =
private final Map<Tree, MapOrCollectMethodToFilterInstanceRecord> streamRecordToFilterMap =
new LinkedHashMap<>();

/*
Expand Down Expand Up @@ -301,8 +301,8 @@ private void handleChainFromFilter(
// Update mapToFilterMap
Symbol.MethodSymbol mapMethod = ASTHelpers.getSymbol(outerCallInChain);
if (streamType.isMapMethod(mapMethod)) {
StreamMethodToFilterInstanceRecord record =
new StreamMethodToFilterInstanceRecord(
MapOrCollectMethodToFilterInstanceRecord record =
new MapOrCollectMethodToFilterInstanceRecord(
streamType.getMaplikeMethodRecord(mapMethod), filterMethodOrLambda);
streamRecordToFilterMap.put(
observableCallToInnerMethodOrLambda.get(outerCallInChain), record);
Expand All @@ -315,8 +315,8 @@ private void handleChainFromFilter(
if (collectlikeMethodRecord != null) {
for (Tree innerMethodOrLambda :
collectCallToInnerMethodsOrLambdas.get(outerCallInChain)) {
StreamMethodToFilterInstanceRecord record =
new StreamMethodToFilterInstanceRecord(
MapOrCollectMethodToFilterInstanceRecord record =
new MapOrCollectMethodToFilterInstanceRecord(
collectlikeMethodRecord, filterMethodOrLambda);
streamRecordToFilterMap.put(innerMethodOrLambda, record);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private void handleFilterLambda(
}

private void handleMapOrCollectAnonClass(
StreamMethodRecord methodRecord, ClassTree anonClassBody, Consumer<Tree> consumer) {
MapOrCollectLikeMethodRecord methodRecord, ClassTree anonClassBody, Consumer<Tree> consumer) {
for (Tree t : anonClassBody.getMembers()) {
if (t instanceof MethodTree
&& ((MethodTree) t).getName().toString().equals(methodRecord.innerMethodName())) {
Expand Down Expand Up @@ -394,7 +394,7 @@ public void onMatchMethodReference(
MemberReferenceTree tree,
VisitorState state,
Symbol.MethodSymbol methodSymbol) {
StreamMethodToFilterInstanceRecord callInstanceRecord = streamRecordToFilterMap.get(tree);
MapOrCollectMethodToFilterInstanceRecord callInstanceRecord = streamRecordToFilterMap.get(tree);
if (callInstanceRecord != null && ((JCTree.JCMemberReference) tree).kind.isUnbound()) {
// Unbound method reference, check if we know the corresponding path to be NonNull from the
// previous filter.
Expand Down Expand Up @@ -490,13 +490,14 @@ public NullnessStore.Builder onDataflowInitialStore(
return nullnessBuilder;
}
assert (tree instanceof MethodTree || tree instanceof LambdaExpressionTree);
StreamMethodToFilterInstanceRecord callInstanceRecord = streamRecordToFilterMap.get(tree);
MapOrCollectMethodToFilterInstanceRecord callInstanceRecord = streamRecordToFilterMap.get(tree);
if (callInstanceRecord != null) {
// Plug Nullness info from filter method into entry to map method.
Tree filterTree = callInstanceRecord.getFilter();
assert (filterTree instanceof MethodTree || filterTree instanceof LambdaExpressionTree);
StreamMethodRecord mapMR = callInstanceRecord.getMaplikeMethodRecord();
for (int argIdx : mapMR.argsFromStream()) {
MapOrCollectLikeMethodRecord methodRecord =
callInstanceRecord.getMapOrCollectLikeMethodRecord();
for (int argIdx : methodRecord.argsFromStream()) {
LocalVariableNode filterLocalName;
LocalVariableNode mapLocalName;
if (filterTree instanceof MethodTree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* java.util.stream.Stream#collect(Collector)}.
*/
@AutoValue
public abstract class CollectlikeMethodRecord implements StreamMethodRecord {
public abstract class CollectlikeMethodRecord implements MapOrCollectLikeMethodRecord {

public static CollectlikeMethodRecord create(
String collectorFactoryMethodClass,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.uber.nullaway.handlers.stream;

import com.google.common.collect.ImmutableSet;

/** Common information needed for map-like and collect-like stream methods. */
public interface MapOrCollectLikeMethodRecord {

/** Name of the method that gets passed the elements of the stream */
String innerMethodName();

/** Indices of the arguments to the inner method that are passed the elements of the stream */
ImmutableSet<Integer> argsFromStream();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
* Internal bookeeping record that keeps track of the model of a map-like method and the previous
* filter method's inner method tree. See RxNullabilityPropagator documentation and diagram.
*/
public class StreamMethodToFilterInstanceRecord {
public class MapOrCollectMethodToFilterInstanceRecord {

private final StreamMethodRecord mapMR;
private final MapOrCollectLikeMethodRecord methodRecord;

public StreamMethodRecord getMaplikeMethodRecord() {
return mapMR;
public MapOrCollectLikeMethodRecord getMapOrCollectLikeMethodRecord() {
return methodRecord;
}

private final Tree filter;
Expand All @@ -43,9 +43,10 @@ public Tree getFilter() {
return filter;
}

public StreamMethodToFilterInstanceRecord(StreamMethodRecord mapMR, Tree filter) {
public MapOrCollectMethodToFilterInstanceRecord(
MapOrCollectLikeMethodRecord methodRecord, Tree filter) {
assert (filter instanceof MethodTree || filter instanceof LambdaExpressionTree);
this.mapMR = mapMR;
this.methodRecord = methodRecord;
this.filter = filter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.common.collect.ImmutableSet;

/** An immutable model describing a map-like method from a stream-based API such as RxJava. */
public class MaplikeMethodRecord implements StreamMethodRecord {
public class MaplikeMethodRecord implements MapOrCollectLikeMethodRecord {

private final String innerMethodName;

Expand Down

This file was deleted.

0 comments on commit cad63a0

Please sign in to comment.