1453 1454 TypeAnnotationProxy readTypeAnnotation() { 1455 TypeAnnotationPosition position = readPosition(); 1456 CompoundAnnotationProxy proxy = readCompoundAnnotation(); 1457 1458 return new TypeAnnotationProxy(proxy, position); 1459 } 1460 1461 TypeAnnotationPosition readPosition() { 1462 int tag = nextByte(); // TargetType tag is a byte 1463 1464 if (!TargetType.isValidTargetTypeValue(tag)) 1465 throw this.badClassFile("bad.type.annotation.value", String.format("0x%02X", tag)); 1466 1467 TypeAnnotationPosition position = new TypeAnnotationPosition(); 1468 TargetType type = TargetType.fromTargetTypeValue(tag); 1469 1470 position.type = type; 1471 1472 switch (type) { 1473 // type cast 1474 case CAST: 1475 // instanceof 1476 case INSTANCEOF: 1477 // new expression 1478 case NEW: 1479 position.offset = nextChar(); 1480 break; 1481 // local variable 1482 case LOCAL_VARIABLE: 1483 // resource variable 1484 case RESOURCE_VARIABLE: 1485 int table_length = nextChar(); 1486 position.lvarOffset = new int[table_length]; 1487 position.lvarLength = new int[table_length]; 1488 position.lvarIndex = new int[table_length]; 1489 1490 for (int i = 0; i < table_length; ++i) { 1491 position.lvarOffset[i] = nextChar(); 1492 position.lvarLength[i] = nextChar(); 1493 position.lvarIndex[i] = nextChar(); 1494 } 1495 break; 1496 // exception parameter 1497 case EXCEPTION_PARAMETER: 1498 position.exception_index = nextByte(); 1507 position.parameter_index = nextByte(); 1508 break; 1509 // type parameter bound 1510 case CLASS_TYPE_PARAMETER_BOUND: 1511 case METHOD_TYPE_PARAMETER_BOUND: 1512 position.parameter_index = nextByte(); 1513 position.bound_index = nextByte(); 1514 break; 1515 // class extends or implements clause 1516 case CLASS_EXTENDS: 1517 position.type_index = nextChar(); 1518 break; 1519 // throws 1520 case THROWS: 1521 position.type_index = nextChar(); 1522 break; 1523 // method parameter 1524 case METHOD_FORMAL_PARAMETER: 1525 position.parameter_index = nextByte(); 1526 break; 1527 // method/constructor/reference type argument 1528 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 1529 case METHOD_INVOCATION_TYPE_ARGUMENT: 1530 case METHOD_REFERENCE_TYPE_ARGUMENT: 1531 position.offset = nextChar(); 1532 position.type_index = nextByte(); 1533 break; 1534 // We don't need to worry about these 1535 case METHOD_RETURN: 1536 case FIELD: 1537 break; 1538 // lambda formal parameter 1539 case LAMBDA_FORMAL_PARAMETER: 1540 position.parameter_index = nextByte(); 1541 break; 1542 case UNKNOWN: 1543 throw new AssertionError("jvm.ClassReader: UNKNOWN target type should never occur!"); 1544 default: 1545 throw new AssertionError("jvm.ClassReader: Unknown target type for position: " + position); 1546 } 1547 1548 { // See whether there is location info and read it 1549 int len = nextByte(); 1550 ListBuffer<Integer> loc = ListBuffer.lb(); 1551 for (int i = 0; i < len * TypeAnnotationPosition.TypePathEntry.bytesPerEntry; ++i) 1552 loc = loc.append(nextByte()); 1553 position.location = TypeAnnotationPosition.getTypePathFromBinary(loc.toList()); 1554 } 1555 1556 return position; 1557 } 1558 1559 Attribute readAttributeValue() { 1560 char c = (char) buf[bp++]; | 1453 1454 TypeAnnotationProxy readTypeAnnotation() { 1455 TypeAnnotationPosition position = readPosition(); 1456 CompoundAnnotationProxy proxy = readCompoundAnnotation(); 1457 1458 return new TypeAnnotationProxy(proxy, position); 1459 } 1460 1461 TypeAnnotationPosition readPosition() { 1462 int tag = nextByte(); // TargetType tag is a byte 1463 1464 if (!TargetType.isValidTargetTypeValue(tag)) 1465 throw this.badClassFile("bad.type.annotation.value", String.format("0x%02X", tag)); 1466 1467 TypeAnnotationPosition position = new TypeAnnotationPosition(); 1468 TargetType type = TargetType.fromTargetTypeValue(tag); 1469 1470 position.type = type; 1471 1472 switch (type) { 1473 // instanceof 1474 case INSTANCEOF: 1475 // new expression 1476 case NEW: 1477 // constructor/method reference receiver 1478 case CONSTRUCTOR_REFERENCE: 1479 case METHOD_REFERENCE: 1480 position.offset = nextChar(); 1481 break; 1482 // local variable 1483 case LOCAL_VARIABLE: 1484 // resource variable 1485 case RESOURCE_VARIABLE: 1486 int table_length = nextChar(); 1487 position.lvarOffset = new int[table_length]; 1488 position.lvarLength = new int[table_length]; 1489 position.lvarIndex = new int[table_length]; 1490 1491 for (int i = 0; i < table_length; ++i) { 1492 position.lvarOffset[i] = nextChar(); 1493 position.lvarLength[i] = nextChar(); 1494 position.lvarIndex[i] = nextChar(); 1495 } 1496 break; 1497 // exception parameter 1498 case EXCEPTION_PARAMETER: 1499 position.exception_index = nextByte(); 1508 position.parameter_index = nextByte(); 1509 break; 1510 // type parameter bound 1511 case CLASS_TYPE_PARAMETER_BOUND: 1512 case METHOD_TYPE_PARAMETER_BOUND: 1513 position.parameter_index = nextByte(); 1514 position.bound_index = nextByte(); 1515 break; 1516 // class extends or implements clause 1517 case CLASS_EXTENDS: 1518 position.type_index = nextChar(); 1519 break; 1520 // throws 1521 case THROWS: 1522 position.type_index = nextChar(); 1523 break; 1524 // method parameter 1525 case METHOD_FORMAL_PARAMETER: 1526 position.parameter_index = nextByte(); 1527 break; 1528 // type cast 1529 case CAST: 1530 // method/constructor/reference type argument 1531 case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: 1532 case METHOD_INVOCATION_TYPE_ARGUMENT: 1533 case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: 1534 case METHOD_REFERENCE_TYPE_ARGUMENT: 1535 position.offset = nextChar(); 1536 position.type_index = nextByte(); 1537 break; 1538 // We don't need to worry about these 1539 case METHOD_RETURN: 1540 case FIELD: 1541 break; 1542 case UNKNOWN: 1543 throw new AssertionError("jvm.ClassReader: UNKNOWN target type should never occur!"); 1544 default: 1545 throw new AssertionError("jvm.ClassReader: Unknown target type for position: " + position); 1546 } 1547 1548 { // See whether there is location info and read it 1549 int len = nextByte(); 1550 ListBuffer<Integer> loc = ListBuffer.lb(); 1551 for (int i = 0; i < len * TypeAnnotationPosition.TypePathEntry.bytesPerEntry; ++i) 1552 loc = loc.append(nextByte()); 1553 position.location = TypeAnnotationPosition.getTypePathFromBinary(loc.toList()); 1554 } 1555 1556 return position; 1557 } 1558 1559 Attribute readAttributeValue() { 1560 char c = (char) buf[bp++]; |