1.1 --- a/src/share/classes/com/sun/tools/javac/code/TargetType.java Mon Jan 21 01:27:42 2013 -0500 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/TargetType.java Mon Feb 04 18:08:53 2013 -0500 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,10 +25,7 @@ 1.11 1.12 package com.sun.tools.javac.code; 1.13 1.14 -import java.util.EnumSet; 1.15 -import java.util.Set; 1.16 - 1.17 -import static com.sun.tools.javac.code.TargetType.TargetAttribute.*; 1.18 +import com.sun.tools.javac.util.Assert; 1.19 1.20 /** 1.21 * Describes the type of program element an extended annotation (or extended 1.22 @@ -44,178 +41,89 @@ 1.23 * This code and its internal interfaces are subject to change or 1.24 * deletion without notice.</b> 1.25 */ 1.26 +// Code duplicated in com.sun.tools.classfile.TypeAnnotation.TargetType 1.27 public enum TargetType { 1.28 + /** For annotations on a class type parameter declaration. */ 1.29 + CLASS_TYPE_PARAMETER(0x00), 1.30 1.31 - // 1.32 - // Some target types are commented out, because Java doesn't permit such 1.33 - // targets. They are included here to confirm that their omission is 1.34 - // intentional omission not an accidental omission. 1.35 - // 1.36 + /** For annotations on a method type parameter declaration. */ 1.37 + METHOD_TYPE_PARAMETER(0x01), 1.38 1.39 - /** For annotations on typecasts. */ 1.40 - TYPECAST(0x00, IsLocal), 1.41 + /** For annotations on the type of an "extends" or "implements" clause. */ 1.42 + CLASS_EXTENDS(0x10), 1.43 1.44 - /** For annotations on a type argument or nested array of a typecast. */ 1.45 - TYPECAST_GENERIC_OR_ARRAY(0x01, HasLocation, IsLocal), 1.46 + /** For annotations on a bound of a type parameter of a class. */ 1.47 + CLASS_TYPE_PARAMETER_BOUND(0x11), 1.48 1.49 - /** For annotations on type tests. */ 1.50 - INSTANCEOF(0x02, IsLocal), 1.51 + /** For annotations on a bound of a type parameter of a method. */ 1.52 + METHOD_TYPE_PARAMETER_BOUND(0x12), 1.53 1.54 - /** For annotations on a type argument or nested array of a type test. */ 1.55 - INSTANCEOF_GENERIC_OR_ARRAY(0x03, HasLocation, IsLocal), 1.56 + /** For annotations on a field. */ 1.57 + FIELD(0x13), 1.58 1.59 - /** For annotations on object creation expressions. */ 1.60 - NEW(0x04, IsLocal), 1.61 - 1.62 - /** 1.63 - * For annotations on a type argument or nested array of an object creation 1.64 - * expression. 1.65 - */ 1.66 - NEW_GENERIC_OR_ARRAY(0x05, HasLocation, IsLocal), 1.67 - 1.68 + /** For annotations on a method return type. */ 1.69 + METHOD_RETURN(0x14), 1.70 1.71 /** For annotations on the method receiver. */ 1.72 - METHOD_RECEIVER(0x06), 1.73 + METHOD_RECEIVER(0x15), 1.74 1.75 - // invalid location 1.76 - //@Deprecated METHOD_RECEIVER_GENERIC_OR_ARRAY(0x07, HasLocation), 1.77 - 1.78 - /** For annotations on local variables. */ 1.79 - LOCAL_VARIABLE(0x08, IsLocal), 1.80 - 1.81 - /** For annotations on a type argument or nested array of a local. */ 1.82 - LOCAL_VARIABLE_GENERIC_OR_ARRAY(0x09, HasLocation, IsLocal), 1.83 - 1.84 - // handled by regular annotations 1.85 - //@Deprecated METHOD_RETURN(0x0A), 1.86 - 1.87 - /** 1.88 - * For annotations on a type argument or nested array of a method return 1.89 - * type. 1.90 - */ 1.91 - METHOD_RETURN_GENERIC_OR_ARRAY(0x0B, HasLocation), 1.92 - 1.93 - // handled by regular annotations 1.94 - //@Deprecated METHOD_PARAMETER(0x0C), 1.95 - 1.96 - /** For annotations on a type argument or nested array of a method parameter. */ 1.97 - METHOD_PARAMETER_GENERIC_OR_ARRAY(0x0D, HasLocation), 1.98 - 1.99 - // handled by regular annotations 1.100 - //@Deprecated FIELD(0x0E), 1.101 - 1.102 - /** For annotations on a type argument or nested array of a field. */ 1.103 - FIELD_GENERIC_OR_ARRAY(0x0F, HasLocation), 1.104 - 1.105 - /** For annotations on a bound of a type parameter of a class. */ 1.106 - CLASS_TYPE_PARAMETER_BOUND(0x10, HasBound, HasParameter), 1.107 - 1.108 - /** 1.109 - * For annotations on a type argument or nested array of a bound of a type 1.110 - * parameter of a class. 1.111 - */ 1.112 - CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x11, HasBound, HasLocation, HasParameter), 1.113 - 1.114 - /** For annotations on a bound of a type parameter of a method. */ 1.115 - METHOD_TYPE_PARAMETER_BOUND(0x12, HasBound, HasParameter), 1.116 - 1.117 - /** 1.118 - * For annotations on a type argument or nested array of a bound of a type 1.119 - * parameter of a method. 1.120 - */ 1.121 - METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x13, HasBound, HasLocation, HasParameter), 1.122 - 1.123 - /** For annotations on the type of an "extends" or "implements" clause. */ 1.124 - CLASS_EXTENDS(0x14), 1.125 - 1.126 - /** For annotations on the inner type of an "extends" or "implements" clause. */ 1.127 - CLASS_EXTENDS_GENERIC_OR_ARRAY(0x15, HasLocation), 1.128 + /** For annotations on a method parameter. */ 1.129 + METHOD_FORMAL_PARAMETER(0x16), 1.130 1.131 /** For annotations on a throws clause in a method declaration. */ 1.132 - THROWS(0x16), 1.133 + THROWS(0x17), 1.134 1.135 - // invalid location 1.136 - //@Deprecated THROWS_GENERIC_OR_ARRAY(0x17, HasLocation), 1.137 + /** For annotations on a local variable. */ 1.138 + LOCAL_VARIABLE(0x40, true), 1.139 1.140 - /** For annotations in type arguments of object creation expressions. */ 1.141 - NEW_TYPE_ARGUMENT(0x18, IsLocal), 1.142 - NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x19, HasLocation, IsLocal), 1.143 + /** For annotations on a resource variable. */ 1.144 + RESOURCE_VARIABLE(0x41, true), 1.145 1.146 - METHOD_TYPE_ARGUMENT(0x1A, IsLocal), 1.147 - METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x1B, HasLocation, IsLocal), 1.148 + /** For annotations on an exception parameter. */ 1.149 + EXCEPTION_PARAMETER(0x42, true), 1.150 1.151 - WILDCARD_BOUND(0x1C, HasBound), 1.152 - WILDCARD_BOUND_GENERIC_OR_ARRAY(0x1D, HasBound, HasLocation), 1.153 + /** For annotations on a typecast. */ 1.154 + CAST(0x43, true), 1.155 1.156 - CLASS_LITERAL(0x1E, IsLocal), 1.157 - CLASS_LITERAL_GENERIC_OR_ARRAY(0x1F, HasLocation, IsLocal), 1.158 + /** For annotations on a type test. */ 1.159 + INSTANCEOF(0x44, true), 1.160 1.161 - METHOD_TYPE_PARAMETER(0x20, HasParameter), 1.162 + /** For annotations on an object creation expression. */ 1.163 + NEW(0x45, true), 1.164 1.165 - // invalid location 1.166 - //@Deprecated METHOD_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x21, HasLocation, HasParameter), 1.167 + /** For annotations on a type argument of an object creation expression. */ 1.168 + CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x46, true), 1.169 1.170 - CLASS_TYPE_PARAMETER(0x22, HasParameter), 1.171 + /** For annotations on a type argument of a method call. */ 1.172 + METHOD_INVOCATION_TYPE_ARGUMENT(0x47, true), 1.173 1.174 - // invalid location 1.175 - //@Deprecated CLASS_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x23, HasLocation, HasParameter), 1.176 + /** For annotations on a lambda parameter type. */ 1.177 + LAMBDA_FORMAL_PARAMETER(0x48, true), 1.178 + 1.179 + /** For annotations on a method reference. */ 1.180 + METHOD_REFERENCE(0x49, true), 1.181 + 1.182 + /** For annotations on a type argument of a method reference. */ 1.183 + METHOD_REFERENCE_TYPE_ARGUMENT(0x50, true), 1.184 1.185 /** For annotations with an unknown target. */ 1.186 - UNKNOWN(-1); 1.187 + UNKNOWN(0xFF); 1.188 1.189 - static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22; 1.190 + private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x92; 1.191 1.192 private final int targetTypeValue; 1.193 - private final Set<TargetAttribute> flags; 1.194 + private final boolean isLocal; 1.195 1.196 - TargetType(int targetTypeValue, TargetAttribute... attributes) { 1.197 - if (targetTypeValue < Byte.MIN_VALUE 1.198 - || targetTypeValue > Byte.MAX_VALUE) 1.199 - throw new AssertionError("attribute type value needs to be a byte: " + targetTypeValue); 1.200 - this.targetTypeValue = (byte)targetTypeValue; 1.201 - flags = EnumSet.noneOf(TargetAttribute.class); 1.202 - for (TargetAttribute attr : attributes) 1.203 - flags.add(attr); 1.204 + private TargetType(int targetTypeValue) { 1.205 + this(targetTypeValue, false); 1.206 } 1.207 1.208 - /** 1.209 - * Returns whether or not this TargetType represents an annotation whose 1.210 - * target is an inner type of a generic or array type. 1.211 - * 1.212 - * @return true if this TargetType represents an annotation on an inner 1.213 - * type, false otherwise 1.214 - */ 1.215 - public boolean hasLocation() { 1.216 - return flags.contains(HasLocation); 1.217 - } 1.218 - 1.219 - public TargetType getGenericComplement() { 1.220 - if (hasLocation()) 1.221 - return this; 1.222 - else 1.223 - return fromTargetTypeValue(targetTypeValue() + 1); 1.224 - } 1.225 - 1.226 - /** 1.227 - * Returns whether or not this TargetType represents an annotation whose 1.228 - * target has a parameter index. 1.229 - * 1.230 - * @return true if this TargetType has a parameter index, 1.231 - * false otherwise 1.232 - */ 1.233 - public boolean hasParameter() { 1.234 - return flags.contains(HasParameter); 1.235 - } 1.236 - 1.237 - /** 1.238 - * Returns whether or not this TargetType represents an annotation whose 1.239 - * target is a type parameter bound. 1.240 - * 1.241 - * @return true if this TargetType represents an type parameter bound 1.242 - * annotation, false otherwise 1.243 - */ 1.244 - public boolean hasBound() { 1.245 - return flags.contains(HasBound); 1.246 + private TargetType(int targetTypeValue, boolean isLocal) { 1.247 + if (targetTypeValue < 0 1.248 + || targetTypeValue > 255) 1.249 + Assert.error("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue)); 1.250 + this.targetTypeValue = targetTypeValue; 1.251 + this.isLocal = isLocal; 1.252 } 1.253 1.254 /** 1.255 @@ -226,7 +134,7 @@ 1.256 * member declaration signature tree 1.257 */ 1.258 public boolean isLocal() { 1.259 - return flags.contains(IsLocal); 1.260 + return isLocal; 1.261 } 1.262 1.263 public int targetTypeValue() { 1.264 @@ -239,7 +147,7 @@ 1.265 targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1]; 1.266 TargetType[] alltargets = values(); 1.267 for (TargetType target : alltargets) { 1.268 - if (target.targetTypeValue >= 0) 1.269 + if (target.targetTypeValue != UNKNOWN.targetTypeValue) 1.270 targets[target.targetTypeValue] = target; 1.271 } 1.272 for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) { 1.273 @@ -249,22 +157,18 @@ 1.274 } 1.275 1.276 public static boolean isValidTargetTypeValue(int tag) { 1.277 - if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue)) 1.278 + if (tag == UNKNOWN.targetTypeValue) 1.279 return true; 1.280 1.281 return (tag >= 0 && tag < targets.length); 1.282 } 1.283 1.284 public static TargetType fromTargetTypeValue(int tag) { 1.285 - if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue)) 1.286 + if (tag == UNKNOWN.targetTypeValue) 1.287 return UNKNOWN; 1.288 1.289 if (tag < 0 || tag >= targets.length) 1.290 - throw new IllegalArgumentException("Unknown TargetType: " + tag); 1.291 + Assert.error("Unknown TargetType: " + tag); 1.292 return targets[tag]; 1.293 } 1.294 - 1.295 - static enum TargetAttribute { 1.296 - HasLocation, HasParameter, HasBound, IsLocal; 1.297 - } 1.298 }