aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/runners/model/FrameworkField.java
blob: 4a4d4a4586454dd6b3a4ee8296e3fe9f27753dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.junit.runners.model;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import org.junit.runners.BlockJUnit4ClassRunner;

/**
 * Represents a field on a test class (currently used only for Rules in
 * {@link BlockJUnit4ClassRunner}, but custom runners can make other uses)
 */
public class FrameworkField extends FrameworkMember<FrameworkField> {
	private final Field fField;

	FrameworkField(Field field) {
		fField= field;
	}

	public String getName() {
		return getField().getName();
	}

	@Override
	public Annotation[] getAnnotations() {
		return fField.getAnnotations();
	}

	public boolean isPublic() {
		int modifiers= fField.getModifiers();
		return Modifier.isPublic(modifiers);
	}

	@Override
	public boolean isShadowedBy(FrameworkField otherMember) {
		return otherMember.getName().equals(getName());
	}

	public boolean isStatic() {
		int modifiers= fField.getModifiers();
		return Modifier.isStatic(modifiers);
	}

	/**
	 * @return the underlying java Field
	 */
	public Field getField() {
		return fField;
	}

	/**
	 * @return the underlying Java Field type
	 * @see java.lang.reflect.Field#getType()
	 */
	public Class<?> getType() {
		return fField.getType();
	}

	/**
	 * Attempts to retrieve the value of this field on {@code target}
	 */
	public Object get(Object target) throws IllegalArgumentException, IllegalAccessException {
		return fField.get(target);
	}
}