Skip to content

Conversation

@Pankraz76
Copy link

@Pankraz76 Pankraz76 commented Jul 10, 2025

What's changed?

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jul 10, 2025
@Pankraz76

This comment was marked as resolved.

@Pankraz76 Pankraz76 mentioned this pull request Jul 13, 2025
4 tasks
@Pankraz76 Pankraz76 reopened this Jul 13, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in OpenRewrite Jul 13, 2025
@Pankraz76
Copy link
Author

@Pankraz76
Copy link
Author

@Pankraz76
Copy link
Author

    @Nested
    @Issue("https://github.com/openrewrite/rewrite/pull/5738")
    class removeUnusedImportsDoc {

        @Test
        void usedInDoc() {
            rewriteRun(
              java(
                """
                  import java.util.Date;
                  import java.util.List;

                  /**
                   * referencing {@link Date} only in doc
                   */
                  class Test {
                      List list;
                  }
                """
              )
            );
        }

        @Test
        void usedInDocFullQualified() {
            rewriteRun(
              java(
                """
                  import java.util.Date;
                  import java.util.List;

                  /**
                   * referencing {@link java.util.Date} only in doc
                   */
                  class Test2 {
                      List list;
                  }
                """,
                """
                  import java.util.List;

                  /**
                   * referencing {@link java.util.Date} only in doc
                   */
                  class Test2 {
                      List list;
                  }
                """
              )
            );
        }
    }

still the case seem to be fixed, but i came across another issue, not able to fix the impl.

Feel free to incorporate.
Thanks for considering.


Recipe was expected to make a change but made no changes.
java.lang.AssertionError: Recipe was expected to make a change but made no changes.
	at org.openrewrite.test.LargeSourceSetCheckingExpectedCycles.afterCycle(LargeSourceSetCheckingExpectedCycles.java:119)
	at org.openrewrite.RecipeScheduler.runRecipeCycles(RecipeScheduler.java:95)
	at org.openrewrite.RecipeScheduler.scheduleRun(RecipeScheduler.java:41)
	at org.openrewrite.Recipe.run(Recipe.java:442)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:381)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)
	at org.openrewrite.java.RemoveUnusedImportsTest$removeUnusedImportsDoc.usedInDocFullQualified(RemoveUnusedImportsTest.java:2299)
	at java.base/java.lang.invoke.LambdaForm$DMH/0x0000007001174400.invokeVirtual(LambdaForm$DMH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x000000700109c800.invoke(LambdaForm$MH)
	at java.base/java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

@timtebeek timtebeek changed the title Fix remove unused imports doc Remove fully qualified JavaDoc references from TypesInUse for RemoveUnusedImports Aug 20, 2025
@timtebeek timtebeek added the bug Something isn't working label Aug 20, 2025
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Aug 20, 2025
@timtebeek timtebeek marked this pull request as ready for review August 20, 2025 10:51
// Fully qualified Javadoc references are _using_ those types as much as they are just references;
// TypesInUse also determines what imports are retained, and for fully qualified these can be dropped
return cursor.getValue() instanceof J.FieldAccess &&
cursor.getPathAsStream().anyMatch(o -> o instanceof Javadoc.Reference);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code is a bit performance critical, I think we may want to optimize this, so that we also have other parent types, which break the cursor walking. Can we perhaps also break on J.Block?

Also, what if we have a reference to a nested type, like Outer.Inner? It seems like the Outer import would still be required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks! Added a first loop for the J.Block; haven't yet explored the Outer.Inner, but worst case there we would not remove a stray import, which I'd consider to be fairly niche and perhaps not worth handling separately here.

@Pankraz76
Copy link
Author

Pankraz76 commented Aug 20, 2025

no going to finish this, feel free to continue.

Thanks.

@Pankraz76 Pankraz76 closed this Aug 20, 2025
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Aug 20, 2025
@timtebeek timtebeek reopened this Aug 20, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in OpenRewrite Aug 20, 2025
Comment on lines +118 to +119
Iterator<Object> path = cursor.getPath();
while (path.hasNext()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing a note from Slack: some performance concerns here due to the use of cursor.getPath().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working javadoc parser

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

3 participants