Merge jdk7-b84

Sun, 14 Feb 2010 23:39:40 -0800

author
lana
date
Sun, 14 Feb 2010 23:39:40 -0800
changeset 491
d9cd5b8286e4
parent 476
2edcb5dc642d
parent 490
56a46d079264
child 492
75d5bd12eb86
child 498
67f0e05098fa

Merge

     1.1 --- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Fri Feb 12 13:25:27 2010 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Sun Feb 14 23:39:40 2010 -0800
     1.3 @@ -744,6 +744,7 @@
     1.4                  out.writeByte(p.type_index);
     1.5                  break;
     1.6              case CLASS_LITERAL:
     1.7 +            case CLASS_LITERAL_GENERIC_OR_ARRAY:
     1.8                  out.writeShort(p.offset);
     1.9                  break;
    1.10              // method parameter: not specified
     2.1 --- a/src/share/classes/com/sun/tools/classfile/ExtendedAnnotation.java	Fri Feb 12 13:25:27 2010 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/classfile/ExtendedAnnotation.java	Sun Feb 14 23:39:40 2010 -0800
     2.3 @@ -123,11 +123,14 @@
     2.4           // Class extends and implements clauses
     2.5          case CLASS_EXTENDS:
     2.6          case CLASS_EXTENDS_GENERIC_OR_ARRAY:
     2.7 -            position.type_index = cr.readUnsignedByte();
     2.8 +            int in = cr.readUnsignedShort();
     2.9 +            if (in == 0xFFFF)
    2.10 +                in = -1;
    2.11 +            position.type_index = in;
    2.12              break;
    2.13          // throws
    2.14          case THROWS:
    2.15 -            position.type_index = cr.readUnsignedByte();
    2.16 +            position.type_index = cr.readUnsignedShort();
    2.17              break;
    2.18          case CLASS_LITERAL:
    2.19          case CLASS_LITERAL_GENERIC_OR_ARRAY:
    2.20 @@ -213,11 +216,11 @@
    2.21           // Class extends and implements clauses
    2.22          case CLASS_EXTENDS:
    2.23          case CLASS_EXTENDS_GENERIC_OR_ARRAY:
    2.24 -            n += 1; // type_index
    2.25 +            n += 2; // type_index
    2.26              break;
    2.27          // throws
    2.28          case THROWS:
    2.29 -            n += 1; // type_index
    2.30 +            n += 2; // type_index
    2.31              break;
    2.32          case CLASS_LITERAL:
    2.33          case CLASS_LITERAL_GENERIC_OR_ARRAY:
    2.34 @@ -264,18 +267,18 @@
    2.35          public int offset = -1;
    2.36  
    2.37          // For locals.
    2.38 -        public int[] lvarOffset = new int[] { -1 };
    2.39 -        public int[] lvarLength = new int[] { -1 };
    2.40 -        public int[] lvarIndex = new int[] { -1 };
    2.41 +        public int[] lvarOffset = null;
    2.42 +        public int[] lvarLength = null;
    2.43 +        public int[] lvarIndex = null;
    2.44  
    2.45          // For type parameter bound
    2.46 -        public int bound_index = -1;
    2.47 +        public int bound_index = Integer.MIN_VALUE;
    2.48  
    2.49          // For type parameter and method parameter
    2.50 -        public int parameter_index = -1;
    2.51 +        public int parameter_index = Integer.MIN_VALUE;
    2.52  
    2.53          // For class extends, implements, and throws classes
    2.54 -        public int type_index = -2;
    2.55 +        public int type_index = Integer.MIN_VALUE;
    2.56  
    2.57          // For wildcards
    2.58          public Position wildcard_position = null;
     3.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Fri Feb 12 13:25:27 2010 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Sun Feb 14 23:39:40 2010 -0800
     3.3 @@ -113,6 +113,7 @@
     3.4      public static final int ENUM         = 1<<14;
     3.5  
     3.6      public static final int StandardFlags = 0x0fff;
     3.7 +    public static final int ModifierFlags = StandardFlags & ~INTERFACE;
     3.8  
     3.9      // Because the following access flags are overloaded with other
    3.10      // bit positions, we translate them when reading and writing class
     4.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Feb 12 13:25:27 2010 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Feb 14 23:39:40 2010 -0800
     4.3 @@ -657,6 +657,11 @@
     4.4  
     4.5          public List<Attribute.Compound> getAnnotationMirrors() {
     4.6              if (completer != null) complete();
     4.7 +            if (package_info != null && package_info.completer != null) {
     4.8 +                package_info.complete();
     4.9 +                if (attributes_field.isEmpty())
    4.10 +                    attributes_field = package_info.attributes_field;
    4.11 +            }
    4.12              assert attributes_field != null;
    4.13              return attributes_field;
    4.14          }
     5.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Fri Feb 12 13:25:27 2010 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Sun Feb 14 23:39:40 2010 -0800
     5.3 @@ -49,18 +49,18 @@
     5.4      public int offset = -1;
     5.5  
     5.6      // For locals. arrays same length
     5.7 -    public int[] lvarOffset = new int[] { -1 };
     5.8 -    public int[] lvarLength = new int[] { -1 };
     5.9 -    public int[] lvarIndex = new int[] { -1 };
    5.10 +    public int[] lvarOffset = null;
    5.11 +    public int[] lvarLength = null;
    5.12 +    public int[] lvarIndex = null;
    5.13  
    5.14      // For type parameter bound
    5.15 -    public int bound_index = -1;
    5.16 +    public int bound_index = Integer.MIN_VALUE;
    5.17  
    5.18      // For type parameter and method parameter
    5.19 -    public int parameter_index = -1;
    5.20 +    public int parameter_index = Integer.MIN_VALUE;
    5.21  
    5.22      // For class extends, implements, and throws classes
    5.23 -    public int type_index = -2;
    5.24 +    public int type_index = Integer.MIN_VALUE;
    5.25  
    5.26      // For wildcards
    5.27      public TypeAnnotationPosition wildcard_position = null;
    5.28 @@ -139,6 +139,7 @@
    5.29              sb.append(type_index);
    5.30              break;
    5.31          case CLASS_LITERAL:
    5.32 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
    5.33              sb.append(", offset = ");
    5.34              sb.append(offset);
    5.35              break;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Feb 14 23:39:40 2010 -0800
     6.3 @@ -0,0 +1,400 @@
     6.4 +/*
     6.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.  Sun designates this
    6.11 + * particular file as subject to the "Classpath" exception as provided
    6.12 + * by Sun in the LICENSE file that accompanied this code.
    6.13 + *
    6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 + * version 2 for more details (a copy is included in the LICENSE file that
    6.18 + * accompanied this code).
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License version
    6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 + *
    6.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.26 + * have any questions.
    6.27 + */
    6.28 +
    6.29 +package com.sun.tools.javac.code;
    6.30 +
    6.31 +import javax.lang.model.element.ElementKind;
    6.32 +
    6.33 +import com.sun.tools.javac.code.Symbol.VarSymbol;
    6.34 +import com.sun.tools.javac.tree.JCTree;
    6.35 +import com.sun.tools.javac.tree.TreeInfo;
    6.36 +import com.sun.tools.javac.tree.TreeScanner;
    6.37 +import com.sun.tools.javac.tree.JCTree.*;
    6.38 +import com.sun.tools.javac.util.Context;
    6.39 +import com.sun.tools.javac.util.List;
    6.40 +import com.sun.tools.javac.util.ListBuffer;
    6.41 +
    6.42 +/**
    6.43 + * Contains operations specific to processing type annotations
    6.44 + */
    6.45 +public class TypeAnnotations {
    6.46 +    private static final Context.Key<TypeAnnotations> key
    6.47 +        = new Context.Key<TypeAnnotations>();
    6.48 +
    6.49 +    public static TypeAnnotations instance(Context context) {
    6.50 +        TypeAnnotations instance = context.get(key);
    6.51 +        if (instance == null)
    6.52 +            instance = new TypeAnnotations(context);
    6.53 +        return instance;
    6.54 +    }
    6.55 +
    6.56 +    protected TypeAnnotations(Context context) {
    6.57 +        context.put(key, this);
    6.58 +    }
    6.59 +
    6.60 +    public void taFillAndLift(JCClassDecl tree, boolean visitBodies) {
    6.61 +        new TypeAnnotationPositions().scan(tree);
    6.62 +        new TypeAnnotationLift().scan(tree);
    6.63 +    }
    6.64 +
    6.65 +    private static class TypeAnnotationPositions extends TreeScanner {
    6.66 +
    6.67 +        private ListBuffer<JCTree> frames = ListBuffer.lb();
    6.68 +        private void push(JCTree t) { frames = frames.prepend(t); }
    6.69 +        private JCTree pop() { return frames.next(); }
    6.70 +        private JCTree peek2() { return frames.toList().tail.head; }
    6.71 +
    6.72 +        @Override
    6.73 +        public void scan(JCTree tree) {
    6.74 +            push(tree);
    6.75 +            super.scan(tree);
    6.76 +            pop();
    6.77 +        }
    6.78 +
    6.79 +        private boolean inClass = false;
    6.80 +
    6.81 +        @Override
    6.82 +        public void visitClassDef(JCClassDecl tree) {
    6.83 +           if (!inClass) {
    6.84 +               // Do not recurse into nested and inner classes since
    6.85 +               // TransTypes.visitClassDef makes an invocation for each class
    6.86 +               // separately.
    6.87 +               inClass = true;
    6.88 +               try {
    6.89 +                   super.visitClassDef(tree);
    6.90 +               } finally {
    6.91 +                   inClass = false;
    6.92 +               }
    6.93 +           }
    6.94 +        }
    6.95 +
    6.96 +        private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame,
    6.97 +                List<JCTree> path, TypeAnnotationPosition p) {
    6.98 +            switch (frame.getKind()) {
    6.99 +                case TYPE_CAST:
   6.100 +                    p.type = TargetType.TYPECAST;
   6.101 +                    p.pos = frame.pos;
   6.102 +                    return p;
   6.103 +
   6.104 +                case INSTANCE_OF:
   6.105 +                    p.type = TargetType.INSTANCEOF;
   6.106 +                    p.pos = frame.pos;
   6.107 +                    return p;
   6.108 +
   6.109 +                case NEW_CLASS:
   6.110 +                    p.type = TargetType.NEW;
   6.111 +                    p.pos = frame.pos;
   6.112 +                    return p;
   6.113 +
   6.114 +                case NEW_ARRAY:
   6.115 +                    p.type = TargetType.NEW;
   6.116 +                    p.pos = frame.pos;
   6.117 +                    return p;
   6.118 +
   6.119 +                case CLASS:
   6.120 +                    p.pos = frame.pos;
   6.121 +                    if (((JCClassDecl)frame).extending == tree) {
   6.122 +                        p.type = TargetType.CLASS_EXTENDS;
   6.123 +                        p.type_index = -1;
   6.124 +                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
   6.125 +                        p.type = TargetType.CLASS_EXTENDS;
   6.126 +                        p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
   6.127 +                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
   6.128 +                        p.type = TargetType.CLASS_TYPE_PARAMETER;
   6.129 +                        p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
   6.130 +                    } else
   6.131 +                        throw new AssertionError();
   6.132 +                    return p;
   6.133 +
   6.134 +                case METHOD: {
   6.135 +                    JCMethodDecl frameMethod = (JCMethodDecl)frame;
   6.136 +                    p.pos = frame.pos;
   6.137 +                    if (frameMethod.receiverAnnotations.contains(tree))
   6.138 +                        p.type = TargetType.METHOD_RECEIVER;
   6.139 +                    else if (frameMethod.thrown.contains(tree)) {
   6.140 +                        p.type = TargetType.THROWS;
   6.141 +                        p.type_index = frameMethod.thrown.indexOf(tree);
   6.142 +                    } else if (((JCMethodDecl)frame).restype == tree) {
   6.143 +                        p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY;
   6.144 +                    } else if (frameMethod.typarams.contains(tree)) {
   6.145 +                        p.type = TargetType.METHOD_TYPE_PARAMETER;
   6.146 +                        p.parameter_index = frameMethod.typarams.indexOf(tree);
   6.147 +                    } else
   6.148 +                        throw new AssertionError();
   6.149 +                    return p;
   6.150 +                }
   6.151 +                case MEMBER_SELECT: {
   6.152 +                    JCFieldAccess fieldFrame = (JCFieldAccess)frame;
   6.153 +                    if ("class".contentEquals(fieldFrame.name)) {
   6.154 +                        p.type = TargetType.CLASS_LITERAL;
   6.155 +                        p.pos = TreeInfo.innermostType(fieldFrame.selected).pos;
   6.156 +                    } else
   6.157 +                        throw new AssertionError();
   6.158 +                    return p;
   6.159 +                }
   6.160 +                case PARAMETERIZED_TYPE: {
   6.161 +                    TypeAnnotationPosition nextP;
   6.162 +                    if (((JCTypeApply)frame).clazz == tree)
   6.163 +                        nextP = p; // generic: RAW; noop
   6.164 +                    else if (((JCTypeApply)frame).arguments.contains(tree))
   6.165 +                        p.location = p.location.prepend(
   6.166 +                                ((JCTypeApply)frame).arguments.indexOf(tree));
   6.167 +                    else
   6.168 +                        throw new AssertionError();
   6.169 +
   6.170 +                    List<JCTree> newPath = path.tail;
   6.171 +                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   6.172 +                }
   6.173 +
   6.174 +                case ARRAY_TYPE: {
   6.175 +                    p.location = p.location.prepend(0);
   6.176 +                    List<JCTree> newPath = path.tail;
   6.177 +                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   6.178 +                }
   6.179 +
   6.180 +                case TYPE_PARAMETER:
   6.181 +                    if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) {
   6.182 +                        JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
   6.183 +                        p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
   6.184 +                        p.parameter_index = clazz.typarams.indexOf(path.tail.head);
   6.185 +                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
   6.186 +                    } else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) {
   6.187 +                        JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
   6.188 +                        p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
   6.189 +                        p.parameter_index = method.typarams.indexOf(path.tail.head);
   6.190 +                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
   6.191 +                    } else
   6.192 +                        throw new AssertionError();
   6.193 +                    p.pos = frame.pos;
   6.194 +                    return p;
   6.195 +
   6.196 +                case VARIABLE:
   6.197 +                    VarSymbol v = ((JCVariableDecl)frame).sym;
   6.198 +                    p.pos = frame.pos;
   6.199 +                    switch (v.getKind()) {
   6.200 +                        case LOCAL_VARIABLE:
   6.201 +                            p.type = TargetType.LOCAL_VARIABLE; break;
   6.202 +                        case FIELD:
   6.203 +                            p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break;
   6.204 +                        case PARAMETER:
   6.205 +                            p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY;
   6.206 +                            p.parameter_index = methodParamIndex(path, frame);
   6.207 +                            break;
   6.208 +                        default: throw new AssertionError();
   6.209 +                    }
   6.210 +                    return p;
   6.211 +
   6.212 +                case ANNOTATED_TYPE: {
   6.213 +                    List<JCTree> newPath = path.tail;
   6.214 +                    return resolveFrame(newPath.head, newPath.tail.head,
   6.215 +                            newPath, p);
   6.216 +                }
   6.217 +
   6.218 +                case METHOD_INVOCATION: {
   6.219 +                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
   6.220 +                    if (!invocation.typeargs.contains(tree))
   6.221 +                        throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
   6.222 +                    p.type = TargetType.METHOD_TYPE_ARGUMENT;
   6.223 +                    p.pos = invocation.pos;
   6.224 +                    p.type_index = invocation.typeargs.indexOf(tree);
   6.225 +                    return p;
   6.226 +                }
   6.227 +
   6.228 +                case EXTENDS_WILDCARD:
   6.229 +                case SUPER_WILDCARD: {
   6.230 +                    p.type = TargetType.WILDCARD_BOUND;
   6.231 +                    List<JCTree> newPath = path.tail;
   6.232 +
   6.233 +                    TypeAnnotationPosition wildcard =
   6.234 +                        resolveFrame(newPath.head, newPath.tail.head, newPath,
   6.235 +                                new TypeAnnotationPosition());
   6.236 +                    if (!wildcard.location.isEmpty())
   6.237 +                        wildcard.type = wildcard.type.getGenericComplement();
   6.238 +                    p.wildcard_position = wildcard;
   6.239 +                    p.pos = frame.pos;
   6.240 +                    return p;
   6.241 +                }
   6.242 +            }
   6.243 +            return p;
   6.244 +        }
   6.245 +
   6.246 +        private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) {
   6.247 +            for (JCTypeAnnotation anno : annotations) {
   6.248 +                anno.annotation_position = position;
   6.249 +                anno.attribute_field.position = position;
   6.250 +            }
   6.251 +        }
   6.252 +
   6.253 +        @Override
   6.254 +        public void visitNewArray(JCNewArray tree) {
   6.255 +            findPosition(tree, tree, tree.annotations);
   6.256 +            int dimAnnosCount = tree.dimAnnotations.size();
   6.257 +
   6.258 +            // handle annotations associated with dimentions
   6.259 +            for (int i = 0; i < dimAnnosCount; ++i) {
   6.260 +                TypeAnnotationPosition p = new TypeAnnotationPosition();
   6.261 +                p.type = TargetType.NEW_GENERIC_OR_ARRAY;
   6.262 +                p.pos = tree.pos;
   6.263 +                p.location = p.location.append(i);
   6.264 +                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
   6.265 +            }
   6.266 +
   6.267 +            // handle "free" annotations
   6.268 +            int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
   6.269 +            JCExpression elemType = tree.elemtype;
   6.270 +            while (elemType != null) {
   6.271 +                if (elemType.getTag() == JCTree.ANNOTATED_TYPE) {
   6.272 +                    JCAnnotatedType at = (JCAnnotatedType)elemType;
   6.273 +                    TypeAnnotationPosition p = new TypeAnnotationPosition();
   6.274 +                    p.type = TargetType.NEW_GENERIC_OR_ARRAY;
   6.275 +                    p.pos = tree.pos;
   6.276 +                    p.location = p.location.append(i);
   6.277 +                    setTypeAnnotationPos(at.annotations, p);
   6.278 +                    elemType = at.underlyingType;
   6.279 +                } else if (elemType.getTag() == JCTree.TYPEARRAY) {
   6.280 +                    ++i;
   6.281 +                    elemType = ((JCArrayTypeTree)elemType).elemtype;
   6.282 +                } else
   6.283 +                    break;
   6.284 +            }
   6.285 +
   6.286 +            // find annotations locations of initializer elements
   6.287 +            scan(tree.elems);
   6.288 +        }
   6.289 +
   6.290 +        @Override
   6.291 +        public void visitAnnotatedType(JCAnnotatedType tree) {
   6.292 +            findPosition(tree, peek2(), tree.annotations);
   6.293 +            super.visitAnnotatedType(tree);
   6.294 +        }
   6.295 +
   6.296 +        @Override
   6.297 +        public void visitMethodDef(JCMethodDecl tree) {
   6.298 +            TypeAnnotationPosition p = new TypeAnnotationPosition();
   6.299 +            p.type = TargetType.METHOD_RECEIVER;
   6.300 +            setTypeAnnotationPos(tree.receiverAnnotations, p);
   6.301 +            super.visitMethodDef(tree);
   6.302 +        }
   6.303 +        @Override
   6.304 +        public void visitTypeParameter(JCTypeParameter tree) {
   6.305 +            findPosition(tree, peek2(), tree.annotations);
   6.306 +            super.visitTypeParameter(tree);
   6.307 +        }
   6.308 +
   6.309 +        void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) {
   6.310 +            if (!annotations.isEmpty()) {
   6.311 +                TypeAnnotationPosition p =
   6.312 +                        resolveFrame(tree, frame, frames.toList(),
   6.313 +                                new TypeAnnotationPosition());
   6.314 +                if (!p.location.isEmpty())
   6.315 +                    p.type = p.type.getGenericComplement();
   6.316 +                setTypeAnnotationPos(annotations, p);
   6.317 +            }
   6.318 +        }
   6.319 +
   6.320 +        private int methodParamIndex(List<JCTree> path, JCTree param) {
   6.321 +            List<JCTree> curr = path;
   6.322 +            if (curr.head != param)
   6.323 +                curr = path.tail;
   6.324 +            JCMethodDecl method = (JCMethodDecl)curr.tail.head;
   6.325 +            return method.params.indexOf(param);
   6.326 +        }
   6.327 +    }
   6.328 +
   6.329 +    private static class TypeAnnotationLift extends TreeScanner {
   6.330 +        List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil();
   6.331 +
   6.332 +        boolean isInner = false;
   6.333 +        @Override
   6.334 +        public void visitClassDef(JCClassDecl tree) {
   6.335 +            if (isInner) {
   6.336 +                // tree is an inner class tree.  stop now.
   6.337 +                // TransTypes.visitClassDef makes an invocation for each class
   6.338 +                // separately.
   6.339 +                return;
   6.340 +            }
   6.341 +            isInner = true;
   6.342 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
   6.343 +            recordedTypeAnnotations = List.nil();
   6.344 +            try {
   6.345 +                super.visitClassDef(tree);
   6.346 +            } finally {
   6.347 +                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
   6.348 +                recordedTypeAnnotations = prevTAs;
   6.349 +            }
   6.350 +        }
   6.351 +
   6.352 +        @Override
   6.353 +        public void visitMethodDef(JCMethodDecl tree) {
   6.354 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
   6.355 +            recordedTypeAnnotations = List.nil();
   6.356 +            try {
   6.357 +                super.visitMethodDef(tree);
   6.358 +            } finally {
   6.359 +                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
   6.360 +                recordedTypeAnnotations = prevTAs;
   6.361 +            }
   6.362 +        }
   6.363 +
   6.364 +        @Override
   6.365 +        public void visitVarDef(JCVariableDecl tree) {
   6.366 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
   6.367 +            recordedTypeAnnotations = List.nil();
   6.368 +            ElementKind kind = tree.sym.getKind();
   6.369 +            if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) {
   6.370 +                // need to lift the annotations
   6.371 +                TypeAnnotationPosition position = new TypeAnnotationPosition();
   6.372 +                position.pos = tree.pos;
   6.373 +                position.type = TargetType.LOCAL_VARIABLE;
   6.374 +                for (Attribute.Compound attribute : tree.sym.attributes_field) {
   6.375 +                    Attribute.TypeCompound tc =
   6.376 +                        new Attribute.TypeCompound(attribute.type, attribute.values, position);
   6.377 +                    recordedTypeAnnotations = recordedTypeAnnotations.append(tc);
   6.378 +                }
   6.379 +            }
   6.380 +            try {
   6.381 +                super.visitVarDef(tree);
   6.382 +            } finally {
   6.383 +                if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE)
   6.384 +                    tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
   6.385 +                recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations);
   6.386 +            }
   6.387 +        }
   6.388 +
   6.389 +        @Override
   6.390 +        public void visitApply(JCMethodInvocation tree) {
   6.391 +            scan(tree.meth);
   6.392 +            scan(tree.typeargs);
   6.393 +            scan(tree.args);
   6.394 +        }
   6.395 +
   6.396 +        public void visitAnnotation(JCAnnotation tree) {
   6.397 +            if (tree instanceof JCTypeAnnotation)
   6.398 +                recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field);
   6.399 +            super.visitAnnotation(tree);
   6.400 +        }
   6.401 +    }
   6.402 +
   6.403 +}
     7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Feb 12 13:25:27 2010 -0800
     7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Sun Feb 14 23:39:40 2010 -0800
     7.3 @@ -2047,7 +2047,7 @@
     7.4              Symbol m = TreeInfo.symbol(assign.lhs);
     7.5              if (m == null || m.type.isErroneous()) continue;
     7.6              if (!members.remove(m))
     7.7 -                log.error(arg.pos(), "duplicate.annotation.member.value",
     7.8 +                log.error(assign.lhs.pos(), "duplicate.annotation.member.value",
     7.9                            m.name, a.type);
    7.10              if (assign.rhs.getTag() == ANNOTATION)
    7.11                  validateAnnotation((JCAnnotation)assign.rhs);
     8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Fri Feb 12 13:25:27 2010 -0800
     8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Sun Feb 14 23:39:40 2010 -0800
     8.3 @@ -100,6 +100,7 @@
     8.4      MemberEnter memberEnter;
     8.5      Types types;
     8.6      Lint lint;
     8.7 +    Names names;
     8.8      JavaFileManager fileManager;
     8.9  
    8.10      private final Todo todo;
    8.11 @@ -123,6 +124,7 @@
    8.12          types = Types.instance(context);
    8.13          annotate = Annotate.instance(context);
    8.14          lint = Lint.instance(context);
    8.15 +        names = Names.instance(context);
    8.16  
    8.17          predefClassDef = make.ClassDef(
    8.18              make.Modifiers(PUBLIC),
    8.19 @@ -308,6 +310,17 @@
    8.20                      }
    8.21                  }
    8.22              }
    8.23 +
    8.24 +            for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner)
    8.25 +                q.flags_field |= EXISTS;
    8.26 +
    8.27 +            Name name = names.package_info;
    8.28 +            ClassSymbol c = reader.enterClass(name, tree.packge);
    8.29 +            c.flatname = names.fromString(tree.packge + "." + name);
    8.30 +            c.sourcefile = tree.sourcefile;
    8.31 +            c.completer = null;
    8.32 +            c.members_field = new Scope(c);
    8.33 +            tree.packge.package_info = c;
    8.34          }
    8.35          classEnter(tree.defs, env);
    8.36          if (addEnv) {
     9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Feb 12 13:25:27 2010 -0800
     9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Feb 14 23:39:40 2010 -0800
     9.3 @@ -1994,19 +1994,14 @@
     9.4                                                 tree.packageAnnotations),
     9.5                                  name, List.<JCTypeParameter>nil(),
     9.6                                  null, List.<JCExpression>nil(), List.<JCTree>nil());
     9.7 -            ClassSymbol c = reader.enterClass(name, tree.packge);
     9.8 -            c.flatname = names.fromString(tree.packge + "." + name);
     9.9 -            c.sourcefile = tree.sourcefile;
    9.10 -            c.completer = null;
    9.11 -            c.members_field = new Scope(c);
    9.12 -            c.flags_field = flags;
    9.13 +            ClassSymbol c = tree.packge.package_info;
    9.14 +            c.flags_field |= flags;
    9.15              c.attributes_field = tree.packge.attributes_field;
    9.16              ClassType ctype = (ClassType) c.type;
    9.17              ctype.supertype_field = syms.objectType;
    9.18              ctype.interfaces_field = List.nil();
    9.19              packageAnnotationsClass.sym = c;
    9.20  
    9.21 -
    9.22              translated.append(packageAnnotationsClass);
    9.23          }
    9.24      }
    10.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Feb 12 13:25:27 2010 -0800
    10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Sun Feb 14 23:39:40 2010 -0800
    10.3 @@ -1065,11 +1065,6 @@
    10.4              super.visitNewArray(tree);
    10.5          }
    10.6          @Override
    10.7 -        public void visitApply(JCMethodInvocation tree) {
    10.8 -            super.visitApply(tree);
    10.9 -            scan(tree.typeargs);
   10.10 -        }
   10.11 -        @Override
   10.12          public void visitMethodDef(JCMethodDecl tree) {
   10.13              annotate(tree, tree.receiverAnnotations);
   10.14              super.visitMethodDef(tree);
    11.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Fri Feb 12 13:25:27 2010 -0800
    11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Sun Feb 14 23:39:40 2010 -0800
    11.3 @@ -61,8 +61,6 @@
    11.4          return instance;
    11.5      }
    11.6  
    11.7 -    private boolean debugJSR308;
    11.8 -
    11.9      private Names names;
   11.10      private Log log;
   11.11      private Symtab syms;
   11.12 @@ -71,6 +69,7 @@
   11.13      private boolean allowEnums;
   11.14      private Types types;
   11.15      private final Resolve resolve;
   11.16 +    private final TypeAnnotations typeAnnotations;
   11.17  
   11.18      /**
   11.19       * Flag to indicate whether or not to generate bridge methods.
   11.20 @@ -92,7 +91,7 @@
   11.21          types = Types.instance(context);
   11.22          make = TreeMaker.instance(context);
   11.23          resolve = Resolve.instance(context);
   11.24 -        debugJSR308 = Options.instance(context).get("TA:trans") != null;
   11.25 +        typeAnnotations = TypeAnnotations.instance(context);
   11.26      }
   11.27  
   11.28      /** A hashtable mapping bridge methods to the methods they override after
   11.29 @@ -440,8 +439,7 @@
   11.30      }
   11.31  
   11.32      public void visitClassDef(JCClassDecl tree) {
   11.33 -        new TypeAnnotationPositions().scan(tree);
   11.34 -        new TypeAnnotationLift().scan(tree);
   11.35 +        typeAnnotations.taFillAndLift(tree, true);
   11.36          translateClass(tree.sym);
   11.37          result = tree;
   11.38      }
   11.39 @@ -801,359 +799,4 @@
   11.40          pt = null;
   11.41          return translate(cdef, null);
   11.42      }
   11.43 -
   11.44 -    private class TypeAnnotationPositions extends TreeScanner {
   11.45 -
   11.46 -        private ListBuffer<JCTree> frames = ListBuffer.lb();
   11.47 -        private void push(JCTree t) { frames = frames.prepend(t); }
   11.48 -        private JCTree pop() { return frames.next(); }
   11.49 -        private JCTree peek() { return frames.first(); }
   11.50 -        private JCTree peek2() { return frames.toList().tail.head; }
   11.51 -
   11.52 -        @Override
   11.53 -        public void scan(JCTree tree) {
   11.54 -            push(tree);
   11.55 -            super.scan(tree);
   11.56 -            pop();
   11.57 -        }
   11.58 -
   11.59 -        private boolean inClass = false;
   11.60 -
   11.61 -        @Override
   11.62 -        public void visitClassDef(JCClassDecl tree) {
   11.63 -           if (!inClass) {
   11.64 -               // Do not recurse into nested and inner classes since
   11.65 -               // TransTypes.visitClassDef makes an invocation for each class
   11.66 -               // separately.
   11.67 -               inClass = true;
   11.68 -               try {
   11.69 -                   super.visitClassDef(tree);
   11.70 -               } finally {
   11.71 -                   inClass = false;
   11.72 -               }
   11.73 -           }
   11.74 -        }
   11.75 -
   11.76 -        private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame,
   11.77 -                List<JCTree> path, TypeAnnotationPosition p) {
   11.78 -            switch (frame.getKind()) {
   11.79 -                case TYPE_CAST:
   11.80 -                    p.type = TargetType.TYPECAST;
   11.81 -                    p.pos = frame.pos;
   11.82 -                    return p;
   11.83 -
   11.84 -                case INSTANCE_OF:
   11.85 -                    p.type = TargetType.INSTANCEOF;
   11.86 -                    p.pos = frame.pos;
   11.87 -                    return p;
   11.88 -
   11.89 -                case NEW_CLASS:
   11.90 -                    p.type = TargetType.NEW;
   11.91 -                    p.pos = frame.pos;
   11.92 -                    return p;
   11.93 -
   11.94 -                case NEW_ARRAY:
   11.95 -                    p.type = TargetType.NEW;
   11.96 -                    p.pos = frame.pos;
   11.97 -                    return p;
   11.98 -
   11.99 -                case CLASS:
  11.100 -                    p.pos = frame.pos;
  11.101 -                    if (((JCClassDecl)frame).extending == tree) {
  11.102 -                        p.type = TargetType.CLASS_EXTENDS;
  11.103 -                        p.type_index = -1;
  11.104 -                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
  11.105 -                        p.type = TargetType.CLASS_EXTENDS;
  11.106 -                        p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
  11.107 -                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
  11.108 -                        p.type = TargetType.CLASS_TYPE_PARAMETER;
  11.109 -                        p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
  11.110 -                    } else
  11.111 -                        throw new AssertionError();
  11.112 -                    return p;
  11.113 -
  11.114 -                case METHOD: {
  11.115 -                    JCMethodDecl frameMethod = (JCMethodDecl)frame;
  11.116 -                    p.pos = frame.pos;
  11.117 -                    if (frameMethod.receiverAnnotations.contains(tree))
  11.118 -                        p.type = TargetType.METHOD_RECEIVER;
  11.119 -                    else if (frameMethod.thrown.contains(tree)) {
  11.120 -                        p.type = TargetType.THROWS;
  11.121 -                        p.type_index = frameMethod.thrown.indexOf(tree);
  11.122 -                    } else if (((JCMethodDecl)frame).restype == tree) {
  11.123 -                        p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY;
  11.124 -                    } else if (frameMethod.typarams.contains(tree)) {
  11.125 -                        p.type = TargetType.METHOD_TYPE_PARAMETER;
  11.126 -                        p.parameter_index = frameMethod.typarams.indexOf(tree);
  11.127 -                    } else
  11.128 -                        throw new AssertionError();
  11.129 -                    return p;
  11.130 -                }
  11.131 -                case MEMBER_SELECT: {
  11.132 -                    JCFieldAccess fieldFrame = (JCFieldAccess)frame;
  11.133 -                    if (fieldFrame.name == names._class) {
  11.134 -                        p.type = TargetType.CLASS_LITERAL;
  11.135 -                        if (fieldFrame.selected instanceof JCAnnotatedType) {
  11.136 -                            p.pos = TreeInfo.typeIn(fieldFrame).pos;
  11.137 -                        } else if (fieldFrame.selected instanceof JCArrayTypeTree) {
  11.138 -                            p.pos = fieldFrame.selected.pos;
  11.139 -                        }
  11.140 -                    } else
  11.141 -                        throw new AssertionError();
  11.142 -                    return p;
  11.143 -                }
  11.144 -                case PARAMETERIZED_TYPE: {
  11.145 -                    TypeAnnotationPosition nextP;
  11.146 -                    if (((JCTypeApply)frame).clazz == tree)
  11.147 -                        nextP = p; // generic: RAW; noop
  11.148 -                    else if (((JCTypeApply)frame).arguments.contains(tree))
  11.149 -                        p.location = p.location.prepend(
  11.150 -                                ((JCTypeApply)frame).arguments.indexOf(tree));
  11.151 -                    else
  11.152 -                        throw new AssertionError();
  11.153 -
  11.154 -                    List<JCTree> newPath = path.tail;
  11.155 -                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  11.156 -                }
  11.157 -
  11.158 -                case ARRAY_TYPE: {
  11.159 -                    p.location = p.location.prepend(0);
  11.160 -                    List<JCTree> newPath = path.tail;
  11.161 -                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  11.162 -                }
  11.163 -
  11.164 -                case TYPE_PARAMETER:
  11.165 -                    if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) {
  11.166 -                        JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
  11.167 -                        p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
  11.168 -                        p.parameter_index = clazz.typarams.indexOf(path.tail.head);
  11.169 -                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
  11.170 -                    } else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) {
  11.171 -                        JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
  11.172 -                        p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
  11.173 -                        p.parameter_index = method.typarams.indexOf(path.tail.head);
  11.174 -                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
  11.175 -                    } else
  11.176 -                        throw new AssertionError();
  11.177 -                    p.pos = frame.pos;
  11.178 -                    return p;
  11.179 -
  11.180 -                case VARIABLE:
  11.181 -                    VarSymbol v = ((JCVariableDecl)frame).sym;
  11.182 -                    p.pos = frame.pos;
  11.183 -                    switch (v.getKind()) {
  11.184 -                        case LOCAL_VARIABLE:
  11.185 -                            p.type = TargetType.LOCAL_VARIABLE; break;
  11.186 -                        case FIELD:
  11.187 -                            p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break;
  11.188 -                        case PARAMETER:
  11.189 -                            p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY;
  11.190 -                            p.parameter_index = methodParamIndex(path, frame);
  11.191 -                            break;
  11.192 -                        default: throw new AssertionError();
  11.193 -                    }
  11.194 -                    return p;
  11.195 -
  11.196 -                case ANNOTATED_TYPE: {
  11.197 -                    List<JCTree> newPath = path.tail;
  11.198 -                    return resolveFrame(newPath.head, newPath.tail.head,
  11.199 -                            newPath, p);
  11.200 -                }
  11.201 -
  11.202 -                case METHOD_INVOCATION: {
  11.203 -                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
  11.204 -                    if (!invocation.typeargs.contains(tree))
  11.205 -                        throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
  11.206 -                    p.type = TargetType.METHOD_TYPE_ARGUMENT;
  11.207 -                    p.pos = invocation.pos;
  11.208 -                    p.type_index = invocation.typeargs.indexOf(tree);
  11.209 -                    return p;
  11.210 -                }
  11.211 -
  11.212 -                case EXTENDS_WILDCARD:
  11.213 -                case SUPER_WILDCARD: {
  11.214 -                    p.type = TargetType.WILDCARD_BOUND;
  11.215 -                    List<JCTree> newPath = path.tail;
  11.216 -
  11.217 -                    TypeAnnotationPosition wildcard =
  11.218 -                        resolveFrame(newPath.head, newPath.tail.head, newPath,
  11.219 -                                new TypeAnnotationPosition());
  11.220 -                    if (!wildcard.location.isEmpty())
  11.221 -                        wildcard.type = wildcard.type.getGenericComplement();
  11.222 -                    p.wildcard_position = wildcard;
  11.223 -                    p.pos = frame.pos;
  11.224 -                    return p;
  11.225 -                }
  11.226 -            }
  11.227 -            return p;
  11.228 -        }
  11.229 -
  11.230 -        @Override
  11.231 -        public void visitApply(JCMethodInvocation tree) {
  11.232 -            scan(tree.meth);
  11.233 -            scan(tree.typeargs);
  11.234 -            scan(tree.args);
  11.235 -        }
  11.236 -
  11.237 -        private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) {
  11.238 -            for (JCTypeAnnotation anno : annotations) {
  11.239 -                anno.annotation_position = position;
  11.240 -                anno.attribute_field.position = position;
  11.241 -            }
  11.242 -        }
  11.243 -
  11.244 -        @Override
  11.245 -        public void visitNewArray(JCNewArray tree) {
  11.246 -            findPosition(tree, tree, tree.annotations);
  11.247 -            int dimAnnosCount = tree.dimAnnotations.size();
  11.248 -
  11.249 -            // handle annotations associated with dimentions
  11.250 -            for (int i = 0; i < dimAnnosCount; ++i) {
  11.251 -                TypeAnnotationPosition p = new TypeAnnotationPosition();
  11.252 -                p.type = TargetType.NEW_GENERIC_OR_ARRAY;
  11.253 -                p.pos = tree.pos;
  11.254 -                p.location = p.location.append(i);
  11.255 -                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
  11.256 -            }
  11.257 -
  11.258 -            // handle "free" annotations
  11.259 -            int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
  11.260 -            JCExpression elemType = tree.elemtype;
  11.261 -            while (elemType != null) {
  11.262 -                if (elemType.getTag() == JCTree.ANNOTATED_TYPE) {
  11.263 -                    JCAnnotatedType at = (JCAnnotatedType)elemType;
  11.264 -                    TypeAnnotationPosition p = new TypeAnnotationPosition();
  11.265 -                    p.type = TargetType.NEW_GENERIC_OR_ARRAY;
  11.266 -                    p.pos = tree.pos;
  11.267 -                    p.location = p.location.append(i);
  11.268 -                    setTypeAnnotationPos(at.annotations, p);
  11.269 -                    elemType = at.underlyingType;
  11.270 -                } else if (elemType.getTag() == JCTree.TYPEARRAY) {
  11.271 -                    ++i;
  11.272 -                    elemType = ((JCArrayTypeTree)elemType).elemtype;
  11.273 -                } else
  11.274 -                    break;
  11.275 -            }
  11.276 -
  11.277 -            // find annotations locations of initializer elements
  11.278 -            scan(tree.elems);
  11.279 -        }
  11.280 -
  11.281 -        @Override
  11.282 -        public void visitAnnotatedType(JCAnnotatedType tree) {
  11.283 -            findPosition(tree, peek2(), tree.annotations);
  11.284 -            super.visitAnnotatedType(tree);
  11.285 -        }
  11.286 -
  11.287 -        @Override
  11.288 -        public void visitMethodDef(JCMethodDecl tree) {
  11.289 -            TypeAnnotationPosition p = new TypeAnnotationPosition();
  11.290 -            p.type = TargetType.METHOD_RECEIVER;
  11.291 -            setTypeAnnotationPos(tree.receiverAnnotations, p);
  11.292 -            super.visitMethodDef(tree);
  11.293 -        }
  11.294 -        @Override
  11.295 -        public void visitTypeParameter(JCTypeParameter tree) {
  11.296 -            findPosition(tree, peek2(), tree.annotations);
  11.297 -            super.visitTypeParameter(tree);
  11.298 -        }
  11.299 -
  11.300 -        void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) {
  11.301 -            if (!annotations.isEmpty()) {
  11.302 -                TypeAnnotationPosition p =
  11.303 -                        resolveFrame(tree, frame, frames.toList(),
  11.304 -                                new TypeAnnotationPosition());
  11.305 -                if (!p.location.isEmpty())
  11.306 -                    p.type = p.type.getGenericComplement();
  11.307 -                setTypeAnnotationPos(annotations, p);
  11.308 -                if (debugJSR308) {
  11.309 -                    System.out.println("trans: " + tree);
  11.310 -                    System.out.println("  target: " + p);
  11.311 -                }
  11.312 -            }
  11.313 -        }
  11.314 -
  11.315 -        private int methodParamIndex(List<JCTree> path, JCTree param) {
  11.316 -            List<JCTree> curr = path;
  11.317 -            if (curr.head != param)
  11.318 -                curr = path.tail;
  11.319 -            JCMethodDecl method = (JCMethodDecl)curr.tail.head;
  11.320 -            return method.params.indexOf(param);
  11.321 -        }
  11.322 -    }
  11.323 -
  11.324 -    private class TypeAnnotationLift extends TreeScanner {
  11.325 -        List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil();
  11.326 -
  11.327 -        boolean isInner = false;
  11.328 -        @Override
  11.329 -        public void visitClassDef(JCClassDecl tree) {
  11.330 -            if (isInner) {
  11.331 -                // tree is an inner class tree.  stop now.
  11.332 -                // TransTypes.visitClassDef makes an invocation for each class
  11.333 -                // seperately.
  11.334 -                return;
  11.335 -            }
  11.336 -            isInner = true;
  11.337 -            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  11.338 -            recordedTypeAnnotations = List.nil();
  11.339 -            try {
  11.340 -                super.visitClassDef(tree);
  11.341 -            } finally {
  11.342 -                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  11.343 -                recordedTypeAnnotations = prevTAs;
  11.344 -            }
  11.345 -        }
  11.346 -
  11.347 -        @Override
  11.348 -        public void visitMethodDef(JCMethodDecl tree) {
  11.349 -            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  11.350 -            recordedTypeAnnotations = List.nil();
  11.351 -            try {
  11.352 -                super.visitMethodDef(tree);
  11.353 -            } finally {
  11.354 -                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  11.355 -                recordedTypeAnnotations = prevTAs;
  11.356 -            }
  11.357 -        }
  11.358 -
  11.359 -        @Override
  11.360 -        public void visitVarDef(JCVariableDecl tree) {
  11.361 -            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  11.362 -            recordedTypeAnnotations = List.nil();
  11.363 -            ElementKind kind = tree.sym.getKind();
  11.364 -            if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) {
  11.365 -                // need to lift the annotations
  11.366 -                TypeAnnotationPosition position = new TypeAnnotationPosition();
  11.367 -                position.pos = tree.pos;
  11.368 -                position.type = TargetType.LOCAL_VARIABLE;
  11.369 -                for (Attribute.Compound attribute : tree.sym.attributes_field) {
  11.370 -                    Attribute.TypeCompound tc =
  11.371 -                        new Attribute.TypeCompound(attribute.type, attribute.values, position);
  11.372 -                    recordedTypeAnnotations = recordedTypeAnnotations.append(tc);
  11.373 -                }
  11.374 -            }
  11.375 -            try {
  11.376 -                super.visitVarDef(tree);
  11.377 -            } finally {
  11.378 -                if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE)
  11.379 -                    tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  11.380 -                recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations);
  11.381 -            }
  11.382 -        }
  11.383 -
  11.384 -        @Override
  11.385 -        public void visitApply(JCMethodInvocation tree) {
  11.386 -            scan(tree.meth);
  11.387 -            scan(tree.typeargs);
  11.388 -            scan(tree.args);
  11.389 -        }
  11.390 -
  11.391 -        public void visitAnnotation(JCAnnotation tree) {
  11.392 -            if (tree instanceof JCTypeAnnotation)
  11.393 -                recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field);
  11.394 -            super.visitAnnotation(tree);
  11.395 -        }
  11.396 -    }
  11.397 -
  11.398  }
    12.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Feb 12 13:25:27 2010 -0800
    12.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Sun Feb 14 23:39:40 2010 -0800
    12.3 @@ -1425,11 +1425,11 @@
    12.4           // Class extends and implements clauses
    12.5          case CLASS_EXTENDS:
    12.6          case CLASS_EXTENDS_GENERIC_OR_ARRAY:
    12.7 -            position.type_index = nextByte();
    12.8 +            position.type_index = nextChar();
    12.9              break;
   12.10          // throws
   12.11          case THROWS:
   12.12 -            position.type_index = nextByte();
   12.13 +            position.type_index = nextChar();
   12.14              break;
   12.15          case CLASS_LITERAL:
   12.16          case CLASS_LITERAL_GENERIC_OR_ARRAY:
    13.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Feb 12 13:25:27 2010 -0800
    13.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Sun Feb 14 23:39:40 2010 -0800
    13.3 @@ -965,11 +965,11 @@
    13.4           // Class extends and implements clauses
    13.5          case CLASS_EXTENDS:
    13.6          case CLASS_EXTENDS_GENERIC_OR_ARRAY:
    13.7 -            databuf.appendByte(p.type_index);
    13.8 +            databuf.appendChar(p.type_index);
    13.9              break;
   13.10          // throws
   13.11          case THROWS:
   13.12 -            databuf.appendByte(p.type_index);
   13.13 +            databuf.appendChar(p.type_index);
   13.14              break;
   13.15          case CLASS_LITERAL:
   13.16          case CLASS_LITERAL_GENERIC_OR_ARRAY:
    14.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java	Fri Feb 12 13:25:27 2010 -0800
    14.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java	Sun Feb 14 23:39:40 2010 -0800
    14.3 @@ -1926,9 +1926,9 @@
    14.4          for (Attribute.TypeCompound ta : lv.sym.typeAnnotations) {
    14.5              TypeAnnotationPosition p = ta.position;
    14.6              while (p != null) {
    14.7 -                p.lvarOffset[0] = (int)lv.start_pc;
    14.8 -                p.lvarLength[0] = (int)lv.length;
    14.9 -                p.lvarIndex[0] = (int)lv.reg;
   14.10 +                p.lvarOffset = new int[] { (int)lv.start_pc };
   14.11 +                p.lvarLength = new int[] { (int)lv.length };
   14.12 +                p.lvarIndex = new int[] { (int)lv.reg };
   14.13                  p.isValidOffset = true;
   14.14                  p = p.wildcard_position;
   14.15              }
    15.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Feb 12 13:25:27 2010 -0800
    15.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Sun Feb 14 23:39:40 2010 -0800
    15.3 @@ -1714,7 +1714,7 @@
    15.4          for (Attribute.TypeCompound ta : meth.typeAnnotations) {
    15.5              if (ta.position.pos == treePos) {
    15.6                  ta.position.offset = code.cp;
    15.7 -                ta.position.lvarOffset[0] = code.cp;
    15.8 +                ta.position.lvarOffset = new int[] { code.cp };
    15.9                  ta.position.isValidOffset = true;
   15.10              }
   15.11          }
   15.12 @@ -1726,7 +1726,7 @@
   15.13          for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
   15.14              if (ta.position.pos == treePos) {
   15.15                  ta.position.offset = code.cp;
   15.16 -                ta.position.lvarOffset[0] = code.cp;
   15.17 +                ta.position.lvarOffset = new int[] { code.cp };
   15.18                  ta.position.isValidOffset = true;
   15.19              }
   15.20          }
   15.21 @@ -1738,7 +1738,7 @@
   15.22              for (Attribute.TypeCompound ta : s.typeAnnotations) {
   15.23                  if (ta.position.pos == treePos) {
   15.24                      ta.position.offset = code.cp;
   15.25 -                    ta.position.lvarOffset[0] = code.cp;
   15.26 +                    ta.position.lvarOffset = new int[] { code.cp };
   15.27                      ta.position.isValidOffset = true;
   15.28                  }
   15.29              }
   15.30 @@ -2158,6 +2158,11 @@
   15.31              code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
   15.32              result = items.makeStackItem(pt);
   15.33              return;
   15.34 +        } else if (tree.name == names.TYPE) {
   15.35 +            // Set the annotation positions for primitive class literals
   15.36 +            // (e.g. int.class) which have been converted to TYPE field
   15.37 +            // access on the corresponding boxed type (e.g. Integer.TYPE).
   15.38 +            setTypeAnnotationPositions(tree.pos);
   15.39          }
   15.40  
   15.41          Symbol ssym = TreeInfo.symbol(tree.selected);
    16.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Feb 12 13:25:27 2010 -0800
    16.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sun Feb 14 23:39:40 2010 -0800
    16.3 @@ -761,23 +761,28 @@
    16.4          JCExpression[] odStack = newOdStack();
    16.5          List<Token[]> savedOp = opStackSupply.elems;
    16.6          Token[] opStack = newOpStack();
    16.7 +        List<int[]> savedPos = posStackSupply.elems;
    16.8 +        int[] posStack = newPosStack();
    16.9          // optimization, was odStack = new Tree[...]; opStack = new Tree[...];
   16.10          int top = 0;
   16.11          odStack[0] = t;
   16.12          int startPos = S.pos();
   16.13          Token topOp = ERROR;
   16.14 +        int topOpPos = Position.NOPOS;
   16.15          while (prec(S.token()) >= minprec) {
   16.16 +            posStack[top] = topOpPos;
   16.17              opStack[top] = topOp;
   16.18              top++;
   16.19              topOp = S.token();
   16.20 -            int pos = S.pos();
   16.21 +            topOpPos = S.pos();
   16.22              S.nextToken();
   16.23 -            odStack[top] = topOp == INSTANCEOF ? parseType() : term3();
   16.24 +            odStack[top] = (topOp == INSTANCEOF) ? parseType() : term3();
   16.25              while (top > 0 && prec(topOp) >= prec(S.token())) {
   16.26 -                odStack[top-1] = makeOp(pos, topOp, odStack[top-1],
   16.27 +                odStack[top-1] = makeOp(topOpPos, topOp, odStack[top-1],
   16.28                                          odStack[top]);
   16.29                  top--;
   16.30                  topOp = opStack[top];
   16.31 +                topOpPos = posStack[top];
   16.32              }
   16.33          }
   16.34          assert top == 0;
   16.35 @@ -792,6 +797,7 @@
   16.36  
   16.37          odStackSupply.elems = savedOd; // optimization
   16.38          opStackSupply.elems = savedOp; // optimization
   16.39 +        posStackSupply.elems = savedPos; // optimization
   16.40          return t;
   16.41      }
   16.42  //where
   16.43 @@ -845,6 +851,7 @@
   16.44           */
   16.45          ListBuffer<JCExpression[]> odStackSupply = new ListBuffer<JCExpression[]>();
   16.46          ListBuffer<Token[]> opStackSupply = new ListBuffer<Token[]>();
   16.47 +        ListBuffer<int[]> posStackSupply = new ListBuffer<int[]>();
   16.48  
   16.49          private JCExpression[] newOdStack() {
   16.50              if (odStackSupply.elems == odStackSupply.last)
   16.51 @@ -862,6 +869,14 @@
   16.52              return opStack;
   16.53          }
   16.54  
   16.55 +        private int[] newPosStack() {
   16.56 +            if (posStackSupply.elems == posStackSupply.last)
   16.57 +                posStackSupply.append(new int[infixPrecedenceLevels + 1]);
   16.58 +            int[] posStack = posStackSupply.elems.head;
   16.59 +            posStackSupply.elems = posStackSupply.elems.tail;
   16.60 +            return posStack;
   16.61 +        }
   16.62 +
   16.63      /** Expression3    = PrefixOp Expression3
   16.64       *                 | "(" Expr | TypeNoParams ")" Expression3
   16.65       *                 | Primary {Selector} {PostfixOp}
   16.66 @@ -939,7 +954,7 @@
   16.67                              args.append(typeArgument());
   16.68                          }
   16.69                          accept(GT);
   16.70 -                        t = F.at(pos1).TypeApply(t, args.toList());
   16.71 +                        t = toP(F.at(pos1).TypeApply(t, args.toList()));
   16.72                          checkGenerics();
   16.73                          while (S.token() == DOT) {
   16.74                              S.nextToken();
   16.75 @@ -950,7 +965,8 @@
   16.76                          t = bracketsOpt(toP(t));
   16.77                      } else if ((mode & EXPR) != 0) {
   16.78                          mode = EXPR;
   16.79 -                        t = F.at(pos1).Binary(op, t, term2Rest(t1, TreeInfo.shiftPrec));
   16.80 +                        JCExpression e = term2Rest(t1, TreeInfo.shiftPrec);
   16.81 +                        t = F.at(pos1).Binary(op, t, e);
   16.82                          t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec)));
   16.83                      } else {
   16.84                          accept(GT);
   16.85 @@ -998,7 +1014,8 @@
   16.86          case SUPER:
   16.87              if ((mode & EXPR) != 0) {
   16.88                  mode = EXPR;
   16.89 -                t = to(superSuffix(typeArgs, F.at(pos).Ident(names._super)));
   16.90 +                t = to(F.at(pos).Ident(names._super));
   16.91 +                t = superSuffix(typeArgs, t);
   16.92                  typeArgs = null;
   16.93              } else return illegal();
   16.94              break;
   16.95 @@ -1380,13 +1397,15 @@
   16.96          S.nextToken();
   16.97          JCExpression result;
   16.98          if (S.token() == EXTENDS) {
   16.99 -            TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.EXTENDS));
  16.100 +            TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.EXTENDS));
  16.101              S.nextToken();
  16.102 -            result = F.at(pos).Wildcard(t, parseType());
  16.103 +            JCExpression bound = parseType();
  16.104 +            result = F.at(pos).Wildcard(t, bound);
  16.105          } else if (S.token() == SUPER) {
  16.106 -            TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.SUPER));
  16.107 +            TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.SUPER));
  16.108              S.nextToken();
  16.109 -            result = F.at(pos).Wildcard(t, parseType());
  16.110 +            JCExpression bound = parseType();
  16.111 +            result = F.at(pos).Wildcard(t, bound);
  16.112          } else if (S.token() == IDENTIFIER) {
  16.113              //error recovery
  16.114              reportSyntaxError(S.prevEndPos(), "expected3",
  16.115 @@ -1396,7 +1415,7 @@
  16.116              JCIdent id = toP(F.at(S.pos()).Ident(ident()));
  16.117              result = F.at(pos).Erroneous(List.<JCTree>of(wc, id));
  16.118          } else {
  16.119 -            TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
  16.120 +            TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND));
  16.121              result = toP(F.at(pos).Wildcard(t, null));
  16.122          }
  16.123          if (!annotations.isEmpty())
  16.124 @@ -2117,14 +2136,21 @@
  16.125          return modifiersOpt(null);
  16.126      }
  16.127      JCModifiers modifiersOpt(JCModifiers partial) {
  16.128 -        long flags = (partial == null) ? 0 : partial.flags;
  16.129 +        long flags;
  16.130 +        ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>();
  16.131 +        int pos;
  16.132 +        if (partial == null) {
  16.133 +            flags = 0;
  16.134 +            pos = S.pos();
  16.135 +        } else {
  16.136 +            flags = partial.flags;
  16.137 +            annotations.appendList(partial.annotations);
  16.138 +            pos = partial.pos;
  16.139 +        }
  16.140          if (S.deprecatedFlag()) {
  16.141              flags |= Flags.DEPRECATED;
  16.142              S.resetDeprecatedFlag();
  16.143          }
  16.144 -        ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>();
  16.145 -        if (partial != null) annotations.appendList(partial.annotations);
  16.146 -        int pos = S.pos();
  16.147          int lastPos = Position.NOPOS;
  16.148      loop:
  16.149          while (true) {
  16.150 @@ -2150,12 +2176,12 @@
  16.151              if (flag == Flags.ANNOTATION) {
  16.152                  checkAnnotations();
  16.153                  if (S.token() != INTERFACE) {
  16.154 -                JCAnnotation ann = annotation(lastPos, AnnotationKind.DEFAULT_ANNO);
  16.155 -                // if first modifier is an annotation, set pos to annotation's.
  16.156 -                if (flags == 0 && annotations.isEmpty())
  16.157 -                    pos = ann.pos;
  16.158 -                annotations.append(ann);
  16.159 -                lastPos = ann.pos;
  16.160 +                    JCAnnotation ann = annotation(lastPos, AnnotationKind.DEFAULT_ANNO);
  16.161 +                    // if first modifier is an annotation, set pos to annotation's.
  16.162 +                    if (flags == 0 && annotations.isEmpty())
  16.163 +                        pos = ann.pos;
  16.164 +                    annotations.append(ann);
  16.165 +                    lastPos = ann.pos;
  16.166                      flag = 0;
  16.167                  }
  16.168              }
  16.169 @@ -2169,7 +2195,7 @@
  16.170  
  16.171          /* A modifiers tree with no modifier tokens or annotations
  16.172           * has no text position. */
  16.173 -        if (flags == 0 && annotations.isEmpty())
  16.174 +        if ((flags & Flags.ModifierFlags) == 0 && annotations.isEmpty())
  16.175              pos = Position.NOPOS;
  16.176  
  16.177          JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList());
  16.178 @@ -2226,7 +2252,8 @@
  16.179              if (t1.getTag() == JCTree.IDENT && S.token() == EQ) {
  16.180                  int pos = S.pos();
  16.181                  accept(EQ);
  16.182 -                return toP(F.at(pos).Assign(t1, annotationValue()));
  16.183 +                JCExpression v = annotationValue();
  16.184 +                return toP(F.at(pos).Assign(t1, v));
  16.185              } else {
  16.186                  return t1;
  16.187              }
  16.188 @@ -2543,10 +2570,9 @@
  16.189          }
  16.190  
  16.191          List<JCTree> defs = enumBody(name);
  16.192 -        JCModifiers newMods =
  16.193 -            F.at(mods.pos).Modifiers(mods.flags|Flags.ENUM, mods.annotations);
  16.194 +        mods.flags |= Flags.ENUM;
  16.195          JCClassDecl result = toP(F.at(pos).
  16.196 -            ClassDef(newMods, name, List.<JCTypeParameter>nil(),
  16.197 +            ClassDef(mods, name, List.<JCTypeParameter>nil(),
  16.198                  null, implementing, defs));
  16.199          attach(result, dc);
  16.200          return result;
  16.201 @@ -2695,16 +2721,8 @@
  16.202              } else {
  16.203                  pos = S.pos();
  16.204                  List<JCTypeParameter> typarams = typeParametersOpt();
  16.205 -                // Hack alert:  if there are type arguments but no Modifiers, the start
  16.206 -                // position will be lost unless we set the Modifiers position.  There
  16.207 -                // should be an AST node for type parameters (BugId 5005090).
  16.208 -                if (typarams.length() > 0 && mods.pos == Position.NOPOS) {
  16.209 -                    mods.pos = pos;
  16.210 -                }
  16.211 -
  16.212                  List<JCAnnotation> annosAfterParams = annotationsOpt(AnnotationKind.DEFAULT_ANNO);
  16.213  
  16.214 -                Token token = S.token();
  16.215                  Name name = S.name();
  16.216                  pos = S.pos();
  16.217                  JCExpression type;
  16.218 @@ -2715,7 +2733,11 @@
  16.219                      type = to(F.at(pos).TypeIdent(TypeTags.VOID));
  16.220                      S.nextToken();
  16.221                  } else {
  16.222 -                    mods.annotations = mods.annotations.appendList(annosAfterParams);
  16.223 +                    if (annosAfterParams.nonEmpty()) {
  16.224 +                        mods.annotations = mods.annotations.appendList(annosAfterParams);
  16.225 +                        if (mods.pos == Position.NOPOS)
  16.226 +                            mods.pos = mods.annotations.head.pos;
  16.227 +                    }
  16.228                      // method returns types are un-annotated types
  16.229                      type = unannotatedType();
  16.230                  }
  16.231 @@ -2813,6 +2835,7 @@
  16.232                  }
  16.233              }
  16.234          }
  16.235 +
  16.236          JCMethodDecl result =
  16.237              toP(F.at(pos).MethodDef(mods, name, type, typarams,
  16.238                                      params, receiverAnnotations, thrown,
    17.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Fri Feb 12 13:25:27 2010 -0800
    17.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Sun Feb 14 23:39:40 2010 -0800
    17.3 @@ -67,6 +67,7 @@
    17.4  import com.sun.tools.javac.tree.JCTree.*;
    17.5  import com.sun.tools.javac.util.Abort;
    17.6  import com.sun.tools.javac.util.Context;
    17.7 +import com.sun.tools.javac.util.Convert;
    17.8  import com.sun.tools.javac.util.List;
    17.9  import com.sun.tools.javac.util.ListBuffer;
   17.10  import com.sun.tools.javac.util.Log;
   17.11 @@ -893,14 +894,20 @@
   17.12                          errorStatus = true;
   17.13                          break runAround;
   17.14                      } else {
   17.15 -                        ListBuffer<ClassSymbol> classes = enterNewClassFiles(currentContext);
   17.16 +                        List<ClassSymbol> newClasses = enterNewClassFiles(currentContext);
   17.17                          compiler.enterTrees(roots);
   17.18  
   17.19                          // annotationsPresentInSource =
   17.20                          // collector.findAnnotations(parsedFiles);
   17.21 -                        classes.appendList(getTopLevelClasses(parsedFiles));
   17.22 -                        topLevelClasses  = classes.toList();
   17.23 -                        packageInfoFiles = getPackageInfoFiles(parsedFiles);
   17.24 +                        ListBuffer<ClassSymbol> tlc = new ListBuffer<ClassSymbol>();
   17.25 +                        tlc.appendList(getTopLevelClasses(parsedFiles));
   17.26 +                        tlc.appendList(getTopLevelClassesFromClasses(newClasses));
   17.27 +                        topLevelClasses  = tlc.toList();
   17.28 +
   17.29 +                        ListBuffer<PackageSymbol> pif = new ListBuffer<PackageSymbol>();
   17.30 +                        pif.appendList(getPackageInfoFiles(parsedFiles));
   17.31 +                        pif.appendList(getPackageInfoFilesFromClasses(newClasses));
   17.32 +                        packageInfoFiles = pif.toList();
   17.33  
   17.34                          annotationsPresent = new LinkedHashSet<TypeElement>();
   17.35                          for (ClassSymbol classSym : topLevelClasses)
   17.36 @@ -1026,20 +1033,30 @@
   17.37          }
   17.38      }
   17.39  
   17.40 -    private ListBuffer<ClassSymbol> enterNewClassFiles(Context currentContext) {
   17.41 +    private List<ClassSymbol> enterNewClassFiles(Context currentContext) {
   17.42          ClassReader reader = ClassReader.instance(currentContext);
   17.43          Names names = Names.instance(currentContext);
   17.44 -        ListBuffer<ClassSymbol> list = new ListBuffer<ClassSymbol>();
   17.45 +        List<ClassSymbol> list = List.nil();
   17.46  
   17.47          for (Map.Entry<String,JavaFileObject> entry : filer.getGeneratedClasses().entrySet()) {
   17.48              Name name = names.fromString(entry.getKey());
   17.49              JavaFileObject file = entry.getValue();
   17.50              if (file.getKind() != JavaFileObject.Kind.CLASS)
   17.51                  throw new AssertionError(file);
   17.52 -            ClassSymbol cs = reader.enterClass(name, file);
   17.53 -            list.append(cs);
   17.54 +            ClassSymbol cs;
   17.55 +            if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
   17.56 +                Name packageName = Convert.packagePart(name);
   17.57 +                PackageSymbol p = reader.enterPackage(packageName);
   17.58 +                if (p.package_info == null)
   17.59 +                    p.package_info = reader.enterClass(Convert.shortName(name), p);
   17.60 +                cs = p.package_info;
   17.61 +                if (cs.classfile == null)
   17.62 +                    cs.classfile = file;
   17.63 +            } else
   17.64 +                cs = reader.enterClass(name, file);
   17.65 +            list = list.prepend(cs);
   17.66          }
   17.67 -        return list;
   17.68 +        return list.reverse();
   17.69      }
   17.70  
   17.71      /**
   17.72 @@ -1066,18 +1083,44 @@
   17.73          return classes.reverse();
   17.74      }
   17.75  
   17.76 +    private List<ClassSymbol> getTopLevelClassesFromClasses(List<? extends ClassSymbol> syms) {
   17.77 +        List<ClassSymbol> classes = List.nil();
   17.78 +        for (ClassSymbol sym : syms) {
   17.79 +            if (!isPkgInfo(sym)) {
   17.80 +                classes = classes.prepend(sym);
   17.81 +            }
   17.82 +        }
   17.83 +        return classes.reverse();
   17.84 +    }
   17.85 +
   17.86      private List<PackageSymbol> getPackageInfoFiles(List<? extends JCCompilationUnit> units) {
   17.87          List<PackageSymbol> packages = List.nil();
   17.88          for (JCCompilationUnit unit : units) {
   17.89 -            boolean isPkgInfo = unit.sourcefile.isNameCompatible("package-info",
   17.90 -                                                                 JavaFileObject.Kind.SOURCE);
   17.91 -            if (isPkgInfo) {
   17.92 +            if (isPkgInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE)) {
   17.93                  packages = packages.prepend(unit.packge);
   17.94              }
   17.95          }
   17.96          return packages.reverse();
   17.97      }
   17.98  
   17.99 +    private List<PackageSymbol> getPackageInfoFilesFromClasses(List<? extends ClassSymbol> syms) {
  17.100 +        List<PackageSymbol> packages = List.nil();
  17.101 +        for (ClassSymbol sym : syms) {
  17.102 +            if (isPkgInfo(sym)) {
  17.103 +                packages = packages.prepend((PackageSymbol) sym.owner);
  17.104 +            }
  17.105 +        }
  17.106 +        return packages.reverse();
  17.107 +    }
  17.108 +
  17.109 +    private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) {
  17.110 +        return fo.isNameCompatible("package-info", kind);
  17.111 +    }
  17.112 +
  17.113 +    private boolean isPkgInfo(ClassSymbol sym) {
  17.114 +        return isPkgInfo(sym.classfile, JavaFileObject.Kind.CLASS) && (sym.packge().package_info == sym);
  17.115 +    }
  17.116 +
  17.117      private Context contextForNextRound(Context context, boolean shareNames)
  17.118          throws IOException
  17.119      {
  17.120 @@ -1252,10 +1295,6 @@
  17.121                  node.sym = null;
  17.122                  super.visitIdent(node);
  17.123              }
  17.124 -            public void visitApply(JCMethodInvocation node) {
  17.125 -                scan(node.typeargs);
  17.126 -                super.visitApply(node);
  17.127 -            }
  17.128          };
  17.129  
  17.130  
    18.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Fri Feb 12 13:25:27 2010 -0800
    18.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Sun Feb 14 23:39:40 2010 -0800
    18.3 @@ -307,8 +307,18 @@
    18.4          case(JCTree.POSTINC):
    18.5          case(JCTree.POSTDEC):
    18.6              return getStartPos(((JCUnary) tree).arg);
    18.7 -        case(JCTree.ANNOTATED_TYPE):
    18.8 -            return getStartPos(((JCAnnotatedType) tree).underlyingType);
    18.9 +        case(JCTree.ANNOTATED_TYPE): {
   18.10 +            JCAnnotatedType node = (JCAnnotatedType) tree;
   18.11 +            if (node.annotations.nonEmpty())
   18.12 +                return getStartPos(node.annotations.head);
   18.13 +            return getStartPos(node.underlyingType);
   18.14 +        }
   18.15 +        case(JCTree.NEWCLASS): {
   18.16 +            JCNewClass node = (JCNewClass)tree;
   18.17 +            if (node.encl != null)
   18.18 +                return getStartPos(node.encl);
   18.19 +            break;
   18.20 +        }
   18.21          case(JCTree.VARDEF): {
   18.22              JCVariableDecl node = (JCVariableDecl)tree;
   18.23              if (node.mods.pos != Position.NOPOS) {
   18.24 @@ -406,6 +416,8 @@
   18.25              return getEndPos(((JCUnary) tree).arg, endPositions);
   18.26          case(JCTree.WHILELOOP):
   18.27              return getEndPos(((JCWhileLoop) tree).body, endPositions);
   18.28 +        case(JCTree.ANNOTATED_TYPE):
   18.29 +            return getEndPos(((JCAnnotatedType) tree).underlyingType, endPositions);
   18.30          case(JCTree.ERRONEOUS): {
   18.31              JCErroneous node = (JCErroneous)tree;
   18.32              if (node.errs != null && node.errs.nonEmpty())
    19.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Fri Feb 12 13:25:27 2010 -0800
    19.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sun Feb 14 23:39:40 2010 -0800
    19.3 @@ -480,7 +480,7 @@
    19.4  
    19.5      public JCModifiers Modifiers(long flags, List<JCAnnotation> annotations) {
    19.6          JCModifiers tree = new JCModifiers(flags, annotations);
    19.7 -        boolean noFlags = (flags & Flags.StandardFlags) == 0;
    19.8 +        boolean noFlags = (flags & Flags.ModifierFlags) == 0;
    19.9          tree.pos = (noFlags && annotations.isEmpty()) ? Position.NOPOS : pos;
   19.10          return tree;
   19.11      }
    20.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Fri Feb 12 13:25:27 2010 -0800
    20.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Sun Feb 14 23:39:40 2010 -0800
    20.3 @@ -193,6 +193,7 @@
    20.4      }
    20.5  
    20.6      public void visitApply(JCMethodInvocation tree) {
    20.7 +        scan(tree.typeargs);
    20.8          scan(tree.meth);
    20.9          scan(tree.args);
   20.10      }
   20.11 @@ -200,6 +201,7 @@
   20.12      public void visitNewClass(JCNewClass tree) {
   20.13          scan(tree.encl);
   20.14          scan(tree.clazz);
   20.15 +        scan(tree.typeargs);
   20.16          scan(tree.args);
   20.17          scan(tree.def);
   20.18      }
    21.1 --- a/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Fri Feb 12 13:25:27 2010 -0800
    21.2 +++ b/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Sun Feb 14 23:39:40 2010 -0800
    21.3 @@ -162,6 +162,7 @@
    21.4              print(pos.type_index);
    21.5              break;
    21.6          case CLASS_LITERAL:
    21.7 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
    21.8              if (showOffsets) {
    21.9                  print(", offset=");
   21.10                  print(pos.offset);
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/test/tools/javac/T6654037.java	Sun Feb 14 23:39:40 2010 -0800
    22.3 @@ -0,0 +1,76 @@
    22.4 +/*
    22.5 + * Copyright 2008-2010 Sun Microsystems, Inc.  All Rights Reserved.
    22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.7 + *
    22.8 + * This code is free software; you can redistribute it and/or modify it
    22.9 + * under the terms of the GNU General Public License version 2 only, as
   22.10 + * published by the Free Software Foundation.
   22.11 + *
   22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   22.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   22.15 + * version 2 for more details (a copy is included in the LICENSE file that
   22.16 + * accompanied this code).
   22.17 + *
   22.18 + * You should have received a copy of the GNU General Public License version
   22.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   22.21 + *
   22.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   22.24 + * have any questions.
   22.25 + */
   22.26 +
   22.27 +/*
   22.28 + * @test
   22.29 + * @bug 6654037
   22.30 + * @summary JCTree.pos may be incorrect for BinaryTrees
   22.31 + */
   22.32 +
   22.33 +import com.sun.source.tree.BinaryTree;
   22.34 +import com.sun.source.tree.ClassTree;
   22.35 +import com.sun.source.tree.CompilationUnitTree;
   22.36 +import com.sun.source.tree.MethodTree;
   22.37 +import com.sun.source.tree.VariableTree;
   22.38 +import com.sun.tools.javac.api.JavacTaskImpl;
   22.39 +import com.sun.tools.javac.tree.JCTree;
   22.40 +import java.net.URI;
   22.41 +import java.util.Arrays;
   22.42 +import javax.tools.JavaCompiler;
   22.43 +import javax.tools.JavaFileObject;
   22.44 +import javax.tools.SimpleJavaFileObject;
   22.45 +import javax.tools.ToolProvider;
   22.46 +
   22.47 +public class T6654037 {
   22.48 +
   22.49 +    public static void main(String[] args) throws Exception {
   22.50 +        final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
   22.51 +        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
   22.52 +        assert tool != null;
   22.53 +
   22.54 +        String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";
   22.55 +
   22.56 +        JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
   22.57 +        CompilationUnitTree cut = ct.parse().iterator().next();
   22.58 +        ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
   22.59 +        MethodTree method = (MethodTree) clazz.getMembers().get(0);
   22.60 +        VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
   22.61 +        BinaryTree cond = (BinaryTree) condSt.getInitializer();
   22.62 +        JCTree condJC = (JCTree) cond;
   22.63 +
   22.64 +        if (condJC.pos != 93)
   22.65 +            throw new IllegalStateException("Unexpected position=" + condJC.pos);
   22.66 +    }
   22.67 +
   22.68 +    static class MyFileObject extends SimpleJavaFileObject {
   22.69 +        private String text;
   22.70 +        public MyFileObject(String text) {
   22.71 +            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
   22.72 +            this.text = text;
   22.73 +        }
   22.74 +        @Override
   22.75 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
   22.76 +            return text;
   22.77 +        }
   22.78 +    }
   22.79 +}
    23.1 --- a/test/tools/javac/generics/diamond/neg/Neg01.out	Fri Feb 12 13:25:27 2010 -0800
    23.2 +++ b/test/tools/javac/generics/diamond/neg/Neg01.out	Sun Feb 14 23:39:40 2010 -0800
    23.3 @@ -1,31 +1,31 @@
    23.4  Neg01.java:18:15: compiler.err.not.within.bounds: java.lang.String
    23.5  Neg01.java:18:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
    23.6 -Neg01.java:19:25: compiler.err.not.within.bounds: ? extends java.lang.String
    23.7 +Neg01.java:19:15: compiler.err.not.within.bounds: ? extends java.lang.String
    23.8  Neg01.java:19:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
    23.9  Neg01.java:20:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number>
   23.10 -Neg01.java:21:23: compiler.err.not.within.bounds: ? super java.lang.String
   23.11 +Neg01.java:21:15: compiler.err.not.within.bounds: ? super java.lang.String
   23.12  Neg01.java:21:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
   23.13  Neg01.java:23:15: compiler.err.not.within.bounds: java.lang.String
   23.14  Neg01.java:23:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
   23.15 -Neg01.java:24:25: compiler.err.not.within.bounds: ? extends java.lang.String
   23.16 +Neg01.java:24:15: compiler.err.not.within.bounds: ? extends java.lang.String
   23.17  Neg01.java:24:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   23.18  Neg01.java:25:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number>
   23.19  Neg01.java:25:38: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number>
   23.20 -Neg01.java:26:23: compiler.err.not.within.bounds: ? super java.lang.String
   23.21 +Neg01.java:26:15: compiler.err.not.within.bounds: ? super java.lang.String
   23.22  Neg01.java:26:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
   23.23  Neg01.java:28:15: compiler.err.not.within.bounds: java.lang.String
   23.24  Neg01.java:28:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
   23.25 -Neg01.java:29:25: compiler.err.not.within.bounds: ? extends java.lang.String
   23.26 +Neg01.java:29:15: compiler.err.not.within.bounds: ? extends java.lang.String
   23.27  Neg01.java:29:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   23.28  Neg01.java:30:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
   23.29  Neg01.java:31:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , kindname.class, Neg01<X>
   23.30  Neg01.java:31:35: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
   23.31  Neg01.java:33:15: compiler.err.not.within.bounds: java.lang.String
   23.32  Neg01.java:33:38: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
   23.33 -Neg01.java:34:25: compiler.err.not.within.bounds: ? extends java.lang.String
   23.34 +Neg01.java:34:15: compiler.err.not.within.bounds: ? extends java.lang.String
   23.35  Neg01.java:34:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   23.36  Neg01.java:35:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
   23.37  Neg01.java:35:43: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number>
   23.38 -Neg01.java:36:23: compiler.err.not.within.bounds: ? super java.lang.String
   23.39 +Neg01.java:36:15: compiler.err.not.within.bounds: ? super java.lang.String
   23.40  Neg01.java:36:46: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
   23.41  30 errors
    24.1 --- a/test/tools/javac/generics/diamond/neg/Neg02.out	Fri Feb 12 13:25:27 2010 -0800
    24.2 +++ b/test/tools/javac/generics/diamond/neg/Neg02.out	Sun Feb 14 23:39:40 2010 -0800
    24.3 @@ -1,61 +1,61 @@
    24.4  Neg02.java:19:13: compiler.err.not.within.bounds: java.lang.String
    24.5  Neg02.java:19:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
    24.6 -Neg02.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String
    24.7 +Neg02.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String
    24.8  Neg02.java:20:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
    24.9  Neg02.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.10 -Neg02.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.11 +Neg02.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.12  Neg02.java:22:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.13  Neg02.java:24:13: compiler.err.not.within.bounds: java.lang.String
   24.14  Neg02.java:24:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.15 -Neg02.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.16 +Neg02.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.17  Neg02.java:25:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.18  Neg02.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.19  Neg02.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
   24.20 -Neg02.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.21 +Neg02.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.22  Neg02.java:27:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.23  Neg02.java:29:13: compiler.err.not.within.bounds: java.lang.String
   24.24  Neg02.java:29:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.25 -Neg02.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.26 +Neg02.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.27  Neg02.java:30:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.28  Neg02.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.29 -Neg02.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.30 +Neg02.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.31  Neg02.java:32:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.32  Neg02.java:34:13: compiler.err.not.within.bounds: java.lang.String
   24.33  Neg02.java:34:34: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.34 -Neg02.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.35 +Neg02.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.36  Neg02.java:35:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.37  Neg02.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.38  Neg02.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
   24.39 -Neg02.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.40 +Neg02.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.41  Neg02.java:37:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.42  Neg02.java:41:13: compiler.err.not.within.bounds: java.lang.String
   24.43  Neg02.java:41:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.44 -Neg02.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.45 +Neg02.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.46  Neg02.java:42:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.47  Neg02.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.48 -Neg02.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.49 +Neg02.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.50  Neg02.java:44:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.51  Neg02.java:46:13: compiler.err.not.within.bounds: java.lang.String
   24.52  Neg02.java:46:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.53 -Neg02.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.54 +Neg02.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.55  Neg02.java:47:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.56  Neg02.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.57  Neg02.java:48:40: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
   24.58 -Neg02.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.59 +Neg02.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.60  Neg02.java:49:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.61  Neg02.java:51:13: compiler.err.not.within.bounds: java.lang.String
   24.62  Neg02.java:51:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.63 -Neg02.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.64 +Neg02.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.65  Neg02.java:52:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.66  Neg02.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.67 -Neg02.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.68 +Neg02.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.69  Neg02.java:54:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.70  Neg02.java:56:13: compiler.err.not.within.bounds: java.lang.String
   24.71  Neg02.java:56:40: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
   24.72 -Neg02.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String
   24.73 +Neg02.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String
   24.74  Neg02.java:57:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
   24.75  Neg02.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
   24.76  Neg02.java:58:45: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
   24.77 -Neg02.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String
   24.78 +Neg02.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String
   24.79  Neg02.java:59:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
   24.80  60 errors
    25.1 --- a/test/tools/javac/generics/diamond/neg/Neg03.out	Fri Feb 12 13:25:27 2010 -0800
    25.2 +++ b/test/tools/javac/generics/diamond/neg/Neg03.out	Sun Feb 14 23:39:40 2010 -0800
    25.3 @@ -1,91 +1,91 @@
    25.4  Neg03.java:19:13: compiler.err.not.within.bounds: java.lang.String
    25.5  Neg03.java:19:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
    25.6 -Neg03.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String
    25.7 +Neg03.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String
    25.8  Neg03.java:20:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
    25.9  Neg03.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.10 -Neg03.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.11 +Neg03.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.12  Neg03.java:22:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.13  Neg03.java:24:13: compiler.err.not.within.bounds: java.lang.String
   25.14  Neg03.java:24:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.15 -Neg03.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.16 +Neg03.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.17  Neg03.java:25:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.18  Neg03.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.19  Neg03.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.20 -Neg03.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.21 +Neg03.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.22  Neg03.java:27:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.23  Neg03.java:29:13: compiler.err.not.within.bounds: java.lang.String
   25.24  Neg03.java:29:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.25 -Neg03.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.26 +Neg03.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.27  Neg03.java:30:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.28  Neg03.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.29 -Neg03.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.30 +Neg03.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.31  Neg03.java:32:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.32  Neg03.java:34:13: compiler.err.not.within.bounds: java.lang.String
   25.33  Neg03.java:34:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.34 -Neg03.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.35 +Neg03.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.36  Neg03.java:35:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.37  Neg03.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.38  Neg03.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.39 -Neg03.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.40 +Neg03.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.41  Neg03.java:37:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.42  Neg03.java:41:13: compiler.err.not.within.bounds: java.lang.String
   25.43  Neg03.java:41:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.44 -Neg03.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.45 +Neg03.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.46  Neg03.java:42:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.47  Neg03.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.48 -Neg03.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.49 +Neg03.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.50  Neg03.java:44:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.51  Neg03.java:46:13: compiler.err.not.within.bounds: java.lang.String
   25.52  Neg03.java:46:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.53 -Neg03.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.54 +Neg03.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.55  Neg03.java:47:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.56  Neg03.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.57  Neg03.java:48:43: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.58 -Neg03.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.59 +Neg03.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.60  Neg03.java:49:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.61  Neg03.java:51:13: compiler.err.not.within.bounds: java.lang.String
   25.62  Neg03.java:51:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.63 -Neg03.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.64 +Neg03.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.65  Neg03.java:52:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.66  Neg03.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.67 -Neg03.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.68 +Neg03.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.69  Neg03.java:54:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.70  Neg03.java:56:13: compiler.err.not.within.bounds: java.lang.String
   25.71  Neg03.java:56:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.72 -Neg03.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.73 +Neg03.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.74  Neg03.java:57:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.75  Neg03.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.76  Neg03.java:58:48: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.77 -Neg03.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.78 +Neg03.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.79  Neg03.java:59:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.80  Neg03.java:63:13: compiler.err.not.within.bounds: java.lang.String
   25.81  Neg03.java:63:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.82 -Neg03.java:64:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.83 +Neg03.java:64:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.84  Neg03.java:64:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.85  Neg03.java:65:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.86 -Neg03.java:66:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.87 +Neg03.java:66:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.88  Neg03.java:66:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.89  Neg03.java:68:13: compiler.err.not.within.bounds: java.lang.String
   25.90  Neg03.java:68:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
   25.91 -Neg03.java:69:23: compiler.err.not.within.bounds: ? extends java.lang.String
   25.92 +Neg03.java:69:13: compiler.err.not.within.bounds: ? extends java.lang.String
   25.93  Neg03.java:69:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   25.94  Neg03.java:70:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.95  Neg03.java:70:36: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
   25.96 -Neg03.java:71:21: compiler.err.not.within.bounds: ? super java.lang.String
   25.97 +Neg03.java:71:13: compiler.err.not.within.bounds: ? super java.lang.String
   25.98  Neg03.java:71:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
   25.99  Neg03.java:73:13: compiler.err.not.within.bounds: java.lang.String
  25.100  Neg03.java:73:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
  25.101 -Neg03.java:74:23: compiler.err.not.within.bounds: ? extends java.lang.String
  25.102 +Neg03.java:74:13: compiler.err.not.within.bounds: ? extends java.lang.String
  25.103  Neg03.java:74:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
  25.104  Neg03.java:75:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
  25.105 -Neg03.java:76:21: compiler.err.not.within.bounds: ? super java.lang.String
  25.106 +Neg03.java:76:13: compiler.err.not.within.bounds: ? super java.lang.String
  25.107  Neg03.java:76:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
  25.108  Neg03.java:78:13: compiler.err.not.within.bounds: java.lang.String
  25.109  Neg03.java:78:29: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
  25.110 -Neg03.java:79:23: compiler.err.not.within.bounds: ? extends java.lang.String
  25.111 +Neg03.java:79:13: compiler.err.not.within.bounds: ? extends java.lang.String
  25.112  Neg03.java:79:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
  25.113  Neg03.java:80:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
  25.114  Neg03.java:80:41: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
  25.115 -Neg03.java:81:21: compiler.err.not.within.bounds: ? super java.lang.String
  25.116 +Neg03.java:81:13: compiler.err.not.within.bounds: ? super java.lang.String
  25.117  Neg03.java:81:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
  25.118  90 errors
    26.1 --- a/test/tools/javac/generics/diamond/neg/Neg04.out	Fri Feb 12 13:25:27 2010 -0800
    26.2 +++ b/test/tools/javac/generics/diamond/neg/Neg04.out	Sun Feb 14 23:39:40 2010 -0800
    26.3 @@ -1,31 +1,31 @@
    26.4  Neg04.java:18:13: compiler.err.not.within.bounds: java.lang.String
    26.5  Neg04.java:18:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
    26.6 -Neg04.java:19:23: compiler.err.not.within.bounds: ? extends java.lang.String
    26.7 +Neg04.java:19:13: compiler.err.not.within.bounds: ? extends java.lang.String
    26.8  Neg04.java:19:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
    26.9  Neg04.java:20:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number>
   26.10 -Neg04.java:21:21: compiler.err.not.within.bounds: ? super java.lang.String
   26.11 +Neg04.java:21:13: compiler.err.not.within.bounds: ? super java.lang.String
   26.12  Neg04.java:21:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
   26.13  Neg04.java:23:13: compiler.err.not.within.bounds: java.lang.String
   26.14  Neg04.java:23:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
   26.15 -Neg04.java:24:23: compiler.err.not.within.bounds: ? extends java.lang.String
   26.16 +Neg04.java:24:13: compiler.err.not.within.bounds: ? extends java.lang.String
   26.17  Neg04.java:24:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   26.18  Neg04.java:25:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number>
   26.19  Neg04.java:25:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number>
   26.20 -Neg04.java:26:21: compiler.err.not.within.bounds: ? super java.lang.String
   26.21 +Neg04.java:26:13: compiler.err.not.within.bounds: ? super java.lang.String
   26.22  Neg04.java:26:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
   26.23  Neg04.java:28:13: compiler.err.not.within.bounds: java.lang.String
   26.24  Neg04.java:28:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
   26.25 -Neg04.java:29:23: compiler.err.not.within.bounds: ? extends java.lang.String
   26.26 +Neg04.java:29:13: compiler.err.not.within.bounds: ? extends java.lang.String
   26.27  Neg04.java:29:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   26.28  Neg04.java:30:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number>
   26.29 -Neg04.java:31:21: compiler.err.not.within.bounds: ? super java.lang.String
   26.30 +Neg04.java:31:13: compiler.err.not.within.bounds: ? super java.lang.String
   26.31  Neg04.java:31:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
   26.32  Neg04.java:33:13: compiler.err.not.within.bounds: java.lang.String
   26.33  Neg04.java:33:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
   26.34 -Neg04.java:34:23: compiler.err.not.within.bounds: ? extends java.lang.String
   26.35 +Neg04.java:34:13: compiler.err.not.within.bounds: ? extends java.lang.String
   26.36  Neg04.java:34:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
   26.37  Neg04.java:35:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number>
   26.38  Neg04.java:35:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number>
   26.39 -Neg04.java:36:21: compiler.err.not.within.bounds: ? super java.lang.String
   26.40 +Neg04.java:36:13: compiler.err.not.within.bounds: ? super java.lang.String
   26.41  Neg04.java:36:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
   26.42  30 errors
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/tools/javac/processing/6499119/ClassProcessor.java	Sun Feb 14 23:39:40 2010 -0800
    27.3 @@ -0,0 +1,132 @@
    27.4 +/*
    27.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.7 + *
    27.8 + * This code is free software; you can redistribute it and/or modify it
    27.9 + * under the terms of the GNU General Public License version 2 only, as
   27.10 + * published by the Free Software Foundation.
   27.11 + *
   27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   27.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   27.15 + * version 2 for more details (a copy is included in the LICENSE file that
   27.16 + * accompanied this code).
   27.17 + *
   27.18 + * You should have received a copy of the GNU General Public License version
   27.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   27.21 + *
   27.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   27.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   27.24 + * have any questions.
   27.25 + */
   27.26 +
   27.27 +import java.io.*;
   27.28 +import java.util.*;
   27.29 +import javax.annotation.processing.*;
   27.30 +import javax.lang.model.element.*;
   27.31 +import javax.lang.model.SourceVersion;
   27.32 +import javax.tools.Diagnostic.Kind;
   27.33 +
   27.34 +/*
   27.35 + * @test
   27.36 + * @bug 6499119
   27.37 + * @summary Created package-info class file modeled improperly
   27.38 + * @compile ClassProcessor.java package-info.java
   27.39 + * @compile/process -cp . -processor ClassProcessor -Akind=java  java.lang.Object
   27.40 + * @compile/process -cp . -processor ClassProcessor -Akind=class java.lang.Object
   27.41 + */
   27.42 +
   27.43 +@SupportedOptions({ "gen", "expect" })
   27.44 +@SupportedAnnotationTypes({"*"})
   27.45 +public class ClassProcessor extends AbstractProcessor {
   27.46 +    int round = 1;
   27.47 +
   27.48 +    public SourceVersion getSupportedSourceVersion() {
   27.49 +        return SourceVersion.latest();
   27.50 +    }
   27.51 +
   27.52 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   27.53 +        if (round == 1) {
   27.54 +            System.out.println("-- Round 1 --");
   27.55 +            createPackageFile();
   27.56 +        } else if (round == 2) {
   27.57 +            boolean found_foo_A = false;
   27.58 +            System.out.println("-- Round 2 --");
   27.59 +            for(Element e: roundEnv.getRootElements()) {
   27.60 +                System.out.println("ElementKind: " + e.getKind());
   27.61 +                System.out.println("Modifiers:   " + e.getModifiers());
   27.62 +                System.out.println("Annotations: " + e.getAnnotationMirrors());
   27.63 +                if (e.getAnnotationMirrors().toString().equals("@foo.A")) {
   27.64 +                    found_foo_A = true;
   27.65 +                    checkEqual("ElementKind", e.getKind().toString(), "PACKAGE");
   27.66 +                    checkEqual("Modifiers",   e.getModifiers().toString(), "[]");
   27.67 +                }
   27.68 +            }
   27.69 +            if (!found_foo_A)
   27.70 +                error("did not find @foo.A");
   27.71 +        }
   27.72 +        round++;
   27.73 +        return true;
   27.74 +    }
   27.75 +
   27.76 +    private void createPackageFile() {
   27.77 +        Filer filer = processingEnv.getFiler();
   27.78 +
   27.79 +        String kind = processingEnv.getOptions().get("kind");
   27.80 +
   27.81 +        File pkgInfo;
   27.82 +        if (kind.equals("java"))
   27.83 +            pkgInfo = new File(System.getProperty("test.src"),     "package-info.java");
   27.84 +        else
   27.85 +            pkgInfo = new File(System.getProperty("test.classes"), "foo/package-info.class");
   27.86 +
   27.87 +        byte[] bytes = new byte[(int) pkgInfo.length()];
   27.88 +        DataInputStream in = null;
   27.89 +        try {
   27.90 +            in = new DataInputStream(new FileInputStream(pkgInfo));
   27.91 +            in.readFully(bytes);
   27.92 +        } catch (IOException ioe) {
   27.93 +            error("Couldn't read package info file: " + ioe);
   27.94 +        } finally {
   27.95 +            if(in != null) {
   27.96 +                try {
   27.97 +                    in.close();
   27.98 +                } catch (IOException e) {
   27.99 +                    error("InputStream closing failed: " + e);
  27.100 +                }
  27.101 +            }
  27.102 +        }
  27.103 +
  27.104 +        OutputStream out = null;
  27.105 +        try {
  27.106 +            if (kind.equals("java"))
  27.107 +                out = filer.createSourceFile("foo.package-info").openOutputStream();
  27.108 +            else
  27.109 +                out = filer.createClassFile("foo.package-info").openOutputStream();
  27.110 +            out.write(bytes, 0, bytes.length);
  27.111 +        } catch (IOException ioe) {
  27.112 +            error("Couldn't create package info file: " + ioe);
  27.113 +        } finally {
  27.114 +            if(out != null) {
  27.115 +                try {
  27.116 +                    out.close();
  27.117 +                } catch (IOException e) {
  27.118 +                    error("OutputStream closing failed: " + e);
  27.119 +                }
  27.120 +            }
  27.121 +        }
  27.122 +    }
  27.123 +
  27.124 +    private void checkEqual(String label, String actual, String expect) {
  27.125 +        if (!actual.equals(expect)) {
  27.126 +            error("Unexpected value for " + label + "; actual=" + actual + ", expected=" + expect);
  27.127 +        }
  27.128 +    }
  27.129 +
  27.130 +    private void error(String msg) {
  27.131 +        Messager messager = processingEnv.getMessager();
  27.132 +        messager.printMessage(Kind.ERROR, msg);
  27.133 +    }
  27.134 +}
  27.135 +
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/tools/javac/processing/6499119/package-info.java	Sun Feb 14 23:39:40 2010 -0800
    28.3 @@ -0,0 +1,27 @@
    28.4 +/*
    28.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 + *
    28.8 + * This code is free software; you can redistribute it and/or modify it
    28.9 + * under the terms of the GNU General Public License version 2 only, as
   28.10 + * published by the Free Software Foundation.
   28.11 + *
   28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.15 + * version 2 for more details (a copy is included in the LICENSE file that
   28.16 + * accompanied this code).
   28.17 + *
   28.18 + * You should have received a copy of the GNU General Public License version
   28.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.21 + *
   28.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   28.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   28.24 + * have any questions.
   28.25 + */
   28.26 +
   28.27 +@A package foo;
   28.28 +
   28.29 +@interface A {}
   28.30 +
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/tools/javac/processing/T6920317.java	Sun Feb 14 23:39:40 2010 -0800
    29.3 @@ -0,0 +1,462 @@
    29.4 +/*
    29.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    29.7 + *
    29.8 + * This code is free software; you can redistribute it and/or modify it
    29.9 + * under the terms of the GNU General Public License version 2 only, as
   29.10 + * published by the Free Software Foundation.
   29.11 + *
   29.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   29.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   29.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   29.15 + * version 2 for more details (a copy is included in the LICENSE file that
   29.16 + * accompanied this code).
   29.17 + *
   29.18 + * You should have received a copy of the GNU General Public License version
   29.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   29.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   29.21 + *
   29.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   29.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   29.24 + * have any questions.
   29.25 + */
   29.26 +
   29.27 +/*
   29.28 + * @test
   29.29 + * @bug 6920317
   29.30 + * @summary package-info.java file has to be specified on the javac cmdline, else it will not be avail
   29.31 + */
   29.32 +
   29.33 +import java.io.*;
   29.34 +import java.util.*;
   29.35 +import javax.annotation.processing.*;
   29.36 +import javax.lang.model.*;
   29.37 +import javax.lang.model.element.*;
   29.38 +import javax.lang.model.util.*;
   29.39 +import javax.tools.*;
   29.40 +
   29.41 +/**
   29.42 + * The test exercises different ways of providing annotations for a package.
   29.43 + * Each way provides an annotation with a unique argument. For each test
   29.44 + * case, the test verifies that the annotation with the correct argument is
   29.45 + * found by the compiler.
   29.46 + */
   29.47 +public class T6920317 {
   29.48 +    public static void main(String... args) throws Exception {
   29.49 +        new T6920317().run(args);
   29.50 +    }
   29.51 +
   29.52 +    // Used to describe properties of files to be put on command line, source path, class path
   29.53 +    enum Kind {
   29.54 +        /** File is not used. */
   29.55 +        NONE,
   29.56 +        /** File is used. */
   29.57 +        OLD,
   29.58 +        /** Only applies to files on classpath/sourcepath, when there is another file on the
   29.59 +         *  other path of type OLD, in which case, this file must be newer than the other one. */
   29.60 +        NEW,
   29.61 +        /** Only applies to files on classpath/sourcepath, when there is no file in any other
   29.62 +         *  location, in which case, this file will be generated by the annotation processor. */
   29.63 +        GEN
   29.64 +    }
   29.65 +
   29.66 +    void run(String... args) throws Exception {
   29.67 +        // if no args given, all test cases are run
   29.68 +        // if args given, they indicate the test cases to be run
   29.69 +        for (int i = 0; i < args.length; i++) {
   29.70 +            tests.add(Integer.valueOf(args[i]));
   29.71 +        }
   29.72 +
   29.73 +        setup();
   29.74 +
   29.75 +        // Run tests for all combinations of files on command line, source path and class path.
   29.76 +        // Invalid combinations are skipped in the test method
   29.77 +        for (Kind cmdLine: EnumSet.of(Kind.NONE, Kind.OLD)) {
   29.78 +            for (Kind srcPath: Kind.values()) {
   29.79 +                for (Kind clsPath: Kind.values()) {
   29.80 +                    try {
   29.81 +                        test(cmdLine, srcPath, clsPath);
   29.82 +                    } catch (Exception e) {
   29.83 +                        e.printStackTrace();
   29.84 +                        error("Exception " + e);
   29.85 +                        // uncomment to stop on first failed test case
   29.86 +                        // throw e;
   29.87 +                    }
   29.88 +                }
   29.89 +            }
   29.90 +        }
   29.91 +
   29.92 +        if (errors > 0)
   29.93 +            throw new Exception(errors + " errors occurred");
   29.94 +    }
   29.95 +
   29.96 +    /** One time setup for files and directories to be used in the various test cases. */
   29.97 +    void setup() throws Exception {
   29.98 +        // Annotation used in test cases to annotate package. This file is
   29.99 +        // given on the command line in test cases.
  29.100 +        test_java = writeFile("Test.java", "package p; @interface Test { String value(); }");
  29.101 +        // Compile the annotation for use later in setup
  29.102 +        File tmpClasses = new File("tmp.classes");
  29.103 +        compile(tmpClasses, new String[] { }, test_java);
  29.104 +
  29.105 +        // package-info file to use on the command line when requied
  29.106 +        cl_pkgInfo_java = writeFile("cl/p/package-info.java", "@Test(\"CL\") package p;");
  29.107 +
  29.108 +        // source path containing package-info
  29.109 +        sp_old = new File("src.old");
  29.110 +        writeFile("src.old/p/package-info.java", "@Test(\"SP_OLD\") package p;");
  29.111 +
  29.112 +        // class path containing package-info
  29.113 +        cp_old = new File("classes.old");
  29.114 +        compile(cp_old, new String[] { "-classpath", tmpClasses.getPath() },
  29.115 +                writeFile("tmp.old/p/package-info.java", "@Test(\"CP_OLD\") package p;"));
  29.116 +
  29.117 +        // source path containing package-info which is newer than the one in cp-old
  29.118 +        sp_new = new File("src.new");
  29.119 +        File old_class = new File(cp_old, "p/package-info.class");
  29.120 +        writeFile("src.new/p/package-info.java", "@Test(\"SP_NEW\") package p;", old_class);
  29.121 +
  29.122 +        // class path containing package-info which is newer than the one in sp-old
  29.123 +        cp_new = new File("classes.new");
  29.124 +        File old_java = new File(sp_old, "p/package-info.java");
  29.125 +        compile(cp_new, new String[] { "-classpath", tmpClasses.getPath() },
  29.126 +                writeFile("tmp.new/p/package-info.java", "@Test(\"CP_NEW\") package p;", old_java));
  29.127 +
  29.128 +        // directory containing package-info.java to be "generated" later by annotation processor
  29.129 +        sp_gen = new File("src.gen");
  29.130 +        writeFile("src.gen/p/package-info.java", "@Test(\"SP_GEN\") package p;");
  29.131 +
  29.132 +        // directory containing package-info.class to be "generated" later by annotation processor
  29.133 +        cp_gen = new File("classes.gen");
  29.134 +        compile(cp_gen, new String[] { "-classpath", tmpClasses.getPath() },
  29.135 +                writeFile("tmp.gen/p/package-info.java", "@Test(\"CP_GEN\") package p;"));
  29.136 +    }
  29.137 +
  29.138 +    void test(Kind cl, Kind sp, Kind cp) throws Exception {
  29.139 +        if (skip(cl, sp, cp))
  29.140 +            return;
  29.141 +
  29.142 +        ++count;
  29.143 +        // if test cases specified, skip this test case if not selected
  29.144 +        if (tests.size() > 0 && !tests.contains(count))
  29.145 +            return;
  29.146 +
  29.147 +        System.err.println("Test " + count + " cl:" + cl + " sp:" + sp + " cp:" + cp);
  29.148 +
  29.149 +        // test specific tmp directory
  29.150 +        File test_tmp = new File("tmp.test" + count);
  29.151 +        test_tmp.mkdirs();
  29.152 +
  29.153 +        // build up list of options and files to be compiled
  29.154 +        List<String> opts = new ArrayList<String>();
  29.155 +        List<File> files = new ArrayList<File>();
  29.156 +
  29.157 +        // expected value for annotation
  29.158 +        String expect = null;
  29.159 +
  29.160 +        opts.add("-processorpath");
  29.161 +        opts.add(System.getProperty("test.classes"));
  29.162 +        opts.add("-processor");
  29.163 +        opts.add(Processor.class.getName());
  29.164 +        opts.add("-proc:only");
  29.165 +        opts.add("-d");
  29.166 +        opts.add(test_tmp.getPath());
  29.167 +        //opts.add("-verbose");
  29.168 +        files.add(test_java);
  29.169 +
  29.170 +        /*
  29.171 +         * Analyze each of cl, cp, sp, building up the options and files to
  29.172 +         * be compiled, and determining the expected outcome fo the test case.
  29.173 +         */
  29.174 +
  29.175 +        // command line file: either omitted or given
  29.176 +        if (cl == Kind.OLD) {
  29.177 +            files.add(cl_pkgInfo_java);
  29.178 +            // command line files always supercede files on paths
  29.179 +            expect = "CL";
  29.180 +        }
  29.181 +
  29.182 +        // source path:
  29.183 +        switch (sp) {
  29.184 +        case NONE:
  29.185 +            break;
  29.186 +
  29.187 +        case OLD:
  29.188 +            opts.add("-sourcepath");
  29.189 +            opts.add(sp_old.getPath());
  29.190 +            if (expect == null && cp == Kind.NONE) {
  29.191 +                assert cl == Kind.NONE && cp == Kind.NONE;
  29.192 +                expect = "SP_OLD";
  29.193 +            }
  29.194 +            break;
  29.195 +
  29.196 +        case NEW:
  29.197 +            opts.add("-sourcepath");
  29.198 +            opts.add(sp_new.getPath());
  29.199 +            if (expect == null) {
  29.200 +                assert cl == Kind.NONE && cp == Kind.OLD;
  29.201 +                expect = "SP_NEW";
  29.202 +            }
  29.203 +            break;
  29.204 +
  29.205 +        case GEN:
  29.206 +            opts.add("-Agen=" + new File(sp_gen, "p/package-info.java"));
  29.207 +            assert cl == Kind.NONE && cp == Kind.NONE;
  29.208 +            expect = "SP_GEN";
  29.209 +            break;
  29.210 +        }
  29.211 +
  29.212 +        // class path:
  29.213 +        switch (cp) {
  29.214 +        case NONE:
  29.215 +            break;
  29.216 +
  29.217 +        case OLD:
  29.218 +            opts.add("-classpath");
  29.219 +            opts.add(cp_old.getPath());
  29.220 +            if (expect == null && sp == Kind.NONE) {
  29.221 +                assert cl == Kind.NONE && sp == Kind.NONE;
  29.222 +                expect = "CP_OLD";
  29.223 +            }
  29.224 +            break;
  29.225 +
  29.226 +        case NEW:
  29.227 +            opts.add("-classpath");
  29.228 +            opts.add(cp_new.getPath());
  29.229 +            if (expect == null) {
  29.230 +                assert cl == Kind.NONE && sp == Kind.OLD;
  29.231 +                expect = "CP_NEW";
  29.232 +            }
  29.233 +            break;
  29.234 +
  29.235 +        case GEN:
  29.236 +            opts.add("-Agen=" + new File(cp_gen, "p/package-info.class"));
  29.237 +            assert cl == Kind.NONE && sp == Kind.NONE;
  29.238 +            expect = "CP_GEN";
  29.239 +            break;
  29.240 +        }
  29.241 +
  29.242 +        // pass expected value to annotation processor
  29.243 +        assert expect != null;
  29.244 +        opts.add("-Aexpect=" + expect);
  29.245 +
  29.246 +        // compile the files with the options that have been built up
  29.247 +        compile(opts, files);
  29.248 +    }
  29.249 +
  29.250 +    /**
  29.251 +     * Return true if this combination of parameters does not identify a useful test case.
  29.252 +     */
  29.253 +    boolean skip(Kind cl, Kind sp, Kind cp) {
  29.254 +        // skip if no package files required
  29.255 +        if (cl == Kind.NONE && sp == Kind.NONE && cp == Kind.NONE)
  29.256 +            return true;
  29.257 +
  29.258 +        // skip if both sp and sp are OLD, since results may be indeterminate
  29.259 +        if (sp == Kind.OLD && cp == Kind.OLD)
  29.260 +            return true;
  29.261 +
  29.262 +        // skip if sp or cp is NEW but the other is not OLD
  29.263 +        if ((sp == Kind.NEW && cp != Kind.OLD) || (cp == Kind.NEW && sp != Kind.OLD))
  29.264 +            return true;
  29.265 +
  29.266 +        // only use GEN if no other package-info files present
  29.267 +        if (sp == Kind.GEN && !(cl == Kind.NONE && cp == Kind.NONE) ||
  29.268 +            cp == Kind.GEN && !(cl == Kind.NONE && sp == Kind.NONE)) {
  29.269 +            return true;
  29.270 +        }
  29.271 +
  29.272 +        // remaining combinations are valid
  29.273 +        return false;
  29.274 +    }
  29.275 +
  29.276 +    /** Write a file with a given body. */
  29.277 +    File writeFile(String path, String body) throws Exception {
  29.278 +        File f = new File(path);
  29.279 +        if (f.getParentFile() != null)
  29.280 +            f.getParentFile().mkdirs();
  29.281 +        Writer out = new FileWriter(path);
  29.282 +        try {
  29.283 +            out.write(body);
  29.284 +        } finally {
  29.285 +            out.close();
  29.286 +        }
  29.287 +        return f;
  29.288 +    }
  29.289 +
  29.290 +    /** Write a file with a given body, ensuring that the file is newer than a reference file. */
  29.291 +    File writeFile(String path, String body, File ref) throws Exception {
  29.292 +        for (int i = 0; i < 5; i++) {
  29.293 +            File f = writeFile(path, body);
  29.294 +            if (f.lastModified() > ref.lastModified())
  29.295 +                return f;
  29.296 +            Thread.sleep(2000);
  29.297 +        }
  29.298 +        throw new Exception("cannot create file " + path + " newer than " + ref);
  29.299 +    }
  29.300 +
  29.301 +    /** Compile a file to a given directory, with options provided. */
  29.302 +    void compile(File dir, String[] opts, File src) throws Exception {
  29.303 +        dir.mkdirs();
  29.304 +        List<String> opts2 = new ArrayList<String>();
  29.305 +        opts2.addAll(Arrays.asList("-d", dir.getPath()));
  29.306 +        opts2.addAll(Arrays.asList(opts));
  29.307 +        compile(opts2, Collections.singletonList(src));
  29.308 +    }
  29.309 +
  29.310 +    /** Compile files with options provided. */
  29.311 +    void compile(List<String> opts, List<File> files) throws Exception {
  29.312 +        System.err.println("javac: " + opts + " " + files);
  29.313 +        List<String> args = new ArrayList<String>();
  29.314 +        args.addAll(opts);
  29.315 +        for (File f: files)
  29.316 +            args.add(f.getPath());
  29.317 +        StringWriter sw = new StringWriter();
  29.318 +        PrintWriter pw = new PrintWriter(sw);
  29.319 +        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
  29.320 +        pw.flush();
  29.321 +        if (sw.getBuffer().length() > 0)
  29.322 +            System.err.println(sw.toString());
  29.323 +        if (rc != 0)
  29.324 +            throw new Exception("compilation failed: rc=" + rc);
  29.325 +    }
  29.326 +
  29.327 +    /** Report an error. */
  29.328 +    void error(String msg) {
  29.329 +        System.err.println("Error: " + msg);
  29.330 +        errors++;
  29.331 +    }
  29.332 +
  29.333 +    /** Test case counter. */
  29.334 +    int count;
  29.335 +
  29.336 +    /** Number of errors found. */
  29.337 +    int errors;
  29.338 +
  29.339 +    /** Optional set of test cases to be run; empty implies all test cases. */
  29.340 +    Set<Integer> tests = new HashSet<Integer>();
  29.341 +
  29.342 +    /*  Files created by setup. */
  29.343 +    File test_java;
  29.344 +    File sp_old;
  29.345 +    File sp_new;
  29.346 +    File sp_gen;
  29.347 +    File cp_old;
  29.348 +    File cp_new;
  29.349 +    File cp_gen;
  29.350 +    File cl_pkgInfo_java;
  29.351 +
  29.352 +    /** Annotation processor used to verify the expected value for the
  29.353 +        package annotations found by javac. */
  29.354 +    @SupportedOptions({ "gen", "expect" })
  29.355 +    @SupportedAnnotationTypes({"*"})
  29.356 +    public static class Processor extends AbstractProcessor {
  29.357 +        public SourceVersion getSupportedSourceVersion() {
  29.358 +            return SourceVersion.latest();
  29.359 +        }
  29.360 +
  29.361 +        public boolean process(Set<? extends TypeElement> annots, RoundEnvironment renv) {
  29.362 +            round++;
  29.363 +            System.err.println("Round " + round + " annots:" + annots + " rootElems:" + renv.getRootElements());
  29.364 +
  29.365 +            // if this is the first round and the gen option is given, use the filer to create
  29.366 +            // a copy of the file specified by the gen option.
  29.367 +            String gen = getOption("gen");
  29.368 +            if (round == 1 && gen != null) {
  29.369 +                try {
  29.370 +                    Filer filer = processingEnv.getFiler();
  29.371 +                    JavaFileObject f;
  29.372 +                    if (gen.endsWith(".java"))
  29.373 +                        f = filer.createSourceFile("p.package-info");
  29.374 +                    else
  29.375 +                        f = filer.createClassFile("p.package-info");
  29.376 +                    System.err.println("copy " + gen + " to " + f.getName());
  29.377 +                    write(f, read(new File(gen)));
  29.378 +                } catch (IOException e) {
  29.379 +                    error("Cannot create package-info file: " + e);
  29.380 +                }
  29.381 +            }
  29.382 +
  29.383 +            // if annotation processing is complete, verify the package annotation
  29.384 +            // found by the compiler.
  29.385 +            if (renv.processingOver()) {
  29.386 +                System.err.println("final round");
  29.387 +                Elements eu = processingEnv.getElementUtils();
  29.388 +                TypeElement te = eu.getTypeElement("p.Test");
  29.389 +                PackageElement pe = eu.getPackageOf(te);
  29.390 +                System.err.println("final: te:" + te + " pe:" + pe);
  29.391 +                List<? extends AnnotationMirror> annos = pe.getAnnotationMirrors();
  29.392 +                System.err.println("final: annos:" + annos);
  29.393 +                if (annos.size() == 1) {
  29.394 +                    String expect = "@" + te + "(\"" + getOption("expect") + "\")";
  29.395 +                    String actual = annos.get(0).toString();
  29.396 +                    checkEqual("package annotations", actual, expect);
  29.397 +                } else {
  29.398 +                    error("Wrong number of annotations found: (" + annos.size() + ") " + annos);
  29.399 +                }
  29.400 +            }
  29.401 +
  29.402 +            return true;
  29.403 +        }
  29.404 +
  29.405 +        /** Get an option given to the annotation processor. */
  29.406 +        String getOption(String name) {
  29.407 +            return processingEnv.getOptions().get(name);
  29.408 +        }
  29.409 +
  29.410 +        /** Read a file. */
  29.411 +        byte[] read(File file) {
  29.412 +            byte[] bytes = new byte[(int) file.length()];
  29.413 +            DataInputStream in = null;
  29.414 +            try {
  29.415 +                in = new DataInputStream(new FileInputStream(file));
  29.416 +                in.readFully(bytes);
  29.417 +            } catch (IOException e) {
  29.418 +                error("Error reading file: " + e);
  29.419 +            } finally {
  29.420 +                if (in != null) {
  29.421 +                    try {
  29.422 +                        in.close();
  29.423 +                    } catch (IOException e) {
  29.424 +                        error("Error closing file: " + e);
  29.425 +                    }
  29.426 +                }
  29.427 +            }
  29.428 +            return  bytes;
  29.429 +        }
  29.430 +
  29.431 +        /** Write a file. */
  29.432 +        void write(JavaFileObject file, byte[] bytes) {
  29.433 +            OutputStream out = null;
  29.434 +            try {
  29.435 +                out = file.openOutputStream();
  29.436 +                out.write(bytes, 0, bytes.length);
  29.437 +            } catch (IOException e) {
  29.438 +                error("Error writing file: " + e);
  29.439 +            } finally {
  29.440 +                if (out != null) {
  29.441 +                    try {
  29.442 +                        out.close();
  29.443 +                    } catch (IOException e) {
  29.444 +                        error("Error closing file: " + e);
  29.445 +                    }
  29.446 +                }
  29.447 +            }
  29.448 +        }
  29.449 +
  29.450 +        /** Check two strings are equal, and report an error if they are not. */
  29.451 +        private void checkEqual(String label, String actual, String expect) {
  29.452 +            if (!actual.equals(expect)) {
  29.453 +                error("Unexpected value for " + label + "; actual=" + actual + ", expected=" + expect);
  29.454 +            }
  29.455 +        }
  29.456 +
  29.457 +        /** Report an error to the annotation processing system. */
  29.458 +        void error(String msg) {
  29.459 +            Messager messager = processingEnv.getMessager();
  29.460 +            messager.printMessage(Diagnostic.Kind.ERROR, msg);
  29.461 +        }
  29.462 +
  29.463 +        int round;
  29.464 +    }
  29.465 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/tools/javac/tree/T6923080.java	Sun Feb 14 23:39:40 2010 -0800
    30.3 @@ -0,0 +1,40 @@
    30.4 +/*
    30.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.7 + *
    30.8 + * This code is free software; you can redistribute it and/or modify it
    30.9 + * under the terms of the GNU General Public License version 2 only, as
   30.10 + * published by the Free Software Foundation.
   30.11 + *
   30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   30.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   30.15 + * version 2 for more details (a copy is included in the LICENSE file that
   30.16 + * accompanied this code).
   30.17 + *
   30.18 + * You should have received a copy of the GNU General Public License version
   30.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   30.21 + *
   30.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   30.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   30.24 + * have any questions.
   30.25 + */
   30.26 +
   30.27 +/*
   30.28 + * This file is not a regular test, but is processed by ./TreeScannerTest.java,
   30.29 + * which verifies the operation of the javac TreeScanner.
   30.30 + * @bug 6923080
   30.31 + * @summary TreeScanner.visitNewClass should scan tree.typeargs
   30.32 + */
   30.33 +class T6923080 {
   30.34 +    void test() {
   30.35 +        C c = new <Integer>C();  // exercises TreeScanner.visitNewClass
   30.36 +        Object o = c.<Float>m(); // exercises TreeScanner.visitApply
   30.37 +    }
   30.38 +
   30.39 +    static class C {
   30.40 +        <T> C()   { }
   30.41 +        <T> T m() { return null; }
   30.42 +    }
   30.43 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/tools/javac/tree/TreeScannerTest.java	Sun Feb 14 23:39:40 2010 -0800
    31.3 @@ -0,0 +1,387 @@
    31.4 +/*
    31.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    31.7 + *
    31.8 + * This code is free software; you can redistribute it and/or modify it
    31.9 + * under the terms of the GNU General Public License version 2 only, as
   31.10 + * published by the Free Software Foundation.
   31.11 + *
   31.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   31.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   31.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   31.15 + * version 2 for more details (a copy is included in the LICENSE file that
   31.16 + * accompanied this code).
   31.17 + *
   31.18 + * You should have received a copy of the GNU General Public License version
   31.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   31.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   31.21 + *
   31.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   31.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   31.24 + * have any questions.
   31.25 + */
   31.26 +
   31.27 +
   31.28 +/**
   31.29 + * Utility and test program to check javac's internal TreeScanner class.
   31.30 + * The program can be run standalone, or as a jtreg test.  For info on
   31.31 + * command line args, run program with no args.
   31.32 + *
   31.33 + * <p>
   31.34 + * jtreg: Note that by using the -r switch in the test description below, this test
   31.35 + * will process all java files in the langtools/test directory, thus implicitly
   31.36 + * covering any new language features that may be tested in this test suite.
   31.37 + */
   31.38 +
   31.39 +/*
   31.40 + * @test
   31.41 + * @bug 6923080
   31.42 + * @summary TreeScanner.visitNewClass should scan tree.typeargs
   31.43 + * @run main TreeScannerTest -q -r .
   31.44 + */
   31.45 +
   31.46 +import java.io.*;
   31.47 +import java.lang.reflect.*;
   31.48 +import java.util.*;
   31.49 +import javax.tools.*;
   31.50 +
   31.51 +import com.sun.source.tree.CompilationUnitTree;
   31.52 +import com.sun.source.util.JavacTask;
   31.53 +import com.sun.tools.javac.api.JavacTool;
   31.54 +import com.sun.tools.javac.tree.*;
   31.55 +import com.sun.tools.javac.tree.JCTree.*;
   31.56 +import com.sun.tools.javac.util.List;
   31.57 +
   31.58 +public class TreeScannerTest {
   31.59 +    /**
   31.60 +     * Main entry point.
   31.61 +     * If test.src is set, program runs in jtreg mode, and will throw an Error
   31.62 +     * if any errors arise, otherwise System.exit will be used. In jtreg mode,
   31.63 +     * the default base directory for file args is the value of ${test.src}.
   31.64 +     * In jtreg mode, the -r option can be given to change the default base
   31.65 +     * directory to the root test directory.
   31.66 +     */
   31.67 +    public static void main(String... args) {
   31.68 +        String testSrc = System.getProperty("test.src");
   31.69 +        File baseDir = (testSrc == null) ? null : new File(testSrc);
   31.70 +        boolean ok = new TreeScannerTest().run(baseDir, args);
   31.71 +        if (!ok) {
   31.72 +            if (testSrc != null)  // jtreg mode
   31.73 +                throw new Error("failed");
   31.74 +            else
   31.75 +                System.exit(1);
   31.76 +        }
   31.77 +    }
   31.78 +
   31.79 +    /**
   31.80 +     * Run the program. A base directory can be provided for file arguments.
   31.81 +     * In jtreg mode, the -r option can be given to change the default base
   31.82 +     * directory to the test root directory. For other options, see usage().
   31.83 +     * @param baseDir base directory for any file arguments.
   31.84 +     * @param args command line args
   31.85 +     * @return true if successful or in gui mode
   31.86 +     */
   31.87 +    boolean run(File baseDir, String... args) {
   31.88 +        if (args.length == 0) {
   31.89 +            usage(System.out);
   31.90 +            return true;
   31.91 +        }
   31.92 +
   31.93 +        ArrayList<File> files = new ArrayList<File>();
   31.94 +        for (int i = 0; i < args.length; i++) {
   31.95 +            String arg = args[i];
   31.96 +            if (arg.equals("-q"))
   31.97 +                quiet = true;
   31.98 +            else if (arg.equals("-v"))
   31.99 +                verbose = true;
  31.100 +            else if (arg.equals("-r")) {
  31.101 +                File d = baseDir;
  31.102 +                while (!new File(d, "TEST.ROOT").exists()) {
  31.103 +                    d = d.getParentFile();
  31.104 +                    if (d == null)
  31.105 +                        throw new Error("cannot find TEST.ROOT");
  31.106 +                }
  31.107 +                baseDir = d;
  31.108 +            }
  31.109 +            else if (arg.startsWith("-"))
  31.110 +                throw new Error("unknown option: " + arg);
  31.111 +            else {
  31.112 +                while (i < args.length)
  31.113 +                    files.add(new File(baseDir, args[i++]));
  31.114 +            }
  31.115 +        }
  31.116 +
  31.117 +        for (File file: files) {
  31.118 +            if (file.exists())
  31.119 +                test(file);
  31.120 +            else
  31.121 +                error("File not found: " + file);
  31.122 +        }
  31.123 +
  31.124 +        if (fileCount != 1)
  31.125 +            System.err.println(fileCount + " files read");
  31.126 +        if (errors > 0)
  31.127 +            System.err.println(errors + " errors");
  31.128 +
  31.129 +        return (errors == 0);
  31.130 +    }
  31.131 +
  31.132 +    /**
  31.133 +     * Print command line help.
  31.134 +     * @param out output stream
  31.135 +     */
  31.136 +    void usage(PrintStream out) {
  31.137 +        out.println("Usage:");
  31.138 +        out.println("  java TreeScannerTest options... files...");
  31.139 +        out.println("");
  31.140 +        out.println("where options include:");
  31.141 +        out.println("-q        Quiet: don't report on inapplicable files");
  31.142 +        out.println("-v        Verbose: report on files as they are being read");
  31.143 +        out.println("");
  31.144 +        out.println("files may be directories or files");
  31.145 +        out.println("directories will be scanned recursively");
  31.146 +        out.println("non java files, or java files which cannot be parsed, will be ignored");
  31.147 +        out.println("");
  31.148 +    }
  31.149 +
  31.150 +    /**
  31.151 +     * Test a file. If the file is a directory, it will be recursively scanned
  31.152 +     * for java files.
  31.153 +     * @param file the file or directory to test
  31.154 +     */
  31.155 +    void test(File file) {
  31.156 +        if (file.isDirectory()) {
  31.157 +            for (File f: file.listFiles()) {
  31.158 +                test(f);
  31.159 +            }
  31.160 +            return;
  31.161 +        }
  31.162 +
  31.163 +        if (file.isFile() && file.getName().endsWith(".java")) {
  31.164 +            try {
  31.165 +                if (verbose)
  31.166 +                    System.err.println(file);
  31.167 +                fileCount++;
  31.168 +                ScanTester t = new ScanTester();
  31.169 +                t.test(read(file));
  31.170 +            } catch (ParseException e) {
  31.171 +                if (!quiet) {
  31.172 +                    error("Error parsing " + file + "\n" + e.getMessage());
  31.173 +                }
  31.174 +            } catch (IOException e) {
  31.175 +                error("Error reading " + file + ": " + e);
  31.176 +            }
  31.177 +            return;
  31.178 +        }
  31.179 +
  31.180 +        if (!quiet)
  31.181 +            error("File " + file + " ignored");
  31.182 +    }
  31.183 +
  31.184 +    /**
  31.185 +     * Read a file.
  31.186 +     * @param file the file to be read
  31.187 +     * @return the tree for the content of the file
  31.188 +     * @throws IOException if any IO errors occur
  31.189 +     * @throws TreePosTest.ParseException if any errors occur while parsing the file
  31.190 +     */
  31.191 +    JCCompilationUnit read(File file) throws IOException, ParseException {
  31.192 +        StringWriter sw = new StringWriter();
  31.193 +        PrintWriter pw = new PrintWriter(sw);
  31.194 +        Reporter r = new Reporter(pw);
  31.195 +        JavacTool tool = JavacTool.create();
  31.196 +        StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
  31.197 +        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
  31.198 +        JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
  31.199 +        Iterable<? extends CompilationUnitTree> trees = task.parse();
  31.200 +        pw.flush();
  31.201 +        if (r.errors > 0)
  31.202 +            throw new ParseException(sw.toString());
  31.203 +        Iterator<? extends CompilationUnitTree> iter = trees.iterator();
  31.204 +        if (!iter.hasNext())
  31.205 +            throw new Error("no trees found");
  31.206 +        JCCompilationUnit t = (JCCompilationUnit) iter.next();
  31.207 +        if (iter.hasNext())
  31.208 +            throw new Error("too many trees found");
  31.209 +        return t;
  31.210 +    }
  31.211 +
  31.212 +    /**
  31.213 +     * Report an error. When the program is complete, the program will either
  31.214 +     * exit or throw an Error if any errors have been reported.
  31.215 +     * @param msg the error message
  31.216 +     */
  31.217 +    void error(String msg) {
  31.218 +        System.err.println(msg);
  31.219 +        errors++;
  31.220 +    }
  31.221 +
  31.222 +    /**
  31.223 +     *  Report an error for a specific tree node.
  31.224 +     *  @param file the source file for the tree
  31.225 +     *  @param t    the tree node
  31.226 +     *  @param label an indication of the error
  31.227 +     */
  31.228 +    void error(JavaFileObject file, JCTree t, String msg) {
  31.229 +        error(file.getName() + ":" + getLine(file, t) + ": " + msg + " " + trim(t, 64));
  31.230 +    }
  31.231 +
  31.232 +    /**
  31.233 +     * Get a trimmed string for a tree node, with normalized white space and limited length.
  31.234 +     */
  31.235 +    String trim(JCTree t, int len) {
  31.236 +        String s = t.toString().replaceAll("[\r\n]+", " ").replaceAll(" +", " ");
  31.237 +        return (s.length() < len) ? s : s.substring(0, len);
  31.238 +    }
  31.239 +
  31.240 +    /** Number of files that have been analyzed. */
  31.241 +    int fileCount;
  31.242 +    /** Number of errors reported. */
  31.243 +    int errors;
  31.244 +    /** Flag: don't report irrelevant files. */
  31.245 +    boolean quiet;
  31.246 +    /** Flag: report files as they are processed. */
  31.247 +    boolean verbose;
  31.248 +
  31.249 +    /**
  31.250 +     * Main class for testing operation of tree scanner.
  31.251 +     * The set of nodes found by the scanner are compared
  31.252 +     * against the set of nodes found by reflection.
  31.253 +     */
  31.254 +    private class ScanTester extends TreeScanner {
  31.255 +        /** Main entry method for the class. */
  31.256 +        void test(JCCompilationUnit tree) {
  31.257 +            sourcefile = tree.sourcefile;
  31.258 +            found = new HashSet<JCTree>();
  31.259 +            scan(tree);
  31.260 +            expect = new HashSet<JCTree>();
  31.261 +            reflectiveScan(tree);
  31.262 +            if (found.equals(expect))
  31.263 +                return;
  31.264 +
  31.265 +            error("Differences found for " + tree.sourcefile.getName());
  31.266 +
  31.267 +            if (found.size() != expect.size())
  31.268 +                error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
  31.269 +
  31.270 +            Set<JCTree> missing = new HashSet<JCTree>();
  31.271 +            missing.addAll(expect);
  31.272 +            missing.removeAll(found);
  31.273 +            for (JCTree t: missing)
  31.274 +                error(tree.sourcefile, t, "missing");
  31.275 +
  31.276 +            Set<JCTree> excess = new HashSet<JCTree>();
  31.277 +            excess.addAll(found);
  31.278 +            excess.removeAll(expect);
  31.279 +            for (JCTree t: excess)
  31.280 +                error(tree.sourcefile, t, "unexpected");
  31.281 +        }
  31.282 +
  31.283 +        /** Record all tree nodes found by scanner. */
  31.284 +        @Override
  31.285 +        public void scan(JCTree tree) {
  31.286 +            if (tree == null)
  31.287 +                return;
  31.288 +            System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
  31.289 +            found.add(tree);
  31.290 +            super.scan(tree);
  31.291 +        }
  31.292 +
  31.293 +        /** record all tree nodes found by reflection. */
  31.294 +        public void reflectiveScan(Object o) {
  31.295 +            if (o == null)
  31.296 +                return;
  31.297 +            if (o instanceof JCTree) {
  31.298 +                JCTree tree = (JCTree) o;
  31.299 +                System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
  31.300 +                expect.add(tree);
  31.301 +                for (Field f: getFields(tree)) {
  31.302 +                    try {
  31.303 +                        //System.err.println("FIELD: " + f.getName());
  31.304 +                        reflectiveScan(f.get(tree));
  31.305 +                    } catch (IllegalAccessException e) {
  31.306 +                        error(e.toString());
  31.307 +                    }
  31.308 +                }
  31.309 +            } else if (o instanceof List) {
  31.310 +                List<?> list = (List<?>) o;
  31.311 +                for (Object item: list)
  31.312 +                    reflectiveScan(item);
  31.313 +            } else
  31.314 +                error("unexpected item: " + o);
  31.315 +        }
  31.316 +
  31.317 +        JavaFileObject sourcefile;
  31.318 +        Set<JCTree> found;
  31.319 +        Set<JCTree> expect;
  31.320 +    }
  31.321 +
  31.322 +    /**
  31.323 +     * Thrown when errors are found parsing a java file.
  31.324 +     */
  31.325 +    private static class ParseException extends Exception {
  31.326 +        ParseException(String msg) {
  31.327 +            super(msg);
  31.328 +        }
  31.329 +    }
  31.330 +
  31.331 +    /**
  31.332 +     * DiagnosticListener to report diagnostics and count any errors that occur.
  31.333 +     */
  31.334 +    private static class Reporter implements DiagnosticListener<JavaFileObject> {
  31.335 +        Reporter(PrintWriter out) {
  31.336 +            this.out = out;
  31.337 +        }
  31.338 +
  31.339 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  31.340 +            out.println(diagnostic);
  31.341 +            switch (diagnostic.getKind()) {
  31.342 +                case ERROR:
  31.343 +                    errors++;
  31.344 +            }
  31.345 +        }
  31.346 +        int errors;
  31.347 +        PrintWriter out;
  31.348 +    }
  31.349 +
  31.350 +    /**
  31.351 +     * Get the set of fields for a tree node that may contain child tree nodes.
  31.352 +     * These are the fields that are subtypes of JCTree or List.
  31.353 +     * The results are cached, based on the tree's tag.
  31.354 +     */
  31.355 +    Set<Field> getFields(JCTree tree) {
  31.356 +        Set<Field> fields = map.get(tree.getTag());
  31.357 +        if (fields == null) {
  31.358 +            fields = new HashSet<Field>();
  31.359 +            for (Field f: tree.getClass().getFields()) {
  31.360 +                Class<?> fc = f.getType();
  31.361 +                if (JCTree.class.isAssignableFrom(fc) || List.class.isAssignableFrom(fc))
  31.362 +                    fields.add(f);
  31.363 +            }
  31.364 +            map.put(tree.getTag(), fields);
  31.365 +        }
  31.366 +        return fields;
  31.367 +    }
  31.368 +    // where
  31.369 +    Map<Integer, Set<Field>> map = new HashMap<Integer,Set<Field>>();
  31.370 +
  31.371 +    /** Get the line number for the primary position for a tree.
  31.372 +     * The code is intended to be simple, although not necessarily efficient.
  31.373 +     * However, note that a file manager such as JavacFileManager is likely
  31.374 +     * to cache the results of file.getCharContent, avoiding the need to read
  31.375 +     * the bits from disk each time this method is called.
  31.376 +     */
  31.377 +    int getLine(JavaFileObject file, JCTree tree) {
  31.378 +        try {
  31.379 +            CharSequence cs = file.getCharContent(true);
  31.380 +            int line = 1;
  31.381 +            for (int i = 0; i < tree.pos; i++) {
  31.382 +                if (cs.charAt(i) == '\n') // jtreg tests always use Unix line endings
  31.383 +                    line++;
  31.384 +            }
  31.385 +            return line;
  31.386 +        } catch (IOException e) {
  31.387 +            return -1;
  31.388 +        }
  31.389 +    }
  31.390 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/tools/javac/treeannotests/AnnoTreeTests.java	Sun Feb 14 23:39:40 2010 -0800
    32.3 @@ -0,0 +1,44 @@
    32.4 +/*
    32.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.7 + *
    32.8 + * This code is free software; you can redistribute it and/or modify it
    32.9 + * under the terms of the GNU General Public License version 2 only, as
   32.10 + * published by the Free Software Foundation.
   32.11 + *
   32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   32.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   32.15 + * version 2 for more details (a copy is included in the LICENSE file that
   32.16 + * accompanied this code).
   32.17 + *
   32.18 + * You should have received a copy of the GNU General Public License version
   32.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   32.21 + *
   32.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   32.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   32.24 + * have any questions.
   32.25 + */
   32.26 +
   32.27 +/*
   32.28 + * @test
   32.29 + * @build DA TA Test TestProcessor
   32.30 + * @compile -proc:only -processor TestProcessor AnnoTreeTests.java
   32.31 + */
   32.32 +
   32.33 +@Test(6)
   32.34 +class AnnoTreeTests {
   32.35 +    // primitive types
   32.36 +    @DA("int") int i1;
   32.37 +    int i2 = (@TA("int") int) 0;
   32.38 +
   32.39 +    // simple array types
   32.40 +    @DA("int[]") int[] a1;
   32.41 +    int @TA("int") [] a2;
   32.42 +    int[] a3 = (@TA("int[]") int[]) a1;
   32.43 +    int[] a4 = (int @TA("int") []) a1;
   32.44 +
   32.45 +    // multi-dimensional array types
   32.46 +    // (still to come)
   32.47 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/tools/javac/treeannotests/DA.java	Sun Feb 14 23:39:40 2010 -0800
    33.3 @@ -0,0 +1,37 @@
    33.4 +/*
    33.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.7 + *
    33.8 + * This code is free software; you can redistribute it and/or modify it
    33.9 + * under the terms of the GNU General Public License version 2 only, as
   33.10 + * published by the Free Software Foundation.
   33.11 + *
   33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   33.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   33.15 + * version 2 for more details (a copy is included in the LICENSE file that
   33.16 + * accompanied this code).
   33.17 + *
   33.18 + * You should have received a copy of the GNU General Public License version
   33.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   33.21 + *
   33.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   33.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   33.24 + * have any questions.
   33.25 + */
   33.26 +
   33.27 +import java.lang.annotation.*;
   33.28 +import static java.lang.annotation.ElementType.*;
   33.29 +
   33.30 +/**
   33.31 + * Annotation used by TestProcessor to indicate the expected type
   33.32 + * of the declaration to which the annotation is attached.
   33.33 + * These annotations are expected to be found in the modifiers
   33.34 + * field on ClassDef, MethodDef and VarDef nodes.
   33.35 + */
   33.36 +@Target({FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
   33.37 +@interface DA {
   33.38 +    String value();
   33.39 +}
   33.40 +
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/tools/javac/treeannotests/TA.java	Sun Feb 14 23:39:40 2010 -0800
    34.3 @@ -0,0 +1,36 @@
    34.4 +/*
    34.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    34.7 + *
    34.8 + * This code is free software; you can redistribute it and/or modify it
    34.9 + * under the terms of the GNU General Public License version 2 only, as
   34.10 + * published by the Free Software Foundation.
   34.11 + *
   34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   34.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   34.15 + * version 2 for more details (a copy is included in the LICENSE file that
   34.16 + * accompanied this code).
   34.17 + *
   34.18 + * You should have received a copy of the GNU General Public License version
   34.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   34.21 + *
   34.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   34.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   34.24 + * have any questions.
   34.25 + */
   34.26 +
   34.27 +import java.lang.annotation.*;
   34.28 +import static java.lang.annotation.ElementType.*;
   34.29 +
   34.30 +/**
   34.31 + * Annotation used by TestProcessor to indicate the expected type
   34.32 + * to which the annotation is attached.
   34.33 + * These annotations are expected to be found in AnnotatedType nodes.
   34.34 + */
   34.35 +@Target({TYPE_USE, TYPE_PARAMETER})
   34.36 +@interface TA {
   34.37 +    String value();
   34.38 +}
   34.39 +
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/tools/javac/treeannotests/Test.java	Sun Feb 14 23:39:40 2010 -0800
    35.3 @@ -0,0 +1,32 @@
    35.4 +/*
    35.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    35.7 + *
    35.8 + * This code is free software; you can redistribute it and/or modify it
    35.9 + * under the terms of the GNU General Public License version 2 only, as
   35.10 + * published by the Free Software Foundation.
   35.11 + *
   35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   35.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   35.15 + * version 2 for more details (a copy is included in the LICENSE file that
   35.16 + * accompanied this code).
   35.17 + *
   35.18 + * You should have received a copy of the GNU General Public License version
   35.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   35.21 + *
   35.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   35.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   35.24 + * have any questions.
   35.25 + */
   35.26 +
   35.27 +/**
   35.28 + * Annotation used by TestProcessor to indicate the expected number of
   35.29 + * @DA and @TA annotations in the source tree to which the Test annotation
   35.30 + * is attached.
   35.31 + */
   35.32 +@interface Test {
   35.33 +    int value();
   35.34 +}
   35.35 +
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/tools/javac/treeannotests/TestProcessor.java	Sun Feb 14 23:39:40 2010 -0800
    36.3 @@ -0,0 +1,302 @@
    36.4 +/*
    36.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.7 + *
    36.8 + * This code is free software; you can redistribute it and/or modify it
    36.9 + * under the terms of the GNU General Public License version 2 only, as
   36.10 + * published by the Free Software Foundation.
   36.11 + *
   36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   36.15 + * version 2 for more details (a copy is included in the LICENSE file that
   36.16 + * accompanied this code).
   36.17 + *
   36.18 + * You should have received a copy of the GNU General Public License version
   36.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   36.21 + *
   36.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   36.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   36.24 + * have any questions.
   36.25 + */
   36.26 +
   36.27 +import java.io.*;
   36.28 +import java.util.*;
   36.29 +import javax.annotation.processing.*;
   36.30 +import javax.lang.model.*;
   36.31 +import javax.lang.model.element.*;
   36.32 +import javax.lang.model.util.*;
   36.33 +import javax.tools.*;
   36.34 +
   36.35 +import com.sun.source.util.*;
   36.36 +import com.sun.tools.javac.code.BoundKind;
   36.37 +import com.sun.tools.javac.tree.JCTree.*;
   36.38 +import com.sun.tools.javac.tree.TreeScanner;
   36.39 +import com.sun.tools.javac.tree.*;
   36.40 +import com.sun.tools.javac.util.List;
   36.41 +
   36.42 +/**
   36.43 + * Test processor used to check test programs using the @Test, @DA, and @TA
   36.44 + * annotations.
   36.45 + *
   36.46 + * The processor looks for elements annotated with @Test, and analyzes the
   36.47 + * syntax trees for those elements. Within such trees, the processor looks
   36.48 + * for the DA annotations on decls and TA annotations on types.
   36.49 + * The value of these annotations should be a simple string rendition of
   36.50 + * the tree node to which it is attached.
   36.51 + * The expected number of annotations is given by the parameter to the
   36.52 + * @Test annotation itself.
   36.53 + */
   36.54 +@SupportedAnnotationTypes({"Test"})
   36.55 +public class TestProcessor extends AbstractProcessor {
   36.56 +    public SourceVersion getSupportedSourceVersion() {
   36.57 +        return SourceVersion.latest();
   36.58 +    }
   36.59 +
   36.60 +    /** Process trees for elements annotated with the @Test(n) annotation. */
   36.61 +    public boolean process(Set<? extends TypeElement> annos, RoundEnvironment renv) {
   36.62 +        if (renv.processingOver())
   36.63 +            return true;
   36.64 +
   36.65 +        Elements elements = processingEnv.getElementUtils();
   36.66 +        Trees trees = Trees.instance(processingEnv);
   36.67 +
   36.68 +        TypeElement testAnno = elements.getTypeElement("Test");
   36.69 +        for (Element elem: renv.getElementsAnnotatedWith(testAnno)) {
   36.70 +            System.err.println("ELEM: " + elem);
   36.71 +            int count = getValue(getAnnoMirror(elem, testAnno), Integer.class);
   36.72 +            System.err.println("count: " + count);
   36.73 +            TreePath p = trees.getPath(elem);
   36.74 +            JavaFileObject file = p.getCompilationUnit().getSourceFile();
   36.75 +            JCTree tree = (JCTree) p.getLeaf();
   36.76 +            System.err.println("tree: " + tree);
   36.77 +            new TestScanner(file).check(tree, count);
   36.78 +        }
   36.79 +        return true;
   36.80 +    }
   36.81 +
   36.82 +    /** Get the AnnotationMirror on an element for a given annotation. */
   36.83 +    AnnotationMirror getAnnoMirror(Element e, TypeElement anno) {
   36.84 +        Types types = processingEnv.getTypeUtils();
   36.85 +        for (AnnotationMirror m: e.getAnnotationMirrors()) {
   36.86 +            if (types.isSameType(m.getAnnotationType(), anno.asType()))
   36.87 +                return m;
   36.88 +        }
   36.89 +        return null;
   36.90 +    }
   36.91 +
   36.92 +    /** Get the value of the value element of an annotation mirror. */
   36.93 +    <T> T getValue(AnnotationMirror m, Class<T> type) {
   36.94 +        for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> e: m.getElementValues().entrySet()) {
   36.95 +            ExecutableElement ee = e.getKey();
   36.96 +            if (ee.getSimpleName().contentEquals("value")) {
   36.97 +                AnnotationValue av = e.getValue();
   36.98 +                return type.cast(av.getValue());
   36.99 +            }
  36.100 +        }
  36.101 +        return null;
  36.102 +    }
  36.103 +
  36.104 +    /** Report an error to the annotation processing system. */
  36.105 +    void error(String msg) {
  36.106 +        Messager messager = processingEnv.getMessager();
  36.107 +        messager.printMessage(Diagnostic.Kind.ERROR, msg);
  36.108 +    }
  36.109 +
  36.110 +    /** Report an error to the annotation processing system. */
  36.111 +    void error(JavaFileObject file, JCTree tree, String msg) {
  36.112 +        // need better API for reporting tree position errors to the messager
  36.113 +        Messager messager = processingEnv.getMessager();
  36.114 +        String text = file.getName() + ":" + getLine(file, tree) + ": " + msg;
  36.115 +        messager.printMessage(Diagnostic.Kind.ERROR, text);
  36.116 +    }
  36.117 +
  36.118 +    /** Get the line number for the primary position for a tree.
  36.119 +     * The code is intended to be simple, although not necessarily efficient.
  36.120 +     * However, note that a file manager such as JavacFileManager is likely
  36.121 +     * to cache the results of file.getCharContent, avoiding the need to read
  36.122 +     * the bits from disk each time this method is called.
  36.123 +     */
  36.124 +    int getLine(JavaFileObject file, JCTree tree) {
  36.125 +        try {
  36.126 +            CharSequence cs = file.getCharContent(true);
  36.127 +            int line = 1;
  36.128 +            for (int i = 0; i < tree.pos; i++) {
  36.129 +                if (cs.charAt(i) == '\n') // jtreg tests always use Unix line endings
  36.130 +                    line++;
  36.131 +            }
  36.132 +            return line;
  36.133 +        } catch (IOException e) {
  36.134 +            return -1;
  36.135 +        }
  36.136 +    }
  36.137 +
  36.138 +    /** Scan a tree, looking for @DA and @TA annotations, and verifying that such
  36.139 +     * annotations are attached to the expected tree node matching the string
  36.140 +     * parameter of the annotation.
  36.141 +     */
  36.142 +    class TestScanner extends TreeScanner {
  36.143 +        /** Create a scanner for a given file. */
  36.144 +        TestScanner(JavaFileObject file) {
  36.145 +            this.file = file;
  36.146 +        }
  36.147 +
  36.148 +        /** Check the annotations in a given tree. */
  36.149 +        void check(JCTree tree, int expectCount) {
  36.150 +            foundCount = 0;
  36.151 +            scan(tree);
  36.152 +            if (foundCount != expectCount)
  36.153 +                error(file, tree, "Wrong number of annotations found: " + foundCount + ", expected: " + expectCount);
  36.154 +        }
  36.155 +
  36.156 +        /** Check @DA annotations on a class declaration. */
  36.157 +        @Override
  36.158 +        public void visitClassDef(JCClassDecl tree) {
  36.159 +            super.visitClassDef(tree);
  36.160 +            check(tree.mods.annotations, "DA", tree);
  36.161 +        }
  36.162 +
  36.163 +        /** Check @DA annotations on a method declaration. */
  36.164 +        @Override
  36.165 +        public void visitMethodDef(JCMethodDecl tree) {
  36.166 +            super.visitMethodDef(tree);
  36.167 +            check(tree.mods.annotations, "DA", tree);
  36.168 +        }
  36.169 +
  36.170 +        /** Check @DA annotations on a field, parameter or local variable declaration. */
  36.171 +        @Override
  36.172 +        public void visitVarDef(JCVariableDecl tree) {
  36.173 +            super.visitVarDef(tree);
  36.174 +            check(tree.mods.annotations, "DA", tree);
  36.175 +        }
  36.176 +
  36.177 +        /** Check @TA annotations on a type. */
  36.178 +        public void visitAnnotatedType(JCAnnotatedType tree) {
  36.179 +            super.visitAnnotatedType(tree);
  36.180 +            check(tree.annotations, "TA", tree);
  36.181 +        }
  36.182 +
  36.183 +        /** Check to see if a list of annotations contains a named annotation, and
  36.184 +         * if so, verify the annotation is expected by comparing the value of the
  36.185 +         * annotation's argument against the string rendition of the reference tree
  36.186 +         * node.
  36.187 +         * @param annos the list of annotations to be checked
  36.188 +         * @param name  the name of the annotation to be checked
  36.189 +         * @param tree  the tree against which to compare the annotations's argument
  36.190 +         */
  36.191 +        void check(List<? extends JCAnnotation> annos, String name, JCTree tree) {
  36.192 +            for (List<? extends JCAnnotation> l = annos; l.nonEmpty(); l = l.tail) {
  36.193 +                JCAnnotation anno = l.head;
  36.194 +                if (anno.annotationType.toString().equals(name) && (anno.args.size() == 1)) {
  36.195 +                    String expect = getStringValue(anno.args.head);
  36.196 +                    foundCount++;
  36.197 +                    System.err.println("found: " + name + " " + expect);
  36.198 +                    String found = new TypePrinter().print(tree);
  36.199 +                    if (!found.equals(expect))
  36.200 +                        error(file, anno, "Unexpected result: expected: \"" + expect + "\", found: \"" + found + "\"");
  36.201 +                }
  36.202 +            }
  36.203 +        }
  36.204 +
  36.205 +        /** Get the string value of an annotation argument, which is given by the
  36.206 +         * expression <i>name</i>=<i>value</i>.
  36.207 +         */
  36.208 +        String getStringValue(JCExpression e) {
  36.209 +            if (e.getTag() == JCTree.ASSIGN)  {
  36.210 +                JCAssign a = (JCAssign) e;
  36.211 +                JCExpression rhs = a.rhs;
  36.212 +                if (rhs.getTag() == JCTree.LITERAL) {
  36.213 +                    JCLiteral l = (JCLiteral) rhs;
  36.214 +                    return (String) l.value;
  36.215 +                }
  36.216 +            }
  36.217 +            throw new IllegalArgumentException(e.toString());
  36.218 +        }
  36.219 +
  36.220 +        /** The file for the tree. Used to locate errors. */
  36.221 +        JavaFileObject file;
  36.222 +        /** The number of annotations that have been found. @see #check */
  36.223 +        int foundCount;
  36.224 +    }
  36.225 +
  36.226 +    /** Convert a type or decl tree to a reference string used by the @DA and @TA annotations. */
  36.227 +    class TypePrinter extends Visitor {
  36.228 +        /** Convert a type or decl tree to a string. */
  36.229 +        String print(JCTree tree) {
  36.230 +            if (tree == null)
  36.231 +                return null;
  36.232 +            tree.accept(this);
  36.233 +            return result;
  36.234 +        }
  36.235 +
  36.236 +        String print(List<? extends JCTree> list) {
  36.237 +            return print(list, ", ");
  36.238 +        }
  36.239 +
  36.240 +        String print(List<? extends JCTree> list, String sep) {
  36.241 +            StringBuilder sb = new StringBuilder();
  36.242 +            if (list.nonEmpty()) {
  36.243 +                sb.append(print(list.head));
  36.244 +                for (List<? extends JCTree> l = list.tail; l.nonEmpty(); l = l.tail) {
  36.245 +                    sb.append(sep);
  36.246 +                    sb.append(print(l.head));
  36.247 +                }
  36.248 +            }
  36.249 +            return sb.toString();
  36.250 +        }
  36.251 +
  36.252 +        @Override
  36.253 +        public void visitClassDef(JCClassDecl tree) {
  36.254 +            result = tree.name.toString();
  36.255 +        }
  36.256 +
  36.257 +        @Override
  36.258 +        public void visitMethodDef(JCMethodDecl tree) {
  36.259 +            result = tree.name.toString();
  36.260 +        }
  36.261 +
  36.262 +        @Override
  36.263 +        public void visitVarDef(JCVariableDecl tree) {
  36.264 +            tree.vartype.accept(this);
  36.265 +        }
  36.266 +
  36.267 +        @Override
  36.268 +        public void visitAnnotatedType(JCAnnotatedType tree) {
  36.269 +            tree.underlyingType.accept(this);
  36.270 +        }
  36.271 +
  36.272 +        @Override
  36.273 +        public void visitTypeIdent(JCPrimitiveTypeTree tree) {
  36.274 +            result = tree.toString();
  36.275 +        }
  36.276 +
  36.277 +        @Override
  36.278 +        public void visitTypeArray(JCArrayTypeTree tree) {
  36.279 +            result = print(tree.elemtype) + "[]";
  36.280 +        }
  36.281 +
  36.282 +        @Override
  36.283 +        public void visitTypeApply(JCTypeApply tree) {
  36.284 +            result = print(tree.clazz) + "<" + print(tree.arguments) + ">";
  36.285 +        }
  36.286 +
  36.287 +        @Override
  36.288 +        public void visitTypeParameter(JCTypeParameter tree) {
  36.289 +            if (tree.bounds.isEmpty())
  36.290 +                result = tree.name.toString();
  36.291 +            else
  36.292 +                result = tree.name + " extends " + print(tree.bounds, "&");
  36.293 +        }
  36.294 +
  36.295 +        @Override
  36.296 +        public void visitWildcard(JCWildcard tree) {
  36.297 +            if (tree.kind.kind == BoundKind.UNBOUND)
  36.298 +                result = tree.kind.toString();
  36.299 +            else
  36.300 +                result = tree.kind + " " + print(tree.inner);
  36.301 +        }
  36.302 +
  36.303 +        private String result;
  36.304 +    }
  36.305 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/tools/javac/treepostests/TreePosTest.java	Sun Feb 14 23:39:40 2010 -0800
    37.3 @@ -0,0 +1,752 @@
    37.4 +/*
    37.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    37.7 + *
    37.8 + * This code is free software; you can redistribute it and/or modify it
    37.9 + * under the terms of the GNU General Public License version 2 only, as
   37.10 + * published by the Free Software Foundation.
   37.11 + *
   37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   37.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   37.15 + * version 2 for more details (a copy is included in the LICENSE file that
   37.16 + * accompanied this code).
   37.17 + *
   37.18 + * You should have received a copy of the GNU General Public License version
   37.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   37.21 + *
   37.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   37.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   37.24 + * have any questions.
   37.25 + */
   37.26 +
   37.27 +import java.awt.BorderLayout;
   37.28 +import java.awt.Color;
   37.29 +import java.awt.Dimension;
   37.30 +import java.awt.EventQueue;
   37.31 +import java.awt.Font;
   37.32 +import java.awt.GridBagConstraints;
   37.33 +import java.awt.GridBagLayout;
   37.34 +import java.awt.Rectangle;
   37.35 +import java.awt.event.ActionEvent;
   37.36 +import java.awt.event.ActionListener;
   37.37 +import java.awt.event.MouseAdapter;
   37.38 +import java.awt.event.MouseEvent;
   37.39 +import java.io.File;
   37.40 +import java.io.IOException;
   37.41 +import java.io.PrintStream;
   37.42 +import java.io.PrintWriter;
   37.43 +import java.io.StringWriter;
   37.44 +import java.lang.reflect.Field;
   37.45 +import java.lang.reflect.Modifier;
   37.46 +import java.nio.charset.Charset;
   37.47 +import java.util.ArrayList;
   37.48 +import java.util.Collections;
   37.49 +import java.util.HashMap;
   37.50 +import java.util.HashSet;
   37.51 +import java.util.Iterator;
   37.52 +import java.util.List;
   37.53 +import java.util.Map;
   37.54 +import java.util.Set;
   37.55 +import javax.swing.DefaultComboBoxModel;
   37.56 +import javax.swing.JComboBox;
   37.57 +import javax.swing.JComponent;
   37.58 +import javax.swing.JFrame;
   37.59 +import javax.swing.JLabel;
   37.60 +import javax.swing.JPanel;
   37.61 +import javax.swing.JScrollPane;
   37.62 +import javax.swing.JTextArea;
   37.63 +import javax.swing.JTextField;
   37.64 +import javax.swing.SwingUtilities;
   37.65 +import javax.swing.event.CaretEvent;
   37.66 +import javax.swing.event.CaretListener;
   37.67 +import javax.swing.text.BadLocationException;
   37.68 +import javax.swing.text.DefaultHighlighter;
   37.69 +import javax.swing.text.Highlighter;
   37.70 +import javax.tools.Diagnostic;
   37.71 +import javax.tools.DiagnosticListener;
   37.72 +import javax.tools.JavaFileObject;
   37.73 +import javax.tools.StandardJavaFileManager;
   37.74 +
   37.75 +import com.sun.source.tree.CompilationUnitTree;
   37.76 +import com.sun.source.util.JavacTask;
   37.77 +import com.sun.tools.javac.api.JavacTool;
   37.78 +import com.sun.tools.javac.code.Flags;
   37.79 +import com.sun.tools.javac.tree.JCTree;
   37.80 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
   37.81 +import com.sun.tools.javac.tree.JCTree.JCNewClass;
   37.82 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
   37.83 +import com.sun.tools.javac.tree.TreeInfo;
   37.84 +import com.sun.tools.javac.tree.TreeScanner;
   37.85 +
   37.86 +import static com.sun.tools.javac.util.Position.NOPOS;
   37.87 +
   37.88 +/**
   37.89 + * Utility and test program to check validity of tree positions for tree nodes.
   37.90 + * The program can be run standalone, or as a jtreg test.  In standalone mode,
   37.91 + * errors can be displayed in a gui viewer. For info on command line args,
   37.92 + * run program with no args.
   37.93 + *
   37.94 + * <p>
   37.95 + * jtreg: Note that by using the -r switch in the test description below, this test
   37.96 + * will process all java files in the langtools/test directory, thus implicitly
   37.97 + * covering any new language features that may be tested in this test suite.
   37.98 + */
   37.99 +
  37.100 +/*
  37.101 + * @test
  37.102 + * @bug 6919889
  37.103 + * @summary assorted position errors in compiler syntax trees
  37.104 + * @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations -ef ./tools/javap/typeAnnotations  .
  37.105 + */
  37.106 +public class TreePosTest {
  37.107 +    /**
  37.108 +     * Main entry point.
  37.109 +     * If test.src is set, program runs in jtreg mode, and will throw an Error
  37.110 +     * if any errors arise, otherwise System.exit will be used, unless the gui
  37.111 +     * viewer is being used. In jtreg mode, the default base directory for file
  37.112 +     * args is the value of ${test.src}. In jtreg mode, the -r option can be
  37.113 +     * given to change the default base directory to the root test directory.
  37.114 +     */
  37.115 +    public static void main(String... args) {
  37.116 +        String testSrc = System.getProperty("test.src");
  37.117 +        File baseDir = (testSrc == null) ? null : new File(testSrc);
  37.118 +        boolean ok = new TreePosTest().run(baseDir, args);
  37.119 +        if (!ok) {
  37.120 +            if (testSrc != null)  // jtreg mode
  37.121 +                throw new Error("failed");
  37.122 +            else
  37.123 +                System.exit(1);
  37.124 +        }
  37.125 +    }
  37.126 +
  37.127 +    /**
  37.128 +     * Run the program. A base directory can be provided for file arguments.
  37.129 +     * In jtreg mode, the -r option can be given to change the default base
  37.130 +     * directory to the test root directory. For other options, see usage().
  37.131 +     * @param baseDir base directory for any file arguments.
  37.132 +     * @param args command line args
  37.133 +     * @return true if successful or in gui mode
  37.134 +     */
  37.135 +    boolean run(File baseDir, String... args) {
  37.136 +        if (args.length == 0) {
  37.137 +            usage(System.out);
  37.138 +            return true;
  37.139 +        }
  37.140 +
  37.141 +        List<File> files = new ArrayList<File>();
  37.142 +        for (int i = 0; i < args.length; i++) {
  37.143 +            String arg = args[i];
  37.144 +            if (arg.equals("-encoding") && i + 1 < args.length)
  37.145 +                encoding = args[++i];
  37.146 +            else if (arg.equals("-gui"))
  37.147 +                gui = true;
  37.148 +            else if (arg.equals("-q"))
  37.149 +                quiet = true;
  37.150 +            else if (arg.equals("-v"))
  37.151 +                verbose = true;
  37.152 +            else if (arg.equals("-t") && i + 1 < args.length)
  37.153 +                tags.add(args[++i]);
  37.154 +            else if (arg.equals("-ef") && i + 1 < args.length)
  37.155 +                excludeFiles.add(new File(baseDir, args[++i]));
  37.156 +            else if (arg.equals("-r")) {
  37.157 +                if (excludeFiles.size() > 0)
  37.158 +                    throw new Error("-r must be used before -ef");
  37.159 +                File d = baseDir;
  37.160 +                while (!new File(d, "TEST.ROOT").exists()) {
  37.161 +                    d = d.getParentFile();
  37.162 +                    if (d == null)
  37.163 +                        throw new Error("cannot find TEST.ROOT");
  37.164 +                }
  37.165 +                baseDir = d;
  37.166 +            }
  37.167 +            else if (arg.startsWith("-"))
  37.168 +                throw new Error("unknown option: " + arg);
  37.169 +            else {
  37.170 +                while (i < args.length)
  37.171 +                    files.add(new File(baseDir, args[i++]));
  37.172 +            }
  37.173 +        }
  37.174 +
  37.175 +        for (File file: files) {
  37.176 +            if (file.exists())
  37.177 +                test(file);
  37.178 +            else
  37.179 +                error("File not found: " + file);
  37.180 +        }
  37.181 +
  37.182 +        if (fileCount != 1)
  37.183 +            System.err.println(fileCount + " files read");
  37.184 +        if (errors > 0)
  37.185 +            System.err.println(errors + " errors");
  37.186 +
  37.187 +        return (gui || errors == 0);
  37.188 +    }
  37.189 +
  37.190 +    /**
  37.191 +     * Print command line help.
  37.192 +     * @param out output stream
  37.193 +     */
  37.194 +    void usage(PrintStream out) {
  37.195 +        out.println("Usage:");
  37.196 +        out.println("  java TreePosTest options... files...");
  37.197 +        out.println("");
  37.198 +        out.println("where options include:");
  37.199 +        out.println("-gui      Display returns in a GUI viewer");
  37.200 +        out.println("-q        Quiet: don't report on inapplicable files");
  37.201 +        out.println("-v        Verbose: report on files as they are being read");
  37.202 +        out.println("-t tag    Limit checks to tree nodes with this tag");
  37.203 +        out.println("          Can be repeated if desired");
  37.204 +        out.println("-ef file  Exclude file or directory");
  37.205 +        out.println("");
  37.206 +        out.println("files may be directories or files");
  37.207 +        out.println("directories will be scanned recursively");
  37.208 +        out.println("non java files, or java files which cannot be parsed, will be ignored");
  37.209 +        out.println("");
  37.210 +    }
  37.211 +
  37.212 +    /**
  37.213 +     * Test a file. If the file is a directory, it will be recursively scanned
  37.214 +     * for java files.
  37.215 +     * @param file the file or directory to test
  37.216 +     */
  37.217 +    void test(File file) {
  37.218 +        if (excludeFiles.contains(file)) {
  37.219 +            if (!quiet)
  37.220 +                error("File " + file + " excluded");
  37.221 +            return;
  37.222 +        }
  37.223 +
  37.224 +        if (file.isDirectory()) {
  37.225 +            for (File f: file.listFiles()) {
  37.226 +                test(f);
  37.227 +            }
  37.228 +            return;
  37.229 +        }
  37.230 +
  37.231 +        if (file.isFile() && file.getName().endsWith(".java")) {
  37.232 +            try {
  37.233 +                if (verbose)
  37.234 +                    System.err.println(file);
  37.235 +                fileCount++;
  37.236 +                PosTester p = new PosTester();
  37.237 +                p.test(read(file));
  37.238 +            } catch (ParseException e) {
  37.239 +                if (!quiet) {
  37.240 +                    error("Error parsing " + file + "\n" + e.getMessage());
  37.241 +                }
  37.242 +            } catch (IOException e) {
  37.243 +                error("Error reading " + file + ": " + e);
  37.244 +            }
  37.245 +            return;
  37.246 +        }
  37.247 +
  37.248 +        if (!quiet)
  37.249 +            error("File " + file + " ignored");
  37.250 +    }
  37.251 +
  37.252 +    /**
  37.253 +     * Read a file.
  37.254 +     * @param file the file to be read
  37.255 +     * @return the tree for the content of the file
  37.256 +     * @throws IOException if any IO errors occur
  37.257 +     * @throws TreePosTest.ParseException if any errors occur while parsing the file
  37.258 +     */
  37.259 +    JCCompilationUnit read(File file) throws IOException, ParseException {
  37.260 +        StringWriter sw = new StringWriter();
  37.261 +        PrintWriter pw = new PrintWriter(sw);
  37.262 +        Reporter r = new Reporter(pw);
  37.263 +        JavacTool tool = JavacTool.create();
  37.264 +        Charset cs = (encoding == null ? null : Charset.forName(encoding));
  37.265 +        StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
  37.266 +        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
  37.267 +        JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
  37.268 +        Iterable<? extends CompilationUnitTree> trees = task.parse();
  37.269 +        pw.flush();
  37.270 +        if (r.errors > 0)
  37.271 +            throw new ParseException(sw.toString());
  37.272 +        Iterator<? extends CompilationUnitTree> iter = trees.iterator();
  37.273 +        if (!iter.hasNext())
  37.274 +            throw new Error("no trees found");
  37.275 +        JCCompilationUnit t = (JCCompilationUnit) iter.next();
  37.276 +        if (iter.hasNext())
  37.277 +            throw new Error("too many trees found");
  37.278 +        return t;
  37.279 +    }
  37.280 +
  37.281 +    /**
  37.282 +     * Report an error. When the program is complete, the program will either
  37.283 +     * exit or throw an Error if any errors have been reported.
  37.284 +     * @param msg the error message
  37.285 +     */
  37.286 +    void error(String msg) {
  37.287 +        System.err.println(msg);
  37.288 +        errors++;
  37.289 +    }
  37.290 +
  37.291 +    /** Number of files that have been analyzed. */
  37.292 +    int fileCount;
  37.293 +    /** Number of errors reported. */
  37.294 +    int errors;
  37.295 +    /** Flag: don't report irrelevant files. */
  37.296 +    boolean quiet;
  37.297 +    /** Flag: report files as they are processed. */
  37.298 +    boolean verbose;
  37.299 +    /** Flag: show errors in GUI viewer. */
  37.300 +    boolean gui;
  37.301 +    /** Option: encoding for test files. */
  37.302 +    String encoding;
  37.303 +    /** The GUI viewer for errors. */
  37.304 +    Viewer viewer;
  37.305 +    /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes
  37.306 +     * are analyzed. */
  37.307 +    Set<String> tags = new HashSet<String>();
  37.308 +    /** Set of files and directories to be excluded from analysis. */
  37.309 +    Set<File> excludeFiles = new HashSet<File>();
  37.310 +    /** Table of printable names for tree tag values. */
  37.311 +    TagNames tagNames = new TagNames();
  37.312 +
  37.313 +    /**
  37.314 +     * Main class for testing assertions concerning tree positions for tree nodes.
  37.315 +     */
  37.316 +    private class PosTester extends TreeScanner {
  37.317 +        void test(JCCompilationUnit tree) {
  37.318 +            sourcefile = tree.sourcefile;
  37.319 +            endPosTable = tree.endPositions;
  37.320 +            encl = new Info();
  37.321 +            tree.accept(this);
  37.322 +        }
  37.323 +
  37.324 +        @Override
  37.325 +        public void scan(JCTree tree) {
  37.326 +            if (tree == null)
  37.327 +                return;
  37.328 +
  37.329 +            Info self = new Info(tree, endPosTable);
  37.330 +            if (check(self)) {
  37.331 +                // Modifiers nodes are present throughout the tree even where
  37.332 +                // there is no corresponding source text.
  37.333 +                // Redundant semicolons in a class definition can cause empty
  37.334 +                // initializer blocks with no positions.
  37.335 +                if ((self.tag == JCTree.MODIFIERS || self.tag == JCTree.BLOCK)
  37.336 +                        && self.pos == NOPOS) {
  37.337 +                    // If pos is NOPOS, so should be the start and end positions
  37.338 +                    check("start == NOPOS", encl, self, self.start == NOPOS);
  37.339 +                    check("end == NOPOS", encl, self, self.end == NOPOS);
  37.340 +                } else {
  37.341 +                    // For this node, start , pos, and endpos should be all defined
  37.342 +                    check("start != NOPOS", encl, self, self.start != NOPOS);
  37.343 +                    check("pos != NOPOS", encl, self, self.pos != NOPOS);
  37.344 +                    check("end != NOPOS", encl, self, self.end != NOPOS);
  37.345 +                    // The following should normally be ordered
  37.346 +                    // encl.start <= start <= pos <= end <= encl.end
  37.347 +                    // In addition, the position of the enclosing node should be
  37.348 +                    // within this node.
  37.349 +                    // The primary exceptions are for array type nodes, because of the
  37.350 +                    // need to support legacy syntax:
  37.351 +                    //    e.g.    int a[];    int[] b[];    int f()[] { return null; }
  37.352 +                    // and because of inconsistent nesting of left and right of
  37.353 +                    // array declarations:
  37.354 +                    //    e.g.    int[][] a = new int[2][];
  37.355 +                    check("encl.start <= start", encl, self, encl.start <= self.start);
  37.356 +                    check("start <= pos", encl, self, self.start <= self.pos);
  37.357 +                    if (!(self.tag == JCTree.TYPEARRAY
  37.358 +                            && (encl.tag == JCTree.VARDEF || encl.tag == JCTree.TYPEARRAY))) {
  37.359 +                        check("encl.pos <= start || end <= encl.pos",
  37.360 +                                encl, self, encl.pos <= self.start || self.end <= encl.pos);
  37.361 +                    }
  37.362 +                    check("pos <= end", encl, self, self.pos <= self.end);
  37.363 +                    if (!(self.tag == JCTree.TYPEARRAY && encl.tag == JCTree.TYPEARRAY)) {
  37.364 +                        check("end <= encl.end", encl, self, self.end <= encl.end);
  37.365 +                    }
  37.366 +                }
  37.367 +            }
  37.368 +
  37.369 +            Info prevEncl = encl;
  37.370 +            encl = self;
  37.371 +            tree.accept(this);
  37.372 +            encl = prevEncl;
  37.373 +        }
  37.374 +
  37.375 +        @Override
  37.376 +        public void visitVarDef(JCVariableDecl tree) {
  37.377 +            // enum member declarations are desugared in the parser and have
  37.378 +            // ill-defined semantics for tree positions, so for now, we
  37.379 +            // skip the synthesized bits and just check parts which came from
  37.380 +            // the original source text
  37.381 +            if ((tree.mods.flags & Flags.ENUM) != 0) {
  37.382 +                scan(tree.mods);
  37.383 +                if (tree.init != null) {
  37.384 +                    if (tree.init.getTag() == JCTree.NEWCLASS) {
  37.385 +                        JCNewClass init = (JCNewClass) tree.init;
  37.386 +                        if (init.args != null && init.args.nonEmpty()) {
  37.387 +                            scan(init.args);
  37.388 +                        }
  37.389 +                        if (init.def != null && init.def.defs != null) {
  37.390 +                            scan(init.def.defs);
  37.391 +                        }
  37.392 +                    }
  37.393 +                }
  37.394 +            } else
  37.395 +                super.visitVarDef(tree);
  37.396 +        }
  37.397 +
  37.398 +        boolean check(Info x) {
  37.399 +            return tags.size() == 0 || tags.contains(tagNames.get(x.tag));
  37.400 +        }
  37.401 +
  37.402 +        void check(String label, Info encl, Info self, boolean ok) {
  37.403 +            if (!ok) {
  37.404 +                if (gui) {
  37.405 +                    if (viewer == null)
  37.406 +                        viewer = new Viewer();
  37.407 +                    viewer.addEntry(sourcefile, label, encl, self);
  37.408 +                }
  37.409 +
  37.410 +                String s = self.tree.toString();
  37.411 +                String msg = sourcefile.getName() + ": " + label + ": " +
  37.412 +                        "encl:" + encl + " this:" + self + "\n" +
  37.413 +                        s.substring(0, Math.min(80, s.length())).replaceAll("[\r\n]+", " ");
  37.414 +                error(msg);
  37.415 +            }
  37.416 +        }
  37.417 +
  37.418 +        JavaFileObject sourcefile;
  37.419 +        Map<JCTree, Integer> endPosTable;
  37.420 +        Info encl;
  37.421 +
  37.422 +    }
  37.423 +
  37.424 +    /**
  37.425 +     * Utility class providing easy access to position and other info for a tree node.
  37.426 +     */
  37.427 +    private class Info {
  37.428 +        Info() {
  37.429 +            tree = null;
  37.430 +            tag = JCTree.ERRONEOUS;
  37.431 +            start = 0;
  37.432 +            pos = 0;
  37.433 +            end = Integer.MAX_VALUE;
  37.434 +        }
  37.435 +
  37.436 +        Info(JCTree tree, Map<JCTree, Integer> endPosTable) {
  37.437 +            this.tree = tree;
  37.438 +            tag = tree.getTag();
  37.439 +            start = TreeInfo.getStartPos(tree);
  37.440 +            pos = tree.pos;
  37.441 +            end = TreeInfo.getEndPos(tree, endPosTable);
  37.442 +        }
  37.443 +
  37.444 +        @Override
  37.445 +        public String toString() {
  37.446 +            return tagNames.get(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]";
  37.447 +        }
  37.448 +
  37.449 +        final JCTree tree;
  37.450 +        final int tag;
  37.451 +        final int start;
  37.452 +        final int pos;
  37.453 +        final int end;
  37.454 +    }
  37.455 +
  37.456 +    /**
  37.457 +     * Names for tree tags.
  37.458 +     * javac does not provide an API to convert tag values to strings, so this class uses
  37.459 +     * reflection to determine names of public static final int values in JCTree.
  37.460 +     */
  37.461 +    private static class TagNames {
  37.462 +        String get(int tag) {
  37.463 +            if (map == null) {
  37.464 +                map = new HashMap<Integer, String>();
  37.465 +                Class c = JCTree.class;
  37.466 +                for (Field f : c.getDeclaredFields()) {
  37.467 +                    if (f.getType().equals(int.class)) {
  37.468 +                        int mods = f.getModifiers();
  37.469 +                        if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
  37.470 +                            try {
  37.471 +                                map.put(f.getInt(null), f.getName());
  37.472 +                            } catch (IllegalAccessException e) {
  37.473 +                            }
  37.474 +                        }
  37.475 +                    }
  37.476 +                }
  37.477 +            }
  37.478 +            String name = map.get(tag);
  37.479 +            return (name == null) ? "??" : name;
  37.480 +        }
  37.481 +
  37.482 +        private Map<Integer, String> map;
  37.483 +    }
  37.484 +
  37.485 +    /**
  37.486 +     * Thrown when errors are found parsing a java file.
  37.487 +     */
  37.488 +    private static class ParseException extends Exception {
  37.489 +        ParseException(String msg) {
  37.490 +            super(msg);
  37.491 +        }
  37.492 +    }
  37.493 +
  37.494 +    /**
  37.495 +     * DiagnosticListener to report diagnostics and count any errors that occur.
  37.496 +     */
  37.497 +    private static class Reporter implements DiagnosticListener<JavaFileObject> {
  37.498 +        Reporter(PrintWriter out) {
  37.499 +            this.out = out;
  37.500 +        }
  37.501 +
  37.502 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  37.503 +            out.println(diagnostic);
  37.504 +            switch (diagnostic.getKind()) {
  37.505 +                case ERROR:
  37.506 +                    errors++;
  37.507 +            }
  37.508 +        }
  37.509 +        int errors;
  37.510 +        PrintWriter out;
  37.511 +    }
  37.512 +
  37.513 +    /**
  37.514 +     * GUI viewer for issues found by TreePosTester. The viewer provides a drop
  37.515 +     * down list for selecting error conditions, a header area providing details
  37.516 +     * about an error, and a text area with the ranges of text highlighted as
  37.517 +     * appropriate.
  37.518 +     */
  37.519 +    private class Viewer extends JFrame {
  37.520 +        /**
  37.521 +         * Create a viewer.
  37.522 +         */
  37.523 +        Viewer() {
  37.524 +            initGUI();
  37.525 +        }
  37.526 +
  37.527 +        /**
  37.528 +         * Add another entry to the list of errors.
  37.529 +         * @param file The file containing the error
  37.530 +         * @param check The condition that was being tested, and which failed
  37.531 +         * @param encl the enclosing tree node
  37.532 +         * @param self the tree node containing the error
  37.533 +         */
  37.534 +        void addEntry(JavaFileObject file, String check, Info encl, Info self) {
  37.535 +            Entry e = new Entry(file, check, encl, self);
  37.536 +            DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
  37.537 +            m.addElement(e);
  37.538 +            if (m.getSize() == 1)
  37.539 +                entries.setSelectedItem(e);
  37.540 +        }
  37.541 +
  37.542 +        /**
  37.543 +         * Initialize the GUI window.
  37.544 +         */
  37.545 +        private void initGUI() {
  37.546 +            JPanel head = new JPanel(new GridBagLayout());
  37.547 +            GridBagConstraints lc = new GridBagConstraints();
  37.548 +            GridBagConstraints fc = new GridBagConstraints();
  37.549 +            fc.anchor = GridBagConstraints.WEST;
  37.550 +            fc.fill = GridBagConstraints.HORIZONTAL;
  37.551 +            fc.gridwidth = GridBagConstraints.REMAINDER;
  37.552 +
  37.553 +            entries = new JComboBox();
  37.554 +            entries.addActionListener(new ActionListener() {
  37.555 +                public void actionPerformed(ActionEvent e) {
  37.556 +                    showEntry((Entry) entries.getSelectedItem());
  37.557 +                }
  37.558 +            });
  37.559 +            fc.insets.bottom = 10;
  37.560 +            head.add(entries, fc);
  37.561 +            fc.insets.bottom = 0;
  37.562 +            head.add(new JLabel("check:"), lc);
  37.563 +            head.add(checkField = createTextField(80), fc);
  37.564 +            fc.fill = GridBagConstraints.NONE;
  37.565 +            head.add(setBackground(new JLabel("encl:"), enclColor), lc);
  37.566 +            head.add(enclPanel = new InfoPanel(), fc);
  37.567 +            head.add(setBackground(new JLabel("self:"), selfColor), lc);
  37.568 +            head.add(selfPanel = new InfoPanel(), fc);
  37.569 +            add(head, BorderLayout.NORTH);
  37.570 +
  37.571 +            body = new JTextArea();
  37.572 +            body.setFont(Font.decode(Font.MONOSPACED));
  37.573 +            body.addCaretListener(new CaretListener() {
  37.574 +                public void caretUpdate(CaretEvent e) {
  37.575 +                    int dot = e.getDot();
  37.576 +                    int mark = e.getMark();
  37.577 +                    if (dot == mark)
  37.578 +                        statusText.setText("dot: " + dot);
  37.579 +                    else
  37.580 +                        statusText.setText("dot: " + dot + ", mark:" + mark);
  37.581 +                }
  37.582 +            });
  37.583 +            JScrollPane p = new JScrollPane(body,
  37.584 +                    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  37.585 +                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  37.586 +            p.setPreferredSize(new Dimension(640, 480));
  37.587 +            add(p, BorderLayout.CENTER);
  37.588 +
  37.589 +            statusText = createTextField(80);
  37.590 +            add(statusText, BorderLayout.SOUTH);
  37.591 +
  37.592 +            pack();
  37.593 +            setLocationRelativeTo(null); // centered on screen
  37.594 +            setVisible(true);
  37.595 +            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.596 +        }
  37.597 +
  37.598 +        /** Show an entry that has been selected. */
  37.599 +        private void showEntry(Entry e) {
  37.600 +            try {
  37.601 +                // update simple fields
  37.602 +                setTitle(e.file.getName());
  37.603 +                checkField.setText(e.check);
  37.604 +                enclPanel.setInfo(e.encl);
  37.605 +                selfPanel.setInfo(e.self);
  37.606 +                // show file text with highlights
  37.607 +                body.setText(e.file.getCharContent(true).toString());
  37.608 +                Highlighter highlighter = body.getHighlighter();
  37.609 +                highlighter.removeAllHighlights();
  37.610 +                addHighlight(highlighter, e.encl, enclColor);
  37.611 +                addHighlight(highlighter, e.self, selfColor);
  37.612 +                scroll(body, getMinPos(enclPanel.info, selfPanel.info));
  37.613 +            } catch (IOException ex) {
  37.614 +                body.setText("Cannot read " + e.file.getName() + ": " + e);
  37.615 +            }
  37.616 +        }
  37.617 +
  37.618 +        /** Create a test field. */
  37.619 +        private JTextField createTextField(int width) {
  37.620 +            JTextField f = new JTextField(width);
  37.621 +            f.setEditable(false);
  37.622 +            f.setBorder(null);
  37.623 +            return f;
  37.624 +        }
  37.625 +
  37.626 +        /** Add a highlighted region based on the positions in an Info object. */
  37.627 +        private void addHighlight(Highlighter h, Info info, Color c) {
  37.628 +            int start = info.start;
  37.629 +            int end = info.end;
  37.630 +            if (start == -1 && end == -1)
  37.631 +                return;
  37.632 +            if (start == -1)
  37.633 +                start = end;
  37.634 +            if (end == -1)
  37.635 +                end = start;
  37.636 +            try {
  37.637 +                h.addHighlight(info.start, info.end,
  37.638 +                        new DefaultHighlighter.DefaultHighlightPainter(c));
  37.639 +                if (info.pos != -1) {
  37.640 +                    Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
  37.641 +                    h.addHighlight(info.pos, info.pos + 1,
  37.642 +                        new DefaultHighlighter.DefaultHighlightPainter(c2));
  37.643 +                }
  37.644 +            } catch (BadLocationException e) {
  37.645 +                e.printStackTrace();
  37.646 +            }
  37.647 +        }
  37.648 +
  37.649 +        /** Get the minimum valid position in a set of info objects. */
  37.650 +        private int getMinPos(Info... values) {
  37.651 +            int i = Integer.MAX_VALUE;
  37.652 +            for (Info info: values) {
  37.653 +                if (info.start >= 0) i = Math.min(i, info.start);
  37.654 +                if (info.pos   >= 0) i = Math.min(i, info.pos);
  37.655 +                if (info.end   >= 0) i = Math.min(i, info.end);
  37.656 +            }
  37.657 +            return (i == Integer.MAX_VALUE) ? 0 : i;
  37.658 +        }
  37.659 +
  37.660 +        /** Set the background on a component. */
  37.661 +        private JComponent setBackground(JComponent comp, Color c) {
  37.662 +            comp.setOpaque(true);
  37.663 +            comp.setBackground(c);
  37.664 +            return comp;
  37.665 +        }
  37.666 +
  37.667 +        /** Scroll a text area to display a given position near the middle of the visible area. */
  37.668 +        private void scroll(final JTextArea t, final int pos) {
  37.669 +            // Using invokeLater appears to give text a chance to sort itself out
  37.670 +            // before the scroll happens; otherwise scrollRectToVisible doesn't work.
  37.671 +            // Maybe there's a better way to sync with the text...
  37.672 +            EventQueue.invokeLater(new Runnable() {
  37.673 +                public void run() {
  37.674 +                    try {
  37.675 +                        Rectangle r = t.modelToView(pos);
  37.676 +                        JScrollPane p = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, t);
  37.677 +                        r.y = Math.max(0, r.y - p.getHeight() * 2 / 5);
  37.678 +                        r.height += p.getHeight() * 4 / 5;
  37.679 +                        t.scrollRectToVisible(r);
  37.680 +                    } catch (BadLocationException ignore) {
  37.681 +                    }
  37.682 +                }
  37.683 +            });
  37.684 +        }
  37.685 +
  37.686 +        private JComboBox entries;
  37.687 +        private JTextField checkField;
  37.688 +        private InfoPanel enclPanel;
  37.689 +        private InfoPanel selfPanel;
  37.690 +        private JTextArea body;
  37.691 +        private JTextField statusText;
  37.692 +
  37.693 +        private Color selfColor = new Color(0.f, 1.f, 0.f, 0.2f); // 20% green
  37.694 +        private Color enclColor = new Color(1.f, 0.f, 0.f, 0.2f); // 20% red
  37.695 +
  37.696 +        /** Panel to display an Info object. */
  37.697 +        private class InfoPanel extends JPanel {
  37.698 +            InfoPanel() {
  37.699 +                add(tagName = createTextField(20));
  37.700 +                add(new JLabel("start:"));
  37.701 +                add(addListener(start = createTextField(6)));
  37.702 +                add(new JLabel("pos:"));
  37.703 +                add(addListener(pos = createTextField(6)));
  37.704 +                add(new JLabel("end:"));
  37.705 +                add(addListener(end = createTextField(6)));
  37.706 +            }
  37.707 +
  37.708 +            void setInfo(Info info) {
  37.709 +                this.info = info;
  37.710 +                tagName.setText(tagNames.get(info.tag));
  37.711 +                start.setText(String.valueOf(info.start));
  37.712 +                pos.setText(String.valueOf(info.pos));
  37.713 +                end.setText(String.valueOf(info.end));
  37.714 +            }
  37.715 +
  37.716 +            JTextField addListener(final JTextField f) {
  37.717 +                f.addMouseListener(new MouseAdapter() {
  37.718 +                    @Override
  37.719 +                    public void mouseClicked(MouseEvent e) {
  37.720 +                        body.setCaretPosition(Integer.valueOf(f.getText()));
  37.721 +                        body.getCaret().setVisible(true);
  37.722 +                    }
  37.723 +                });
  37.724 +                return f;
  37.725 +            }
  37.726 +
  37.727 +            Info info;
  37.728 +            JTextField tagName;
  37.729 +            JTextField start;
  37.730 +            JTextField pos;
  37.731 +            JTextField end;
  37.732 +        }
  37.733 +
  37.734 +        /** Object to record information about an error to be displayed. */
  37.735 +        private class Entry {
  37.736 +            Entry(JavaFileObject file, String check, Info encl, Info self) {
  37.737 +                this.file = file;
  37.738 +                this.check = check;
  37.739 +                this.encl = encl;
  37.740 +                this.self= self;
  37.741 +            }
  37.742 +
  37.743 +            @Override
  37.744 +            public String toString() {
  37.745 +                return file.getName() + " " + check + " " + getMinPos(encl, self);
  37.746 +            }
  37.747 +
  37.748 +            final JavaFileObject file;
  37.749 +            final String check;
  37.750 +            final Info encl;
  37.751 +            final Info self;
  37.752 +        }
  37.753 +    }
  37.754 +}
  37.755 +
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/tools/javac/typeAnnotations/classfile/DeadCode.java	Sun Feb 14 23:39:40 2010 -0800
    38.3 @@ -0,0 +1,181 @@
    38.4 +/*
    38.5 + * Copyright 2009-2010 Sun Microsystems, Inc.  All Rights Reserved.
    38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    38.7 + *
    38.8 + * This code is free software; you can redistribute it and/or modify it
    38.9 + * under the terms of the GNU General Public License version 2 only, as
   38.10 + * published by the Free Software Foundation.
   38.11 + *
   38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   38.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   38.15 + * version 2 for more details (a copy is included in the LICENSE file that
   38.16 + * accompanied this code).
   38.17 + *
   38.18 + * You should have received a copy of the GNU General Public License version
   38.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   38.21 + *
   38.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   38.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   38.24 + * have any questions.
   38.25 + */
   38.26 +
   38.27 +import java.io.*;
   38.28 +import java.net.URL;
   38.29 +import java.util.List;
   38.30 +
   38.31 +import com.sun.tools.classfile.*;
   38.32 +
   38.33 +/*
   38.34 + * @test
   38.35 + * @bug 6917130
   38.36 + * @summary test that optimized away annotations are not emited to classfile
   38.37 + */
   38.38 +
   38.39 +public class DeadCode {
   38.40 +    public static void main(String[] args) throws Exception {
   38.41 +        new DeadCode().run();
   38.42 +    }
   38.43 +
   38.44 +    public void run() throws Exception {
   38.45 +        ClassFile cf = getClassFile("DeadCode$Test.class");
   38.46 +        test(cf);
   38.47 +        for (Field f : cf.fields) {
   38.48 +            test(cf, f);
   38.49 +        }
   38.50 +        for (Method m: cf.methods) {
   38.51 +            test(cf, m);
   38.52 +        }
   38.53 +
   38.54 +        countAnnotations();
   38.55 +
   38.56 +        if (errors > 0)
   38.57 +            throw new Exception(errors + " errors found");
   38.58 +        System.out.println("PASSED");
   38.59 +    }
   38.60 +
   38.61 +    ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
   38.62 +        URL url = getClass().getResource(name);
   38.63 +        InputStream in = url.openStream();
   38.64 +        try {
   38.65 +            return ClassFile.read(in);
   38.66 +        } finally {
   38.67 +            in.close();
   38.68 +        }
   38.69 +    }
   38.70 +
   38.71 +    /************ Helper annotations counting methods ******************/
   38.72 +    void test(ClassFile cf) {
   38.73 +        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
   38.74 +        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
   38.75 +    }
   38.76 +
   38.77 +    void test(ClassFile cf, Method m) {
   38.78 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
   38.79 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
   38.80 +    }
   38.81 +
   38.82 +    void test(ClassFile cf, Field m) {
   38.83 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
   38.84 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
   38.85 +    }
   38.86 +
   38.87 +    // test the result of Attributes.getIndex according to expectations
   38.88 +    // encoded in the method's name
   38.89 +    void test(ClassFile cf, String name, boolean visible) {
   38.90 +        int index = cf.attributes.getIndex(cf.constant_pool, name);
   38.91 +        if (index != -1) {
   38.92 +            Attribute attr = cf.attributes.get(index);
   38.93 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
   38.94 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
   38.95 +            all += tAttr.annotations.length;
   38.96 +            if (visible)
   38.97 +                visibles += tAttr.annotations.length;
   38.98 +            else
   38.99 +                invisibles += tAttr.annotations.length;
  38.100 +        }
  38.101 +    }
  38.102 +
  38.103 +    // test the result of Attributes.getIndex according to expectations
  38.104 +    // encoded in the method's name
  38.105 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  38.106 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  38.107 +        if (index != -1) {
  38.108 +            Attribute attr = m.attributes.get(index);
  38.109 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  38.110 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  38.111 +            all += tAttr.annotations.length;
  38.112 +            if (visible)
  38.113 +                visibles += tAttr.annotations.length;
  38.114 +            else
  38.115 +                invisibles += tAttr.annotations.length;
  38.116 +        }
  38.117 +    }
  38.118 +
  38.119 +    // test the result of Attributes.getIndex according to expectations
  38.120 +    // encoded in the method's name
  38.121 +    void test(ClassFile cf, Field m, String name, boolean visible) {
  38.122 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  38.123 +        if (index != -1) {
  38.124 +            Attribute attr = m.attributes.get(index);
  38.125 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  38.126 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  38.127 +            all += tAttr.annotations.length;
  38.128 +            if (visible)
  38.129 +                visibles += tAttr.annotations.length;
  38.130 +            else
  38.131 +                invisibles += tAttr.annotations.length;
  38.132 +        }
  38.133 +    }
  38.134 +
  38.135 +    void countAnnotations() {
  38.136 +        int expected_all = expected_visibles + expected_invisibles;
  38.137 +
  38.138 +        if (expected_all != all) {
  38.139 +            errors++;
  38.140 +            System.err.println("expected " + expected_all
  38.141 +                    + " annotations but found " + all);
  38.142 +        }
  38.143 +
  38.144 +        if (expected_visibles != visibles) {
  38.145 +            errors++;
  38.146 +            System.err.println("expected " + expected_visibles
  38.147 +                    + " visibles annotations but found " + visibles);
  38.148 +        }
  38.149 +
  38.150 +        if (expected_invisibles != invisibles) {
  38.151 +            errors++;
  38.152 +            System.err.println("expected " + expected_invisibles
  38.153 +                    + " invisibles annotations but found " + invisibles);
  38.154 +        }
  38.155 +
  38.156 +    }
  38.157 +
  38.158 +    int errors;
  38.159 +    int all;
  38.160 +    int visibles;
  38.161 +    int invisibles;
  38.162 +
  38.163 +    /*********************** Test class *************************/
  38.164 +    static int expected_invisibles = 1;
  38.165 +    static int expected_visibles = 0;
  38.166 +    static class Test {
  38.167 +        @interface A {}
  38.168 +
  38.169 +        void test() {
  38.170 +            List<? extends @A Object> o = null;
  38.171 +            o.toString();
  38.172 +
  38.173 +            @A String m;
  38.174 +            if (false) {
  38.175 +                @A String a;
  38.176 +                @A String b = "m";
  38.177 +                b.toString();
  38.178 +                List<? extends @A Object> c = null;
  38.179 +                c.toString();
  38.180 +            }
  38.181 +        }
  38.182 +    }
  38.183 +
  38.184 +}
    39.1 --- a/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    39.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    39.3 @@ -1,6 +1,6 @@
    39.4  /*
    39.5   * @test /nodynamiccopyright/
    39.6 - * @bug 6843077
    39.7 + * @bug 6843077 6919944
    39.8   * @summary check for duplicate annotation values
    39.9   * @author Mahmood Ali
   39.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    40.1 --- a/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    40.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    40.3 @@ -1,2 +1,2 @@
    40.4 -DuplicateAnnotationValue.java:10:45: compiler.err.duplicate.annotation.member.value: value, A
    40.5 +DuplicateAnnotationValue.java:10:37: compiler.err.duplicate.annotation.member.value: value, A
    40.6  1 error
    41.1 --- a/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    41.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    41.3 @@ -1,6 +1,6 @@
    41.4  /*
    41.5   * @test /nodynamiccopyright/
    41.6 - * @bug 6843077
    41.7 + * @bug 6843077 6919944
    41.8   * @summary check for duplicate annotation values
    41.9   * @author Mahmood Ali
   41.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    42.1 --- a/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    42.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    42.3 @@ -1,2 +1,2 @@
    42.4 -DuplicateAnnotationValue.java:10:34: compiler.err.duplicate.annotation.member.value: value, A
    42.5 +DuplicateAnnotationValue.java:10:26: compiler.err.duplicate.annotation.member.value: value, A
    42.6  1 error
    43.1 --- a/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    43.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    43.3 @@ -1,6 +1,6 @@
    43.4  /*
    43.5   * @test /nodynamiccopyright/
    43.6 - * @bug 6843077
    43.7 + * @bug 6843077 6919944
    43.8   * @summary check for duplicate annotation values for type parameter
    43.9   * @author Mahmood Ali
   43.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    44.1 --- a/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    44.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    44.3 @@ -1,2 +1,2 @@
    44.4 -DuplicateAnnotationValue.java:10:39: compiler.err.duplicate.annotation.member.value: value, A
    44.5 +DuplicateAnnotationValue.java:10:31: compiler.err.duplicate.annotation.member.value: value, A
    44.6  1 error
    45.1 --- a/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    45.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    45.3 @@ -1,6 +1,6 @@
    45.4  /*
    45.5   * @test /nodynamiccopyright/
    45.6 - * @bug 6843077
    45.7 + * @bug 6843077 6919944
    45.8   * @summary check for duplicate annotation values
    45.9   * @author Mahmood Ali
   45.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    46.1 --- a/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    46.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    46.3 @@ -1,2 +1,2 @@
    46.4 -DuplicateAnnotationValue.java:10:51: compiler.err.duplicate.annotation.member.value: value, A
    46.5 +DuplicateAnnotationValue.java:10:43: compiler.err.duplicate.annotation.member.value: value, A
    46.6  1 error
    47.1 --- a/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    47.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    47.3 @@ -1,6 +1,6 @@
    47.4  /*
    47.5   * @test /nodynamiccopyright/
    47.6 - * @bug 6843077
    47.7 + * @bug 6843077 6919944
    47.8   * @summary check for duplicate annotation values for type parameter
    47.9   * @author Mahmood Ali
   47.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    48.1 --- a/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    48.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    48.3 @@ -1,2 +1,2 @@
    48.4 -DuplicateAnnotationValue.java:8:64: compiler.err.duplicate.annotation.member.value: value, A
    48.5 +DuplicateAnnotationValue.java:8:56: compiler.err.duplicate.annotation.member.value: value, A
    48.6  1 error
    49.1 --- a/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    49.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    49.3 @@ -1,6 +1,6 @@
    49.4  /*
    49.5   * @test /nodynamiccopyright/
    49.6 - * @bug 6843077
    49.7 + * @bug 6843077 6919944
    49.8   * @summary check for duplicate annotation values in receiver
    49.9   * @author Mahmood Ali
   49.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    50.1 --- a/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    50.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    50.3 @@ -1,2 +1,2 @@
    50.4 -DuplicateAnnotationValue.java:9:37: compiler.err.duplicate.annotation.member.value: value, A
    50.5 +DuplicateAnnotationValue.java:9:29: compiler.err.duplicate.annotation.member.value: value, A
    50.6  1 error
    51.1 --- a/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    51.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    51.3 @@ -1,6 +1,6 @@
    51.4  /*
    51.5   * @test /nodynamiccopyright/
    51.6 - * @bug 6843077
    51.7 + * @bug 6843077 6919944
    51.8   * @summary check for duplicate annotation values for type parameter
    51.9   * @author Mahmood Ali
   51.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    52.1 --- a/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    52.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    52.3 @@ -1,2 +1,2 @@
    52.4 -DuplicateAnnotationValue.java:9:50: compiler.err.duplicate.annotation.member.value: value, A
    52.5 +DuplicateAnnotationValue.java:9:42: compiler.err.duplicate.annotation.member.value: value, A
    52.6  1 error
    53.1 --- a/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    53.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    53.3 @@ -1,6 +1,6 @@
    53.4  /*
    53.5   * @test /nodynamiccopyright/
    53.6 - * @bug 6843077
    53.7 + * @bug 6843077 6919944
    53.8   * @summary check for duplicate annotation values for type parameter
    53.9   * @author Mahmood Ali
   53.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    54.1 --- a/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    54.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    54.3 @@ -1,2 +1,2 @@
    54.4 -DuplicateAnnotationValue.java:8:54: compiler.err.duplicate.annotation.member.value: value, A
    54.5 +DuplicateAnnotationValue.java:8:46: compiler.err.duplicate.annotation.member.value: value, A
    54.6  1 error
    55.1 --- a/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.java	Fri Feb 12 13:25:27 2010 -0800
    55.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.java	Sun Feb 14 23:39:40 2010 -0800
    55.3 @@ -1,6 +1,6 @@
    55.4  /*
    55.5   * @test /nodynamiccopyright/
    55.6 - * @bug 6843077
    55.7 + * @bug 6843077 6919944
    55.8   * @summary check for duplicate annotation values for type parameter
    55.9   * @author Mahmood Ali
   55.10   * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
    56.1 --- a/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.out	Fri Feb 12 13:25:27 2010 -0800
    56.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.out	Sun Feb 14 23:39:40 2010 -0800
    56.3 @@ -1,2 +1,2 @@
    56.4 -DuplicateAnnotationValue.java:9:50: compiler.err.duplicate.annotation.member.value: value, A
    56.5 +DuplicateAnnotationValue.java:9:42: compiler.err.duplicate.annotation.member.value: value, A
    56.6  1 error
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/test/tools/javap/typeAnnotations/ArrayClassLiterals2.java	Sun Feb 14 23:39:40 2010 -0800
    57.3 @@ -0,0 +1,82 @@
    57.4 +/*
    57.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    57.7 + *
    57.8 + * This code is free software; you can redistribute it and/or modify it
    57.9 + * under the terms of the GNU General Public License version 2 only, as
   57.10 + * published by the Free Software Foundation.
   57.11 + *
   57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   57.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   57.15 + * version 2 for more details (a copy is included in the LICENSE file that
   57.16 + * accompanied this code).
   57.17 + *
   57.18 + * You should have received a copy of the GNU General Public License version
   57.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   57.21 + *
   57.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   57.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   57.24 + * have any questions.
   57.25 + */
   57.26 +
   57.27 +/*
   57.28 + * @test
   57.29 + * @bug 6918625
   57.30 + * @summary javap dumps type information of array class literals
   57.31 + */
   57.32 +
   57.33 +import java.io.*;
   57.34 +
   57.35 +public class ArrayClassLiterals2 {
   57.36 +    public static void main(String[] args) throws Exception {
   57.37 +        new ArrayClassLiterals2().run();
   57.38 +    }
   57.39 +
   57.40 +    public void run() throws IOException {
   57.41 +        File classFile = new File(System.getProperty("test.classes"), "ArrayClassLiterals2$Test.class");
   57.42 +
   57.43 +        verify(classFile,
   57.44 +               "RuntimeInvisibleTypeAnnotations:",
   57.45 +               "CLASS_LITERAL_GENERIC_OR_ARRAY"
   57.46 +               );
   57.47 +
   57.48 +        if (errors > 0)
   57.49 +            throw new Error(errors + " found.");
   57.50 +    }
   57.51 +
   57.52 +    String javap(File f) {
   57.53 +        StringWriter sw = new StringWriter();
   57.54 +        PrintWriter out = new PrintWriter(sw);
   57.55 +        int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out);
   57.56 +        if (rc != 0)
   57.57 +            throw new Error("javap failed. rc=" + rc);
   57.58 +        out.close();
   57.59 +        return sw.toString();
   57.60 +    }
   57.61 +
   57.62 +    void verify(File classFile, String... expects) {
   57.63 +        String output = javap(classFile);
   57.64 +        for (String expect: expects) {
   57.65 +            if (output.indexOf(expect)< 0)
   57.66 +                error(expect + " not found");
   57.67 +        }
   57.68 +    }
   57.69 +
   57.70 +    void error(String msg) {
   57.71 +        System.err.println(msg);
   57.72 +        errors++;
   57.73 +    }
   57.74 +
   57.75 +    int errors;
   57.76 +
   57.77 +
   57.78 +    /*********************** Test class *************************/
   57.79 +    static class Test {
   57.80 +        @interface A { }
   57.81 +        void test() {
   57.82 +            Object a = @A String @A [] @A [].class;
   57.83 +        }
   57.84 +    }
   57.85 +}

mercurial