auto-matter
auto-matter copied to clipboard
Don't emit `@SafeVarargs` for reifiable types
Attempt to detect if a type is reifiable, and omit the annotation in those cases.
https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html
However one problem as noted in the comments is we can't get at a
ParameterizedTypeName's enclosing type. So for instance, this code will
treat Foo<X>.Bar
as reifiable, even though it isn't.
One idea to get around it would be to toString()
the type and check if
it contains any type parameters, although that seems kinda messy.
Hi! Giving a look at how java.util.List.of()
is implemented, could we just do the same that they do and generate always the following?
@SafeVarargs
@SuppressWarnings("varargs")
~~@lepistone That indeed seems like a simpler approach. 👍~~
Would using @SuppressWarnings("varargs")
help in this case though? Adding it to a method with a reifiable vararg parameter does not seem to make IntelliJ happier about the method.
Javac with -Xlint:all
does not emit any warning about @SafeVarargs
either way. Is there some static analysis tool that does complain (other than IntelliJ)?
@danielnorberg in my case, with Java 11, Javac with -Xlint:all
does emit warnings, and auto-matter is the only reason why I have to pass -XLint:-varargs
to maven-compiler-plugin
. So this is not about intelliJ. I wonder why I get this warning and you don't.
@lepistone Indeed. I had simply failed to enable showWarnings
.
https://github.com/danielnorberg/auto-matter/pull/72
Although the @SuppressWarnings("varargs")
has been released in 0.15.3
, I guess it could still be neat to avoid both @SafeVarargs
and @SuppressWarnings
in code generated for reifiable types.
@bndbsh I attempted to handle nested types here, please take a look: https://github.com/mninja/auto-matter/pull/1