src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java

changeset 1755
ddb4a2bfcd82
parent 1698
49d32c84dfea
child 1792
ec871c3e8337
equal deleted inserted replaced
1754:0384683c64be 1755:ddb4a2bfcd82
630 databuf.appendChar(pool.put(typeSig(sym.type))); 630 databuf.appendChar(pool.put(typeSig(sym.type)));
631 endAttr(alenIdx); 631 endAttr(alenIdx);
632 acount++; 632 acount++;
633 } 633 }
634 acount += writeJavaAnnotations(sym.getRawAttributes()); 634 acount += writeJavaAnnotations(sym.getRawAttributes());
635 acount += writeTypeAnnotations(sym.getRawTypeAttributes()); 635 acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false);
636 return acount; 636 return acount;
637 } 637 }
638 638
639 /** 639 /**
640 * Write method parameter names attribute. 640 * Write method parameter names attribute.
757 attrCount++; 757 attrCount++;
758 } 758 }
759 return attrCount; 759 return attrCount;
760 } 760 }
761 761
762 int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) { 762 int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos, boolean inCode) {
763 if (typeAnnos.isEmpty()) return 0; 763 if (typeAnnos.isEmpty()) return 0;
764 764
765 ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb(); 765 ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
766 ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb(); 766 ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
767 767
768 for (Attribute.TypeCompound tc : typeAnnos) { 768 for (Attribute.TypeCompound tc : typeAnnos) {
769 if (tc.position == null || tc.position.type == TargetType.UNKNOWN) { 769 if (tc.hasUnknownPosition()) {
770 boolean found = false; 770 boolean fixed = tc.tryFixPosition();
771 // TODO: the position for the container annotation of a 771
772 // repeating type annotation has to be set. 772 // Could we fix it?
773 // This cannot be done when the container is created, because 773 if (!fixed) {
774 // then the position is not determined yet.
775 // How can we link these pieces better together?
776 if (tc.values.size() == 1) {
777 Pair<MethodSymbol, Attribute> val = tc.values.get(0);
778 if (val.fst.getSimpleName().contentEquals("value") &&
779 val.snd instanceof Attribute.Array) {
780 Attribute.Array arr = (Attribute.Array) val.snd;
781 if (arr.values.length != 0 &&
782 arr.values[0] instanceof Attribute.TypeCompound) {
783 TypeCompound atycomp = (Attribute.TypeCompound) arr.values[0];
784 if (atycomp.position.type != TargetType.UNKNOWN) {
785 tc.position = atycomp.position;
786 found = true;
787 }
788 }
789 }
790 }
791 if (!found) {
792 // This happens for nested types like @A Outer. @B Inner. 774 // This happens for nested types like @A Outer. @B Inner.
793 // For method parameters we get the annotation twice! Once with 775 // For method parameters we get the annotation twice! Once with
794 // a valid position, once unknown. 776 // a valid position, once unknown.
795 // TODO: find a cleaner solution. 777 // TODO: find a cleaner solution.
796 // System.err.println("ClassWriter: Position UNKNOWN in type annotation: " + tc); 778 PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
779 pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
797 continue; 780 continue;
798 } 781 }
799 } 782 }
783
784 if (tc.position.type.isLocal() != inCode)
785 continue;
800 if (!tc.position.emitToClassfile()) 786 if (!tc.position.emitToClassfile())
801 continue; 787 continue;
802 switch (types.getRetention(tc)) { 788 switch (types.getRetention(tc)) {
803 case SOURCE: break; 789 case SOURCE: break;
804 case CLASS: invisibles.append(tc); break; 790 case CLASS: invisibles.append(tc); break;
934 databuf.appendChar(p.lvarIndex[i]); 920 databuf.appendChar(p.lvarIndex[i]);
935 } 921 }
936 break; 922 break;
937 // exception parameter 923 // exception parameter
938 case EXCEPTION_PARAMETER: 924 case EXCEPTION_PARAMETER:
939 databuf.appendByte(p.exception_index); 925 databuf.appendChar(p.exception_index);
940 break; 926 break;
941 // method receiver 927 // method receiver
942 case METHOD_RECEIVER: 928 case METHOD_RECEIVER:
943 // Do nothing 929 // Do nothing
944 break; 930 break;
1239 int alenIdx = writeAttr(code.stackMap.getAttributeName(names)); 1225 int alenIdx = writeAttr(code.stackMap.getAttributeName(names));
1240 writeStackMap(code); 1226 writeStackMap(code);
1241 endAttr(alenIdx); 1227 endAttr(alenIdx);
1242 acount++; 1228 acount++;
1243 } 1229 }
1230
1231 acount += writeTypeAnnotations(code.meth.getRawTypeAttributes(), true);
1232
1244 endAttrs(acountIdx, acount); 1233 endAttrs(acountIdx, acount);
1245 } 1234 }
1246 //where 1235 //where
1247 private boolean needsLocalVariableTypeEntry(Type t) { 1236 private boolean needsLocalVariableTypeEntry(Type t) {
1248 //a local variable needs a type-entry if its type T is generic 1237 //a local variable needs a type-entry if its type T is generic
1625 log.printVerbose("wrote.file", outFile); 1614 log.printVerbose("wrote.file", outFile);
1626 out.close(); 1615 out.close();
1627 out = null; 1616 out = null;
1628 } finally { 1617 } finally {
1629 if (out != null) { 1618 if (out != null) {
1630 // if we are propogating an exception, delete the file 1619 // if we are propagating an exception, delete the file
1631 out.close(); 1620 out.close();
1632 outFile.delete(); 1621 outFile.delete();
1633 outFile = null; 1622 outFile = null;
1634 } 1623 }
1635 } 1624 }
1739 acount++; 1728 acount++;
1740 } 1729 }
1741 1730
1742 acount += writeFlagAttrs(c.flags()); 1731 acount += writeFlagAttrs(c.flags());
1743 acount += writeJavaAnnotations(c.getRawAttributes()); 1732 acount += writeJavaAnnotations(c.getRawAttributes());
1744 acount += writeTypeAnnotations(c.getRawTypeAttributes()); 1733 acount += writeTypeAnnotations(c.getRawTypeAttributes(), false);
1745 acount += writeEnclosingMethodAttribute(c); 1734 acount += writeEnclosingMethodAttribute(c);
1746 acount += writeExtraClassAttributes(c); 1735 acount += writeExtraClassAttributes(c);
1747 1736
1748 poolbuf.appendInt(JAVA_MAGIC); 1737 poolbuf.appendInt(JAVA_MAGIC);
1749 poolbuf.appendChar(target.minorVersion); 1738 poolbuf.appendChar(target.minorVersion);

mercurial