Refaster support for varargs methods
See original GitHub issueI tried to write a Refaster rule for callers of some internal library method M which has a signature that matches String#format(String, Object...)
. The idea is to identify callers which explicitly call String.format
before invoking M and to rewrite those expressions to defer the formatting to M. But nothing happened.
This appears to be because of the use of varargs. As a test I tried to apply the following dummy Refaster template to our code base, but that didn’t do anything either:
final class VarargsRefasterTemplate {
@BeforeTemplate
String before(final String format, final Object... args) {
return String.format(format, args);
}
@AfterTemplate
String after(final String format, final Object... args) {
return "This is a test";
}
}
Would it be possible to support varargs?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Refaster (Error Prone parent POM HEAD-SNAPSHOT API)
Indicates that Refaster should treat this @Repeated argument specifically as a varargs argument. For example, you might write
Read more >How to refactor code with varargs - put to map - Stack Overflow
Simple answer. You're doing it wrong. This stuff already exists; use e.g. guava's ImmutableMap.builder , or use the existing Map.of() .
Read more >Variable argument and Varargs methods in Java with Example
Variable argument or varargs in Java allows you to write more flexible methods which can accept as many arguments as you need. variable...
Read more >Log - HEAD - external/guava-libraries - Git at Google
EMPTY_ENTRY_ARRAY in other ImmutableMap types by Chris Povirk · 8 years ago; 8aa58da Eliminate varargs-accepting create() method, which was never called ...
Read more >The jOOQ Release Note History
Names unquoted. #9825, Document new jOOQ-refaster module. #9833, Add missing @Support annotation to DSLContext#fetch*() methods.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is supported, just not in a super well documented way, I think?
Write
@BeforeTemplate String before(String format, @Repeated Object arg)
.@Repeated
is slightly more general, though; it can be interspersed with normal arguments, put in an array declaration, and generally stand in for any comma repeated expression.When writing a Refaster template for a method with a varargs parameter, I currently always need to specify at least two templates: one for call sites using varargs and one for call sites using explicit arrays. Could Refaster simplify this use case?