1 package org.robolectric.annotation.processing.validator; 2 3 import com.google.common.collect.ImmutableSet; 4 import java.util.Set; 5 import javax.annotation.processing.ProcessingEnvironment; 6 import javax.lang.model.element.ExecutableElement; 7 import javax.lang.model.element.Modifier; 8 import javax.lang.model.element.TypeElement; 9 import javax.tools.Diagnostic.Kind; 10 import org.robolectric.annotation.processing.RobolectricModel; 11 12 /** 13 * Validator that checks usages of {@link org.robolectric.annotation.Implementation}. 14 */ 15 public class ImplementationValidator extends FoundOnImplementsValidator { 16 public static final Set<String> METHODS_ALLOWED_TO_BE_PUBLIC = ImmutableSet.of( 17 "toString", 18 "hashCode", 19 "equals" 20 ); 21 22 public ImplementationValidator(RobolectricModel model, ProcessingEnvironment env) { 23 super(model, env, "org.robolectric.annotation.Implementation"); 24 } 25 26 @Override 27 public Void visitExecutable(ExecutableElement elem, TypeElement parent) { 28 Set<Modifier> modifiers = elem.getModifiers(); 29 if (!METHODS_ALLOWED_TO_BE_PUBLIC.contains(elem.getSimpleName().toString())) { 30 if (!modifiers.contains(Modifier.PUBLIC) && !modifiers.contains(Modifier.PROTECTED)) { 31 message(Kind.ERROR, "@Implementation methods should be protected (preferred) or public (deprecated)"); 32 } 33 } 34 35 // TODO: Check that it has the right signature 36 return null; 37 } 38 } 39