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

changeset 308
03944ee4fac4
parent 267
e2722bd43f3a
child 310
7c154fdc3547
     1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 26 12:22:40 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 26 18:51:39 2009 -0700
     1.3 @@ -26,6 +26,8 @@
     1.4  package com.sun.tools.javac.jvm;
     1.5  import java.util.*;
     1.6  
     1.7 +import javax.lang.model.element.ElementKind;
     1.8 +
     1.9  import com.sun.tools.javac.util.*;
    1.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    1.11  import com.sun.tools.javac.util.List;
    1.12 @@ -939,7 +941,6 @@
    1.13                                   startpcCrt,
    1.14                                   code.curPc());
    1.15  
    1.16 -                // End the scope of all local variables in variable info.
    1.17                  code.endScopes(0);
    1.18  
    1.19                  // If we exceeded limits, panic
    1.20 @@ -1439,7 +1440,6 @@
    1.21              // Resolve all breaks.
    1.22              code.resolve(exitChain);
    1.23  
    1.24 -            // End the scopes of all try-local variables in variable info.
    1.25              code.endScopes(limit);
    1.26          }
    1.27  
    1.28 @@ -1672,6 +1672,7 @@
    1.29   *************************************************************************/
    1.30  
    1.31      public void visitApply(JCMethodInvocation tree) {
    1.32 +        setTypeAnnotationPositions(tree.pos);
    1.33          // Generate code for method.
    1.34          Item m = genExpr(tree.meth, methodType);
    1.35          // Generate code for all arguments, where the expected types are
    1.36 @@ -1707,10 +1708,45 @@
    1.37          result = items.makeStackItem(pt);
    1.38      }
    1.39  
    1.40 +    private void setTypeAnnotationPositions(int treePos) {
    1.41 +        MethodSymbol meth = code.meth;
    1.42 +
    1.43 +        for (Attribute.TypeCompound ta : meth.typeAnnotations) {
    1.44 +            if (ta.position.pos == treePos) {
    1.45 +                ta.position.offset = code.cp;
    1.46 +                ta.position.lvarOffset[0] = code.cp;
    1.47 +            }
    1.48 +        }
    1.49 +
    1.50 +        if (code.meth.getKind() != ElementKind.CONSTRUCTOR
    1.51 +                && code.meth.getKind() != ElementKind.STATIC_INIT)
    1.52 +            return;
    1.53 +
    1.54 +        for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
    1.55 +            if (ta.position.pos == treePos) {
    1.56 +                ta.position.offset = code.cp;
    1.57 +                ta.position.lvarOffset[0] = code.cp;
    1.58 +            }
    1.59 +        }
    1.60 +
    1.61 +        ClassSymbol clazz = meth.enclClass();
    1.62 +        for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
    1.63 +            if (!s.getKind().isField())
    1.64 +                continue;
    1.65 +            for (Attribute.TypeCompound ta : s.typeAnnotations) {
    1.66 +                if (ta.position.pos == treePos) {
    1.67 +                    ta.position.offset = code.cp;
    1.68 +                    ta.position.lvarOffset[0] = code.cp;
    1.69 +                }
    1.70 +            }
    1.71 +        }
    1.72 +    }
    1.73 +
    1.74      public void visitNewClass(JCNewClass tree) {
    1.75          // Enclosing instances or anonymous classes should have been eliminated
    1.76          // by now.
    1.77          assert tree.encl == null && tree.def == null;
    1.78 +        setTypeAnnotationPositions(tree.pos);
    1.79  
    1.80          code.emitop2(new_, makeRef(tree.pos(), tree.type));
    1.81          code.emitop0(dup);
    1.82 @@ -1725,6 +1761,8 @@
    1.83      }
    1.84  
    1.85      public void visitNewArray(JCNewArray tree) {
    1.86 +        setTypeAnnotationPositions(tree.pos);
    1.87 +
    1.88          if (tree.elems != null) {
    1.89              Type elemtype = types.elemtype(tree.type);
    1.90              loadIntConst(tree.elems.length());
    1.91 @@ -2053,6 +2091,7 @@
    1.92          }
    1.93  
    1.94      public void visitTypeCast(JCTypeCast tree) {
    1.95 +        setTypeAnnotationPositions(tree.pos);
    1.96          result = genExpr(tree.expr, tree.clazz.type).load();
    1.97          // Additional code is only needed if we cast to a reference type
    1.98          // which is not statically a supertype of the expression's type.
    1.99 @@ -2069,6 +2108,8 @@
   1.100      }
   1.101  
   1.102      public void visitTypeTest(JCInstanceOf tree) {
   1.103 +        setTypeAnnotationPositions(tree.pos);
   1.104 +
   1.105          genExpr(tree.expr, tree.expr.type).load();
   1.106          code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
   1.107          result = items.makeStackItem(syms.booleanType);
   1.108 @@ -2110,6 +2151,7 @@
   1.109  
   1.110          if (tree.name == names._class) {
   1.111              assert target.hasClassLiterals();
   1.112 +            setTypeAnnotationPositions(tree.pos);
   1.113              code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
   1.114              result = items.makeStackItem(pt);
   1.115              return;

mercurial