langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java
changeset 3149 0cd06d598d6f
parent 2723 b659ca23d5f5
child 3151 41800a86aad3
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 26 12:22:40 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 26 18:51:39 2009 -0700
@@ -26,6 +26,8 @@
 package com.sun.tools.javac.jvm;
 import java.util.*;
 
+import javax.lang.model.element.ElementKind;
+
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.util.List;
@@ -939,7 +941,6 @@
                                  startpcCrt,
                                  code.curPc());
 
-                // End the scope of all local variables in variable info.
                 code.endScopes(0);
 
                 // If we exceeded limits, panic
@@ -1439,7 +1440,6 @@
             // Resolve all breaks.
             code.resolve(exitChain);
 
-            // End the scopes of all try-local variables in variable info.
             code.endScopes(limit);
         }
 
@@ -1672,6 +1672,7 @@
  *************************************************************************/
 
     public void visitApply(JCMethodInvocation tree) {
+        setTypeAnnotationPositions(tree.pos);
         // Generate code for method.
         Item m = genExpr(tree.meth, methodType);
         // Generate code for all arguments, where the expected types are
@@ -1707,10 +1708,45 @@
         result = items.makeStackItem(pt);
     }
 
+    private void setTypeAnnotationPositions(int treePos) {
+        MethodSymbol meth = code.meth;
+
+        for (Attribute.TypeCompound ta : meth.typeAnnotations) {
+            if (ta.position.pos == treePos) {
+                ta.position.offset = code.cp;
+                ta.position.lvarOffset[0] = code.cp;
+            }
+        }
+
+        if (code.meth.getKind() != ElementKind.CONSTRUCTOR
+                && code.meth.getKind() != ElementKind.STATIC_INIT)
+            return;
+
+        for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
+            if (ta.position.pos == treePos) {
+                ta.position.offset = code.cp;
+                ta.position.lvarOffset[0] = code.cp;
+            }
+        }
+
+        ClassSymbol clazz = meth.enclClass();
+        for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
+            if (!s.getKind().isField())
+                continue;
+            for (Attribute.TypeCompound ta : s.typeAnnotations) {
+                if (ta.position.pos == treePos) {
+                    ta.position.offset = code.cp;
+                    ta.position.lvarOffset[0] = code.cp;
+                }
+            }
+        }
+    }
+
     public void visitNewClass(JCNewClass tree) {
         // Enclosing instances or anonymous classes should have been eliminated
         // by now.
         assert tree.encl == null && tree.def == null;
+        setTypeAnnotationPositions(tree.pos);
 
         code.emitop2(new_, makeRef(tree.pos(), tree.type));
         code.emitop0(dup);
@@ -1725,6 +1761,8 @@
     }
 
     public void visitNewArray(JCNewArray tree) {
+        setTypeAnnotationPositions(tree.pos);
+
         if (tree.elems != null) {
             Type elemtype = types.elemtype(tree.type);
             loadIntConst(tree.elems.length());
@@ -2053,6 +2091,7 @@
         }
 
     public void visitTypeCast(JCTypeCast tree) {
+        setTypeAnnotationPositions(tree.pos);
         result = genExpr(tree.expr, tree.clazz.type).load();
         // Additional code is only needed if we cast to a reference type
         // which is not statically a supertype of the expression's type.
@@ -2069,6 +2108,8 @@
     }
 
     public void visitTypeTest(JCInstanceOf tree) {
+        setTypeAnnotationPositions(tree.pos);
+
         genExpr(tree.expr, tree.expr.type).load();
         code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
         result = items.makeStackItem(syms.booleanType);
@@ -2110,6 +2151,7 @@
 
         if (tree.name == names._class) {
             assert target.hasClassLiterals();
+            setTypeAnnotationPositions(tree.pos);
             code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
             result = items.makeStackItem(pt);
             return;