547 * // index to CONSTANT_utf8_info structure in constant pool representing |
547 * // index to CONSTANT_utf8_info structure in constant pool representing |
548 * // the string "ModuleTarget" |
548 * // the string "ModuleTarget" |
549 * u2 attribute_name_index; |
549 * u2 attribute_name_index; |
550 * u4 attribute_length; |
550 * u4 attribute_length; |
551 * |
551 * |
552 * // index to CONSTANT_utf8_info structure with the OS name |
552 * // index to CONSTANT_utf8_info structure with the target platform |
553 * u2 os_name_index; |
553 * u2 target_platform_index; |
554 * // index to CONSTANT_utf8_info structure with the OS arch |
|
555 * u2 os_arch_index |
|
556 * } |
554 * } |
557 * |
555 * |
558 * } </pre> |
556 * } </pre> |
559 */ |
557 */ |
560 public static class ModuleTargetAttribute extends Attribute { |
558 public static class ModuleTargetAttribute extends Attribute { |
561 private final String osName; |
559 private final String targetPlatform; |
562 private final String osArch; |
560 |
563 |
561 public ModuleTargetAttribute(String targetPlatform) { |
564 public ModuleTargetAttribute(String osName, String osArch) { |
|
565 super(MODULE_TARGET); |
562 super(MODULE_TARGET); |
566 this.osName = osName; |
563 this.targetPlatform = targetPlatform; |
567 this.osArch = osArch; |
|
568 } |
564 } |
569 |
565 |
570 public ModuleTargetAttribute() { |
566 public ModuleTargetAttribute() { |
571 this(null, null); |
567 this(null); |
572 } |
568 } |
573 |
569 |
574 public String osName() { |
570 public String targetPlatform() { |
575 return osName; |
571 return targetPlatform; |
576 } |
|
577 |
|
578 public String osArch() { |
|
579 return osArch; |
|
580 } |
572 } |
581 |
573 |
582 @Override |
574 @Override |
583 protected Attribute read(ClassReader cr, |
575 protected Attribute read(ClassReader cr, |
584 int off, |
576 int off, |
586 char[] buf, |
578 char[] buf, |
587 int codeOff, |
579 int codeOff, |
588 Label[] labels) |
580 Label[] labels) |
589 { |
581 { |
590 |
582 |
591 String osName = null; |
583 String targetPlatform = null; |
592 String osArch = null; |
584 |
593 |
585 int target_platform_index = cr.readUnsignedShort(off); |
594 int name_index = cr.readUnsignedShort(off); |
586 if (target_platform_index != 0) |
595 if (name_index != 0) |
587 targetPlatform = cr.readUTF8(off, buf); |
596 osName = cr.readUTF8(off, buf); |
588 off += 2; |
597 off += 2; |
589 |
598 |
590 return new ModuleTargetAttribute(targetPlatform); |
599 int arch_index = cr.readUnsignedShort(off); |
|
600 if (arch_index != 0) |
|
601 osArch = cr.readUTF8(off, buf); |
|
602 off += 2; |
|
603 |
|
604 return new ModuleTargetAttribute(osName, osArch); |
|
605 } |
591 } |
606 |
592 |
607 @Override |
593 @Override |
608 protected ByteVector write(ClassWriter cw, |
594 protected ByteVector write(ClassWriter cw, |
609 byte[] code, |
595 byte[] code, |
611 int maxStack, |
597 int maxStack, |
612 int maxLocals) |
598 int maxLocals) |
613 { |
599 { |
614 ByteVector attr = new ByteVector(); |
600 ByteVector attr = new ByteVector(); |
615 |
601 |
616 int name_index = 0; |
602 int target_platform_index = 0; |
617 if (osName != null && osName.length() > 0) |
603 if (targetPlatform != null && targetPlatform.length() > 0) |
618 name_index = cw.newUTF8(osName); |
604 target_platform_index = cw.newUTF8(targetPlatform); |
619 attr.putShort(name_index); |
605 attr.putShort(target_platform_index); |
620 |
|
621 int arch_index = 0; |
|
622 if (osArch != null && osArch.length() > 0) |
|
623 arch_index = cw.newUTF8(osArch); |
|
624 attr.putShort(arch_index); |
|
625 |
606 |
626 return attr; |
607 return attr; |
627 } |
608 } |
628 } |
609 } |
629 |
610 |