src/share/classes/com/sun/tools/classfile/TypeAnnotation.java
Print this page
*** 84,99 ****
Position position = new Position();
position.type = type;
switch (type) {
- // type cast
- case CAST:
// instanceof
case INSTANCEOF:
// new expression
case NEW:
position.offset = cr.readUnsignedShort();
break;
// local variable
case LOCAL_VARIABLE:
// resource variable
--- 84,100 ----
Position position = new Position();
position.type = type;
switch (type) {
// instanceof
case INSTANCEOF:
// new expression
case NEW:
+ // constructor/method reference receiver
+ case CONSTRUCTOR_REFERENCE:
+ case METHOD_REFERENCE:
position.offset = cr.readUnsignedShort();
break;
// local variable
case LOCAL_VARIABLE:
// resource variable
*** 140,164 ****
break;
// method parameter
case METHOD_FORMAL_PARAMETER:
position.parameter_index = cr.readUnsignedByte();
break;
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
position.offset = cr.readUnsignedShort();
position.type_index = cr.readUnsignedByte();
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
- // lambda formal parameter
- case LAMBDA_FORMAL_PARAMETER:
- position.parameter_index = cr.readUnsignedByte();
- break;
case UNKNOWN:
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
default:
throw new AssertionError("TypeAnnotation: Unknown target type: " + type);
}
--- 141,164 ----
break;
// method parameter
case METHOD_FORMAL_PARAMETER:
position.parameter_index = cr.readUnsignedByte();
break;
+ // type cast
+ case CAST:
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
+ case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
position.offset = cr.readUnsignedShort();
position.type_index = cr.readUnsignedByte();
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
case UNKNOWN:
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
default:
throw new AssertionError("TypeAnnotation: Unknown target type: " + type);
}
*** 175,200 ****
private static int position_length(Position pos) {
int n = 0;
n += 1; // TargetType tag is a byte
switch (pos.type) {
- // type cast
- case CAST:
// instanceof
case INSTANCEOF:
// new expression
case NEW:
! n += 2;
break;
// local variable
case LOCAL_VARIABLE:
// resource variable
case RESOURCE_VARIABLE:
n += 2; // table_length;
int table_length = pos.lvarOffset.length;
n += 2 * table_length; // offset
! n += 2 * table_length; // length;
n += 2 * table_length; // index
break;
// exception parameter
case EXCEPTION_PARAMETER:
n += 1; // exception_index
--- 175,201 ----
private static int position_length(Position pos) {
int n = 0;
n += 1; // TargetType tag is a byte
switch (pos.type) {
// instanceof
case INSTANCEOF:
// new expression
case NEW:
! // constructor/method reference receiver
! case CONSTRUCTOR_REFERENCE:
! case METHOD_REFERENCE:
! n += 2; // offset
break;
// local variable
case LOCAL_VARIABLE:
// resource variable
case RESOURCE_VARIABLE:
n += 2; // table_length;
int table_length = pos.lvarOffset.length;
n += 2 * table_length; // offset
! n += 2 * table_length; // length
n += 2 * table_length; // index
break;
// exception parameter
case EXCEPTION_PARAMETER:
n += 1; // exception_index
*** 204,214 ****
// Do nothing
break;
// type parameter
case CLASS_TYPE_PARAMETER:
case METHOD_TYPE_PARAMETER:
! n += 1; // parameter_index;
break;
// type parameter bound
case CLASS_TYPE_PARAMETER_BOUND:
case METHOD_TYPE_PARAMETER_BOUND:
n += 1; // parameter_index
--- 205,215 ----
// Do nothing
break;
// type parameter
case CLASS_TYPE_PARAMETER:
case METHOD_TYPE_PARAMETER:
! n += 1; // parameter_index
break;
// type parameter bound
case CLASS_TYPE_PARAMETER_BOUND:
case METHOD_TYPE_PARAMETER_BOUND:
n += 1; // parameter_index
*** 224,248 ****
break;
// method parameter
case METHOD_FORMAL_PARAMETER:
n += 1; // parameter_index
break;
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
n += 2; // offset
n += 1; // type index
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
- // lambda formal parameter
- case LAMBDA_FORMAL_PARAMETER:
- n += 1; // parameter_index
- break;
case UNKNOWN:
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
default:
throw new AssertionError("TypeAnnotation: Unknown target type: " + pos.type);
}
--- 225,248 ----
break;
// method parameter
case METHOD_FORMAL_PARAMETER:
n += 1; // parameter_index
break;
+ // type cast
+ case CAST:
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
+ case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
n += 2; // offset
n += 1; // type index
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
case UNKNOWN:
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
default:
throw new AssertionError("TypeAnnotation: Unknown target type: " + pos.type);
}
*** 375,390 ****
StringBuilder sb = new StringBuilder();
sb.append('[');
sb.append(type);
switch (type) {
- // type cast
- case CAST:
// instanceof
case INSTANCEOF:
// new expression
case NEW:
sb.append(", offset = ");
sb.append(offset);
break;
// local variable
case LOCAL_VARIABLE:
--- 375,391 ----
StringBuilder sb = new StringBuilder();
sb.append('[');
sb.append(type);
switch (type) {
// instanceof
case INSTANCEOF:
// new expression
case NEW:
+ // constructor/method reference receiver
+ case CONSTRUCTOR_REFERENCE:
+ case METHOD_REFERENCE:
sb.append(", offset = ");
sb.append(offset);
break;
// local variable
case LOCAL_VARIABLE:
*** 442,470 ****
// method parameter
case METHOD_FORMAL_PARAMETER:
sb.append(", param_index = ");
sb.append(parameter_index);
break;
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
sb.append(", offset = ");
sb.append(offset);
sb.append(", type_index = ");
sb.append(type_index);
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
- // lambda formal parameter
- case LAMBDA_FORMAL_PARAMETER:
- // TODO: also needs an offset?
- sb.append(", param_index = ");
- sb.append(parameter_index);
- break;
case UNKNOWN:
sb.append(", position UNKNOWN!");
break;
default:
throw new AssertionError("Unknown target type: " + type);
--- 443,468 ----
// method parameter
case METHOD_FORMAL_PARAMETER:
sb.append(", param_index = ");
sb.append(parameter_index);
break;
+ // type cast
+ case CAST:
// method/constructor/reference type argument
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
case METHOD_INVOCATION_TYPE_ARGUMENT:
+ case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
case METHOD_REFERENCE_TYPE_ARGUMENT:
sb.append(", offset = ");
sb.append(offset);
sb.append(", type_index = ");
sb.append(type_index);
break;
// We don't need to worry about these
case METHOD_RETURN:
case FIELD:
break;
case UNKNOWN:
sb.append(", position UNKNOWN!");
break;
default:
throw new AssertionError("Unknown target type: " + type);
*** 562,599 ****
RESOURCE_VARIABLE(0x41, true),
/** For annotations on an exception parameter. */
EXCEPTION_PARAMETER(0x42, true),
- /** For annotations on a typecast. */
- CAST(0x43, true),
-
/** For annotations on a type test. */
! INSTANCEOF(0x44, true),
/** For annotations on an object creation expression. */
! NEW(0x45, true),
/** For annotations on a type argument of an object creation expression. */
! CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x46, true),
/** For annotations on a type argument of a method call. */
! METHOD_INVOCATION_TYPE_ARGUMENT(0x47, true),
!
! /** For annotations on a lambda parameter type. */
! LAMBDA_FORMAL_PARAMETER(0x48, true),
! /** For annotations on a method reference. */
! METHOD_REFERENCE(0x49, true),
/** For annotations on a type argument of a method reference. */
! METHOD_REFERENCE_TYPE_ARGUMENT(0x50, true),
/** For annotations with an unknown target. */
UNKNOWN(0xFF);
! private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x50;
private final int targetTypeValue;
private final boolean isLocal;
private TargetType(int targetTypeValue) {
--- 560,600 ----
RESOURCE_VARIABLE(0x41, true),
/** For annotations on an exception parameter. */
EXCEPTION_PARAMETER(0x42, true),
/** For annotations on a type test. */
! INSTANCEOF(0x43, true),
/** For annotations on an object creation expression. */
! NEW(0x44, true),
!
! /** For annotations on a constructor reference receiver. */
! CONSTRUCTOR_REFERENCE(0x45, true),
!
! /** For annotations on a method reference receiver. */
! METHOD_REFERENCE(0x46, true),
!
! /** For annotations on a typecast. */
! CAST(0x47, true),
/** For annotations on a type argument of an object creation expression. */
! CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true),
/** For annotations on a type argument of a method call. */
! METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true),
! /** For annotations on a type argument of a constructor reference. */
! CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
/** For annotations on a type argument of a method reference. */
! METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true),
/** For annotations with an unknown target. */
UNKNOWN(0xFF);
! private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
private final int targetTypeValue;
private final boolean isLocal;
private TargetType(int targetTypeValue) {