1package org.junit.runners.model;
2
3import java.lang.annotation.Annotation;
4import java.lang.reflect.Field;
5import java.lang.reflect.Modifier;
6
7import org.junit.runners.BlockJUnit4ClassRunner;
8
9/**
10 * Represents a field on a test class (currently used only for Rules in
11 * {@link BlockJUnit4ClassRunner}, but custom runners can make other uses)
12 */
13public class FrameworkField extends FrameworkMember<FrameworkField> {
14	private final Field fField;
15
16	FrameworkField(Field field) {
17		fField= field;
18	}
19
20	public String getName() {
21		return getField().getName();
22	}
23
24	@Override
25	public Annotation[] getAnnotations() {
26		return fField.getAnnotations();
27	}
28
29	public boolean isPublic() {
30		int modifiers= fField.getModifiers();
31		return Modifier.isPublic(modifiers);
32	}
33
34	@Override
35	public boolean isShadowedBy(FrameworkField otherMember) {
36		return otherMember.getName().equals(getName());
37	}
38
39	public boolean isStatic() {
40		int modifiers= fField.getModifiers();
41		return Modifier.isStatic(modifiers);
42	}
43
44	/**
45	 * @return the underlying java Field
46	 */
47	public Field getField() {
48		return fField;
49	}
50
51	/**
52	 * @return the underlying Java Field type
53	 * @see java.lang.reflect.Field#getType()
54	 */
55	public Class<?> getType() {
56		return fField.getType();
57	}
58
59	/**
60	 * Attempts to retrieve the value of this field on {@code target}
61	 */
62	public Object get(Object target) throws IllegalArgumentException, IllegalAccessException {
63		return fField.get(target);
64	}
65}
66