KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > attributes > Target


1 package org.apache.commons.attributes;
2
3 /**
4  * Attribute indicating what elements an attribute may be applied to.
5  * This is checked at runtime. If the attribute is absent, it defaults
6  * to Target.ALL.
7  *
8  * <p>This attribute is intended to be used with attribute classes:
9  *
10  * <pre><code>
11  * / **
12  * * MyAttribute can only be applied to classes and fields, not methods.
13  * * @@Target(Target.CLASS | Target.FIELD)
14  * * /
15  * public class MyAttribute { ... }
16  * </code></pre>
17  */

18 public class Target {
19     
20     /**
21      * Indicates that the attribute can be applied to a class or interface.
22      */

23     public static final int CLASS = 1;
24     
25     /**
26      * Indicates that the attribute can be applied to a field.
27      */

28     public static final int FIELD = 2;
29     
30     /**
31      * Indicates that the attribute can be applied to a method.
32      */

33     public static final int METHOD = 4;
34     
35     /**
36      * Indicates that the attribute can be applied to a constructor.
37      */

38     public static final int CONSTRUCTOR = 8;
39     
40     /**
41      * Indicates that the attribute can be applied to a method parameter.
42      */

43     public static final int METHOD_PARAMETER = 16;
44     
45     /**
46      * Indicates that the attribute can be applied to a constructor parameter.
47      */

48     public static final int CONSTRUCTOR_PARAMETER = 32;
49     
50     /**
51      * Indicates that the attribute can be applied to a method return value.
52      */

53     public static final int RETURN = 64;
54     
55     /**
56      * Indicates that the attribute can be applied to a parameter of a method or a constructor.
57      * It is equal to <code>METHOD_PARAMETER | CONSTRUCTOR_PARAMETER</code>.
58      */

59     public static final int PARAMETER = METHOD_PARAMETER | CONSTRUCTOR_PARAMETER;
60     
61     /**
62      * Indicates that the attribute can be applied to any program element.
63      */

64     public static final int ALL = CLASS | FIELD | METHOD | CONSTRUCTOR | PARAMETER | RETURN;
65     
66     private final int flags;
67     
68     /**
69      * Creates a new target attribute.
70      *
71      * @param flags a bitwise or of flags indicating the allowed targets.
72      */

73     public Target (int flags) {
74         this.flags = flags;
75     }
76     
77     /**
78      * Returns an int that is the bitwise or of the allowed target flags.
79      */

80     public int getFlags () {
81         return flags;
82     }
83     
84 }
Popular Tags