deptective icon indicating copy to clipboard operation
deptective copied to clipboard

Implement all checks for kinds of type references

Open gunnarmorling opened this issue 7 years ago • 10 comments

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 is other.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()

gunnarmorling avatar Jan 02 '19 15:01 gunnarmorling

@nilshartmann FYI, logged this issue for completing the detection logic in the visitor.

gunnarmorling avatar Jan 02 '19 15:01 gunnarmorling

I've already expanded the BasicPluginTest to cover the ones above except the super-type ones (commented out the assertions for now).

gunnarmorling avatar Jan 02 '19 15:01 gunnarmorling

ok, I'll merge with my tests and push my work-in-progress state

nilshartmann avatar Jan 02 '19 15:01 nilshartmann

Thanks, @nilshartmann!

gunnarmorling avatar Jan 02 '19 17:01 gunnarmorling

@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 is other.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)

gunnarmorling avatar Jan 07 '19 12:01 gunnarmorling

I'll have a look!

nilshartmann avatar Jan 07 '19 13:01 nilshartmann

@nilshartmann, added two more cases to the check list above.

gunnarmorling avatar Jan 16 '19 21:01 gunnarmorling

@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.

nilshartmann avatar Jan 16 '19 22:01 nilshartmann

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!

gunnarmorling avatar Jan 17 '19 08:01 gunnarmorling

@nilshartmann Added the license headers and merged #25. Thanks!

gunnarmorling avatar Jan 18 '19 21:01 gunnarmorling