org.openrewrite.test.AdHocRecipe Maven / Gradle / Ivy
Show all versions of rewrite-test Show documentation
/*
* Copyright 2022 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.test;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.With;
import org.intellij.lang.annotations.Language;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.StringUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
@Value
@EqualsAndHashCode(callSuper = false)
public class AdHocRecipe extends Recipe {
@With
@Nullable
@Language("markdown")
String displayName;
@With
@Nullable
String name;
@With
@Nullable
Boolean causesAnotherCycle;
@With
transient Supplier> getVisitor;
@With
@Nullable
List maintainers;
@With
@Nullable
Integer maxCycles;
public AdHocScanningRecipe withGenerator(Supplier> generator) {
return new AdHocScanningRecipe(displayName, name, causesAnotherCycle, getVisitor, generator, maintainers, maxCycles);
}
@Override
public String getDisplayName() {
return StringUtils.isBlank(displayName) ? "Ad hoc recipe" : displayName;
}
@Override
public String getDescription() {
return "An ad hoc recipe used in RewriteTest.";
}
@Override
public String getName() {
return StringUtils.isBlank(name) ? super.getName() : name;
}
@Override
public boolean causesAnotherCycle() {
return causesAnotherCycle == null ? super.causesAnotherCycle() : causesAnotherCycle;
}
@Override
public int maxCycles() {
return maxCycles == null ? super.maxCycles() : maxCycles;
}
@Override
public List getMaintainers() {
return maintainers == null ? Collections.emptyList() : maintainers;
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
return getVisitor.get();
}
}