Java Code Examples for com.sun.tools.classfile.TypeAnnotation.Position.TypePathEntry#bytesPerEntry()
The following examples show how to use
com.sun.tools.classfile.TypeAnnotation.Position.TypePathEntry#bytesPerEntry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeAnnotation.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Decode the binary representation for a type path and set * the {@code location} field. * * @param list The bytecode representation of the type path. */ public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) { List<TypePathEntry> loc = new ArrayList<TypePathEntry>(list.size() / TypePathEntry.bytesPerEntry); int idx = 0; while (idx < list.size()) { if (idx + 1 == list.size()) { throw new AssertionError("Could not decode type path: " + list); } loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); idx += 2; } return loc; }
Example 2
Source File: TypeAnnotation.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 3
Source File: TypeAnnotation.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Decode the binary representation for a type path and set * the {@code location} field. * * @param list The bytecode representation of the type path. */ public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) { List<TypePathEntry> loc = new ArrayList<>(list.size() / TypePathEntry.bytesPerEntry); int idx = 0; while (idx < list.size()) { if (idx + 1 == list.size()) { throw new AssertionError("Could not decode type path: " + list); } loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); idx += 2; } return loc; }
Example 4
Source File: TypeAnnotation.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<Integer>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 5
Source File: TypeAnnotation.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Decode the binary representation for a type path and set * the {@code location} field. * * @param list The bytecode representation of the type path. */ public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) { List<TypePathEntry> loc = new ArrayList<TypePathEntry>(list.size() / TypePathEntry.bytesPerEntry); int idx = 0; while (idx < list.size()) { if (idx + 1 == list.size()) { throw new AssertionError("Could not decode type path: " + list); } loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); idx += 2; } return loc; }
Example 6
Source File: TypeAnnotation.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<Integer>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 7
Source File: TypeAnnotation.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<Integer>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 8
Source File: TypeAnnotation.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Decode the binary representation for a type path and set * the {@code location} field. * * @param list The bytecode representation of the type path. */ public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) { List<TypePathEntry> loc = new ArrayList<TypePathEntry>(list.size() / TypePathEntry.bytesPerEntry); int idx = 0; while (idx < list.size()) { if (idx + 1 == list.size()) { throw new AssertionError("Could not decode type path: " + list); } loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); idx += 2; } return loc; }
Example 9
Source File: TypeAnnotation.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<Integer>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 10
Source File: TypeAnnotation.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Decode the binary representation for a type path and set * the {@code location} field. * * @param list The bytecode representation of the type path. */ public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) { List<TypePathEntry> loc = new ArrayList<TypePathEntry>(list.size() / TypePathEntry.bytesPerEntry); int idx = 0; while (idx < list.size()) { if (idx + 1 == list.size()) { throw new AssertionError("Could not decode type path: " + list); } loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); idx += 2; } return loc; }
Example 11
Source File: TypeAnnotation.java From hottub with GNU General Public License v2.0 | 5 votes |
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) { List<Integer> loc = new ArrayList<Integer>(locs.size() * TypePathEntry.bytesPerEntry); for (TypePathEntry tpe : locs) { loc.add(tpe.tag.tag); loc.add(tpe.arg); } return loc; }
Example 12
Source File: TypeAnnotation.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 13
Source File: TypeAnnotation.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 += 2; // exception_index break; // method receiver case METHOD_RECEIVER: // 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 n += 1; // bound_index break; // class extends or implements clause case CLASS_EXTENDS: n += 2; // type_index break; // throws case THROWS: n += 2; // type_index 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); } { n += 1; // length n += TypePathEntry.bytesPerEntry * pos.location.size(); // bytes for actual array } return n; }
Example 14
Source File: TypeAnnotation.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 15
Source File: TypeAnnotation.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 16
Source File: TypeAnnotation.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 17
Source File: TypeAnnotation.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 18
Source File: TypeAnnotation.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: position.type_index = cr.readUnsignedShort();; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 19
Source File: TypeAnnotation.java From hottub with GNU General Public License v2.0 | 4 votes |
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { // Copied from ClassReader int tag = cr.readUnsignedByte(); // TargetType tag is a byte if (!TargetType.isValidTargetTypeValue(tag)) throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); TargetType type = TargetType.fromTargetTypeValue(tag); 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 case RESOURCE_VARIABLE: int table_length = cr.readUnsignedShort(); position.lvarOffset = new int[table_length]; position.lvarLength = new int[table_length]; position.lvarIndex = new int[table_length]; for (int i = 0; i < table_length; ++i) { position.lvarOffset[i] = cr.readUnsignedShort(); position.lvarLength[i] = cr.readUnsignedShort(); position.lvarIndex[i] = cr.readUnsignedShort(); } break; // exception parameter case EXCEPTION_PARAMETER: position.exception_index = cr.readUnsignedShort(); break; // method receiver case METHOD_RECEIVER: // Do nothing break; // type parameter case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: position.parameter_index = cr.readUnsignedByte(); break; // type parameter bound case CLASS_TYPE_PARAMETER_BOUND: case METHOD_TYPE_PARAMETER_BOUND: position.parameter_index = cr.readUnsignedByte(); position.bound_index = cr.readUnsignedByte(); break; // class extends or implements clause case CLASS_EXTENDS: int in = cr.readUnsignedShort(); if (in == 0xFFFF) in = -1; position.type_index = in; break; // throws case THROWS: position.type_index = cr.readUnsignedShort(); 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); } { // Write type path int len = cr.readUnsignedByte(); List<Integer> loc = new ArrayList<Integer>(len); for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) loc.add(cr.readUnsignedByte()); position.location = Position.getTypePathFromBinary(loc); } return position; }
Example 20
Source File: TypeAnnotation.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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 += 2; // exception_index break; // method receiver case METHOD_RECEIVER: // 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 n += 1; // bound_index break; // class extends or implements clause case CLASS_EXTENDS: n += 2; // type_index break; // throws case THROWS: n += 2; // type_index 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); } { n += 1; // length n += TypePathEntry.bytesPerEntry * pos.location.size(); // bytes for actual array } return n; }