diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependency.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependency.java index 7e79261c09..33a1bdce31 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependency.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependency.java @@ -30,7 +30,6 @@ import org.openrewrite.groovy.tree.G; import org.openrewrite.internal.ListUtils; import org.openrewrite.internal.StringUtils; -import org.openrewrite.java.InlineMe; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.tree.Expression; import org.openrewrite.java.tree.J; @@ -132,7 +131,6 @@ public ChangeDependency(String oldGroupId, String oldArtifactId, @Nullable Strin this.changeManagedDependency = changeManagedDependency; } - @InlineMe(replacement = "this(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern, overrideManagedVersion, true)") public ChangeDependency(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean overrideManagedVersion) { this(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern, overrideManagedVersion, true); } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/trait/Traits.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/trait/Traits.java index e95ba81d1d..f98c569e22 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/trait/Traits.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/trait/Traits.java @@ -15,8 +15,6 @@ */ package org.openrewrite.gradle.trait; -import org.openrewrite.java.InlineMe; - /** * @deprecated Use specific matchers like {@link GradleDependency.Matcher} or {@link JvmTestSuite.Matcher} instead. */ @@ -29,7 +27,6 @@ private Traits() { * @deprecated Use {@link GradleDependency.Matcher} instead. */ @Deprecated - @InlineMe(replacement = "new GradleDependency.Matcher()", imports = "org.openrewrite.gradle.GradleDependency") public static GradleDependency.Matcher gradleDependency() { return new GradleDependency.Matcher(); } @@ -38,7 +35,6 @@ public static GradleDependency.Matcher gradleDependency() { * @deprecated Use {@link JvmTestSuite.Matcher} instead. */ @Deprecated - @InlineMe(replacement = "new JvmTestSuite.Matcher()", imports = "org.openrewrite.gradle.JvmTestSuite") public static JvmTestSuite.Matcher jvmTestSuite() { return new JvmTestSuite.Matcher(); } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ChangeMethodTargetToStatic.java b/rewrite-java/src/main/java/org/openrewrite/java/ChangeMethodTargetToStatic.java index efd2c5c170..cd6d481f8c 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ChangeMethodTargetToStatic.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ChangeMethodTargetToStatic.java @@ -68,7 +68,6 @@ public class ChangeMethodTargetToStatic extends Recipe { @Nullable Boolean matchUnknownTypes; - @InlineMe(replacement = "this(methodPattern, fullyQualifiedTargetTypeName, returnType, matchOverrides, false)") public ChangeMethodTargetToStatic(String methodPattern, String fullyQualifiedTargetTypeName, @Nullable String returnType, @Nullable Boolean matchOverrides) { this(methodPattern, fullyQualifiedTargetTypeName, returnType, matchOverrides, false); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/InlineMe.java b/rewrite-java/src/main/java/org/openrewrite/java/InlineMe.java deleted file mode 100644 index ef1b223d23..0000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/InlineMe.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2025 the original author or authors. - *
- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *
- * https://www.apache.org/licenses/LICENSE-2.0 - *
- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -/** - * Indicates that calls to the annotated method or constructor can be replaced with the provided replacement template. - *
- * This annotation is typically used to mark methods or constructors that are deprecated and have a preferred alternative - * implementation. The replacement template should provide a way to achieve the same functionality as the annotated - * method or constructor, but using a different approach. - */ -@Documented -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface InlineMe { - /** - * A Java template that can be used to replace calls to the annotated method. Typically starts with {@code this.} - * for method invocations in the same class, or {@code this(}, for constructor invocations in the same class. - * - * Replacement templates may refer to elements from other classes, provided the necessary imports are passed in. - * - * Replacement templates can reference method parameters by name, and can also reference {@code this}. - * - * @return a Java template that can be used to replace calls to the annotated method. - */ - String replacement(); - - /** - * Optional imports required by the replacement template. - * - * @return imports to be used when compiling the replacement template, and added to the source file if necessary. - */ - String[] imports() default {}; - - /** - * Optional static imports required by the replacement template. - * - * @return static imports to be used when compiling the replacement template, and added to the source file if necessary. - */ - String[] staticImports() default {}; -} diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/parser/InlineMethodCallsRecipeGenerator.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/parser/InlineMethodCallsRecipeGenerator.java deleted file mode 100644 index 11e4749ab8..0000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/parser/InlineMethodCallsRecipeGenerator.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright 2025 the original author or authors. - *- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *
- * https://www.apache.org/licenses/LICENSE-2.0 - *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.java.internal.parser;
-
-import lombok.AllArgsConstructor;
-import org.jspecify.annotations.Nullable;
-import org.openrewrite.InMemoryExecutionContext;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.time.Year;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
-import java.util.zip.GZIPInputStream;
-
-import static java.lang.String.format;
-import static java.util.Objects.requireNonNull;
-import static java.util.stream.Collectors.groupingBy;
-
-public class InlineMethodCallsRecipeGenerator {
-
- public static void main(String[] args) {
- if (args.length < 3) {
- System.err.println("Usage: InlineMethodCallsRecipeGenerator
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.java.internal.parser;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.zip.GZIPOutputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class InlineMethodCallsRecipeGeneratorTest {
-
- @Test
- void generateRecipesFromTypeTable(@TempDir Path tempDir) throws Exception {
- // Create a test TypeTable TSV file
- Path inputTsv = tempDir.resolve("test.tsv.gz");
- String tsvContent = """
- groupId\tartifactId\tversion\tclassAccess\tclassName\tclassSignature\tclassSuperclassSignature\tclassSuperinterfaceSignatures\taccess\tname\tdescriptor\tsignature\tparameterNames\texceptions\telementAnnotations\tparameterAnnotations\ttypeAnnotations\tconstantValue
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t-1\t\t\t\t\t\t\t\t\t
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t1\toldMethod\t(Ljava/lang/String;)V\t\tinput\t\t@Lorg/openrewrite/java/InlineMe;(replacement=s"newMethod(input)",imports=[s"java.util.List"])\t\t\t
- """;
- try (OutputStream os = Files.newOutputStream(inputTsv);
- GZIPOutputStream gzos = new GZIPOutputStream(os)) {
- gzos.write(tsvContent.getBytes());
- }
-
- // Run the generator
- Path outputYaml = tempDir.resolve("output.yaml");
- InlineMethodCallsRecipeGenerator.generate(inputTsv, outputYaml, "org.openrewrite.java.InlineMethodCallsGenerated");
-
- // Read and verify the content
- //language=yaml
- assertThat(outputYaml).hasContent("""
- #
- # Generated InlineMe recipes from TypeTable
- #
-
- type: specs.openrewrite.org/v1beta/recipe
- name: org.openrewrite.java.InlineMethodCallsGenerated
- displayName: Inline methods annotated with `@InlineMe`
- description: >-
- Automatically generated recipes to inline method calls based on `@InlineMe` annotations
- discovered in the type table.
- recipeList:
-
- # From com.example:test-lib:1.0.0
- - org.openrewrite.java.InlineMethodCalls:
- methodPattern: 'com.example.TestClass oldMethod(java.lang.String)'
- replacement: 'newMethod(input)'
- imports:
- - 'java.util.List'
- classpathFromResources:
- - 'test-lib-1.0.0'
- """);
- }
-
- @Test
- void handleMultipleAnnotatedMethods(@TempDir Path tempDir) throws Exception {
- // Create a test TypeTable TSV file with multiple annotated methods
- Path inputTsv = tempDir.resolve("test.tsv.gz");
- String tsvContent = """
- groupId\tartifactId\tversion\tclassAccess\tclassName\tclassSignature\tclassSuperclassSignature\tclassSuperinterfaceSignatures\taccess\tname\tdescriptor\tsignature\tparameterNames\texceptions\telementAnnotations\tparameterAnnotations\ttypeAnnotations\tconstantValue
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t-1\t\t\t\t\t\t\t\t\t
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t1\tmethod1\t()V\t\t\t\t@Lorg/openrewrite/java/InlineMe;(replacement=s"replacement1()")\t\t\t
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t1\tmethod2\t(I)V\t\tnum\t\t@Lorg/openrewrite/java/InlineMe;(replacement=s"replacement2(num)",staticImports=[s"java.util.Collections.emptyList"])\t\t\t
- """;
- try (OutputStream os = Files.newOutputStream(inputTsv);
- GZIPOutputStream gzos = new GZIPOutputStream(os)) {
- gzos.write(tsvContent.getBytes());
- }
-
- // Run the generator
- Path outputYaml = tempDir.resolve("output.yaml");
- InlineMethodCallsRecipeGenerator.generate(inputTsv, outputYaml, "org.openrewrite.java.InlineMethodCallsGenerated");
-
- // Read and verify the content
- //language=yaml
- assertThat(outputYaml).hasContent("""
- #
- # Generated InlineMe recipes from TypeTable
- #
-
- type: specs.openrewrite.org/v1beta/recipe
- name: org.openrewrite.java.InlineMethodCallsGenerated
- displayName: Inline methods annotated with `@InlineMe`
- description: >-
- Automatically generated recipes to inline method calls based on `@InlineMe` annotations
- discovered in the type table.
- recipeList:
-
- # From com.example:test-lib:1.0.0
- - org.openrewrite.java.InlineMethodCalls:
- methodPattern: 'com.example.TestClass method1()'
- replacement: 'replacement1()'
- classpathFromResources:
- - 'test-lib-1.0.0'
- - org.openrewrite.java.InlineMethodCalls:
- methodPattern: 'com.example.TestClass method2(int)'
- replacement: 'replacement2(num)'
- staticImports:
- - 'java.util.Collections.emptyList'
- classpathFromResources:
- - 'test-lib-1.0.0'
- """);
- }
-
- @Test
- void skipMethodsWithoutInlineMeAnnotation(@TempDir Path tempDir) throws Exception {
- // Create a test TypeTable TSV file with a mix of annotated and non-annotated methods
- Path inputTsv = tempDir.resolve("test.tsv.gz");
- String tsvContent = """
- groupId\tartifactId\tversion\tclassAccess\tclassName\tclassSignature\tclassSuperclassSignature\tclassSuperinterfaceSignatures\taccess\tname\tdescriptor\tsignature\tparameterNames\texceptions\telementAnnotations\tparameterAnnotations\ttypeAnnotations\tconstantValue
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t-1\t\t\t\t\t\t\t\t\t
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t1\tregularMethod\t()V\t\t\t\t\t\t\t
- com.example\ttest-lib\t1.0.0\t1\tcom/example/TestClass\t\tjava/lang/Object\t\t1\tannotatedMethod\t()V\t\t\t\t@Lorg/openrewrite/java/InlineMe;(replacement=s"replacement()")\t\t\t
- """;
- try (OutputStream os = Files.newOutputStream(inputTsv);
- GZIPOutputStream gzos = new GZIPOutputStream(os)) {
- gzos.write(tsvContent.getBytes());
- }
-
- // Run the generator
- Path outputYaml = tempDir.resolve("output.yaml");
- InlineMethodCallsRecipeGenerator.generate(inputTsv, outputYaml, "org.openrewrite.java.InlineMethodCallsGenerated");
-
- // Read and verify the content
- //language=yaml
- assertThat(outputYaml).hasContent("""
- #
- # Generated InlineMe recipes from TypeTable
- #
-
- type: specs.openrewrite.org/v1beta/recipe
- name: org.openrewrite.java.InlineMethodCallsGenerated
- displayName: Inline methods annotated with `@InlineMe`
- description: >-
- Automatically generated recipes to inline method calls based on `@InlineMe` annotations
- discovered in the type table.
- recipeList:
-
- # From com.example:test-lib:1.0.0
- - org.openrewrite.java.InlineMethodCalls:
- methodPattern: 'com.example.TestClass annotatedMethod()'
- replacement: 'replacement()'
- classpathFromResources:
- - 'test-lib-1.0.0'
- """);
- }
-}
diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java
index 5189a07ff0..a3e7e62f83 100644
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java
@@ -21,7 +21,6 @@
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.StringUtils;
-import org.openrewrite.java.InlineMe;
import org.openrewrite.maven.table.MavenMetadataFailures;
import org.openrewrite.maven.trait.MavenDependency;
import org.openrewrite.maven.tree.*;
@@ -114,7 +113,6 @@ public class AddManagedDependency extends ScanningRecipe