1 package org.junit.runners.model;
2 
3 import java.lang.annotation.Annotation;
4 import java.lang.reflect.Field;
5 import java.lang.reflect.Modifier;
6 
7 import 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  */
13 public class FrameworkField extends FrameworkMember<FrameworkField> {
14 	private final Field fField;
15 
FrameworkField(Field field)16 	FrameworkField(Field field) {
17 		fField= field;
18 	}
19 
getName()20 	public String getName() {
21 		return getField().getName();
22 	}
23 
24 	@Override
getAnnotations()25 	public Annotation[] getAnnotations() {
26 		return fField.getAnnotations();
27 	}
28 
isPublic()29 	public boolean isPublic() {
30 		int modifiers= fField.getModifiers();
31 		return Modifier.isPublic(modifiers);
32 	}
33 
34 	@Override
isShadowedBy(FrameworkField otherMember)35 	public boolean isShadowedBy(FrameworkField otherMember) {
36 		return otherMember.getName().equals(getName());
37 	}
38 
isStatic()39 	public boolean isStatic() {
40 		int modifiers= fField.getModifiers();
41 		return Modifier.isStatic(modifiers);
42 	}
43 
44 	/**
45 	 * @return the underlying java Field
46 	 */
getField()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 	 */
getType()55 	public Class<?> getType() {
56 		return fField.getType();
57 	}
58 
59 	/**
60 	 * Attempts to retrieve the value of this field on {@code target}
61 	 */
get(Object target)62 	public Object get(Object target) throws IllegalArgumentException, IllegalAccessException {
63 		return fField.get(target);
64 	}
65 }
66