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; |
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 |
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); |