All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openrewrite.text.ChangeText Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020 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.text; import lombok.EqualsAndHashCode; import lombok.Value; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import java.util.Collections; import java.util.Set; import static java.util.Collections.emptyList; @Value @EqualsAndHashCode(callSuper = false) public class ChangeText extends Recipe { @Option(displayName = "Text after change", description = "The text file will have only this text after the change. The snippet provided here can be multiline.", example = "Some text.") String toText; @Override public Set getTags() { return Collections.singleton("plain text"); } @Override public String getDisplayName() { return "Change text"; } @Override public String getInstanceNameSuffix() { return "to `" + toText + "`"; } @Override public String getDescription() { return "Completely replaces the contents of the text file with other text. " + "Use together with a `FindSourceFiles` precondition to limit which files are changed."; } @Override public TreeVisitor getVisitor() { return new PlainTextVisitor() { @Override public PlainText visitText(PlainText text, ExecutionContext ctx) { return text .withSnippets(emptyList()) .withText(toText); } }; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy