8000 Please also add @DaggerGenerated to generated nested classes · Issue #4540 · google/dagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Please also add @DaggerGenerated to generated nested classes #4540
Open
@aleuner

Description

@aleuner

Dagger- generated code has the @Generated and the @DaggerGenerated annotations on top level classes of all generated Java source files.

The firster nicely allows source code scanning (e.g. static analysis) tools to recognize the code as generated, and to skip those classes. Also, implying that inner (or nested) classes of such code must also be generated code, to skip them too.
Sonar Scanner for example does this just fine.

JaCoCo, which scans class files, is different and will, for example, include generated classes like *_Factory.InstanceHolder or *ComponentImpl in its scans, even when excluding their respective directly annotated *_Factory / Dagger*Component outer classes.

I made feature request jacoco/jacoco#1815 for an improvement on this, and got an explanation basically pointing out:

  • Tools scanning class files cannot infer the inner-outer relationship so easily, because outer and inner classes reside in separate files.
  • While it might be possible to detect that a class is nested inside another (or maybe that an outer class has nested classes), figuring out if the outer class has @DaggerGenerated would mean no longer being able to look at class files one-by-one.

While the code for @Modules and @Components mostly resides in packages separated from other code - and I can thus add scanning exclusions for them by their package - the factory code for @Inject annotated classes is generated next to them.
I can still apply exclusion patterns but this requires knowledge of Dagger internals, which is uglier IMHO (but here you are for jacoco-maven-plugin: <exclude>**/*Factory$InstanceHolder.class</exclude>).

So it would be much nicer if all classes generated by Dagger got the @DaggerGenerated annotation ... generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0