Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
package org.openrewrite.java.migrate;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
Expand All @@ -33,16 +32,19 @@
import org.openrewrite.java.tree.TypeUtils;

@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class JREThrowableFinalMethods extends Recipe {

private final String methodPatternAddSuppressed;
private final String methodPatternGetSuppressed;

@JsonCreator
public JREThrowableFinalMethods() {
this.methodPatternAddSuppressed = "*..* addSuppressed(Throwable)";
this.methodPatternGetSuppressed = "*..* getSuppressed()";
public JREThrowableFinalMethods(
@Nullable String methodPatternAddSuppressed,
@Nullable String methodPatternGetSuppressed) {
this.methodPatternAddSuppressed = methodPatternAddSuppressed == null ?
"*..* addSuppressed(Throwable)" : methodPatternAddSuppressed;
this.methodPatternGetSuppressed = methodPatternGetSuppressed == null ?
"*..* getSuppressed()" : methodPatternGetSuppressed;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void methodUsingException(ThrowableWithIllegalOverrrides t1) {
void shouldRenameOnJava6() {
//language=java
rewriteRun(
spec -> spec.recipe(new JREThrowableFinalMethods()),
spec -> spec.recipe(new JREThrowableFinalMethods(null, null)),
java(
"""
class ClassUsingThrowable {
Expand All @@ -118,7 +118,7 @@ void methodUsingRenamedMethodsAlready(Throwable t1) {
void shouldNotRenameOnJava7() {
//language=java
rewriteRun(
spec -> spec.recipe(new JREThrowableFinalMethods()),
spec -> spec.recipe(new JREThrowableFinalMethods(null, null)),
java(
"""
class ClassUsingThrowable {
Expand Down
Loading