Merge

Sun, 28 Jun 2009 00:01:09 -0700

author
tbell
date
Sun, 28 Jun 2009 00:01:09 -0700
changeset 312
c391a167ac57
parent 306
e71fd3fcebf5
parent 311
464d58654324
child 314
ec1acd3af057

Merge

     1.1 --- a/src/share/bin/launcher.sh-template	Fri Jun 26 10:26:27 2009 -0700
     1.2 +++ b/src/share/bin/launcher.sh-template	Sun Jun 28 00:01:09 2009 -0700
     1.3 @@ -1,7 +1,7 @@
     1.4  #!/bin/sh
     1.5  
     1.6  #
     1.7 -# Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.8 +# Copyright 2006-2009 Sun Microsystems, Inc.  All Rights Reserved.
     1.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    1.10  #
    1.11  # This code is free software; you can redistribute it and/or modify it
    1.12 @@ -44,7 +44,27 @@
    1.13     bcp="$mylib/#PROGRAM#.jar":$cp 
    1.14  fi
    1.15  
    1.16 -# javac currently assumes that assertions are enabled in the launcher
    1.17 +# tools currently assumes that assertions are enabled in the launcher
    1.18  ea=-ea:com.sun.tools
    1.19  
    1.20 -"#TARGET_JAVA#" ${bcp:+-Xbootclasspath/p:"$bcp"} ${ea} -jar "${mydir}"/../lib/#PROGRAM#.jar "$@"
    1.21 +# Any parameters starting with -J are passed to the JVM.
    1.22 +# All other parameters become parameters of #PROGRAM#.
    1.23 +
    1.24 +# Separate out -J* options for the JVM
    1.25 +# Note jdk as possible default to run jtreg
    1.26 +# Unset IFS and use newline as arg separator to preserve spaces in args
    1.27 +DUALCASE=1  # for MKS: make case statement case-sensitive (6709498)
    1.28 +saveIFS="$IFS"
    1.29 +nl='
    1.30 +'
    1.31 +for i in "$@" ; do
    1.32 +   IFS=
    1.33 +   case $i in
    1.34 +   -J* )       javaOpts=$javaOpts$nl`echo $i | sed -e 's/^-J//'` ;;
    1.35 +   *   )       toolOpts=$toolOpts$nl$i ;;
    1.36 +   esac
    1.37 +   IFS="$saveIFS"
    1.38 +done
    1.39 +unset DUALCASE
    1.40 +
    1.41 +eval "#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mydir}"/../lib/#PROGRAM#.jar ${toolOpts}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/com/sun/source/tree/AnnotatedTypeTree.java	Sun Jun 28 00:01:09 2009 -0700
     2.3 @@ -0,0 +1,47 @@
     2.4 +/*
     2.5 + * Copyright 2008-2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Sun designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Sun in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.26 + * have any questions.
    2.27 + */
    2.28 +
    2.29 +package com.sun.source.tree;
    2.30 +
    2.31 +import java.util.List;
    2.32 +
    2.33 +/**
    2.34 + * A tree node for an annotated type
    2.35 + *
    2.36 + * For example:
    2.37 + * <pre>
    2.38 + *    {@code @}<em>annotationType String</em>
    2.39 + *    {@code @}<em>annotationType</em> ( <em>arguments</em> ) <em>Date</em>
    2.40 + * </pre>
    2.41 + *
    2.42 + * @see "JSR 308: Annotations on Java Types"
    2.43 + *
    2.44 + * @author Mahmood Ali
    2.45 + * @since 1.7
    2.46 + */
    2.47 +public interface AnnotatedTypeTree extends ExpressionTree {
    2.48 +    List<? extends AnnotationTree> getAnnotations();
    2.49 +    ExpressionTree getUnderlyingType();
    2.50 +}
     3.1 --- a/src/share/classes/com/sun/source/tree/MethodTree.java	Fri Jun 26 10:26:27 2009 -0700
     3.2 +++ b/src/share/classes/com/sun/source/tree/MethodTree.java	Sun Jun 28 00:01:09 2009 -0700
     3.3 @@ -53,6 +53,7 @@
     3.4      Tree getReturnType();
     3.5      List<? extends TypeParameterTree> getTypeParameters();
     3.6      List<? extends VariableTree> getParameters();
     3.7 +    List<? extends AnnotationTree> getReceiverAnnotations();
     3.8      List<? extends ExpressionTree> getThrows();
     3.9      BlockTree getBody();
    3.10      Tree getDefaultValue(); // for annotation types
     4.1 --- a/src/share/classes/com/sun/source/tree/Tree.java	Fri Jun 26 10:26:27 2009 -0700
     4.2 +++ b/src/share/classes/com/sun/source/tree/Tree.java	Sun Jun 28 00:01:09 2009 -0700
     4.3 @@ -45,6 +45,9 @@
     4.4       * Enumerates all kinds of trees.
     4.5       */
     4.6      public enum Kind {
     4.7 +
     4.8 +        ANNOTATED_TYPE(AnnotatedTypeTree.class),
     4.9 +
    4.10          /**
    4.11           * Used for instances of {@link AnnotationTree}.
    4.12           */
     5.1 --- a/src/share/classes/com/sun/source/tree/TreeVisitor.java	Fri Jun 26 10:26:27 2009 -0700
     5.2 +++ b/src/share/classes/com/sun/source/tree/TreeVisitor.java	Sun Jun 28 00:01:09 2009 -0700
     5.3 @@ -57,6 +57,7 @@
     5.4   * @since 1.6
     5.5   */
     5.6  public interface TreeVisitor<R,P> {
     5.7 +    R visitAnnotatedType(AnnotatedTypeTree node, P p);
     5.8      R visitAnnotation(AnnotationTree node, P p);
     5.9      R visitMethodInvocation(MethodInvocationTree node, P p);
    5.10      R visitAssert(AssertTree node, P p);
     6.1 --- a/src/share/classes/com/sun/source/tree/TypeParameterTree.java	Fri Jun 26 10:26:27 2009 -0700
     6.2 +++ b/src/share/classes/com/sun/source/tree/TypeParameterTree.java	Sun Jun 28 00:01:09 2009 -0700
     6.3 @@ -47,4 +47,5 @@
     6.4  public interface TypeParameterTree extends Tree {
     6.5      Name getName();
     6.6      List<? extends Tree> getBounds();
     6.7 +    List<? extends AnnotationTree> getAnnotations();
     6.8  }
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/share/classes/com/sun/source/util/AbstractTypeProcessor.java	Sun Jun 28 00:01:09 2009 -0700
     7.3 @@ -0,0 +1,245 @@
     7.4 +/*
     7.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.  Sun designates this
    7.11 + * particular file as subject to the "Classpath" exception as provided
    7.12 + * by Sun in the LICENSE file that accompanied this code.
    7.13 + *
    7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 + * version 2 for more details (a copy is included in the LICENSE file that
    7.18 + * accompanied this code).
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License version
    7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 + *
    7.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    7.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    7.26 + * have any questions.
    7.27 + */
    7.28 +
    7.29 +package com.sun.source.util;
    7.30 +
    7.31 +import java.util.ArrayList;
    7.32 +import java.util.HashSet;
    7.33 +import java.util.List;
    7.34 +import java.util.Set;
    7.35 +
    7.36 +import javax.annotation.processing.*;
    7.37 +import javax.lang.model.element.Name;
    7.38 +import javax.lang.model.element.TypeElement;
    7.39 +import javax.lang.model.util.ElementFilter;
    7.40 +
    7.41 +import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    7.42 +import com.sun.tools.javac.util.Context;
    7.43 +import com.sun.tools.javac.util.Log;
    7.44 +
    7.45 +import com.sun.source.tree.ClassTree;
    7.46 +
    7.47 +/**
    7.48 + * This class is an abstract annotation processor designed to be a
    7.49 + * convenient superclass for concrete "type processors", processors that
    7.50 + * require the type information in the processed source.
    7.51 + *
    7.52 + * <p>Type processing occurs in one round after the tool (e.g. java compiler)
    7.53 + * analyzes the source (all sources taken as input to the tool and sources
    7.54 + * generated by other annotation processors).
    7.55 + *
    7.56 + * <p>The tool infrastructure will interact with classes extending this abstract
    7.57 + * class as follows:
    7.58 + *
    7.59 + * <ol>
    7.60 + * [1-3: Identical to {@link Processor} life cycle]
    7.61 + *
    7.62 + * <li>If an existing {@code Processor} object is not being used, to
    7.63 + * create an instance of a processor the tool calls the no-arg
    7.64 + * constructor of the processor class.
    7.65 + *
    7.66 + * <li>Next, the tool calls the {@link #init init} method with
    7.67 + * an appropriate {@code ProcessingEnvironment}.
    7.68 + *
    7.69 + * <li>Afterwards, the tool calls {@link #getSupportedAnnotationTypes
    7.70 + * getSupportedAnnotationTypes}, {@link #getSupportedOptions
    7.71 + * getSupportedOptions}, and {@link #getSupportedSourceVersion
    7.72 + * getSupportedSourceVersion}.  These methods are only called once per
    7.73 + * run, not on each round.
    7.74 + *
    7.75 + * [4-5Unique to {@code AbstractTypeProcessor} subclasses]
    7.76 + *
    7.77 + * <li>For each class containing a supported annotation, the tool calls
    7.78 + * {@link #typeProcess(TypeElement, TreePath) typeProcess} method on the
    7.79 + * {@code Processor}.  The class is guaranteed to be type-checked Java code
    7.80 + * and all the tree type and symbol information is resolved.
    7.81 + *
    7.82 + * <li>Finally, the tools calls the
    7.83 + * {@link #typeProcessingOver() typeProcessingOver} method
    7.84 + * on the {@code Processor}.
    7.85 + *
    7.86 + * </ol>
    7.87 + *
    7.88 + * <p>The tool is permitted to ask type processors to process a class once
    7.89 + * it is analyzed before the rest of classes are analyzed.  The tool is also
    7.90 + * permitted to stop type processing immediately if any errors are raised,
    7.91 + * without invoking {@code typeProcessingOver}
    7.92 + *
    7.93 + * <p>A subclass may override any of the methods in this class, as long as the
    7.94 + * general {@link javax.annotation.processing.Processor Processor}
    7.95 + * contract is obeyed, with one notable exception.
    7.96 + * {@link #process(Set, RoundEnvironment)} may not be overridden, as it
    7.97 + * is called during the regular annotation phase before classes are analyzed.
    7.98 + *
    7.99 + * @author Mahmood Ali
   7.100 + * @since 1.7
   7.101 + */
   7.102 +public abstract class AbstractTypeProcessor extends AbstractProcessor {
   7.103 +    private final Set<Name> elements = new HashSet<Name>();
   7.104 +    private boolean hasInvokedTypeProcessingOver = false;
   7.105 +    private JavacProcessingEnvironment env;
   7.106 +    private final AttributionTaskListener listener = new AttributionTaskListener();
   7.107 +
   7.108 +    /**
   7.109 +     * Constructor for subclasses to call.
   7.110 +     */
   7.111 +    protected AbstractTypeProcessor() { }
   7.112 +
   7.113 +    /**
   7.114 +     * {@inheritDoc}
   7.115 +     */
   7.116 +    @Override
   7.117 +    public void init(ProcessingEnvironment env) {
   7.118 +        super.init(env);
   7.119 +        this.env = (JavacProcessingEnvironment)env;
   7.120 +        prepareContext(this.env.getContext());
   7.121 +    }
   7.122 +
   7.123 +    /**
   7.124 +     * The use of this method is obsolete in type processors.  The method is
   7.125 +     * called during regular annotation processing phase only.
   7.126 +     */
   7.127 +    @Override
   7.128 +    public final boolean process(Set<? extends TypeElement> annotations,
   7.129 +            RoundEnvironment roundEnv) {
   7.130 +        for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
   7.131 +            elements.add(elem.getQualifiedName());
   7.132 +        }
   7.133 +        return false;
   7.134 +    }
   7.135 +
   7.136 +    /**
   7.137 +     * Processes a fully analyzed class that contains a supported annotation
   7.138 +     * (look {@link #getSupportedAnnotationTypes()}).
   7.139 +     *
   7.140 +     * <p>The passed class is always a valid type-checked Java code.
   7.141 +     *
   7.142 +     * @param element       element of the analyzed class
   7.143 +     * @param tree  the tree path to the element, with the leaf being a
   7.144 +     *              {@link ClassTree}
   7.145 +     */
   7.146 +    public abstract void typeProcess(TypeElement element, TreePath tree);
   7.147 +
   7.148 +    /**
   7.149 +     * A method to be called once all the classes are processed and no error
   7.150 +     * is reported.
   7.151 +     *
   7.152 +     * <p>Subclasses may override this method to do any aggregate analysis
   7.153 +     * (e.g. generate report, persistence) or resource deallocation.
   7.154 +     *
   7.155 +     * <p>If an error (a Java error or a processor error) is reported, this
   7.156 +     * method is not guaranteed to be invoked.
   7.157 +     */
   7.158 +    public void typeProcessingOver() { }
   7.159 +
   7.160 +    /**
   7.161 +     * adds a listener for attribution.
   7.162 +     */
   7.163 +    private void prepareContext(Context context) {
   7.164 +        TaskListener otherListener = context.get(TaskListener.class);
   7.165 +        if (otherListener == null) {
   7.166 +            context.put(TaskListener.class, listener);
   7.167 +        } else {
   7.168 +            // handle cases of multiple listeners
   7.169 +            context.put(TaskListener.class, (TaskListener)null);
   7.170 +            TaskListeners listeners = new TaskListeners();
   7.171 +            listeners.add(otherListener);
   7.172 +            listeners.add(listener);
   7.173 +            context.put(TaskListener.class, listeners);
   7.174 +        }
   7.175 +    }
   7.176 +
   7.177 +    /**
   7.178 +     * A task listener that invokes the processor whenever a class is fully
   7.179 +     * analyzed.
   7.180 +     */
   7.181 +    private final class AttributionTaskListener implements TaskListener {
   7.182 +
   7.183 +        @Override
   7.184 +        public void finished(TaskEvent e) {
   7.185 +            Log log = Log.instance(env.getContext());
   7.186 +
   7.187 +            if (!hasInvokedTypeProcessingOver && elements.isEmpty() && log.nerrors == 0) {
   7.188 +                typeProcessingOver();
   7.189 +                hasInvokedTypeProcessingOver = true;
   7.190 +            }
   7.191 +
   7.192 +            if (e.getKind() != TaskEvent.Kind.ANALYZE)
   7.193 +                return;
   7.194 +
   7.195 +            if (e.getTypeElement() == null)
   7.196 +                throw new AssertionError("event task without a type element");
   7.197 +            if (e.getCompilationUnit() == null)
   7.198 +                throw new AssertionError("even task without compilation unit");
   7.199 +
   7.200 +            if (!elements.remove(e.getTypeElement().getQualifiedName()))
   7.201 +                return;
   7.202 +
   7.203 +            if (log.nerrors != 0)
   7.204 +                return;
   7.205 +
   7.206 +            TypeElement elem = e.getTypeElement();
   7.207 +            TreePath p = Trees.instance(env).getPath(elem);
   7.208 +
   7.209 +            typeProcess(elem, p);
   7.210 +
   7.211 +            if (!hasInvokedTypeProcessingOver && elements.isEmpty() && log.nerrors == 0) {
   7.212 +                typeProcessingOver();
   7.213 +                hasInvokedTypeProcessingOver = true;
   7.214 +            }
   7.215 +        }
   7.216 +
   7.217 +        @Override
   7.218 +        public void started(TaskEvent e) { }
   7.219 +
   7.220 +    }
   7.221 +
   7.222 +    /**
   7.223 +     * A task listener multiplexer.
   7.224 +     */
   7.225 +    private static class TaskListeners implements TaskListener {
   7.226 +        private final List<TaskListener> listeners = new ArrayList<TaskListener>();
   7.227 +
   7.228 +        public void add(TaskListener listener) {
   7.229 +            listeners.add(listener);
   7.230 +        }
   7.231 +
   7.232 +        public void remove(TaskListener listener) {
   7.233 +            listeners.remove(listener);
   7.234 +        }
   7.235 +
   7.236 +        @Override
   7.237 +        public void finished(TaskEvent e) {
   7.238 +            for (TaskListener listener : listeners)
   7.239 +                listener.finished(e);
   7.240 +        }
   7.241 +
   7.242 +        @Override
   7.243 +        public void started(TaskEvent e) {
   7.244 +            for (TaskListener listener : listeners)
   7.245 +                listener.started(e);
   7.246 +        }
   7.247 +    }
   7.248 +}
     8.1 --- a/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Fri Jun 26 10:26:27 2009 -0700
     8.2 +++ b/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Sun Jun 28 00:01:09 2009 -0700
     8.3 @@ -244,6 +244,10 @@
     8.4          return defaultAction(node, p);
     8.5      }
     8.6  
     8.7 +    public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
     8.8 +        return defaultAction(node, p);
     8.9 +    }
    8.10 +
    8.11      public R visitErroneous(ErroneousTree node, P p) {
    8.12          return defaultAction(node, p);
    8.13      }
     9.1 --- a/src/share/classes/com/sun/source/util/TreePath.java	Fri Jun 26 10:26:27 2009 -0700
     9.2 +++ b/src/share/classes/com/sun/source/util/TreePath.java	Sun Jun 28 00:01:09 2009 -0700
     9.3 @@ -120,19 +120,20 @@
     9.4      public Iterator<Tree> iterator() {
     9.5          return new Iterator<Tree>() {
     9.6              public boolean hasNext() {
     9.7 -                return curr.parent != null;
     9.8 +                return next != null;
     9.9              }
    9.10  
    9.11              public Tree next() {
    9.12 -                curr = curr.parent;
    9.13 -                return curr.leaf;
    9.14 +                Tree t = next.leaf;
    9.15 +                next = next.parent;
    9.16 +                return t;
    9.17              }
    9.18  
    9.19              public void remove() {
    9.20                  throw new UnsupportedOperationException();
    9.21              }
    9.22  
    9.23 -            private TreePath curr;
    9.24 +            private TreePath next = TreePath.this;
    9.25          };
    9.26      }
    9.27  
    10.1 --- a/src/share/classes/com/sun/source/util/TreeScanner.java	Fri Jun 26 10:26:27 2009 -0700
    10.2 +++ b/src/share/classes/com/sun/source/util/TreeScanner.java	Sun Jun 28 00:01:09 2009 -0700
    10.3 @@ -138,6 +138,7 @@
    10.4          r = scanAndReduce(node.getReturnType(), p, r);
    10.5          r = scanAndReduce(node.getTypeParameters(), p, r);
    10.6          r = scanAndReduce(node.getParameters(), p, r);
    10.7 +        r = scanAndReduce(node.getReceiverAnnotations(), p, r);
    10.8          r = scanAndReduce(node.getThrows(), p, r);
    10.9          r = scanAndReduce(node.getBody(), p, r);
   10.10          return r;
   10.11 @@ -354,7 +355,9 @@
   10.12      }
   10.13  
   10.14      public R visitTypeParameter(TypeParameterTree node, P p) {
   10.15 -        return scan(node.getBounds(), p);
   10.16 +        R r = scan(node.getAnnotations(), p);
   10.17 +        r = scanAndReduce(node.getBounds(), p, r);
   10.18 +        return r;
   10.19      }
   10.20  
   10.21      public R visitWildcard(WildcardTree node, P p) {
   10.22 @@ -371,6 +374,12 @@
   10.23          return r;
   10.24      }
   10.25  
   10.26 +   public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
   10.27 +       R r = scan(node.getAnnotations(), p);
   10.28 +       r = scanAndReduce(node.getUnderlyingType(), p, r);
   10.29 +       return r;
   10.30 +   }
   10.31 +
   10.32      public R visitOther(Tree node, P p) {
   10.33          return null;
   10.34      }
    11.1 --- a/src/share/classes/com/sun/source/util/Trees.java	Fri Jun 26 10:26:27 2009 -0700
    11.2 +++ b/src/share/classes/com/sun/source/util/Trees.java	Sun Jun 28 00:01:09 2009 -0700
    11.3 @@ -35,6 +35,7 @@
    11.4  import javax.lang.model.type.DeclaredType;
    11.5  import javax.lang.model.type.ErrorType;
    11.6  import javax.lang.model.type.TypeMirror;
    11.7 +import javax.tools.Diagnostic;
    11.8  import javax.tools.JavaCompiler.CompilationTask;
    11.9  
   11.10  import com.sun.source.tree.ClassTree;
   11.11 @@ -182,7 +183,20 @@
   11.12      /**
   11.13        * Gets the original type from the ErrorType object.
   11.14        * @param errorType The errorType for which we want to get the original type.
   11.15 -      * @returns javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
   11.16 +      * @return javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
   11.17        */
   11.18      public abstract TypeMirror getOriginalType(ErrorType errorType);
   11.19 +
   11.20 +    /**
   11.21 +     * Prints a message of the specified kind at the location of the
   11.22 +     * tree within the provided compilation unit
   11.23 +     *
   11.24 +     * @param kind the kind of message
   11.25 +     * @param msg  the message, or an empty string if none
   11.26 +     * @param t    the tree to use as a position hint
   11.27 +     * @param root the compilation unit that contains tree
   11.28 +     */
   11.29 +    public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
   11.30 +            com.sun.source.tree.Tree t,
   11.31 +            com.sun.source.tree.CompilationUnitTree root);
   11.32  }
    12.1 --- a/src/share/classes/com/sun/tools/classfile/Attribute.java	Fri Jun 26 10:26:27 2009 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/classfile/Attribute.java	Sun Jun 28 00:01:09 2009 -0700
    12.3 @@ -54,6 +54,8 @@
    12.4      public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
    12.5      public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
    12.6      public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
    12.7 +    public static final String RuntimeVisibleTypeAnnotations = "RuntimeVisibleTypeAnnotations";
    12.8 +    public static final String RuntimeInvisibleTypeAnnotations = "RuntimeInvisibleTypeAnnotations";
    12.9      public static final String Signature                = "Signature";
   12.10      public static final String SourceDebugExtension     = "SourceDebugExtension";
   12.11      public static final String SourceFile               = "SourceFile";
   12.12 @@ -131,6 +133,8 @@
   12.13                  standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
   12.14                  standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
   12.15                  standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
   12.16 +                standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
   12.17 +                standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
   12.18                  standardAttributes.put(Signature,     Signature_attribute.class);
   12.19                  standardAttributes.put(SourceID, SourceID_attribute.class);
   12.20              }
   12.21 @@ -184,6 +188,8 @@
   12.22          R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p);
   12.23          R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p);
   12.24          R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p);
   12.25 +        R visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, P p);
   12.26 +        R visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, P p);
   12.27          R visitSignature(Signature_attribute attr, P p);
   12.28          R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p);
   12.29          R visitSourceFile(SourceFile_attribute attr, P p);
    13.1 --- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Fri Jun 26 10:26:27 2009 -0700
    13.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Sun Jun 28 00:01:09 2009 -0700
    13.3 @@ -1,3 +1,4 @@
    13.4 +
    13.5  /*
    13.6   * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    13.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.8 @@ -477,6 +478,16 @@
    13.9              return null;
   13.10          }
   13.11  
   13.12 +        public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
   13.13 +            annotationWriter.write(attr.annotations, out);
   13.14 +            return null;
   13.15 +        }
   13.16 +
   13.17 +        public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
   13.18 +            annotationWriter.write(attr.annotations, out);
   13.19 +            return null;
   13.20 +        }
   13.21 +
   13.22          public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
   13.23              out.writeByte(attr.parameter_annotations.length);
   13.24              for (Annotation[] annos: attr.parameter_annotations)
   13.25 @@ -636,6 +647,12 @@
   13.26                  write(anno, out);
   13.27          }
   13.28  
   13.29 +        public void write(ExtendedAnnotation[] annos, ClassOutputStream out) {
   13.30 +            out.writeShort(annos.length);
   13.31 +            for (ExtendedAnnotation anno: annos)
   13.32 +                write(anno, out);
   13.33 +        }
   13.34 +
   13.35          public void write(Annotation anno, ClassOutputStream out) {
   13.36              out.writeShort(anno.type_index);
   13.37              out.writeShort(anno.element_value_pairs.length);
   13.38 @@ -643,6 +660,11 @@
   13.39                  write(p, out);
   13.40          }
   13.41  
   13.42 +        public void write(ExtendedAnnotation anno, ClassOutputStream out) {
   13.43 +            write(anno.annotation, out);
   13.44 +            write(anno.position, out);
   13.45 +        }
   13.46 +
   13.47          public void write(element_value_pair pair, ClassOutputStream out) {
   13.48              out.writeShort(pair.element_name_index);
   13.49              write(pair.value, out);
   13.50 @@ -680,5 +702,95 @@
   13.51                  write(v, out);
   13.52              return null;
   13.53          }
   13.54 +
   13.55 +        private void write(ExtendedAnnotation.Position p, ClassOutputStream out) {
   13.56 +            out.writeByte(p.type.targetTypeValue());
   13.57 +            switch (p.type) {
   13.58 +            // type case
   13.59 +            case TYPECAST:
   13.60 +            case TYPECAST_GENERIC_OR_ARRAY:
   13.61 +            // object creation
   13.62 +            case INSTANCEOF:
   13.63 +            case INSTANCEOF_GENERIC_OR_ARRAY:
   13.64 +            // new expression
   13.65 +            case NEW:
   13.66 +            case NEW_GENERIC_OR_ARRAY:
   13.67 +            case NEW_TYPE_ARGUMENT:
   13.68 +            case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
   13.69 +                out.writeShort(p.offset);
   13.70 +                break;
   13.71 +             // local variable
   13.72 +            case LOCAL_VARIABLE:
   13.73 +            case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
   13.74 +                int table_length = p.lvarOffset.length;
   13.75 +                out.writeShort(table_length);
   13.76 +                for (int i = 0; i < table_length; ++i) {
   13.77 +                    out.writeShort(1);  // for table length
   13.78 +                    out.writeShort(p.lvarOffset[i]);
   13.79 +                    out.writeShort(p.lvarLength[i]);
   13.80 +                    out.writeShort(p.lvarIndex[i]);
   13.81 +                }
   13.82 +                break;
   13.83 +             // method receiver
   13.84 +            case METHOD_RECEIVER:
   13.85 +                // Do nothing
   13.86 +                break;
   13.87 +            // type parameters
   13.88 +            case CLASS_TYPE_PARAMETER:
   13.89 +            case METHOD_TYPE_PARAMETER:
   13.90 +                out.writeByte(p.parameter_index);
   13.91 +                break;
   13.92 +            // type parameters bounds
   13.93 +            case CLASS_TYPE_PARAMETER_BOUND:
   13.94 +            case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
   13.95 +            case METHOD_TYPE_PARAMETER_BOUND:
   13.96 +            case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
   13.97 +                out.writeByte(p.parameter_index);
   13.98 +                out.writeByte(p.bound_index);
   13.99 +                break;
  13.100 +             // wildcards
  13.101 +            case WILDCARD_BOUND:
  13.102 +            case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  13.103 +                write(p.wildcard_position, out);
  13.104 +                break;
  13.105 +            // Class extends and implements clauses
  13.106 +            case CLASS_EXTENDS:
  13.107 +            case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  13.108 +                out.writeByte(p.type_index);
  13.109 +                break;
  13.110 +            // throws
  13.111 +            case THROWS:
  13.112 +                out.writeByte(p.type_index);
  13.113 +                break;
  13.114 +            case CLASS_LITERAL:
  13.115 +                out.writeShort(p.offset);
  13.116 +                break;
  13.117 +            // method parameter: not specified
  13.118 +            case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  13.119 +                out.writeByte(p.parameter_index);
  13.120 +                break;
  13.121 +            // method type argument: wasn't specified
  13.122 +            case METHOD_TYPE_ARGUMENT:
  13.123 +            case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  13.124 +                out.writeShort(p.offset);
  13.125 +                out.writeByte(p.type_index);
  13.126 +                break;
  13.127 +            // We don't need to worry abut these
  13.128 +            case METHOD_RETURN_GENERIC_OR_ARRAY:
  13.129 +            case FIELD_GENERIC_OR_ARRAY:
  13.130 +                break;
  13.131 +            case UNKNOWN:
  13.132 +                break;
  13.133 +            default:
  13.134 +                throw new AssertionError("unknown type: " + p);
  13.135 +            }
  13.136 +
  13.137 +            // Append location data for generics/arrays.
  13.138 +            if (p.type.hasLocation()) {
  13.139 +                out.writeShort(p.location.size());
  13.140 +                for (int i : p.location)
  13.141 +                    out.writeByte((byte)i);
  13.142 +            }
  13.143 +        }
  13.144      }
  13.145  }
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/share/classes/com/sun/tools/classfile/ExtendedAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
    14.3 @@ -0,0 +1,614 @@
    14.4 +/*
    14.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.7 + *
    14.8 + * This code is free software; you can redistribute it and/or modify it
    14.9 + * under the terms of the GNU General Public License version 2 only, as
   14.10 + * published by the Free Software Foundation.  Sun designates this
   14.11 + * particular file as subject to the "Classpath" exception as provided
   14.12 + * by Sun in the LICENSE file that accompanied this code.
   14.13 + *
   14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.17 + * version 2 for more details (a copy is included in the LICENSE file that
   14.18 + * accompanied this code).
   14.19 + *
   14.20 + * You should have received a copy of the GNU General Public License version
   14.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.23 + *
   14.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   14.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   14.26 + * have any questions.
   14.27 + */
   14.28 +
   14.29 +package com.sun.tools.classfile;
   14.30 +
   14.31 +import java.io.IOException;
   14.32 +import java.util.ArrayList;
   14.33 +import java.util.EnumSet;
   14.34 +import java.util.List;
   14.35 +import java.util.Set;
   14.36 +
   14.37 +import static com.sun.tools.classfile.ExtendedAnnotation.TargetAttribute.*;
   14.38 +
   14.39 +/**
   14.40 + * See JSR 308 specification, section 4.1
   14.41 + *
   14.42 + *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   14.43 + *  you write code that depends on this, you do so at your own risk.
   14.44 + *  This code and its internal interfaces are subject to change or
   14.45 + *  deletion without notice.</b>
   14.46 + */
   14.47 +public class ExtendedAnnotation {
   14.48 +    ExtendedAnnotation(ClassReader cr) throws IOException, Annotation.InvalidAnnotation {
   14.49 +        annotation = new Annotation(cr);
   14.50 +        position = read_position(cr);
   14.51 +    }
   14.52 +
   14.53 +    public ExtendedAnnotation(ConstantPool constant_pool,
   14.54 +            Annotation annotation, Position position) {
   14.55 +        this.annotation = annotation;
   14.56 +        this.position = position;
   14.57 +    }
   14.58 +
   14.59 +    public int length() {
   14.60 +        int n = annotation.length();
   14.61 +        n += position_length(position);
   14.62 +        return n;
   14.63 +    }
   14.64 +
   14.65 +    public final Annotation annotation;
   14.66 +    public final Position position;
   14.67 +
   14.68 +    private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation {
   14.69 +        // Copied from ClassReader
   14.70 +        int tag = (byte)cr.readUnsignedByte();  // cast to introduce signedness
   14.71 +        if (!TargetType.isValidTargetTypeValue(tag))
   14.72 +            throw new Annotation.InvalidAnnotation("invalid type annotation target type value: " + tag);
   14.73 +
   14.74 +        TargetType type = TargetType.fromTargetTypeValue(tag);
   14.75 +
   14.76 +        Position position = new Position();
   14.77 +        position.type = type;
   14.78 +
   14.79 +        switch (type) {
   14.80 +        // type case
   14.81 +        case TYPECAST:
   14.82 +        case TYPECAST_GENERIC_OR_ARRAY:
   14.83 +        // object creation
   14.84 +        case INSTANCEOF:
   14.85 +        case INSTANCEOF_GENERIC_OR_ARRAY:
   14.86 +        // new expression
   14.87 +        case NEW:
   14.88 +        case NEW_GENERIC_OR_ARRAY:
   14.89 +            position.offset = cr.readUnsignedShort();
   14.90 +            break;
   14.91 +         // local variable
   14.92 +        case LOCAL_VARIABLE:
   14.93 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
   14.94 +            int table_length = cr.readUnsignedShort();
   14.95 +            position.lvarOffset = new int[table_length];
   14.96 +            position.lvarLength = new int[table_length];
   14.97 +            position.lvarIndex = new int[table_length];
   14.98 +            for (int i = 0; i < table_length; ++i) {
   14.99 +                position.lvarOffset[i] = cr.readUnsignedShort();
  14.100 +                position.lvarLength[i] = cr.readUnsignedShort();
  14.101 +                position.lvarIndex[i] = cr.readUnsignedShort();
  14.102 +            }
  14.103 +            break;
  14.104 +         // method receiver
  14.105 +        case METHOD_RECEIVER:
  14.106 +            // Do nothing
  14.107 +            break;
  14.108 +        // type parameters
  14.109 +        case CLASS_TYPE_PARAMETER:
  14.110 +        case METHOD_TYPE_PARAMETER:
  14.111 +            position.parameter_index = cr.readUnsignedByte();
  14.112 +            break;
  14.113 +        // type parameter bounds
  14.114 +        case CLASS_TYPE_PARAMETER_BOUND:
  14.115 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.116 +        case METHOD_TYPE_PARAMETER_BOUND:
  14.117 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.118 +            position.parameter_index = cr.readUnsignedByte();
  14.119 +            position.bound_index = cr.readUnsignedByte();
  14.120 +            break;
  14.121 +         // wildcards
  14.122 +        case WILDCARD_BOUND:
  14.123 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  14.124 +            position.wildcard_position = read_position(cr);
  14.125 +            break;
  14.126 +         // Class extends and implements clauses
  14.127 +        case CLASS_EXTENDS:
  14.128 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  14.129 +            position.type_index = cr.readUnsignedByte();
  14.130 +            break;
  14.131 +        // throws
  14.132 +        case THROWS:
  14.133 +            position.type_index = cr.readUnsignedByte();
  14.134 +            break;
  14.135 +        case CLASS_LITERAL:
  14.136 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
  14.137 +            position.offset = cr.readUnsignedShort();
  14.138 +            break;
  14.139 +        // method parameter: not specified
  14.140 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  14.141 +            position.parameter_index = cr.readUnsignedByte();
  14.142 +            break;
  14.143 +        // method type argument: wasn't specified
  14.144 +        case NEW_TYPE_ARGUMENT:
  14.145 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.146 +        case METHOD_TYPE_ARGUMENT:
  14.147 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.148 +            position.offset = cr.readUnsignedShort();
  14.149 +            position.type_index = cr.readUnsignedByte();
  14.150 +            break;
  14.151 +        // We don't need to worry abut these
  14.152 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
  14.153 +        case FIELD_GENERIC_OR_ARRAY:
  14.154 +            break;
  14.155 +        case UNKNOWN:
  14.156 +            break;
  14.157 +        default:
  14.158 +            throw new AssertionError("Cannot be here");
  14.159 +        }
  14.160 +
  14.161 +        if (type.hasLocation()) {
  14.162 +            int len = cr.readUnsignedShort();
  14.163 +            List<Integer> loc = new ArrayList<Integer>(len);
  14.164 +            for (int i = 0; i < len; i++)
  14.165 +                loc.add(cr.readUnsignedByte());
  14.166 +            position.location = loc;
  14.167 +        }
  14.168 +        return position;
  14.169 +    }
  14.170 +
  14.171 +    private static int position_length(Position pos) {
  14.172 +        int n = 0;
  14.173 +        n += 1; // target_type
  14.174 +        switch (pos.type) {
  14.175 +        // type case
  14.176 +        case TYPECAST:
  14.177 +        case TYPECAST_GENERIC_OR_ARRAY:
  14.178 +        // object creation
  14.179 +        case INSTANCEOF:
  14.180 +        case INSTANCEOF_GENERIC_OR_ARRAY:
  14.181 +        // new expression
  14.182 +        case NEW:
  14.183 +        case NEW_GENERIC_OR_ARRAY:
  14.184 +            n += 2;
  14.185 +            break;
  14.186 +         // local variable
  14.187 +        case LOCAL_VARIABLE:
  14.188 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
  14.189 +            n += 2; // table_length;
  14.190 +            int table_length = pos.lvarOffset.length;
  14.191 +            n += 2 * table_length; // offset
  14.192 +            n += 2 * table_length; // length;
  14.193 +            n += 2 * table_length; // index
  14.194 +            break;
  14.195 +         // method receiver
  14.196 +        case METHOD_RECEIVER:
  14.197 +            // Do nothing
  14.198 +            break;
  14.199 +        // type parameters
  14.200 +        case CLASS_TYPE_PARAMETER:
  14.201 +        case METHOD_TYPE_PARAMETER:
  14.202 +            n += 1; // parameter_index;
  14.203 +            break;
  14.204 +        // type parameter bounds
  14.205 +        case CLASS_TYPE_PARAMETER_BOUND:
  14.206 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.207 +        case METHOD_TYPE_PARAMETER_BOUND:
  14.208 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.209 +            n += 1; // parameter_index
  14.210 +            n += 1; // bound_index
  14.211 +            break;
  14.212 +        case WILDCARD_BOUND:
  14.213 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  14.214 +            n += position_length(pos.wildcard_position);
  14.215 +            break;
  14.216 +         // Class extends and implements clauses
  14.217 +        case CLASS_EXTENDS:
  14.218 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  14.219 +            n += 1; // type_index
  14.220 +            break;
  14.221 +        // throws
  14.222 +        case THROWS:
  14.223 +            n += 1; // type_index
  14.224 +            break;
  14.225 +        case CLASS_LITERAL:
  14.226 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
  14.227 +            n += 1; // offset
  14.228 +            break;
  14.229 +        // method parameter: not specified
  14.230 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  14.231 +            n += 1; // parameter_index
  14.232 +            break;
  14.233 +        // method type argument: wasn't specified
  14.234 +        case NEW_TYPE_ARGUMENT:
  14.235 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.236 +        case METHOD_TYPE_ARGUMENT:
  14.237 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.238 +            n += 2; // offset
  14.239 +            n += 1; // type index
  14.240 +            break;
  14.241 +        // We don't need to worry abut these
  14.242 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
  14.243 +        case FIELD_GENERIC_OR_ARRAY:
  14.244 +            break;
  14.245 +        case UNKNOWN:
  14.246 +            break;
  14.247 +        default:
  14.248 +        }
  14.249 +
  14.250 +        if (pos.type.hasLocation()) {
  14.251 +            n += 2; // length
  14.252 +            n += 1 * pos.location.size(); // actual array size
  14.253 +        }
  14.254 +
  14.255 +        return n;
  14.256 +    }
  14.257 +
  14.258 +    // Code duplicated from com.sun.tools.javac.code.TypeAnnotations.Position
  14.259 +    public static class Position {
  14.260 +
  14.261 +        public TargetType type = TargetType.UNKNOWN;
  14.262 +
  14.263 +        // For generic/array types.
  14.264 +        public List<Integer> location = new ArrayList<Integer>();
  14.265 +
  14.266 +        // Tree position.
  14.267 +        public int pos = -1;
  14.268 +
  14.269 +        // For typecasts, type tests, new (and locals, as start_pc).
  14.270 +        public int offset = -1;
  14.271 +
  14.272 +        // For locals.
  14.273 +        public int[] lvarOffset = new int[] { -1 };
  14.274 +        public int[] lvarLength = new int[] { -1 };
  14.275 +        public int[] lvarIndex = new int[] { -1 };
  14.276 +
  14.277 +        // For type parameter bound
  14.278 +        public int bound_index = -1;
  14.279 +
  14.280 +        // For type parameter and method parameter
  14.281 +        public int parameter_index = -1;
  14.282 +
  14.283 +        // For class extends, implements, and throws classes
  14.284 +        public int type_index = -2;
  14.285 +
  14.286 +        // For wildcards
  14.287 +        public Position wildcard_position = null;
  14.288 +
  14.289 +        @Override
  14.290 +        public String toString() {
  14.291 +            StringBuilder sb = new StringBuilder();
  14.292 +            sb.append('[');
  14.293 +            sb.append(type);
  14.294 +
  14.295 +            switch (type) {
  14.296 +            // type case
  14.297 +            case TYPECAST:
  14.298 +            case TYPECAST_GENERIC_OR_ARRAY:
  14.299 +            // object creation
  14.300 +            case INSTANCEOF:
  14.301 +            case INSTANCEOF_GENERIC_OR_ARRAY:
  14.302 +            // new expression
  14.303 +            case NEW:
  14.304 +            case NEW_GENERIC_OR_ARRAY:
  14.305 +            case NEW_TYPE_ARGUMENT:
  14.306 +            case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.307 +                sb.append(", offset = ");
  14.308 +                sb.append(offset);
  14.309 +                break;
  14.310 +             // local variable
  14.311 +            case LOCAL_VARIABLE:
  14.312 +            case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
  14.313 +                sb.append(", {");
  14.314 +                for (int i = 0; i < lvarOffset.length; ++i) {
  14.315 +                    if (i != 0) sb.append("; ");
  14.316 +                    sb.append(", start_pc = ");
  14.317 +                    sb.append(lvarOffset[i]);
  14.318 +                    sb.append(", length = ");
  14.319 +                    sb.append(lvarLength[i]);
  14.320 +                    sb.append(", index = ");
  14.321 +                    sb.append(lvarIndex[i]);
  14.322 +                }
  14.323 +                sb.append("}");
  14.324 +                break;
  14.325 +             // method receiver
  14.326 +            case METHOD_RECEIVER:
  14.327 +                // Do nothing
  14.328 +                break;
  14.329 +            // type parameters
  14.330 +            case CLASS_TYPE_PARAMETER:
  14.331 +            case METHOD_TYPE_PARAMETER:
  14.332 +                sb.append(", param_index = ");
  14.333 +                sb.append(parameter_index);
  14.334 +                break;
  14.335 +            // type parameters bound
  14.336 +            case CLASS_TYPE_PARAMETER_BOUND:
  14.337 +            case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.338 +            case METHOD_TYPE_PARAMETER_BOUND:
  14.339 +            case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  14.340 +                sb.append(", param_index = ");
  14.341 +                sb.append(parameter_index);
  14.342 +                sb.append(", bound_index = ");
  14.343 +                sb.append(bound_index);
  14.344 +                break;
  14.345 +             // wildcard
  14.346 +            case WILDCARD_BOUND:
  14.347 +            case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  14.348 +                sb.append(", wild_card = ");
  14.349 +                sb.append(wildcard_position);
  14.350 +                break;
  14.351 +             // Class extends and implements clauses
  14.352 +            case CLASS_EXTENDS:
  14.353 +            case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  14.354 +                sb.append(", type_index = ");
  14.355 +                sb.append(type_index);
  14.356 +                break;
  14.357 +            // throws
  14.358 +            case THROWS:
  14.359 +                sb.append(", type_index = ");
  14.360 +                sb.append(type_index);
  14.361 +                break;
  14.362 +            case CLASS_LITERAL:
  14.363 +                sb.append(", offset = ");
  14.364 +                sb.append(offset);
  14.365 +                break;
  14.366 +            // method parameter: not specified
  14.367 +            case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  14.368 +                sb.append(", param_index = ");
  14.369 +                sb.append(parameter_index);
  14.370 +                break;
  14.371 +            // method type argument: wasn't specified
  14.372 +            case METHOD_TYPE_ARGUMENT:
  14.373 +            case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  14.374 +                sb.append(", offset = ");
  14.375 +                sb.append(offset);
  14.376 +                sb.append(", type_index = ");
  14.377 +                sb.append(type_index);
  14.378 +                break;
  14.379 +            // We don't need to worry abut these
  14.380 +            case METHOD_RETURN_GENERIC_OR_ARRAY:
  14.381 +            case FIELD_GENERIC_OR_ARRAY:
  14.382 +                break;
  14.383 +            case UNKNOWN:
  14.384 +                break;
  14.385 +            default:
  14.386 +                throw new AssertionError("unknown type: " + type);
  14.387 +            }
  14.388 +
  14.389 +            // Append location data for generics/arrays.
  14.390 +            if (type.hasLocation()) {
  14.391 +                sb.append(", location = (");
  14.392 +                sb.append(location);
  14.393 +                sb.append(")");
  14.394 +            }
  14.395 +
  14.396 +            sb.append(", pos = ");
  14.397 +            sb.append(pos);
  14.398 +
  14.399 +            sb.append(']');
  14.400 +            return sb.toString();
  14.401 +        }
  14.402 +    }
  14.403 +
  14.404 +    // Code duplicated from com.sun.tools.javac.comp.TargetType
  14.405 +    public enum TargetType {
  14.406 +
  14.407 +        /** For annotations on typecasts. */
  14.408 +        TYPECAST(0x00),
  14.409 +
  14.410 +        /** For annotations on a type argument or nested array of a typecast. */
  14.411 +        TYPECAST_GENERIC_OR_ARRAY(0x01, HasLocation),
  14.412 +
  14.413 +        /** For annotations on type tests. */
  14.414 +        INSTANCEOF(0x02),
  14.415 +
  14.416 +        /** For annotations on a type argument or nested array of a type test. */
  14.417 +        INSTANCEOF_GENERIC_OR_ARRAY(0x03, HasLocation),
  14.418 +
  14.419 +        /** For annotations on object creation expressions. */
  14.420 +        NEW(0x04),
  14.421 +
  14.422 +        /**
  14.423 +         * For annotations on a type argument or nested array of an object creation
  14.424 +         * expression.
  14.425 +         */
  14.426 +        NEW_GENERIC_OR_ARRAY(0x05, HasLocation),
  14.427 +
  14.428 +
  14.429 +        /** For annotations on the method receiver. */
  14.430 +        METHOD_RECEIVER(0x06),
  14.431 +
  14.432 +        // invalid location
  14.433 +        // METHOD_RECEIVER_GENERIC_OR_ARRAY(0x07, HasLocation),
  14.434 +
  14.435 +        /** For annotations on local variables. */
  14.436 +        LOCAL_VARIABLE(0x08),
  14.437 +
  14.438 +        /** For annotations on a type argument or nested array of a local. */
  14.439 +        LOCAL_VARIABLE_GENERIC_OR_ARRAY(0x09, HasLocation),
  14.440 +
  14.441 +        // already handled by regular annotations
  14.442 +        // METHOD_RETURN(0x0A),
  14.443 +
  14.444 +        /**
  14.445 +         * For annotations on a type argument or nested array of a method return
  14.446 +         * type.
  14.447 +         */
  14.448 +        METHOD_RETURN_GENERIC_OR_ARRAY(0x0B, HasLocation),
  14.449 +
  14.450 +        // already handled by regular annotations
  14.451 +        // METHOD_PARAMETER(0x0C),
  14.452 +
  14.453 +        /** For annotations on a type argument or nested array of a method parameter. */
  14.454 +        METHOD_PARAMETER_GENERIC_OR_ARRAY(0x0D, HasLocation),
  14.455 +
  14.456 +        // already handled by regular annotations
  14.457 +        // FIELD(0x0E),
  14.458 +
  14.459 +        /** For annotations on a type argument or nested array of a field. */
  14.460 +        FIELD_GENERIC_OR_ARRAY(0x0F, HasLocation),
  14.461 +
  14.462 +        /** For annotations on a bound of a type parameter of a class. */
  14.463 +        CLASS_TYPE_PARAMETER_BOUND(0x10, HasBound, HasParameter),
  14.464 +
  14.465 +        /**
  14.466 +         * For annotations on a type argument or nested array of a bound of a type
  14.467 +         * parameter of a class.
  14.468 +         */
  14.469 +        CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x11, HasBound, HasLocation, HasParameter),
  14.470 +
  14.471 +        /** For annotations on a bound of a type parameter of a method. */
  14.472 +        METHOD_TYPE_PARAMETER_BOUND(0x12, HasBound, HasParameter),
  14.473 +
  14.474 +        /**
  14.475 +         * For annotations on a type argument or nested array of a bound of a type
  14.476 +         * parameter of a method.
  14.477 +         */
  14.478 +        METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x13, HasBound, HasLocation, HasParameter),
  14.479 +
  14.480 +        /** For annotations on the type of an "extends" or "implements" clause. */
  14.481 +        CLASS_EXTENDS(0x14),
  14.482 +
  14.483 +        /** For annotations on the inner type of an "extends" or "implements" clause. */
  14.484 +        CLASS_EXTENDS_GENERIC_OR_ARRAY(0x15, HasLocation),
  14.485 +
  14.486 +        /** For annotations on a throws clause in a method declaration. */
  14.487 +        THROWS(0x16),
  14.488 +
  14.489 +        // invalid location
  14.490 +        // THROWS_GENERIC_OR_ARRAY(0x17, HasLocation),
  14.491 +
  14.492 +        /** For annotations in type arguments of object creation expressions. */
  14.493 +        NEW_TYPE_ARGUMENT(0x18),
  14.494 +        NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x19, HasLocation),
  14.495 +
  14.496 +        METHOD_TYPE_ARGUMENT(0x1A),
  14.497 +        METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x1B, HasLocation),
  14.498 +
  14.499 +        WILDCARD_BOUND(0x1C, HasBound),
  14.500 +        WILDCARD_BOUND_GENERIC_OR_ARRAY(0x1D, HasBound, HasLocation),
  14.501 +
  14.502 +        CLASS_LITERAL(0x1E),
  14.503 +        CLASS_LITERAL_GENERIC_OR_ARRAY(0x1F, HasLocation),
  14.504 +
  14.505 +        METHOD_TYPE_PARAMETER(0x20, HasParameter),
  14.506 +
  14.507 +        // invalid location
  14.508 +        // METHOD_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x21, HasLocation, HasParameter),
  14.509 +
  14.510 +        CLASS_TYPE_PARAMETER(0x22, HasParameter),
  14.511 +
  14.512 +        // invalid location
  14.513 +        // CLASS_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x23, HasLocation, HasParameter),
  14.514 +
  14.515 +        /** For annotations with an unknown target. */
  14.516 +        UNKNOWN(-1);
  14.517 +
  14.518 +        static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22;
  14.519 +
  14.520 +        private final int targetTypeValue;
  14.521 +        private Set<TargetAttribute> flags;
  14.522 +
  14.523 +        TargetType(int targetTypeValue, TargetAttribute... attrs) {
  14.524 +            if (targetTypeValue < Byte.MIN_VALUE
  14.525 +                || targetTypeValue > Byte.MAX_VALUE)
  14.526 +                throw new AssertionError("attribute type value needs to be a byte: " + targetTypeValue);
  14.527 +            this.targetTypeValue = (byte)targetTypeValue;
  14.528 +            this.flags = EnumSet.noneOf(TargetAttribute.class);
  14.529 +            for (TargetAttribute attr : attrs)
  14.530 +                this.flags.add(attr);
  14.531 +        }
  14.532 +
  14.533 +        /**
  14.534 +         * Returns whether or not this TargetType represents an annotation whose
  14.535 +         * target is an inner type of a generic or array type.
  14.536 +         *
  14.537 +         * @return true if this TargetType represents an annotation on an inner
  14.538 +         *         type, false otherwise
  14.539 +         */
  14.540 +        public boolean hasLocation() {
  14.541 +            return flags.contains(HasLocation);
  14.542 +        }
  14.543 +
  14.544 +        public TargetType getGenericComplement() {
  14.545 +            if (hasLocation())
  14.546 +                return this;
  14.547 +            else
  14.548 +                return fromTargetTypeValue(targetTypeValue() + 1);
  14.549 +        }
  14.550 +
  14.551 +        /**
  14.552 +         * Returns whether or not this TargetType represents an annotation whose
  14.553 +         * target has a parameter index.
  14.554 +         *
  14.555 +         * @return true if this TargetType has a parameter index,
  14.556 +         *         false otherwise
  14.557 +         */
  14.558 +        public boolean hasParameter() {
  14.559 +            return flags.contains(HasParameter);
  14.560 +        }
  14.561 +
  14.562 +        /**
  14.563 +         * Returns whether or not this TargetType represents an annotation whose
  14.564 +         * target is a type parameter bound.
  14.565 +         *
  14.566 +         * @return true if this TargetType represents an type parameter bound
  14.567 +         *         annotation, false otherwise
  14.568 +         */
  14.569 +        public boolean hasBound() {
  14.570 +            return flags.contains(HasBound);
  14.571 +        }
  14.572 +
  14.573 +        public int targetTypeValue() {
  14.574 +            return this.targetTypeValue;
  14.575 +        }
  14.576 +
  14.577 +        private static TargetType[] targets = null;
  14.578 +
  14.579 +        private static TargetType[] buildTargets() {
  14.580 +            TargetType[] targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
  14.581 +            TargetType[] alltargets = values();
  14.582 +            for (TargetType target : alltargets)
  14.583 +                if (target.targetTypeValue >= 0)
  14.584 +                    targets[target.targetTypeValue] = target;
  14.585 +            for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i)
  14.586 +                if (targets[i] == null)
  14.587 +                    targets[i] = UNKNOWN;
  14.588 +            return targets;
  14.589 +        }
  14.590 +
  14.591 +        public static boolean isValidTargetTypeValue(int tag) {
  14.592 +            if (targets == null)
  14.593 +                targets = buildTargets();
  14.594 +
  14.595 +            if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
  14.596 +                return true;
  14.597 +
  14.598 +            return (tag >= 0 && tag < targets.length);
  14.599 +        }
  14.600 +
  14.601 +        public static TargetType fromTargetTypeValue(int tag) {
  14.602 +            if (targets == null)
  14.603 +                targets = buildTargets();
  14.604 +
  14.605 +            if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
  14.606 +                return UNKNOWN;
  14.607 +
  14.608 +            if (tag < 0 || tag >= targets.length)
  14.609 +                throw new IllegalArgumentException("Unknown TargetType: " + tag);
  14.610 +            return targets[tag];
  14.611 +        }
  14.612 +    }
  14.613 +
  14.614 +    static enum TargetAttribute {
  14.615 +        HasLocation, HasParameter, HasBound;
  14.616 +    }
  14.617 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java	Sun Jun 28 00:01:09 2009 -0700
    15.3 @@ -0,0 +1,56 @@
    15.4 +/*
    15.5 + * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + *
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.  Sun designates this
   15.11 + * particular file as subject to the "Classpath" exception as provided
   15.12 + * by Sun in the LICENSE file that accompanied this code.
   15.13 + *
   15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.17 + * version 2 for more details (a copy is included in the LICENSE file that
   15.18 + * accompanied this code).
   15.19 + *
   15.20 + * You should have received a copy of the GNU General Public License version
   15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.23 + *
   15.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   15.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   15.26 + * have any questions.
   15.27 + */
   15.28 +
   15.29 +package com.sun.tools.classfile;
   15.30 +
   15.31 +import java.io.IOException;
   15.32 +
   15.33 +/**
   15.34 + * See JSR 308 specification, section 4.1
   15.35 + *
   15.36 + *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   15.37 + *  you write code that depends on this, you do so at your own risk.
   15.38 + *  This code and its internal interfaces are subject to change or
   15.39 + *  deletion without notice.</b>
   15.40 + */
   15.41 +public class RuntimeInvisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
   15.42 +    RuntimeInvisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
   15.43 +            throws IOException, Annotation.InvalidAnnotation {
   15.44 +        super(cr, name_index, length);
   15.45 +    }
   15.46 +
   15.47 +    public RuntimeInvisibleTypeAnnotations_attribute(ConstantPool cp, ExtendedAnnotation[] annotations)
   15.48 +            throws ConstantPoolException {
   15.49 +        this(cp.getUTF8Index(Attribute.RuntimeInvisibleTypeAnnotations), annotations);
   15.50 +    }
   15.51 +
   15.52 +    public RuntimeInvisibleTypeAnnotations_attribute(int name_index, ExtendedAnnotation[] annotations) {
   15.53 +        super(name_index, annotations);
   15.54 +    }
   15.55 +
   15.56 +    public <R, P> R accept(Visitor<R, P> visitor, P p) {
   15.57 +        return visitor.visitRuntimeInvisibleTypeAnnotations(this, p);
   15.58 +    }
   15.59 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java	Sun Jun 28 00:01:09 2009 -0700
    16.3 @@ -0,0 +1,61 @@
    16.4 +/*
    16.5 + * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + *
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.  Sun designates this
   16.11 + * particular file as subject to the "Classpath" exception as provided
   16.12 + * by Sun in the LICENSE file that accompanied this code.
   16.13 + *
   16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.17 + * version 2 for more details (a copy is included in the LICENSE file that
   16.18 + * accompanied this code).
   16.19 + *
   16.20 + * You should have received a copy of the GNU General Public License version
   16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.23 + *
   16.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   16.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   16.26 + * have any questions.
   16.27 + */
   16.28 +
   16.29 +package com.sun.tools.classfile;
   16.30 +
   16.31 +import java.io.IOException;
   16.32 +
   16.33 +/**
   16.34 + * See JSR 308 specification, section 4
   16.35 + *
   16.36 + *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   16.37 + *  you write code that depends on this, you do so at your own risk.
   16.38 + *  This code and its internal interfaces are subject to change or
   16.39 + *  deletion without notice.</b>
   16.40 + */
   16.41 +public abstract class RuntimeTypeAnnotations_attribute extends Attribute {
   16.42 +    protected RuntimeTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
   16.43 +            throws IOException, Annotation.InvalidAnnotation {
   16.44 +        super(name_index, length);
   16.45 +        int num_annotations = cr.readUnsignedShort();
   16.46 +        annotations = new ExtendedAnnotation[num_annotations];
   16.47 +        for (int i = 0; i < annotations.length; i++)
   16.48 +            annotations[i] = new ExtendedAnnotation(cr);
   16.49 +    }
   16.50 +
   16.51 +    protected RuntimeTypeAnnotations_attribute(int name_index, ExtendedAnnotation[] annotations) {
   16.52 +        super(name_index, length(annotations));
   16.53 +        this.annotations = annotations;
   16.54 +    }
   16.55 +
   16.56 +    private static int length(ExtendedAnnotation[] annos) {
   16.57 +        int n = 2;
   16.58 +        for (ExtendedAnnotation anno: annos)
   16.59 +            n += anno.length();
   16.60 +        return n;
   16.61 +    }
   16.62 +
   16.63 +    public final ExtendedAnnotation[] annotations;
   16.64 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java	Sun Jun 28 00:01:09 2009 -0700
    17.3 @@ -0,0 +1,56 @@
    17.4 +/*
    17.5 + * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.  Sun designates this
   17.11 + * particular file as subject to the "Classpath" exception as provided
   17.12 + * by Sun in the LICENSE file that accompanied this code.
   17.13 + *
   17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.17 + * version 2 for more details (a copy is included in the LICENSE file that
   17.18 + * accompanied this code).
   17.19 + *
   17.20 + * You should have received a copy of the GNU General Public License version
   17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.23 + *
   17.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   17.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   17.26 + * have any questions.
   17.27 + */
   17.28 +
   17.29 +package com.sun.tools.classfile;
   17.30 +
   17.31 +import java.io.IOException;
   17.32 +
   17.33 +/**
   17.34 + * See JSR 308 specification, section 4.1
   17.35 + *
   17.36 + *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   17.37 + *  you write code that depends on this, you do so at your own risk.
   17.38 + *  This code and its internal interfaces are subject to change or
   17.39 + *  deletion without notice.</b>
   17.40 + */
   17.41 +public class RuntimeVisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
   17.42 +    RuntimeVisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
   17.43 +            throws IOException, Annotation.InvalidAnnotation {
   17.44 +        super(cr, name_index, length);
   17.45 +    }
   17.46 +
   17.47 +    public RuntimeVisibleTypeAnnotations_attribute(ConstantPool cp, ExtendedAnnotation[] annotations)
   17.48 +            throws ConstantPoolException {
   17.49 +        this(cp.getUTF8Index(Attribute.RuntimeVisibleTypeAnnotations), annotations);
   17.50 +    }
   17.51 +
   17.52 +    public RuntimeVisibleTypeAnnotations_attribute(int name_index, ExtendedAnnotation[] annotations) {
   17.53 +        super(name_index, annotations);
   17.54 +    }
   17.55 +
   17.56 +    public <R, P> R accept(Visitor<R, P> visitor, P p) {
   17.57 +        return visitor.visitRuntimeVisibleTypeAnnotations(this, p);
   17.58 +    }
   17.59 +}
    18.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Fri Jun 26 10:26:27 2009 -0700
    18.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Sun Jun 28 00:01:09 2009 -0700
    18.3 @@ -133,6 +133,7 @@
    18.4      public Boolean call() {
    18.5          if (!used.getAndSet(true)) {
    18.6              beginContext();
    18.7 +            notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>();
    18.8              try {
    18.9                  compilerMain.setFatalErrors(true);
   18.10                  result = compilerMain.compile(args, context, fileObjects, processors);
   18.11 @@ -143,6 +144,7 @@
   18.12              args = null;
   18.13              context = null;
   18.14              fileObjects = null;
   18.15 +            notYetEntered = null;
   18.16              return result == 0;
   18.17          } else {
   18.18              throw new IllegalStateException("multiple calls to method 'call'");
    19.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Fri Jun 26 10:26:27 2009 -0700
    19.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Sun Jun 28 00:01:09 2009 -0700
    19.3 @@ -35,6 +35,7 @@
    19.4  import javax.lang.model.element.TypeElement;
    19.5  import javax.lang.model.type.DeclaredType;
    19.6  import javax.lang.model.type.TypeMirror;
    19.7 +import javax.tools.Diagnostic;
    19.8  import javax.tools.JavaCompiler;
    19.9  import javax.tools.JavaFileObject;
   19.10  
   19.11 @@ -54,6 +55,7 @@
   19.12  import com.sun.tools.javac.comp.MemberEnter;
   19.13  import com.sun.tools.javac.comp.Resolve;
   19.14  import com.sun.tools.javac.model.JavacElements;
   19.15 +import com.sun.tools.javac.processing.JavacMessager;
   19.16  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
   19.17  import com.sun.tools.javac.tree.JCTree.*;
   19.18  import com.sun.tools.javac.tree.JCTree;
   19.19 @@ -61,6 +63,7 @@
   19.20  import com.sun.tools.javac.tree.TreeInfo;
   19.21  import com.sun.tools.javac.tree.TreeMaker;
   19.22  import com.sun.tools.javac.util.Context;
   19.23 +import com.sun.tools.javac.util.JCDiagnostic;
   19.24  import com.sun.tools.javac.util.List;
   19.25  import com.sun.tools.javac.util.Log;
   19.26  import com.sun.tools.javac.util.Pair;
   19.27 @@ -336,4 +339,54 @@
   19.28  
   19.29          return com.sun.tools.javac.code.Type.noType;
   19.30      }
   19.31 +
   19.32 +    /**
   19.33 +     * Prints a message of the specified kind at the location of the
   19.34 +     * tree within the provided compilation unit
   19.35 +     *
   19.36 +     * @param kind the kind of message
   19.37 +     * @param msg  the message, or an empty string if none
   19.38 +     * @param t    the tree to use as a position hint
   19.39 +     * @param root the compilation unit that contains tree
   19.40 +     */
   19.41 +    public void printMessage(Diagnostic.Kind kind, CharSequence msg,
   19.42 +            com.sun.source.tree.Tree t,
   19.43 +            com.sun.source.tree.CompilationUnitTree root) {
   19.44 +        JavaFileObject oldSource = null;
   19.45 +        JavaFileObject newSource = null;
   19.46 +        JCDiagnostic.DiagnosticPosition pos = null;
   19.47 +
   19.48 +        newSource = root.getSourceFile();
   19.49 +        if (newSource != null) {
   19.50 +            oldSource = log.useSource(newSource);
   19.51 +            pos = ((JCTree) t).pos();
   19.52 +        }
   19.53 +
   19.54 +        try {
   19.55 +            switch (kind) {
   19.56 +            case ERROR:
   19.57 +                boolean prev = log.multipleErrors;
   19.58 +                try {
   19.59 +                    log.error(pos, "proc.messager", msg.toString());
   19.60 +                } finally {
   19.61 +                    log.multipleErrors = prev;
   19.62 +                }
   19.63 +                break;
   19.64 +
   19.65 +            case WARNING:
   19.66 +                log.warning(pos, "proc.messager", msg.toString());
   19.67 +                break;
   19.68 +
   19.69 +            case MANDATORY_WARNING:
   19.70 +                log.mandatoryWarning(pos, "proc.messager", msg.toString());
   19.71 +                break;
   19.72 +
   19.73 +            default:
   19.74 +                log.note(pos, "proc.messager", msg.toString());
   19.75 +            }
   19.76 +        } finally {
   19.77 +            if (oldSource != null)
   19.78 +                log.useSource(oldSource);
   19.79 +        }
   19.80 +    }
   19.81  }
    20.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java	Fri Jun 26 10:26:27 2009 -0700
    20.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java	Sun Jun 28 00:01:09 2009 -0700
    20.3 @@ -204,6 +204,21 @@
    20.4          }
    20.5      }
    20.6  
    20.7 +    public static class TypeCompound extends Compound {
    20.8 +        public TypeAnnotationPosition position;
    20.9 +        public TypeCompound(Compound compound,
   20.10 +                TypeAnnotationPosition position) {
   20.11 +            this(compound.type, compound.values, position);
   20.12 +        }
   20.13 +        public TypeCompound(Type type,
   20.14 +                List<Pair<MethodSymbol, Attribute>> values,
   20.15 +                TypeAnnotationPosition position) {
   20.16 +            super(type, values);
   20.17 +            this.position = position;
   20.18 +        }
   20.19 +
   20.20 +    }
   20.21 +
   20.22      /** The value for an annotation element of an array type.
   20.23       */
   20.24      public static class Array extends Attribute {
    21.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java	Fri Jun 26 10:26:27 2009 -0700
    21.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java	Sun Jun 28 00:01:09 2009 -0700
    21.3 @@ -153,6 +153,9 @@
    21.4      public boolean enforceMandatoryWarnings() {
    21.5          return compareTo(JDK1_5) >= 0;
    21.6      }
    21.7 +    public boolean allowTypeAnnotations() {
    21.8 +        return compareTo(JDK1_7) >= 0;
    21.9 +    }
   21.10      public static SourceVersion toSourceVersion(Source source) {
   21.11          switch(source) {
   21.12          case JDK1_2:
    22.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Jun 26 10:26:27 2009 -0700
    22.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Jun 28 00:01:09 2009 -0700
    22.3 @@ -100,6 +100,17 @@
    22.4       */
    22.5      public Type type;
    22.6  
    22.7 +    /** The type annotations targeted to a tree directly owned by this symbol
    22.8 +     */
    22.9 +    // type annotations are stored here for two purposes:
   22.10 +    //  - convenient location to store annotations for generation after erasure
   22.11 +    //  - a private interface for accessing type annotations parsed from
   22.12 +    //    classfiles
   22.13 +    //  the field is populated for the following declaration only
   22.14 +    //  class, field, variable and type parameters
   22.15 +    //
   22.16 +    public List<Attribute.TypeCompound> typeAnnotations;
   22.17 +
   22.18      /** The owner of this symbol.
   22.19       */
   22.20      public Symbol owner;
   22.21 @@ -122,6 +133,7 @@
   22.22          this.completer = null;
   22.23          this.erasure_field = null;
   22.24          this.attributes_field = List.nil();
   22.25 +        this.typeAnnotations = List.nil();
   22.26          this.name = name;
   22.27      }
   22.28  
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/share/classes/com/sun/tools/javac/code/TargetType.java	Sun Jun 28 00:01:09 2009 -0700
    23.3 @@ -0,0 +1,277 @@
    23.4 +/*
    23.5 + * Copyright 2008-2009 Sun Microsystems, Inc.  All Rights Reserved.
    23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 + *
    23.8 + * This code is free software; you can redistribute it and/or modify it
    23.9 + * under the terms of the GNU General Public License version 2 only, as
   23.10 + * published by the Free Software Foundation.  Sun designates this
   23.11 + * particular file as subject to the "Classpath" exception as provided
   23.12 + * by Sun in the LICENSE file that accompanied this code.
   23.13 + *
   23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.17 + * version 2 for more details (a copy is included in the LICENSE file that
   23.18 + * accompanied this code).
   23.19 + *
   23.20 + * You should have received a copy of the GNU General Public License version
   23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.23 + *
   23.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   23.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   23.26 + * have any questions.
   23.27 + */
   23.28 +
   23.29 +package com.sun.tools.javac.code;
   23.30 +
   23.31 +import static com.sun.tools.javac.code.TargetType.TargetAttribute.*;
   23.32 +
   23.33 +import java.util.EnumSet;
   23.34 +import java.util.Set;
   23.35 +
   23.36 +/**
   23.37 + * Describes the type of program element an extended annotation (or extended
   23.38 + * compound attribute) targets.
   23.39 + *
   23.40 + * By comparison, a Tree.Kind has enum values for all elements in the AST, and
   23.41 + * it does not provide enough resolution for type arguments (i.e., whether an
   23.42 + * annotation targets a type argument in a local variable, method return type,
   23.43 + * or a typecast).
   23.44 + *
   23.45 + *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   23.46 + *  you write code that depends on this, you do so at your own risk.
   23.47 + *  This code and its internal interfaces are subject to change or
   23.48 + *  deletion without notice.</b>
   23.49 + */
   23.50 +public enum TargetType {
   23.51 +
   23.52 +    //
   23.53 +    // Some target types are commented out, because Java doesn't permit such
   23.54 +    // targets.  They are included here to confirm that their omission is
   23.55 +    // intentional omission not an accidental omission.
   23.56 +    //
   23.57 +
   23.58 +    /** For annotations on typecasts. */
   23.59 +    TYPECAST(0x00, IsLocal),
   23.60 +
   23.61 +    /** For annotations on a type argument or nested array of a typecast. */
   23.62 +    TYPECAST_GENERIC_OR_ARRAY(0x01, HasLocation, IsLocal),
   23.63 +
   23.64 +    /** For annotations on type tests. */
   23.65 +    INSTANCEOF(0x02, IsLocal),
   23.66 +
   23.67 +    /** For annotations on a type argument or nested array of a type test. */
   23.68 +    INSTANCEOF_GENERIC_OR_ARRAY(0x03, HasLocation, IsLocal),
   23.69 +
   23.70 +    /** For annotations on object creation expressions. */
   23.71 +    NEW(0x04, IsLocal),
   23.72 +
   23.73 +    /**
   23.74 +     * For annotations on a type argument or nested array of an object creation
   23.75 +     * expression.
   23.76 +     */
   23.77 +    NEW_GENERIC_OR_ARRAY(0x05, HasLocation, IsLocal),
   23.78 +
   23.79 +
   23.80 +    /** For annotations on the method receiver. */
   23.81 +    METHOD_RECEIVER(0x06),
   23.82 +
   23.83 +    // invalid location
   23.84 +    //@Deprecated METHOD_RECEIVER_GENERIC_OR_ARRAY(0x07, HasLocation),
   23.85 +
   23.86 +    /** For annotations on local variables. */
   23.87 +    LOCAL_VARIABLE(0x08, IsLocal),
   23.88 +
   23.89 +    /** For annotations on a type argument or nested array of a local. */
   23.90 +    LOCAL_VARIABLE_GENERIC_OR_ARRAY(0x09, HasLocation, IsLocal),
   23.91 +
   23.92 +    // handled by regular annotations
   23.93 +    //@Deprecated METHOD_RETURN(0x0A),
   23.94 +
   23.95 +    /**
   23.96 +     * For annotations on a type argument or nested array of a method return
   23.97 +     * type.
   23.98 +     */
   23.99 +    METHOD_RETURN_GENERIC_OR_ARRAY(0x0B, HasLocation),
  23.100 +
  23.101 +    // handled by regular annotations
  23.102 +    //@Deprecated METHOD_PARAMETER(0x0C),
  23.103 +
  23.104 +    /** For annotations on a type argument or nested array of a method parameter. */
  23.105 +    METHOD_PARAMETER_GENERIC_OR_ARRAY(0x0D, HasLocation),
  23.106 +
  23.107 +    // handled by regular annotations
  23.108 +    //@Deprecated FIELD(0x0E),
  23.109 +
  23.110 +    /** For annotations on a type argument or nested array of a field. */
  23.111 +    FIELD_GENERIC_OR_ARRAY(0x0F, HasLocation),
  23.112 +
  23.113 +    /** For annotations on a bound of a type parameter of a class. */
  23.114 +    CLASS_TYPE_PARAMETER_BOUND(0x10, HasBound, HasParameter),
  23.115 +
  23.116 +    /**
  23.117 +     * For annotations on a type argument or nested array of a bound of a type
  23.118 +     * parameter of a class.
  23.119 +     */
  23.120 +    CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x11, HasBound, HasLocation, HasParameter),
  23.121 +
  23.122 +    /** For annotations on a bound of a type parameter of a method. */
  23.123 +    METHOD_TYPE_PARAMETER_BOUND(0x12, HasBound, HasParameter),
  23.124 +
  23.125 +    /**
  23.126 +     * For annotations on a type argument or nested array of a bound of a type
  23.127 +     * parameter of a method.
  23.128 +     */
  23.129 +    METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY(0x13, HasBound, HasLocation, HasParameter),
  23.130 +
  23.131 +    /** For annotations on the type of an "extends" or "implements" clause. */
  23.132 +    CLASS_EXTENDS(0x14),
  23.133 +
  23.134 +    /** For annotations on the inner type of an "extends" or "implements" clause. */
  23.135 +    CLASS_EXTENDS_GENERIC_OR_ARRAY(0x15, HasLocation),
  23.136 +
  23.137 +    /** For annotations on a throws clause in a method declaration. */
  23.138 +    THROWS(0x16),
  23.139 +
  23.140 +    // invalid location
  23.141 +    //@Deprecated THROWS_GENERIC_OR_ARRAY(0x17, HasLocation),
  23.142 +
  23.143 +    /** For annotations in type arguments of object creation expressions. */
  23.144 +    NEW_TYPE_ARGUMENT(0x18, IsLocal),
  23.145 +    NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x19, HasLocation, IsLocal),
  23.146 +
  23.147 +    METHOD_TYPE_ARGUMENT(0x1A, IsLocal),
  23.148 +    METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x1B, HasLocation, IsLocal),
  23.149 +
  23.150 +    WILDCARD_BOUND(0x1C, HasBound),
  23.151 +    WILDCARD_BOUND_GENERIC_OR_ARRAY(0x1D, HasBound, HasLocation),
  23.152 +
  23.153 +    CLASS_LITERAL(0x1E, IsLocal),
  23.154 +    CLASS_LITERAL_GENERIC_OR_ARRAY(0x1F, HasLocation, IsLocal),
  23.155 +
  23.156 +    METHOD_TYPE_PARAMETER(0x20, HasParameter),
  23.157 +
  23.158 +    // invalid location
  23.159 +    //@Deprecated METHOD_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x21, HasLocation, HasParameter),
  23.160 +
  23.161 +    CLASS_TYPE_PARAMETER(0x22, HasParameter),
  23.162 +
  23.163 +    // invalid location
  23.164 +    //@Deprecated CLASS_TYPE_PARAMETER_GENERIC_OR_ARRAY(0x23, HasLocation, HasParameter),
  23.165 +
  23.166 +    /** For annotations with an unknown target. */
  23.167 +    UNKNOWN(-1);
  23.168 +
  23.169 +    static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22;
  23.170 +
  23.171 +    private final int targetTypeValue;
  23.172 +    private Set<TargetAttribute> flags;
  23.173 +
  23.174 +    TargetType(int targetTypeValue, TargetAttribute... attributes) {
  23.175 +        if (targetTypeValue < Byte.MIN_VALUE
  23.176 +                || targetTypeValue > Byte.MAX_VALUE)
  23.177 +                throw new AssertionError("attribute type value needs to be a byte: " + targetTypeValue);
  23.178 +        this.targetTypeValue = (byte)targetTypeValue;
  23.179 +        flags = EnumSet.noneOf(TargetAttribute.class);
  23.180 +        for (TargetAttribute attr : attributes)
  23.181 +            flags.add(attr);
  23.182 +    }
  23.183 +
  23.184 +    /**
  23.185 +     * Returns whether or not this TargetType represents an annotation whose
  23.186 +     * target is an inner type of a generic or array type.
  23.187 +     *
  23.188 +     * @return true if this TargetType represents an annotation on an inner
  23.189 +     *         type, false otherwise
  23.190 +     */
  23.191 +    public boolean hasLocation() {
  23.192 +        return flags.contains(HasLocation);
  23.193 +    }
  23.194 +
  23.195 +    public TargetType getGenericComplement() {
  23.196 +        if (hasLocation())
  23.197 +            return this;
  23.198 +        else
  23.199 +            return fromTargetTypeValue(targetTypeValue() + 1);
  23.200 +    }
  23.201 +
  23.202 +    /**
  23.203 +     * Returns whether or not this TargetType represents an annotation whose
  23.204 +     * target has a parameter index.
  23.205 +     *
  23.206 +     * @return true if this TargetType has a parameter index,
  23.207 +     *         false otherwise
  23.208 +     */
  23.209 +    public boolean hasParameter() {
  23.210 +        return flags.contains(HasParameter);
  23.211 +    }
  23.212 +
  23.213 +    /**
  23.214 +     * Returns whether or not this TargetType represents an annotation whose
  23.215 +     * target is a type parameter bound.
  23.216 +     *
  23.217 +     * @return true if this TargetType represents an type parameter bound
  23.218 +     *         annotation, false otherwise
  23.219 +     */
  23.220 +    public boolean hasBound() {
  23.221 +        return flags.contains(HasBound);
  23.222 +    }
  23.223 +
  23.224 +    /**
  23.225 +     * Returns whether or not this TargetType represents an annotation whose
  23.226 +     * target is exclusively a tree in a method body
  23.227 +     *
  23.228 +     * Note: wildcard bound targets could target a local tree and a class
  23.229 +     * member declaration signature tree
  23.230 +     */
  23.231 +    public boolean isLocal() {
  23.232 +        return flags.contains(IsLocal);
  23.233 +    }
  23.234 +
  23.235 +    public int targetTypeValue() {
  23.236 +        return this.targetTypeValue;
  23.237 +    }
  23.238 +
  23.239 +    private static TargetType[] targets = null;
  23.240 +
  23.241 +    private static TargetType[] buildTargets() {
  23.242 +        TargetType[] targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
  23.243 +        TargetType[] alltargets = values();
  23.244 +        for (TargetType target : alltargets) {
  23.245 +            if (target.targetTypeValue >= 0)
  23.246 +                targets[target.targetTypeValue] = target;
  23.247 +        }
  23.248 +        for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) {
  23.249 +            if (targets[i] == null)
  23.250 +                targets[i] = UNKNOWN;
  23.251 +        }
  23.252 +        return targets;
  23.253 +    }
  23.254 +
  23.255 +    public static boolean isValidTargetTypeValue(int tag) {
  23.256 +        if (targets == null)
  23.257 +            targets = buildTargets();
  23.258 +
  23.259 +        if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
  23.260 +            return true;
  23.261 +
  23.262 +        return (tag >= 0 && tag < targets.length);
  23.263 +    }
  23.264 +
  23.265 +    public static TargetType fromTargetTypeValue(int tag) {
  23.266 +        if (targets == null)
  23.267 +            targets = buildTargets();
  23.268 +
  23.269 +        if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
  23.270 +            return UNKNOWN;
  23.271 +
  23.272 +        if (tag < 0 || tag >= targets.length)
  23.273 +            throw new IllegalArgumentException("Unknown TargetType: " + tag);
  23.274 +        return targets[tag];
  23.275 +    }
  23.276 +
  23.277 +    static enum TargetAttribute {
  23.278 +        HasLocation, HasParameter, HasBound, IsLocal;
  23.279 +    }
  23.280 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Sun Jun 28 00:01:09 2009 -0700
    24.3 @@ -0,0 +1,194 @@
    24.4 +/*
    24.5 + * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
    24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    24.7 + *
    24.8 + * This code is free software; you can redistribute it and/or modify it
    24.9 + * under the terms of the GNU General Public License version 2 only, as
   24.10 + * published by the Free Software Foundation.  Sun designates this
   24.11 + * particular file as subject to the "Classpath" exception as provided
   24.12 + * by Sun in the LICENSE file that accompanied this code.
   24.13 + *
   24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   24.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   24.17 + * version 2 for more details (a copy is included in the LICENSE file that
   24.18 + * accompanied this code).
   24.19 + *
   24.20 + * You should have received a copy of the GNU General Public License version
   24.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   24.23 + *
   24.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   24.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
   24.26 + * have any questions.
   24.27 + */
   24.28 +
   24.29 +package com.sun.tools.javac.code;
   24.30 +
   24.31 +import com.sun.tools.javac.util.*;
   24.32 +
   24.33 +/** A type annotation position.
   24.34 +*
   24.35 +*  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
   24.36 +*  you write code that depends on this, you do so at your own risk.
   24.37 +*  This code and its internal interfaces are subject to change or
   24.38 +*  deletion without notice.</b>
   24.39 +*/
   24.40 +public class TypeAnnotationPosition {
   24.41 +
   24.42 +    public TargetType type = TargetType.UNKNOWN;
   24.43 +
   24.44 +    // For generic/array types.
   24.45 +    public List<Integer> location = List.nil();
   24.46 +
   24.47 +    // Tree position.
   24.48 +    public int pos = -1;
   24.49 +
   24.50 +    // For typecasts, type tests, new (and locals, as start_pc).
   24.51 +    public boolean isValidOffset = false;
   24.52 +    public int offset = -1;
   24.53 +
   24.54 +    // For locals. arrays same length
   24.55 +    public int[] lvarOffset = new int[] { -1 };
   24.56 +    public int[] lvarLength = new int[] { -1 };
   24.57 +    public int[] lvarIndex = new int[] { -1 };
   24.58 +
   24.59 +    // For type parameter bound
   24.60 +    public int bound_index = -1;
   24.61 +
   24.62 +    // For type parameter and method parameter
   24.63 +    public int parameter_index = -1;
   24.64 +
   24.65 +    // For class extends, implements, and throws classes
   24.66 +    public int type_index = -2;
   24.67 +
   24.68 +    // For wildcards
   24.69 +    public TypeAnnotationPosition wildcard_position = null;
   24.70 +
   24.71 +    @Override
   24.72 +    public String toString() {
   24.73 +        StringBuilder sb = new StringBuilder();
   24.74 +        sb.append('[');
   24.75 +        sb.append(type);
   24.76 +
   24.77 +        switch (type) {
   24.78 +        // type case
   24.79 +        case TYPECAST:
   24.80 +        case TYPECAST_GENERIC_OR_ARRAY:
   24.81 +            // object creation
   24.82 +        case INSTANCEOF:
   24.83 +        case INSTANCEOF_GENERIC_OR_ARRAY:
   24.84 +            // new expression
   24.85 +        case NEW:
   24.86 +        case NEW_GENERIC_OR_ARRAY:
   24.87 +        case NEW_TYPE_ARGUMENT:
   24.88 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
   24.89 +            sb.append(", offset = ");
   24.90 +            sb.append(offset);
   24.91 +            break;
   24.92 +            // local variable
   24.93 +        case LOCAL_VARIABLE:
   24.94 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
   24.95 +            sb.append(", {");
   24.96 +            for (int i = 0; i < lvarOffset.length; ++i) {
   24.97 +                if (i != 0) sb.append("; ");
   24.98 +                sb.append(", start_pc = ");
   24.99 +                sb.append(lvarOffset[i]);
  24.100 +                sb.append(", length = ");
  24.101 +                sb.append(lvarLength[i]);
  24.102 +                sb.append(", index = ");
  24.103 +                sb.append(lvarIndex[i]);
  24.104 +            }
  24.105 +            sb.append("}");
  24.106 +            break;
  24.107 +            // method receiver
  24.108 +        case METHOD_RECEIVER:
  24.109 +            // Do nothing
  24.110 +            break;
  24.111 +            // type parameters
  24.112 +        case CLASS_TYPE_PARAMETER:
  24.113 +        case METHOD_TYPE_PARAMETER:
  24.114 +            sb.append(", param_index = ");
  24.115 +            sb.append(parameter_index);
  24.116 +            break;
  24.117 +            // type parameters bound
  24.118 +        case CLASS_TYPE_PARAMETER_BOUND:
  24.119 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  24.120 +        case METHOD_TYPE_PARAMETER_BOUND:
  24.121 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  24.122 +            sb.append(", param_index = ");
  24.123 +            sb.append(parameter_index);
  24.124 +            sb.append(", bound_index = ");
  24.125 +            sb.append(bound_index);
  24.126 +            break;
  24.127 +            // wildcard
  24.128 +        case WILDCARD_BOUND:
  24.129 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  24.130 +            sb.append(", wild_card = ");
  24.131 +            sb.append(wildcard_position);
  24.132 +            break;
  24.133 +            // Class extends and implements clauses
  24.134 +        case CLASS_EXTENDS:
  24.135 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  24.136 +            sb.append(", type_index = ");
  24.137 +            sb.append(type_index);
  24.138 +            break;
  24.139 +            // throws
  24.140 +        case THROWS:
  24.141 +            sb.append(", type_index = ");
  24.142 +            sb.append(type_index);
  24.143 +            break;
  24.144 +        case CLASS_LITERAL:
  24.145 +            sb.append(", offset = ");
  24.146 +            sb.append(offset);
  24.147 +            break;
  24.148 +            // method parameter: not specified
  24.149 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  24.150 +            sb.append(", param_index = ");
  24.151 +            sb.append(parameter_index);
  24.152 +            break;
  24.153 +            // method type argument: wasn't specified
  24.154 +        case METHOD_TYPE_ARGUMENT:
  24.155 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  24.156 +            sb.append(", offset = ");
  24.157 +            sb.append(offset);
  24.158 +            sb.append(", type_index = ");
  24.159 +            sb.append(type_index);
  24.160 +            break;
  24.161 +            // We don't need to worry abut these
  24.162 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
  24.163 +        case FIELD_GENERIC_OR_ARRAY:
  24.164 +            break;
  24.165 +        case UNKNOWN:
  24.166 +            break;
  24.167 +        default:
  24.168 +            //                throw new AssertionError("unknown type: " + type);
  24.169 +        }
  24.170 +
  24.171 +        // Append location data for generics/arrays.
  24.172 +        if (type.hasLocation()) {
  24.173 +            sb.append(", location = (");
  24.174 +            sb.append(location);
  24.175 +            sb.append(")");
  24.176 +        }
  24.177 +
  24.178 +        sb.append(", pos = ");
  24.179 +        sb.append(pos);
  24.180 +
  24.181 +        sb.append(']');
  24.182 +        return sb.toString();
  24.183 +    }
  24.184 +
  24.185 +    /**
  24.186 +     * Indicates whether the target tree of the annotation has been optimized
  24.187 +     * away from classfile or not.
  24.188 +     * @return true if the target has not been optimized away
  24.189 +     */
  24.190 +    public boolean emitToClassfile() {
  24.191 +        if (type == TargetType.WILDCARD_BOUND
  24.192 +            || type == TargetType.WILDCARD_BOUND_GENERIC_OR_ARRAY)
  24.193 +            return wildcard_position.isValidOffset;
  24.194 +        else
  24.195 +            return !type.isLocal() || isValidOffset;
  24.196 +    }
  24.197 +}
    25.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jun 26 10:26:27 2009 -0700
    25.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Jun 28 00:01:09 2009 -0700
    25.3 @@ -700,7 +700,6 @@
    25.4              localEnv.info.scope.leave();
    25.5              result = tree.type = m.type;
    25.6              chk.validateAnnotations(tree.mods.annotations, m);
    25.7 -
    25.8          }
    25.9          finally {
   25.10              chk.setLint(prevLint);
   25.11 @@ -2516,10 +2515,11 @@
   25.12                  Type clazzOuter = clazztype.getEnclosingType();
   25.13                  if (clazzOuter.tag == CLASS) {
   25.14                      Type site;
   25.15 -                    if (tree.clazz.getTag() == JCTree.IDENT) {
   25.16 +                    JCExpression clazz = TreeInfo.typeIn(tree.clazz);
   25.17 +                    if (clazz.getTag() == JCTree.IDENT) {
   25.18                          site = env.enclClass.sym.type;
   25.19 -                    } else if (tree.clazz.getTag() == JCTree.SELECT) {
   25.20 -                        site = ((JCFieldAccess) tree.clazz).selected.type;
   25.21 +                    } else if (clazz.getTag() == JCTree.SELECT) {
   25.22 +                        site = ((JCFieldAccess) clazz).selected.type;
   25.23                      } else throw new AssertionError(""+tree);
   25.24                      if (clazzOuter.tag == CLASS && site != clazzOuter) {
   25.25                          if (site.tag == CLASS)
   25.26 @@ -2628,6 +2628,10 @@
   25.27          result = tree.type = syms.errType;
   25.28      }
   25.29  
   25.30 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   25.31 +        result = tree.type = attribType(tree.getUnderlyingType(), env);
   25.32 +    }
   25.33 +
   25.34      public void visitErroneous(JCErroneous tree) {
   25.35          if (tree.errs != null)
   25.36              for (JCTree err : tree.errs)
   25.37 @@ -2816,6 +2820,9 @@
   25.38              (c.flags() & ABSTRACT) == 0) {
   25.39              checkSerialVersionUID(tree, c);
   25.40          }
   25.41 +
   25.42 +        // Check type annotations applicability rules
   25.43 +        validateTypeAnnotations(tree);
   25.44      }
   25.45          // where
   25.46          /** check if a class is a subtype of Serializable, if that is available. */
   25.47 @@ -2858,4 +2865,33 @@
   25.48      private Type capture(Type type) {
   25.49          return types.capture(type);
   25.50      }
   25.51 +
   25.52 +    private void validateTypeAnnotations(JCTree tree) {
   25.53 +        tree.accept(typeAnnotationsValidator);
   25.54 +    }
   25.55 +    //where
   25.56 +    private final JCTree.Visitor typeAnnotationsValidator =
   25.57 +        new TreeScanner() {
   25.58 +        public void visitAnnotation(JCAnnotation tree) {
   25.59 +            if (tree instanceof JCTypeAnnotation) {
   25.60 +                chk.validateTypeAnnotation((JCTypeAnnotation)tree, false);
   25.61 +            }
   25.62 +            super.visitAnnotation(tree);
   25.63 +        }
   25.64 +        public void visitTypeParameter(JCTypeParameter tree) {
   25.65 +            chk.validateTypeAnnotations(tree.annotations, true);
   25.66 +            // don't call super. skip type annotations
   25.67 +            scan(tree.bounds);
   25.68 +        }
   25.69 +        public void visitMethodDef(JCMethodDecl tree) {
   25.70 +            // need to check static methods
   25.71 +            if ((tree.sym.flags() & Flags.STATIC) != 0) {
   25.72 +                for (JCTypeAnnotation a : tree.receiverAnnotations) {
   25.73 +                    if (chk.isTypeAnnotation(a, false))
   25.74 +                        log.error(a.pos(), "annotation.type.not.applicable");
   25.75 +                }
   25.76 +            }
   25.77 +            super.visitMethodDef(tree);
   25.78 +        }
   25.79 +    };
   25.80  }
    26.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 26 10:26:27 2009 -0700
    26.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Sun Jun 28 00:01:09 2009 -0700
    26.3 @@ -916,6 +916,10 @@
    26.4              }
    26.5          }
    26.6  
    26.7 +        public void visitAnnotatedType(JCAnnotatedType tree) {
    26.8 +            tree.underlyingType.accept(this);
    26.9 +        }
   26.10 +
   26.11          /** Default visitor method: do nothing.
   26.12           */
   26.13          public void visitTree(JCTree tree) {
   26.14 @@ -1806,6 +1810,14 @@
   26.15              validateAnnotation(a, s);
   26.16      }
   26.17  
   26.18 +    /** Check the type annotations
   26.19 +     */
   26.20 +    public void validateTypeAnnotations(List<JCTypeAnnotation> annotations, boolean isTypeParameter) {
   26.21 +        if (skipAnnotations) return;
   26.22 +        for (JCTypeAnnotation a : annotations)
   26.23 +            validateTypeAnnotation(a, isTypeParameter);
   26.24 +    }
   26.25 +
   26.26      /** Check an annotation of a symbol.
   26.27       */
   26.28      public void validateAnnotation(JCAnnotation a, Symbol s) {
   26.29 @@ -1820,6 +1832,15 @@
   26.30          }
   26.31      }
   26.32  
   26.33 +    public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
   26.34 +        if (a.type == null)
   26.35 +            throw new AssertionError("annotation tree hasn't been attributed yet: " + a);
   26.36 +        validateAnnotation(a);
   26.37 +
   26.38 +        if (!isTypeAnnotation(a, isTypeParameter))
   26.39 +            log.error(a.pos(), "annotation.type.not.applicable");
   26.40 +    }
   26.41 +
   26.42      /** Is s a method symbol that overrides a method in a superclass? */
   26.43      boolean isOverrider(Symbol s) {
   26.44          if (s.kind != MTH || s.isStatic())
   26.45 @@ -1838,6 +1859,25 @@
   26.46          return false;
   26.47      }
   26.48  
   26.49 +    /** Is the annotation applicable to type annotations */
   26.50 +    boolean isTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
   26.51 +        Attribute.Compound atTarget =
   26.52 +            a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym);
   26.53 +        if (atTarget == null) return true;
   26.54 +        Attribute atValue = atTarget.member(names.value);
   26.55 +        if (!(atValue instanceof Attribute.Array)) return true; // error recovery
   26.56 +        Attribute.Array arr = (Attribute.Array) atValue;
   26.57 +        for (Attribute app : arr.values) {
   26.58 +            if (!(app instanceof Attribute.Enum)) return true; // recovery
   26.59 +            Attribute.Enum e = (Attribute.Enum) app;
   26.60 +            if (!isTypeParameter && e.value.name == names.TYPE_USE)
   26.61 +                return true;
   26.62 +            else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER)
   26.63 +                return true;
   26.64 +        }
   26.65 +        return false;
   26.66 +    }
   26.67 +
   26.68      /** Is the annotation applicable to the symbol? */
   26.69      boolean annotationApplicable(JCAnnotation a, Symbol s) {
   26.70          Attribute.Compound atTarget =
   26.71 @@ -1874,6 +1914,13 @@
   26.72                  }
   26.73              else if (e.value.name == names.PACKAGE)
   26.74                  { if (s.kind == PCK) return true; }
   26.75 +            else if (e.value.name == names.TYPE_USE)
   26.76 +                { if (s.kind == TYP ||
   26.77 +                      s.kind == VAR ||
   26.78 +                      (s.kind == MTH && !s.isConstructor() &&
   26.79 +                       s.type.getReturnType().tag != VOID))
   26.80 +                    return true;
   26.81 +                }
   26.82              else
   26.83                  return true; // recovery
   26.84          }
    27.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Jun 26 10:26:27 2009 -0700
    27.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Sun Jun 28 00:01:09 2009 -0700
    27.3 @@ -1245,6 +1245,11 @@
    27.4          }
    27.5      }
    27.6  
    27.7 +    public void visitAnnotatedType(JCAnnotatedType tree) {
    27.8 +        // annotations don't get scanned
    27.9 +        tree.underlyingType.accept(this);
   27.10 +    }
   27.11 +
   27.12      public void visitIdent(JCIdent tree) {
   27.13          if (tree.sym.kind == VAR)
   27.14              checkInit(tree.pos(), (VarSymbol)tree.sym);
   27.15 @@ -1254,7 +1259,8 @@
   27.16          super.visitTypeCast(tree);
   27.17          if (!tree.type.isErroneous()
   27.18              && lint.isEnabled(Lint.LintCategory.CAST)
   27.19 -            && types.isSameType(tree.expr.type, tree.clazz.type)) {
   27.20 +            && types.isSameType(tree.expr.type, tree.clazz.type)
   27.21 +            && !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))) {
   27.22              log.warning(tree.pos(), "redundant.cast", tree.expr.type);
   27.23          }
   27.24      }
   27.25 @@ -1264,6 +1270,23 @@
   27.26      }
   27.27  
   27.28  /**************************************************************************
   27.29 + * utility methods for ignoring type-annotated casts lint checking
   27.30 + *************************************************************************/
   27.31 +    private static final boolean ignoreAnnotatedCasts = true;
   27.32 +    private static class AnnotationFinder extends TreeScanner {
   27.33 +        public boolean foundTypeAnno = false;
   27.34 +        public void visitAnnotation(JCAnnotation tree) {
   27.35 +            foundTypeAnno = foundTypeAnno || (tree instanceof JCTypeAnnotation);
   27.36 +        }
   27.37 +    }
   27.38 +
   27.39 +    private boolean containsTypeAnnotation(JCTree e) {
   27.40 +        AnnotationFinder finder = new AnnotationFinder();
   27.41 +        finder.scan(e);
   27.42 +        return finder.foundTypeAnno;
   27.43 +    }
   27.44 +
   27.45 +/**************************************************************************
   27.46   * main method
   27.47   *************************************************************************/
   27.48  
    28.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Jun 26 10:26:27 2009 -0700
    28.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Jun 28 00:01:09 2009 -0700
    28.3 @@ -1979,7 +1979,6 @@
    28.4              c.members_field = new Scope(c);
    28.5              c.flags_field = flags;
    28.6              c.attributes_field = tree.packge.attributes_field;
    28.7 -            tree.packge.attributes_field = List.nil();
    28.8              ClassType ctype = (ClassType) c.type;
    28.9              ctype.supertype_field = syms.objectType;
   28.10              ctype.interfaces_field = List.nil();
   28.11 @@ -2369,6 +2368,11 @@
   28.12          result = tree;
   28.13      }
   28.14  
   28.15 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   28.16 +        tree.underlyingType = translate(tree.underlyingType);
   28.17 +        result = tree.underlyingType;
   28.18 +    }
   28.19 +
   28.20      public void visitTypeCast(JCTypeCast tree) {
   28.21          tree.clazz = translate(tree.clazz);
   28.22          if (tree.type.isPrimitive() != tree.expr.type.isPrimitive())
    29.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Jun 26 10:26:27 2009 -0700
    29.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Sun Jun 28 00:01:09 2009 -0700
    29.3 @@ -99,8 +99,8 @@
    29.4          types = Types.instance(context);
    29.5          diags = JCDiagnostic.Factory.instance(context);
    29.6          target = Target.instance(context);
    29.7 -        skipAnnotations =
    29.8 -            Options.instance(context).get("skipAnnotations") != null;
    29.9 +        Options options = Options.instance(context);
   29.10 +        skipAnnotations = options.get("skipAnnotations") != null;
   29.11      }
   29.12  
   29.13      /** A queue for classes whose members still need to be entered into the
   29.14 @@ -906,6 +906,10 @@
   29.15              if (hasDeprecatedAnnotation(tree.mods.annotations))
   29.16                  c.flags_field |= DEPRECATED;
   29.17              annotateLater(tree.mods.annotations, baseEnv, c);
   29.18 +            // class type parameters use baseEnv but everything uses env
   29.19 +            for (JCTypeParameter tp : tree.typarams)
   29.20 +                tp.accept(new TypeAnnotate(baseEnv));
   29.21 +            tree.accept(new TypeAnnotate(env));
   29.22  
   29.23              chk.checkNonCyclic(tree.pos(), c.type);
   29.24  
   29.25 @@ -988,6 +992,100 @@
   29.26          }
   29.27      }
   29.28  
   29.29 +    // A sub-phase that "compiles" annotations in annotated types.
   29.30 +    private class TypeAnnotate extends TreeScanner {
   29.31 +        private Env<AttrContext> env;
   29.32 +        public TypeAnnotate(Env<AttrContext> env) { this.env = env; }
   29.33 +
   29.34 +        private void enterTypeAnnotations(List<JCTypeAnnotation> annotations) {
   29.35 +            Set<TypeSymbol> annotated = new HashSet<TypeSymbol>();
   29.36 +            if (!skipAnnotations)
   29.37 +                for (List<JCTypeAnnotation> al = annotations; al.nonEmpty(); al = al.tail) {
   29.38 +                    JCTypeAnnotation a = al.head;
   29.39 +                    Attribute.Compound c = annotate.enterAnnotation(a,
   29.40 +                            syms.annotationType,
   29.41 +                            env);
   29.42 +                    if (c == null) continue;
   29.43 +                    Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, a.annotation_position);
   29.44 +                    a.attribute_field = tc;
   29.45 +                    // Note: @Deprecated has no effect on local variables and parameters
   29.46 +                    if (!annotated.add(a.type.tsym))
   29.47 +                        log.error(a.pos, "duplicate.annotation");
   29.48 +                }
   29.49 +        }
   29.50 +
   29.51 +        // each class (including enclosed inner classes) should be visited
   29.52 +        // separately through MemberEnter.complete(Symbol)
   29.53 +        // this flag is used to prevent from visiting inner classes.
   29.54 +        private boolean isEnclosingClass = false;
   29.55 +        @Override
   29.56 +        public void visitClassDef(final JCClassDecl tree) {
   29.57 +            if (isEnclosingClass)
   29.58 +                return;
   29.59 +            isEnclosingClass = true;
   29.60 +            scan(tree.mods);
   29.61 +            // type parameter need to be visited with a separate env
   29.62 +            // scan(tree.typarams);
   29.63 +            scan(tree.extending);
   29.64 +            scan(tree.implementing);
   29.65 +            scan(tree.defs);
   29.66 +        }
   29.67 +
   29.68 +        private void annotate(final JCTree tree, final List<JCTypeAnnotation> annotations) {
   29.69 +            annotate.later(new Annotate.Annotator() {
   29.70 +                public String toString() {
   29.71 +                    return "annotate " + annotations + " onto " + tree;
   29.72 +                }
   29.73 +                public void enterAnnotation() {
   29.74 +                    JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
   29.75 +                    try {
   29.76 +                        enterTypeAnnotations(annotations);
   29.77 +
   29.78 +                        // enrich type parameter symbols... easier for annotation processors
   29.79 +                        if (tree instanceof JCTypeParameter) {
   29.80 +                            JCTypeParameter typeparam = (JCTypeParameter)tree;
   29.81 +                            ListBuffer<Attribute.Compound> buf = ListBuffer.lb();
   29.82 +                            for (JCTypeAnnotation anno : annotations)
   29.83 +                                buf.add(anno.attribute_field);
   29.84 +                            typeparam.type.tsym.attributes_field = buf.toList();
   29.85 +                        }
   29.86 +                    } finally {
   29.87 +                        log.useSource(prev);
   29.88 +                    }
   29.89 +                }
   29.90 +            });
   29.91 +        }
   29.92 +
   29.93 +        @Override
   29.94 +        public void visitAnnotatedType(final JCAnnotatedType tree) {
   29.95 +            annotate(tree, tree.annotations);
   29.96 +            super.visitAnnotatedType(tree);
   29.97 +        }
   29.98 +        @Override
   29.99 +        public void visitTypeParameter(final JCTypeParameter tree) {
  29.100 +            annotate(tree, tree.annotations);
  29.101 +            super.visitTypeParameter(tree);
  29.102 +        }
  29.103 +        @Override
  29.104 +        public void visitNewArray(final JCNewArray tree) {
  29.105 +            annotate(tree, tree.annotations);
  29.106 +            for (List<JCTypeAnnotation> dimAnnos : tree.dimAnnotations)
  29.107 +                annotate(tree, dimAnnos);
  29.108 +            super.visitNewArray(tree);
  29.109 +        }
  29.110 +        @Override
  29.111 +        public void visitApply(JCMethodInvocation tree) {
  29.112 +            super.visitApply(tree);
  29.113 +            scan(tree.typeargs);
  29.114 +        }
  29.115 +        @Override
  29.116 +        public void visitMethodDef(JCMethodDecl tree) {
  29.117 +            annotate(tree, tree.receiverAnnotations);
  29.118 +            super.visitMethodDef(tree);
  29.119 +        }
  29.120 +    }
  29.121 +
  29.122 +
  29.123      private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
  29.124          Scope typaramScope = new Scope(tree.sym);
  29.125          if (tree.typarams != null)
    30.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Fri Jun 26 10:26:27 2009 -0700
    30.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Sun Jun 28 00:01:09 2009 -0700
    30.3 @@ -27,6 +27,8 @@
    30.4  
    30.5  import java.util.*;
    30.6  
    30.7 +import javax.lang.model.element.ElementKind;
    30.8 +
    30.9  import com.sun.tools.javac.code.*;
   30.10  import com.sun.tools.javac.code.Symbol.*;
   30.11  import com.sun.tools.javac.tree.*;
   30.12 @@ -59,6 +61,8 @@
   30.13          return instance;
   30.14      }
   30.15  
   30.16 +    private boolean debugJSR308;
   30.17 +
   30.18      private Names names;
   30.19      private Log log;
   30.20      private Symtab syms;
   30.21 @@ -88,6 +92,7 @@
   30.22          types = Types.instance(context);
   30.23          make = TreeMaker.instance(context);
   30.24          resolve = Resolve.instance(context);
   30.25 +        debugJSR308 = Options.instance(context).get("TA:trans") != null;
   30.26      }
   30.27  
   30.28      /** A hashtable mapping bridge methods to the methods they override after
   30.29 @@ -435,12 +440,15 @@
   30.30      }
   30.31  
   30.32      public void visitClassDef(JCClassDecl tree) {
   30.33 +        new TypeAnnotationPositions().scan(tree);
   30.34 +        new TypeAnnotationLift().scan(tree);
   30.35          translateClass(tree.sym);
   30.36          result = tree;
   30.37      }
   30.38  
   30.39      JCMethodDecl currentMethod = null;
   30.40      public void visitMethodDef(JCMethodDecl tree) {
   30.41 +        tree.sym.typeAnnotations = tree.sym.typeAnnotations;
   30.42          JCMethodDecl previousMethod = currentMethod;
   30.43          try {
   30.44              currentMethod = tree;
   30.45 @@ -726,8 +734,8 @@
   30.46      /** Visitor method for parameterized types.
   30.47       */
   30.48      public void visitTypeApply(JCTypeApply tree) {
   30.49 -        // Delete all type parameters.
   30.50 -        result = translate(tree.clazz, null);
   30.51 +        JCTree clazz = translate(tree.clazz, null);
   30.52 +        result = clazz;
   30.53      }
   30.54  
   30.55  /**************************************************************************
   30.56 @@ -793,4 +801,342 @@
   30.57          pt = null;
   30.58          return translate(cdef, null);
   30.59      }
   30.60 +
   30.61 +    private class TypeAnnotationPositions extends TreeScanner {
   30.62 +
   30.63 +        private ListBuffer<JCTree> frames = ListBuffer.lb();
   30.64 +        private void push(JCTree t) { frames = frames.prepend(t); }
   30.65 +        private JCTree pop() { return frames.next(); }
   30.66 +        private JCTree peek() { return frames.first(); }
   30.67 +        private JCTree peek2() { return frames.toList().tail.head; }
   30.68 +
   30.69 +        @Override
   30.70 +        public void scan(JCTree tree) {
   30.71 +            push(tree);
   30.72 +            super.scan(tree);
   30.73 +            pop();
   30.74 +        }
   30.75 +
   30.76 +        private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame,
   30.77 +                List<JCTree> path, TypeAnnotationPosition p) {
   30.78 +            switch (frame.getKind()) {
   30.79 +                case TYPE_CAST:
   30.80 +                    p.type = TargetType.TYPECAST;
   30.81 +                    p.pos = frame.pos;
   30.82 +                    return p;
   30.83 +
   30.84 +                case INSTANCE_OF:
   30.85 +                    p.type = TargetType.INSTANCEOF;
   30.86 +                    p.pos = frame.pos;
   30.87 +                    return p;
   30.88 +
   30.89 +                case NEW_CLASS:
   30.90 +                    p.type = TargetType.NEW;
   30.91 +                    p.pos = frame.pos;
   30.92 +                    return p;
   30.93 +
   30.94 +                case NEW_ARRAY:
   30.95 +                    p.type = TargetType.NEW;
   30.96 +                    p.pos = frame.pos;
   30.97 +                    return p;
   30.98 +
   30.99 +                case CLASS:
  30.100 +                    p.pos = frame.pos;
  30.101 +                    if (((JCClassDecl)frame).extending == tree) {
  30.102 +                        p.type = TargetType.CLASS_EXTENDS;
  30.103 +                        p.type_index = -1;
  30.104 +                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
  30.105 +                        p.type = TargetType.CLASS_EXTENDS;
  30.106 +                        p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
  30.107 +                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
  30.108 +                        p.type = TargetType.CLASS_TYPE_PARAMETER;
  30.109 +                        p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
  30.110 +                    } else
  30.111 +                        throw new AssertionError();
  30.112 +                    return p;
  30.113 +
  30.114 +                case METHOD: {
  30.115 +                    JCMethodDecl frameMethod = (JCMethodDecl)frame;
  30.116 +                    p.pos = frame.pos;
  30.117 +                    if (frameMethod.receiverAnnotations.contains(tree))
  30.118 +                        p.type = TargetType.METHOD_RECEIVER;
  30.119 +                    else if (frameMethod.thrown.contains(tree)) {
  30.120 +                        p.type = TargetType.THROWS;
  30.121 +                        p.type_index = frameMethod.thrown.indexOf(tree);
  30.122 +                    } else if (((JCMethodDecl)frame).restype == tree) {
  30.123 +                        p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY;
  30.124 +                    } else if (frameMethod.typarams.contains(tree)) {
  30.125 +                        p.type = TargetType.METHOD_TYPE_PARAMETER;
  30.126 +                        p.parameter_index = frameMethod.typarams.indexOf(tree);
  30.127 +                    } else
  30.128 +                        throw new AssertionError();
  30.129 +                    return p;
  30.130 +                }
  30.131 +                case MEMBER_SELECT: {
  30.132 +                    JCFieldAccess fieldFrame = (JCFieldAccess)frame;
  30.133 +                    if (fieldFrame.name == names._class) {
  30.134 +                        p.type = TargetType.CLASS_LITERAL;
  30.135 +                        if (fieldFrame.selected instanceof JCAnnotatedType) {
  30.136 +                            p.pos = TreeInfo.typeIn(fieldFrame).pos;
  30.137 +                        } else if (fieldFrame.selected instanceof JCArrayTypeTree) {
  30.138 +                            p.pos = fieldFrame.selected.pos;
  30.139 +                        }
  30.140 +                    } else
  30.141 +                        throw new AssertionError();
  30.142 +                    return p;
  30.143 +                }
  30.144 +                case PARAMETERIZED_TYPE: {
  30.145 +                    TypeAnnotationPosition nextP;
  30.146 +                    if (((JCTypeApply)frame).clazz == tree)
  30.147 +                        nextP = p; // generic: RAW; noop
  30.148 +                    else if (((JCTypeApply)frame).arguments.contains(tree))
  30.149 +                        p.location = p.location.prepend(
  30.150 +                                ((JCTypeApply)frame).arguments.indexOf(tree));
  30.151 +                    else
  30.152 +                        throw new AssertionError();
  30.153 +
  30.154 +                    List<JCTree> newPath = path.tail;
  30.155 +                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  30.156 +                }
  30.157 +
  30.158 +                case ARRAY_TYPE: {
  30.159 +                    p.location = p.location.prepend(0);
  30.160 +                    List<JCTree> newPath = path.tail;
  30.161 +                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  30.162 +                }
  30.163 +
  30.164 +                case TYPE_PARAMETER:
  30.165 +                    if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) {
  30.166 +                        JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
  30.167 +                        p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
  30.168 +                        p.parameter_index = clazz.typarams.indexOf(path.tail.head);
  30.169 +                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
  30.170 +                    } else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) {
  30.171 +                        JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
  30.172 +                        p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
  30.173 +                        p.parameter_index = method.typarams.indexOf(path.tail.head);
  30.174 +                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
  30.175 +                    } else
  30.176 +                        throw new AssertionError();
  30.177 +                    p.pos = frame.pos;
  30.178 +                    return p;
  30.179 +
  30.180 +                case VARIABLE:
  30.181 +                    VarSymbol v = ((JCVariableDecl)frame).sym;
  30.182 +                    p.pos = frame.pos;
  30.183 +                    switch (v.getKind()) {
  30.184 +                        case LOCAL_VARIABLE:
  30.185 +                            p.type = TargetType.LOCAL_VARIABLE; break;
  30.186 +                        case FIELD:
  30.187 +                            p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break;
  30.188 +                        case PARAMETER:
  30.189 +                            p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY;
  30.190 +                            p.parameter_index = methodParamIndex(path, frame);
  30.191 +                            break;
  30.192 +                        default: throw new AssertionError();
  30.193 +                    }
  30.194 +                    return p;
  30.195 +
  30.196 +                case ANNOTATED_TYPE: {
  30.197 +                    List<JCTree> newPath = path.tail;
  30.198 +                    return resolveFrame(newPath.head, newPath.tail.head,
  30.199 +                            newPath, p);
  30.200 +                }
  30.201 +
  30.202 +                case METHOD_INVOCATION: {
  30.203 +                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
  30.204 +                    if (!invocation.typeargs.contains(tree))
  30.205 +                        throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
  30.206 +                    p.type = TargetType.METHOD_TYPE_ARGUMENT;
  30.207 +                    p.pos = invocation.pos;
  30.208 +                    p.type_index = invocation.typeargs.indexOf(tree);
  30.209 +                    return p;
  30.210 +                }
  30.211 +
  30.212 +                case EXTENDS_WILDCARD:
  30.213 +                case SUPER_WILDCARD: {
  30.214 +                    p.type = TargetType.WILDCARD_BOUND;
  30.215 +                    List<JCTree> newPath = path.tail;
  30.216 +
  30.217 +                    TypeAnnotationPosition wildcard =
  30.218 +                        resolveFrame(newPath.head, newPath.tail.head, newPath,
  30.219 +                                new TypeAnnotationPosition());
  30.220 +                    if (!wildcard.location.isEmpty())
  30.221 +                        wildcard.type = wildcard.type.getGenericComplement();
  30.222 +                    p.wildcard_position = wildcard;
  30.223 +                    p.pos = frame.pos;
  30.224 +                    return p;
  30.225 +                }
  30.226 +            }
  30.227 +            return p;
  30.228 +        }
  30.229 +
  30.230 +        @Override
  30.231 +        public void visitApply(JCMethodInvocation tree) {
  30.232 +            scan(tree.meth);
  30.233 +            scan(tree.typeargs);
  30.234 +            scan(tree.args);
  30.235 +        }
  30.236 +
  30.237 +        private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) {
  30.238 +            for (JCTypeAnnotation anno : annotations) {
  30.239 +                anno.annotation_position = position;
  30.240 +                anno.attribute_field.position = position;
  30.241 +            }
  30.242 +        }
  30.243 +
  30.244 +        @Override
  30.245 +        public void visitNewArray(JCNewArray tree) {
  30.246 +            findPosition(tree, tree, tree.annotations);
  30.247 +            int dimAnnosCount = tree.dimAnnotations.size();
  30.248 +
  30.249 +            // handle annotations associated with dimentions
  30.250 +            for (int i = 0; i < dimAnnosCount; ++i) {
  30.251 +                TypeAnnotationPosition p = new TypeAnnotationPosition();
  30.252 +                p.type = TargetType.NEW_GENERIC_OR_ARRAY;
  30.253 +                p.pos = tree.pos;
  30.254 +                p.location = p.location.append(i);
  30.255 +                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
  30.256 +            }
  30.257 +
  30.258 +            // handle "free" annotations
  30.259 +            int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
  30.260 +            JCExpression elemType = tree.elemtype;
  30.261 +            while (elemType != null) {
  30.262 +                if (elemType.getTag() == JCTree.ANNOTATED_TYPE) {
  30.263 +                    JCAnnotatedType at = (JCAnnotatedType)elemType;
  30.264 +                    TypeAnnotationPosition p = new TypeAnnotationPosition();
  30.265 +                    p.type = TargetType.NEW_GENERIC_OR_ARRAY;
  30.266 +                    p.pos = tree.pos;
  30.267 +                    p.location = p.location.append(i);
  30.268 +                    setTypeAnnotationPos(at.annotations, p);
  30.269 +                    elemType = at.underlyingType;
  30.270 +                } else if (elemType.getTag() == JCTree.TYPEARRAY) {
  30.271 +                    ++i;
  30.272 +                    elemType = ((JCArrayTypeTree)elemType).elemtype;
  30.273 +                } else
  30.274 +                    break;
  30.275 +            }
  30.276 +
  30.277 +            // find annotations locations of initializer elements
  30.278 +            scan(tree.elems);
  30.279 +        }
  30.280 +
  30.281 +        @Override
  30.282 +        public void visitAnnotatedType(JCAnnotatedType tree) {
  30.283 +            findPosition(tree, peek2(), tree.annotations);
  30.284 +            super.visitAnnotatedType(tree);
  30.285 +        }
  30.286 +
  30.287 +        @Override
  30.288 +        public void visitMethodDef(JCMethodDecl tree) {
  30.289 +            TypeAnnotationPosition p = new TypeAnnotationPosition();
  30.290 +            p.type = TargetType.METHOD_RECEIVER;
  30.291 +            setTypeAnnotationPos(tree.receiverAnnotations, p);
  30.292 +            super.visitMethodDef(tree);
  30.293 +        }
  30.294 +        @Override
  30.295 +        public void visitTypeParameter(JCTypeParameter tree) {
  30.296 +            findPosition(tree, peek2(), tree.annotations);
  30.297 +            super.visitTypeParameter(tree);
  30.298 +        }
  30.299 +
  30.300 +        void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) {
  30.301 +            if (!annotations.isEmpty()) {
  30.302 +                TypeAnnotationPosition p =
  30.303 +                        resolveFrame(tree, frame, frames.toList(),
  30.304 +                                new TypeAnnotationPosition());
  30.305 +                if (!p.location.isEmpty())
  30.306 +                    p.type = p.type.getGenericComplement();
  30.307 +                setTypeAnnotationPos(annotations, p);
  30.308 +                if (debugJSR308) {
  30.309 +                    System.out.println("trans: " + tree);
  30.310 +                    System.out.println("  target: " + p);
  30.311 +                }
  30.312 +            }
  30.313 +        }
  30.314 +
  30.315 +        private int methodParamIndex(List<JCTree> path, JCTree param) {
  30.316 +            List<JCTree> curr = path;
  30.317 +            if (curr.head != param)
  30.318 +                curr = path.tail;
  30.319 +            JCMethodDecl method = (JCMethodDecl)curr.tail.head;
  30.320 +            return method.params.indexOf(param);
  30.321 +        }
  30.322 +    }
  30.323 +
  30.324 +    private class TypeAnnotationLift extends TreeScanner {
  30.325 +        List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil();
  30.326 +
  30.327 +        boolean isInner = false;
  30.328 +        @Override
  30.329 +        public void visitClassDef(JCClassDecl tree) {
  30.330 +            if (isInner) {
  30.331 +                // tree is an inner class tree.  stop now.
  30.332 +                // TransTypes.visitClassDef makes an invocation for each class
  30.333 +                // seperately.
  30.334 +                return;
  30.335 +            }
  30.336 +            isInner = true;
  30.337 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  30.338 +            recordedTypeAnnotations = List.nil();
  30.339 +            try {
  30.340 +                super.visitClassDef(tree);
  30.341 +            } finally {
  30.342 +                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  30.343 +                recordedTypeAnnotations = prevTAs;
  30.344 +            }
  30.345 +        }
  30.346 +
  30.347 +        @Override
  30.348 +        public void visitMethodDef(JCMethodDecl tree) {
  30.349 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  30.350 +            recordedTypeAnnotations = List.nil();
  30.351 +            try {
  30.352 +                super.visitMethodDef(tree);
  30.353 +            } finally {
  30.354 +                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  30.355 +                recordedTypeAnnotations = prevTAs;
  30.356 +            }
  30.357 +        }
  30.358 +
  30.359 +        @Override
  30.360 +        public void visitVarDef(JCVariableDecl tree) {
  30.361 +            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
  30.362 +            recordedTypeAnnotations = List.nil();
  30.363 +            ElementKind kind = tree.sym.getKind();
  30.364 +            if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) {
  30.365 +                // need to lift the annotations
  30.366 +                TypeAnnotationPosition position = new TypeAnnotationPosition();
  30.367 +                position.pos = tree.pos;
  30.368 +                position.type = TargetType.LOCAL_VARIABLE;
  30.369 +                for (Attribute.Compound attribute : tree.sym.attributes_field) {
  30.370 +                    Attribute.TypeCompound tc =
  30.371 +                        new Attribute.TypeCompound(attribute.type, attribute.values, position);
  30.372 +                    recordedTypeAnnotations = recordedTypeAnnotations.append(tc);
  30.373 +                }
  30.374 +            }
  30.375 +            try {
  30.376 +                super.visitVarDef(tree);
  30.377 +            } finally {
  30.378 +                if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE)
  30.379 +                    tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
  30.380 +                recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations);
  30.381 +            }
  30.382 +        }
  30.383 +
  30.384 +        @Override
  30.385 +        public void visitApply(JCMethodInvocation tree) {
  30.386 +            scan(tree.meth);
  30.387 +            scan(tree.typeargs);
  30.388 +            scan(tree.args);
  30.389 +        }
  30.390 +
  30.391 +        public void visitAnnotation(JCAnnotation tree) {
  30.392 +            if (tree instanceof JCTypeAnnotation)
  30.393 +                recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field);
  30.394 +            super.visitAnnotation(tree);
  30.395 +        }
  30.396 +    }
  30.397 +
  30.398  }
    31.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jun 26 10:26:27 2009 -0700
    31.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Sun Jun 28 00:01:09 2009 -0700
    31.3 @@ -47,7 +47,6 @@
    31.4  import com.sun.tools.javac.code.Symtab;
    31.5  import com.sun.tools.javac.file.BaseFileObject;
    31.6  import com.sun.tools.javac.util.*;
    31.7 -import com.sun.tools.javac.util.List;
    31.8  
    31.9  import static com.sun.tools.javac.code.Flags.*;
   31.10  import static com.sun.tools.javac.code.Kinds.*;
   31.11 @@ -187,6 +186,10 @@
   31.12      /** The minor version number of the class file being read. */
   31.13      int minorVersion;
   31.14  
   31.15 +    /** Switch: debug output for JSR 308-related operations.
   31.16 +     */
   31.17 +    boolean debugJSR308;
   31.18 +
   31.19      /** Get the ClassReader instance for this invocation. */
   31.20      public static ClassReader instance(Context context) {
   31.21          ClassReader instance = context.get(classReaderKey);
   31.22 @@ -256,6 +259,7 @@
   31.23              : null;
   31.24  
   31.25          typevars = new Scope(syms.noSymbol);
   31.26 +        debugJSR308 = options.get("TA:reader") != null;
   31.27  
   31.28          initAttributeReaders();
   31.29      }
   31.30 @@ -303,6 +307,12 @@
   31.31          return (char)(((buf[bp++] & 0xFF) << 8) + (buf[bp++] & 0xFF));
   31.32      }
   31.33  
   31.34 +    /** Read a byte.
   31.35 +     */
   31.36 +    byte nextByte() {
   31.37 +        return buf[bp++];
   31.38 +    }
   31.39 +
   31.40      /** Read an integer.
   31.41       */
   31.42      int nextInt() {
   31.43 @@ -1060,7 +1070,21 @@
   31.44                      if (allowVarargs)
   31.45                          sym.flags_field |= VARARGS;
   31.46                  }
   31.47 -            }
   31.48 +            },
   31.49 +
   31.50 +            // v51 attributes
   31.51 +            new AttributeReader(names.RuntimeVisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
   31.52 +                void read(Symbol sym, int attrLen) {
   31.53 +                    attachTypeAnnotations(sym);
   31.54 +                }
   31.55 +            },
   31.56 +
   31.57 +            new AttributeReader(names.RuntimeInvisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
   31.58 +                void read(Symbol sym, int attrLen) {
   31.59 +                    attachTypeAnnotations(sym);
   31.60 +                }
   31.61 +            },
   31.62 +
   31.63  
   31.64              // The following attributes for a Code attribute are not currently handled
   31.65              // StackMapTable
   31.66 @@ -1268,6 +1292,17 @@
   31.67          }
   31.68      }
   31.69  
   31.70 +    void attachTypeAnnotations(final Symbol sym) {
   31.71 +        int numAttributes = nextChar();
   31.72 +        if (numAttributes != 0) {
   31.73 +            ListBuffer<TypeAnnotationProxy> proxies =
   31.74 +                ListBuffer.lb();
   31.75 +            for (int i = 0; i < numAttributes; i++)
   31.76 +                proxies.append(readTypeAnnotation());
   31.77 +            annotate.later(new TypeAnnotationCompleter(sym, proxies.toList()));
   31.78 +        }
   31.79 +    }
   31.80 +
   31.81      /** Attach the default value for an annotation element.
   31.82       */
   31.83      void attachAnnotationDefault(final Symbol sym) {
   31.84 @@ -1304,6 +1339,121 @@
   31.85          return new CompoundAnnotationProxy(t, pairs.toList());
   31.86      }
   31.87  
   31.88 +    TypeAnnotationProxy readTypeAnnotation() {
   31.89 +        CompoundAnnotationProxy proxy = readCompoundAnnotation();
   31.90 +        TypeAnnotationPosition position = readPosition();
   31.91 +
   31.92 +        if (debugJSR308)
   31.93 +            System.out.println("TA: reading: " + proxy + " @ " + position
   31.94 +                    + " in " + log.currentSourceFile());
   31.95 +
   31.96 +        return new TypeAnnotationProxy(proxy, position);
   31.97 +    }
   31.98 +
   31.99 +    TypeAnnotationPosition readPosition() {
  31.100 +        byte tag = nextByte();
  31.101 +
  31.102 +        if (!TargetType.isValidTargetTypeValue(tag))
  31.103 +            throw this.badClassFile("bad.type.annotation.value", tag);
  31.104 +
  31.105 +        TypeAnnotationPosition position = new TypeAnnotationPosition();
  31.106 +        TargetType type = TargetType.fromTargetTypeValue(tag);
  31.107 +
  31.108 +        position.type = type;
  31.109 +
  31.110 +        switch (type) {
  31.111 +        // type case
  31.112 +        case TYPECAST:
  31.113 +        case TYPECAST_GENERIC_OR_ARRAY:
  31.114 +        // object creation
  31.115 +        case INSTANCEOF:
  31.116 +        case INSTANCEOF_GENERIC_OR_ARRAY:
  31.117 +        // new expression
  31.118 +        case NEW:
  31.119 +        case NEW_GENERIC_OR_ARRAY:
  31.120 +            position.offset = nextChar();
  31.121 +            break;
  31.122 +         // local variable
  31.123 +        case LOCAL_VARIABLE:
  31.124 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
  31.125 +            int table_length = nextChar();
  31.126 +            position.lvarOffset = new int[table_length];
  31.127 +            position.lvarLength = new int[table_length];
  31.128 +            position.lvarIndex = new int[table_length];
  31.129 +
  31.130 +            for (int i = 0; i < table_length; ++i) {
  31.131 +                position.lvarOffset[i] = nextChar();
  31.132 +                position.lvarLength[i] = nextChar();
  31.133 +                position.lvarIndex[i] = nextChar();
  31.134 +            }
  31.135 +            break;
  31.136 +         // method receiver
  31.137 +        case METHOD_RECEIVER:
  31.138 +            // Do nothing
  31.139 +            break;
  31.140 +        // type parameters
  31.141 +        case CLASS_TYPE_PARAMETER:
  31.142 +        case METHOD_TYPE_PARAMETER:
  31.143 +            position.parameter_index = nextByte();
  31.144 +            break;
  31.145 +        // type parameter bounds
  31.146 +        case CLASS_TYPE_PARAMETER_BOUND:
  31.147 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  31.148 +        case METHOD_TYPE_PARAMETER_BOUND:
  31.149 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  31.150 +            position.parameter_index = nextByte();
  31.151 +            position.bound_index = nextByte();
  31.152 +            break;
  31.153 +         // wildcard
  31.154 +        case WILDCARD_BOUND:
  31.155 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  31.156 +            position.wildcard_position = readPosition();
  31.157 +            break;
  31.158 +         // Class extends and implements clauses
  31.159 +        case CLASS_EXTENDS:
  31.160 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  31.161 +            position.type_index = nextByte();
  31.162 +            break;
  31.163 +        // throws
  31.164 +        case THROWS:
  31.165 +            position.type_index = nextByte();
  31.166 +            break;
  31.167 +        case CLASS_LITERAL:
  31.168 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
  31.169 +            position.offset = nextChar();
  31.170 +            break;
  31.171 +        // method parameter: not specified
  31.172 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  31.173 +            position.parameter_index = nextByte();
  31.174 +            break;
  31.175 +        // method type argument: wasn't specified
  31.176 +        case NEW_TYPE_ARGUMENT:
  31.177 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  31.178 +        case METHOD_TYPE_ARGUMENT:
  31.179 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  31.180 +            position.offset = nextChar();
  31.181 +            position.type_index = nextByte();
  31.182 +            break;
  31.183 +        // We don't need to worry abut these
  31.184 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
  31.185 +        case FIELD_GENERIC_OR_ARRAY:
  31.186 +            break;
  31.187 +        case UNKNOWN:
  31.188 +            break;
  31.189 +        default:
  31.190 +            throw new AssertionError("unknown type: " + position);
  31.191 +        }
  31.192 +
  31.193 +        if (type.hasLocation()) {
  31.194 +            int len = nextChar();
  31.195 +            ListBuffer<Integer> loc = ListBuffer.lb();
  31.196 +            for (int i = 0; i < len; i++)
  31.197 +                loc = loc.append((int)nextByte());
  31.198 +            position.location = loc.toList();
  31.199 +        }
  31.200 +
  31.201 +        return position;
  31.202 +    }
  31.203      Attribute readAttributeValue() {
  31.204          char c = (char) buf[bp++];
  31.205          switch (c) {
  31.206 @@ -1408,6 +1558,18 @@
  31.207          }
  31.208      }
  31.209  
  31.210 +    /** A temporary proxy representing a type annotation.
  31.211 +     */
  31.212 +    static class TypeAnnotationProxy {
  31.213 +        final CompoundAnnotationProxy compound;
  31.214 +        final TypeAnnotationPosition position;
  31.215 +        public TypeAnnotationProxy(CompoundAnnotationProxy compound,
  31.216 +                TypeAnnotationPosition position) {
  31.217 +            this.compound = compound;
  31.218 +            this.position = position;
  31.219 +        }
  31.220 +    }
  31.221 +
  31.222      class AnnotationDeproxy implements ProxyVisitor {
  31.223          private ClassSymbol requestingOwner = currentOwner.kind == MTH
  31.224              ? currentOwner.enclClass() : (ClassSymbol)currentOwner;
  31.225 @@ -1604,6 +1766,45 @@
  31.226          }
  31.227      }
  31.228  
  31.229 +    class TypeAnnotationCompleter extends AnnotationCompleter {
  31.230 +
  31.231 +        List<TypeAnnotationProxy> proxies;
  31.232 +
  31.233 +        TypeAnnotationCompleter(Symbol sym,
  31.234 +                List<TypeAnnotationProxy> proxies) {
  31.235 +            super(sym, List.<CompoundAnnotationProxy>nil());
  31.236 +            this.proxies = proxies;
  31.237 +        }
  31.238 +
  31.239 +        List<Attribute.TypeCompound> deproxyTypeCompoundList(List<TypeAnnotationProxy> proxies) {
  31.240 +            ListBuffer<Attribute.TypeCompound> buf = ListBuffer.lb();
  31.241 +            for (TypeAnnotationProxy proxy: proxies) {
  31.242 +                Attribute.Compound compound = deproxyCompound(proxy.compound);
  31.243 +                Attribute.TypeCompound typeCompound = new Attribute.TypeCompound(compound, proxy.position);
  31.244 +                buf.add(typeCompound);
  31.245 +            }
  31.246 +            return buf.toList();
  31.247 +        }
  31.248 +
  31.249 +        @Override
  31.250 +        public void enterAnnotation() {
  31.251 +            JavaFileObject previousClassFile = currentClassFile;
  31.252 +            try {
  31.253 +                currentClassFile = classFile;
  31.254 +                List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies);
  31.255 +              if (debugJSR308)
  31.256 +              System.out.println("TA: reading: adding " + newList
  31.257 +                      + " to symbol " + sym + " in " + log.currentSourceFile());
  31.258 +                sym.typeAnnotations = ((sym.typeAnnotations == null)
  31.259 +                                        ? newList
  31.260 +                                        : newList.prependList(sym.typeAnnotations));
  31.261 +
  31.262 +            } finally {
  31.263 +                currentClassFile = previousClassFile;
  31.264 +            }
  31.265 +        }
  31.266 +    }
  31.267 +
  31.268  
  31.269  /************************************************************************
  31.270   * Reading Symbols
    32.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Jun 26 10:26:27 2009 -0700
    32.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Sun Jun 28 00:01:09 2009 -0700
    32.3 @@ -37,7 +37,6 @@
    32.4  import com.sun.tools.javac.code.Symbol.*;
    32.5  import com.sun.tools.javac.code.Type.*;
    32.6  import com.sun.tools.javac.util.*;
    32.7 -import com.sun.tools.javac.util.List;
    32.8  
    32.9  import static com.sun.tools.javac.code.BoundKind.*;
   32.10  import static com.sun.tools.javac.code.Flags.*;
   32.11 @@ -62,6 +61,10 @@
   32.12  
   32.13      private final Options options;
   32.14  
   32.15 +    /** Switch: debugging output for JSR 308-related operations.
   32.16 +     */
   32.17 +    private boolean debugJSR308;
   32.18 +
   32.19      /** Switch: verbose output.
   32.20       */
   32.21      private boolean verbose;
   32.22 @@ -173,6 +176,7 @@
   32.23          types = Types.instance(context);
   32.24          fileManager = context.get(JavaFileManager.class);
   32.25  
   32.26 +        debugJSR308    = options.get("TA:writer") != null;
   32.27          verbose        = options.get("-verbose")     != null;
   32.28          scramble       = options.get("-scramble")    != null;
   32.29          scrambleAll    = options.get("-scrambleAll") != null;
   32.30 @@ -668,6 +672,7 @@
   32.31              acount++;
   32.32          }
   32.33          acount += writeJavaAnnotations(sym.getAnnotationMirrors());
   32.34 +        acount += writeTypeAnnotations(sym.typeAnnotations);
   32.35          return acount;
   32.36      }
   32.37  
   32.38 @@ -762,6 +767,46 @@
   32.39          return attrCount;
   32.40      }
   32.41  
   32.42 +    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) {
   32.43 +        if (typeAnnos.isEmpty()) return 0;
   32.44 +
   32.45 +        ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
   32.46 +        ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
   32.47 +
   32.48 +        for (Attribute.TypeCompound tc : typeAnnos) {
   32.49 +            if (tc.position.type == TargetType.UNKNOWN
   32.50 +                || !tc.position.emitToClassfile())
   32.51 +                continue;
   32.52 +            switch (getRetention(tc.type.tsym)) {
   32.53 +            case SOURCE: break;
   32.54 +            case CLASS: invisibles.append(tc); break;
   32.55 +            case RUNTIME: visibles.append(tc); break;
   32.56 +            default: ;// /* fail soft */ throw new AssertionError(vis);
   32.57 +            }
   32.58 +        }
   32.59 +
   32.60 +        int attrCount = 0;
   32.61 +        if (visibles.length() != 0) {
   32.62 +            int attrIndex = writeAttr(names.RuntimeVisibleTypeAnnotations);
   32.63 +            databuf.appendChar(visibles.length());
   32.64 +            for (Attribute.TypeCompound p : visibles)
   32.65 +                writeTypeAnnotation(p);
   32.66 +            endAttr(attrIndex);
   32.67 +            attrCount++;
   32.68 +        }
   32.69 +
   32.70 +        if (invisibles.length() != 0) {
   32.71 +            int attrIndex = writeAttr(names.RuntimeInvisibleTypeAnnotations);
   32.72 +            databuf.appendChar(invisibles.length());
   32.73 +            for (Attribute.TypeCompound p : invisibles)
   32.74 +                writeTypeAnnotation(p);
   32.75 +            endAttr(attrIndex);
   32.76 +            attrCount++;
   32.77 +        }
   32.78 +
   32.79 +        return attrCount;
   32.80 +    }
   32.81 +
   32.82      /** A mirror of java.lang.annotation.RetentionPolicy. */
   32.83      enum RetentionPolicy {
   32.84          SOURCE,
   32.85 @@ -862,6 +907,103 @@
   32.86          }
   32.87      }
   32.88  
   32.89 +    void writeTypeAnnotation(Attribute.TypeCompound c) {
   32.90 +        if (debugJSR308)
   32.91 +            System.out.println("TA: writing " + c + " at " + c.position
   32.92 +                    + " in " + log.currentSourceFile());
   32.93 +        writeCompoundAttribute(c);
   32.94 +        writePosition(c.position);
   32.95 +    }
   32.96 +
   32.97 +    void writePosition(TypeAnnotationPosition p) {
   32.98 +        databuf.appendByte(p.type.targetTypeValue());
   32.99 +        switch (p.type) {
  32.100 +        // type case
  32.101 +        case TYPECAST:
  32.102 +        case TYPECAST_GENERIC_OR_ARRAY:
  32.103 +        // object creation
  32.104 +        case INSTANCEOF:
  32.105 +        case INSTANCEOF_GENERIC_OR_ARRAY:
  32.106 +        // new expression
  32.107 +        case NEW:
  32.108 +        case NEW_GENERIC_OR_ARRAY:
  32.109 +            databuf.appendChar(p.offset);
  32.110 +            break;
  32.111 +         // local variable
  32.112 +        case LOCAL_VARIABLE:
  32.113 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
  32.114 +            databuf.appendChar(p.lvarOffset.length);  // for table length
  32.115 +            for (int i = 0; i < p.lvarOffset.length; ++i) {
  32.116 +                databuf.appendChar(p.lvarOffset[i]);
  32.117 +                databuf.appendChar(p.lvarLength[i]);
  32.118 +                databuf.appendChar(p.lvarIndex[i]);
  32.119 +            }
  32.120 +            break;
  32.121 +         // method receiver
  32.122 +        case METHOD_RECEIVER:
  32.123 +            // Do nothing
  32.124 +            break;
  32.125 +        // type parameters
  32.126 +        case CLASS_TYPE_PARAMETER:
  32.127 +        case METHOD_TYPE_PARAMETER:
  32.128 +            databuf.appendByte(p.parameter_index);
  32.129 +            break;
  32.130 +        // type parameters bounds
  32.131 +        case CLASS_TYPE_PARAMETER_BOUND:
  32.132 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  32.133 +        case METHOD_TYPE_PARAMETER_BOUND:
  32.134 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
  32.135 +            databuf.appendByte(p.parameter_index);
  32.136 +            databuf.appendByte(p.bound_index);
  32.137 +            break;
  32.138 +         // wildcards
  32.139 +        case WILDCARD_BOUND:
  32.140 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
  32.141 +            writePosition(p.wildcard_position);
  32.142 +            break;
  32.143 +         // Class extends and implements clauses
  32.144 +        case CLASS_EXTENDS:
  32.145 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
  32.146 +            databuf.appendByte(p.type_index);
  32.147 +            break;
  32.148 +        // throws
  32.149 +        case THROWS:
  32.150 +            databuf.appendByte(p.type_index);
  32.151 +            break;
  32.152 +        case CLASS_LITERAL:
  32.153 +        case CLASS_LITERAL_GENERIC_OR_ARRAY:
  32.154 +            databuf.appendChar(p.offset);
  32.155 +            break;
  32.156 +        // method parameter: not specified
  32.157 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
  32.158 +            databuf.appendByte(p.parameter_index);
  32.159 +            break;
  32.160 +        // method type argument: wasn't specified
  32.161 +        case NEW_TYPE_ARGUMENT:
  32.162 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  32.163 +        case METHOD_TYPE_ARGUMENT:
  32.164 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
  32.165 +            databuf.appendChar(p.offset);
  32.166 +            databuf.appendByte(p.type_index);
  32.167 +            break;
  32.168 +        // We don't need to worry abut these
  32.169 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
  32.170 +        case FIELD_GENERIC_OR_ARRAY:
  32.171 +            break;
  32.172 +        case UNKNOWN:
  32.173 +            break;
  32.174 +        default:
  32.175 +            throw new AssertionError("unknown position: " + p);
  32.176 +        }
  32.177 +
  32.178 +        // Append location data for generics/arrays.
  32.179 +        if (p.type.hasLocation()) {
  32.180 +            databuf.appendChar(p.location.size());
  32.181 +            for (int i : p.location)
  32.182 +                databuf.appendByte((byte)i);
  32.183 +        }
  32.184 +    }
  32.185 +
  32.186  /**********************************************************************
  32.187   * Writing Objects
  32.188   **********************************************************************/
  32.189 @@ -1569,6 +1711,7 @@
  32.190  
  32.191          acount += writeFlagAttrs(c.flags());
  32.192          acount += writeJavaAnnotations(c.getAnnotationMirrors());
  32.193 +        acount += writeTypeAnnotations(c.typeAnnotations);
  32.194          acount += writeEnclosingMethodAttribute(c);
  32.195  
  32.196          poolbuf.appendInt(JAVA_MAGIC);
    33.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java	Fri Jun 26 10:26:27 2009 -0700
    33.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java	Sun Jun 28 00:01:09 2009 -0700
    33.3 @@ -1912,12 +1912,29 @@
    33.4                  if (length < Character.MAX_VALUE) {
    33.5                      v.length = length;
    33.6                      putVar(v);
    33.7 +                    fillLocalVarPosition(v);
    33.8                  }
    33.9              }
   33.10          }
   33.11          state.defined.excl(adr);
   33.12      }
   33.13  
   33.14 +    private void fillLocalVarPosition(LocalVar lv) {
   33.15 +        if (lv == null || lv.sym == null
   33.16 +                || lv.sym.typeAnnotations == null)
   33.17 +            return;
   33.18 +        for (Attribute.TypeCompound ta : lv.sym.typeAnnotations) {
   33.19 +            TypeAnnotationPosition p = ta.position;
   33.20 +            while (p != null) {
   33.21 +                p.lvarOffset[0] = (int)lv.start_pc;
   33.22 +                p.lvarLength[0] = (int)lv.length;
   33.23 +                p.lvarIndex[0] = (int)lv.reg;
   33.24 +                p.isValidOffset = true;
   33.25 +                p = p.wildcard_position;
   33.26 +            }
   33.27 +        }
   33.28 +    }
   33.29 +
   33.30      /** Put a live variable range into the buffer to be output to the
   33.31       *  class file.
   33.32       */
    34.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 26 10:26:27 2009 -0700
    34.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Sun Jun 28 00:01:09 2009 -0700
    34.3 @@ -26,6 +26,8 @@
    34.4  package com.sun.tools.javac.jvm;
    34.5  import java.util.*;
    34.6  
    34.7 +import javax.lang.model.element.ElementKind;
    34.8 +
    34.9  import com.sun.tools.javac.util.*;
   34.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
   34.11  import com.sun.tools.javac.util.List;
   34.12 @@ -939,7 +941,6 @@
   34.13                                   startpcCrt,
   34.14                                   code.curPc());
   34.15  
   34.16 -                // End the scope of all local variables in variable info.
   34.17                  code.endScopes(0);
   34.18  
   34.19                  // If we exceeded limits, panic
   34.20 @@ -1439,7 +1440,6 @@
   34.21              // Resolve all breaks.
   34.22              code.resolve(exitChain);
   34.23  
   34.24 -            // End the scopes of all try-local variables in variable info.
   34.25              code.endScopes(limit);
   34.26          }
   34.27  
   34.28 @@ -1672,6 +1672,7 @@
   34.29   *************************************************************************/
   34.30  
   34.31      public void visitApply(JCMethodInvocation tree) {
   34.32 +        setTypeAnnotationPositions(tree.pos);
   34.33          // Generate code for method.
   34.34          Item m = genExpr(tree.meth, methodType);
   34.35          // Generate code for all arguments, where the expected types are
   34.36 @@ -1707,10 +1708,48 @@
   34.37          result = items.makeStackItem(pt);
   34.38      }
   34.39  
   34.40 +    private void setTypeAnnotationPositions(int treePos) {
   34.41 +        MethodSymbol meth = code.meth;
   34.42 +
   34.43 +        for (Attribute.TypeCompound ta : meth.typeAnnotations) {
   34.44 +            if (ta.position.pos == treePos) {
   34.45 +                ta.position.offset = code.cp;
   34.46 +                ta.position.lvarOffset[0] = code.cp;
   34.47 +                ta.position.isValidOffset = true;
   34.48 +            }
   34.49 +        }
   34.50 +
   34.51 +        if (code.meth.getKind() != ElementKind.CONSTRUCTOR
   34.52 +                && code.meth.getKind() != ElementKind.STATIC_INIT)
   34.53 +            return;
   34.54 +
   34.55 +        for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
   34.56 +            if (ta.position.pos == treePos) {
   34.57 +                ta.position.offset = code.cp;
   34.58 +                ta.position.lvarOffset[0] = code.cp;
   34.59 +                ta.position.isValidOffset = true;
   34.60 +            }
   34.61 +        }
   34.62 +
   34.63 +        ClassSymbol clazz = meth.enclClass();
   34.64 +        for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
   34.65 +            if (!s.getKind().isField())
   34.66 +                continue;
   34.67 +            for (Attribute.TypeCompound ta : s.typeAnnotations) {
   34.68 +                if (ta.position.pos == treePos) {
   34.69 +                    ta.position.offset = code.cp;
   34.70 +                    ta.position.lvarOffset[0] = code.cp;
   34.71 +                    ta.position.isValidOffset = true;
   34.72 +                }
   34.73 +            }
   34.74 +        }
   34.75 +    }
   34.76 +
   34.77      public void visitNewClass(JCNewClass tree) {
   34.78          // Enclosing instances or anonymous classes should have been eliminated
   34.79          // by now.
   34.80          assert tree.encl == null && tree.def == null;
   34.81 +        setTypeAnnotationPositions(tree.pos);
   34.82  
   34.83          code.emitop2(new_, makeRef(tree.pos(), tree.type));
   34.84          code.emitop0(dup);
   34.85 @@ -1725,6 +1764,8 @@
   34.86      }
   34.87  
   34.88      public void visitNewArray(JCNewArray tree) {
   34.89 +        setTypeAnnotationPositions(tree.pos);
   34.90 +
   34.91          if (tree.elems != null) {
   34.92              Type elemtype = types.elemtype(tree.type);
   34.93              loadIntConst(tree.elems.length());
   34.94 @@ -2053,6 +2094,7 @@
   34.95          }
   34.96  
   34.97      public void visitTypeCast(JCTypeCast tree) {
   34.98 +        setTypeAnnotationPositions(tree.pos);
   34.99          result = genExpr(tree.expr, tree.clazz.type).load();
  34.100          // Additional code is only needed if we cast to a reference type
  34.101          // which is not statically a supertype of the expression's type.
  34.102 @@ -2069,6 +2111,8 @@
  34.103      }
  34.104  
  34.105      public void visitTypeTest(JCInstanceOf tree) {
  34.106 +        setTypeAnnotationPositions(tree.pos);
  34.107 +
  34.108          genExpr(tree.expr, tree.expr.type).load();
  34.109          code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
  34.110          result = items.makeStackItem(syms.booleanType);
  34.111 @@ -2110,6 +2154,7 @@
  34.112  
  34.113          if (tree.name == names._class) {
  34.114              assert target.hasClassLiterals();
  34.115 +            setTypeAnnotationPositions(tree.pos);
  34.116              code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
  34.117              result = items.makeStackItem(pt);
  34.118              return;
    35.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Jun 26 10:26:27 2009 -0700
    35.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Sun Jun 28 00:01:09 2009 -0700
    35.3 @@ -477,7 +477,7 @@
    35.4      public Todo todo;
    35.5  
    35.6      /** Ordered list of compiler phases for each compilation unit. */
    35.7 -    protected enum CompileState {
    35.8 +    public enum CompileState {
    35.9          PARSE(1),
   35.10          ENTER(2),
   35.11          PROCESS(3),
    36.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Jun 26 10:26:27 2009 -0700
    36.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sun Jun 28 00:01:09 2009 -0700
    36.3 @@ -75,6 +75,42 @@
    36.4      /** The name table. */
    36.5      private Names names;
    36.6  
    36.7 +    // Because of javac's limited lookahead, some contexts are ambiguous in
    36.8 +    // the presence of type annotations even though they are not ambiguous
    36.9 +    // in the absence of type annotations.  Consider this code:
   36.10 +    //   void m(String [] m) { }
   36.11 +    //   void m(String ... m) { }
   36.12 +    // After parsing "String", javac calls bracketsOpt which immediately
   36.13 +    // returns if the next character is not '['.  Similarly, javac can see
   36.14 +    // if the next token is ... and in that case parse an ellipsis.  But in
   36.15 +    // the presence of type annotations:
   36.16 +    //   void m(String @A [] m) { }
   36.17 +    //   void m(String @A ... m) { }
   36.18 +    // no finite lookahead is enough to determine whether to read array
   36.19 +    // levels or an ellipsis.  Furthermore, if you call bracketsOpt, then
   36.20 +    // bracketsOpt first reads all the leading annotations and only then
   36.21 +    // discovers that it needs to fail.  bracketsOpt needs a way to push
   36.22 +    // back the extra annotations that it read.  (But, bracketsOpt should
   36.23 +    // not *always* be allowed to push back extra annotations that it finds
   36.24 +    // -- in most contexts, any such extra annotation is an error.
   36.25 +    // Another similar case occurs with arrays and receiver annotations:
   36.26 +    //   String b() @Array [] @Receiver { }
   36.27 +    //   String b() @Receiver { }
   36.28 +    //
   36.29 +    // The following two variables permit type annotations that have
   36.30 +    // already been read to be stored for later use.  Alternate
   36.31 +    // implementations are possible but would cause much larger changes to
   36.32 +    // the parser.
   36.33 +    /** Type annotations that have already been read but have not yet been used. **/
   36.34 +    private List<JCTypeAnnotation> typeAnnotationsPushedBack = null;
   36.35 +    /**
   36.36 +     * If the parser notices extra annotations, then it either immediately
   36.37 +     * issues an error (if this variable is false) or places the extra
   36.38 +     * annotations in variable typeAnnotationsPushedBack (if this variable
   36.39 +     * is true).
   36.40 +     */
   36.41 +    private boolean permitTypeAnnotationsPushBack = false;
   36.42 +
   36.43      /** Construct a parser from a given scanner, tree factory and log.
   36.44       */
   36.45      protected JavacParser(ParserFactory fac,
   36.46 @@ -95,13 +131,19 @@
   36.47          this.allowForeach = source.allowForeach();
   36.48          this.allowStaticImport = source.allowStaticImport();
   36.49          this.allowAnnotations = source.allowAnnotations();
   36.50 +        this.allowTypeAnnotations = source.allowTypeAnnotations();
   36.51          this.keepDocComments = keepDocComments;
   36.52          if (keepDocComments)
   36.53              docComments = new HashMap<JCTree,String>();
   36.54          this.keepLineMap = keepLineMap;
   36.55          this.errorTree = F.Erroneous();
   36.56 +        this.debugJSR308 = fac.options.get("TA:parser") != null;
   36.57      }
   36.58  
   36.59 +    /** Switch: debug output for type-annotations operations
   36.60 +     */
   36.61 +    boolean debugJSR308;
   36.62 +
   36.63      /** Switch: Should generics be recognized?
   36.64       */
   36.65      boolean allowGenerics;
   36.66 @@ -130,6 +172,10 @@
   36.67       */
   36.68      boolean allowAnnotations;
   36.69  
   36.70 +    /** Switch: should we recognize type annotations?
   36.71 +     */
   36.72 +    boolean allowTypeAnnotations;
   36.73 +
   36.74      /** Switch: should we keep docComments?
   36.75       */
   36.76      boolean keepDocComments;
   36.77 @@ -558,7 +604,33 @@
   36.78          return term(EXPR);
   36.79      }
   36.80  
   36.81 +    /**
   36.82 +     * parses (optional) type annotations followed by a type. If the
   36.83 +     * annotations are present before the type and are not consumed during array
   36.84 +     * parsing, this method returns a {@link JCAnnotatedType} consisting of
   36.85 +     * these annotations and the underlying type. Otherwise, it returns the
   36.86 +     * underlying type.
   36.87 +     *
   36.88 +     * <p>
   36.89 +     *
   36.90 +     * Note that this method sets {@code mode} to {@code TYPE} first, before
   36.91 +     * parsing annotations.
   36.92 +     */
   36.93      public JCExpression parseType() {
   36.94 +        List<JCTypeAnnotation> annotations = typeAnnotationsOpt();
   36.95 +        return parseType(annotations);
   36.96 +    }
   36.97 +
   36.98 +    public JCExpression parseType(List<JCTypeAnnotation> annotations) {
   36.99 +        JCExpression result = unannotatedType();
  36.100 +
  36.101 +        if (!annotations.isEmpty())
  36.102 +            result = F.AnnotatedType(annotations, result);
  36.103 +
  36.104 +        return result;
  36.105 +    }
  36.106 +
  36.107 +    public JCExpression unannotatedType() {
  36.108          return term(TYPE);
  36.109      }
  36.110  
  36.111 @@ -792,8 +864,8 @@
  36.112       *                 | [TypeArguments] THIS [Arguments]
  36.113       *                 | [TypeArguments] SUPER SuperSuffix
  36.114       *                 | NEW [TypeArguments] Creator
  36.115 -     *                 | Ident { "." Ident }
  36.116 -     *                   [ "[" ( "]" BracketsOpt "." CLASS | Expression "]" )
  36.117 +     *                 | [Annotations] Ident { "." Ident }
  36.118 +     *                   [ [Annotations] "[" ( "]" BracketsOpt "." CLASS | Expression "]" )
  36.119       *                   | Arguments
  36.120       *                   | "." ( CLASS | THIS | [TypeArguments] SUPER Arguments | NEW [TypeArguments] InnerCreator )
  36.121       *                   ]
  36.122 @@ -942,23 +1014,62 @@
  36.123                  typeArgs = null;
  36.124              } else return illegal();
  36.125              break;
  36.126 +        case MONKEYS_AT:
  36.127 +
  36.128 +            // only annotated targetting class literals or cast types are valid
  36.129 +            List<JCTypeAnnotation> typeAnnos = typeAnnotationsOpt();
  36.130 +            if (typeAnnos.isEmpty()) {
  36.131 +                // else there would be no '@'
  36.132 +                throw new AssertionError("type annos is empty");
  36.133 +            }
  36.134 +
  36.135 +            JCExpression expr = term3();
  36.136 +
  36.137 +            // Type annotations: If term3 just parsed a non-type, expect a
  36.138 +            // class literal (and issue a syntax error if there is no class
  36.139 +            // literal). Otherwise, create a JCAnnotatedType.
  36.140 +            if ((mode & TYPE) == 0) {
  36.141 +                if (expr.getTag() != JCTree.SELECT)
  36.142 +                    return illegal(typeAnnos.head.pos);
  36.143 +                JCFieldAccess sel = (JCFieldAccess)expr;
  36.144 +                if (sel.name != names._class)
  36.145 +                    return illegal();
  36.146 +                else {
  36.147 +                    sel.selected = F.AnnotatedType(typeAnnos, sel.selected);
  36.148 +                    t = expr;
  36.149 +                }
  36.150 +            } else {
  36.151 +                // type annotation targeting a cast
  36.152 +                t = toP(F.at(S.pos()).AnnotatedType(typeAnnos, expr));
  36.153 +            }
  36.154 +            break;
  36.155          case IDENTIFIER: case ASSERT: case ENUM:
  36.156              if (typeArgs != null) return illegal();
  36.157              t = toP(F.at(S.pos()).Ident(ident()));
  36.158              loop: while (true) {
  36.159                  pos = S.pos();
  36.160 +                final List<JCTypeAnnotation> annos = typeAnnotationsOpt();
  36.161 +
  36.162 +                // need to report an error later if LBRACKET is for array
  36.163 +                // index access rather than array creation level
  36.164 +                if (!annos.isEmpty() && S.token() != LBRACKET && S.token() != ELLIPSIS)
  36.165 +                    return illegal(annos.head.pos);
  36.166                  switch (S.token()) {
  36.167                  case LBRACKET:
  36.168                      S.nextToken();
  36.169 +
  36.170                      if (S.token() == RBRACKET) {
  36.171 +
  36.172                          S.nextToken();
  36.173 -                        t = bracketsOpt(t);
  36.174 +
  36.175 +                        t = bracketsOpt(t, annos);
  36.176                          t = toP(F.at(pos).TypeArray(t));
  36.177                          t = bracketsSuffix(t);
  36.178                      } else {
  36.179                          if ((mode & EXPR) != 0) {
  36.180                              mode = EXPR;
  36.181                              JCExpression t1 = term();
  36.182 +                            if (!annos.isEmpty()) t = illegal(annos.head.pos);
  36.183                              t = to(F.at(pos).Indexed(t, t1));
  36.184                          }
  36.185                          accept(RBRACKET);
  36.186 @@ -1011,6 +1122,10 @@
  36.187                      // typeArgs saved for next loop iteration.
  36.188                      t = toP(F.at(pos).Select(t, ident()));
  36.189                      break;
  36.190 +                case ELLIPSIS:
  36.191 +                    assert this.permitTypeAnnotationsPushBack;
  36.192 +                    typeAnnotationsPushedBack = annos;
  36.193 +                    break loop;
  36.194                  default:
  36.195                      break loop;
  36.196                  }
  36.197 @@ -1049,14 +1164,18 @@
  36.198          if (typeArgs != null) illegal();
  36.199          while (true) {
  36.200              int pos1 = S.pos();
  36.201 +
  36.202 +            final List<JCTypeAnnotation> annos = typeAnnotationsOpt();
  36.203 +
  36.204              if (S.token() == LBRACKET) {
  36.205                  S.nextToken();
  36.206 +
  36.207                  if ((mode & TYPE) != 0) {
  36.208                      int oldmode = mode;
  36.209                      mode = TYPE;
  36.210                      if (S.token() == RBRACKET) {
  36.211                          S.nextToken();
  36.212 -                        t = bracketsOpt(t);
  36.213 +                        t = bracketsOpt(t, annos);
  36.214                          t = toP(F.at(pos1).TypeArray(t));
  36.215                          return t;
  36.216                      }
  36.217 @@ -1091,6 +1210,12 @@
  36.218                      typeArgs = null;
  36.219                  }
  36.220              } else {
  36.221 +                if (!annos.isEmpty()) {
  36.222 +                    if (permitTypeAnnotationsPushBack)
  36.223 +                        typeAnnotationsPushedBack = annos;
  36.224 +                    else
  36.225 +                        return illegal(annos.head.pos);
  36.226 +                }
  36.227                  break;
  36.228              }
  36.229          }
  36.230 @@ -1100,6 +1225,7 @@
  36.231                    S.token() == PLUSPLUS ? JCTree.POSTINC : JCTree.POSTDEC, t));
  36.232              S.nextToken();
  36.233          }
  36.234 +
  36.235          return toP(t);
  36.236      }
  36.237  
  36.238 @@ -1232,22 +1358,24 @@
  36.239      }
  36.240  
  36.241      /** TypeArgument = Type
  36.242 -     *               | "?"
  36.243 -     *               | "?" EXTENDS Type {"&" Type}
  36.244 -     *               | "?" SUPER Type
  36.245 +     *               | [Annotations] "?"
  36.246 +     *               | [Annotations] "?" EXTENDS Type {"&" Type}
  36.247 +     *               | [Annotations] "?" SUPER Type
  36.248       */
  36.249      JCExpression typeArgument() {
  36.250 -        if (S.token() != QUES) return parseType();
  36.251 +        List<JCTypeAnnotation> annotations = typeAnnotationsOpt();
  36.252 +        if (S.token() != QUES) return parseType(annotations);
  36.253          int pos = S.pos();
  36.254          S.nextToken();
  36.255 +        JCExpression result;
  36.256          if (S.token() == EXTENDS) {
  36.257              TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.EXTENDS));
  36.258              S.nextToken();
  36.259 -            return F.at(pos).Wildcard(t, parseType());
  36.260 +            result = F.at(pos).Wildcard(t, parseType());
  36.261          } else if (S.token() == SUPER) {
  36.262              TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.SUPER));
  36.263              S.nextToken();
  36.264 -            return F.at(pos).Wildcard(t, parseType());
  36.265 +            result = F.at(pos).Wildcard(t, parseType());
  36.266          } else if (S.token() == IDENTIFIER) {
  36.267              //error recovery
  36.268              reportSyntaxError(S.prevEndPos(), "expected3",
  36.269 @@ -1255,11 +1383,14 @@
  36.270              TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
  36.271              JCExpression wc = toP(F.at(pos).Wildcard(t, null));
  36.272              JCIdent id = toP(F.at(S.pos()).Ident(ident()));
  36.273 -            return F.at(pos).Erroneous(List.<JCTree>of(wc, id));
  36.274 +            result = F.at(pos).Erroneous(List.<JCTree>of(wc, id));
  36.275          } else {
  36.276              TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
  36.277 -            return toP(F.at(pos).Wildcard(t, null));
  36.278 +            result = toP(F.at(pos).Wildcard(t, null));
  36.279          }
  36.280 +        if (!annotations.isEmpty())
  36.281 +            result = toP(F.at(annotations.head.pos).AnnotatedType(annotations,result));
  36.282 +        return result;
  36.283      }
  36.284  
  36.285      JCTypeApply typeArguments(JCExpression t) {
  36.286 @@ -1268,21 +1399,47 @@
  36.287          return toP(F.at(pos).TypeApply(t, args));
  36.288      }
  36.289  
  36.290 -    /** BracketsOpt = {"[" "]"}
  36.291 +    /**
  36.292 +     * BracketsOpt = { [Annotations] "[" "]" }
  36.293 +     *
  36.294 +     * <p>
  36.295 +     *
  36.296 +     * <code>annotations</code> is the list of annotations targeting
  36.297 +     * the expression <code>t</code>.
  36.298       */
  36.299 -    private JCExpression bracketsOpt(JCExpression t) {
  36.300 +    private JCExpression bracketsOpt(JCExpression t,
  36.301 +            List<JCTypeAnnotation> annotations) {
  36.302 +        List<JCTypeAnnotation> nextLevelAnnotations = typeAnnotationsOpt();
  36.303 +
  36.304          if (S.token() == LBRACKET) {
  36.305              int pos = S.pos();
  36.306              S.nextToken();
  36.307 -            t = bracketsOptCont(t, pos);
  36.308 -            F.at(pos);
  36.309 +
  36.310 +            JCExpression orig = t;
  36.311 +            t = bracketsOptCont(t, pos, nextLevelAnnotations);
  36.312 +        } else if (!nextLevelAnnotations.isEmpty()) {
  36.313 +            if (permitTypeAnnotationsPushBack) {
  36.314 +                this.typeAnnotationsPushedBack = nextLevelAnnotations;
  36.315 +            } else
  36.316 +                return illegal(nextLevelAnnotations.head.pos);
  36.317          }
  36.318 +
  36.319 +        int apos = S.pos();
  36.320 +        if (!annotations.isEmpty())
  36.321 +            t = F.at(apos).AnnotatedType(annotations, t);
  36.322          return t;
  36.323      }
  36.324  
  36.325 -    private JCArrayTypeTree bracketsOptCont(JCExpression t, int pos) {
  36.326 +    /** BracketsOpt = {"[" TypeAnnotations "]"}
  36.327 +     */
  36.328 +    private JCExpression bracketsOpt(JCExpression t) {
  36.329 +        return bracketsOpt(t, List.<JCTypeAnnotation>nil());
  36.330 +    }
  36.331 +
  36.332 +    private JCArrayTypeTree bracketsOptCont(JCExpression t, int pos,
  36.333 +            List<JCTypeAnnotation> annotations) {
  36.334          accept(RBRACKET);
  36.335 -        t = bracketsOpt(t);
  36.336 +        t = bracketsOpt(t, annotations);
  36.337          return toP(F.at(pos).TypeArray(t));
  36.338      }
  36.339  
  36.340 @@ -1316,18 +1473,29 @@
  36.341          return t;
  36.342      }
  36.343  
  36.344 -    /** Creator = Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
  36.345 +    /** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
  36.346       */
  36.347      JCExpression creator(int newpos, List<JCExpression> typeArgs) {
  36.348 +
  36.349 +        List<JCTypeAnnotation> newAnnotations = typeAnnotationsOpt();
  36.350 +
  36.351          switch (S.token()) {
  36.352          case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
  36.353          case DOUBLE: case BOOLEAN:
  36.354 -            if (typeArgs == null)
  36.355 -                return arrayCreatorRest(newpos, basicType());
  36.356 +            if (typeArgs == null) {
  36.357 +                if (newAnnotations.isEmpty())
  36.358 +                    return arrayCreatorRest(newpos, basicType());
  36.359 +                else
  36.360 +                    return arrayCreatorRest(newpos, F.AnnotatedType(newAnnotations, basicType()));
  36.361 +            }
  36.362              break;
  36.363          default:
  36.364          }
  36.365          JCExpression t = qualident();
  36.366 +        // handle type annotations for non primitive arrays
  36.367 +        if (!newAnnotations.isEmpty())
  36.368 +            t = F.AnnotatedType(newAnnotations, t);
  36.369 +
  36.370          int oldmode = mode;
  36.371          mode = TYPE;
  36.372          if (S.token() == LT) {
  36.373 @@ -1344,7 +1512,7 @@
  36.374              }
  36.375          }
  36.376          mode = oldmode;
  36.377 -        if (S.token() == LBRACKET) {
  36.378 +        if (S.token() == LBRACKET || S.token() == MONKEYS_AT) {
  36.379              JCExpression e = arrayCreatorRest(newpos, t);
  36.380              if (typeArgs != null) {
  36.381                  int pos = newpos;
  36.382 @@ -1360,7 +1528,12 @@
  36.383              }
  36.384              return e;
  36.385          } else if (S.token() == LPAREN) {
  36.386 -            return classCreatorRest(newpos, null, typeArgs, t);
  36.387 +            JCNewClass newClass = classCreatorRest(newpos, null, typeArgs, t);
  36.388 +            if (newClass.def != null) {
  36.389 +                assert newClass.def.mods.annotations.isEmpty();
  36.390 +                newClass.def.mods.annotations = List.convert(JCAnnotation.class, newAnnotations);
  36.391 +            }
  36.392 +            return newClass;
  36.393          } else {
  36.394              reportSyntaxError(S.pos(), "expected2",
  36.395                                 LPAREN, LBRACKET);
  36.396 @@ -1380,40 +1553,73 @@
  36.397          return classCreatorRest(newpos, encl, typeArgs, t);
  36.398      }
  36.399  
  36.400 -    /** ArrayCreatorRest = "[" ( "]" BracketsOpt ArrayInitializer
  36.401 -     *                         | Expression "]" {"[" Expression "]"} BracketsOpt )
  36.402 +    /** ArrayCreatorRest = [Annotations] "[" ( "]" BracketsOpt ArrayInitializer
  36.403 +     *                         | Expression "]" {[Annotations]  "[" Expression "]"} BracketsOpt )
  36.404       */
  36.405      JCExpression arrayCreatorRest(int newpos, JCExpression elemtype) {
  36.406 +
  36.407 +        List<JCTypeAnnotation> topAnnos = List.nil();
  36.408 +        if (elemtype.getTag() == JCTree.ANNOTATED_TYPE) {
  36.409 +            JCAnnotatedType atype = (JCAnnotatedType) elemtype;
  36.410 +            topAnnos = atype.annotations;
  36.411 +            elemtype = atype.underlyingType;
  36.412 +        }
  36.413 +
  36.414 +        List<JCTypeAnnotation> annos = typeAnnotationsOpt();
  36.415 +
  36.416          accept(LBRACKET);
  36.417 +
  36.418          if (S.token() == RBRACKET) {
  36.419              accept(RBRACKET);
  36.420 -            elemtype = bracketsOpt(elemtype);
  36.421 +
  36.422 +            elemtype = bracketsOpt(elemtype, annos);
  36.423 +
  36.424              if (S.token() == LBRACE) {
  36.425 -                return arrayInitializer(newpos, elemtype);
  36.426 +                JCNewArray na = (JCNewArray)arrayInitializer(newpos, elemtype);
  36.427 +
  36.428 +                na.annotations = topAnnos;
  36.429 +
  36.430 +                return na;
  36.431              } else {
  36.432                  return syntaxError(S.pos(), "array.dimension.missing");
  36.433              }
  36.434          } else {
  36.435              ListBuffer<JCExpression> dims = new ListBuffer<JCExpression>();
  36.436 +
  36.437 +            // maintain array dimension type annotations
  36.438 +            ListBuffer<List<JCTypeAnnotation>> dimAnnotations = ListBuffer.lb();
  36.439 +            dimAnnotations.append(annos);
  36.440 +
  36.441              dims.append(parseExpression());
  36.442              accept(RBRACKET);
  36.443 -            while (S.token() == LBRACKET) {
  36.444 +            while (S.token() == LBRACKET
  36.445 +                    || (S.token() == MONKEYS_AT)) {
  36.446 +                List<JCTypeAnnotation> maybeDimAnnos = typeAnnotationsOpt();
  36.447                  int pos = S.pos();
  36.448                  S.nextToken();
  36.449                  if (S.token() == RBRACKET) {
  36.450 -                    elemtype = bracketsOptCont(elemtype, pos);
  36.451 +                    elemtype = bracketsOptCont(elemtype, pos, maybeDimAnnos);
  36.452                  } else {
  36.453 -                    dims.append(parseExpression());
  36.454 -                    accept(RBRACKET);
  36.455 +                    if (S.token() == RBRACKET) { // no dimension
  36.456 +                        elemtype = bracketsOptCont(elemtype, pos, maybeDimAnnos);
  36.457 +                    } else {
  36.458 +                        dimAnnotations.append(maybeDimAnnos);
  36.459 +                        dims.append(parseExpression());
  36.460 +                        accept(RBRACKET);
  36.461 +                    }
  36.462                  }
  36.463              }
  36.464 -            return toP(F.at(newpos).NewArray(elemtype, dims.toList(), null));
  36.465 +
  36.466 +            JCNewArray na = toP(F.at(newpos).NewArray(elemtype, dims.toList(), null));
  36.467 +            na.annotations = topAnnos;
  36.468 +            na.dimAnnotations = dimAnnotations.toList();
  36.469 +            return na;
  36.470          }
  36.471      }
  36.472  
  36.473      /** ClassCreatorRest = Arguments [ClassBody]
  36.474       */
  36.475 -    JCExpression classCreatorRest(int newpos,
  36.476 +    JCNewClass classCreatorRest(int newpos,
  36.477                                    JCExpression encl,
  36.478                                    List<JCExpression> typeArgs,
  36.479                                    JCExpression t)
  36.480 @@ -1860,17 +2066,32 @@
  36.481                                          new ListBuffer<JCExpressionStatement>()).toList();
  36.482      }
  36.483  
  36.484 +    enum AnnotationKind { DEFAULT_ANNO, TYPE_ANNO };
  36.485 +
  36.486      /** AnnotationsOpt = { '@' Annotation }
  36.487       */
  36.488 -    List<JCAnnotation> annotationsOpt() {
  36.489 +    List<JCAnnotation> annotationsOpt(AnnotationKind kind) {
  36.490          if (S.token() != MONKEYS_AT) return List.nil(); // optimization
  36.491          ListBuffer<JCAnnotation> buf = new ListBuffer<JCAnnotation>();
  36.492 +        int prevmode = mode;
  36.493          while (S.token() == MONKEYS_AT) {
  36.494              int pos = S.pos();
  36.495              S.nextToken();
  36.496 -            buf.append(annotation(pos));
  36.497 +            buf.append(annotation(pos, kind));
  36.498          }
  36.499 -        return buf.toList();
  36.500 +        lastmode = mode;
  36.501 +        mode = prevmode;
  36.502 +        List<JCAnnotation> annotations = buf.toList();
  36.503 +
  36.504 +        if (debugJSR308 && kind == AnnotationKind.TYPE_ANNO)
  36.505 +            System.out.println("TA: parsing " + annotations
  36.506 +                    + " in " + log.currentSourceFile());
  36.507 +        return annotations;
  36.508 +    }
  36.509 +
  36.510 +    List<JCTypeAnnotation> typeAnnotationsOpt() {
  36.511 +        List<JCAnnotation> annotations = annotationsOpt(AnnotationKind.TYPE_ANNO);
  36.512 +        return List.convert(JCTypeAnnotation.class, annotations);
  36.513      }
  36.514  
  36.515      /** ModifiersOpt = { Modifier }
  36.516 @@ -1915,7 +2136,7 @@
  36.517              if (flag == Flags.ANNOTATION) {
  36.518                  checkAnnotations();
  36.519                  if (S.token() != INTERFACE) {
  36.520 -                JCAnnotation ann = annotation(lastPos);
  36.521 +                JCAnnotation ann = annotation(lastPos, AnnotationKind.DEFAULT_ANNO);
  36.522                  // if first modifier is an annotation, set pos to annotation's.
  36.523                  if (flags == 0 && annotations.isEmpty())
  36.524                      pos = ann.pos;
  36.525 @@ -1946,12 +2167,18 @@
  36.526      /** Annotation              = "@" Qualident [ "(" AnnotationFieldValues ")" ]
  36.527       * @param pos position of "@" token
  36.528       */
  36.529 -    JCAnnotation annotation(int pos) {
  36.530 +    JCAnnotation annotation(int pos, AnnotationKind kind) {
  36.531          // accept(AT); // AT consumed by caller
  36.532          checkAnnotations();
  36.533 +        if (kind == AnnotationKind.TYPE_ANNO)
  36.534 +            checkTypeAnnotations();
  36.535          JCTree ident = qualident();
  36.536          List<JCExpression> fieldValues = annotationFieldValuesOpt();
  36.537 -        JCAnnotation ann = F.at(pos).Annotation(ident, fieldValues);
  36.538 +        JCAnnotation ann;
  36.539 +        if (kind == AnnotationKind.DEFAULT_ANNO)
  36.540 +            ann = F.at(pos).Annotation(ident, fieldValues);
  36.541 +        else
  36.542 +            ann = F.at(pos).TypeAnnotation(ident, fieldValues);
  36.543          storeEnd(ann, S.prevEndPos());
  36.544          return ann;
  36.545      }
  36.546 @@ -2003,7 +2230,7 @@
  36.547          case MONKEYS_AT:
  36.548              pos = S.pos();
  36.549              S.nextToken();
  36.550 -            return annotation(pos);
  36.551 +            return annotation(pos, AnnotationKind.DEFAULT_ANNO);
  36.552          case LBRACE:
  36.553              pos = S.pos();
  36.554              accept(LBRACE);
  36.555 @@ -2357,7 +2584,7 @@
  36.556              S.resetDeprecatedFlag();
  36.557          }
  36.558          int pos = S.pos();
  36.559 -        List<JCAnnotation> annotations = annotationsOpt();
  36.560 +        List<JCAnnotation> annotations = annotationsOpt(AnnotationKind.DEFAULT_ANNO);
  36.561          JCModifiers mods = F.at(annotations.isEmpty() ? Position.NOPOS : pos).Modifiers(flags, annotations);
  36.562          List<JCExpression> typeArgs = typeArgumentsOpt();
  36.563          int identPos = S.pos();
  36.564 @@ -2460,16 +2687,23 @@
  36.565                  if (typarams.length() > 0 && mods.pos == Position.NOPOS) {
  36.566                      mods.pos = pos;
  36.567                  }
  36.568 +
  36.569 +                List<JCAnnotation> annosAfterParams = annotationsOpt(AnnotationKind.DEFAULT_ANNO);
  36.570 +
  36.571                  Token token = S.token();
  36.572                  Name name = S.name();
  36.573                  pos = S.pos();
  36.574                  JCExpression type;
  36.575                  boolean isVoid = S.token() == VOID;
  36.576                  if (isVoid) {
  36.577 +                    if (annosAfterParams.nonEmpty())
  36.578 +                        illegal(annosAfterParams.head.pos);
  36.579                      type = to(F.at(pos).TypeIdent(TypeTags.VOID));
  36.580                      S.nextToken();
  36.581                  } else {
  36.582 -                    type = parseType();
  36.583 +                    mods.annotations = mods.annotations.appendList(annosAfterParams);
  36.584 +                    // method returns types are un-annotated types
  36.585 +                    type = unannotatedType();
  36.586                  }
  36.587                  if (S.token() == LPAREN && !isInterface && type.getTag() == JCTree.IDENT) {
  36.588                      if (isInterface || name != className)
  36.589 @@ -2505,15 +2739,15 @@
  36.590      }
  36.591  
  36.592      /** MethodDeclaratorRest =
  36.593 -     *      FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
  36.594 +     *      FormalParameters BracketsOpt [Annotations] [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
  36.595       *  VoidMethodDeclaratorRest =
  36.596 -     *      FormalParameters [Throws TypeList] ( MethodBody | ";")
  36.597 +     *      FormalParameters [Annotations] [Throws TypeList] ( MethodBody | ";")
  36.598       *  InterfaceMethodDeclaratorRest =
  36.599 -     *      FormalParameters BracketsOpt [THROWS TypeList] ";"
  36.600 +     *      FormalParameters BracketsOpt [Annotations] [THROWS TypeList] ";"
  36.601       *  VoidInterfaceMethodDeclaratorRest =
  36.602 -     *      FormalParameters [THROWS TypeList] ";"
  36.603 +     *      FormalParameters [Annotations] [THROWS TypeList] ";"
  36.604       *  ConstructorDeclaratorRest =
  36.605 -     *      "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody
  36.606 +     *      "(" FormalParameterListOpt ")" [Annotations] [THROWS TypeList] MethodBody
  36.607       */
  36.608      JCTree methodDeclaratorRest(int pos,
  36.609                                JCModifiers mods,
  36.610 @@ -2523,7 +2757,22 @@
  36.611                                boolean isInterface, boolean isVoid,
  36.612                                String dc) {
  36.613          List<JCVariableDecl> params = formalParameters();
  36.614 -        if (!isVoid) type = bracketsOpt(type);
  36.615 +
  36.616 +        List<JCTypeAnnotation> receiverAnnotations;
  36.617 +        if (!isVoid) {
  36.618 +            // need to distinguish between receiver anno and array anno
  36.619 +            // look at typeAnnotationsPushedBack comment
  36.620 +            this.permitTypeAnnotationsPushBack = true;
  36.621 +            type = methodReturnArrayRest(type);
  36.622 +            this.permitTypeAnnotationsPushBack = false;
  36.623 +            if (typeAnnotationsPushedBack == null)
  36.624 +                receiverAnnotations = List.nil();
  36.625 +            else
  36.626 +                receiverAnnotations = typeAnnotationsPushedBack;
  36.627 +            typeAnnotationsPushedBack = null;
  36.628 +        } else
  36.629 +            receiverAnnotations = typeAnnotationsOpt();
  36.630 +
  36.631          List<JCExpression> thrown = List.nil();
  36.632          if (S.token() == THROWS) {
  36.633              S.nextToken();
  36.634 @@ -2552,20 +2801,51 @@
  36.635          }
  36.636          JCMethodDecl result =
  36.637              toP(F.at(pos).MethodDef(mods, name, type, typarams,
  36.638 -                                    params, thrown,
  36.639 +                                    params, receiverAnnotations, thrown,
  36.640                                      body, defaultValue));
  36.641          attach(result, dc);
  36.642          return result;
  36.643      }
  36.644  
  36.645 -    /** QualidentList = Qualident {"," Qualident}
  36.646 +    /** Parses the array levels after the format parameters list, and append
  36.647 +     * them to the return type, while preseving the order of type annotations
  36.648 +     */
  36.649 +    private JCExpression methodReturnArrayRest(JCExpression type) {
  36.650 +        if (type.getTag() != JCTree.TYPEARRAY)
  36.651 +            return bracketsOpt(type);
  36.652 +
  36.653 +        JCArrayTypeTree baseArray = (JCArrayTypeTree)type;
  36.654 +        while (TreeInfo.typeIn(baseArray.elemtype) instanceof JCArrayTypeTree)
  36.655 +            baseArray = (JCArrayTypeTree)TreeInfo.typeIn(baseArray.elemtype);
  36.656 +
  36.657 +        if (baseArray.elemtype.getTag() == JCTree.ANNOTATED_TYPE) {
  36.658 +            JCAnnotatedType at = (JCAnnotatedType)baseArray.elemtype;
  36.659 +            at.underlyingType = bracketsOpt(at.underlyingType);
  36.660 +        } else {
  36.661 +            baseArray.elemtype = bracketsOpt(baseArray.elemtype);
  36.662 +        }
  36.663 +
  36.664 +        return type;
  36.665 +    }
  36.666 +
  36.667 +    /** QualidentList = [Annotations] Qualident {"," [Annotations] Qualident}
  36.668       */
  36.669      List<JCExpression> qualidentList() {
  36.670          ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>();
  36.671 -        ts.append(qualident());
  36.672 +
  36.673 +        List<JCTypeAnnotation> typeAnnos = typeAnnotationsOpt();
  36.674 +        if (!typeAnnos.isEmpty())
  36.675 +            ts.append(F.AnnotatedType(typeAnnos, qualident()));
  36.676 +        else
  36.677 +            ts.append(qualident());
  36.678          while (S.token() == COMMA) {
  36.679              S.nextToken();
  36.680 -            ts.append(qualident());
  36.681 +
  36.682 +            typeAnnos = typeAnnotationsOpt();
  36.683 +            if (!typeAnnos.isEmpty())
  36.684 +                ts.append(F.AnnotatedType(typeAnnos, qualident()));
  36.685 +            else
  36.686 +                ts.append(qualident());
  36.687          }
  36.688          return ts.toList();
  36.689      }
  36.690 @@ -2589,12 +2869,13 @@
  36.691          }
  36.692      }
  36.693  
  36.694 -    /** TypeParameter = TypeVariable [TypeParameterBound]
  36.695 +    /** TypeParameter = [Annotations] TypeVariable [TypeParameterBound]
  36.696       *  TypeParameterBound = EXTENDS Type {"&" Type}
  36.697       *  TypeVariable = Ident
  36.698       */
  36.699      JCTypeParameter typeParameter() {
  36.700          int pos = S.pos();
  36.701 +        List<JCTypeAnnotation> annos = typeAnnotationsOpt();
  36.702          Name name = ident();
  36.703          ListBuffer<JCExpression> bounds = new ListBuffer<JCExpression>();
  36.704          if (S.token() == EXTENDS) {
  36.705 @@ -2605,7 +2886,7 @@
  36.706                  bounds.append(parseType());
  36.707              }
  36.708          }
  36.709 -        return toP(F.at(pos).TypeParameter(name, bounds.toList()));
  36.710 +        return toP(F.at(pos).TypeParameter(name, bounds.toList(), annos));
  36.711      }
  36.712  
  36.713      /** FormalParameters = "(" [ FormalParameterList ] ")"
  36.714 @@ -2639,12 +2920,31 @@
  36.715       */
  36.716      JCVariableDecl formalParameter() {
  36.717          JCModifiers mods = optFinal(Flags.PARAMETER);
  36.718 +        // need to distinguish between vararg annos and array annos
  36.719 +        // look at typeAnnotaitonsPushedBack comment
  36.720 +        this.permitTypeAnnotationsPushBack = true;
  36.721          JCExpression type = parseType();
  36.722 +        this.permitTypeAnnotationsPushBack = false;
  36.723 +
  36.724          if (S.token() == ELLIPSIS) {
  36.725 +            List<JCTypeAnnotation> varargsAnnos = typeAnnotationsPushedBack;
  36.726 +            typeAnnotationsPushedBack = null;
  36.727              checkVarargs();
  36.728              mods.flags |= Flags.VARARGS;
  36.729 +            // insert var arg type annotations
  36.730 +            if (varargsAnnos != null && varargsAnnos.nonEmpty())
  36.731 +                type = F.at(S.pos()).AnnotatedType(varargsAnnos, type);
  36.732              type = to(F.at(S.pos()).TypeArray(type));
  36.733 +
  36.734              S.nextToken();
  36.735 +        } else {
  36.736 +            // if not a var arg, then typeAnnotationsPushedBack should be null
  36.737 +            if (typeAnnotationsPushedBack != null
  36.738 +                    && !typeAnnotationsPushedBack.isEmpty()) {
  36.739 +                reportSyntaxError(typeAnnotationsPushedBack.head.pos,
  36.740 +                        "illegal.start.of.type");
  36.741 +            }
  36.742 +            typeAnnotationsPushedBack = null;
  36.743          }
  36.744          return variableDeclaratorId(mods, type);
  36.745      }
  36.746 @@ -2829,4 +3129,10 @@
  36.747              allowAnnotations = true;
  36.748          }
  36.749      }
  36.750 +    void checkTypeAnnotations() {
  36.751 +        if (!allowTypeAnnotations) {
  36.752 +            log.error(S.pos(), "type.annotations.not.supported.in.source", source.name);
  36.753 +            allowTypeAnnotations = true;
  36.754 +        }
  36.755 +    }
  36.756  }
    37.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Fri Jun 26 10:26:27 2009 -0700
    37.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Sun Jun 28 00:01:09 2009 -0700
    37.3 @@ -50,6 +50,7 @@
    37.4  import javax.tools.JavaFileObject;
    37.5  import javax.tools.DiagnosticListener;
    37.6  
    37.7 +import com.sun.source.util.AbstractTypeProcessor;
    37.8  import com.sun.source.util.TaskEvent;
    37.9  import com.sun.source.util.TaskListener;
   37.10  import com.sun.tools.javac.api.JavacTaskImpl;
   37.11 @@ -58,6 +59,7 @@
   37.12  import com.sun.tools.javac.file.JavacFileManager;
   37.13  import com.sun.tools.javac.jvm.*;
   37.14  import com.sun.tools.javac.main.JavaCompiler;
   37.15 +import com.sun.tools.javac.main.JavaCompiler.CompileState;
   37.16  import com.sun.tools.javac.model.JavacElements;
   37.17  import com.sun.tools.javac.model.JavacTypes;
   37.18  import com.sun.tools.javac.parser.*;
   37.19 @@ -93,6 +95,7 @@
   37.20      private final boolean lint;
   37.21      private final boolean procOnly;
   37.22      private final boolean fatalErrors;
   37.23 +    private boolean foundTypeProcessors;
   37.24  
   37.25      private final JavacFiler filer;
   37.26      private final JavacMessager messager;
   37.27 @@ -153,6 +156,7 @@
   37.28              options.get("-Xprint") != null;
   37.29          fatalErrors = options.get("fatalEnterError") != null;
   37.30          platformAnnotations = initPlatformAnnotations();
   37.31 +        foundTypeProcessors = false;
   37.32  
   37.33          // Initialize services before any processors are initialzied
   37.34          // in case processors use them.
   37.35 @@ -670,6 +674,7 @@
   37.36              }
   37.37  
   37.38              if (matchedNames.size() > 0 || ps.contributed) {
   37.39 +                foundTypeProcessors = foundTypeProcessors || (ps.processor instanceof AbstractTypeProcessor);
   37.40                  boolean processingResult = callProcessor(ps.processor, typeElements, renv);
   37.41                  ps.contributed = true;
   37.42                  ps.removeSupportedOptions(unmatchedProcessorOptions);
   37.43 @@ -916,12 +921,16 @@
   37.44              compiler.log.nerrors += messager.errorCount();
   37.45              if (compiler.errorCount() == 0)
   37.46                  compiler.log.nerrors++;
   37.47 -        } else if (procOnly) {
   37.48 +        } else if (procOnly && !foundTypeProcessors) {
   37.49              compiler.todo.clear();
   37.50          } else { // Final compilation
   37.51              compiler.close(false);
   37.52              currentContext = contextForNextRound(currentContext, true);
   37.53 +            this.context = currentContext;
   37.54 +            updateProcessingState(currentContext, true);
   37.55              compiler = JavaCompiler.instance(currentContext);
   37.56 +            if (procOnly && foundTypeProcessors)
   37.57 +                compiler.shouldStopPolicy = CompileState.FLOW;
   37.58  
   37.59              if (true) {
   37.60                  compiler.enterTrees(cleanTrees(roots));
   37.61 @@ -1213,6 +1222,10 @@
   37.62                  node.sym = null;
   37.63                  super.visitIdent(node);
   37.64              }
   37.65 +            public void visitApply(JCMethodInvocation node) {
   37.66 +                scan(node.typeargs);
   37.67 +                super.visitApply(node);
   37.68 +            }
   37.69          };
   37.70  
   37.71  
    38.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java	Fri Jun 26 10:26:27 2009 -0700
    38.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java	Sun Jun 28 00:01:09 2009 -0700
    38.3 @@ -37,6 +37,9 @@
    38.4  /**
    38.5   * Object providing state about a prior round of annotation processing.
    38.6   *
    38.7 + * <p>The methods in this class do not take type annotations into account,
    38.8 + * as target types, not java elements.
    38.9 + *
   38.10   * <p><b>This is NOT part of any API supported by Sun Microsystems.
   38.11   * If you write code that depends on this, you do so at your own risk.
   38.12   * This code and its internal interfaces are subject to change or
    39.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Jun 26 10:26:27 2009 -0700
    39.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Sun Jun 28 00:01:09 2009 -0700
    39.3 @@ -882,6 +882,8 @@
    39.4      bad constant pool tag: {0} at {1}
    39.5  compiler.misc.bad.signature=\
    39.6      bad signature: {0}
    39.7 +compiler.misc.bad.type.annotation.value=\
    39.8 +    bad type annotation target type value: {0}
    39.9  compiler.misc.class.file.wrong.class=\
   39.10      class file contains wrong class: {0}
   39.11  compiler.misc.class.file.not.found=\
   39.12 @@ -1162,6 +1164,10 @@
   39.13      annotations are not supported in -source {0}\n\
   39.14  (use -source 5 or higher to enable annotations)
   39.15  
   39.16 +compiler.err.type.annotations.not.supported.in.source=\
   39.17 +    type annotations are not supported in -source {0}\n\
   39.18 +(use -source 7 or higher to enable type annotations)
   39.19 +
   39.20  compiler.err.foreach.not.supported.in.source=\
   39.21      for-each loops are not supported in -source {0}\n\
   39.22  (use -source 5 or higher to enable for-each loops)
    40.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Fri Jun 26 10:26:27 2009 -0700
    40.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Sun Jun 28 00:01:09 2009 -0700
    40.3 @@ -256,9 +256,11 @@
    40.4       */
    40.5      public static final int MODIFIERS = ANNOTATION + 1;
    40.6  
    40.7 +    public static final int ANNOTATED_TYPE = MODIFIERS + 1;
    40.8 +
    40.9      /** Error trees, of type Erroneous.
   40.10       */
   40.11 -    public static final int ERRONEOUS = MODIFIERS + 1;
   40.12 +    public static final int ERRONEOUS = ANNOTATED_TYPE + 1;
   40.13  
   40.14      /** Unary operators, of type Unary.
   40.15       */
   40.16 @@ -622,6 +624,7 @@
   40.17          public JCExpression restype;
   40.18          public List<JCTypeParameter> typarams;
   40.19          public List<JCVariableDecl> params;
   40.20 +        public List<JCTypeAnnotation> receiverAnnotations;
   40.21          public List<JCExpression> thrown;
   40.22          public JCBlock body;
   40.23          public JCExpression defaultValue; // for annotation types
   40.24 @@ -631,6 +634,7 @@
   40.25                              JCExpression restype,
   40.26                              List<JCTypeParameter> typarams,
   40.27                              List<JCVariableDecl> params,
   40.28 +                            List<JCTypeAnnotation> receiver,
   40.29                              List<JCExpression> thrown,
   40.30                              JCBlock body,
   40.31                              JCExpression defaultValue,
   40.32 @@ -641,6 +645,7 @@
   40.33              this.restype = restype;
   40.34              this.typarams = typarams;
   40.35              this.params = params;
   40.36 +            this.receiverAnnotations = (receiver != null ? receiver : List.<JCTypeAnnotation>nil());
   40.37              this.thrown = thrown;
   40.38              this.body = body;
   40.39              this.defaultValue = defaultValue;
   40.40 @@ -659,6 +664,7 @@
   40.41          public List<JCVariableDecl> getParameters() {
   40.42              return params;
   40.43          }
   40.44 +        public List<JCTypeAnnotation> getReceiverAnnotations() { return receiverAnnotations; }
   40.45          public List<JCExpression> getThrows() {
   40.46              return thrown;
   40.47          }
   40.48 @@ -1371,6 +1377,8 @@
   40.49      public static class JCNewArray extends JCExpression implements NewArrayTree {
   40.50          public JCExpression elemtype;
   40.51          public List<JCExpression> dims;
   40.52 +        public List<JCTypeAnnotation> annotations;
   40.53 +        public List<List<JCTypeAnnotation>> dimAnnotations;
   40.54          public List<JCExpression> elems;
   40.55          protected JCNewArray(JCExpression elemtype,
   40.56                             List<JCExpression> dims,
   40.57 @@ -1378,6 +1386,8 @@
   40.58          {
   40.59              this.elemtype = elemtype;
   40.60              this.dims = dims;
   40.61 +            this.annotations = List.nil();
   40.62 +            this.dimAnnotations = List.nil();
   40.63              this.elems = elems;
   40.64          }
   40.65          @Override
   40.66 @@ -1860,9 +1870,11 @@
   40.67      public static class JCTypeParameter extends JCTree implements TypeParameterTree {
   40.68          public Name name;
   40.69          public List<JCExpression> bounds;
   40.70 -        protected JCTypeParameter(Name name, List<JCExpression> bounds) {
   40.71 +        public List<JCTypeAnnotation> annotations;
   40.72 +        protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCTypeAnnotation> annotations) {
   40.73              this.name = name;
   40.74              this.bounds = bounds;
   40.75 +            this.annotations = annotations;
   40.76          }
   40.77          @Override
   40.78          public void accept(Visitor v) { v.visitTypeParameter(this); }
   40.79 @@ -1872,6 +1884,9 @@
   40.80          public List<JCExpression> getBounds() {
   40.81              return bounds;
   40.82          }
   40.83 +        public List<JCTypeAnnotation> getAnnotations() {
   40.84 +            return annotations;
   40.85 +        }
   40.86          @Override
   40.87          public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   40.88              return v.visitTypeParameter(this, d);
   40.89 @@ -1962,6 +1977,16 @@
   40.90          }
   40.91      }
   40.92  
   40.93 +    public static class JCTypeAnnotation extends JCAnnotation {
   40.94 +        public TypeAnnotationPosition annotation_position;
   40.95 +        public Attribute.TypeCompound attribute_field;
   40.96 +
   40.97 +        protected JCTypeAnnotation(JCTree annotationType, List<JCExpression> args) {
   40.98 +            super(annotationType, args);
   40.99 +            this.annotation_position = new TypeAnnotationPosition();
  40.100 +        }
  40.101 +    }
  40.102 +
  40.103      public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
  40.104          public long flags;
  40.105          public List<JCAnnotation> annotations;
  40.106 @@ -1989,6 +2014,33 @@
  40.107          }
  40.108      }
  40.109  
  40.110 +    public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
  40.111 +        public List<JCTypeAnnotation> annotations;
  40.112 +        public JCExpression underlyingType;
  40.113 +        protected JCAnnotatedType(List<JCTypeAnnotation> annotations, JCExpression underlyingType) {
  40.114 +            this.annotations = annotations;
  40.115 +            this.underlyingType = underlyingType;
  40.116 +        }
  40.117 +        @Override
  40.118 +        public void accept(Visitor v) { v.visitAnnotatedType(this); }
  40.119 +
  40.120 +        public Kind getKind() { return Kind.ANNOTATED_TYPE; }
  40.121 +        public List<JCTypeAnnotation> getAnnotations() {
  40.122 +            return annotations;
  40.123 +        }
  40.124 +        public JCExpression getUnderlyingType() {
  40.125 +            return underlyingType;
  40.126 +        }
  40.127 +        @Override
  40.128 +        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  40.129 +            return v.visitAnnotatedType(this, d);
  40.130 +        }
  40.131 +        @Override
  40.132 +        public int getTag() {
  40.133 +            return ANNOTATED_TYPE;
  40.134 +        }
  40.135 +    }
  40.136 +
  40.137      public static class JCErroneous extends JCExpression
  40.138              implements com.sun.source.tree.ErroneousTree {
  40.139          public List<? extends JCTree> errs;
  40.140 @@ -2056,6 +2108,7 @@
  40.141                              JCExpression restype,
  40.142                              List<JCTypeParameter> typarams,
  40.143                              List<JCVariableDecl> params,
  40.144 +                            List<JCTypeAnnotation> receiver,
  40.145                              List<JCExpression> thrown,
  40.146                              JCBlock body,
  40.147                              JCExpression defaultValue);
  40.148 @@ -2172,6 +2225,7 @@
  40.149          public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
  40.150          public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
  40.151          public void visitModifiers(JCModifiers that)         { visitTree(that); }
  40.152 +        public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
  40.153          public void visitErroneous(JCErroneous that)         { visitTree(that); }
  40.154          public void visitLetExpr(LetExpr that)               { visitTree(that); }
  40.155  
    41.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Fri Jun 26 10:26:27 2009 -0700
    41.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Sun Jun 28 00:01:09 2009 -0700
    41.3 @@ -224,6 +224,15 @@
    41.4          }
    41.5      }
    41.6  
    41.7 +    public void printTypeAnnotations(List<JCTypeAnnotation> trees) throws IOException {
    41.8 +        if (trees.nonEmpty())
    41.9 +            print(" ");
   41.10 +        for (List<JCTypeAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
   41.11 +            printExpr(l.head);
   41.12 +            print(" ");
   41.13 +        }
   41.14 +    }
   41.15 +
   41.16      /** Print documentation comment, if it exists
   41.17       *  @param tree    The tree for which a documentation comment should be printed.
   41.18       */
   41.19 @@ -850,21 +859,33 @@
   41.20          try {
   41.21              if (tree.elemtype != null) {
   41.22                  print("new ");
   41.23 +                printTypeAnnotations(tree.annotations);
   41.24                  JCTree elem = tree.elemtype;
   41.25 -                if (elem instanceof JCArrayTypeTree)
   41.26 -                    printBaseElementType((JCArrayTypeTree) elem);
   41.27 -                else
   41.28 -                    printExpr(elem);
   41.29 +                printBaseElementType(elem);
   41.30 +                boolean isElemAnnoType = elem instanceof JCAnnotatedType;
   41.31 +                int i = 0;
   41.32 +                List<List<JCTypeAnnotation>> da = tree.dimAnnotations;
   41.33                  for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
   41.34 +                    if (da.size() > i) {
   41.35 +                        printTypeAnnotations(da.get(i));
   41.36 +                    }
   41.37                      print("[");
   41.38 +                    i++;
   41.39                      printExpr(l.head);
   41.40                      print("]");
   41.41                  }
   41.42 +                if (tree.elems != null) {
   41.43 +                    if (isElemAnnoType) {
   41.44 +                        printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations);
   41.45 +                    }
   41.46 +                    print("[]");
   41.47 +                }
   41.48 +                if (isElemAnnoType)
   41.49 +                    elem = ((JCAnnotatedType)elem).underlyingType;
   41.50                  if (elem instanceof JCArrayTypeTree)
   41.51                      printBrackets((JCArrayTypeTree) elem);
   41.52              }
   41.53              if (tree.elems != null) {
   41.54 -                if (tree.elemtype != null) print("[]");
   41.55                  print("{");
   41.56                  printExprs(tree.elems);
   41.57                  print("}");
   41.58 @@ -1112,14 +1133,21 @@
   41.59      }
   41.60  
   41.61      // Prints the inner element type of a nested array
   41.62 -    private void printBaseElementType(JCArrayTypeTree tree) throws IOException {
   41.63 -        JCTree elem = tree.elemtype;
   41.64 -        while (elem instanceof JCWildcard)
   41.65 -            elem = ((JCWildcard) elem).inner;
   41.66 -        if (elem instanceof JCArrayTypeTree)
   41.67 -            printBaseElementType((JCArrayTypeTree) elem);
   41.68 -        else
   41.69 -            printExpr(elem);
   41.70 +    private void printBaseElementType(JCTree tree) throws IOException {
   41.71 +        switch (tree.getTag()) {
   41.72 +        case JCTree.TYPEARRAY:
   41.73 +            printBaseElementType(((JCArrayTypeTree)tree).elemtype);
   41.74 +            return;
   41.75 +        case JCTree.WILDCARD:
   41.76 +            printBaseElementType(((JCWildcard)tree).inner);
   41.77 +            return;
   41.78 +        case JCTree.ANNOTATED_TYPE:
   41.79 +            printBaseElementType(((JCAnnotatedType)tree).underlyingType);
   41.80 +            return;
   41.81 +        default:
   41.82 +            printExpr(tree);
   41.83 +            return;
   41.84 +        }
   41.85      }
   41.86  
   41.87      // prints the brackets of a nested array in reverse order
   41.88 @@ -1127,8 +1155,13 @@
   41.89          JCTree elem;
   41.90          while (true) {
   41.91              elem = tree.elemtype;
   41.92 +            if (elem.getTag() == JCTree.ANNOTATED_TYPE) {
   41.93 +                JCAnnotatedType atype = (JCAnnotatedType) elem;
   41.94 +                printTypeAnnotations(atype.annotations);
   41.95 +                elem = atype.underlyingType;
   41.96 +            }
   41.97              print("[]");
   41.98 -            if (!(elem instanceof JCArrayTypeTree)) break;
   41.99 +            if (elem.getTag() != JCTree.TYPEARRAY) break;
  41.100              tree = (JCArrayTypeTree) elem;
  41.101          }
  41.102      }
  41.103 @@ -1213,6 +1246,15 @@
  41.104          }
  41.105      }
  41.106  
  41.107 +    public void visitAnnotatedType(JCAnnotatedType tree) {
  41.108 +        try {
  41.109 +            printTypeAnnotations(tree.annotations);
  41.110 +            printExpr(tree.underlyingType);
  41.111 +        } catch (IOException e) {
  41.112 +            throw new UncheckedIOException(e);
  41.113 +        }
  41.114 +    }
  41.115 +
  41.116      public void visitTree(JCTree tree) {
  41.117          try {
  41.118              print("(UNKNOWN: " + tree + ")");
  41.119 @@ -1221,4 +1263,5 @@
  41.120              throw new UncheckedIOException(e);
  41.121          }
  41.122      }
  41.123 +
  41.124  }
    42.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Fri Jun 26 10:26:27 2009 -0700
    42.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Sun Jun 28 00:01:09 2009 -0700
    42.3 @@ -71,6 +71,13 @@
    42.4          return lb.toList();
    42.5      }
    42.6  
    42.7 +    public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) {
    42.8 +        JCAnnotatedType t = (JCAnnotatedType) node;
    42.9 +        List<JCTypeAnnotation> annotations = copy(t.annotations, p);
   42.10 +        JCExpression underlyingType = copy(t.underlyingType, p);
   42.11 +        return M.at(t.pos).AnnotatedType(annotations, underlyingType);
   42.12 +    }
   42.13 +
   42.14      public JCTree visitAnnotation(AnnotationTree node, P p) {
   42.15          JCAnnotation t = (JCAnnotation) node;
   42.16          JCTree annotationType = copy(t.annotationType, p);
   42.17 @@ -233,10 +240,11 @@
   42.18          JCExpression restype = copy(t.restype, p);
   42.19          List<JCTypeParameter> typarams = copy(t.typarams, p);
   42.20          List<JCVariableDecl> params = copy(t.params, p);
   42.21 +        List<JCTypeAnnotation> receiver = copy(t.receiverAnnotations, p);
   42.22          List<JCExpression> thrown = copy(t.thrown, p);
   42.23          JCBlock body = copy(t.body, p);
   42.24          JCExpression defaultValue = copy(t.defaultValue, p);
   42.25 -        return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, params, thrown, body, defaultValue);
   42.26 +        return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, params, receiver, thrown, body, defaultValue);
   42.27      }
   42.28  
   42.29      public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
   42.30 @@ -357,8 +365,9 @@
   42.31  
   42.32      public JCTree visitTypeParameter(TypeParameterTree node, P p) {
   42.33          JCTypeParameter t = (JCTypeParameter) node;
   42.34 +        List<JCTypeAnnotation> annos = copy(t.annotations, p);
   42.35          List<JCExpression> bounds = copy(t.bounds, p);
   42.36 -        return M.at(t.pos).TypeParameter(t.name, t.bounds);
   42.37 +        return M.at(t.pos).TypeParameter(t.name, bounds, annos);
   42.38      }
   42.39  
   42.40      public JCTree visitInstanceOf(InstanceOfTree node, P p) {
    43.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Fri Jun 26 10:26:27 2009 -0700
    43.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Sun Jun 28 00:01:09 2009 -0700
    43.3 @@ -298,6 +298,8 @@
    43.4          case(JCTree.POSTINC):
    43.5          case(JCTree.POSTDEC):
    43.6              return getStartPos(((JCUnary) tree).arg);
    43.7 +        case(JCTree.ANNOTATED_TYPE):
    43.8 +            return getStartPos(((JCAnnotatedType) tree).underlyingType);
    43.9          case(JCTree.VARDEF): {
   43.10              JCVariableDecl node = (JCVariableDecl)tree;
   43.11              if (node.mods.pos != Position.NOPOS) {
   43.12 @@ -859,4 +861,25 @@
   43.13              return null;
   43.14          }
   43.15      }
   43.16 +
   43.17 +    /**
   43.18 +     * Returns the underlying type of the tree if it is annotated type,
   43.19 +     * or the tree itself otherwise
   43.20 +     */
   43.21 +    public static JCExpression typeIn(JCExpression tree) {
   43.22 +        switch (tree.getTag()) {
   43.23 +        case JCTree.ANNOTATED_TYPE:
   43.24 +            return ((JCAnnotatedType)tree).underlyingType;
   43.25 +        case JCTree.IDENT: /* simple names */
   43.26 +        case JCTree.TYPEIDENT: /* primitive name */
   43.27 +        case JCTree.SELECT: /* qualified name */
   43.28 +        case JCTree.TYPEARRAY: /* array types */
   43.29 +        case JCTree.WILDCARD: /* wild cards */
   43.30 +        case JCTree.TYPEPARAMETER: /* type parameters */
   43.31 +        case JCTree.TYPEAPPLY: /* parameterized types */
   43.32 +            return tree;
   43.33 +        default:
   43.34 +            throw new AssertionError("Unexpected type tree: " + tree);
   43.35 +        }
   43.36 +    }
   43.37  }
    44.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Fri Jun 26 10:26:27 2009 -0700
    44.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sun Jun 28 00:01:09 2009 -0700
    44.3 @@ -168,6 +168,20 @@
    44.4                                 List<JCVariableDecl> params,
    44.5                                 List<JCExpression> thrown,
    44.6                                 JCBlock body,
    44.7 +                               JCExpression defaultValue) {
    44.8 +        return MethodDef(
    44.9 +                mods, name, restype, typarams, params,
   44.10 +                null, thrown, body, defaultValue);
   44.11 +    }
   44.12 +
   44.13 +    public JCMethodDecl MethodDef(JCModifiers mods,
   44.14 +                               Name name,
   44.15 +                               JCExpression restype,
   44.16 +                               List<JCTypeParameter> typarams,
   44.17 +                               List<JCVariableDecl> params,
   44.18 +                               List<JCTypeAnnotation> receiver,
   44.19 +                               List<JCExpression> thrown,
   44.20 +                               JCBlock body,
   44.21                                 JCExpression defaultValue)
   44.22      {
   44.23          JCMethodDecl tree = new JCMethodDecl(mods,
   44.24 @@ -175,6 +189,7 @@
   44.25                                         restype,
   44.26                                         typarams,
   44.27                                         params,
   44.28 +                                       receiver,
   44.29                                         thrown,
   44.30                                         body,
   44.31                                         defaultValue,
   44.32 @@ -430,7 +445,11 @@
   44.33      }
   44.34  
   44.35      public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds) {
   44.36 -        JCTypeParameter tree = new JCTypeParameter(name, bounds);
   44.37 +        return TypeParameter(name, bounds, List.<JCTypeAnnotation>nil());
   44.38 +    }
   44.39 +
   44.40 +    public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds, List<JCTypeAnnotation> annos) {
   44.41 +        JCTypeParameter tree = new JCTypeParameter(name, bounds, annos);
   44.42          tree.pos = pos;
   44.43          return tree;
   44.44      }
   44.45 @@ -453,6 +472,12 @@
   44.46          return tree;
   44.47      }
   44.48  
   44.49 +    public JCTypeAnnotation TypeAnnotation(JCTree annotationType, List<JCExpression> args) {
   44.50 +        JCTypeAnnotation tree = new JCTypeAnnotation(annotationType, args);
   44.51 +        tree.pos = pos;
   44.52 +        return tree;
   44.53 +    }
   44.54 +
   44.55      public JCModifiers Modifiers(long flags, List<JCAnnotation> annotations) {
   44.56          JCModifiers tree = new JCModifiers(flags, annotations);
   44.57          boolean noFlags = (flags & Flags.StandardFlags) == 0;
   44.58 @@ -464,6 +489,12 @@
   44.59          return Modifiers(flags, List.<JCAnnotation>nil());
   44.60      }
   44.61  
   44.62 +    public JCAnnotatedType AnnotatedType(List<JCTypeAnnotation> annotations, JCExpression underlyingType) {
   44.63 +        JCAnnotatedType tree = new JCAnnotatedType(annotations, underlyingType);
   44.64 +        tree.pos = pos;
   44.65 +        return tree;
   44.66 +    }
   44.67 +
   44.68      public JCErroneous Erroneous() {
   44.69          return Erroneous(List.<JCTree>nil());
   44.70      }
   44.71 @@ -772,6 +803,7 @@
   44.72                  Type(mtype.getReturnType()),
   44.73                  TypeParams(mtype.getTypeArguments()),
   44.74                  Params(mtype.getParameterTypes(), m),
   44.75 +                null,
   44.76                  Types(mtype.getThrownTypes()),
   44.77                  body,
   44.78                  null,
    45.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Fri Jun 26 10:26:27 2009 -0700
    45.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Sun Jun 28 00:01:09 2009 -0700
    45.3 @@ -85,6 +85,7 @@
    45.4          scan(tree.restype);
    45.5          scan(tree.typarams);
    45.6          scan(tree.params);
    45.7 +        scan(tree.receiverAnnotations);
    45.8          scan(tree.thrown);
    45.9          scan(tree.defaultValue);
   45.10          scan(tree.body);
   45.11 @@ -204,8 +205,11 @@
   45.12      }
   45.13  
   45.14      public void visitNewArray(JCNewArray tree) {
   45.15 +        scan(tree.annotations);
   45.16          scan(tree.elemtype);
   45.17          scan(tree.dims);
   45.18 +        for (List<JCTypeAnnotation> annos : tree.dimAnnotations)
   45.19 +            scan(annos);
   45.20          scan(tree.elems);
   45.21      }
   45.22  
   45.23 @@ -270,6 +274,7 @@
   45.24      }
   45.25  
   45.26      public void visitTypeParameter(JCTypeParameter tree) {
   45.27 +        scan(tree.annotations);
   45.28          scan(tree.bounds);
   45.29      }
   45.30  
   45.31 @@ -293,6 +298,11 @@
   45.32          scan(tree.args);
   45.33      }
   45.34  
   45.35 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   45.36 +        scan(tree.annotations);
   45.37 +        scan(tree.underlyingType);
   45.38 +    }
   45.39 +
   45.40      public void visitErroneous(JCErroneous tree) {
   45.41      }
   45.42  
    46.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Fri Jun 26 10:26:27 2009 -0700
    46.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Sun Jun 28 00:01:09 2009 -0700
    46.3 @@ -282,6 +282,11 @@
    46.4      }
    46.5  
    46.6      public void visitNewArray(JCNewArray tree) {
    46.7 +        tree.annotations = translate(tree.annotations);
    46.8 +        List<List<JCTypeAnnotation>> dimAnnos = List.nil();
    46.9 +        for (List<JCTypeAnnotation> origDimAnnos : tree.dimAnnotations)
   46.10 +            dimAnnos = dimAnnos.append(translate(origDimAnnos));
   46.11 +        tree.dimAnnotations = dimAnnos;
   46.12          tree.elemtype = translate(tree.elemtype);
   46.13          tree.dims = translate(tree.dims);
   46.14          tree.elems = translate(tree.elems);
   46.15 @@ -363,6 +368,7 @@
   46.16      }
   46.17  
   46.18      public void visitTypeParameter(JCTypeParameter tree) {
   46.19 +        tree.annotations = translate(tree.annotations);
   46.20          tree.bounds = translate(tree.bounds);
   46.21          result = tree;
   46.22      }
   46.23 @@ -400,6 +406,12 @@
   46.24          result = tree;
   46.25      }
   46.26  
   46.27 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   46.28 +        tree.annotations = translate(tree.annotations);
   46.29 +        tree.underlyingType = translate(tree.underlyingType);
   46.30 +        result = tree;
   46.31 +    }
   46.32 +
   46.33      public void visitTree(JCTree tree) {
   46.34          throw new AssertionError(tree);
   46.35      }
    47.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java	Fri Jun 26 10:26:27 2009 -0700
    47.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Sun Jun 28 00:01:09 2009 -0700
    47.3 @@ -99,6 +99,8 @@
    47.4      public final Name Annotation;
    47.5      public final Name RuntimeVisibleAnnotations;
    47.6      public final Name RuntimeInvisibleAnnotations;
    47.7 +    public final Name RuntimeVisibleTypeAnnotations;
    47.8 +    public final Name RuntimeInvisibleTypeAnnotations;
    47.9      public final Name RuntimeVisibleParameterAnnotations;
   47.10      public final Name RuntimeInvisibleParameterAnnotations;
   47.11      public final Name Value;
   47.12 @@ -115,6 +117,8 @@
   47.13      public final Name getClass;
   47.14      public final Name invoke;
   47.15      public final Name TYPE;
   47.16 +    public final Name TYPE_USE;
   47.17 +    public final Name TYPE_PARAMETER;
   47.18      public final Name FIELD;
   47.19      public final Name METHOD;
   47.20      public final Name PARAMETER;
   47.21 @@ -205,6 +209,8 @@
   47.22          Annotation = fromString("Annotation");
   47.23          RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
   47.24          RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
   47.25 +        RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
   47.26 +        RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
   47.27          RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
   47.28          RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
   47.29          Value = fromString("Value");
   47.30 @@ -224,6 +230,8 @@
   47.31          invoke = fromString("invoke");
   47.32  
   47.33          TYPE = fromString("TYPE");
   47.34 +        TYPE_USE = fromString("TYPE_USE");
   47.35 +        TYPE_PARAMETER = fromString("TYPE_PARAMETER");
   47.36          FIELD = fromString("FIELD");
   47.37          METHOD = fromString("METHOD");
   47.38          PARAMETER = fromString("PARAMETER");
    48.1 --- a/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Fri Jun 26 10:26:27 2009 -0700
    48.2 +++ b/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Sun Jun 28 00:01:09 2009 -0700
    48.3 @@ -26,6 +26,7 @@
    48.4  package com.sun.tools.javap;
    48.5  
    48.6  import com.sun.tools.classfile.Annotation;
    48.7 +import com.sun.tools.classfile.ExtendedAnnotation;
    48.8  import com.sun.tools.classfile.Annotation.Annotation_element_value;
    48.9  import com.sun.tools.classfile.Annotation.Array_element_value;
   48.10  import com.sun.tools.classfile.Annotation.Class_element_value;
   48.11 @@ -62,6 +63,12 @@
   48.12          print(")");
   48.13      }
   48.14  
   48.15 +    public void write(ExtendedAnnotation annot) {
   48.16 +        write(annot.annotation);
   48.17 +        print('@');
   48.18 +        print(annot.position.toString());
   48.19 +    }
   48.20 +
   48.21      public void write(Annotation.element_value_pair pair) {
   48.22          print("#" + pair.element_name_index + ":");
   48.23          write(pair.value);
    49.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Fri Jun 26 10:26:27 2009 -0700
    49.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Sun Jun 28 00:01:09 2009 -0700
    49.3 @@ -51,8 +51,10 @@
    49.4  import com.sun.tools.classfile.Module_attribute;
    49.5  import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
    49.6  import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
    49.7 +import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute;
    49.8  import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
    49.9  import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
   49.10 +import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute;
   49.11  import com.sun.tools.classfile.Signature_attribute;
   49.12  import com.sun.tools.classfile.SourceDebugExtension_attribute;
   49.13  import com.sun.tools.classfile.SourceFile_attribute;
   49.14 @@ -434,6 +436,26 @@
   49.15          return null;
   49.16      }
   49.17  
   49.18 +    public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, Void ignore) {
   49.19 +        println("  RuntimeVisibleTypeAnnotations: ");
   49.20 +        for (int i = 0; i < attr.annotations.length; i++) {
   49.21 +            print("    " + i + ": ");
   49.22 +            annotationWriter.write(attr.annotations[i]);
   49.23 +            println();
   49.24 +        }
   49.25 +        return null;
   49.26 +    }
   49.27 +
   49.28 +    public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, Void ignore) {
   49.29 +        println("  RuntimeInvisibleTypeAnnotations: ");
   49.30 +        for (int i = 0; i < attr.annotations.length; i++) {
   49.31 +            print("    " + i + ": ");
   49.32 +            annotationWriter.write(attr.annotations[i]);
   49.33 +            println();
   49.34 +        }
   49.35 +        return null;
   49.36 +    }
   49.37 +
   49.38      public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) {
   49.39          println("  RuntimeVisibleParameterAnnotations: ");
   49.40          for (int param = 0; param < attr.parameter_annotations.length; param++) {
    50.1 --- a/src/share/classes/javax/lang/model/type/MirroredTypeException.java	Fri Jun 26 10:26:27 2009 -0700
    50.2 +++ b/src/share/classes/javax/lang/model/type/MirroredTypeException.java	Sun Jun 28 00:01:09 2009 -0700
    50.3 @@ -54,7 +54,7 @@
    50.4       * @param type  the type being accessed
    50.5       */
    50.6      public MirroredTypeException(TypeMirror type) {
    50.7 -        super("Attempt to access Class object for TypeMirror " + type);
    50.8 +        super("Attempt to access Class object for TypeMirror " + type.toString());
    50.9          this.type = type;
   50.10      }
   50.11  
    51.1 --- a/test/tools/javac/6341866/T6341866.java	Fri Jun 26 10:26:27 2009 -0700
    51.2 +++ b/test/tools/javac/6341866/T6341866.java	Sun Jun 28 00:01:09 2009 -0700
    51.3 @@ -97,7 +97,7 @@
    51.4          processorServices.delete();
    51.5  
    51.6          List<String> opts = new ArrayList<String>();
    51.7 -        opts.addAll(Arrays.asList("-d", ".", "-sourcepath", testSrc, "-classpath", testClasses));
    51.8 +        opts.addAll(Arrays.asList("-d", ".", "-sourcepath", testSrc, "-classpath", testClasses, "-source", "1.6"));
    51.9          if (implicitType.opt != null)
   51.10              opts.add(implicitType.opt);
   51.11  
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/test/tools/javac/api/TestTreePath.java	Sun Jun 28 00:01:09 2009 -0700
    52.3 @@ -0,0 +1,124 @@
    52.4 +/*
    52.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
    52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    52.7 + *
    52.8 + * This code is free software; you can redistribute it and/or modify it
    52.9 + * under the terms of the GNU General Public License version 2 only, as
   52.10 + * published by the Free Software Foundation.
   52.11 + *
   52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   52.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   52.15 + * version 2 for more details (a copy is included in the LICENSE file that
   52.16 + * accompanied this code).
   52.17 + *
   52.18 + * You should have received a copy of the GNU General Public License version
   52.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   52.21 + *
   52.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   52.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   52.24 + * have any questions.
   52.25 + */
   52.26 +
   52.27 +/*
   52.28 + * @test
   52.29 + * @bug 6473148
   52.30 + * @summary TreePath.iterator() throws NPE
   52.31 + */
   52.32 +import java.io.*;
   52.33 +import java.util.Arrays;
   52.34 +import java.util.Iterator;
   52.35 +import java.util.Set;
   52.36 +
   52.37 +import javax.annotation.processing.*;
   52.38 +import javax.lang.model.SourceVersion;
   52.39 +import javax.lang.model.element.Element;
   52.40 +import javax.lang.model.element.TypeElement;
   52.41 +import javax.lang.model.util.ElementFilter;
   52.42 +import javax.tools.JavaCompiler;
   52.43 +import javax.tools.JavaFileObject;
   52.44 +import javax.tools.StandardJavaFileManager;
   52.45 +import javax.tools.ToolProvider;
   52.46 +
   52.47 +import com.sun.source.tree.Tree;
   52.48 +import com.sun.source.util.*;
   52.49 +
   52.50 +@SupportedAnnotationTypes("*")
   52.51 +public class TestTreePath extends AbstractProcessor {
   52.52 +
   52.53 +    @Override
   52.54 +    public boolean process(Set<? extends TypeElement> annotations,
   52.55 +            RoundEnvironment roundEnv) {
   52.56 +        final Trees trees = Trees.instance(this.processingEnv);
   52.57 +        for (Element element : ElementFilter.typesIn(roundEnv.getRootElements())) {
   52.58 +            checkTreePath(trees, element, 2);
   52.59 +            for (Element member : element.getEnclosedElements())
   52.60 +                checkTreePath(trees, member, 3);
   52.61 +        }
   52.62 +        return true;
   52.63 +    }
   52.64 +
   52.65 +    private void checkTreePath(Trees trees, Element element, int expectedLength) {
   52.66 +        TreePath path = trees.getPath(element);
   52.67 +        assert path != null;
   52.68 +
   52.69 +        int enhancedLength = 0;
   52.70 +        for (Tree tree : path)
   52.71 +            ++enhancedLength;
   52.72 +
   52.73 +        if (enhancedLength != expectedLength)
   52.74 +            throw new RuntimeException("found path length is wrong");
   52.75 +
   52.76 +        int normalLoopLength = 0;
   52.77 +        Iterator<Tree> iter = path.iterator();
   52.78 +        while (iter.hasNext()) {
   52.79 +          iter.next();
   52.80 +          ++normalLoopLength;
   52.81 +        }
   52.82 +        if (normalLoopLength != expectedLength)
   52.83 +            throw new RuntimeException("found path length is wrong");
   52.84 +
   52.85 +        TreePath curr = path;
   52.86 +        // using getParent
   52.87 +        int whileLoopLength = 0;
   52.88 +        while (curr != null) {
   52.89 +          ++whileLoopLength;
   52.90 +          curr = curr.getParentPath();
   52.91 +        }
   52.92 +        if (whileLoopLength != expectedLength)
   52.93 +            throw new RuntimeException("found path length is wrong");
   52.94 +    }
   52.95 +
   52.96 +    @Override
   52.97 +    public SourceVersion getSupportedSourceVersion() {
   52.98 +        return SourceVersion.latest();
   52.99 +    }
  52.100 +
  52.101 +    File writeTestFile() throws IOException {
  52.102 +        File f = new File("Test.java");
  52.103 +        PrintWriter out = new PrintWriter(new FileWriter(f));
  52.104 +        out.println("class Test { void method() { } }");
  52.105 +        out.close();
  52.106 +        return f;
  52.107 +    }
  52.108 +
  52.109 +    public void run() throws IOException {
  52.110 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  52.111 +        StandardJavaFileManager fileManager
  52.112 +            = compiler.getStandardFileManager(null, null, null);
  52.113 +        Iterable<? extends JavaFileObject> tests
  52.114 +            = fileManager.getJavaFileObjects(writeTestFile());
  52.115 +
  52.116 +        JavaCompiler.CompilationTask task =
  52.117 +            ToolProvider.getSystemJavaCompiler().getTask(
  52.118 +                    null, null, null,
  52.119 +                    Arrays.asList("-processor", this.getClass().getName()), null,
  52.120 +                    tests);
  52.121 +        task.call();
  52.122 +    }
  52.123 +
  52.124 +    public static void main(String[] args) throws IOException {
  52.125 +        new TestTreePath().run();
  52.126 +    }
  52.127 +}
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/test/tools/javac/meth/InvokeMH_BAD68.java	Sun Jun 28 00:01:09 2009 -0700
    53.3 @@ -0,0 +1,75 @@
    53.4 +/*
    53.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    53.7 + *
    53.8 + * This code is free software; you can redistribute it and/or modify it
    53.9 + * under the terms of the GNU General Public License version 2 only, as
   53.10 + * published by the Free Software Foundation.
   53.11 + *
   53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   53.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   53.15 + * version 2 for more details (a copy is included in the LICENSE file that
   53.16 + * accompanied this code).
   53.17 + *
   53.18 + * You should have received a copy of the GNU General Public License version
   53.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   53.21 + *
   53.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   53.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   53.24 + * have any questions.
   53.25 + */
   53.26 +
   53.27 +/*
   53.28 + * ##test
   53.29 + * ##bug 6754038
   53.30 + * ##summary Generate call sites for method handle
   53.31 + * ##author jrose
   53.32 + *
   53.33 + * ##compile/fail -source 7 -target 7 InvokeMH_BAD68.java
   53.34 + */
   53.35 +
   53.36 +/*
   53.37 + * Standalone testing:
   53.38 + * <code>
   53.39 + * $ cd $MY_REPO_DIR/langtools
   53.40 + * $ (cd make; make)
   53.41 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH_BAD68.java
   53.42 + * $ javap -c -classpath dist meth.InvokeMH_BAD68
   53.43 + * </code>
   53.44 + */
   53.45 +
   53.46 +package meth;
   53.47 +
   53.48 +import java.dyn.MethodHandle;
   53.49 +
   53.50 +public class InvokeMH_BAD68 {
   53.51 +    void test(MethodHandle mh_SiO,
   53.52 +              MethodHandle mh_vS,
   53.53 +              MethodHandle mh_vi,
   53.54 +              MethodHandle mh_vv) {
   53.55 +        Object o; String s; int i;  // for return type testing
   53.56 +
   53.57 +        // next five must have sig = (String,int)Object
   53.58 +        mh_SiO.invoke("world", 123);
   53.59 +        mh_SiO.invoke("mundus", 456);
   53.60 +        Object k = "kosmos";
   53.61 +        mh_SiO.invoke((String)k, 789);
   53.62 +        o = mh_SiO.invoke((String)null, 000);
   53.63 +        o = mh_SiO.<Object>invoke("arda", -123);
   53.64 +
   53.65 +        // sig = ()String
   53.66 +        s = mh_vS.<String>invoke();
   53.67 +
   53.68 +        // sig = ()int
   53.69 +        i = mh_vi.<int>invoke();
   53.70 +        o = mh_vi.<int>invoke();
   53.71 +    s = mh_vi.<int>invoke(); //BAD
   53.72 +        mh_vi.<int>invoke();
   53.73 +
   53.74 +        // sig = ()void
   53.75 +        //o = mh_vv.<void>invoke(); //BAD
   53.76 +        mh_vv.<void>invoke();
   53.77 +    }
   53.78 +}
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/test/tools/javac/meth/InvokeMH_BAD72.java	Sun Jun 28 00:01:09 2009 -0700
    54.3 @@ -0,0 +1,75 @@
    54.4 +/*
    54.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    54.7 + *
    54.8 + * This code is free software; you can redistribute it and/or modify it
    54.9 + * under the terms of the GNU General Public License version 2 only, as
   54.10 + * published by the Free Software Foundation.
   54.11 + *
   54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   54.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   54.15 + * version 2 for more details (a copy is included in the LICENSE file that
   54.16 + * accompanied this code).
   54.17 + *
   54.18 + * You should have received a copy of the GNU General Public License version
   54.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   54.21 + *
   54.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   54.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   54.24 + * have any questions.
   54.25 + */
   54.26 +
   54.27 +/*
   54.28 + * ##test
   54.29 + * ##bug 6754038
   54.30 + * ##summary Generate call sites for method handle
   54.31 + * ##author jrose
   54.32 + *
   54.33 + * ##compile/fail -source 7 -target 7 InvokeMH_BAD72.java
   54.34 + */
   54.35 +
   54.36 +/*
   54.37 + * Standalone testing:
   54.38 + * <code>
   54.39 + * $ cd $MY_REPO_DIR/langtools
   54.40 + * $ (cd make; make)
   54.41 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH_BAD72.java
   54.42 + * $ javap -c -classpath dist meth.InvokeMH_BAD72
   54.43 + * </code>
   54.44 + */
   54.45 +
   54.46 +package meth;
   54.47 +
   54.48 +import java.dyn.MethodHandle;
   54.49 +
   54.50 +public class InvokeMH_BAD72 {
   54.51 +    void test(MethodHandle mh_SiO,
   54.52 +              MethodHandle mh_vS,
   54.53 +              MethodHandle mh_vi,
   54.54 +              MethodHandle mh_vv) {
   54.55 +        Object o; String s; int i;  // for return type testing
   54.56 +
   54.57 +        // next five must have sig = (String,int)Object
   54.58 +        mh_SiO.invoke("world", 123);
   54.59 +        mh_SiO.invoke("mundus", 456);
   54.60 +        Object k = "kosmos";
   54.61 +        mh_SiO.invoke((String)k, 789);
   54.62 +        o = mh_SiO.invoke((String)null, 000);
   54.63 +        o = mh_SiO.<Object>invoke("arda", -123);
   54.64 +
   54.65 +        // sig = ()String
   54.66 +        s = mh_vS.<String>invoke();
   54.67 +
   54.68 +        // sig = ()int
   54.69 +        i = mh_vi.<int>invoke();
   54.70 +        o = mh_vi.<int>invoke();
   54.71 +        //s = mh_vi.<int>invoke(); //BAD
   54.72 +        mh_vi.<int>invoke();
   54.73 +
   54.74 +        // sig = ()void
   54.75 +    o = mh_vv.<void>invoke(); //BAD
   54.76 +        mh_vv.<void>invoke();
   54.77 +    }
   54.78 +}
    55.1 --- a/test/tools/javac/processing/6348499/T6348499.java	Fri Jun 26 10:26:27 2009 -0700
    55.2 +++ b/test/tools/javac/processing/6348499/T6348499.java	Sun Jun 28 00:01:09 2009 -0700
    55.3 @@ -54,6 +54,7 @@
    55.4              fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
    55.5          Iterable<String> opts = Arrays.asList("-proc:only",
    55.6                                                "-processor", "A",
    55.7 +                                              "-source", "1.6",
    55.8                                                "-processorpath", testClasses);
    55.9          StringWriter out = new StringWriter();
   55.10          JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
    56.1 --- a/test/tools/javac/processing/6414633/T6414633.java	Fri Jun 26 10:26:27 2009 -0700
    56.2 +++ b/test/tools/javac/processing/6414633/T6414633.java	Sun Jun 28 00:01:09 2009 -0700
    56.3 @@ -55,6 +55,7 @@
    56.4              fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, A.class.getName()+".java")));
    56.5          String[] opts = { "-proc:only",
    56.6                            "-processor", A.class.getName(),
    56.7 +                          "-source", "1.6",
    56.8                            "-classpath", testClasses };
    56.9          JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files);
   56.10          task.call();
    57.1 --- a/test/tools/javac/processing/6430209/T6430209.java	Fri Jun 26 10:26:27 2009 -0700
    57.2 +++ b/test/tools/javac/processing/6430209/T6430209.java	Sun Jun 28 00:01:09 2009 -0700
    57.3 @@ -63,6 +63,7 @@
    57.4              new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
    57.5          Iterable<String> opts = Arrays.asList("-proc:only",
    57.6                                                "-processor", "b6341534",
    57.7 +                                              "-source", "1.6",
    57.8                                                "-processorpath", testClasses);
    57.9          StringWriter out = new StringWriter();
   57.10          JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
    58.1 --- a/test/tools/javac/processing/T6439826.java	Fri Jun 26 10:26:27 2009 -0700
    58.2 +++ b/test/tools/javac/processing/T6439826.java	Sun Jun 28 00:01:09 2009 -0700
    58.3 @@ -49,7 +49,8 @@
    58.4          StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
    58.5          Iterable<? extends JavaFileObject> files =
    58.6              fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java")));
    58.7 -        Iterable<String> opts = Arrays.asList("-proc:only",
    58.8 +        Iterable<String> opts = Arrays.asList("-source","1.6",
    58.9 +                                              "-proc:only",
   58.10                                                "-processor", "T6439826",
   58.11                                                "-processorpath", testClasses);
   58.12          StringWriter out = new StringWriter();
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/test/tools/javac/processing/model/type/MirroredTypeEx/NpeTest.java	Sun Jun 28 00:01:09 2009 -0700
    59.3 @@ -0,0 +1,42 @@
    59.4 +/*
    59.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    59.7 + *
    59.8 + * This code is free software; you can redistribute it and/or modify it
    59.9 + * under the terms of the GNU General Public License version 2 only, as
   59.10 + * published by the Free Software Foundation.
   59.11 + *
   59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   59.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   59.15 + * version 2 for more details (a copy is included in the LICENSE file that
   59.16 + * accompanied this code).
   59.17 + *
   59.18 + * You should have received a copy of the GNU General Public License version
   59.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   59.21 + *
   59.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   59.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   59.24 + * have any questions.
   59.25 + */
   59.26 +
   59.27 +/*
   59.28 + * @test
   59.29 + * @bug     6593082
   59.30 + * @summary MirroredTypeException constructor should not accept null
   59.31 + * @author  Joseph D. Darcy
   59.32 + */
   59.33 +
   59.34 +import javax.lang.model.type.*;
   59.35 +
   59.36 +public class NpeTest  {
   59.37 +    public static void main(String... args) {
   59.38 +        try {
   59.39 +            MirroredTypeException mte = new MirroredTypeException(null);
   59.40 +            throw new RuntimeException("Expected NPE not thrown.");
   59.41 +        } catch (NullPointerException npe) {
   59.42 +            ; // success
   59.43 +        }
   59.44 +    }
   59.45 +}
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/test/tools/javac/quid/QuotedIdent_BAD61.java	Sun Jun 28 00:01:09 2009 -0700
    60.3 @@ -0,0 +1,132 @@
    60.4 +/*
    60.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    60.7 + *
    60.8 + * This code is free software; you can redistribute it and/or modify it
    60.9 + * under the terms of the GNU General Public License version 2 only, as
   60.10 + * published by the Free Software Foundation.
   60.11 + *
   60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   60.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   60.15 + * version 2 for more details (a copy is included in the LICENSE file that
   60.16 + * accompanied this code).
   60.17 + *
   60.18 + * You should have received a copy of the GNU General Public License version
   60.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   60.21 + *
   60.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   60.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   60.24 + * have any questions.
   60.25 + */
   60.26 +
   60.27 +/*
   60.28 + * ##test
   60.29 + * ##bug 6746458
   60.30 + * ##summary Verify correct lexing of quoted identifiers.
   60.31 + * ##author jrose
   60.32 + *
   60.33 + * ##library ..
   60.34 + * ##run main quid.QuotedIdent_BAD61
   60.35 + */
   60.36 +
   60.37 +/*
   60.38 + * Standalone testing:
   60.39 + * <code>
   60.40 + * $ cd $MY_REPO_DIR/langtools
   60.41 + * $ (cd make; make)
   60.42 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD61.java
   60.43 + * $ java -version  # should print 1.6 or later
   60.44 + * $ java -cp dist quid.QuotedIdent_BAD61
   60.45 + * </code>
   60.46 + */
   60.47 +
   60.48 +package quid;
   60.49 +
   60.50 +public class QuotedIdent_BAD61 {
   60.51 +    static void check(int testid, String have, String expect)
   60.52 +                throws RuntimeException {
   60.53 +        if ((have == null && have != expect) ||
   60.54 +                (have != null && !have.equals(expect))) {
   60.55 +            String msg =
   60.56 +                "TEST " + testid + ": HAVE \"" +
   60.57 +                have + "\" EXPECT \"" + expect + "\"";
   60.58 +            System.out.println("StringConversion: " + msg);
   60.59 +            throw new RuntimeException(msg);
   60.60 +        }
   60.61 +    }
   60.62 +
   60.63 +    // negative tests:
   60.64 +    static class #"" { } //BAD empty ident name
   60.65 +    //static class #"<foo>" { } //BAD bad char in ident name
   60.66 +    /*static class /*(//BAD ident name interrupted by newline) #"jump:
   60.67 +    " { } /* uncomment previous line to attempt class w/ bad name */
   60.68 +
   60.69 +    static class #"int" extends Number {
   60.70 +        final int #"int";
   60.71 +        #"int"(int #"int") {
   60.72 +            this.#"int" = #"int";
   60.73 +        }
   60.74 +        static #"int" valueOf(int #"int") {
   60.75 +            return new #"int"(#"int");
   60.76 +        }
   60.77 +        public int intValue() { return #"int"; }
   60.78 +        public long longValue() { return #"int"; }
   60.79 +        public float floatValue() { return #"int"; }
   60.80 +        public double doubleValue() { return #"int"; }
   60.81 +        public String toString() { return String.valueOf(#"int"); }
   60.82 +    }
   60.83 +
   60.84 +    class #"*86" {
   60.85 +        String #"555-1212"() { return "[*86.555-1212]"; }
   60.86 +    }
   60.87 +    static#"*86"#"MAKE-*86"() {   // note close spacing
   60.88 +        return new QuotedIdent_BAD61().new#"*86"();
   60.89 +    }
   60.90 +
   60.91 +    static String bar() { return "[bar]"; }
   60.92 +
   60.93 +    public static void main(String[] args) throws Exception {
   60.94 +        String s;
   60.95 +
   60.96 +        String #"sticky \' wicket" = "wicked ' stick";
   60.97 +        s = #"sticky ' wicket";
   60.98 +        check(11, s, "wicked \' stick");
   60.99 +        check(12, #"s", s);
  60.100 +        check(13, #"\163", s);
  60.101 +
  60.102 +        s = #"QuotedIdent_BAD61".bar();
  60.103 +        check(21, s, "[bar]");
  60.104 +
  60.105 +        s = #"int".valueOf(123).toString();
  60.106 +        check(22, s, "123");
  60.107 +
  60.108 +        s = #"MAKE-*86"().#"555-1212"();
  60.109 +        check(23, s, "[*86.555-1212]");
  60.110 +
  60.111 +        class#"{{{inmost}}}" { }
  60.112 +        s = new#"{{{inmost}}}"().getClass().getName();
  60.113 +        if (!s.endsWith("{{{inmost}}}"))
  60.114 +            check(24, s, "should end with \"{{{inmost}}}\"");
  60.115 +
  60.116 +        s = #"Yog-Shoggoth".#"(nameless ululation)";
  60.117 +        check(25, s, "Tekeli-li!");
  60.118 +
  60.119 +        s = #"int".class.getName();
  60.120 +        check(31, s, QuotedIdent_BAD61.class.getName()+"$int");
  60.121 +
  60.122 +        Class x86 = Class.forName(QuotedIdent_BAD61.class.getName()+"$*86");
  60.123 +        if (x86 != #"*86".class)
  60.124 +            check(32, "reflected "+x86, "static "+#"*86".class);
  60.125 +
  60.126 +        s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
  60.127 +        check(31, s, "[*86.555-1212]");
  60.128 +
  60.129 +        System.out.println("OK");
  60.130 +    }
  60.131 +}
  60.132 +
  60.133 +interface #"Yog-Shoggoth" {
  60.134 +    final String #"(nameless ululation)" = "Tekeli-li!";
  60.135 +}
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/test/tools/javac/quid/QuotedIdent_BAD62.java	Sun Jun 28 00:01:09 2009 -0700
    61.3 @@ -0,0 +1,132 @@
    61.4 +/*
    61.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    61.7 + *
    61.8 + * This code is free software; you can redistribute it and/or modify it
    61.9 + * under the terms of the GNU General Public License version 2 only, as
   61.10 + * published by the Free Software Foundation.
   61.11 + *
   61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   61.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   61.15 + * version 2 for more details (a copy is included in the LICENSE file that
   61.16 + * accompanied this code).
   61.17 + *
   61.18 + * You should have received a copy of the GNU General Public License version
   61.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   61.21 + *
   61.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   61.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   61.24 + * have any questions.
   61.25 + */
   61.26 +
   61.27 +/*
   61.28 + * ##test
   61.29 + * ##bug 6746458
   61.30 + * ##summary Verify correct lexing of quoted identifiers.
   61.31 + * ##author jrose
   61.32 + *
   61.33 + * ##library ..
   61.34 + * ##run main quid.QuotedIdent_BAD62
   61.35 + */
   61.36 +
   61.37 +/*
   61.38 + * Standalone testing:
   61.39 + * <code>
   61.40 + * $ cd $MY_REPO_DIR/langtools
   61.41 + * $ (cd make; make)
   61.42 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD62.java
   61.43 + * $ java -version  # should print 1.6 or later
   61.44 + * $ java -cp dist quid.QuotedIdent_BAD62
   61.45 + * </code>
   61.46 + */
   61.47 +
   61.48 +package quid;
   61.49 +
   61.50 +public class QuotedIdent_BAD62 {
   61.51 +    static void check(int testid, String have, String expect)
   61.52 +                throws RuntimeException {
   61.53 +        if ((have == null && have != expect) ||
   61.54 +                (have != null && !have.equals(expect))) {
   61.55 +            String msg =
   61.56 +                "TEST " + testid + ": HAVE \"" +
   61.57 +                have + "\" EXPECT \"" + expect + "\"";
   61.58 +            System.out.println("StringConversion: " + msg);
   61.59 +            throw new RuntimeException(msg);
   61.60 +        }
   61.61 +    }
   61.62 +
   61.63 +    // negative tests:
   61.64 +    //static class #"" { } //BAD empty ident name
   61.65 +    static class #"<foo>" { } //BAD bad char in ident name
   61.66 +    /*static class /*(//BAD ident name interrupted by newline) #"jump:
   61.67 +    " { } /* uncomment previous line to attempt class w/ bad name */
   61.68 +
   61.69 +    static class #"int" extends Number {
   61.70 +        final int #"int";
   61.71 +        #"int"(int #"int") {
   61.72 +            this.#"int" = #"int";
   61.73 +        }
   61.74 +        static #"int" valueOf(int #"int") {
   61.75 +            return new #"int"(#"int");
   61.76 +        }
   61.77 +        public int intValue() { return #"int"; }
   61.78 +        public long longValue() { return #"int"; }
   61.79 +        public float floatValue() { return #"int"; }
   61.80 +        public double doubleValue() { return #"int"; }
   61.81 +        public String toString() { return String.valueOf(#"int"); }
   61.82 +    }
   61.83 +
   61.84 +    class #"*86" {
   61.85 +        String #"555-1212"() { return "[*86.555-1212]"; }
   61.86 +    }
   61.87 +    static#"*86"#"MAKE-*86"() {   // note close spacing
   61.88 +        return new QuotedIdent_BAD62().new#"*86"();
   61.89 +    }
   61.90 +
   61.91 +    static String bar() { return "[bar]"; }
   61.92 +
   61.93 +    public static void main(String[] args) throws Exception {
   61.94 +        String s;
   61.95 +
   61.96 +        String #"sticky \' wicket" = "wicked ' stick";
   61.97 +        s = #"sticky ' wicket";
   61.98 +        check(11, s, "wicked \' stick");
   61.99 +        check(12, #"s", s);
  61.100 +        check(13, #"\163", s);
  61.101 +
  61.102 +        s = #"QuotedIdent_BAD62".bar();
  61.103 +        check(21, s, "[bar]");
  61.104 +
  61.105 +        s = #"int".valueOf(123).toString();
  61.106 +        check(22, s, "123");
  61.107 +
  61.108 +        s = #"MAKE-*86"().#"555-1212"();
  61.109 +        check(23, s, "[*86.555-1212]");
  61.110 +
  61.111 +        class#"{{{inmost}}}" { }
  61.112 +        s = new#"{{{inmost}}}"().getClass().getName();
  61.113 +        if (!s.endsWith("{{{inmost}}}"))
  61.114 +            check(24, s, "should end with \"{{{inmost}}}\"");
  61.115 +
  61.116 +        s = #"Yog-Shoggoth".#"(nameless ululation)";
  61.117 +        check(25, s, "Tekeli-li!");
  61.118 +
  61.119 +        s = #"int".class.getName();
  61.120 +        check(31, s, QuotedIdent_BAD62.class.getName()+"$int");
  61.121 +
  61.122 +        Class x86 = Class.forName(QuotedIdent_BAD62.class.getName()+"$*86");
  61.123 +        if (x86 != #"*86".class)
  61.124 +            check(32, "reflected "+x86, "static "+#"*86".class);
  61.125 +
  61.126 +        s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
  61.127 +        check(31, s, "[*86.555-1212]");
  61.128 +
  61.129 +        System.out.println("OK");
  61.130 +    }
  61.131 +}
  61.132 +
  61.133 +interface #"Yog-Shoggoth" {
  61.134 +    final String #"(nameless ululation)" = "Tekeli-li!";
  61.135 +}
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/test/tools/javac/quid/QuotedIdent_BAD63.java	Sun Jun 28 00:01:09 2009 -0700
    62.3 @@ -0,0 +1,132 @@
    62.4 +/*
    62.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    62.7 + *
    62.8 + * This code is free software; you can redistribute it and/or modify it
    62.9 + * under the terms of the GNU General Public License version 2 only, as
   62.10 + * published by the Free Software Foundation.
   62.11 + *
   62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   62.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   62.15 + * version 2 for more details (a copy is included in the LICENSE file that
   62.16 + * accompanied this code).
   62.17 + *
   62.18 + * You should have received a copy of the GNU General Public License version
   62.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   62.21 + *
   62.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   62.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   62.24 + * have any questions.
   62.25 + */
   62.26 +
   62.27 +/*
   62.28 + * ##test
   62.29 + * ##bug 6746458
   62.30 + * ##summary Verify correct lexing of quoted identifiers.
   62.31 + * ##author jrose
   62.32 + *
   62.33 + * ##library ..
   62.34 + * ##run main quid.QuotedIdent_BAD63
   62.35 + */
   62.36 +
   62.37 +/*
   62.38 + * Standalone testing:
   62.39 + * <code>
   62.40 + * $ cd $MY_REPO_DIR/langtools
   62.41 + * $ (cd make; make)
   62.42 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD63.java
   62.43 + * $ java -version  # should print 1.6 or later
   62.44 + * $ java -cp dist quid.QuotedIdent_BAD63
   62.45 + * </code>
   62.46 + */
   62.47 +
   62.48 +package quid;
   62.49 +
   62.50 +public class QuotedIdent_BAD63 {
   62.51 +    static void check(int testid, String have, String expect)
   62.52 +                throws RuntimeException {
   62.53 +        if ((have == null && have != expect) ||
   62.54 +                (have != null && !have.equals(expect))) {
   62.55 +            String msg =
   62.56 +                "TEST " + testid + ": HAVE \"" +
   62.57 +                have + "\" EXPECT \"" + expect + "\"";
   62.58 +            System.out.println("StringConversion: " + msg);
   62.59 +            throw new RuntimeException(msg);
   62.60 +        }
   62.61 +    }
   62.62 +
   62.63 +    // negative tests:
   62.64 +    //static class #"" { } //BAD empty ident name
   62.65 +    //static class #"<foo>" { } //BAD bad char in ident name
   62.66 +    static class /*(//BAD ident name interrupted by newline) #"jump:
   62.67 +    " { } /* uncomment previous line to attempt class w/ bad name */
   62.68 +
   62.69 +    static class #"int" extends Number {
   62.70 +        final int #"int";
   62.71 +        #"int"(int #"int") {
   62.72 +            this.#"int" = #"int";
   62.73 +        }
   62.74 +        static #"int" valueOf(int #"int") {
   62.75 +            return new #"int"(#"int");
   62.76 +        }
   62.77 +        public int intValue() { return #"int"; }
   62.78 +        public long longValue() { return #"int"; }
   62.79 +        public float floatValue() { return #"int"; }
   62.80 +        public double doubleValue() { return #"int"; }
   62.81 +        public String toString() { return String.valueOf(#"int"); }
   62.82 +    }
   62.83 +
   62.84 +    class #"*86" {
   62.85 +        String #"555-1212"() { return "[*86.555-1212]"; }
   62.86 +    }
   62.87 +    static#"*86"#"MAKE-*86"() {   // note close spacing
   62.88 +        return new QuotedIdent_BAD63().new#"*86"();
   62.89 +    }
   62.90 +
   62.91 +    static String bar() { return "[bar]"; }
   62.92 +
   62.93 +    public static void main(String[] args) throws Exception {
   62.94 +        String s;
   62.95 +
   62.96 +        String #"sticky \' wicket" = "wicked ' stick";
   62.97 +        s = #"sticky ' wicket";
   62.98 +        check(11, s, "wicked \' stick");
   62.99 +        check(12, #"s", s);
  62.100 +        check(13, #"\163", s);
  62.101 +
  62.102 +        s = #"QuotedIdent_BAD63".bar();
  62.103 +        check(21, s, "[bar]");
  62.104 +
  62.105 +        s = #"int".valueOf(123).toString();
  62.106 +        check(22, s, "123");
  62.107 +
  62.108 +        s = #"MAKE-*86"().#"555-1212"();
  62.109 +        check(23, s, "[*86.555-1212]");
  62.110 +
  62.111 +        class#"{{{inmost}}}" { }
  62.112 +        s = new#"{{{inmost}}}"().getClass().getName();
  62.113 +        if (!s.endsWith("{{{inmost}}}"))
  62.114 +            check(24, s, "should end with \"{{{inmost}}}\"");
  62.115 +
  62.116 +        s = #"Yog-Shoggoth".#"(nameless ululation)";
  62.117 +        check(25, s, "Tekeli-li!");
  62.118 +
  62.119 +        s = #"int".class.getName();
  62.120 +        check(31, s, QuotedIdent_BAD63.class.getName()+"$int");
  62.121 +
  62.122 +        Class x86 = Class.forName(QuotedIdent_BAD63.class.getName()+"$*86");
  62.123 +        if (x86 != #"*86".class)
  62.124 +            check(32, "reflected "+x86, "static "+#"*86".class);
  62.125 +
  62.126 +        s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
  62.127 +        check(31, s, "[*86.555-1212]");
  62.128 +
  62.129 +        System.out.println("OK");
  62.130 +    }
  62.131 +}
  62.132 +
  62.133 +interface #"Yog-Shoggoth" {
  62.134 +    final String #"(nameless ululation)" = "Tekeli-li!";
  62.135 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/test/tools/javac/typeAnnotations/InnerClass.java	Sun Jun 28 00:01:09 2009 -0700
    63.3 @@ -0,0 +1,38 @@
    63.4 +/*
    63.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    63.7 + *
    63.8 + * This code is free software; you can redistribute it and/or modify it
    63.9 + * under the terms of the GNU General Public License version 2 only, as
   63.10 + * published by the Free Software Foundation.
   63.11 + *
   63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   63.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   63.15 + * version 2 for more details (a copy is included in the LICENSE file that
   63.16 + * accompanied this code).
   63.17 + *
   63.18 + * You should have received a copy of the GNU General Public License version
   63.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   63.21 + *
   63.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   63.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   63.24 + * have any questions.
   63.25 + */
   63.26 +
   63.27 +/*
   63.28 + * @test
   63.29 + * @bug 6843077
   63.30 + * @summary compiler crashes when visiting inner classes
   63.31 + * @author Mahmood Ali
   63.32 + * @compile -source 1.7 InnerClass.java
   63.33 + */
   63.34 +
   63.35 +class InnerClass {
   63.36 +    private void a() {
   63.37 +        new Object() {
   63.38 +            public <R> void method() { }
   63.39 +        };
   63.40 +    }
   63.41 +}
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/test/tools/javac/typeAnnotations/MultipleTargets.java	Sun Jun 28 00:01:09 2009 -0700
    64.3 @@ -0,0 +1,41 @@
    64.4 +/*
    64.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    64.7 + *
    64.8 + * This code is free software; you can redistribute it and/or modify it
    64.9 + * under the terms of the GNU General Public License version 2 only, as
   64.10 + * published by the Free Software Foundation.
   64.11 + *
   64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   64.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   64.15 + * version 2 for more details (a copy is included in the LICENSE file that
   64.16 + * accompanied this code).
   64.17 + *
   64.18 + * You should have received a copy of the GNU General Public License version
   64.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   64.21 + *
   64.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   64.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   64.24 + * have any questions.
   64.25 + */
   64.26 +
   64.27 +/*
   64.28 + * @test
   64.29 + * @bug 6843077
   64.30 + * @summary check that type annotations may appear on void method if it is a
   64.31 + *          method annotation too.
   64.32 + * @author Mahmood Ali
   64.33 + * @compile -source 1.7 MultipleTargets.java
   64.34 + */
   64.35 +
   64.36 +import java.lang.annotation.Target;
   64.37 +import java.lang.annotation.ElementType;
   64.38 +
   64.39 +class TypeUseTarget<K extends @A Object> {
   64.40 +  @A void voidMethod() { }
   64.41 +}
   64.42 +
   64.43 +@Target({ElementType.TYPE_USE, ElementType.METHOD})
   64.44 +@interface A { }
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/test/tools/javac/typeAnnotations/TypeParameterTarget.java	Sun Jun 28 00:01:09 2009 -0700
    65.3 @@ -0,0 +1,46 @@
    65.4 +/*
    65.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    65.7 + *
    65.8 + * This code is free software; you can redistribute it and/or modify it
    65.9 + * under the terms of the GNU General Public License version 2 only, as
   65.10 + * published by the Free Software Foundation.
   65.11 + *
   65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   65.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   65.15 + * version 2 for more details (a copy is included in the LICENSE file that
   65.16 + * accompanied this code).
   65.17 + *
   65.18 + * You should have received a copy of the GNU General Public License version
   65.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   65.21 + *
   65.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   65.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   65.24 + * have any questions.
   65.25 + */
   65.26 +
   65.27 +/*
   65.28 + * @test
   65.29 + * @bug 6843077
   65.30 + * @summary check that type annotations may appear on all type parameter
   65.31 + * @author Mahmood Ali
   65.32 + * @compile -source 1.7 TypeParameterTarget.java
   65.33 + */
   65.34 +
   65.35 +import java.lang.annotation.Target;
   65.36 +import java.lang.annotation.ElementType;
   65.37 +
   65.38 +class TypeUseTarget<@A K extends Object> {
   65.39 +  String[] field;
   65.40 +
   65.41 +  <@A K, @A V> String genericMethod(K k) { return null; }
   65.42 +}
   65.43 +
   65.44 +interface MyInterface { }
   65.45 +
   65.46 +@interface MyAnnotation { }
   65.47 +
   65.48 +@Target(ElementType.TYPE_PARAMETER)
   65.49 +@interface A { }
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/test/tools/javac/typeAnnotations/TypeUseTarget.java	Sun Jun 28 00:01:09 2009 -0700
    66.3 @@ -0,0 +1,55 @@
    66.4 +/*
    66.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    66.7 + *
    66.8 + * This code is free software; you can redistribute it and/or modify it
    66.9 + * under the terms of the GNU General Public License version 2 only, as
   66.10 + * published by the Free Software Foundation.
   66.11 + *
   66.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   66.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   66.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   66.15 + * version 2 for more details (a copy is included in the LICENSE file that
   66.16 + * accompanied this code).
   66.17 + *
   66.18 + * You should have received a copy of the GNU General Public License version
   66.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   66.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   66.21 + *
   66.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   66.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   66.24 + * have any questions.
   66.25 + */
   66.26 +
   66.27 +/*
   66.28 + * @test
   66.29 + * @bug 6843077
   66.30 + * @summary check that type annotations may appear on all type declarations
   66.31 + * @author Mahmood Ali
   66.32 + * @compile -source 1.7 TypeUseTarget.java
   66.33 + */
   66.34 +
   66.35 +import java.lang.annotation.Target;
   66.36 +import java.lang.annotation.ElementType;
   66.37 +
   66.38 +@A
   66.39 +class TypeUseTarget<K extends @A Object> {
   66.40 +  @A String @A [] field;
   66.41 +
   66.42 +  @A String test(@A String param, @A String @A ... vararg) @A {
   66.43 +    @A Object o = new @A String @A [3];
   66.44 +    TypeUseTarget<@A String> target;
   66.45 +    return (@A String) null;
   66.46 +  }
   66.47 +
   66.48 +  <K> @A String genericMethod(K k) { return null; }
   66.49 +}
   66.50 +
   66.51 +@A
   66.52 +interface MyInterface { }
   66.53 +
   66.54 +@A
   66.55 +@interface MyAnnotation { }
   66.56 +
   66.57 +@Target(ElementType.TYPE_USE)
   66.58 +@interface A { }
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/test/tools/javac/typeAnnotations/attribution/Scopes.java	Sun Jun 28 00:01:09 2009 -0700
    67.3 @@ -0,0 +1,38 @@
    67.4 +/*
    67.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    67.7 + *
    67.8 + * This code is free software; you can redistribute it and/or modify it
    67.9 + * under the terms of the GNU General Public License version 2 only, as
   67.10 + * published by the Free Software Foundation.
   67.11 + *
   67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   67.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   67.15 + * version 2 for more details (a copy is included in the LICENSE file that
   67.16 + * accompanied this code).
   67.17 + *
   67.18 + * You should have received a copy of the GNU General Public License version
   67.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   67.21 + *
   67.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   67.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   67.24 + * have any questions.
   67.25 + */
   67.26 +
   67.27 +/*
   67.28 + * @test
   67.29 + * @bug 6843077
   67.30 + * @summary test scopes of attribution
   67.31 + * @author Mahmood Ali
   67.32 + * @compile -source 1.7 Scopes.java
   67.33 + */
   67.34 +class Scopes {
   67.35 +
   67.36 +  void test() @A(VALUE) { }
   67.37 +  void test1() @A(value=VALUE) { }
   67.38 +
   67.39 +  private static final int VALUE = 1;
   67.40 +  @interface A { int value(); }
   67.41 +}
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/test/tools/javac/typeAnnotations/failures/AnnotationVersion.java	Sun Jun 28 00:01:09 2009 -0700
    68.3 @@ -0,0 +1,35 @@
    68.4 +/*
    68.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    68.7 + *
    68.8 + * This code is free software; you can redistribute it and/or modify it
    68.9 + * under the terms of the GNU General Public License version 2 only, as
   68.10 + * published by the Free Software Foundation.
   68.11 + *
   68.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   68.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   68.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   68.15 + * version 2 for more details (a copy is included in the LICENSE file that
   68.16 + * accompanied this code).
   68.17 + *
   68.18 + * You should have received a copy of the GNU General Public License version
   68.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   68.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   68.21 + *
   68.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   68.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   68.24 + * have any questions.
   68.25 + */
   68.26 +
   68.27 +/*
   68.28 + * @test
   68.29 + * @bug 6843077
   68.30 + * @summary test that only java 7 allows type annotations
   68.31 + * @author Mahmood Ali
   68.32 + * @compile/fail/ref=AnnotationVersion.out -XDrawDiagnostics -source 1.6 AnnotationVersion.java
   68.33 + */
   68.34 +class AnnotationVersion {
   68.35 +  public void method() @A { }
   68.36 +}
   68.37 +
   68.38 +@interface A { }
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/test/tools/javac/typeAnnotations/failures/AnnotationVersion.out	Sun Jun 28 00:01:09 2009 -0700
    69.3 @@ -0,0 +1,2 @@
    69.4 +AnnotationVersion.java:32:25: compiler.err.type.annotations.not.supported.in.source: 1.6
    69.5 +1 error
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/test/tools/javac/typeAnnotations/failures/IncompleteArray.java	Sun Jun 28 00:01:09 2009 -0700
    70.3 @@ -0,0 +1,35 @@
    70.4 +/*
    70.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    70.7 + *
    70.8 + * This code is free software; you can redistribute it and/or modify it
    70.9 + * under the terms of the GNU General Public License version 2 only, as
   70.10 + * published by the Free Software Foundation.
   70.11 + *
   70.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   70.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   70.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   70.15 + * version 2 for more details (a copy is included in the LICENSE file that
   70.16 + * accompanied this code).
   70.17 + *
   70.18 + * You should have received a copy of the GNU General Public License version
   70.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   70.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   70.21 + *
   70.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   70.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   70.24 + * have any questions.
   70.25 + */
   70.26 +
   70.27 +/*
   70.28 + * @test
   70.29 + * @bug 6843077
   70.30 + * @summary test incomplete array declaration
   70.31 + * @author Mahmood Ali
   70.32 + * @compile/fail/ref=IncompleteArray.out -XDrawDiagnostics -source 1.7 IncompleteArray.java
   70.33 + */
   70.34 +class IncompleteArray {
   70.35 +  int @A [] @A var;
   70.36 +}
   70.37 +
   70.38 +@interface A { }
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/test/tools/javac/typeAnnotations/failures/IncompleteArray.out	Sun Jun 28 00:01:09 2009 -0700
    71.3 @@ -0,0 +1,2 @@
    71.4 +IncompleteArray.java:32:13: compiler.err.illegal.start.of.type
    71.5 +1 error
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/test/tools/javac/typeAnnotations/failures/IncompleteVararg.java	Sun Jun 28 00:01:09 2009 -0700
    72.3 @@ -0,0 +1,36 @@
    72.4 +/*
    72.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    72.7 + *
    72.8 + * This code is free software; you can redistribute it and/or modify it
    72.9 + * under the terms of the GNU General Public License version 2 only, as
   72.10 + * published by the Free Software Foundation.
   72.11 + *
   72.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   72.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   72.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   72.15 + * version 2 for more details (a copy is included in the LICENSE file that
   72.16 + * accompanied this code).
   72.17 + *
   72.18 + * You should have received a copy of the GNU General Public License version
   72.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   72.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   72.21 + *
   72.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   72.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   72.24 + * have any questions.
   72.25 + */
   72.26 +
   72.27 +/*
   72.28 + * @test
   72.29 + * @bug 6843077
   72.30 + * @summary test incomplete vararg declaration
   72.31 + * @author Mahmood Ali
   72.32 + * @compile/fail/ref=IncompleteVararg.out -XDrawDiagnostics -source 1.7 IncompleteVararg.java
   72.33 + */
   72.34 +class IncompleteArray {
   72.35 +  // the last variable may be vararg
   72.36 +  void method(int @A test) { }
   72.37 +}
   72.38 +
   72.39 +@interface A { }
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/test/tools/javac/typeAnnotations/failures/IncompleteVararg.out	Sun Jun 28 00:01:09 2009 -0700
    73.3 @@ -0,0 +1,2 @@
    73.4 +IncompleteVararg.java:33:19: compiler.err.illegal.start.of.type
    73.5 +1 error
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/test/tools/javac/typeAnnotations/failures/IndexArray.java	Sun Jun 28 00:01:09 2009 -0700
    74.3 @@ -0,0 +1,36 @@
    74.4 +/*
    74.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    74.7 + *
    74.8 + * This code is free software; you can redistribute it and/or modify it
    74.9 + * under the terms of the GNU General Public License version 2 only, as
   74.10 + * published by the Free Software Foundation.
   74.11 + *
   74.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   74.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   74.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   74.15 + * version 2 for more details (a copy is included in the LICENSE file that
   74.16 + * accompanied this code).
   74.17 + *
   74.18 + * You should have received a copy of the GNU General Public License version
   74.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   74.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   74.21 + *
   74.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   74.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   74.24 + * have any questions.
   74.25 + */
   74.26 +
   74.27 +/*
   74.28 + * @test
   74.29 + * @bug 6843077
   74.30 + * @summary test indexing of an array
   74.31 + * @author Mahmood Ali
   74.32 + * @compile/fail/ref=IndexArray.out -XDrawDiagnostics -source 1.7 IndexArray.java
   74.33 + */
   74.34 +class IndexArray {
   74.35 +  int[] var;
   74.36 +  int a = var @A [1];
   74.37 +}
   74.38 +
   74.39 +@interface A { }
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/test/tools/javac/typeAnnotations/failures/IndexArray.out	Sun Jun 28 00:01:09 2009 -0700
    75.3 @@ -0,0 +1,2 @@
    75.4 +IndexArray.java:33:15: compiler.err.illegal.start.of.expr
    75.5 +1 error
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/test/tools/javac/typeAnnotations/failures/LintCast.java	Sun Jun 28 00:01:09 2009 -0700
    76.3 @@ -0,0 +1,65 @@
    76.4 +/*
    76.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    76.7 + *
    76.8 + * This code is free software; you can redistribute it and/or modify it
    76.9 + * under the terms of the GNU General Public License version 2 only, as
   76.10 + * published by the Free Software Foundation.
   76.11 + *
   76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   76.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   76.15 + * version 2 for more details (a copy is included in the LICENSE file that
   76.16 + * accompanied this code).
   76.17 + *
   76.18 + * You should have received a copy of the GNU General Public License version
   76.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   76.21 + *
   76.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   76.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   76.24 + * have any questions.
   76.25 + */
   76.26 +
   76.27 +import java.util.List;
   76.28 +
   76.29 +/*
   76.30 + * @test
   76.31 + * @bug 6843077
   76.32 + * @summary test that compiler doesn't warn about annotated redundant casts
   76.33 + * @author Mahmood Ali
   76.34 + * @compile/ref=LintCast.out -Xlint:cast -XDrawDiagnostics -source 1.7 LintCast.java
   76.35 + */
   76.36 +class LintCast {
   76.37 +    void unparameterized() {
   76.38 +        String s = "m";
   76.39 +        String s1 = (String)s;
   76.40 +        String s2 = (@A String)s;
   76.41 +    }
   76.42 +
   76.43 +    void parameterized() {
   76.44 +        List<String> l = null;
   76.45 +        List<String> l1 = (List<String>)l;
   76.46 +        List<String> l2 = (List<@A String>)l;
   76.47 +    }
   76.48 +
   76.49 +    void array() {
   76.50 +        int @A [] a = null;
   76.51 +        int[] a1 = (int[])a;
   76.52 +        int[] a2 = (int @A [])a;
   76.53 +    }
   76.54 +
   76.55 +    void sameAnnotations() {
   76.56 +        @A String annotated = null;
   76.57 +        String unannotated = null;
   76.58 +
   76.59 +        // compiler ignore annotated casts even if redundant
   76.60 +        @A String anno1 = (@A String)annotated;
   76.61 +
   76.62 +        // warn if redundant without an annotation
   76.63 +        String anno2 = (String)annotated;
   76.64 +        String unanno2 = (String)unannotated;
   76.65 +    }
   76.66 +}
   76.67 +
   76.68 +@interface A { }
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/test/tools/javac/typeAnnotations/failures/LintCast.out	Sun Jun 28 00:01:09 2009 -0700
    77.3 @@ -0,0 +1,6 @@
    77.4 +LintCast.java:36:21: compiler.warn.redundant.cast: java.lang.String
    77.5 +LintCast.java:42:27: compiler.warn.redundant.cast: java.util.List<java.lang.String>
    77.6 +LintCast.java:48:20: compiler.warn.redundant.cast: int[]
    77.7 +LintCast.java:60:24: compiler.warn.redundant.cast: java.lang.String
    77.8 +LintCast.java:61:26: compiler.warn.redundant.cast: java.lang.String
    77.9 +5 warnings
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/test/tools/javac/typeAnnotations/failures/OldArray.java	Sun Jun 28 00:01:09 2009 -0700
    78.3 @@ -0,0 +1,35 @@
    78.4 +/*
    78.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    78.7 + *
    78.8 + * This code is free software; you can redistribute it and/or modify it
    78.9 + * under the terms of the GNU General Public License version 2 only, as
   78.10 + * published by the Free Software Foundation.
   78.11 + *
   78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   78.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   78.15 + * version 2 for more details (a copy is included in the LICENSE file that
   78.16 + * accompanied this code).
   78.17 + *
   78.18 + * You should have received a copy of the GNU General Public License version
   78.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   78.21 + *
   78.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   78.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   78.24 + * have any questions.
   78.25 + */
   78.26 +
   78.27 +/*
   78.28 + * @test
   78.29 + * @bug 6843077
   78.30 + * @summary test old array syntax
   78.31 + * @author Mahmood Ali
   78.32 + * @compile/fail -XDrawDiagnostics -source 1.7 OldArray.java
   78.33 + */
   78.34 +class OldArray {
   78.35 +  String [@A]  s() { return null; }
   78.36 +}
   78.37 +
   78.38 +@interface A { }
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/test/tools/javac/typeAnnotations/failures/Scopes.java	Sun Jun 28 00:01:09 2009 -0700
    79.3 @@ -0,0 +1,33 @@
    79.4 +/*
    79.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    79.7 + *
    79.8 + * This code is free software; you can redistribute it and/or modify it
    79.9 + * under the terms of the GNU General Public License version 2 only, as
   79.10 + * published by the Free Software Foundation.
   79.11 + *
   79.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   79.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   79.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   79.15 + * version 2 for more details (a copy is included in the LICENSE file that
   79.16 + * accompanied this code).
   79.17 + *
   79.18 + * You should have received a copy of the GNU General Public License version
   79.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   79.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   79.21 + *
   79.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   79.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   79.24 + * have any questions.
   79.25 + */
   79.26 +
   79.27 +/*
   79.28 + * @test
   79.29 + * @bug 6843077
   79.30 + * @summary check that A is accessible in the class type parameters
   79.31 + * @author Mahmood Ali
   79.32 + * @compile/fail/ref=Scopes.out -XDrawDiagnostics -source 1.7 Scopes.java
   79.33 + */
   79.34 +class Scopes<T extends @UniqueInner Object> {
   79.35 +  @interface UniqueInner { };
   79.36 +}
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/test/tools/javac/typeAnnotations/failures/Scopes.out	Sun Jun 28 00:01:09 2009 -0700
    80.3 @@ -0,0 +1,2 @@
    80.4 +Scopes.java:31:25: compiler.err.cant.resolve: kindname.class, UniqueInner, , 
    80.5 +1 error
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/test/tools/javac/typeAnnotations/failures/StaticFields.java	Sun Jun 28 00:01:09 2009 -0700
    81.3 @@ -0,0 +1,36 @@
    81.4 +/*
    81.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    81.7 + *
    81.8 + * This code is free software; you can redistribute it and/or modify it
    81.9 + * under the terms of the GNU General Public License version 2 only, as
   81.10 + * published by the Free Software Foundation.
   81.11 + *
   81.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   81.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   81.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   81.15 + * version 2 for more details (a copy is included in the LICENSE file that
   81.16 + * accompanied this code).
   81.17 + *
   81.18 + * You should have received a copy of the GNU General Public License version
   81.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   81.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   81.21 + *
   81.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   81.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   81.24 + * have any questions.
   81.25 + */
   81.26 +
   81.27 +/*
   81.28 + * @test
   81.29 + * @bug 6843077
   81.30 + * @summary static field access isn't a valid location
   81.31 + * @author Mahmood Ali
   81.32 + * @compile/fail/ref=StaticFields.out -XDrawDiagnostics -source 1.7 StaticFields.java
   81.33 + */
   81.34 +class C {
   81.35 +  int f;
   81.36 +  int a = @A C.f;
   81.37 +}
   81.38 +
   81.39 +@interface A { }
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/test/tools/javac/typeAnnotations/failures/StaticFields.out	Sun Jun 28 00:01:09 2009 -0700
    82.3 @@ -0,0 +1,2 @@
    82.4 +StaticFields.java:33:17: compiler.err.illegal.start.of.expr
    82.5 +1 error
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/test/tools/javac/typeAnnotations/failures/StaticMethods.java	Sun Jun 28 00:01:09 2009 -0700
    83.3 @@ -0,0 +1,35 @@
    83.4 +/*
    83.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.7 + *
    83.8 + * This code is free software; you can redistribute it and/or modify it
    83.9 + * under the terms of the GNU General Public License version 2 only, as
   83.10 + * published by the Free Software Foundation.
   83.11 + *
   83.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   83.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   83.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   83.15 + * version 2 for more details (a copy is included in the LICENSE file that
   83.16 + * accompanied this code).
   83.17 + *
   83.18 + * You should have received a copy of the GNU General Public License version
   83.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   83.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   83.21 + *
   83.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   83.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   83.24 + * have any questions.
   83.25 + */
   83.26 +
   83.27 +/*
   83.28 + * @test
   83.29 + * @bug 6843077
   83.30 + * @summary static methods don't have receivers
   83.31 + * @author Mahmood Ali
   83.32 + * @compile/fail/ref=StaticMethods.out -XDrawDiagnostics -source 1.7 StaticMethods.java
   83.33 + */
   83.34 +class StaticMethods {
   83.35 +  static void main() @A { }
   83.36 +}
   83.37 +
   83.38 +@interface A { }
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/test/tools/javac/typeAnnotations/failures/StaticMethods.out	Sun Jun 28 00:01:09 2009 -0700
    84.3 @@ -0,0 +1,2 @@
    84.4 +StaticMethods.java:32:22: compiler.err.annotation.type.not.applicable
    84.5 +1 error
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/test/tools/javac/typeAnnotations/failures/VoidGenericMethod.java	Sun Jun 28 00:01:09 2009 -0700
    85.3 @@ -0,0 +1,35 @@
    85.4 +/*
    85.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.7 + *
    85.8 + * This code is free software; you can redistribute it and/or modify it
    85.9 + * under the terms of the GNU General Public License version 2 only, as
   85.10 + * published by the Free Software Foundation.
   85.11 + *
   85.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   85.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   85.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   85.15 + * version 2 for more details (a copy is included in the LICENSE file that
   85.16 + * accompanied this code).
   85.17 + *
   85.18 + * You should have received a copy of the GNU General Public License version
   85.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   85.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   85.21 + *
   85.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   85.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   85.24 + * have any questions.
   85.25 + */
   85.26 +
   85.27 +/*
   85.28 + * @test
   85.29 + * @bug 6843077
   85.30 + * @summary test type annotation on void generic methods
   85.31 + * @author Mahmood Ali
   85.32 + * @compile/fail -source 1.7 VoidGenericMethod.java
   85.33 + */
   85.34 +class VoidGenericMethod {
   85.35 +  public <T> @A void method() { }
   85.36 +}
   85.37 +
   85.38 +@interface A { }
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
    86.3 @@ -0,0 +1,37 @@
    86.4 +/*
    86.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    86.7 + *
    86.8 + * This code is free software; you can redistribute it and/or modify it
    86.9 + * under the terms of the GNU General Public License version 2 only, as
   86.10 + * published by the Free Software Foundation.
   86.11 + *
   86.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   86.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   86.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   86.15 + * version 2 for more details (a copy is included in the LICENSE file that
   86.16 + * accompanied this code).
   86.17 + *
   86.18 + * You should have received a copy of the GNU General Public License version
   86.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   86.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   86.21 + *
   86.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   86.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   86.24 + * have any questions.
   86.25 + */
   86.26 +
   86.27 +/*
   86.28 + * @test
   86.29 + * @bug 6843077
   86.30 + * @summary check for duplicate annotation values
   86.31 + * @author Mahmood Ali
   86.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
   86.33 + */
   86.34 +class DuplicateAnnotationValue {
   86.35 +  void test() {
   86.36 +    Object a = String @A(value = 2, value = 1) [].class;
   86.37 +  }
   86.38 +}
   86.39 +
   86.40 +@interface A { int value(); }
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
    87.3 @@ -0,0 +1,2 @@
    87.4 +DuplicateAnnotationValue.java:33:45: compiler.err.duplicate.annotation.member.value: value, A
    87.5 +1 error
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
    88.3 @@ -0,0 +1,38 @@
    88.4 +/*
    88.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    88.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    88.7 + *
    88.8 + * This code is free software; you can redistribute it and/or modify it
    88.9 + * under the terms of the GNU General Public License version 2 only, as
   88.10 + * published by the Free Software Foundation.
   88.11 + *
   88.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   88.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   88.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   88.15 + * version 2 for more details (a copy is included in the LICENSE file that
   88.16 + * accompanied this code).
   88.17 + *
   88.18 + * You should have received a copy of the GNU General Public License version
   88.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   88.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   88.21 + *
   88.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   88.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   88.24 + * have any questions.
   88.25 + */
   88.26 +
   88.27 +/*
   88.28 + * @test
   88.29 + * @bug 6843077
   88.30 + * @summary check for duplicate annotations
   88.31 + * @author Mahmood Ali
   88.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
   88.33 + */
   88.34 +
   88.35 +class DuplicateTypeAnnotation {
   88.36 +  void test() {
   88.37 +    Object a = String @A @A [].class;
   88.38 +  }
   88.39 +}
   88.40 +
   88.41 +@interface A { }
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
    89.3 @@ -0,0 +1,2 @@
    89.4 +DuplicateTypeAnnotation.java:34:26: compiler.err.duplicate.annotation
    89.5 +1 error
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
    90.3 @@ -0,0 +1,39 @@
    90.4 +/*
    90.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    90.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    90.7 + *
    90.8 + * This code is free software; you can redistribute it and/or modify it
    90.9 + * under the terms of the GNU General Public License version 2 only, as
   90.10 + * published by the Free Software Foundation.
   90.11 + *
   90.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   90.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   90.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   90.15 + * version 2 for more details (a copy is included in the LICENSE file that
   90.16 + * accompanied this code).
   90.17 + *
   90.18 + * You should have received a copy of the GNU General Public License version
   90.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   90.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   90.21 + *
   90.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   90.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   90.24 + * have any questions.
   90.25 + */
   90.26 +
   90.27 +/*
   90.28 + * @test
   90.29 + * @bug 6843077
   90.30 + * @summary check for invalid annotatins given the target
   90.31 + * @author Mahmood Ali
   90.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
   90.33 + */
   90.34 +
   90.35 +class InvalidLocation {
   90.36 +  void test() {
   90.37 +    Object a = String @A [].class;
   90.38 +  }
   90.39 +}
   90.40 +
   90.41 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
   90.42 +@interface A { }
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
    91.3 @@ -0,0 +1,2 @@
    91.4 +InvalidLocation.java:34:23: compiler.err.annotation.type.not.applicable
    91.5 +1 error
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
    92.3 @@ -0,0 +1,37 @@
    92.4 +/*
    92.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    92.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    92.7 + *
    92.8 + * This code is free software; you can redistribute it and/or modify it
    92.9 + * under the terms of the GNU General Public License version 2 only, as
   92.10 + * published by the Free Software Foundation.
   92.11 + *
   92.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   92.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   92.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   92.15 + * version 2 for more details (a copy is included in the LICENSE file that
   92.16 + * accompanied this code).
   92.17 + *
   92.18 + * You should have received a copy of the GNU General Public License version
   92.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   92.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   92.21 + *
   92.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   92.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   92.24 + * have any questions.
   92.25 + */
   92.26 +
   92.27 +/*
   92.28 + * @test
   92.29 + * @bug 6843077
   92.30 + * @summary check for missing annotation value
   92.31 + * @author Mahmood Ali
   92.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
   92.33 + */
   92.34 +class MissingAnnotationValue {
   92.35 +  void test() {
   92.36 +    Object a = String @A [].class;
   92.37 +  }
   92.38 +}
   92.39 +
   92.40 +@interface A { int field(); }
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
    93.3 @@ -0,0 +1,2 @@
    93.4 +MissingAnnotationValue.java:33:23: compiler.err.annotation.missing.default.value: A, field
    93.5 +1 error
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
    94.3 @@ -0,0 +1,37 @@
    94.4 +/*
    94.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    94.7 + *
    94.8 + * This code is free software; you can redistribute it and/or modify it
    94.9 + * under the terms of the GNU General Public License version 2 only, as
   94.10 + * published by the Free Software Foundation.
   94.11 + *
   94.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   94.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   94.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   94.15 + * version 2 for more details (a copy is included in the LICENSE file that
   94.16 + * accompanied this code).
   94.17 + *
   94.18 + * You should have received a copy of the GNU General Public License version
   94.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   94.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   94.21 + *
   94.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   94.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   94.24 + * have any questions.
   94.25 + */
   94.26 +
   94.27 +/*
   94.28 + * @test
   94.29 + * @bug 6843077
   94.30 + * @summary check for duplicate annotation values
   94.31 + * @author Mahmood Ali
   94.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
   94.33 + */
   94.34 +class DuplicateAnnotationValue {
   94.35 +  void test() {
   94.36 +    String @A(value = 2, value = 1) [] s;
   94.37 +  }
   94.38 +}
   94.39 +
   94.40 +@interface A { int value(); }
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
    95.3 @@ -0,0 +1,2 @@
    95.4 +DuplicateAnnotationValue.java:33:34: compiler.err.duplicate.annotation.member.value: value, A
    95.5 +1 error
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
    96.3 @@ -0,0 +1,38 @@
    96.4 +/*
    96.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    96.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    96.7 + *
    96.8 + * This code is free software; you can redistribute it and/or modify it
    96.9 + * under the terms of the GNU General Public License version 2 only, as
   96.10 + * published by the Free Software Foundation.
   96.11 + *
   96.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   96.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   96.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   96.15 + * version 2 for more details (a copy is included in the LICENSE file that
   96.16 + * accompanied this code).
   96.17 + *
   96.18 + * You should have received a copy of the GNU General Public License version
   96.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   96.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   96.21 + *
   96.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   96.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   96.24 + * have any questions.
   96.25 + */
   96.26 +
   96.27 +/*
   96.28 + * @test
   96.29 + * @bug 6843077
   96.30 + * @summary check for duplicate annotations
   96.31 + * @author Mahmood Ali
   96.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
   96.33 + */
   96.34 +
   96.35 +class DuplicateTypeAnnotation {
   96.36 +  void test() {
   96.37 +    String @A @A [] s;
   96.38 +  }
   96.39 +}
   96.40 +
   96.41 +@interface A { }
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
    97.3 @@ -0,0 +1,2 @@
    97.4 +DuplicateTypeAnnotation.java:34:15: compiler.err.duplicate.annotation
    97.5 +1 error
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
    98.3 @@ -0,0 +1,39 @@
    98.4 +/*
    98.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
    98.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    98.7 + *
    98.8 + * This code is free software; you can redistribute it and/or modify it
    98.9 + * under the terms of the GNU General Public License version 2 only, as
   98.10 + * published by the Free Software Foundation.
   98.11 + *
   98.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   98.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   98.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   98.15 + * version 2 for more details (a copy is included in the LICENSE file that
   98.16 + * accompanied this code).
   98.17 + *
   98.18 + * You should have received a copy of the GNU General Public License version
   98.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   98.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   98.21 + *
   98.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   98.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   98.24 + * have any questions.
   98.25 + */
   98.26 +
   98.27 +/*
   98.28 + * @test
   98.29 + * @bug 6843077
   98.30 + * @summary check for invalid annotatins given the target
   98.31 + * @author Mahmood Ali
   98.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
   98.33 + */
   98.34 +
   98.35 +class InvalidLocation {
   98.36 +  void test() {
   98.37 +    String @A [] s;
   98.38 +  }
   98.39 +}
   98.40 +
   98.41 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
   98.42 +@interface A { }
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
    99.3 @@ -0,0 +1,2 @@
    99.4 +InvalidLocation.java:34:12: compiler.err.annotation.type.not.applicable
    99.5 +1 error
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   100.3 @@ -0,0 +1,37 @@
   100.4 +/*
   100.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   100.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   100.7 + *
   100.8 + * This code is free software; you can redistribute it and/or modify it
   100.9 + * under the terms of the GNU General Public License version 2 only, as
  100.10 + * published by the Free Software Foundation.
  100.11 + *
  100.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  100.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  100.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  100.15 + * version 2 for more details (a copy is included in the LICENSE file that
  100.16 + * accompanied this code).
  100.17 + *
  100.18 + * You should have received a copy of the GNU General Public License version
  100.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  100.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  100.21 + *
  100.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  100.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  100.24 + * have any questions.
  100.25 + */
  100.26 +
  100.27 +/*
  100.28 + * @test
  100.29 + * @bug 6843077
  100.30 + * @summary check for missing annotation value
  100.31 + * @author Mahmood Ali
  100.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  100.33 + */
  100.34 +class MissingAnnotationValue {
  100.35 +  void test() {
  100.36 +    String @A [] s;
  100.37 +  }
  100.38 +}
  100.39 +
  100.40 +@interface A { int field(); }
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/test/tools/javac/typeAnnotations/failures/common/arrays/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   101.3 @@ -0,0 +1,2 @@
   101.4 +MissingAnnotationValue.java:33:12: compiler.err.annotation.missing.default.value: A, field
   101.5 +1 error
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   102.3 @@ -0,0 +1,37 @@
   102.4 +/*
   102.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   102.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   102.7 + *
   102.8 + * This code is free software; you can redistribute it and/or modify it
   102.9 + * under the terms of the GNU General Public License version 2 only, as
  102.10 + * published by the Free Software Foundation.
  102.11 + *
  102.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  102.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  102.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  102.15 + * version 2 for more details (a copy is included in the LICENSE file that
  102.16 + * accompanied this code).
  102.17 + *
  102.18 + * You should have received a copy of the GNU General Public License version
  102.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  102.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  102.21 + *
  102.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  102.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  102.24 + * have any questions.
  102.25 + */
  102.26 +
  102.27 +/*
  102.28 + * @test
  102.29 + * @bug 6843077
  102.30 + * @summary check for duplicate annotation values for type parameter
  102.31 + * @author Mahmood Ali
  102.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  102.33 + */
  102.34 +class DuplicateAnnotationValue {
  102.35 +  void method() {
  102.36 +    class Inner<@A(value = 2, value = 1) K> {}
  102.37 +  }
  102.38 +}
  102.39 +
  102.40 +@interface A { int value(); }
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   103.3 @@ -0,0 +1,2 @@
   103.4 +DuplicateAnnotationValue.java:33:39: compiler.err.duplicate.annotation.member.value: value, A
   103.5 +1 error
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   104.3 @@ -0,0 +1,37 @@
   104.4 +/*
   104.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   104.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   104.7 + *
   104.8 + * This code is free software; you can redistribute it and/or modify it
   104.9 + * under the terms of the GNU General Public License version 2 only, as
  104.10 + * published by the Free Software Foundation.
  104.11 + *
  104.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  104.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  104.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  104.15 + * version 2 for more details (a copy is included in the LICENSE file that
  104.16 + * accompanied this code).
  104.17 + *
  104.18 + * You should have received a copy of the GNU General Public License version
  104.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  104.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  104.21 + *
  104.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  104.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  104.24 + * have any questions.
  104.25 + */
  104.26 +
  104.27 +/*
  104.28 + * @test
  104.29 + * @bug 6843077
  104.30 + * @summary check for duplicate annotations
  104.31 + * @author Mahmood Ali
  104.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  104.33 + */
  104.34 +class DuplicateTypeAnno {
  104.35 +  void innermethod() {
  104.36 +    class Inner<@A @A K> { }
  104.37 +  }
  104.38 +}
  104.39 +
  104.40 +@interface A { }
   105.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   105.3 @@ -0,0 +1,2 @@
   105.4 +DuplicateTypeAnnotation.java:33:20: compiler.err.duplicate.annotation
   105.5 +1 error
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   106.3 @@ -0,0 +1,38 @@
   106.4 +/*
   106.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   106.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   106.7 + *
   106.8 + * This code is free software; you can redistribute it and/or modify it
   106.9 + * under the terms of the GNU General Public License version 2 only, as
  106.10 + * published by the Free Software Foundation.
  106.11 + *
  106.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  106.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  106.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  106.15 + * version 2 for more details (a copy is included in the LICENSE file that
  106.16 + * accompanied this code).
  106.17 + *
  106.18 + * You should have received a copy of the GNU General Public License version
  106.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  106.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  106.21 + *
  106.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  106.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  106.24 + * have any questions.
  106.25 + */
  106.26 +
  106.27 +/*
  106.28 + * @test
  106.29 + * @bug 6843077
  106.30 + * @summary check for invalid annotatins given the target
  106.31 + * @author Mahmood Ali
  106.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  106.33 + */
  106.34 +class InvalidLocation {
  106.35 +  void innermethod() {
  106.36 +    class Inner<@A K> {}
  106.37 +  }
  106.38 +}
  106.39 +
  106.40 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  106.41 +@interface A { }
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   107.3 @@ -0,0 +1,2 @@
   107.4 +InvalidLocation.java:33:17: compiler.err.annotation.type.not.applicable
   107.5 +1 error
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   108.3 @@ -0,0 +1,37 @@
   108.4 +/*
   108.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   108.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   108.7 + *
   108.8 + * This code is free software; you can redistribute it and/or modify it
   108.9 + * under the terms of the GNU General Public License version 2 only, as
  108.10 + * published by the Free Software Foundation.
  108.11 + *
  108.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  108.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  108.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  108.15 + * version 2 for more details (a copy is included in the LICENSE file that
  108.16 + * accompanied this code).
  108.17 + *
  108.18 + * You should have received a copy of the GNU General Public License version
  108.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  108.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  108.21 + *
  108.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  108.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  108.24 + * have any questions.
  108.25 + */
  108.26 +
  108.27 +/*
  108.28 + * @test
  108.29 + * @bug 6843077
  108.30 + * @summary check for missing annotation value
  108.31 + * @author Mahmood Ali
  108.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  108.33 + */
  108.34 +class MissingAnnotationValue {
  108.35 +  void innermethod() {
  108.36 +    class Inner<@A K> { }
  108.37 +  }
  108.38 +}
  108.39 +
  108.40 +@interface A { int field(); }
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/test/tools/javac/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   109.3 @@ -0,0 +1,2 @@
   109.4 +MissingAnnotationValue.java:33:17: compiler.err.annotation.missing.default.value: A, field
   109.5 +1 error
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   110.3 @@ -0,0 +1,37 @@
   110.4 +/*
   110.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   110.7 + *
   110.8 + * This code is free software; you can redistribute it and/or modify it
   110.9 + * under the terms of the GNU General Public License version 2 only, as
  110.10 + * published by the Free Software Foundation.
  110.11 + *
  110.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  110.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  110.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  110.15 + * version 2 for more details (a copy is included in the LICENSE file that
  110.16 + * accompanied this code).
  110.17 + *
  110.18 + * You should have received a copy of the GNU General Public License version
  110.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  110.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  110.21 + *
  110.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  110.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  110.24 + * have any questions.
  110.25 + */
  110.26 +
  110.27 +/*
  110.28 + * @test
  110.29 + * @bug 6843077
  110.30 + * @summary check for duplicate annotation values
  110.31 + * @author Mahmood Ali
  110.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  110.33 + */
  110.34 +class DuplicateAnnotationValue {
  110.35 +  void test() {
  110.36 +    String[] a = new String @A(value = 2, value = 1) [5] ;
  110.37 +  }
  110.38 +}
  110.39 +
  110.40 +@interface A { int value(); }
   111.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   111.3 @@ -0,0 +1,2 @@
   111.4 +DuplicateAnnotationValue.java:33:51: compiler.err.duplicate.annotation.member.value: value, A
   111.5 +1 error
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   112.3 @@ -0,0 +1,38 @@
   112.4 +/*
   112.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   112.7 + *
   112.8 + * This code is free software; you can redistribute it and/or modify it
   112.9 + * under the terms of the GNU General Public License version 2 only, as
  112.10 + * published by the Free Software Foundation.
  112.11 + *
  112.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  112.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  112.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  112.15 + * version 2 for more details (a copy is included in the LICENSE file that
  112.16 + * accompanied this code).
  112.17 + *
  112.18 + * You should have received a copy of the GNU General Public License version
  112.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  112.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  112.21 + *
  112.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  112.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  112.24 + * have any questions.
  112.25 + */
  112.26 +
  112.27 +/*
  112.28 + * @test
  112.29 + * @bug 6843077
  112.30 + * @summary check for duplicate annotations
  112.31 + * @author Mahmood Ali
  112.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  112.33 + */
  112.34 +
  112.35 +class DuplicateTypeAnnotation {
  112.36 +  void test() {
  112.37 +    String[] a = new String @A @A [5] ;
  112.38 +  }
  112.39 +}
  112.40 +
  112.41 +@interface A { }
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   113.3 @@ -0,0 +1,2 @@
   113.4 +DuplicateTypeAnnotation.java:34:32: compiler.err.duplicate.annotation
   113.5 +1 error
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   114.3 @@ -0,0 +1,39 @@
   114.4 +/*
   114.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   114.7 + *
   114.8 + * This code is free software; you can redistribute it and/or modify it
   114.9 + * under the terms of the GNU General Public License version 2 only, as
  114.10 + * published by the Free Software Foundation.
  114.11 + *
  114.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  114.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  114.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  114.15 + * version 2 for more details (a copy is included in the LICENSE file that
  114.16 + * accompanied this code).
  114.17 + *
  114.18 + * You should have received a copy of the GNU General Public License version
  114.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  114.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  114.21 + *
  114.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  114.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  114.24 + * have any questions.
  114.25 + */
  114.26 +
  114.27 +/*
  114.28 + * @test
  114.29 + * @bug 6843077
  114.30 + * @summary check for invalid annotatins given the target
  114.31 + * @author Mahmood Ali
  114.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  114.33 + */
  114.34 +
  114.35 +class InvalidLocation {
  114.36 +  void test() {
  114.37 +    String[] s = new String @A [5] ;
  114.38 +  }
  114.39 +}
  114.40 +
  114.41 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  114.42 +@interface A { }
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   115.3 @@ -0,0 +1,2 @@
   115.4 +InvalidLocation.java:34:29: compiler.err.annotation.type.not.applicable
   115.5 +1 error
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   116.3 @@ -0,0 +1,37 @@
   116.4 +/*
   116.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   116.7 + *
   116.8 + * This code is free software; you can redistribute it and/or modify it
   116.9 + * under the terms of the GNU General Public License version 2 only, as
  116.10 + * published by the Free Software Foundation.
  116.11 + *
  116.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  116.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  116.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  116.15 + * version 2 for more details (a copy is included in the LICENSE file that
  116.16 + * accompanied this code).
  116.17 + *
  116.18 + * You should have received a copy of the GNU General Public License version
  116.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  116.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  116.21 + *
  116.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  116.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  116.24 + * have any questions.
  116.25 + */
  116.26 +
  116.27 +/*
  116.28 + * @test
  116.29 + * @bug 6843077
  116.30 + * @summary check for missing annotation value
  116.31 + * @author Mahmood Ali
  116.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  116.33 + */
  116.34 +class MissingAnnotationValue {
  116.35 +  void test() {
  116.36 +    String[] a = new String @A [5];
  116.37 +  }
  116.38 +}
  116.39 +
  116.40 +@interface A { int field(); }
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/test/tools/javac/typeAnnotations/failures/common/newarray/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   117.3 @@ -0,0 +1,2 @@
   117.4 +MissingAnnotationValue.java:33:29: compiler.err.annotation.missing.default.value: A, field
   117.5 +1 error
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   118.3 @@ -0,0 +1,34 @@
   118.4 +/*
   118.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   118.7 + *
   118.8 + * This code is free software; you can redistribute it and/or modify it
   118.9 + * under the terms of the GNU General Public License version 2 only, as
  118.10 + * published by the Free Software Foundation.
  118.11 + *
  118.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  118.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  118.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  118.15 + * version 2 for more details (a copy is included in the LICENSE file that
  118.16 + * accompanied this code).
  118.17 + *
  118.18 + * You should have received a copy of the GNU General Public License version
  118.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  118.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  118.21 + *
  118.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  118.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  118.24 + * have any questions.
  118.25 + */
  118.26 +
  118.27 +/*
  118.28 + * @test
  118.29 + * @bug 6843077
  118.30 + * @summary check for duplicate annotation values for type parameter
  118.31 + * @author Mahmood Ali
  118.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  118.33 + */
  118.34 +class DuplicateAnnotationValue<K extends @A(value = 2, value = 1) Object> {
  118.35 +}
  118.36 +
  118.37 +@interface A { int value(); }
   119.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   119.3 @@ -0,0 +1,2 @@
   119.4 +DuplicateAnnotationValue.java:31:64: compiler.err.duplicate.annotation.member.value: value, A
   119.5 +1 error
   120.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   120.3 @@ -0,0 +1,35 @@
   120.4 +/*
   120.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   120.7 + *
   120.8 + * This code is free software; you can redistribute it and/or modify it
   120.9 + * under the terms of the GNU General Public License version 2 only, as
  120.10 + * published by the Free Software Foundation.
  120.11 + *
  120.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  120.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  120.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  120.15 + * version 2 for more details (a copy is included in the LICENSE file that
  120.16 + * accompanied this code).
  120.17 + *
  120.18 + * You should have received a copy of the GNU General Public License version
  120.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  120.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  120.21 + *
  120.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  120.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  120.24 + * have any questions.
  120.25 + */
  120.26 +
  120.27 +/*
  120.28 + * @test
  120.29 + * @bug 6843077
  120.30 + * @summary check for duplicate annotations
  120.31 + * @author Mahmood Ali
  120.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  120.33 + */
  120.34 +
  120.35 +class DuplicateTypeAnno<K extends @A @A Object> {
  120.36 +}
  120.37 +
  120.38 +@interface A { }
   121.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   121.3 @@ -0,0 +1,2 @@
   121.4 +DuplicateTypeAnnotation.java:32:38: compiler.err.duplicate.annotation
   121.5 +1 error
   122.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   122.3 @@ -0,0 +1,36 @@
   122.4 +/*
   122.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   122.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   122.7 + *
   122.8 + * This code is free software; you can redistribute it and/or modify it
   122.9 + * under the terms of the GNU General Public License version 2 only, as
  122.10 + * published by the Free Software Foundation.
  122.11 + *
  122.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  122.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  122.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  122.15 + * version 2 for more details (a copy is included in the LICENSE file that
  122.16 + * accompanied this code).
  122.17 + *
  122.18 + * You should have received a copy of the GNU General Public License version
  122.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  122.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  122.21 + *
  122.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  122.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  122.24 + * have any questions.
  122.25 + */
  122.26 +
  122.27 +/*
  122.28 + * @test
  122.29 + * @bug 6843077
  122.30 + * @summary check for invalid annotatins given the target
  122.31 + * @author Mahmood Ali
  122.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  122.33 + */
  122.34 +
  122.35 +class InvalidLocation<K extends @A Object> {
  122.36 +}
  122.37 +
  122.38 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  122.39 +@interface A { }
   123.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   123.3 @@ -0,0 +1,2 @@
   123.4 +InvalidLocation.java:32:33: compiler.err.annotation.type.not.applicable
   123.5 +1 error
   124.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   124.3 @@ -0,0 +1,34 @@
   124.4 +/*
   124.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   124.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   124.7 + *
   124.8 + * This code is free software; you can redistribute it and/or modify it
   124.9 + * under the terms of the GNU General Public License version 2 only, as
  124.10 + * published by the Free Software Foundation.
  124.11 + *
  124.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  124.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  124.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  124.15 + * version 2 for more details (a copy is included in the LICENSE file that
  124.16 + * accompanied this code).
  124.17 + *
  124.18 + * You should have received a copy of the GNU General Public License version
  124.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  124.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  124.21 + *
  124.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  124.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  124.24 + * have any questions.
  124.25 + */
  124.26 +
  124.27 +/*
  124.28 + * @test
  124.29 + * @bug 6843077
  124.30 + * @summary check for missing annotation value
  124.31 + * @author Mahmood Ali
  124.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  124.33 + */
  124.34 +class MissingAnnotationValue<K extends @A Object> {
  124.35 +}
  124.36 +
  124.37 +@interface A { int field(); }
   125.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   125.2 +++ b/test/tools/javac/typeAnnotations/failures/common/parambounds/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   125.3 @@ -0,0 +1,2 @@
   125.4 +MissingAnnotationValue.java:31:40: compiler.err.annotation.missing.default.value: A, field
   125.5 +1 error
   126.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   126.3 @@ -0,0 +1,35 @@
   126.4 +/*
   126.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   126.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   126.7 + *
   126.8 + * This code is free software; you can redistribute it and/or modify it
   126.9 + * under the terms of the GNU General Public License version 2 only, as
  126.10 + * published by the Free Software Foundation.
  126.11 + *
  126.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  126.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  126.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  126.15 + * version 2 for more details (a copy is included in the LICENSE file that
  126.16 + * accompanied this code).
  126.17 + *
  126.18 + * You should have received a copy of the GNU General Public License version
  126.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  126.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  126.21 + *
  126.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  126.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  126.24 + * have any questions.
  126.25 + */
  126.26 +
  126.27 +/*
  126.28 + * @test
  126.29 + * @bug 6843077
  126.30 + * @summary check for duplicate annotation values in receiver
  126.31 + * @author Mahmood Ali
  126.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  126.33 + */
  126.34 +class DuplicateAnnotationValue {
  126.35 +  void test() @A(value = 2, value = 1) { }
  126.36 +}
  126.37 +
  126.38 +@interface A { int value(); }
   127.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   127.3 @@ -0,0 +1,2 @@
   127.4 +DuplicateAnnotationValue.java:32:37: compiler.err.duplicate.annotation.member.value: value, A
   127.5 +1 error
   128.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   128.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   128.3 @@ -0,0 +1,36 @@
   128.4 +/*
   128.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   128.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   128.7 + *
   128.8 + * This code is free software; you can redistribute it and/or modify it
   128.9 + * under the terms of the GNU General Public License version 2 only, as
  128.10 + * published by the Free Software Foundation.
  128.11 + *
  128.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  128.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  128.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  128.15 + * version 2 for more details (a copy is included in the LICENSE file that
  128.16 + * accompanied this code).
  128.17 + *
  128.18 + * You should have received a copy of the GNU General Public License version
  128.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  128.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  128.21 + *
  128.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  128.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  128.24 + * have any questions.
  128.25 + */
  128.26 +
  128.27 +/*
  128.28 + * @test
  128.29 + * @bug 6843077
  128.30 + * @summary check for duplicate annotations in receiver
  128.31 + * @author Mahmood Ali
  128.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  128.33 + */
  128.34 +
  128.35 +class DuplicateTypeAnnotation {
  128.36 +  void test() @A @A { }
  128.37 +}
  128.38 +
  128.39 +@interface A { }
   129.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   129.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   129.3 @@ -0,0 +1,2 @@
   129.4 +DuplicateTypeAnnotation.java:33:18: compiler.err.duplicate.annotation
   129.5 +1 error
   130.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   130.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   130.3 @@ -0,0 +1,38 @@
   130.4 +/*
   130.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   130.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   130.7 + *
   130.8 + * This code is free software; you can redistribute it and/or modify it
   130.9 + * under the terms of the GNU General Public License version 2 only, as
  130.10 + * published by the Free Software Foundation.
  130.11 + *
  130.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  130.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  130.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  130.15 + * version 2 for more details (a copy is included in the LICENSE file that
  130.16 + * accompanied this code).
  130.17 + *
  130.18 + * You should have received a copy of the GNU General Public License version
  130.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  130.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  130.21 + *
  130.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  130.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  130.24 + * have any questions.
  130.25 + */
  130.26 +
  130.27 +/*
  130.28 + * @test
  130.29 + * @bug 6843077
  130.30 + * @summary check for invalid annotatins given the target
  130.31 + * @author Mahmood Ali
  130.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  130.33 + */
  130.34 +
  130.35 +class InvalidLocation {
  130.36 +  void test() @A {
  130.37 +  }
  130.38 +}
  130.39 +
  130.40 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  130.41 +@interface A { }
   131.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   131.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   131.3 @@ -0,0 +1,2 @@
   131.4 +InvalidLocation.java:33:15: compiler.err.annotation.type.not.applicable
   131.5 +1 error
   132.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   132.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   132.3 @@ -0,0 +1,35 @@
   132.4 +/*
   132.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   132.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   132.7 + *
   132.8 + * This code is free software; you can redistribute it and/or modify it
   132.9 + * under the terms of the GNU General Public License version 2 only, as
  132.10 + * published by the Free Software Foundation.
  132.11 + *
  132.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  132.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  132.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  132.15 + * version 2 for more details (a copy is included in the LICENSE file that
  132.16 + * accompanied this code).
  132.17 + *
  132.18 + * You should have received a copy of the GNU General Public License version
  132.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  132.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  132.21 + *
  132.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  132.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  132.24 + * have any questions.
  132.25 + */
  132.26 +
  132.27 +/*
  132.28 + * @test
  132.29 + * @bug 6843077
  132.30 + * @summary check for missing annotation value
  132.31 + * @author Mahmood Ali
  132.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  132.33 + */
  132.34 +class MissingAnnotationValue {
  132.35 +  void test() @A { }
  132.36 +}
  132.37 +
  132.38 +@interface A { int field(); }
   133.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.2 +++ b/test/tools/javac/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   133.3 @@ -0,0 +1,2 @@
   133.4 +MissingAnnotationValue.java:32:15: compiler.err.annotation.missing.default.value: A, field
   133.5 +1 error
   134.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   134.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   134.3 @@ -0,0 +1,37 @@
   134.4 +/*
   134.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   134.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   134.7 + *
   134.8 + * This code is free software; you can redistribute it and/or modify it
   134.9 + * under the terms of the GNU General Public License version 2 only, as
  134.10 + * published by the Free Software Foundation.
  134.11 + *
  134.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  134.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  134.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  134.15 + * version 2 for more details (a copy is included in the LICENSE file that
  134.16 + * accompanied this code).
  134.17 + *
  134.18 + * You should have received a copy of the GNU General Public License version
  134.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  134.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  134.21 + *
  134.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  134.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  134.24 + * have any questions.
  134.25 + */
  134.26 +
  134.27 +/*
  134.28 + * @test
  134.29 + * @bug 6843077
  134.30 + * @summary check for Duplicate annotation value
  134.31 + * @author Mahmood Ali
  134.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  134.33 + */
  134.34 +class DuplicateAnnotationValue {
  134.35 +  void test() {
  134.36 +    new @A String();
  134.37 +  }
  134.38 +}
  134.39 +
  134.40 +@interface A { int field(); }
   135.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   135.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   135.3 @@ -0,0 +1,2 @@
   135.4 +DuplicateAnnotationValue.java:33:9: compiler.err.annotation.missing.default.value: A, field
   135.5 +1 error
   136.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   136.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   136.3 @@ -0,0 +1,38 @@
   136.4 +/*
   136.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   136.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   136.7 + *
   136.8 + * This code is free software; you can redistribute it and/or modify it
   136.9 + * under the terms of the GNU General Public License version 2 only, as
  136.10 + * published by the Free Software Foundation.
  136.11 + *
  136.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  136.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  136.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  136.15 + * version 2 for more details (a copy is included in the LICENSE file that
  136.16 + * accompanied this code).
  136.17 + *
  136.18 + * You should have received a copy of the GNU General Public License version
  136.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  136.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  136.21 + *
  136.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  136.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  136.24 + * have any questions.
  136.25 + */
  136.26 +
  136.27 +/*
  136.28 + * @test
  136.29 + * @bug 6843077
  136.30 + * @summary check for duplicate annotations
  136.31 + * @author Mahmood Ali
  136.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  136.33 + */
  136.34 +
  136.35 +class DuplicateTypeAnnotation {
  136.36 +  void test() {
  136.37 +    new @A @A String();
  136.38 +  }
  136.39 +}
  136.40 +
  136.41 +@interface A { }
   137.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   137.3 @@ -0,0 +1,2 @@
   137.4 +DuplicateTypeAnnotation.java:34:12: compiler.err.duplicate.annotation
   137.5 +1 error
   138.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   138.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   138.3 @@ -0,0 +1,39 @@
   138.4 +/*
   138.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   138.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   138.7 + *
   138.8 + * This code is free software; you can redistribute it and/or modify it
   138.9 + * under the terms of the GNU General Public License version 2 only, as
  138.10 + * published by the Free Software Foundation.
  138.11 + *
  138.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  138.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  138.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  138.15 + * version 2 for more details (a copy is included in the LICENSE file that
  138.16 + * accompanied this code).
  138.17 + *
  138.18 + * You should have received a copy of the GNU General Public License version
  138.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  138.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  138.21 + *
  138.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  138.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  138.24 + * have any questions.
  138.25 + */
  138.26 +
  138.27 +/*
  138.28 + * @test
  138.29 + * @bug 6843077
  138.30 + * @summary check for invalid annotatins given the target
  138.31 + * @author Mahmood Ali
  138.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  138.33 + */
  138.34 +
  138.35 +class InvalidLocation {
  138.36 +  void test() {
  138.37 +    new @A String();
  138.38 +  }
  138.39 +}
  138.40 +
  138.41 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  138.42 +@interface A { }
   139.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   139.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   139.3 @@ -0,0 +1,2 @@
   139.4 +InvalidLocation.java:34:9: compiler.err.annotation.type.not.applicable
   139.5 +1 error
   140.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   140.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   140.3 @@ -0,0 +1,37 @@
   140.4 +/*
   140.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   140.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   140.7 + *
   140.8 + * This code is free software; you can redistribute it and/or modify it
   140.9 + * under the terms of the GNU General Public License version 2 only, as
  140.10 + * published by the Free Software Foundation.
  140.11 + *
  140.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  140.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  140.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  140.15 + * version 2 for more details (a copy is included in the LICENSE file that
  140.16 + * accompanied this code).
  140.17 + *
  140.18 + * You should have received a copy of the GNU General Public License version
  140.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  140.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  140.21 + *
  140.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  140.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  140.24 + * have any questions.
  140.25 + */
  140.26 +
  140.27 +/*
  140.28 + * @test
  140.29 + * @bug 6843077
  140.30 + * @summary check for missing annotation value
  140.31 + * @author Mahmood Ali
  140.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  140.33 + */
  140.34 +class MissingAnnotationValue {
  140.35 +  void test() {
  140.36 +    new @A String();
  140.37 +  }
  140.38 +}
  140.39 +
  140.40 +@interface A { int field(); }
   141.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   141.2 +++ b/test/tools/javac/typeAnnotations/failures/common/rest/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   141.3 @@ -0,0 +1,2 @@
   141.4 +MissingAnnotationValue.java:33:9: compiler.err.annotation.missing.default.value: A, field
   141.5 +1 error
   142.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   142.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   142.3 @@ -0,0 +1,35 @@
   142.4 +/*
   142.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   142.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   142.7 + *
   142.8 + * This code is free software; you can redistribute it and/or modify it
   142.9 + * under the terms of the GNU General Public License version 2 only, as
  142.10 + * published by the Free Software Foundation.
  142.11 + *
  142.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  142.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  142.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  142.15 + * version 2 for more details (a copy is included in the LICENSE file that
  142.16 + * accompanied this code).
  142.17 + *
  142.18 + * You should have received a copy of the GNU General Public License version
  142.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  142.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  142.21 + *
  142.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  142.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  142.24 + * have any questions.
  142.25 + */
  142.26 +
  142.27 +/*
  142.28 + * @test
  142.29 + * @bug 6843077
  142.30 + * @summary check for duplicate annotation values for type parameter
  142.31 + * @author Mahmood Ali
  142.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  142.33 + */
  142.34 +class DuplicateAnnotationValue<K> {
  142.35 +  DuplicateAnnotationValue<@A(value = 2, value = 1) String> l;
  142.36 +}
  142.37 +
  142.38 +@interface A { int value(); }
   143.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   143.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   143.3 @@ -0,0 +1,2 @@
   143.4 +DuplicateAnnotationValue.java:32:50: compiler.err.duplicate.annotation.member.value: value, A
   143.5 +1 error
   144.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   144.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   144.3 @@ -0,0 +1,36 @@
   144.4 +/*
   144.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   144.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   144.7 + *
   144.8 + * This code is free software; you can redistribute it and/or modify it
   144.9 + * under the terms of the GNU General Public License version 2 only, as
  144.10 + * published by the Free Software Foundation.
  144.11 + *
  144.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  144.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  144.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  144.15 + * version 2 for more details (a copy is included in the LICENSE file that
  144.16 + * accompanied this code).
  144.17 + *
  144.18 + * You should have received a copy of the GNU General Public License version
  144.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  144.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  144.21 + *
  144.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  144.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  144.24 + * have any questions.
  144.25 + */
  144.26 +
  144.27 +/*
  144.28 + * @test
  144.29 + * @bug 6843077
  144.30 + * @summary check for duplicate annotations
  144.31 + * @author Mahmood Ali
  144.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  144.33 + */
  144.34 +
  144.35 +class DuplicateTypeAnno<K> {
  144.36 +  DuplicateTypeAnno<@A @A String> l;
  144.37 +}
  144.38 +
  144.39 +@interface A { }
   145.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   145.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   145.3 @@ -0,0 +1,2 @@
   145.4 +DuplicateTypeAnnotation.java:33:24: compiler.err.duplicate.annotation
   145.5 +1 error
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   146.3 @@ -0,0 +1,37 @@
   146.4 +/*
   146.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   146.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   146.7 + *
   146.8 + * This code is free software; you can redistribute it and/or modify it
   146.9 + * under the terms of the GNU General Public License version 2 only, as
  146.10 + * published by the Free Software Foundation.
  146.11 + *
  146.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  146.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  146.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  146.15 + * version 2 for more details (a copy is included in the LICENSE file that
  146.16 + * accompanied this code).
  146.17 + *
  146.18 + * You should have received a copy of the GNU General Public License version
  146.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  146.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  146.21 + *
  146.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  146.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  146.24 + * have any questions.
  146.25 + */
  146.26 +
  146.27 +/*
  146.28 + * @test
  146.29 + * @bug 6843077
  146.30 + * @summary check for invalid annotatins given the target
  146.31 + * @author Mahmood Ali
  146.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  146.33 + */
  146.34 +
  146.35 +class InvalidLocation<K> {
  146.36 +  InvalidLocation<@A String> l;
  146.37 +}
  146.38 +
  146.39 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  146.40 +@interface A { }
   147.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   147.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   147.3 @@ -0,0 +1,2 @@
   147.4 +InvalidLocation.java:33:19: compiler.err.annotation.type.not.applicable
   147.5 +1 error
   148.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   148.3 @@ -0,0 +1,35 @@
   148.4 +/*
   148.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   148.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   148.7 + *
   148.8 + * This code is free software; you can redistribute it and/or modify it
   148.9 + * under the terms of the GNU General Public License version 2 only, as
  148.10 + * published by the Free Software Foundation.
  148.11 + *
  148.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  148.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  148.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  148.15 + * version 2 for more details (a copy is included in the LICENSE file that
  148.16 + * accompanied this code).
  148.17 + *
  148.18 + * You should have received a copy of the GNU General Public License version
  148.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  148.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  148.21 + *
  148.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  148.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  148.24 + * have any questions.
  148.25 + */
  148.26 +
  148.27 +/*
  148.28 + * @test
  148.29 + * @bug 6843077
  148.30 + * @summary check for missing annotation value
  148.31 + * @author Mahmood Ali
  148.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  148.33 + */
  148.34 +class MissingAnnotationValue<K> {
  148.35 +  MissingAnnotationValue<@A String> l;
  148.36 +}
  148.37 +
  148.38 +@interface A { int field(); }
   149.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   149.3 @@ -0,0 +1,2 @@
   149.4 +MissingAnnotationValue.java:32:26: compiler.err.annotation.missing.default.value: A, field
   149.5 +1 error
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   150.3 @@ -0,0 +1,34 @@
   150.4 +/*
   150.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   150.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   150.7 + *
   150.8 + * This code is free software; you can redistribute it and/or modify it
   150.9 + * under the terms of the GNU General Public License version 2 only, as
  150.10 + * published by the Free Software Foundation.
  150.11 + *
  150.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  150.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  150.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  150.15 + * version 2 for more details (a copy is included in the LICENSE file that
  150.16 + * accompanied this code).
  150.17 + *
  150.18 + * You should have received a copy of the GNU General Public License version
  150.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  150.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  150.21 + *
  150.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  150.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  150.24 + * have any questions.
  150.25 + */
  150.26 +
  150.27 +/*
  150.28 + * @test
  150.29 + * @bug 6843077
  150.30 + * @summary check for duplicate annotation values for type parameter
  150.31 + * @author Mahmood Ali
  150.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  150.33 + */
  150.34 +class DuplicateAnnotationValue<@A(value = 2, value = 1) K> {
  150.35 +}
  150.36 +
  150.37 +@interface A { int value(); }
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   151.3 @@ -0,0 +1,2 @@
   151.4 +DuplicateAnnotationValue.java:31:54: compiler.err.duplicate.annotation.member.value: value, A
   151.5 +1 error
   152.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   152.3 @@ -0,0 +1,35 @@
   152.4 +/*
   152.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   152.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   152.7 + *
   152.8 + * This code is free software; you can redistribute it and/or modify it
   152.9 + * under the terms of the GNU General Public License version 2 only, as
  152.10 + * published by the Free Software Foundation.
  152.11 + *
  152.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  152.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  152.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  152.15 + * version 2 for more details (a copy is included in the LICENSE file that
  152.16 + * accompanied this code).
  152.17 + *
  152.18 + * You should have received a copy of the GNU General Public License version
  152.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  152.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  152.21 + *
  152.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  152.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  152.24 + * have any questions.
  152.25 + */
  152.26 +
  152.27 +/*
  152.28 + * @test
  152.29 + * @bug 6843077
  152.30 + * @summary check for duplicate annotations
  152.31 + * @author Mahmood Ali
  152.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  152.33 + */
  152.34 +
  152.35 +class DuplicateTypeAnno<@A @A K> {
  152.36 +}
  152.37 +
  152.38 +@interface A { }
   153.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   153.3 @@ -0,0 +1,2 @@
   153.4 +DuplicateTypeAnnotation.java:32:28: compiler.err.duplicate.annotation
   153.5 +1 error
   154.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   154.3 @@ -0,0 +1,36 @@
   154.4 +/*
   154.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   154.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   154.7 + *
   154.8 + * This code is free software; you can redistribute it and/or modify it
   154.9 + * under the terms of the GNU General Public License version 2 only, as
  154.10 + * published by the Free Software Foundation.
  154.11 + *
  154.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  154.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  154.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  154.15 + * version 2 for more details (a copy is included in the LICENSE file that
  154.16 + * accompanied this code).
  154.17 + *
  154.18 + * You should have received a copy of the GNU General Public License version
  154.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  154.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  154.21 + *
  154.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  154.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  154.24 + * have any questions.
  154.25 + */
  154.26 +
  154.27 +/*
  154.28 + * @test
  154.29 + * @bug 6843077
  154.30 + * @summary check for invalid annotatins given the target
  154.31 + * @author Mahmood Ali
  154.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  154.33 + */
  154.34 +
  154.35 +class InvalidLocation<@A K> {
  154.36 +}
  154.37 +
  154.38 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  154.39 +@interface A { }
   155.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   155.3 @@ -0,0 +1,2 @@
   155.4 +InvalidLocation.java:32:23: compiler.err.annotation.type.not.applicable
   155.5 +1 error
   156.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   156.3 @@ -0,0 +1,34 @@
   156.4 +/*
   156.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   156.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   156.7 + *
   156.8 + * This code is free software; you can redistribute it and/or modify it
   156.9 + * under the terms of the GNU General Public License version 2 only, as
  156.10 + * published by the Free Software Foundation.
  156.11 + *
  156.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  156.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  156.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  156.15 + * version 2 for more details (a copy is included in the LICENSE file that
  156.16 + * accompanied this code).
  156.17 + *
  156.18 + * You should have received a copy of the GNU General Public License version
  156.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  156.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  156.21 + *
  156.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  156.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  156.24 + * have any questions.
  156.25 + */
  156.26 +
  156.27 +/*
  156.28 + * @test
  156.29 + * @bug 6843077
  156.30 + * @summary check for missing annotation value
  156.31 + * @author Mahmood Ali
  156.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  156.33 + */
  156.34 +class MissingAnnotationValue<@A K> {
  156.35 +}
  156.36 +
  156.37 +@interface A { int field(); }
   157.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.2 +++ b/test/tools/javac/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   157.3 @@ -0,0 +1,2 @@
   157.4 +MissingAnnotationValue.java:31:30: compiler.err.annotation.missing.default.value: A, field
   157.5 +1 error
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   158.3 @@ -0,0 +1,35 @@
   158.4 +/*
   158.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   158.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   158.7 + *
   158.8 + * This code is free software; you can redistribute it and/or modify it
   158.9 + * under the terms of the GNU General Public License version 2 only, as
  158.10 + * published by the Free Software Foundation.
  158.11 + *
  158.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  158.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  158.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  158.15 + * version 2 for more details (a copy is included in the LICENSE file that
  158.16 + * accompanied this code).
  158.17 + *
  158.18 + * You should have received a copy of the GNU General Public License version
  158.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  158.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  158.21 + *
  158.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  158.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  158.24 + * have any questions.
  158.25 + */
  158.26 +
  158.27 +/*
  158.28 + * @test
  158.29 + * @bug 6843077
  158.30 + * @summary check for duplicate annotation values for type parameter
  158.31 + * @author Mahmood Ali
  158.32 + * @compile/fail/ref=DuplicateAnnotationValue.out -XDrawDiagnostics -source 1.7 DuplicateAnnotationValue.java
  158.33 + */
  158.34 +class DuplicateAnnotationValue<K> {
  158.35 +  DuplicateAnnotationValue<@A(value = 2, value = 1) ?> l;
  158.36 +}
  158.37 +
  158.38 +@interface A { int value(); }
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   159.3 @@ -0,0 +1,2 @@
   159.4 +DuplicateAnnotationValue.java:32:50: compiler.err.duplicate.annotation.member.value: value, A
   159.5 +1 error
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateTypeAnnotation.java	Sun Jun 28 00:01:09 2009 -0700
   160.3 @@ -0,0 +1,36 @@
   160.4 +/*
   160.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   160.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   160.7 + *
   160.8 + * This code is free software; you can redistribute it and/or modify it
   160.9 + * under the terms of the GNU General Public License version 2 only, as
  160.10 + * published by the Free Software Foundation.
  160.11 + *
  160.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  160.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  160.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  160.15 + * version 2 for more details (a copy is included in the LICENSE file that
  160.16 + * accompanied this code).
  160.17 + *
  160.18 + * You should have received a copy of the GNU General Public License version
  160.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  160.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  160.21 + *
  160.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  160.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  160.24 + * have any questions.
  160.25 + */
  160.26 +
  160.27 +/*
  160.28 + * @test
  160.29 + * @bug 6843077
  160.30 + * @summary check for duplicate annotations
  160.31 + * @author Mahmood Ali
  160.32 + * @compile/fail/ref=DuplicateTypeAnnotation.out -XDrawDiagnostics -source 1.7 DuplicateTypeAnnotation.java
  160.33 + */
  160.34 +
  160.35 +class DuplicateTypeAnno<K> {
  160.36 +  DuplicateTypeAnno<@A @A ?> l;
  160.37 +}
  160.38 +
  160.39 +@interface A { }
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/DuplicateTypeAnnotation.out	Sun Jun 28 00:01:09 2009 -0700
   161.3 @@ -0,0 +1,2 @@
   161.4 +DuplicateTypeAnnotation.java:33:24: compiler.err.duplicate.annotation
   161.5 +1 error
   162.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   162.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/InvalidLocation.java	Sun Jun 28 00:01:09 2009 -0700
   162.3 @@ -0,0 +1,37 @@
   162.4 +/*
   162.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   162.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   162.7 + *
   162.8 + * This code is free software; you can redistribute it and/or modify it
   162.9 + * under the terms of the GNU General Public License version 2 only, as
  162.10 + * published by the Free Software Foundation.
  162.11 + *
  162.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  162.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  162.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  162.15 + * version 2 for more details (a copy is included in the LICENSE file that
  162.16 + * accompanied this code).
  162.17 + *
  162.18 + * You should have received a copy of the GNU General Public License version
  162.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  162.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  162.21 + *
  162.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  162.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  162.24 + * have any questions.
  162.25 + */
  162.26 +
  162.27 +/*
  162.28 + * @test
  162.29 + * @bug 6843077
  162.30 + * @summary check for invalid annotatins given the target
  162.31 + * @author Mahmood Ali
  162.32 + * @compile/fail/ref=InvalidLocation.out -XDrawDiagnostics -source 1.7 InvalidLocation.java
  162.33 + */
  162.34 +
  162.35 +class InvalidLocation<K> {
  162.36 +  InvalidLocation<@A ?> l;
  162.37 +}
  162.38 +
  162.39 +@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
  162.40 +@interface A { }
   163.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/InvalidLocation.out	Sun Jun 28 00:01:09 2009 -0700
   163.3 @@ -0,0 +1,2 @@
   163.4 +InvalidLocation.java:33:19: compiler.err.annotation.type.not.applicable
   163.5 +1 error
   164.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   164.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.java	Sun Jun 28 00:01:09 2009 -0700
   164.3 @@ -0,0 +1,35 @@
   164.4 +/*
   164.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   164.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   164.7 + *
   164.8 + * This code is free software; you can redistribute it and/or modify it
   164.9 + * under the terms of the GNU General Public License version 2 only, as
  164.10 + * published by the Free Software Foundation.
  164.11 + *
  164.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  164.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  164.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  164.15 + * version 2 for more details (a copy is included in the LICENSE file that
  164.16 + * accompanied this code).
  164.17 + *
  164.18 + * You should have received a copy of the GNU General Public License version
  164.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  164.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  164.21 + *
  164.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  164.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  164.24 + * have any questions.
  164.25 + */
  164.26 +
  164.27 +/*
  164.28 + * @test
  164.29 + * @bug 6843077
  164.30 + * @summary check for missing annotation value
  164.31 + * @author Mahmood Ali
  164.32 + * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics -source 1.7 MissingAnnotationValue.java
  164.33 + */
  164.34 +class MissingAnnotationValue<K> {
  164.35 +  MissingAnnotationValue<@A ?> l;
  164.36 +}
  164.37 +
  164.38 +@interface A { int field(); }
   165.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   165.2 +++ b/test/tools/javac/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.out	Sun Jun 28 00:01:09 2009 -0700
   165.3 @@ -0,0 +1,2 @@
   165.4 +MissingAnnotationValue.java:32:26: compiler.err.annotation.missing.default.value: A, field
   165.5 +1 error
   166.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   166.2 +++ b/test/tools/javac/typeAnnotations/failures/target/Constructor.java	Sun Jun 28 00:01:09 2009 -0700
   166.3 @@ -0,0 +1,40 @@
   166.4 +/*
   166.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   166.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   166.7 + *
   166.8 + * This code is free software; you can redistribute it and/or modify it
   166.9 + * under the terms of the GNU General Public License version 2 only, as
  166.10 + * published by the Free Software Foundation.
  166.11 + *
  166.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  166.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  166.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  166.15 + * version 2 for more details (a copy is included in the LICENSE file that
  166.16 + * accompanied this code).
  166.17 + *
  166.18 + * You should have received a copy of the GNU General Public License version
  166.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  166.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  166.21 + *
  166.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  166.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  166.24 + * have any questions.
  166.25 + */
  166.26 +
  166.27 +/*
  166.28 + * @test
  166.29 + * @bug 6843077
  166.30 + * @summary test invalid location of TypeUse
  166.31 + * @author Mahmood Ali
  166.32 + * @compile/fail/ref=Constructor.out -XDrawDiagnostics -source 1.7 Constructor.java
  166.33 + */
  166.34 +
  166.35 +import java.lang.annotation.Target;
  166.36 +import java.lang.annotation.ElementType;
  166.37 +
  166.38 +class Constructor {
  166.39 +  @A Constructor() { }
  166.40 +}
  166.41 +
  166.42 +@Target(ElementType.TYPE_USE)
  166.43 +@interface A { }
   167.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   167.2 +++ b/test/tools/javac/typeAnnotations/failures/target/Constructor.out	Sun Jun 28 00:01:09 2009 -0700
   167.3 @@ -0,0 +1,2 @@
   167.4 +Constructor.java:36:3: compiler.err.annotation.type.not.applicable
   167.5 +1 error
   168.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   168.2 +++ b/test/tools/javac/typeAnnotations/failures/target/IncompleteArray.java	Sun Jun 28 00:01:09 2009 -0700
   168.3 @@ -0,0 +1,35 @@
   168.4 +/*
   168.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   168.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   168.7 + *
   168.8 + * This code is free software; you can redistribute it and/or modify it
   168.9 + * under the terms of the GNU General Public License version 2 only, as
  168.10 + * published by the Free Software Foundation.
  168.11 + *
  168.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  168.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  168.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  168.15 + * version 2 for more details (a copy is included in the LICENSE file that
  168.16 + * accompanied this code).
  168.17 + *
  168.18 + * You should have received a copy of the GNU General Public License version
  168.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  168.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  168.21 + *
  168.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  168.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  168.24 + * have any questions.
  168.25 + */
  168.26 +
  168.27 +/*
  168.28 + * @test
  168.29 + * @bug 6843077
  168.30 + * @summary test incomplete array declaration
  168.31 + * @author Mahmood Ali
  168.32 + * @compile/fail/ref=IncompleteArray.out -XDrawDiagnostics -source 1.7 IncompleteArray.java
  168.33 + */
  168.34 +class IncompleteArray {
  168.35 +  int @A [] @A var;
  168.36 +}
  168.37 +
  168.38 +@interface A { }
   169.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   169.2 +++ b/test/tools/javac/typeAnnotations/failures/target/IncompleteArray.out	Sun Jun 28 00:01:09 2009 -0700
   169.3 @@ -0,0 +1,2 @@
   169.4 +IncompleteArray.java:32:13: compiler.err.illegal.start.of.type
   169.5 +1 error
   170.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   170.2 +++ b/test/tools/javac/typeAnnotations/failures/target/NotTypeParameter.java	Sun Jun 28 00:01:09 2009 -0700
   170.3 @@ -0,0 +1,40 @@
   170.4 +/*
   170.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   170.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   170.7 + *
   170.8 + * This code is free software; you can redistribute it and/or modify it
   170.9 + * under the terms of the GNU General Public License version 2 only, as
  170.10 + * published by the Free Software Foundation.
  170.11 + *
  170.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  170.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  170.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  170.15 + * version 2 for more details (a copy is included in the LICENSE file that
  170.16 + * accompanied this code).
  170.17 + *
  170.18 + * You should have received a copy of the GNU General Public License version
  170.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  170.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  170.21 + *
  170.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  170.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  170.24 + * have any questions.
  170.25 + */
  170.26 +
  170.27 +/*
  170.28 + * @test
  170.29 + * @bug 6843077
  170.30 + * @summary test invalid location of TypeUse
  170.31 + * @author Mahmood Ali
  170.32 + * @compile/fail/ref=NotTypeParameter.out -XDrawDiagnostics -source 1.7 NotTypeParameter.java
  170.33 + */
  170.34 +
  170.35 +import java.lang.annotation.Target;
  170.36 +import java.lang.annotation.ElementType;
  170.37 +
  170.38 +class VoidMethod<@A K> {
  170.39 +  @A void test() { }
  170.40 +}
  170.41 +
  170.42 +@Target(ElementType.TYPE_USE)
  170.43 +@interface A { }
   171.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   171.2 +++ b/test/tools/javac/typeAnnotations/failures/target/NotTypeParameter.out	Sun Jun 28 00:01:09 2009 -0700
   171.3 @@ -0,0 +1,3 @@
   171.4 +NotTypeParameter.java:36:3: compiler.err.annotation.type.not.applicable
   171.5 +NotTypeParameter.java:35:18: compiler.err.annotation.type.not.applicable
   171.6 +2 errors
   172.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   172.2 +++ b/test/tools/javac/typeAnnotations/failures/target/NotTypeUse.java	Sun Jun 28 00:01:09 2009 -0700
   172.3 @@ -0,0 +1,40 @@
   172.4 +/*
   172.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   172.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   172.7 + *
   172.8 + * This code is free software; you can redistribute it and/or modify it
   172.9 + * under the terms of the GNU General Public License version 2 only, as
  172.10 + * published by the Free Software Foundation.
  172.11 + *
  172.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  172.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  172.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  172.15 + * version 2 for more details (a copy is included in the LICENSE file that
  172.16 + * accompanied this code).
  172.17 + *
  172.18 + * You should have received a copy of the GNU General Public License version
  172.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  172.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  172.21 + *
  172.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  172.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  172.24 + * have any questions.
  172.25 + */
  172.26 +
  172.27 +/*
  172.28 + * @test
  172.29 + * @bug 6843077
  172.30 + * @summary test invalid location of TypeUse
  172.31 + * @author Mahmood Ali
  172.32 + * @compile/fail/ref=NotTypeUse.out -XDrawDiagnostics -source 1.7 NotTypeUse.java
  172.33 + */
  172.34 +
  172.35 +import java.lang.annotation.Target;
  172.36 +import java.lang.annotation.ElementType;
  172.37 +
  172.38 +class VoidMethod {
  172.39 +  @A void test() { }
  172.40 +}
  172.41 +
  172.42 +@Target(ElementType.TYPE)
  172.43 +@interface A { }
   173.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   173.2 +++ b/test/tools/javac/typeAnnotations/failures/target/NotTypeUse.out	Sun Jun 28 00:01:09 2009 -0700
   173.3 @@ -0,0 +1,2 @@
   173.4 +NotTypeUse.java:36:3: compiler.err.annotation.type.not.applicable
   173.5 +1 error
   174.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   174.2 +++ b/test/tools/javac/typeAnnotations/failures/target/VoidMethod.java	Sun Jun 28 00:01:09 2009 -0700
   174.3 @@ -0,0 +1,40 @@
   174.4 +/*
   174.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   174.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   174.7 + *
   174.8 + * This code is free software; you can redistribute it and/or modify it
   174.9 + * under the terms of the GNU General Public License version 2 only, as
  174.10 + * published by the Free Software Foundation.
  174.11 + *
  174.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  174.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  174.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  174.15 + * version 2 for more details (a copy is included in the LICENSE file that
  174.16 + * accompanied this code).
  174.17 + *
  174.18 + * You should have received a copy of the GNU General Public License version
  174.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  174.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  174.21 + *
  174.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  174.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  174.24 + * have any questions.
  174.25 + */
  174.26 +
  174.27 +/*
  174.28 + * @test
  174.29 + * @bug 6843077
  174.30 + * @summary test invalid location of TypeUse
  174.31 + * @author Mahmood Ali
  174.32 + * @compile/fail/ref=VoidMethod.out -XDrawDiagnostics -source 1.7 VoidMethod.java
  174.33 + */
  174.34 +
  174.35 +import java.lang.annotation.Target;
  174.36 +import java.lang.annotation.ElementType;
  174.37 +
  174.38 +class VoidMethod {
  174.39 +  @A void test() { }
  174.40 +}
  174.41 +
  174.42 +@Target(ElementType.TYPE_USE)
  174.43 +@interface A { }
   175.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   175.2 +++ b/test/tools/javac/typeAnnotations/failures/target/VoidMethod.out	Sun Jun 28 00:01:09 2009 -0700
   175.3 @@ -0,0 +1,2 @@
   175.4 +VoidMethod.java:36:3: compiler.err.annotation.type.not.applicable
   175.5 +1 error
   176.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   176.2 +++ b/test/tools/javac/typeAnnotations/newlocations/BasicTest.java	Sun Jun 28 00:01:09 2009 -0700
   176.3 @@ -0,0 +1,75 @@
   176.4 +
   176.5 +/*
   176.6 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   176.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   176.8 + *
   176.9 + * This code is free software; you can redistribute it and/or modify it
  176.10 + * under the terms of the GNU General Public License version 2 only, as
  176.11 + * published by the Free Software Foundation.
  176.12 + *
  176.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  176.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  176.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  176.16 + * version 2 for more details (a copy is included in the LICENSE file that
  176.17 + * accompanied this code).
  176.18 + *
  176.19 + * You should have received a copy of the GNU General Public License version
  176.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  176.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  176.22 + *
  176.23 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  176.24 + * CA 95054 USA or visit www.sun.com if you need additional information or
  176.25 + * have any questions.
  176.26 + */
  176.27 +
  176.28 +/*
  176.29 + * @test
  176.30 + * @bug 6843077
  176.31 + * @summary random tests for new locations
  176.32 + * @author Matt Papi
  176.33 + * @compile -source 1.7 BasicTest.java
  176.34 + */
  176.35 +
  176.36 +import java.util.*;
  176.37 +import java.io.*;
  176.38 +
  176.39 +@interface A {}
  176.40 +@interface B {}
  176.41 +@interface C {}
  176.42 +@interface D {}
  176.43 +
  176.44 +/**
  176.45 + * Tests basic JSR 308 parser functionality. We don't really care about what
  176.46 + * the parse tree looks like, just that these annotations can be parsed.
  176.47 + */
  176.48 +class BasicTest<T extends @A Object> extends @B LinkedList<T> implements @C List<T> {
  176.49 +
  176.50 +    void test() {
  176.51 +
  176.52 +        // Handle annotated class literals/cast types
  176.53 +        Class<?> c = @A String.class;
  176.54 +        Object o = (@A Object) "foo";
  176.55 +
  176.56 +        // Handle annotated "new" expressions (except arrays; see ArrayTest)
  176.57 +        String s = new @A String("bar");
  176.58 +
  176.59 +        boolean b = o instanceof @A Object;
  176.60 +
  176.61 +
  176.62 +        @A Map<@B List<@C String>, @D String> map =
  176.63 +            new @A HashMap<@B List<@C String>, @D String>();
  176.64 +
  176.65 +        Class<? extends @A String> c2 = @A String.class;
  176.66 +    }
  176.67 +
  176.68 +    // Handle receiver annotations
  176.69 +    // Handle annotations on a qualified identifier list
  176.70 +    void test2() @C @D throws @A IllegalArgumentException, @B IOException {
  176.71 +
  176.72 +    }
  176.73 +
  176.74 +    // Handle annotations on a varargs element type
  176.75 +    void test3(Object @A... objs) {
  176.76 +
  176.77 +    }
  176.78 +}
   177.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   177.2 +++ b/test/tools/javac/typeAnnotations/newlocations/ClassExtends.java	Sun Jun 28 00:01:09 2009 -0700
   177.3 @@ -0,0 +1,40 @@
   177.4 +/*
   177.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   177.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   177.7 + *
   177.8 + * This code is free software; you can redistribute it and/or modify it
   177.9 + * under the terms of the GNU General Public License version 2 only, as
  177.10 + * published by the Free Software Foundation.
  177.11 + *
  177.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  177.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  177.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  177.15 + * version 2 for more details (a copy is included in the LICENSE file that
  177.16 + * accompanied this code).
  177.17 + *
  177.18 + * You should have received a copy of the GNU General Public License version
  177.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  177.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  177.21 + *
  177.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  177.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  177.24 + * have any questions.
  177.25 + */
  177.26 +
  177.27 +/*
  177.28 + * @test
  177.29 + * @bug 6843077
  177.30 + * @summary new type annotation location: class extends/implements
  177.31 + * @author Mahmood Ali
  177.32 + * @compile -source 1.7 ClassExtends.java
  177.33 + */
  177.34 +abstract class MyClass extends @A ParameterizedClass<@B String>
  177.35 +  implements @B CharSequence, @A ParameterizedInterface<@B String> { }
  177.36 +
  177.37 +interface MyInterface extends @A ParameterizedInterface<@A String>,
  177.38 +                              @B CharSequence { }
  177.39 +
  177.40 +class ParameterizedClass<K> {}
  177.41 +interface ParameterizedInterface<K> {}
  177.42 +@interface A {}
  177.43 +@interface B {}
   178.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.2 +++ b/test/tools/javac/typeAnnotations/newlocations/ClassLiterals.java	Sun Jun 28 00:01:09 2009 -0700
   178.3 @@ -0,0 +1,48 @@
   178.4 +/*
   178.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   178.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   178.7 + *
   178.8 + * This code is free software; you can redistribute it and/or modify it
   178.9 + * under the terms of the GNU General Public License version 2 only, as
  178.10 + * published by the Free Software Foundation.
  178.11 + *
  178.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  178.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  178.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  178.15 + * version 2 for more details (a copy is included in the LICENSE file that
  178.16 + * accompanied this code).
  178.17 + *
  178.18 + * You should have received a copy of the GNU General Public License version
  178.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  178.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  178.21 + *
  178.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  178.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  178.24 + * have any questions.
  178.25 + */
  178.26 +
  178.27 +/*
  178.28 + * @test
  178.29 + * @bug 6843077
  178.30 + * @summary new type annotation location: class literals
  178.31 + * @author Mahmood Ali
  178.32 + * @compile -source 1.7 ClassLiterals.java
  178.33 + */
  178.34 +
  178.35 +class ClassLiterals {
  178.36 +
  178.37 +  public static void main(String[] args) {
  178.38 +    if (String.class != @A String.class) throw new Error();
  178.39 +    if (@A int.class != int.class) throw new Error();
  178.40 +    if (@A int.class != Integer.TYPE) throw new Error();
  178.41 +    if (@A int @B(0) [].class != int[].class) throw new Error();
  178.42 +
  178.43 +    if (String[].class != @A String[].class) throw new Error();
  178.44 +    if (String[].class != String @A [].class) throw new Error();
  178.45 +    if (@A int[].class != int[].class) throw new Error();
  178.46 +    if (@A int @B(0) [].class != int[].class) throw new Error();
  178.47 +  }
  178.48 +}
  178.49 +
  178.50 +@interface A {}
  178.51 +@interface B { int value(); }
   179.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   179.2 +++ b/test/tools/javac/typeAnnotations/newlocations/ClassParameters.java	Sun Jun 28 00:01:09 2009 -0700
   179.3 @@ -0,0 +1,56 @@
   179.4 +/*
   179.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   179.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   179.7 + *
   179.8 + * This code is free software; you can redistribute it and/or modify it
   179.9 + * under the terms of the GNU General Public License version 2 only, as
  179.10 + * published by the Free Software Foundation.
  179.11 + *
  179.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  179.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  179.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  179.15 + * version 2 for more details (a copy is included in the LICENSE file that
  179.16 + * accompanied this code).
  179.17 + *
  179.18 + * You should have received a copy of the GNU General Public License version
  179.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  179.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  179.21 + *
  179.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  179.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  179.24 + * have any questions.
  179.25 + */
  179.26 +
  179.27 +/*
  179.28 + * @test
  179.29 + * @bug 6843077
  179.30 + * @summary new type annotation location: class type parameter bounds
  179.31 + * @author Mahmood Ali
  179.32 + * @compile -source 1.7 ClassParameters.java
  179.33 + */
  179.34 +class Unannotated<K> { }
  179.35 +
  179.36 +class ExtendsBound<K extends @A String> { }
  179.37 +class ExtendsGeneric<K extends @A Unannotated<@B String>> { }
  179.38 +class TwoBounds<K extends @A String, V extends @B String> { }
  179.39 +
  179.40 +class Complex1<K extends @A String&Runnable> { }
  179.41 +class Complex2<K extends String & @B Runnable> { }
  179.42 +class ComplexBoth<K extends @A String & @A Runnable> { }
  179.43 +
  179.44 +class Outer {
  179.45 +  void inner() {
  179.46 +    class Unannotated<K> { }
  179.47 +
  179.48 +    class ExtendsBound<K extends @A String> { }
  179.49 +    class ExtendsGeneric<K extends @A Unannotated<@B String>> { }
  179.50 +    class TwoBounds<K extends @A String, V extends @B String> { }
  179.51 +
  179.52 +    class Complex1<K extends @A String&Runnable> { }
  179.53 +    class Complex2<K extends String & @B Runnable> { }
  179.54 +    class ComplexBoth<K extends @A String & @A Runnable> { }
  179.55 +  }
  179.56 +}
  179.57 +
  179.58 +@interface A { }
  179.59 +@interface B { }
   180.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   180.2 +++ b/test/tools/javac/typeAnnotations/newlocations/ConstructorTypeArgs.java	Sun Jun 28 00:01:09 2009 -0700
   180.3 @@ -0,0 +1,55 @@
   180.4 +/*
   180.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   180.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   180.7 + *
   180.8 + * This code is free software; you can redistribute it and/or modify it
   180.9 + * under the terms of the GNU General Public License version 2 only, as
  180.10 + * published by the Free Software Foundation.
  180.11 + *
  180.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  180.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  180.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  180.15 + * version 2 for more details (a copy is included in the LICENSE file that
  180.16 + * accompanied this code).
  180.17 + *
  180.18 + * You should have received a copy of the GNU General Public License version
  180.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  180.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  180.21 + *
  180.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  180.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  180.24 + * have any questions.
  180.25 + */
  180.26 +
  180.27 +/*
  180.28 + * @test
  180.29 + * @bug 6843077
  180.30 + * @summary new type annotation location: constructor type args
  180.31 + * @author Mahmood Ali
  180.32 + * @compile -source 1.7 ConstructorTypeArgs.java
  180.33 + */
  180.34 +
  180.35 +class ConstructorTypeArgs {
  180.36 +  void oneArg() {
  180.37 +    new @A MyList<@A String>();
  180.38 +    new MyList<@A MyList<@B(0) String>>();
  180.39 +  }
  180.40 +
  180.41 +  void twoArg() {
  180.42 +    new MyMap<String, String>();
  180.43 +    new MyMap<@A String, @B(0) MyList<@A String>>();
  180.44 +  }
  180.45 +
  180.46 +  void withArraysIn() {
  180.47 +    new MyList<String[]>();
  180.48 +    new MyList<@A String @B(0) [] @A []>();
  180.49 +
  180.50 +    new MyMap<@A String[], @B(0) MyList<@A String> @A []>();
  180.51 +  }
  180.52 +}
  180.53 +
  180.54 +class MyList<E> { }
  180.55 +class MyMap<K, V> { }
  180.56 +
  180.57 +@interface A { }
  180.58 +@interface B { int value(); }
   181.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   181.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Expressions.java	Sun Jun 28 00:01:09 2009 -0700
   181.3 @@ -0,0 +1,75 @@
   181.4 +/*
   181.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   181.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   181.7 + *
   181.8 + * This code is free software; you can redistribute it and/or modify it
   181.9 + * under the terms of the GNU General Public License version 2 only, as
  181.10 + * published by the Free Software Foundation.
  181.11 + *
  181.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  181.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  181.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  181.15 + * version 2 for more details (a copy is included in the LICENSE file that
  181.16 + * accompanied this code).
  181.17 + *
  181.18 + * You should have received a copy of the GNU General Public License version
  181.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  181.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  181.21 + *
  181.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  181.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  181.24 + * have any questions.
  181.25 + */
  181.26 +
  181.27 +/*
  181.28 + * @test
  181.29 + * @bug 6843077
  181.30 + * @summary new type annotation location: expressions
  181.31 + * @author Mahmood Ali
  181.32 + * @compile -source 1.7 Expressions.java
  181.33 + */
  181.34 +class Expressions {
  181.35 +  void instanceOf() {
  181.36 +    Object o = null;
  181.37 +    boolean a = o instanceof @A String;
  181.38 +    boolean b = o instanceof @B(0) String;
  181.39 +  }
  181.40 +
  181.41 +  void instanceOfArray() {
  181.42 +    Object o = null;
  181.43 +    boolean a1 = o instanceof @A String [];
  181.44 +    boolean a2 = o instanceof @B(0) String [];
  181.45 +
  181.46 +    boolean b1 = o instanceof String @A [];
  181.47 +    boolean b2 = o instanceof String @B(0) [];
  181.48 +  }
  181.49 +
  181.50 +  void objectCreation() {
  181.51 +    new @A String();
  181.52 +    new @B(0) String();
  181.53 +  }
  181.54 +
  181.55 +  void objectCreationArray() {
  181.56 +    Object a1 = new @A String [] [] { };
  181.57 +    Object a2 = new @A String [1] [];
  181.58 +    Object a3 = new @A String [1] [2];
  181.59 +
  181.60 +    Object b1 = new @A String @B(0) [] [] { };
  181.61 +    Object b2 = new @A String @B(0) [1] [];
  181.62 +    Object b3 = new @A String @B(0) [1] [2];
  181.63 +
  181.64 +    Object c1 = new @A String []  @B(0) [] { };
  181.65 +    Object c2 = new @A String [1] @B(0) [];
  181.66 +    Object c3 = new @A String [1] @B(0) [2];
  181.67 +
  181.68 +    Object d1 = new @A String @B(0) []  @B(0) [] { };
  181.69 +    Object d2 = new @A String @B(0) [1] @B(0) [];
  181.70 +    Object d3 = new @A String @B(0) [1] @B(0) [2];
  181.71 +
  181.72 +    Object rand = new @A String @B(value = 0) [1] @B(value = 0) [2];
  181.73 +
  181.74 +  }
  181.75 +}
  181.76 +
  181.77 +@interface A { }
  181.78 +@interface B { int value(); }
   182.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   182.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Fields.java	Sun Jun 28 00:01:09 2009 -0700
   182.3 @@ -0,0 +1,69 @@
   182.4 +/*
   182.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   182.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   182.7 + *
   182.8 + * This code is free software; you can redistribute it and/or modify it
   182.9 + * under the terms of the GNU General Public License version 2 only, as
  182.10 + * published by the Free Software Foundation.
  182.11 + *
  182.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  182.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  182.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  182.15 + * version 2 for more details (a copy is included in the LICENSE file that
  182.16 + * accompanied this code).
  182.17 + *
  182.18 + * You should have received a copy of the GNU General Public License version
  182.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  182.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  182.21 + *
  182.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  182.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  182.24 + * have any questions.
  182.25 + */
  182.26 +
  182.27 +/*
  182.28 + * @test
  182.29 + * @bug 6843077
  182.30 + * @summary new type annotation location: field type array/generics
  182.31 + * @author Mahmood Ali
  182.32 + * @compile -source 1.7 Fields.java
  182.33 + */
  182.34 +
  182.35 +class DefaultScope {
  182.36 +  Parameterized<String, String> unannotated;
  182.37 +  Parameterized<@A String, String> firstTypeArg;
  182.38 +  Parameterized<String, @A String> secondTypeArg;
  182.39 +  Parameterized<@A String, @B String> bothTypeArgs;
  182.40 +
  182.41 +  Parameterized<@A Parameterized<@A String, @B String>, @B String>
  182.42 +    nestedParameterized;
  182.43 +
  182.44 +  @A String [] array1;
  182.45 +  @A String @B [] array1Deep;
  182.46 +  @A String [] [] array2;
  182.47 +  @A String @A [] @B [] array2Deep;
  182.48 +  String @A [] [] array2First;
  182.49 +  String [] @B [] array2Second;
  182.50 +}
  182.51 +
  182.52 +class ModifiedScoped {
  182.53 +  public final Parameterized<String, String> unannotated = null;
  182.54 +  public final Parameterized<@A String, String> firstTypeArg = null;
  182.55 +  public final Parameterized<String, @A String> secondTypeArg = null;
  182.56 +  public final Parameterized<@A String, @B String> bothTypeArgs = null;
  182.57 +
  182.58 +  public final Parameterized<@A Parameterized<@A String, @B String>, @B String>
  182.59 +    nestedParameterized = null;
  182.60 +
  182.61 +  public final @A String [] array1 = null;
  182.62 +  public final @A String @B [] array1Deep = null;
  182.63 +  public final @A String [] [] array2 = null;
  182.64 +  public final @A String @A [] @B [] array2Deep = null;
  182.65 +  public final String @A [] [] array2First = null;
  182.66 +  public final String [] @B [] array2Second = null;
  182.67 +}
  182.68 +
  182.69 +class Parameterized<K, V> { }
  182.70 +
  182.71 +@interface A { }
  182.72 +@interface B { }
   183.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   183.2 +++ b/test/tools/javac/typeAnnotations/newlocations/LocalVariables.java	Sun Jun 28 00:01:09 2009 -0700
   183.3 @@ -0,0 +1,77 @@
   183.4 +/*
   183.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   183.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   183.7 + *
   183.8 + * This code is free software; you can redistribute it and/or modify it
   183.9 + * under the terms of the GNU General Public License version 2 only, as
  183.10 + * published by the Free Software Foundation.
  183.11 + *
  183.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  183.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  183.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  183.15 + * version 2 for more details (a copy is included in the LICENSE file that
  183.16 + * accompanied this code).
  183.17 + *
  183.18 + * You should have received a copy of the GNU General Public License version
  183.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  183.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  183.21 + *
  183.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  183.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  183.24 + * have any questions.
  183.25 + */
  183.26 +
  183.27 +/*
  183.28 + * @test
  183.29 + * @bug 6843077
  183.30 + * @summary new type annotation location: local variables array/generics
  183.31 + * @author Mahmood Ali
  183.32 + * @compile -source 1.7 LocalVariables.java
  183.33 + */
  183.34 +
  183.35 +class DefaultScope {
  183.36 +  void parameterized() {
  183.37 +    Parameterized<String, String> unannotated;
  183.38 +    Parameterized<@A String, String> firstTypeArg;
  183.39 +    Parameterized<String, @A String> secondTypeArg;
  183.40 +    Parameterized<@A String, @B String> bothTypeArgs;
  183.41 +
  183.42 +    Parameterized<@A Parameterized<@A String, @B String>, @B String>
  183.43 +      nestedParameterized;
  183.44 +  }
  183.45 +
  183.46 +  void arrays() {
  183.47 +    @A String [] array1;
  183.48 +    @A String @B [] array1Deep;
  183.49 +    @A String [] [] array2;
  183.50 +    @A String @A [] @B [] array2Deep;
  183.51 +    String @A [] [] array2First;
  183.52 +    String [] @B [] array2Second;
  183.53 +  }
  183.54 +}
  183.55 +
  183.56 +class ModifiedVars {
  183.57 +  void parameterized() {
  183.58 +    final Parameterized<String, String> unannotated = null;
  183.59 +    final Parameterized<@A String, String> firstTypeArg = null;
  183.60 +    final Parameterized<String, @A String> secondTypeArg = null;
  183.61 +    final Parameterized<@A String, @B String> bothTypeArgs = null;
  183.62 +
  183.63 +    final Parameterized<@A Parameterized<@A String, @B String>, @B String>
  183.64 +      nestedParameterized = null;
  183.65 +  }
  183.66 +
  183.67 +  void arrays() {
  183.68 +    final @A String [] array1 = null;
  183.69 +    final @A String @B [] array1Deep = null;
  183.70 +    final @A String [] [] array2 = null;
  183.71 +    final @A String @A [] @B [] array2Deep = null;
  183.72 +    final String @A [] [] array2First = null;
  183.73 +    final String [] @B [] array2Second = null;
  183.74 +  }
  183.75 +}
  183.76 +
  183.77 +class Parameterized<K, V> { }
  183.78 +
  183.79 +@interface A { }
  183.80 +@interface B { }
   184.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   184.2 +++ b/test/tools/javac/typeAnnotations/newlocations/MethodReturnType.java	Sun Jun 28 00:01:09 2009 -0700
   184.3 @@ -0,0 +1,71 @@
   184.4 +/*
   184.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   184.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   184.7 + *
   184.8 + * This code is free software; you can redistribute it and/or modify it
   184.9 + * under the terms of the GNU General Public License version 2 only, as
  184.10 + * published by the Free Software Foundation.
  184.11 + *
  184.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  184.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  184.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  184.15 + * version 2 for more details (a copy is included in the LICENSE file that
  184.16 + * accompanied this code).
  184.17 + *
  184.18 + * You should have received a copy of the GNU General Public License version
  184.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  184.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  184.21 + *
  184.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  184.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  184.24 + * have any questions.
  184.25 + */
  184.26 +
  184.27 +/*
  184.28 + * @test
  184.29 + * @bug 6843077
  184.30 + * @summary new type annotation location: method return type array/generics
  184.31 + * @author Mahmood Ali
  184.32 + * @compile -source 1.7 MethodReturnType.java
  184.33 + */
  184.34 +
  184.35 +class DefaultScope {
  184.36 +  Parameterized<String, String> unannotated() { return null; }
  184.37 +  Parameterized<@A String, String> firstTypeArg() { return null; }
  184.38 +  Parameterized<String, @A String> secondTypeArg() { return null; }
  184.39 +  Parameterized<@A String, @B String> bothTypeArgs() { return null; }
  184.40 +
  184.41 +  Parameterized<@A Parameterized<@A String, @B String>, @B String>
  184.42 +    nestedParameterized() { return null; }
  184.43 +
  184.44 +  public <T> @A String method() { return null; }
  184.45 +
  184.46 +  @A String [] array1() { return null; }
  184.47 +  @A String @B [] array1Deep() { return null; }
  184.48 +  @A String [] [] array2() { return null; }
  184.49 +  @A String @A [] @B [] array2Deep() { return null; }
  184.50 +  String @A [] [] array2First() { return null; }
  184.51 +  String [] @B [] array2Second() { return null; }
  184.52 +}
  184.53 +
  184.54 +class ModifiedScoped {
  184.55 +  public final Parameterized<String, String> unannotated() { return null; }
  184.56 +  public final Parameterized<@A String, String> firstTypeArg() { return null; }
  184.57 +  public final Parameterized<String, @A String> secondTypeArg() { return null; }
  184.58 +  public final Parameterized<@A String, @B String> bothTypeArgs() { return null; }
  184.59 +
  184.60 +  public final Parameterized<@A Parameterized<@A String, @B String>, @B String>
  184.61 +    nestedParameterized() { return null; }
  184.62 +
  184.63 +  public final @A String [] array1() { return null; }
  184.64 +  public final @A String @B [] array1Deep() { return null; }
  184.65 +  public final @A String [] [] array2() { return null; }
  184.66 +  public final @A String @A [] @B [] array2Deep() { return null; }
  184.67 +  public final String @A [] [] array2First() { return null; }
  184.68 +  public final String [] @B [] array2Second() { return null; }
  184.69 +}
  184.70 +
  184.71 +class Parameterized<K, V> { }
  184.72 +
  184.73 +@interface A { }
  184.74 +@interface B { }
   185.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   185.2 +++ b/test/tools/javac/typeAnnotations/newlocations/MethodTypeArgs.java	Sun Jun 28 00:01:09 2009 -0700
   185.3 @@ -0,0 +1,62 @@
   185.4 +/*
   185.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   185.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   185.7 + *
   185.8 + * This code is free software; you can redistribute it and/or modify it
   185.9 + * under the terms of the GNU General Public License version 2 only, as
  185.10 + * published by the Free Software Foundation.
  185.11 + *
  185.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  185.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  185.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  185.15 + * version 2 for more details (a copy is included in the LICENSE file that
  185.16 + * accompanied this code).
  185.17 + *
  185.18 + * You should have received a copy of the GNU General Public License version
  185.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  185.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  185.21 + *
  185.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  185.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  185.24 + * have any questions.
  185.25 + */
  185.26 +
  185.27 +/*
  185.28 + * @test
  185.29 + * @bug 6843077
  185.30 + * @summary new type annotation location: method type args
  185.31 + * @author Mahmood Ali
  185.32 + * @compile -source 1.7 MethodTypeArgs.java
  185.33 + */
  185.34 +
  185.35 +class MethodTypeArgs {
  185.36 +  void oneArg() {
  185.37 +    this.<@A String>newList();
  185.38 +    this.<@A MyList<@B(0) String>>newList();
  185.39 +
  185.40 +    MethodTypeArgs.<@A String>newList();
  185.41 +    MethodTypeArgs.<@A MyList<@B(0) String>>newList();
  185.42 +  }
  185.43 +
  185.44 +  void twoArg() {
  185.45 +    this.<String, String>newMap();
  185.46 +    this.<@A String, @B(0) MyList<@A String>>newMap();
  185.47 +
  185.48 +    MethodTypeArgs.<String, String>newMap();
  185.49 +    MethodTypeArgs.<@A String, @B(0) MyList<@A String>>newMap();
  185.50 +  }
  185.51 +
  185.52 +  void withArraysIn() {
  185.53 +    this.<String[]>newList();
  185.54 +    this.<@A String @B(0) [] @A []>newList();
  185.55 +
  185.56 +    this.<@A String[], @B(0) MyList<@A String> @A []>newMap();
  185.57 +  }
  185.58 +
  185.59 +  static <E> void newList() { }
  185.60 +  static <K, V> void newMap() { }
  185.61 +}
  185.62 +
  185.63 +class MyList<E> { }
  185.64 +@interface A { }
  185.65 +@interface B { int value(); }
   186.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   186.2 +++ b/test/tools/javac/typeAnnotations/newlocations/MethodTypeParameters.java	Sun Jun 28 00:01:09 2009 -0700
   186.3 @@ -0,0 +1,48 @@
   186.4 +/*
   186.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   186.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   186.7 + *
   186.8 + * This code is free software; you can redistribute it and/or modify it
   186.9 + * under the terms of the GNU General Public License version 2 only, as
  186.10 + * published by the Free Software Foundation.
  186.11 + *
  186.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  186.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  186.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  186.15 + * version 2 for more details (a copy is included in the LICENSE file that
  186.16 + * accompanied this code).
  186.17 + *
  186.18 + * You should have received a copy of the GNU General Public License version
  186.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  186.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  186.21 + *
  186.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  186.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  186.24 + * have any questions.
  186.25 + */
  186.26 +
  186.27 +/*
  186.28 + * @test
  186.29 + * @bug 6843077
  186.30 + * @summary new type annotation location: method type parameter bounds
  186.31 + * @author Mahmood Ali
  186.32 + * @compile -source 1.7 MethodTypeParameters.java
  186.33 + */
  186.34 +
  186.35 +class UnscopedUnmodified {
  186.36 +  <K extends @A String> void methodExtends() {}
  186.37 +  <K extends @A Parameterized<@B String>> void nestedExtends() {}
  186.38 +  <K extends @A String, V extends @A Parameterized<@B String>> void dual() {}
  186.39 +  <K extends String, V extends Parameterized<@B String>> void dualOneAnno() {}
  186.40 +}
  186.41 +
  186.42 +class PublicModifiedMethods {
  186.43 +  public final <K extends @A String> void methodExtends() {}
  186.44 +  public final <K extends @A Parameterized<@B String>> void nestedExtends() {}
  186.45 +  public final <K extends @A String, V extends @A Parameterized<@B String>> void dual() {}
  186.46 +  public final <K extends String, V extends Parameterized<@B String>> void dualOneAnno() {}
  186.47 +}
  186.48 +
  186.49 +class Parameterized<K> { }
  186.50 +@interface A { }
  186.51 +@interface B { }
   187.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   187.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Parameters.java	Sun Jun 28 00:01:09 2009 -0700
   187.3 @@ -0,0 +1,51 @@
   187.4 +/*
   187.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   187.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   187.7 + *
   187.8 + * This code is free software; you can redistribute it and/or modify it
   187.9 + * under the terms of the GNU General Public License version 2 only, as
  187.10 + * published by the Free Software Foundation.
  187.11 + *
  187.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  187.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  187.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  187.15 + * version 2 for more details (a copy is included in the LICENSE file that
  187.16 + * accompanied this code).
  187.17 + *
  187.18 + * You should have received a copy of the GNU General Public License version
  187.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  187.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  187.21 + *
  187.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  187.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  187.24 + * have any questions.
  187.25 + */
  187.26 +
  187.27 +/*
  187.28 + * @test
  187.29 + * @bug 6843077
  187.30 + * @summary new type annotation location: parameter type array/generics
  187.31 + * @author Mahmood Ali
  187.32 + * @compile -source 1.7 Parameters.java
  187.33 + */
  187.34 +
  187.35 +class Parameters {
  187.36 +  void unannotated(Parameterized<String, String> a) {}
  187.37 +  void firstTypeArg(Parameterized<@A String, String> a) {}
  187.38 +  void secondTypeArg(Parameterized<String, @A String> a) {}
  187.39 +  void bothTypeArgs(Parameterized<@A String, @B String> both) {}
  187.40 +
  187.41 +  void nestedParameterized(Parameterized<@A Parameterized<@A String, @B String>, @B String> a) {}
  187.42 +
  187.43 +  void array1(@A String [] a) {}
  187.44 +  void array1Deep(@A String @B [] a) {}
  187.45 +  void array2(@A String [] [] a) {}
  187.46 +  void array2Deep(@A String @A [] @B [] a) {}
  187.47 +  void array2First(String @A [] [] a) {}
  187.48 +  void array2Second(String [] @B [] a) {}
  187.49 +}
  187.50 +
  187.51 +class Parameterized<K, V> { }
  187.52 +
  187.53 +@interface A { }
  187.54 +@interface B { }
   188.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   188.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Receivers.java	Sun Jun 28 00:01:09 2009 -0700
   188.3 @@ -0,0 +1,56 @@
   188.4 +/*
   188.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   188.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   188.7 + *
   188.8 + * This code is free software; you can redistribute it and/or modify it
   188.9 + * under the terms of the GNU General Public License version 2 only, as
  188.10 + * published by the Free Software Foundation.
  188.11 + *
  188.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  188.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  188.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  188.15 + * version 2 for more details (a copy is included in the LICENSE file that
  188.16 + * accompanied this code).
  188.17 + *
  188.18 + * You should have received a copy of the GNU General Public License version
  188.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  188.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  188.21 + *
  188.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  188.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  188.24 + * have any questions.
  188.25 + */
  188.26 +
  188.27 +/*
  188.28 + * @test
  188.29 + * @bug 6843077
  188.30 + * @summary new type annotation location: receivers
  188.31 + * @author Mahmood Ali
  188.32 + * @compile -source 1.7 Receivers.java
  188.33 + */
  188.34 +class DefaultUnmodified {
  188.35 +  void plain() @A { }
  188.36 +  <T> void generic() @A { }
  188.37 +  void withException() @A throws Exception { }
  188.38 +  String nonVoid() @A { return null; }
  188.39 +  <T extends Runnable> void accept(T r) @A throws Exception { }
  188.40 +}
  188.41 +
  188.42 +class PublicModified {
  188.43 +  public final void plain() @A { }
  188.44 +  public final <T> void generic() @A { }
  188.45 +  public final void withException() @A throws Exception { }
  188.46 +  public final String nonVoid() @A { return null; }
  188.47 +  public final <T extends Runnable> void accept(T r) @A throws Exception { }
  188.48 +}
  188.49 +
  188.50 +class WithValue {
  188.51 +  void plain() @B("m") { }
  188.52 +  <T> void generic() @B("m") { }
  188.53 +  void withException() @B("m") throws Exception { }
  188.54 +  String nonVoid() @B("m") { return null; }
  188.55 +  <T extends Runnable> void accept(T r) @B("m") throws Exception { }
  188.56 +}
  188.57 +
  188.58 +@interface A {}
  188.59 +@interface B { String value(); }
   189.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   189.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Throws.java	Sun Jun 28 00:01:09 2009 -0700
   189.3 @@ -0,0 +1,47 @@
   189.4 +/*
   189.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   189.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   189.7 + *
   189.8 + * This code is free software; you can redistribute it and/or modify it
   189.9 + * under the terms of the GNU General Public License version 2 only, as
  189.10 + * published by the Free Software Foundation.
  189.11 + *
  189.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  189.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  189.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  189.15 + * version 2 for more details (a copy is included in the LICENSE file that
  189.16 + * accompanied this code).
  189.17 + *
  189.18 + * You should have received a copy of the GNU General Public License version
  189.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  189.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  189.21 + *
  189.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  189.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  189.24 + * have any questions.
  189.25 + */
  189.26 +
  189.27 +/*
  189.28 + * @test
  189.29 + * @bug 6843077
  189.30 + * @summary new type annotation location: throw clauses
  189.31 + * @author Mahmood Ali
  189.32 + * @compile -source 1.7 Throws.java
  189.33 + */
  189.34 +class DefaultUnmodified {
  189.35 +  void oneException() throws @A Exception {}
  189.36 +  void twoExceptions() throws @A RuntimeException, @A Exception {}
  189.37 +}
  189.38 +
  189.39 +class PublicModified {
  189.40 +  public final void oneException(String a) throws @A Exception {}
  189.41 +  public final void twoExceptions(String a) throws @A RuntimeException, @A Exception {}
  189.42 +}
  189.43 +
  189.44 +class WithValue {
  189.45 +  void oneException() throws @B("m") Exception {}
  189.46 +  void twoExceptions() throws @B(value="m") RuntimeException, @A Exception {}
  189.47 +}
  189.48 +
  189.49 +@interface A {}
  189.50 +@interface B { String value(); }
   190.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   190.2 +++ b/test/tools/javac/typeAnnotations/newlocations/TypeCasts.java	Sun Jun 28 00:01:09 2009 -0700
   190.3 @@ -0,0 +1,44 @@
   190.4 +/*
   190.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   190.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   190.7 + *
   190.8 + * This code is free software; you can redistribute it and/or modify it
   190.9 + * under the terms of the GNU General Public License version 2 only, as
  190.10 + * published by the Free Software Foundation.
  190.11 + *
  190.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  190.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  190.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  190.15 + * version 2 for more details (a copy is included in the LICENSE file that
  190.16 + * accompanied this code).
  190.17 + *
  190.18 + * You should have received a copy of the GNU General Public License version
  190.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  190.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  190.21 + *
  190.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  190.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  190.24 + * have any questions.
  190.25 + */
  190.26 +
  190.27 +/*
  190.28 + * @test
  190.29 + * @bug 6843077
  190.30 + * @summary new type annotation location: type casts
  190.31 + * @author Mahmood Ali
  190.32 + * @compile -source 1.7 TypeCasts.java
  190.33 + */
  190.34 +class TypeCasts {
  190.35 +  void methodA() {
  190.36 +    String s = (@A String) null;
  190.37 +    Object o = (@A Class<@A String>) null;
  190.38 +  }
  190.39 +
  190.40 +  void methodB() {
  190.41 +    String s = (@B("m") String) null;
  190.42 +    Object o = (@B("m") Class<@B("m") String>) null;
  190.43 +  }
  190.44 +}
  190.45 +
  190.46 +@interface A { }
  190.47 +@interface B { String value(); }
   191.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   191.2 +++ b/test/tools/javac/typeAnnotations/newlocations/TypeParameters.java	Sun Jun 28 00:01:09 2009 -0700
   191.3 @@ -0,0 +1,50 @@
   191.4 +/*
   191.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   191.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   191.7 + *
   191.8 + * This code is free software; you can redistribute it and/or modify it
   191.9 + * under the terms of the GNU General Public License version 2 only, as
  191.10 + * published by the Free Software Foundation.
  191.11 + *
  191.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  191.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  191.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  191.15 + * version 2 for more details (a copy is included in the LICENSE file that
  191.16 + * accompanied this code).
  191.17 + *
  191.18 + * You should have received a copy of the GNU General Public License version
  191.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  191.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  191.21 + *
  191.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  191.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  191.24 + * have any questions.
  191.25 + */
  191.26 +
  191.27 +/*
  191.28 + * @test
  191.29 + * @bug 6843077
  191.30 + * @summary new type annotation location: class and method type parameters
  191.31 + * @author Mahmood Ali
  191.32 + * @compile -source 1.7 TypeParameters.java
  191.33 + */
  191.34 +
  191.35 +class Unannotated<K> { }
  191.36 +class OneAnnotated<@A K> { }
  191.37 +class TwoAnnotated<@A K, @A V> { }
  191.38 +class SecondAnnotated<K, @A V extends String> { }
  191.39 +
  191.40 +class TestMethods {
  191.41 +  <K> void unannotated() { }
  191.42 +  <@A K> void oneAnnotated() { }
  191.43 +  <@A K, @B("m") V> void twoAnnotated() { }
  191.44 +  <K, @A V extends @A String> void secondAnnotated() { }
  191.45 +}
  191.46 +
  191.47 +class UnannotatedB<K> { }
  191.48 +class OneAnnotatedB<@B("m") K> { }
  191.49 +class TwoAnnotatedB<@B("m") K, @B("m") V> { }
  191.50 +class SecondAnnotatedB<K, @B("m") V extends @B("m") String> { }
  191.51 +
  191.52 +@interface A { }
  191.53 +@interface B { String value(); }
   192.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   192.2 +++ b/test/tools/javac/typeAnnotations/newlocations/Wildcards.java	Sun Jun 28 00:01:09 2009 -0700
   192.3 @@ -0,0 +1,70 @@
   192.4 +/*
   192.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   192.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   192.7 + *
   192.8 + * This code is free software; you can redistribute it and/or modify it
   192.9 + * under the terms of the GNU General Public License version 2 only, as
  192.10 + * published by the Free Software Foundation.
  192.11 + *
  192.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  192.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  192.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  192.15 + * version 2 for more details (a copy is included in the LICENSE file that
  192.16 + * accompanied this code).
  192.17 + *
  192.18 + * You should have received a copy of the GNU General Public License version
  192.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  192.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  192.21 + *
  192.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  192.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  192.24 + * have any questions.
  192.25 + */
  192.26 +
  192.27 +/*
  192.28 + * @test
  192.29 + * @bug 6843077
  192.30 + * @summary new type annotation location: wildcard bound
  192.31 + * @author Mahmood Ali
  192.32 + * @compile -source 1.7 Wildcards.java
  192.33 + */
  192.34 +class BoundTest {
  192.35 +  void wcExtends(MyList<? extends @A String> l) { }
  192.36 +  void wcSuper(MyList<? super @A String> l) { }
  192.37 +
  192.38 +  MyList<? extends @A String> returnWcExtends() { return null; }
  192.39 +  MyList<? super @A String> returnWcSuper() { return null; }
  192.40 +  MyList<? extends @A MyList<? super @B("m") String>> complex() { return null; }
  192.41 +}
  192.42 +
  192.43 +class BoundWithValue {
  192.44 +  void wcExtends(MyList<? extends @B("m") String> l) { }
  192.45 +  void wcSuper(MyList<? super @B(value="m") String> l) { }
  192.46 +
  192.47 +  MyList<? extends @B("m") String> returnWcExtends() { return null; }
  192.48 +  MyList<? super @B(value="m") String> returnWcSuper() { return null; }
  192.49 +  MyList<? extends @B("m") MyList<? super @B("m") String>> complex() { return null; }
  192.50 +}
  192.51 +
  192.52 +class SelfTest {
  192.53 +  void wcExtends(MyList<@A ?> l) { }
  192.54 +  void wcSuper(MyList<@A ?> l) { }
  192.55 +
  192.56 +  MyList<@A ?> returnWcExtends() { return null; }
  192.57 +  MyList<@A ?> returnWcSuper() { return null; }
  192.58 +  MyList<@A ? extends @A MyList<@B("m") ?>> complex() { return null; }
  192.59 +}
  192.60 +
  192.61 +class SelfWithValue {
  192.62 +  void wcExtends(MyList<@B("m") ?> l) { }
  192.63 +  void wcSuper(MyList<@B(value="m") ?> l) { }
  192.64 +
  192.65 +  MyList<@B("m") ?> returnWcExtends() { return null; }
  192.66 +  MyList<@B(value="m") ?> returnWcSuper() { return null; }
  192.67 +  MyList<@B("m") ? extends MyList<@B("m") ? super String>> complex() { return null; }
  192.68 +}
  192.69 +
  192.70 +class MyList<K> { }
  192.71 +
  192.72 +@interface A { }
  192.73 +@interface B { String value(); }
   193.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   193.2 +++ b/test/tools/javap/typeAnnotations/ClassLiterals.java	Sun Jun 28 00:01:09 2009 -0700
   193.3 @@ -0,0 +1,174 @@
   193.4 +/*
   193.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   193.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   193.7 + *
   193.8 + * This code is free software; you can redistribute it and/or modify it
   193.9 + * under the terms of the GNU General Public License version 2 only, as
  193.10 + * published by the Free Software Foundation.
  193.11 + *
  193.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  193.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  193.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  193.15 + * version 2 for more details (a copy is included in the LICENSE file that
  193.16 + * accompanied this code).
  193.17 + *
  193.18 + * You should have received a copy of the GNU General Public License version
  193.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  193.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  193.21 + *
  193.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  193.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  193.24 + * have any questions.
  193.25 + */
  193.26 +
  193.27 +import java.io.*;
  193.28 +import com.sun.tools.classfile.*;
  193.29 +
  193.30 +/*
  193.31 + * @test ClassLiterals
  193.32 + * @bug 6843077
  193.33 + * @summary test that all type annotations are present in the classfile
  193.34 + */
  193.35 +
  193.36 +public class ClassLiterals {
  193.37 +    public static void main(String[] args) throws Exception {
  193.38 +        new ClassLiterals().run();
  193.39 +    }
  193.40 +
  193.41 +    public void run() throws Exception {
  193.42 +        File javaFile = writeTestFile();
  193.43 +        File classFile = compileTestFile(javaFile);
  193.44 +
  193.45 +        ClassFile cf = ClassFile.read(classFile);
  193.46 +        test(cf);
  193.47 +        for (Field f : cf.fields) {
  193.48 +            test(cf, f);
  193.49 +        }
  193.50 +        for (Method m: cf.methods) {
  193.51 +            test(cf, m);
  193.52 +        }
  193.53 +
  193.54 +        countAnnotations();
  193.55 +
  193.56 +        if (errors > 0)
  193.57 +            throw new Exception(errors + " errors found");
  193.58 +        System.out.println("PASSED");
  193.59 +    }
  193.60 +
  193.61 +    void test(ClassFile cf) {
  193.62 +        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  193.63 +        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  193.64 +    }
  193.65 +
  193.66 +    void test(ClassFile cf, Method m) {
  193.67 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  193.68 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  193.69 +    }
  193.70 +
  193.71 +    void test(ClassFile cf, Field m) {
  193.72 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  193.73 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  193.74 +    }
  193.75 +
  193.76 +    // test the result of Attributes.getIndex according to expectations
  193.77 +    // encoded in the method's name
  193.78 +    void test(ClassFile cf, String name, boolean visible) {
  193.79 +        int index = cf.attributes.getIndex(cf.constant_pool, name);
  193.80 +        if (index != -1) {
  193.81 +            Attribute attr = cf.attributes.get(index);
  193.82 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  193.83 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  193.84 +            all += tAttr.annotations.length;
  193.85 +            if (visible)
  193.86 +                visibles += tAttr.annotations.length;
  193.87 +            else
  193.88 +                invisibles += tAttr.annotations.length;
  193.89 +        }
  193.90 +    }
  193.91 +
  193.92 +    // test the result of Attributes.getIndex according to expectations
  193.93 +    // encoded in the method's name
  193.94 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  193.95 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  193.96 +        if (index != -1) {
  193.97 +            Attribute attr = m.attributes.get(index);
  193.98 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  193.99 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 193.100 +            all += tAttr.annotations.length;
 193.101 +            if (visible)
 193.102 +                visibles += tAttr.annotations.length;
 193.103 +            else
 193.104 +                invisibles += tAttr.annotations.length;
 193.105 +        }
 193.106 +    }
 193.107 +
 193.108 +    // test the result of Attributes.getIndex according to expectations
 193.109 +    // encoded in the method's name
 193.110 +    void test(ClassFile cf, Field m, String name, boolean visible) {
 193.111 +        int index = m.attributes.getIndex(cf.constant_pool, name);
 193.112 +        if (index != -1) {
 193.113 +            Attribute attr = m.attributes.get(index);
 193.114 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
 193.115 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 193.116 +            all += tAttr.annotations.length;
 193.117 +            if (visible)
 193.118 +                visibles += tAttr.annotations.length;
 193.119 +            else
 193.120 +                invisibles += tAttr.annotations.length;
 193.121 +        }
 193.122 +    }
 193.123 +
 193.124 +    File writeTestFile() throws IOException {
 193.125 +      File f = new File("Testa.java");
 193.126 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 193.127 +        out.println("import java.util.*;");
 193.128 +        out.println("class Testa { ");
 193.129 +        out.println("  @interface A { }");
 193.130 +
 193.131 +        out.println(" void test() {");
 193.132 +        out.println("  Object a = @A String.class;");
 193.133 +        out.println("  Object b = @A String @A [] @A [].class;");
 193.134 +        out.println(" }");
 193.135 +        out.println("}");
 193.136 +
 193.137 +        out.close();
 193.138 +        return f;
 193.139 +    }
 193.140 +
 193.141 +    File compileTestFile(File f) {
 193.142 +      int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 193.143 +        if (rc != 0)
 193.144 +            throw new Error("compilation failed. rc=" + rc);
 193.145 +        String path = f.getPath();
 193.146 +        return new File(path.substring(0, path.length() - 5) + ".class");
 193.147 +    }
 193.148 +
 193.149 +    void countAnnotations() {
 193.150 +        int expected_visibles = 0, expected_invisibles = 4;
 193.151 +        int expected_all = expected_visibles + expected_invisibles;
 193.152 +
 193.153 +        if (expected_all != all) {
 193.154 +            errors++;
 193.155 +            System.err.println("expected " + expected_all
 193.156 +                    + " annotations but found " + all);
 193.157 +        }
 193.158 +
 193.159 +        if (expected_visibles != visibles) {
 193.160 +            errors++;
 193.161 +            System.err.println("expected " + expected_visibles
 193.162 +                    + " visibles annotations but found " + visibles);
 193.163 +        }
 193.164 +
 193.165 +        if (expected_invisibles != invisibles) {
 193.166 +            errors++;
 193.167 +            System.err.println("expected " + expected_invisibles
 193.168 +                    + " invisibles annotations but found " + invisibles);
 193.169 +        }
 193.170 +
 193.171 +    }
 193.172 +
 193.173 +    int errors;
 193.174 +    int all;
 193.175 +    int visibles;
 193.176 +    int invisibles;
 193.177 +}
   194.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   194.2 +++ b/test/tools/javap/typeAnnotations/JSR175Annotations.java	Sun Jun 28 00:01:09 2009 -0700
   194.3 @@ -0,0 +1,152 @@
   194.4 +/*
   194.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   194.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   194.7 + *
   194.8 + * This code is free software; you can redistribute it and/or modify it
   194.9 + * under the terms of the GNU General Public License version 2 only, as
  194.10 + * published by the Free Software Foundation.
  194.11 + *
  194.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  194.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  194.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  194.15 + * version 2 for more details (a copy is included in the LICENSE file that
  194.16 + * accompanied this code).
  194.17 + *
  194.18 + * You should have received a copy of the GNU General Public License version
  194.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  194.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  194.21 + *
  194.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  194.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  194.24 + * have any questions.
  194.25 + */
  194.26 +
  194.27 +import java.io.*;
  194.28 +import com.sun.tools.classfile.*;
  194.29 +
  194.30 +/*
  194.31 + * @test JSR175Annotations
  194.32 + * @bug 6843077
  194.33 + * @summary test that only type annotations are recorded as such in classfile
  194.34 + */
  194.35 +
  194.36 +public class JSR175Annotations {
  194.37 +    public static void main(String[] args) throws Exception {
  194.38 +        new JSR175Annotations().run();
  194.39 +    }
  194.40 +
  194.41 +    public void run() throws Exception {
  194.42 +        File javaFile = writeTestFile();
  194.43 +        File classFile = compileTestFile(javaFile);
  194.44 +
  194.45 +        ClassFile cf = ClassFile.read(classFile);
  194.46 +        for (Field f : cf.fields) {
  194.47 +            test(cf, f);
  194.48 +        }
  194.49 +        for (Method m: cf.methods) {
  194.50 +            test(cf, m);
  194.51 +        }
  194.52 +
  194.53 +        countAnnotations();
  194.54 +
  194.55 +        if (errors > 0)
  194.56 +            throw new Exception(errors + " errors found");
  194.57 +        System.out.println("PASSED");
  194.58 +    }
  194.59 +
  194.60 +    void test(ClassFile cf, Method m) {
  194.61 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  194.62 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  194.63 +    }
  194.64 +
  194.65 +    void test(ClassFile cf, Field m) {
  194.66 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  194.67 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  194.68 +    }
  194.69 +
  194.70 +    // test the result of Attributes.getIndex according to expectations
  194.71 +    // encoded in the method's name
  194.72 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  194.73 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  194.74 +        if (index != -1) {
  194.75 +            Attribute attr = m.attributes.get(index);
  194.76 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  194.77 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  194.78 +            all += tAttr.annotations.length;
  194.79 +            if (visible)
  194.80 +                visibles += tAttr.annotations.length;
  194.81 +            else
  194.82 +                invisibles += tAttr.annotations.length;
  194.83 +        }
  194.84 +    }
  194.85 +
  194.86 +    // test the result of Attributes.getIndex according to expectations
  194.87 +    // encoded in the method's name
  194.88 +    void test(ClassFile cf, Field m, String name, boolean visible) {
  194.89 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  194.90 +        if (index != -1) {
  194.91 +            Attribute attr = m.attributes.get(index);
  194.92 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  194.93 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  194.94 +            all += tAttr.annotations.length;
  194.95 +            if (visible)
  194.96 +                visibles += tAttr.annotations.length;
  194.97 +            else
  194.98 +                invisibles += tAttr.annotations.length;
  194.99 +        }
 194.100 +    }
 194.101 +
 194.102 +    File writeTestFile() throws IOException {
 194.103 +        File f = new File("Test.java");
 194.104 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 194.105 +        out.println("import java.lang.annotation.Retention;");
 194.106 +        out.println("import java.lang.annotation.RetentionPolicy;");
 194.107 +        out.println("abstract class Test { ");
 194.108 +        out.println("  @Retention(RetentionPolicy.RUNTIME)");
 194.109 +        out.println("  @interface A { }");
 194.110 +        out.println("  @A String m;");
 194.111 +        out.println("  @A String method(@A String a) {");
 194.112 +        out.println("    return a;");
 194.113 +        out.println("  }");
 194.114 +        out.println("}");
 194.115 +        out.close();
 194.116 +        return f;
 194.117 +    }
 194.118 +
 194.119 +    File compileTestFile(File f) {
 194.120 +        int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 194.121 +        if (rc != 0)
 194.122 +            throw new Error("compilation failed. rc=" + rc);
 194.123 +        String path = f.getPath();
 194.124 +        return new File(path.substring(0, path.length() - 5) + ".class");
 194.125 +    }
 194.126 +
 194.127 +    void countAnnotations() {
 194.128 +        int expected_visibles = 0, expected_invisibles = 0;
 194.129 +        int expected_all = expected_visibles + expected_invisibles;
 194.130 +
 194.131 +        if (expected_all != all) {
 194.132 +            errors++;
 194.133 +            System.err.println("expected " + expected_all
 194.134 +                    + " annotations but found " + all);
 194.135 +        }
 194.136 +
 194.137 +        if (expected_visibles != visibles) {
 194.138 +            errors++;
 194.139 +            System.err.println("expected " + expected_visibles
 194.140 +                    + " visibles annotations but found " + visibles);
 194.141 +        }
 194.142 +
 194.143 +        if (expected_invisibles != invisibles) {
 194.144 +            errors++;
 194.145 +            System.err.println("expected " + expected_invisibles
 194.146 +                    + " invisibles annotations but found " + invisibles);
 194.147 +        }
 194.148 +
 194.149 +    }
 194.150 +
 194.151 +    int errors;
 194.152 +    int all;
 194.153 +    int visibles;
 194.154 +    int invisibles;
 194.155 +}
   195.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   195.2 +++ b/test/tools/javap/typeAnnotations/NewArray.java	Sun Jun 28 00:01:09 2009 -0700
   195.3 @@ -0,0 +1,175 @@
   195.4 +/*
   195.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   195.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   195.7 + *
   195.8 + * This code is free software; you can redistribute it and/or modify it
   195.9 + * under the terms of the GNU General Public License version 2 only, as
  195.10 + * published by the Free Software Foundation.
  195.11 + *
  195.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  195.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  195.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  195.15 + * version 2 for more details (a copy is included in the LICENSE file that
  195.16 + * accompanied this code).
  195.17 + *
  195.18 + * You should have received a copy of the GNU General Public License version
  195.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  195.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  195.21 + *
  195.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  195.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  195.24 + * have any questions.
  195.25 + */
  195.26 +
  195.27 +import java.io.*;
  195.28 +import com.sun.tools.classfile.*;
  195.29 +
  195.30 +/*
  195.31 + * @test NewArray
  195.32 + * @bug 6843077
  195.33 + * @summary test that all type annotations are present in the classfile
  195.34 + */
  195.35 +
  195.36 +public class NewArray {
  195.37 +    public static void main(String[] args) throws Exception {
  195.38 +        new NewArray().run();
  195.39 +    }
  195.40 +
  195.41 +    public void run() throws Exception {
  195.42 +        File javaFile = writeTestFile();
  195.43 +        File classFile = compileTestFile(javaFile);
  195.44 +
  195.45 +        ClassFile cf = ClassFile.read(classFile);
  195.46 +        test(cf);
  195.47 +        for (Field f : cf.fields) {
  195.48 +            test(cf, f);
  195.49 +        }
  195.50 +        for (Method m: cf.methods) {
  195.51 +            test(cf, m);
  195.52 +        }
  195.53 +
  195.54 +        countAnnotations();
  195.55 +
  195.56 +        if (errors > 0)
  195.57 +            throw new Exception(errors + " errors found");
  195.58 +        System.out.println("PASSED");
  195.59 +    }
  195.60 +
  195.61 +    void test(ClassFile cf) {
  195.62 +        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  195.63 +        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  195.64 +    }
  195.65 +
  195.66 +    void test(ClassFile cf, Method m) {
  195.67 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  195.68 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  195.69 +    }
  195.70 +
  195.71 +    void test(ClassFile cf, Field m) {
  195.72 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  195.73 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  195.74 +    }
  195.75 +
  195.76 +    // test the result of Attributes.getIndex according to expectations
  195.77 +    // encoded in the method's name
  195.78 +    void test(ClassFile cf, String name, boolean visible) {
  195.79 +        int index = cf.attributes.getIndex(cf.constant_pool, name);
  195.80 +        if (index != -1) {
  195.81 +            Attribute attr = cf.attributes.get(index);
  195.82 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  195.83 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  195.84 +            all += tAttr.annotations.length;
  195.85 +            if (visible)
  195.86 +                visibles += tAttr.annotations.length;
  195.87 +            else
  195.88 +                invisibles += tAttr.annotations.length;
  195.89 +        }
  195.90 +    }
  195.91 +
  195.92 +    // test the result of Attributes.getIndex according to expectations
  195.93 +    // encoded in the method's name
  195.94 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  195.95 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  195.96 +        if (index != -1) {
  195.97 +            Attribute attr = m.attributes.get(index);
  195.98 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  195.99 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 195.100 +            all += tAttr.annotations.length;
 195.101 +            if (visible)
 195.102 +                visibles += tAttr.annotations.length;
 195.103 +            else
 195.104 +                invisibles += tAttr.annotations.length;
 195.105 +        }
 195.106 +    }
 195.107 +
 195.108 +    // test the result of Attributes.getIndex according to expectations
 195.109 +    // encoded in the method's name
 195.110 +    void test(ClassFile cf, Field m, String name, boolean visible) {
 195.111 +        int index = m.attributes.getIndex(cf.constant_pool, name);
 195.112 +        if (index != -1) {
 195.113 +            Attribute attr = m.attributes.get(index);
 195.114 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
 195.115 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 195.116 +            all += tAttr.annotations.length;
 195.117 +            if (visible)
 195.118 +                visibles += tAttr.annotations.length;
 195.119 +            else
 195.120 +                invisibles += tAttr.annotations.length;
 195.121 +        }
 195.122 +    }
 195.123 +
 195.124 +    File writeTestFile() throws IOException {
 195.125 +      File f = new File("Test.java");
 195.126 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 195.127 +        out.println("import java.util.*;");
 195.128 +        out.println("class Test { ");
 195.129 +        out.println("  @interface A { }");
 195.130 +
 195.131 +        out.println(" void test() {");
 195.132 +        out.println("  Object a = new @A String @A [5] @A  [];");
 195.133 +        out.println("  Object b = new @A String @A [5] @A [3];");
 195.134 +        out.println("  Object c = new @A String @A [] @A [] {};");
 195.135 +        out.println(" }");
 195.136 +        out.println("}");
 195.137 +
 195.138 +        out.close();
 195.139 +        return f;
 195.140 +    }
 195.141 +
 195.142 +    File compileTestFile(File f) {
 195.143 +        int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 195.144 +        if (rc != 0)
 195.145 +            throw new Error("compilation failed. rc=" + rc);
 195.146 +        String path = f.getPath();
 195.147 +        return new File(path.substring(0, path.length() - 5) + ".class");
 195.148 +    }
 195.149 +
 195.150 +    void countAnnotations() {
 195.151 +        int expected_visibles = 0, expected_invisibles = 9;
 195.152 +        int expected_all = expected_visibles + expected_invisibles;
 195.153 +
 195.154 +        if (expected_all != all) {
 195.155 +            errors++;
 195.156 +            System.err.println("expected " + expected_all
 195.157 +                    + " annotations but found " + all);
 195.158 +        }
 195.159 +
 195.160 +        if (expected_visibles != visibles) {
 195.161 +            errors++;
 195.162 +            System.err.println("expected " + expected_visibles
 195.163 +                    + " visibles annotations but found " + visibles);
 195.164 +        }
 195.165 +
 195.166 +        if (expected_invisibles != invisibles) {
 195.167 +            errors++;
 195.168 +            System.err.println("expected " + expected_invisibles
 195.169 +                    + " invisibles annotations but found " + invisibles);
 195.170 +        }
 195.171 +
 195.172 +    }
 195.173 +
 195.174 +    int errors;
 195.175 +    int all;
 195.176 +    int visibles;
 195.177 +    int invisibles;
 195.178 +}
   196.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   196.2 +++ b/test/tools/javap/typeAnnotations/Presence.java	Sun Jun 28 00:01:09 2009 -0700
   196.3 @@ -0,0 +1,189 @@
   196.4 +/*
   196.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   196.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   196.7 + *
   196.8 + * This code is free software; you can redistribute it and/or modify it
   196.9 + * under the terms of the GNU General Public License version 2 only, as
  196.10 + * published by the Free Software Foundation.
  196.11 + *
  196.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  196.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  196.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  196.15 + * version 2 for more details (a copy is included in the LICENSE file that
  196.16 + * accompanied this code).
  196.17 + *
  196.18 + * You should have received a copy of the GNU General Public License version
  196.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  196.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  196.21 + *
  196.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  196.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  196.24 + * have any questions.
  196.25 + */
  196.26 +
  196.27 +import java.io.*;
  196.28 +import com.sun.tools.classfile.*;
  196.29 +
  196.30 +/*
  196.31 + * @test Presence
  196.32 + * @bug 6843077
  196.33 + * @summary test that all type annotations are present in the classfile
  196.34 + */
  196.35 +
  196.36 +public class Presence {
  196.37 +    public static void main(String[] args) throws Exception {
  196.38 +        new Presence().run();
  196.39 +    }
  196.40 +
  196.41 +    public void run() throws Exception {
  196.42 +        File javaFile = writeTestFile();
  196.43 +        File classFile = compileTestFile(javaFile);
  196.44 +
  196.45 +        ClassFile cf = ClassFile.read(classFile);
  196.46 +        test(cf);
  196.47 +        for (Field f : cf.fields) {
  196.48 +            test(cf, f);
  196.49 +        }
  196.50 +        for (Method m: cf.methods) {
  196.51 +            test(cf, m);
  196.52 +        }
  196.53 +
  196.54 +        countAnnotations();
  196.55 +
  196.56 +        if (errors > 0)
  196.57 +            throw new Exception(errors + " errors found");
  196.58 +        System.out.println("PASSED");
  196.59 +    }
  196.60 +
  196.61 +    void test(ClassFile cf) {
  196.62 +        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  196.63 +        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  196.64 +    }
  196.65 +
  196.66 +    void test(ClassFile cf, Method m) {
  196.67 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  196.68 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  196.69 +    }
  196.70 +
  196.71 +    void test(ClassFile cf, Field m) {
  196.72 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  196.73 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  196.74 +    }
  196.75 +
  196.76 +    // test the result of Attributes.getIndex according to expectations
  196.77 +    // encoded in the method's name
  196.78 +    void test(ClassFile cf, String name, boolean visible) {
  196.79 +        int index = cf.attributes.getIndex(cf.constant_pool, name);
  196.80 +        if (index != -1) {
  196.81 +            Attribute attr = cf.attributes.get(index);
  196.82 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  196.83 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  196.84 +            all += tAttr.annotations.length;
  196.85 +            if (visible)
  196.86 +                visibles += tAttr.annotations.length;
  196.87 +            else
  196.88 +                invisibles += tAttr.annotations.length;
  196.89 +        }
  196.90 +    }
  196.91 +
  196.92 +    // test the result of Attributes.getIndex according to expectations
  196.93 +    // encoded in the method's name
  196.94 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  196.95 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  196.96 +        if (index != -1) {
  196.97 +            Attribute attr = m.attributes.get(index);
  196.98 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  196.99 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 196.100 +            all += tAttr.annotations.length;
 196.101 +            if (visible)
 196.102 +                visibles += tAttr.annotations.length;
 196.103 +            else
 196.104 +                invisibles += tAttr.annotations.length;
 196.105 +        }
 196.106 +    }
 196.107 +
 196.108 +    // test the result of Attributes.getIndex according to expectations
 196.109 +    // encoded in the method's name
 196.110 +    void test(ClassFile cf, Field m, String name, boolean visible) {
 196.111 +        int index = m.attributes.getIndex(cf.constant_pool, name);
 196.112 +        if (index != -1) {
 196.113 +            Attribute attr = m.attributes.get(index);
 196.114 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
 196.115 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 196.116 +            all += tAttr.annotations.length;
 196.117 +            if (visible)
 196.118 +                visibles += tAttr.annotations.length;
 196.119 +            else
 196.120 +                invisibles += tAttr.annotations.length;
 196.121 +        }
 196.122 +    }
 196.123 +
 196.124 +    File writeTestFile() throws IOException {
 196.125 +        File f = new File("Test.java");
 196.126 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 196.127 +        out.println("import java.util.*;");
 196.128 +        out.println("class Test<@Test.A T extends @Test.A List<@Test.A String>> { ");
 196.129 +        out.println("  @interface A { }");
 196.130 +
 196.131 +        out.println("  Map<@A String, Map<@A String, @A String>> f1;");
 196.132 +
 196.133 +        out.println("  <@A T extends @A List<@A String>>");
 196.134 +        out.println("  Map<@A String, @A List<@A String>>");
 196.135 +        out.println("  method(List<@A String> @A [] param1, String @A [] @A ... param2) @A");
 196.136 +        out.println("  throws @A Exception {");
 196.137 +        out.println("    @A String lc1 = null;");
 196.138 +        out.println("    @A List<@A String> lc2 = null;");
 196.139 +        out.println("    @A String @A [] [] @A[] lc3 = null;");
 196.140 +        out.println("    List<? extends @A List<@A String>> lc4 = null;");
 196.141 +        out.println("    Object lc5 = (@A List<@A String>) null;");
 196.142 +        out.println("    boolean lc6 = lc1 instanceof @A String;");
 196.143 +        out.println("    boolean lc7 = lc5 instanceof @A String @A [] @A [];");
 196.144 +        out.println("    new @A ArrayList<@A String>();");
 196.145 +        out.println("    Object lc8 = new @A String @A [4];");
 196.146 +        out.println("    Object lc9 = @A String.class;");
 196.147 +        out.println("    Object lc10 = @A int.class;");
 196.148 +        out.println("    return null;");
 196.149 +        out.println("  }");
 196.150 +        out.println("  void vararg1(String @A ... t) { } ");
 196.151 +        out.println("}");
 196.152 +        out.close();
 196.153 +        return f;
 196.154 +    }
 196.155 +
 196.156 +    File compileTestFile(File f) {
 196.157 +        int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 196.158 +        if (rc != 0)
 196.159 +            throw new Error("compilation failed. rc=" + rc);
 196.160 +        String path = f.getPath();
 196.161 +        return new File(path.substring(0, path.length() - 5) + ".class");
 196.162 +    }
 196.163 +
 196.164 +    void countAnnotations() {
 196.165 +        int expected_visibles = 0, expected_invisibles = 39;
 196.166 +        int expected_all = expected_visibles + expected_invisibles;
 196.167 +
 196.168 +        if (expected_all != all) {
 196.169 +            errors++;
 196.170 +            System.err.println("expected " + expected_all
 196.171 +                    + " annotations but found " + all);
 196.172 +        }
 196.173 +
 196.174 +        if (expected_visibles != visibles) {
 196.175 +            errors++;
 196.176 +            System.err.println("expected " + expected_visibles
 196.177 +                    + " visibles annotations but found " + visibles);
 196.178 +        }
 196.179 +
 196.180 +        if (expected_invisibles != invisibles) {
 196.181 +            errors++;
 196.182 +            System.err.println("expected " + expected_invisibles
 196.183 +                    + " invisibles annotations but found " + invisibles);
 196.184 +        }
 196.185 +
 196.186 +    }
 196.187 +
 196.188 +    int errors;
 196.189 +    int all;
 196.190 +    int visibles;
 196.191 +    int invisibles;
 196.192 +}
   197.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   197.2 +++ b/test/tools/javap/typeAnnotations/PresenceInner.java	Sun Jun 28 00:01:09 2009 -0700
   197.3 @@ -0,0 +1,185 @@
   197.4 +/*
   197.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
   197.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   197.7 + *
   197.8 + * This code is free software; you can redistribute it and/or modify it
   197.9 + * under the terms of the GNU General Public License version 2 only, as
  197.10 + * published by the Free Software Foundation.
  197.11 + *
  197.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  197.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  197.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  197.15 + * version 2 for more details (a copy is included in the LICENSE file that
  197.16 + * accompanied this code).
  197.17 + *
  197.18 + * You should have received a copy of the GNU General Public License version
  197.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  197.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  197.21 + *
  197.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  197.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  197.24 + * have any questions.
  197.25 + */
  197.26 +
  197.27 +import java.io.*;
  197.28 +import com.sun.tools.classfile.*;
  197.29 +
  197.30 +/*
  197.31 + * @test PresenceInner
  197.32 + * @bug 6843077
  197.33 + * @summary test that annotations in inner types count only once
  197.34 + */
  197.35 +
  197.36 +public class PresenceInner {
  197.37 +    public static void main(String[] args) throws Exception {
  197.38 +        new PresenceInner().run();
  197.39 +    }
  197.40 +
  197.41 +    public void run() throws Exception {
  197.42 +        File javaFile = writeTestFile();
  197.43 +        File classFile = compileTestFile(javaFile);
  197.44 +
  197.45 +        ClassFile cf = ClassFile.read(classFile);
  197.46 +        test(cf);
  197.47 +        for (Field f : cf.fields) {
  197.48 +            test(cf, f);
  197.49 +        }
  197.50 +        for (Method m: cf.methods) {
  197.51 +            test(cf, m);
  197.52 +        }
  197.53 +
  197.54 +        // counts are zero when vising outer class
  197.55 +        countAnnotations(0);
  197.56 +
  197.57 +        // visit inner class
  197.58 +        File innerFile = new File("Test$1Inner.class");
  197.59 +        ClassFile icf = ClassFile.read(innerFile);
  197.60 +        test(icf);
  197.61 +        for (Field f : icf.fields) {
  197.62 +            test(cf, f);
  197.63 +        }
  197.64 +        for (Method m: icf.methods) {
  197.65 +            test(cf, m);
  197.66 +        }
  197.67 +
  197.68 +        countAnnotations(1);
  197.69 +        if (errors > 0)
  197.70 +            throw new Exception(errors + " errors found");
  197.71 +        System.out.println("PASSED");
  197.72 +    }
  197.73 +
  197.74 +    void test(ClassFile cf) {
  197.75 +        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  197.76 +        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  197.77 +    }
  197.78 +
  197.79 +    void test(ClassFile cf, Method m) {
  197.80 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  197.81 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  197.82 +    }
  197.83 +
  197.84 +    void test(ClassFile cf, Field m) {
  197.85 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  197.86 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  197.87 +    }
  197.88 +
  197.89 +    // test the result of Attributes.getIndex according to expectations
  197.90 +    // encoded in the method's name
  197.91 +    void test(ClassFile cf, String name, boolean visible) {
  197.92 +        int index = cf.attributes.getIndex(cf.constant_pool, name);
  197.93 +        if (index != -1) {
  197.94 +            Attribute attr = cf.attributes.get(index);
  197.95 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  197.96 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  197.97 +            all += tAttr.annotations.length;
  197.98 +            if (visible)
  197.99 +                visibles += tAttr.annotations.length;
 197.100 +            else
 197.101 +                invisibles += tAttr.annotations.length;
 197.102 +        }
 197.103 +    }
 197.104 +
 197.105 +    // test the result of Attributes.getIndex according to expectations
 197.106 +    // encoded in the method's name
 197.107 +    void test(ClassFile cf, Method m, String name, boolean visible) {
 197.108 +        int index = m.attributes.getIndex(cf.constant_pool, name);
 197.109 +        if (index != -1) {
 197.110 +            Attribute attr = m.attributes.get(index);
 197.111 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
 197.112 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 197.113 +            all += tAttr.annotations.length;
 197.114 +            if (visible)
 197.115 +                visibles += tAttr.annotations.length;
 197.116 +            else
 197.117 +                invisibles += tAttr.annotations.length;
 197.118 +        }
 197.119 +    }
 197.120 +
 197.121 +    // test the result of Attributes.getIndex according to expectations
 197.122 +    // encoded in the method's name
 197.123 +    void test(ClassFile cf, Field m, String name, boolean visible) {
 197.124 +        int index = m.attributes.getIndex(cf.constant_pool, name);
 197.125 +        if (index != -1) {
 197.126 +            Attribute attr = m.attributes.get(index);
 197.127 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
 197.128 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
 197.129 +            all += tAttr.annotations.length;
 197.130 +            if (visible)
 197.131 +                visibles += tAttr.annotations.length;
 197.132 +            else
 197.133 +                invisibles += tAttr.annotations.length;
 197.134 +        }
 197.135 +    }
 197.136 +
 197.137 +    File writeTestFile() throws IOException {
 197.138 +        File f = new File("Test.java");
 197.139 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 197.140 +
 197.141 +        out.println("class Test {");
 197.142 +        out.println("  void method() {");
 197.143 +        out.println("    class Inner<T extends @A Object> { }");
 197.144 +        out.println("  }");
 197.145 +        out.println("}");
 197.146 +        out.println("@interface A { }");
 197.147 +        out.close();
 197.148 +        System.out.println(f.getAbsolutePath());
 197.149 +        return f;
 197.150 +    }
 197.151 +
 197.152 +    File compileTestFile(File f) {
 197.153 +        int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 197.154 +        if (rc != 0)
 197.155 +            throw new Error("compilation failed. rc=" + rc);
 197.156 +        String path = f.getPath();
 197.157 +        return new File(path.substring(0, path.length() - 5) + ".class");
 197.158 +    }
 197.159 +
 197.160 +    void countAnnotations(int expected_invisibles) {
 197.161 +        int expected_visibles = 0;
 197.162 +        int expected_all = expected_visibles + expected_invisibles;
 197.163 +
 197.164 +        if (expected_all != all) {
 197.165 +            errors++;
 197.166 +            System.err.println("expected " + expected_all
 197.167 +                    + " annotations but found " + all);
 197.168 +        }
 197.169 +
 197.170 +        if (expected_visibles != visibles) {
 197.171 +            errors++;
 197.172 +            System.err.println("expected " + expected_visibles
 197.173 +                    + " visibles annotations but found " + visibles);
 197.174 +        }
 197.175 +
 197.176 +        if (expected_invisibles != invisibles) {
 197.177 +            errors++;
 197.178 +            System.err.println("expected " + expected_invisibles
 197.179 +                    + " invisibles annotations but found " + invisibles);
 197.180 +        }
 197.181 +
 197.182 +    }
 197.183 +
 197.184 +    int errors;
 197.185 +    int all;
 197.186 +    int visibles;
 197.187 +    int invisibles;
 197.188 +}
   198.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   198.2 +++ b/test/tools/javap/typeAnnotations/Visibility.java	Sun Jun 28 00:01:09 2009 -0700
   198.3 @@ -0,0 +1,139 @@
   198.4 +/*
   198.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
   198.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   198.7 + *
   198.8 + * This code is free software; you can redistribute it and/or modify it
   198.9 + * under the terms of the GNU General Public License version 2 only, as
  198.10 + * published by the Free Software Foundation.
  198.11 + *
  198.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  198.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  198.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  198.15 + * version 2 for more details (a copy is included in the LICENSE file that
  198.16 + * accompanied this code).
  198.17 + *
  198.18 + * You should have received a copy of the GNU General Public License version
  198.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  198.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  198.21 + *
  198.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  198.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  198.24 + * have any questions.
  198.25 + */
  198.26 +
  198.27 +import java.io.*;
  198.28 +import com.sun.tools.classfile.*;
  198.29 +
  198.30 +/*
  198.31 + * @test Visibility
  198.32 + * @bug 6843077
  198.33 + * @summary test that type annotations are recorded in the classfile
  198.34 + */
  198.35 +
  198.36 +public class Visibility {
  198.37 +    public static void main(String[] args) throws Exception {
  198.38 +        new Visibility().run();
  198.39 +    }
  198.40 +
  198.41 +    public void run() throws Exception {
  198.42 +        File javaFile = writeTestFile();
  198.43 +        File classFile = compileTestFile(javaFile);
  198.44 +
  198.45 +        ClassFile cf = ClassFile.read(classFile);
  198.46 +        for (Method m: cf.methods) {
  198.47 +            test(cf, m);
  198.48 +        }
  198.49 +
  198.50 +        countAnnotations();
  198.51 +
  198.52 +        if (errors > 0)
  198.53 +            throw new Exception(errors + " errors found");
  198.54 +        System.out.println("PASSED");
  198.55 +    }
  198.56 +
  198.57 +    void test(ClassFile cf, Method m) {
  198.58 +        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  198.59 +        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  198.60 +    }
  198.61 +
  198.62 +    // test the result of Attributes.getIndex according to expectations
  198.63 +    // encoded in the method's name
  198.64 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  198.65 +        int index = m.attributes.getIndex(cf.constant_pool, name);
  198.66 +        if (index != -1) {
  198.67 +            Attribute attr = m.attributes.get(index);
  198.68 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  198.69 +            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  198.70 +            all += tAttr.annotations.length;
  198.71 +            if (visible)
  198.72 +                visibles += tAttr.annotations.length;
  198.73 +            else
  198.74 +                invisibles += tAttr.annotations.length;
  198.75 +        }
  198.76 +    }
  198.77 +
  198.78 +    File writeTestFile() throws IOException {
  198.79 +        File f = new File("Test.java");
  198.80 +        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
  198.81 +        out.println("import java.lang.annotation.Retention;");
  198.82 +        out.println("import java.lang.annotation.RetentionPolicy;");
  198.83 +        out.println("abstract class Test { ");
  198.84 +        // visible annotations: RUNTIME
  198.85 +        out.println("  @Retention(RetentionPolicy.RUNTIME)");
  198.86 +        out.println("  @interface A { }");
  198.87 +        out.println("  void visible() @A { }");
  198.88 +
  198.89 +        // invisible annotations: CLASS
  198.90 +        out.println("  @Retention(RetentionPolicy.CLASS)");
  198.91 +        out.println("  @interface B { }");
  198.92 +        out.println("  void invisible() @B { }");
  198.93 +
  198.94 +        // source annotations
  198.95 +        out.println("  @Retention(RetentionPolicy.SOURCE)");
  198.96 +        out.println("  @interface C { }");
  198.97 +        out.println("  void source() @C { }");
  198.98 +
  198.99 +        // default visibility: CLASS
 198.100 +        out.println("  @interface D { }");
 198.101 +        out.println("  void def() @D { }");
 198.102 +        out.println("}");
 198.103 +        out.close();
 198.104 +        return f;
 198.105 +    }
 198.106 +
 198.107 +    File compileTestFile(File f) {
 198.108 +      int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.7", "-g", f.getPath() });
 198.109 +        if (rc != 0)
 198.110 +            throw new Error("compilation failed. rc=" + rc);
 198.111 +        String path = f.getPath();
 198.112 +        return new File(path.substring(0, path.length() - 5) + ".class");
 198.113 +    }
 198.114 +
 198.115 +    void countAnnotations() {
 198.116 +        int expected_all = 3, expected_visibles = 1, expected_invisibles = 2;
 198.117 +
 198.118 +        if (expected_all != all) {
 198.119 +            errors++;
 198.120 +            System.err.println("expected " + expected_all
 198.121 +                    + " annotations but found " + all);
 198.122 +        }
 198.123 +
 198.124 +        if (expected_visibles != visibles) {
 198.125 +            errors++;
 198.126 +            System.err.println("expected " + expected_visibles
 198.127 +                    + " visibles annotations but found " + visibles);
 198.128 +        }
 198.129 +
 198.130 +        if (expected_invisibles != invisibles) {
 198.131 +            errors++;
 198.132 +            System.err.println("expected " + expected_invisibles
 198.133 +                    + " invisibles annotations but found " + invisibles);
 198.134 +        }
 198.135 +
 198.136 +    }
 198.137 +
 198.138 +    int errors;
 198.139 +    int all;
 198.140 +    int visibles;
 198.141 +    int invisibles;
 198.142 +}

mercurial