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

preserve annotation values when parsing compiled classes #1

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

Conversation

zexblue01
Copy link
Owner

@zexblue01 zexblue01 commented Dec 3, 2024

What's changed?

This PR adds ability to preserve annotation values parsed by JavaParsers (I updated all existing Java parser versions: 8, 11, 17, 21).

It adds a new subclass Annotation of FullyQualified in JavaType. It delegates most functionality to annotation's JavaType.Class object but stores list of value attribute pairs as part of the structure.

What's your motivation?

In the recipe I'm working on I need to be able to access annotation values on the method invoked in the source file (method could be defined in a dependency in the classpath instead of being as part of the source file input).

openrewrite#4745

Have you considered any alternatives or workarounds?

I don't think there is a workaround with OpenRewrite. I worked around in my solution by loading all classes and use reflection to inspect the actual annotation values, which is a bit cumbersome.

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

@zexblue01 zexblue01 force-pushed the eason-preserve_annotation_values branch from aa1a97f to 7774567 Compare December 4, 2024 01:46
@zexblue01 zexblue01 force-pushed the eason-preserve_annotation_values branch from 7774567 to 5b4e72b Compare December 4, 2024 04:13
@zexblue01 zexblue01 force-pushed the eason-preserve_annotation_values branch 2 times, most recently from 7efac83 to 49c43df Compare December 4, 2024 19:27
@zexblue01 zexblue01 force-pushed the eason-preserve_annotation_values branch from 49c43df to 4ce0454 Compare December 4, 2024 20:07
@zexblue01 zexblue01 force-pushed the eason-preserve_annotation_values branch from 4ce0454 to 334b9e2 Compare December 4, 2024 21:15
Eason Lin and others added 17 commits December 4, 2024 13:38
Co-authored-by: Tim te Beek <[email protected]>
* Fix AddImport match variable's name

* Apply formatter

* Run a single test

* Simplify if/else

---------

Co-authored-by: Tim te Beek <[email protected]>
* feat: Added option to comment out property in yaml

Refs: openrewrite#4740

* Update rewrite-yaml/src/main/java/org/openrewrite/yaml/CommentOutProperty.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update rewrite-yaml/src/main/java/org/openrewrite/yaml/CommentOutProperty.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Handle nullable Boolean correctly for usage from rewrite.yml

* Drop unused default

* Prevent double negation

* Adopt `else if`

---------

Co-authored-by: Andrei Shakirin <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
)

* Update get classpath by artifact name to support bazel

* Remove string concatenation and add `else` for clarity

---------

Co-authored-by: Tim te Beek <[email protected]>
* Add ability to change value using RegExp

* Add regex login in separate visitor

* Fix formatting

* Limit new public API by using a nested dedicated `RegexReplaceVisitor`

* Add test for missed case

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Antho Durairaj <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* Add initial support for java references for yaml scalars

* Add incubation annotation

* Add extra test

* Add rename support in YamlReference

* Add NullMarked Package info

* Restrict to application files and rename provider

* Fix paths in tests

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Knut Wannheden <[email protected]>

* Minimize diff between Yaml and Properties type references

---------

Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Knut Wannheden <[email protected]>
* Adding master password decrypting

* Remove redundant nonnull

* Reorder methods to read top down and use ListUtils

* Start off with a minimize public API

* Moving the decryption routing inside MavenSettings so it's always executed.

* Added tests

* Adding newline

* Remove unused and failing ChangeParentPom2Test.java

* Move decryption to MavenSecuritySettings

* Polish MavenSettingsSecurityTest

* Implement relocation

---------

Co-authored-by: Tim te Beek <[email protected]>
t-huebner-id and others added 30 commits January 16, 2025 21:15
openrewrite#4888)

* Fixed missing version on multiple dependency management sections in multi-module projects and fixed ignored classifiers when choosing snapshot timestamp

* Formatted code, add unit test

* Added issue annotation to test

* Formatted

* Minor polish

* Further polish

* Generalize comment on continue

* Test for snapshot downloading issue

* Minor polish

---------

Co-authored-by: Tobias Hübner <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
* Fix parser

* restore build files

* Restore build file

* Put arguments on new line for readability

* Add test case (even though not reproducible)

---------

Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Knut Wannheden <[email protected]>
* Groovy parser fail with Jenkinsfile and single line comment

* Minimize example

* Update rewrite-groovy/src/test/java/org/openrewrite/groovy/JenkinsFileTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix `StringUtils#indexOfNextNonWhitespace()`

A `//` sequence inside a multi-line comment caused trouble.

---------

Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Knut Wannheden <[email protected]>
…e#4661)

* Add full blown support for Switch pattern matching
* Add print idempotency for Record pattern matching

---------

Co-authored-by: Laurens Westerlaken <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
* Pull up recipes from rewrite-migrate-java

* Also pull up `UpdateMavenProjectPropertyJavaVersion`

* Apply formatter
* feat: recipe for adding a key value pair to a json

* Slight polish

* Slight polish

* Strive for better formatting after insertion

* Improve some existing cases already

* Update test as suggested

* Refactoring, extract normalizeNewLines()

* Autoformat visitor for JSON

* Removing @NotNull annotations

* Basic tests for Autodetect

* Basic tests for NormalizeLineBreaksVisitor

* No public classifier

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Copy&paste typo

Co-authored-by: Knut Wannheden <[email protected]>

* Copy&paste typo

Co-authored-by: Knut Wannheden <[email protected]>

* Rename FindLineFormatJsonVisitor

* Adding package-info.java files

* Parsing the value parameter to JSON

* Fixed description

* Removing unneeded unQuote method

---------

Co-authored-by: dpozinen <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Knut Wannheden <[email protected]>
…#4923)

* Support Groovy methods declaring generic type parameters

* Enable some working tests

Using `@ExpectedToFail` I found a bunch of tests which appear to have been fixed. I enabled those and replaced `@Disabled` with `@ExpectedToFail` on others.
While a class extending `groovy.lang.Script` typically represents the synthetic class representing the Groovy script as a whole, this is not necessarily the reason.

Additionally, also fix parsing of classes extending `Object` as well as correct type attribution for parsed classes with a super class (the `JavType.Class` should not declare any inherited methods).
* Map the type information provided by the compiler instead of trying to determine the type
In case a method's return type and method name contain the type and name of the method's first parameter (as in `public String foobar(String foo, String bar)`), the parameter alignment formatting could go wrong.
* Add backwards compatibility constructors

For the two recent changes to `J.Case` and `J.SwitchExpression` which both added new fields, the constructor changed and no constructor was added for API backwards compatibility.

This commit adds the corresponding constructors and annotates them both as `@Deprecated` and as `@ScheduledForRemoval` (from the JetBrains annotations). For the latter we provide a date value for the `inVersion` attribute as in `@ScheduledForRemoval(inVersion = "2025-05-01")`. This will allow us to implement some simple tooling to weed these constructors out again, without this chore getting forgotten.

* Polish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.