use of com.google.copybara.transform.ReplaceMapper in project copybara by google.
the class Core method mapImports.
@StarlarkMethod(name = "replace_mapper", doc = "A mapping function that applies a list of replaces until one replaces the text" + " (Unless `all = True` is used). This should be used with core.filter_replace or" + " other transformations that accept text mapping as parameter.", parameters = { @Param(name = "mapping", allowedTypes = { @ParamType(type = net.starlark.java.eval.Sequence.class, generic1 = Transformation.class) }, named = true, doc = "The list of core.replace transformations"), @Param(name = "all", named = true, positional = false, doc = "Run all the mappings despite a replace happens.", defaultValue = "False") })
public ReplaceMapper mapImports(// <Transformation>
net.starlark.java.eval.Sequence<?> mapping, Boolean all) throws EvalException {
check(!mapping.isEmpty(), "Empty mapping is not allowed");
ImmutableList.Builder<Replace> replaces = ImmutableList.builder();
for (Transformation t : net.starlark.java.eval.Sequence.cast(mapping, Transformation.class, "mapping")) {
check(t instanceof Replace, "Only core.replace can be used as mapping, but got: %S", t.describe());
Replace replace = (Replace) t;
check(replace.getPaths().equals(Glob.ALL_FILES), "core.replace cannot use" + " 'paths' inside core.replace_mapper");
replaces.add(replace);
}
return new ReplaceMapper(replaces.build(), all);
}
Aggregations