Skip to content
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

test: add AnnotationMatcherTest #467

Closed
wants to merge 1 commit into from

Conversation

jeonyeonbin
Copy link

@jeonyeonbin jeonyeonbin commented Nov 27, 2023

What's changed?

  • add AnnotationMatcher Test

Anyone you would like to review specifically?

@timtebeek

Any additional context

@timtebeek timtebeek added bug Something isn't working test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail labels Nov 27, 2023
@timtebeek
Copy link
Contributor

Thanks for adding this reproducer test @jeonyeonbin ! I'm hoping one of my colleagues who are more active with Kotlin can have a look!

@traceyyoshima
Copy link
Contributor

Hi @jeonyeonbin, thank you for opening a PR as an example! I plan to use @Deprecated since the annotation exists on the classpath for the JVM to use the matcher directly on the CU.

Example:

    @Test
    void matchAnnotation() {
        rewriteRun(
          kotlin(
            """
              @Deprecated("")
              class A
              """, spec -> spec.afterRecipe(cu -> {
                  AtomicBoolean found = new AtomicBoolean(false);
                AnnotationMatcher matcher = new AnnotationMatcher("@kotlin.Deprecated");
                new KotlinIsoVisitor<AtomicBoolean>() {
                    @Override
                    public J.Annotation visitAnnotation(J.Annotation annotation, AtomicBoolean atomicBoolean) {
                        if (matcher.matches(annotation)) {
                            found.set(true);
                        }
                        return super.visitAnnotation(annotation, atomicBoolean);
                    }
                }.visit(cu, found);
                assertThat(found.get()).isTrue();
            })
          )
        );
    }

I plan to implement a holistic fix and have a change in place today.

Closing PR -- we really appreciate you!

@jeonyeonbin jeonyeonbin deleted the patch branch November 28, 2023 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants