1. package org.apache.commons.attributes;
  2. /**
  3. * Attribute indicating what elements an attribute may be applied to.
  4. * This is checked at runtime. If the attribute is absent, it defaults
  5. * to Target.ALL.
  6. *
  7. * <p>This attribute is intended to be used with attribute classes:
  8. *
  9. * <pre><code>
  10. * / **
  11. * * MyAttribute can only be applied to classes and fields, not methods.
  12. * * @@Target(Target.CLASS | Target.FIELD)
  13. * * /
  14. * public class MyAttribute { ... }
  15. * </code></pre>
  16. */
  17. public class Target {
  18. /**
  19. * Indicates that the attribute can be applied to a class or interface.
  20. */
  21. public static final int CLASS = 1;
  22. /**
  23. * Indicates that the attribute can be applied to a field.
  24. */
  25. public static final int FIELD = 2;
  26. /**
  27. * Indicates that the attribute can be applied to a method.
  28. */
  29. public static final int METHOD = 4;
  30. /**
  31. * Indicates that the attribute can be applied to a constructor.
  32. */
  33. public static final int CONSTRUCTOR = 8;
  34. /**
  35. * Indicates that the attribute can be applied to a method parameter.
  36. */
  37. public static final int METHOD_PARAMETER = 16;
  38. /**
  39. * Indicates that the attribute can be applied to a constructor parameter.
  40. */
  41. public static final int CONSTRUCTOR_PARAMETER = 32;
  42. /**
  43. * Indicates that the attribute can be applied to a method return value.
  44. */
  45. public static final int RETURN = 64;
  46. /**
  47. * Indicates that the attribute can be applied to a parameter of a method or a constructor.
  48. * It is equal to <code>METHOD_PARAMETER | CONSTRUCTOR_PARAMETER</code>.
  49. */
  50. public static final int PARAMETER = METHOD_PARAMETER | CONSTRUCTOR_PARAMETER;
  51. /**
  52. * Indicates that the attribute can be applied to any program element.
  53. */
  54. public static final int ALL = CLASS | FIELD | METHOD | CONSTRUCTOR | PARAMETER | RETURN;
  55. private final int flags;
  56. /**
  57. * Creates a new target attribute.
  58. *
  59. * @param flags a bitwise or of flags indicating the allowed targets.
  60. */
  61. public Target (int flags) {
  62. this.flags = flags;
  63. }
  64. /**
  65. * Returns an int that is the bitwise or of the allowed target flags.
  66. */
  67. public int getFlags () {
  68. return flags;
  69. }
  70. }