src/share/classes/com/sun/tools/javac/code/TargetType.java

Print this page




  90 
  91     /** For annotations on a constructor reference receiver. */
  92     CONSTRUCTOR_REFERENCE(0x45, true),
  93 
  94     /** For annotations on a method reference receiver. */
  95     METHOD_REFERENCE(0x46, true),
  96 
  97     /** For annotations on a typecast. */
  98     CAST(0x47, true),
  99 
 100     /** For annotations on a type argument of an object creation expression. */
 101     CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true),
 102 
 103     /** For annotations on a type argument of a method call. */
 104     METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true),
 105 
 106     /** For annotations on a type argument of a constructor reference. */
 107     CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
 108 
 109     /** For annotations on a type argument of a method reference. */
 110     METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true),
 111 
 112     /** For annotations with an unknown target. */
 113     UNKNOWN(0xFF);
 114 
 115     private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
 116 
 117     private final int targetTypeValue;
 118     private final boolean isLocal;
 119 
 120     private TargetType(int targetTypeValue) {
 121         this(targetTypeValue, false);
 122     }
 123 
 124     private TargetType(int targetTypeValue, boolean isLocal) {
 125         if (targetTypeValue < 0
 126                 || targetTypeValue > 255)
 127                 Assert.error("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue));
 128         this.targetTypeValue = targetTypeValue;
 129         this.isLocal = isLocal;
 130     }
 131 
 132     /**
 133      * Returns whether or not this TargetType represents an annotation whose
 134      * target is exclusively a tree in a method body
 135      *
 136      * Note: wildcard bound targets could target a local tree and a class
 137      * member declaration signature tree
 138      */
 139     public boolean isLocal() {
 140         return isLocal;
 141     }
 142 
 143     public int targetTypeValue() {
 144         return this.targetTypeValue;
 145     }
 146 
 147     private static final TargetType[] targets;
 148 
 149     static {
 150         targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
 151         TargetType[] alltargets = values();
 152         for (TargetType target : alltargets) {
 153             if (target.targetTypeValue != UNKNOWN.targetTypeValue)
 154                 targets[target.targetTypeValue] = target;
 155         }
 156         for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) {
 157             if (targets[i] == null)
 158                 targets[i] = UNKNOWN;
 159         }
 160     }
 161 
 162     public static boolean isValidTargetTypeValue(int tag) {
 163         if (tag == UNKNOWN.targetTypeValue)
 164             return true;
 165 
 166         return (tag >= 0 && tag < targets.length);
 167     }
 168 
 169     public static TargetType fromTargetTypeValue(int tag) {
 170         if (tag == UNKNOWN.targetTypeValue)
 171             return UNKNOWN;
 172 
 173         if (tag < 0 || tag >= targets.length)
 174             Assert.error("Unknown TargetType: " + tag);
 175         return targets[tag];
 176     }
 177 }


  90 
  91     /** For annotations on a constructor reference receiver. */
  92     CONSTRUCTOR_REFERENCE(0x45, true),
  93 
  94     /** For annotations on a method reference receiver. */
  95     METHOD_REFERENCE(0x46, true),
  96 
  97     /** For annotations on a typecast. */
  98     CAST(0x47, true),
  99 
 100     /** For annotations on a type argument of an object creation expression. */
 101     CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true),
 102 
 103     /** For annotations on a type argument of a method call. */
 104     METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true),
 105 
 106     /** For annotations on a type argument of a constructor reference. */
 107     CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
 108 
 109     /** For annotations on a type argument of a method reference. */
 110     METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true);



 111 
 112     private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
 113 
 114     private final int targetTypeValue;
 115     private final boolean isLocal;
 116 
 117     private TargetType(int targetTypeValue) {
 118         this(targetTypeValue, false);
 119     }
 120 
 121     private TargetType(int targetTypeValue, boolean isLocal) {
 122         if (targetTypeValue < 0
 123                 || targetTypeValue > 255)
 124                 Assert.error("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue));
 125         this.targetTypeValue = targetTypeValue;
 126         this.isLocal = isLocal;
 127     }
 128 
 129     /**
 130      * Returns whether or not this TargetType represents an annotation whose
 131      * target is exclusively a tree in a method body
 132      *
 133      * Note: wildcard bound targets could target a local tree and a class
 134      * member declaration signature tree
 135      */
 136     public boolean isLocal() {
 137         return isLocal;
 138     }
 139 
 140     public int targetTypeValue() {
 141         return this.targetTypeValue;
 142     }
 143 
 144     private static final TargetType[] targets;
 145 
 146     static {
 147         targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
 148         TargetType[] alltargets = values();
 149         for (TargetType target : alltargets) {

 150             targets[target.targetTypeValue] = target;
 151         }




 152     }
 153 
 154     public static boolean isValidTargetTypeValue(int tag) {



 155         return (tag >= 0 && tag < targets.length);
 156     }
 157 
 158     public static TargetType fromTargetTypeValue(int tag) {



 159         if (tag < 0 || tag >= targets.length)
 160             Assert.error("Unknown TargetType: " + tag);
 161         return targets[tag];
 162     }
 163 }