Skip to content

Fix remove unused imports doc #5738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

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
Copy link
Author

with:

image

without:

image

test working assuming version issue.

@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

Comment on lines +137 to +215
void doNotDocRemoval() {
rewriteRun(
java(
"""
/*
* Copyright 2015-2025 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package org.junit.platform.suite.api;

import static org.apiguardian.api.API.Status.STABLE;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Set;

import org.apiguardian.api.API;

/**
* {@code @SelectModules} specifies the modules to <em>select</em> when running
* a test suite on the JUnit Platform.
*
* @since 1.8
* @see Suite
* @see org.junit.platform.engine.discovery.DiscoverySelectors#selectModules(Set)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectModules {

/**
* One or more modules to select.
*/
String[] value();

}
"""
)
);
rewriteRun(
java(
"""
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.java.ast;

import net.sourceforge.pmd.lang.ast.Node;

/**
* The declaration of an annotation type.
* This is a {@linkplain Node#isFindBoundary() find boundary} for tree traversal methods.
* </pre>
*
*/
public final class ASTAnnotationTypeDeclaration {


ASTAnnotationTypeDeclaration(int id) {
}

}
"""
)
);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for reporting the issue! Can we reduce this down to just the minimum required to replicate the test failure?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants