Skip to content

UnnecessarilyFullyQualified and package-info.java #1652

Closed
@Stephan202

Description

@Stephan202
Contributor

Consider the following code:

@com.google.errorprone.annotations.CheckReturnValue
package foo;

Applying the UnnecessarilyFullyQualified check to this code:

wget \
  https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.4.0/error_prone_core-2.4.0-with-dependencies.jar
wget \
  https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.4.0/error_prone_annotations-2.4.0.jar
javac \
  -XDcompilePolicy=simple \
  -processorpath error_prone_core-2.4.0-with-dependencies.jar \
  '-Xplugin:ErrorProne -XepPatchChecks:UnnecessarilyFullyQualified -XepPatchLocation:/tmp' \
  -cp error_prone_annotations-2.4.0.jar \
  foo/package-info.java

This yields:

--- /tmp/foo/package-info.java
+++ /tmp/foo/package-info.java
@@ -1,3 +1,5 @@
-@com.google.errorprone.annotations.CheckReturnValue
+@CheckReturnValue
 package foo;
 
+import com.google.errorprone.annotations.CheckReturnValue;
+

In the case of package-level annotations, single-use fully qualified types arguably result in more straightforward code, as otherwise the type is used before it is imported.

(In case a type is referenced multiple times (perhaps in a nested annotation or Javadoc), I guess importing does make sense. 🤔 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Stephan202

      Issue actions

        `UnnecessarilyFullyQualified` and `package-info.java` · Issue #1652 · google/error-prone