1 /******************************************************************************* 2 * Copyright 2013 André Rouél and Dominik Seichter 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 net.sf.qualitytest.blueprint.strategy.matching; 17 18 import java.lang.reflect.Field; 19 import java.lang.reflect.Method; 20 21 import net.sf.qualitycheck.Check; 22 import net.sf.qualitytest.blueprint.MatchingStrategy; 23 24 /** 25 * This value matching strategy matches all methods that are setters, i.e. start with the prefix 'set'. 26 * 27 * This matching strategy does never match by type. 28 * 29 * @author Dominik Seichter 30 */ 31 public class SetterMethodMatchingStrategy implements MatchingStrategy { 32 33 private static final String SETTER_PREFIX = "set"; 34 35 @Override 36 public boolean matchesByField(final Field field) { 37 return false; 38 } 39 40 @Override 41 public boolean matchesByMethod(final Method method) { 42 Check.notNull(method, "method"); 43 44 return method.getName().startsWith(SETTER_PREFIX); 45 } 46 47 @Override 48 public boolean matchesByType(final Class<?> clazz) { 49 return false; 50 } 51 52 }