EnumAFT.java revision 52336551b494480cf81134123d390900ce145d16
1package annotations.field;
2
3import checkers.nullness.quals.*;
4import checkers.javari.quals.*;
5
6/**
7 * An {@link EnumAFT} is the type of an annotation field that can hold an
8 * constant from a certain enumeration type.
9 */
10public final /*@ReadOnly*/ class EnumAFT extends ScalarAFT {
11
12    /**
13     * The name of the enumeration type whose constants the annotation field
14     * can hold.
15     */
16    public final String typeName;
17
18    /**
19     * Constructs an {@link EnumAFT} for an annotation field that can hold
20     * constants of the enumeration type with the given name.
21     */
22    public EnumAFT(String typeName) {
23        this.typeName = typeName;
24    }
25
26    /**
27     * {@inheritDoc}
28     */
29    @Override
30    public boolean isValidValue(Object o) {
31        // return o instanceof Enum;
32        return o instanceof String;
33    }
34
35    /**
36     * {@inheritDoc}
37     */
38    @Override
39    public  String toString() {
40        return "enum " + typeName;
41    }
42
43    /**
44     * {@inheritDoc}
45     */
46    @Override
47    public String format(Object o) {
48        return typeName + "." + o.toString();
49    }
50
51}
52