Refaster with multiple @AfterTemplates

53 views
Skip to first unread message

Rick Ossendrijver

unread,
Jun 2, 2021, 6:55:39 AM6/2/21
to error-prone-discuss
We were looking into Refaster and saw the following in RefasterRule.java:
`abstract ImmutableList<T> afterTemplates();`

The code base does not appear to contain any example templates containing two @AfterTemplate methods.
Can you tell us whether this is actually being used by Google internally?
We were wondering what the use case would be for this.
If it is being used, could you perhaps provide an example?         
                                                                                          

Chris Povirk

unread,
Jun 2, 2021, 3:34:59 PM6/2/21
to error-pro...@googlegroups.com
We use it when we offer suggested fixes in our code-review tool.

Some examples:

1.

      if (map.get(key) == null) {
        map.put(key, function(key));
      }

->

      map.putIfAbsent(key, function(key));

or, because `function` might be expensive, we also suggest...

      map.computeIfAbsent(key, (K k) -> function(k));

2. String.equalsIgnoreCase is not i18n-correct, so we suggest either Ascii.equalsIgnoreCase (to be explicit about lack of i18n and maybe to avoid dependence on the default locale??) or a more complex, i18n-correct alternative.

3. String.getBytes() uses the system default charset. We suggest either specifying "use the default charset" (to make that dependency explicit) or else using UTF-8.

Rick Ossendrijver

unread,
Jun 5, 2021, 4:39:24 AM6/5/21
to error-prone-discuss
Hi Chris,

Thanks for the quick response and the examples.

Have a nice weekend !

Op woensdag 2 juni 2021 om 21:34:59 UTC+2 schreef Chris Povirk:
Reply all
Reply to author
Forward
0 new messages