Skip to content

Conversation

timtebeek
Copy link
Member

@timtebeek timtebeek commented Jul 7, 2025

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jul 7, 2025
@timtebeek timtebeek self-assigned this Jul 7, 2025
@timtebeek timtebeek added the recipe Recipe requested label Jul 7, 2025
@timtebeek timtebeek changed the title Create replace for @InlineMe annotations Create recipe for @InlineMe annotation replacements Jul 7, 2025
github-actions[bot]

This comment was marked as outdated.

@timtebeek
Copy link
Member Author

@timtebeek timtebeek marked this pull request as ready for review August 18, 2025 15:01
@timtebeek
Copy link
Member Author

timtebeek commented Aug 18, 2025

So as a proof of concept this now works; there's still possible improvements to be made:

  • add / remove static imports as well
  • apply this recipe with a Guava precondition to inline any methods as part of the NoGuava composite recipe
  • add a precondition that we must be using a type that uses @InlineMe; likely requires a change in TypesInUse, with a trade off between performance here and storage needs in the LST, as annotations on types are quite common

Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

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

Nice! I am not sure if we can change the TypesInUse like that, but perhaps we also find a different solution. For now I think wrapping in a declarative recipe with a precondition is quite sufficient.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Aug 19, 2025
@timtebeek timtebeek merged commit d309e2b into main Aug 19, 2025
2 checks passed
@timtebeek timtebeek deleted the recipe-for-InlineMe-annotation branch August 19, 2025 11:41
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Aug 19, 2025
@timtebeek
Copy link
Member Author

timtebeek commented Aug 19, 2025

Confirmed by running at scale: These two methods are annotated with their replacements

  1. https://github.com/google/s2-geometry-library-java/blob/57151fc0f7fe543b75e9f743bf897e81928d5c3f/library/src/com/google/common/geometry/S2EdgeUtil.java#L2925-L2931
  2. https://github.com/google/s2-geometry-library-java/blob/57151fc0f7fe543b75e9f743bf897e81928d5c3f/library/src/com/google/common/geometry/S2Shape.java#L108-L112

Which we ran through the platform: https://app.moderne.io/results/v7n9xVESH
Which then resulted in the following patch file

diff --git a/library/src/com/google/common/geometry/S2ConvexHullQuery.java b/library/src/com/google/common/geometry/S2ConvexHullQuery.java
index d30e9b9..0683d66 100644
--- a/library/src/com/google/common/geometry/S2ConvexHullQuery.java
+++ b/library/src/com/google/common/geometry/S2ConvexHullQuery.java
@@ -268,7 +268,7 @@ org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
     // Construct a loop consisting of the two vertices and their midpoint. We use
     // S2EdgeUtil.interpolate() to ensure that the midpoint is very close to the edge even when its
     // endpoints are nearly antipodal.
-    S2Loop loop = new S2Loop(ImmutableList.of(a, b, S2EdgeUtil.interpolate(0.5, a, b)));
+    S2Loop loop = new S2Loop(ImmutableList.of(a, b, S2EdgeUtil.interpolate(a, b, 0.5)));
     // The resulting loop may be clockwise, so invert it if necessary.
     loop.normalize();
     return loop;
diff --git a/library/src/com/google/common/geometry/S2ContainsPointQuery.java b/library/src/com/google/common/geometry/S2ContainsPointQuery.java
index 1eff5c9..a99bfb6 100644
--- a/library/src/com/google/common/geometry/S2ContainsPointQuery.java
+++ b/library/src/com/google/common/geometry/S2ContainsPointQuery.java
@@ -314,7 +314,7 @@ org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
       for (int i = 0; i < numEdges; i++) {
         int edgeId = clipped.edge(i);
         shape.getEdge(edgeId, tmp);
-        if (tmp.isEndpoint(p) && !visitor.test(shapeId, edgeId, tmp.a, tmp.b)) {
+        if (tmp.hasEndpoint(p) && !visitor.test(shapeId, edgeId, tmp.a, tmp.b)) {
           return false;
         }
       }
diff --git a/library/src/com/google/common/geometry/S2EdgeTessellator.java b/library/src/com/google/common/geometry/S2EdgeTessellator.java
index 531b88d..d15cf22 100644
--- a/library/src/com/google/common/geometry/S2EdgeTessellator.java
+++ b/library/src/com/google/common/geometry/S2EdgeTessellator.java
@@ -280,8 +280,8 @@ org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
 
     double t1 = INTERPOLATION_FRACTION;
     double t2 = 1 - INTERPOLATION_FRACTION;
-    S2Point mid1 = S2EdgeUtil.interpolate(t1, a, b);
-    S2Point mid2 = S2EdgeUtil.interpolate(t2, a, b);
+    S2Point mid1 = S2EdgeUtil.interpolate(a, b, t1);
+    S2Point mid2 = S2EdgeUtil.interpolate(a, b, t2);
     S2Point projectedMid1 = projection.unproject(Projection.interpolate(t1, pa, pb));
     S2Point projectedMid2 = projection.unproject(Projection.interpolate(t2, pa, pb));
     S1ChordAngle mid1Angle = new S1ChordAngle(mid1, projectedMid1);
diff --git a/tests/tests/com/google/common/geometry/S2PolylineTest.java b/tests/tests/com/google/common/geometry/S2PolylineTest.java
index d45801b..8c5a3bc 100644
--- a/tests/tests/com/google/common/geometry/S2PolylineTest.java
+++ b/tests/tests/com/google/common/geometry/S2PolylineTest.java
@@ -565,14 +565,14 @@ org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
   @Test
   public void testNumEdges() {
     // Empty polyline has zero edges
-    assertEquals(0, makePolyline("").numEdges());
+    assertEquals(0, makePolyline("").shape().numEdges());
 
     // Single vertex polyline has one degenerate edge
-    assertEquals(1, makePolyline("0:0").numEdges());
+    assertEquals(1, makePolyline("0:0").shape().numEdges());
 
     // Multiple vertex polylines have non-zero edges
-    assertEquals(1, makePolyline("0:0, 1:1").numEdges());
-    assertEquals(2, makePolyline("0:0, 1:1, 2:2").numEdges());
+    assertEquals(1, makePolyline("0:0, 1:1").shape().numEdges());
+    assertEquals(2, makePolyline("0:0, 1:1, 2:2").shape().numEdges());
   }
 
   @Test

@timtebeek
Copy link
Member Author

@mike-solomon could make for a nice addition to the docs as something we now support for folks looking to migrate internal methods more easily: add that annotation to your deprecated method, then run the recipe that switches over any usage, and finally remove the deprecated method.

mike-solomon added a commit to openrewrite/rewrite-docs that referenced this pull request Aug 20, 2025
timtebeek added a commit to openrewrite/rewrite-docs that referenced this pull request Aug 21, 2025
* Add a guide on migrating deprecated methods

Based on a suggestion from Tim: openrewrite/rewrite-migrate-java#788 (comment)

* Fix spelling warnings

* Slight polish

* Add markdown around annotation in title

---------

Co-authored-by: Mike Solomon <mike-solomon@users.noreply.github.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
mergify bot added a commit to robfrank/linklift that referenced this pull request Sep 2, 2025
…15.0 to 3.16.0 [skip ci]

[//]: # (dependabot-start)
⚠️ \*\*Dependabot is rebasing this PR\*\* ⚠️
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.
---
[//]: # (dependabot-end)
Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 3.15.0 to 3.16.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-migrate-java's releases](https://github.com/openrewrite/rewrite-migrate-java/releases).*

> 3.16.0
> ------
>
> What's Changed
> --------------
>
> * Fixed validation.xml in jakarta-ee-10.yml by [`@​daniel-skovenborg`](https://github.com/daniel-skovenborg) in [openrewrite/rewrite-migrate-java#834](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/834)
> * Adding `jakarta.servlet:jakarta.servlet-api` explicitly when the `javax.servlet:javax.servlet-api` it is trying to migrate from was only available transitively. by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-migrate-java#835](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/835)
> * Drop Joda-Time recipes extracted to rewrite-joda by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#836](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/836)
> * Adopt `InlineMethodCalls` from `openrewrite/rewrite` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#837](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/837)
> * AddJaxbRuntime should use `overrideManagedDependency=true` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#838](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/838)
>
> New Contributors
> ----------------
>
> * [`@​daniel-skovenborg`](https://github.com/daniel-skovenborg) made their first contribution in [openrewrite/rewrite-migrate-java#834](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/834)
>
> **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.15.1...v3.16.0>
>
> v3.15.1
> -------
>
> What's Changed
> --------------
>
> * Update with rewrite 8.60.2
> * Improve Java 17 and Java 21 switch expression tests by [`@​jevanlingen`](https://github.com/jevanlingen) in [openrewrite/rewrite-migrate-java#822](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/822)
> * The JakartaEE9 upgrade process supplements the jakarta.activation upg… by [`@​ChenyuWang98`](https://github.com/ChenyuWang98) in [openrewrite/rewrite-migrate-java#820](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/820)
> * Move all switch expression recipes to Java 21 migration by [`@​jevanlingen`](https://github.com/jevanlingen) in [openrewrite/rewrite-migrate-java#824](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/824)
> * JakartaEE9 update restLet to 2.6.x by [`@​ChenyuWang98`](https://github.com/ChenyuWang98) in [openrewrite/rewrite-migrate-java#827](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/827)
> * Update jetty9 -> jetty12 as part of EE9 by [`@​ChenyuWang98`](https://github.com/ChenyuWang98) in [openrewrite/rewrite-migrate-java#826](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/826)
> * Migrate to `commons-fileupload2-jakarta` by [`@​ChenyuWang98`](https://github.com/ChenyuWang98) in [openrewrite/rewrite-migrate-java#819](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/819)
> * Update jakarta-ee-9.yml add javax.servlet.jsp update by [`@​ChenyuWang98`](https://github.com/ChenyuWang98) in [openrewrite/rewrite-migrate-java#829](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/829)
> * Create recipe for `@InlineMe` annotation replacements by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#788](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/788)
> * Use classpath from resource for Refaster by [`@​jevanlingen`](https://github.com/jevanlingen) in [openrewrite/rewrite-migrate-java#830](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/830)
> * Fix recipe reference to `AccessController` migration for Java 25 by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-migrate-java#832](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/832)
> * Update build Java 25 by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-migrate-java#833](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/833)
>
> New Contributors
> ----------------
>
> * [`@​ChenyuWang98`](https://github.com/ChenyuWang98) made their first contribution in [openrewrite/rewrite-migrate-java#820](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/820)
>
> **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.15.0...v3.15.1>


Commits

* [`caec49a`](openrewrite/rewrite-migrate-java@caec49a) AddJaxbRuntime should use `overrideManagedDependency=true` ([#838](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/838))
* [`c831007`](openrewrite/rewrite-migrate-java@c831007) Update documentation examples
* [`05fa3e0`](openrewrite/rewrite-migrate-java@05fa3e0) Adopt `InlineMethodCalls` from `openrewrite/rewrite` ([#837](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/837))
* [`35ba076`](openrewrite/rewrite-migrate-java@35ba076) Drop Joda-Time recipes extracted to rewrite-joda ([#836](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/836))
* [`7d30127`](openrewrite/rewrite-migrate-java@7d30127) Adding `jakarta.servlet:jakarta.servlet-api` explicitly when the `javax.servl...
* [`cea52ed`](openrewrite/rewrite-migrate-java@cea52ed) [Auto] SDKMAN! Java candidates as of 2025-08-25T1017
* [`eb159a4`](openrewrite/rewrite-migrate-java@eb159a4) Fixed validation.xml in jakarta-ee-10.yml ([#834](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/834))
* [`0563040`](openrewrite/rewrite-migrate-java@0563040) update builds to Java 25 ([#833](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/833))
* [`0d9d736`](openrewrite/rewrite-migrate-java@0d9d736) Fix recipe reference to `AccessController` migration for Java 25 ([#832](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/832))
* [`8a16285`](openrewrite/rewrite-migrate-java@8a16285) Support `@InlineMe` annotations from any package
* Additional commits viewable in [compare view](openrewrite/rewrite-migrate-java@v3.15.0...v3.16.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-migrate-java&package-manager=maven&previous-version=3.15.0&new-version=3.16.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants