653 ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | 654 ((int) m.flags() & SYNTHETIC); 655 databuf.appendChar(pool.put(s.name)); 656 databuf.appendChar(flags); 657 } 658 // Now write the captured locals 659 for (VarSymbol s : m.capturedLocals) { 660 final int flags = 661 ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | 662 ((int) m.flags() & SYNTHETIC); 663 databuf.appendChar(pool.put(s.name)); 664 databuf.appendChar(flags); 665 } 666 endAttr(attrIndex); 667 return 1; 668 } else 669 return 0; 670 } 671 672 673 /** Write method parameter annotations; 674 * return number of attributes written. 675 */ 676 int writeParameterAttrs(MethodSymbol m) { 677 boolean hasVisible = false; 678 boolean hasInvisible = false; 679 if (m.params != null) { 680 for (VarSymbol s : m.params) { 681 for (Attribute.Compound a : s.getRawAttributes()) { 682 switch (types.getRetention(a)) { 683 case SOURCE: break; 684 case CLASS: hasInvisible = true; break; 685 case RUNTIME: hasVisible = true; break; 686 default: ;// /* fail soft */ throw new AssertionError(vis); 687 } 688 } 689 } 690 } 691 692 int attrCount = 0; 693 if (hasVisible) { 694 int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations); 695 databuf.appendByte(m.params.length()); 696 for (VarSymbol s : m.params) { 697 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 698 for (Attribute.Compound a : s.getRawAttributes()) 699 if (types.getRetention(a) == RetentionPolicy.RUNTIME) 700 buf.append(a); 701 databuf.appendChar(buf.length()); 702 for (Attribute.Compound a : buf) 703 writeCompoundAttribute(a); 704 } 705 endAttr(attrIndex); 706 attrCount++; 707 } 708 if (hasInvisible) { 709 int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations); 710 databuf.appendByte(m.params.length()); 711 for (VarSymbol s : m.params) { 712 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 713 for (Attribute.Compound a : s.getRawAttributes()) 714 if (types.getRetention(a) == RetentionPolicy.CLASS) 715 buf.append(a); 716 databuf.appendChar(buf.length()); 717 for (Attribute.Compound a : buf) 718 writeCompoundAttribute(a); 719 } 720 endAttr(attrIndex); 721 attrCount++; 722 } 723 return attrCount; 724 } 725 726 /********************************************************************** 727 * Writing Java-language annotations (aka metadata, attributes) 728 **********************************************************************/ 729 730 /** Write Java-language annotations; return number of JVM 731 * attributes written (zero or one). 732 */ 733 int writeJavaAnnotations(List<Attribute.Compound> attrs) { 734 if (attrs.isEmpty()) return 0; 735 ListBuffer<Attribute.Compound> visibles = new ListBuffer<Attribute.Compound>(); 736 ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>(); 737 for (Attribute.Compound a : attrs) { 738 switch (types.getRetention(a)) { 739 case SOURCE: break; | 653 ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | 654 ((int) m.flags() & SYNTHETIC); 655 databuf.appendChar(pool.put(s.name)); 656 databuf.appendChar(flags); 657 } 658 // Now write the captured locals 659 for (VarSymbol s : m.capturedLocals) { 660 final int flags = 661 ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | 662 ((int) m.flags() & SYNTHETIC); 663 databuf.appendChar(pool.put(s.name)); 664 databuf.appendChar(flags); 665 } 666 endAttr(attrIndex); 667 return 1; 668 } else 669 return 0; 670 } 671 672 673 private void writeParamAnnotations(List<VarSymbol> params, 674 RetentionPolicy retention) { 675 for (VarSymbol s : params) { 676 ListBuffer<Attribute.Compound> buf = new ListBuffer<>(); 677 for (Attribute.Compound a : s.getRawAttributes()) 678 if (types.getRetention(a) == retention) 679 buf.append(a); 680 databuf.appendChar(buf.length()); 681 for (Attribute.Compound a : buf) 682 writeCompoundAttribute(a); 683 } 684 685 } 686 687 private void writeParamAnnotations(MethodSymbol m, 688 RetentionPolicy retention) { 689 databuf.appendByte(m.params.length() + m.extraParams.length()); 690 writeParamAnnotations(m.extraParams, retention); 691 writeParamAnnotations(m.params, retention); 692 } 693 694 /** Write method parameter annotations; 695 * return number of attributes written. 696 */ 697 int writeParameterAttrs(MethodSymbol m) { 698 boolean hasVisible = false; 699 boolean hasInvisible = false; 700 if (m.params != null) { 701 for (VarSymbol s : m.params) { 702 for (Attribute.Compound a : s.getRawAttributes()) { 703 switch (types.getRetention(a)) { 704 case SOURCE: break; 705 case CLASS: hasInvisible = true; break; 706 case RUNTIME: hasVisible = true; break; 707 default: ;// /* fail soft */ throw new AssertionError(vis); 708 } 709 } 710 } 711 } 712 713 int attrCount = 0; 714 if (hasVisible) { 715 int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations); 716 writeParamAnnotations(m, RetentionPolicy.RUNTIME); 717 endAttr(attrIndex); 718 attrCount++; 719 } 720 if (hasInvisible) { 721 int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations); 722 writeParamAnnotations(m, RetentionPolicy.CLASS); 723 endAttr(attrIndex); 724 attrCount++; 725 } 726 return attrCount; 727 } 728 729 /********************************************************************** 730 * Writing Java-language annotations (aka metadata, attributes) 731 **********************************************************************/ 732 733 /** Write Java-language annotations; return number of JVM 734 * attributes written (zero or one). 735 */ 736 int writeJavaAnnotations(List<Attribute.Compound> attrs) { 737 if (attrs.isEmpty()) return 0; 738 ListBuffer<Attribute.Compound> visibles = new ListBuffer<Attribute.Compound>(); 739 ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>(); 740 for (Attribute.Compound a : attrs) { 741 switch (types.getRetention(a)) { 742 case SOURCE: break; |