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

changeset 1521
71f35e4b93a5
parent 1452
de1ec6fc93fe
child 1555
762d0af062f5
     1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Jan 23 20:57:40 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Jan 23 13:27:24 2013 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -1016,8 +1016,11 @@
    1.11                      code.frameBeforeLast = null;
    1.12                  }
    1.13  
    1.14 -                //compress exception table
    1.15 +                // Compress exception table
    1.16                  code.compressCatchTable();
    1.17 +
    1.18 +                // Fill in type annotation positions for exception parameters
    1.19 +                code.fillExceptionParameterPositions();
    1.20              }
    1.21          }
    1.22  
    1.23 @@ -1738,6 +1741,7 @@
    1.24   *************************************************************************/
    1.25  
    1.26      public void visitApply(JCMethodInvocation tree) {
    1.27 +        setTypeAnnotationPositions(tree.pos);
    1.28          // Generate code for method.
    1.29          Item m = genExpr(tree.meth, methodType);
    1.30          // Generate code for all arguments, where the expected types are
    1.31 @@ -1775,10 +1779,48 @@
    1.32          result = items.makeStackItem(pt);
    1.33      }
    1.34  
    1.35 +   private void setTypeAnnotationPositions(int treePos) {
    1.36 +       MethodSymbol meth = code.meth;
    1.37 +
    1.38 +       for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) {
    1.39 +           if (ta.position.pos == treePos) {
    1.40 +               ta.position.offset = code.cp;
    1.41 +               ta.position.lvarOffset = new int[] { code.cp };
    1.42 +               ta.position.isValidOffset = true;
    1.43 +           }
    1.44 +       }
    1.45 +
    1.46 +       if (code.meth.getKind() != javax.lang.model.element.ElementKind.CONSTRUCTOR
    1.47 +               && code.meth.getKind() != javax.lang.model.element.ElementKind.STATIC_INIT)
    1.48 +           return;
    1.49 +
    1.50 +       for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) {
    1.51 +           if (ta.position.pos == treePos) {
    1.52 +               ta.position.offset = code.cp;
    1.53 +               ta.position.lvarOffset = new int[] { code.cp };
    1.54 +               ta.position.isValidOffset = true;
    1.55 +           }
    1.56 +       }
    1.57 +
    1.58 +       ClassSymbol clazz = meth.enclClass();
    1.59 +       for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
    1.60 +           if (!s.getKind().isField())
    1.61 +               continue;
    1.62 +           for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) {
    1.63 +               if (ta.position.pos == treePos) {
    1.64 +                   ta.position.offset = code.cp;
    1.65 +                   ta.position.lvarOffset = new int[] { code.cp };
    1.66 +                   ta.position.isValidOffset = true;
    1.67 +               }
    1.68 +           }
    1.69 +       }
    1.70 +   }
    1.71 +
    1.72      public void visitNewClass(JCNewClass tree) {
    1.73          // Enclosing instances or anonymous classes should have been eliminated
    1.74          // by now.
    1.75          Assert.check(tree.encl == null && tree.def == null);
    1.76 +        setTypeAnnotationPositions(tree.pos);
    1.77  
    1.78          code.emitop2(new_, makeRef(tree.pos(), tree.type));
    1.79          code.emitop0(dup);
    1.80 @@ -1793,6 +1835,7 @@
    1.81      }
    1.82  
    1.83      public void visitNewArray(JCNewArray tree) {
    1.84 +        setTypeAnnotationPositions(tree.pos);
    1.85  
    1.86          if (tree.elems != null) {
    1.87              Type elemtype = types.elemtype(tree.type);
    1.88 @@ -2122,6 +2165,7 @@
    1.89          }
    1.90  
    1.91      public void visitTypeCast(JCTypeCast tree) {
    1.92 +        setTypeAnnotationPositions(tree.pos);
    1.93          result = genExpr(tree.expr, tree.clazz.type).load();
    1.94          // Additional code is only needed if we cast to a reference type
    1.95          // which is not statically a supertype of the expression's type.
    1.96 @@ -2138,6 +2182,7 @@
    1.97      }
    1.98  
    1.99      public void visitTypeTest(JCInstanceOf tree) {
   1.100 +        setTypeAnnotationPositions(tree.pos);
   1.101          genExpr(tree.expr, tree.expr.type).load();
   1.102          code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
   1.103          result = items.makeStackItem(syms.booleanType);
   1.104 @@ -2184,7 +2229,7 @@
   1.105              code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
   1.106              result = items.makeStackItem(pt);
   1.107              return;
   1.108 -        }
   1.109 +       }
   1.110  
   1.111          Symbol ssym = TreeInfo.symbol(tree.selected);
   1.112  

mercurial