langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TargetType.java
changeset 26532 aa84b6606229
parent 25874 83c19f00452c
equal deleted inserted replaced
26531:c32c9586ea94 26532:aa84b6606229
   105 
   105 
   106     /** For annotations on a type argument of a constructor reference. */
   106     /** For annotations on a type argument of a constructor reference. */
   107     CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
   107     CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
   108 
   108 
   109     /** For annotations on a type argument of a method reference. */
   109     /** For annotations on a type argument of a method reference. */
   110     METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true);
   110     METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true),
       
   111 
       
   112     /** For annotations with an unknown target. */
       
   113     UNKNOWN(0xFF);
   111 
   114 
   112     private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
   115     private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
   113 
   116 
   114     private final int targetTypeValue;
   117     private final int targetTypeValue;
   115     private final boolean isLocal;
   118     private final boolean isLocal;
   145 
   148 
   146     static {
   149     static {
   147         targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
   150         targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
   148         TargetType[] alltargets = values();
   151         TargetType[] alltargets = values();
   149         for (TargetType target : alltargets) {
   152         for (TargetType target : alltargets) {
       
   153             if (target.targetTypeValue != UNKNOWN.targetTypeValue)
   150                 targets[target.targetTypeValue] = target;
   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;
   151         }
   159         }
   152     }
   160     }
   153 
   161 
   154     public static boolean isValidTargetTypeValue(int tag) {
   162     public static boolean isValidTargetTypeValue(int tag) {
       
   163         if (tag == UNKNOWN.targetTypeValue)
       
   164             return true;
       
   165 
   155         return (tag >= 0 && tag < targets.length);
   166         return (tag >= 0 && tag < targets.length);
   156     }
   167     }
   157 
   168 
   158     public static TargetType fromTargetTypeValue(int tag) {
   169     public static TargetType fromTargetTypeValue(int tag) {
       
   170         if (tag == UNKNOWN.targetTypeValue)
       
   171             return UNKNOWN;
       
   172 
   159         if (tag < 0 || tag >= targets.length)
   173         if (tag < 0 || tag >= targets.length)
   160             Assert.error("Unknown TargetType: " + tag);
   174             Assert.error("Unknown TargetType: " + tag);
   161         return targets[tag];
   175         return targets[tag];
   162     }
   176     }
   163 }
   177 }