Skip to content

Commit

Permalink
Treat expressions ending in .toBuilder() as a syntactic unit
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=237907460
  • Loading branch information
cushon committed Apr 3, 2019
1 parent 6b57fbf commit a24c9b6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Expand Up @@ -1553,18 +1553,20 @@ private boolean handleLogStatement(MethodInvocationTree node) {
"withCause",
"withStackTrace");

private static Optional<Long> handleStream(List<ExpressionTree> parts) {
return indexIn(
private static Stream<Long> handleStream(List<ExpressionTree> parts) {
return indexes(
parts.stream(),
p ->
(p instanceof MethodInvocationTree)
&& getMethodName((MethodInvocationTree) p).contentEquals("stream"));
p -> {
if (!(p instanceof MethodInvocationTree)) {
return false;
}
Name name = getMethodName((MethodInvocationTree) p);
return Stream.of("stream", "toBuilder").anyMatch(name::contentEquals);
});
}

private static <T> Optional<Long> indexIn(Stream<T> stream, Predicate<T> predicate) {
return Streams.mapWithIndex(stream, (x, i) -> predicate.apply(x) ? i : -1)
.filter(x -> x != -1)
.findFirst();
private static <T> Stream<Long> indexes(Stream<T> stream, Predicate<T> predicate) {
return Streams.mapWithIndex(stream, (x, i) -> predicate.apply(x) ? i : -1).filter(x -> x != -1);
}

@Override
Expand Down Expand Up @@ -2687,7 +2689,7 @@ void visitDot(ExpressionTree node0) {
}
}

handleStream(items).ifPresent(x -> prefixes.add(x.intValue()));
handleStream(items).forEach(x -> prefixes.add(x.intValue()));

if (!prefixes.isEmpty()) {
visitDotWithPrefix(items, needDot, prefixes);
Expand Down
@@ -0,0 +1,12 @@
class B112853497 {
{
XxxxxxxxxxXxxx xxxXxxxx =
xxxXxxxx
.xxxxXxXxxxx(xxxxXxxx, XXXXXX_XXXX_XXXXXXXX_XX_XXXXXXXX)
.toBuilder()
.xxxXxxxxXxxxXx(xxxxxXx.xxxXxxxxXxxxXx())
.xxxXxxxxXxxxXx(xxxxxXx.xxxXxxxxXxxxXx())
.xxxXxxxxx(xxxxxx.xxxXxxxxxXxxx())
.xxxxx();
}
}
@@ -0,0 +1,10 @@
class B112853497 {
{
XxxxxxxxxxXxxx xxxXxxxx =
xxxXxxxx.xxxxXxXxxxx(xxxxXxxx, XXXXXX_XXXX_XXXXXXXX_XX_XXXXXXXX).toBuilder()
.xxxXxxxxXxxxXx(xxxxxXx.xxxXxxxxXxxxXx())
.xxxXxxxxXxxxXx(xxxxxXx.xxxXxxxxXxxxXx())
.xxxXxxxxx(xxxxxx.xxxXxxxxxXxxx())
.xxxxx();
}
}
@@ -1,8 +1,7 @@
class B26928842 {
{
curr.setData(
curr.getData()
.toBuilder()
curr.getData().toBuilder()
.setPushCertificate( // New
curr.getData().getPushCertficate()) // Old, misspelled
.clearPushCertficate() // Old, misspelled
Expand Down

0 comments on commit a24c9b6

Please sign in to comment.