1 package org.junit.runners.model; 2 3 import java.lang.reflect.Modifier; 4 import java.util.List; 5 6 /** 7 * Parent class for {@link FrameworkField} and {@link FrameworkMethod} 8 * 9 * @since 4.7 10 */ 11 public abstract class FrameworkMember<T extends FrameworkMember<T>> implements 12 Annotatable { isShadowedBy(T otherMember)13 abstract boolean isShadowedBy(T otherMember); 14 handlePossibleBridgeMethod(List<T> members)15 T handlePossibleBridgeMethod(List<T> members) { 16 for (int i = members.size() - 1; i >=0; i--) { 17 T otherMember = members.get(i); 18 if (isShadowedBy(otherMember)) { 19 if (otherMember.isBridgeMethod()) { 20 /* 21 * We need to return the previously-encountered bridge method 22 * because JUnit won't be able to call the parent method, 23 * because the parent class isn't public. 24 */ 25 members.remove(i); 26 return otherMember; 27 } 28 // We found a shadowed member that isn't a bridge method. Ignore it. 29 return null; 30 } 31 } 32 // No shadow or bridge method found. The caller should add *this* member. 33 return (T) this; 34 } 35 isBridgeMethod()36 abstract boolean isBridgeMethod(); 37 getModifiers()38 protected abstract int getModifiers(); 39 40 /** 41 * Returns true if this member is static, false if not. 42 */ isStatic()43 public boolean isStatic() { 44 return Modifier.isStatic(getModifiers()); 45 } 46 47 /** 48 * Returns true if this member is public, false if not. 49 */ isPublic()50 public boolean isPublic() { 51 return Modifier.isPublic(getModifiers()); 52 } 53 getName()54 public abstract String getName(); 55 getType()56 public abstract Class<?> getType(); 57 getDeclaringClass()58 public abstract Class<?> getDeclaringClass(); 59 } 60