forked from openrewrite/rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite 8.0 migration recipes (openrewrite#3241)
- Loading branch information
Showing
12 changed files
with
1,767 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
rewrite-core/src/main/java/org/openrewrite/Preconditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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; | ||
|
||
/** | ||
* This class is for rewrite8 migration purpose only | ||
*/ | ||
public class Preconditions { | ||
|
||
public static TreeVisitor<?, ExecutionContext> check(Recipe check, TreeVisitor<?, ExecutionContext> v) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
public static TreeVisitor<?, ExecutionContext> check(TreeVisitor<?, ExecutionContext> check, TreeVisitor<?, ExecutionContext> v) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
public static TreeVisitor<?, ExecutionContext> check(boolean check, TreeVisitor<?, ExecutionContext> v) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
@Incubating(since = "8.0.0") | ||
@SafeVarargs | ||
public static TreeVisitor<?, ExecutionContext> firstAcceptable(TreeVisitor<?, ExecutionContext>... vs) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
public static TreeVisitor<?, ExecutionContext> not(TreeVisitor<?, ExecutionContext> v) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
@SafeVarargs | ||
public static TreeVisitor<?, ExecutionContext> or(TreeVisitor<?, ExecutionContext>... vs) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
|
||
@SafeVarargs | ||
public static TreeVisitor<?, ExecutionContext> and(TreeVisitor<?, ExecutionContext>... vs) { | ||
throw new RuntimeException("Not supported Rewrite8 feature"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...-java-test/src/test/java/org/openrewrite/java/upgrade/MigrateMarkersSearchResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.upgrade; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.java.JavaParser; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class MigrateMarkersSearchResultTest implements RewriteTest { | ||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipe(new MigrateMarkersSearchResult()) | ||
.parser(JavaParser.fromJavaVersion() | ||
.classpath(JavaParser.runtimeClasspath()) | ||
); | ||
} | ||
|
||
@Test | ||
void migrate() { | ||
rewriteRun( | ||
java( | ||
""" | ||
package org.openrewrite.kubernetes.resource; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
import org.openrewrite.*; | ||
import org.openrewrite.yaml.YamlIsoVisitor; | ||
import org.openrewrite.yaml.tree.Yaml; | ||
@Value | ||
@EqualsAndHashCode(callSuper = true) | ||
public class FindExceedsResourceRatio extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "Find exceeds resource ratio"; | ||
} | ||
@Override | ||
protected TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new YamlIsoVisitor<ExecutionContext>() { | ||
@Override | ||
public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { | ||
Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx); | ||
return e.withMarkers(e.getMarkers().searchResult("foo")); | ||
} | ||
}; | ||
} | ||
} | ||
""", | ||
""" | ||
package org.openrewrite.kubernetes.resource; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
import org.openrewrite.*; | ||
import org.openrewrite.marker.SearchResult; | ||
import org.openrewrite.yaml.YamlIsoVisitor; | ||
import org.openrewrite.yaml.tree.Yaml; | ||
@Value | ||
@EqualsAndHashCode(callSuper = true) | ||
public class FindExceedsResourceRatio extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "Find exceeds resource ratio"; | ||
} | ||
@Override | ||
protected TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new YamlIsoVisitor<ExecutionContext>() { | ||
@Override | ||
public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { | ||
Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx); | ||
return SearchResult.found(e, "foo"); | ||
} | ||
}; | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.