001    package org.junit.runners.model;
002    
003    import java.lang.reflect.Modifier;
004    import java.util.List;
005    
006    /**
007     * Parent class for {@link FrameworkField} and {@link FrameworkMethod}
008     *
009     * @since 4.7
010     */
011    public abstract class FrameworkMember<T extends FrameworkMember<T>> implements
012            Annotatable {
013        abstract boolean isShadowedBy(T otherMember);
014    
015        T handlePossibleBridgeMethod(List<T> members) {
016            for (int i = members.size() - 1; i >=0; i--) {
017                T otherMember = members.get(i);
018                if (isShadowedBy(otherMember)) {
019                    if (otherMember.isBridgeMethod()) {
020                        /*
021                         *  We need to return the previously-encountered bridge method
022                         *  because JUnit won't be able to call the parent method,
023                         *  because the parent class isn't public.
024                         */
025                        members.remove(i);
026                        return otherMember;
027                    }
028                    // We found a shadowed member that isn't a bridge method. Ignore it.
029                    return null;
030                }
031            }
032            // No shadow or bridge method found. The caller should add *this* member.
033            return (T) this;
034        }
035    
036        abstract boolean isBridgeMethod();
037    
038        protected abstract int getModifiers();
039    
040        /**
041         * Returns true if this member is static, false if not.
042         */
043        public boolean isStatic() {
044            return Modifier.isStatic(getModifiers());
045        }
046    
047        /**
048         * Returns true if this member is public, false if not.
049         */
050        public boolean isPublic() {
051            return Modifier.isPublic(getModifiers());
052        }
053    
054        public abstract String getName();
055    
056        public abstract Class<?> getType();
057    
058        public abstract Class<?> getDeclaringClass();
059    }