1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.currysrc.api.process; 17 18 import com.google.currysrc.api.match.SourceMatchers; 19 20 /** 21 * Basic utility methods for working with {@link Rule} instances. 22 */ 23 public class Rules { 24 Rules()25 private Rules() { 26 } 27 28 /** 29 * Create a mandatory rule that applies the {@link Processor} to all source files. 30 * 31 * <p>A mandatory rule is one which must result in a change to every file to which it applies and 32 * will fail the transformation otherwise. 33 */ createMandatoryRule(Processor processor)34 public static Rule createMandatoryRule(Processor processor) { 35 return new DefaultRule(processor, SourceMatchers.all(), true /* mustModify */); 36 } 37 38 /** 39 * Create an optional rule that applies the {@link Processor} to all the source files. 40 * 41 * <p>An optional rule does not require that it modifies every file to which it is applied.</p> 42 */ createOptionalRule(Processor processor)43 public static Rule createOptionalRule(Processor processor) { 44 return new DefaultRule(processor, SourceMatchers.all(), false /* mustModify */); 45 } 46 } 47