22namespace PHPJava \Kernel \Structures \Annotations ;
33
44use PHPJava \Exceptions \NotImplementedException ;
5+ use PHPJava \Exceptions \RuntimeException ;
56use PHPJava \Kernel \Attributes \AttributeInfo ;
67use PHPJava \Kernel \Attributes \RuntimeVisibleAnnotationsAttribute ;
78use PHPJava \Utilities \BinaryTool ;
@@ -12,7 +13,11 @@ final class ElementValuePairs implements AnnotationInterface
1213 use \PHPJava \Kernel \Core \ConstantPool;
1314
1415 private $ tag ;
16+ private $ value ;
1517
18+ /**
19+ * @see https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7.16
20+ */
1621 public function execute (): void
1722 {
1823 $ this ->tag = chr ($ this ->readByte ());
@@ -27,14 +32,36 @@ public function execute(): void
2732 case 'S ' :
2833 case 'Z ' :
2934 case 's ' :
35+ $ this ->value = $ this ->readUnsignedShort ();
3036 break ;
3137 case 'e ' : // enum_const_value
38+ $ this ->value = [
39+ 'type_name_index ' => $ this ->readUnsignedShort (),
40+ 'const_name_index ' => $ this ->readUnsignedShort (),
41+ ];
3242 break ;
3343 case 'c ' : // class_info_index
44+ $ this ->value = $ this ->readUnsignedShort ();
3445 break ;
3546 case '@ ' : // annotation_value
47+ $ this ->value = new AttributeInfo ($ this ->reader );
48+ $ this ->value ->setConstantPool ($ this ->getConstantPool ());
49+ $ this ->value ->execute ();
3650 break ;
3751 case '[ ' : // array_value
52+ $ this ->value = [
53+ 'num_values ' => $ this ->readUnsignedShort (),
54+ 'values ' => [],
55+ ];
56+ for ($ i = 0 ; $ i < $ this ->value ['num_values ' ]; $ i ++) {
57+ $ value = new static ($ this ->reader );
58+ $ value ->setConstantPool ($ this ->getConstantPool ());
59+ $ value ->execute ();
60+ $ this ->value ['values ' ][] = $ value ;
61+ }
62+ break ;
63+ default :
64+ throw new RuntimeException ('Invalid tag " ' . $ this ->tag . '" in element_value structure. ' );
3865 break ;
3966 }
4067//
0 commit comments