Implement all checks for kinds of type references
Currently still missing are references in:
- [x] method return values
- [x] (nested) type arguments
- [x] constructor calls
- [x] super-class and implemented interfaces
- [x] annotations
- [x] annotation parameters
- [x] assignments to Class variables (
Class<?> cls = InvalidAcess.class) - [ ] unused "named" import (com.foo.bar)
- [x] import "on demand" (com.foo.*)
- [x] usages of qualified Types without importing it (eg
private other.Bar bar) - [x] a static method call on an imported type:
Bar.bar()(interestingly it is, if the type is not imported and the invocation isother.Bar.bar()) - [x] accessing static fields (String s =
Bar.BAR); - [x] Class literals:
foo(Bar.class); - [x] Generic bounds:
Class<? extends Bar> clazz = null; - [x] Class literal in annotation:
@MyAnno(Bar.class) - [ ] Parameters of lambda expressions:
v -> { } - [ ] Local inferred variables:
var s = getSomething()
@nilshartmann FYI, logged this issue for completing the detection logic in the visitor.
I've already expanded the BasicPluginTest to cover the ones above except the super-type ones (commented out the assertions for now).
ok, I'll merge with my tests and push my work-in-progress state
Thanks, @nilshartmann!
@nilshartmann Just noticed some more situation where no error is raised:
- a static method call on an imported type:
Bar.bar()(interestingly it is, if the type is not imported and the invocation isother.Bar.bar()) - accessing static fields (String s =
Bar.BAR); - Class literals:
foo(Bar.class); - Generic bounds:
Class<? extends Bar> clazz = null; - Class literal in annotation:
@MyAnno(Bar.class)
I'll have a look!
@nilshartmann, added two more cases to the check list above.
@gunnarmorling , I'll add tests for them. If you don't mind you could merge #25 already. Even the new tests in that PR doesn't cover all cases, they'll provide some more safety.
If you don't mind you could merge #25 already
We can merge it, but it's still missing license headers in some files. Can you run mvn license:format, update the PR and merge it yourself? Thanks!
@nilshartmann Added the license headers and merged #25. Thanks!