Merge jdk8-b29

Mon, 05 Mar 2012 17:04:48 -0800

author
lana
date
Mon, 05 Mar 2012 17:04:48 -0800
changeset 1213
e974e82abe51
parent 1206
7e777fcd4d39
parent 1212
3d3350aea968
child 1214
a1af4b95c287
child 1225
83352b2e2ebc

Merge

test/tools/javac/apt.sh file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/source/tree/MemberReferenceTree.java	Thu Mar 01 12:23:33 2012 -0800
     1.2 +++ b/src/share/classes/com/sun/source/tree/MemberReferenceTree.java	Mon Mar 05 17:04:48 2012 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -37,7 +37,7 @@
    1.11   *   <em>expression</em> # <em>[ identifier | new ]</em>
    1.12   * </pre>
    1.13   *
    1.14 - * @see JSR 292
    1.15 + * @since 1.8
    1.16   */
    1.17  public interface MemberReferenceTree extends ExpressionTree {
    1.18  
     2.1 --- a/src/share/classes/com/sun/source/util/JavacTask.java	Thu Mar 01 12:23:33 2012 -0800
     2.2 +++ b/src/share/classes/com/sun/source/util/JavacTask.java	Mon Mar 05 17:04:48 2012 -0800
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -25,9 +25,9 @@
    2.11  
    2.12  package com.sun.source.util;
    2.13  
    2.14 -import com.sun.source.tree.CompilationUnitTree;
    2.15 -import com.sun.source.tree.Tree;
    2.16  import java.io.IOException;
    2.17 +
    2.18 +import javax.annotation.processing.ProcessingEnvironment;
    2.19  import javax.lang.model.element.Element;
    2.20  import javax.lang.model.type.TypeMirror;
    2.21  import javax.lang.model.util.Elements;
    2.22 @@ -35,6 +35,12 @@
    2.23  import javax.tools.JavaCompiler.CompilationTask;
    2.24  import javax.tools.JavaFileObject;
    2.25  
    2.26 +import com.sun.source.tree.CompilationUnitTree;
    2.27 +import com.sun.source.tree.Tree;
    2.28 +import com.sun.tools.javac.api.BasicJavacTask;
    2.29 +import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    2.30 +import com.sun.tools.javac.util.Context;
    2.31 +
    2.32  /**
    2.33   * Provides access to functionality specific to the JDK Java Compiler, javac.
    2.34   *
    2.35 @@ -45,10 +51,29 @@
    2.36  public abstract class JavacTask implements CompilationTask {
    2.37  
    2.38      /**
    2.39 +     * Get the {@code JavacTask} for a {@code ProcessingEnvironment}.
    2.40 +     * If the compiler is being invoked using a
    2.41 +     * {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},
    2.42 +     * then that task will be returned.
    2.43 +     * @param processingEnvironment
    2.44 +     * @return the {@code JavacTask} for a {@code ProcessingEnvironment}
    2.45 +     * @since 1.8
    2.46 +     */
    2.47 +    public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
    2.48 +        if (!processingEnvironment.getClass().getName().equals(
    2.49 +                "com.sun.tools.javac.processing.JavacProcessingEnvironment"))
    2.50 +            throw new IllegalArgumentException();
    2.51 +        Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
    2.52 +        JavacTask t = c.get(JavacTask.class);
    2.53 +        return (t != null) ? t : new BasicJavacTask(c, true);
    2.54 +    }
    2.55 +
    2.56 +    /**
    2.57       * Parse the specified files returning a list of abstract syntax trees.
    2.58       *
    2.59       * @return a list of abstract syntax trees
    2.60       * @throws IOException if an unhandled I/O error occurred in the compiler.
    2.61 +     * @throws IllegalStateException if the operation cannot be performed at this time.
    2.62       */
    2.63      public abstract Iterable<? extends CompilationUnitTree> parse()
    2.64          throws IOException;
    2.65 @@ -58,6 +83,7 @@
    2.66       *
    2.67       * @return a list of elements that were analyzed
    2.68       * @throws IOException if an unhandled I/O error occurred in the compiler.
    2.69 +     * @throws IllegalStateException if the operation cannot be performed at this time.
    2.70       */
    2.71      public abstract Iterable<? extends Element> analyze() throws IOException;
    2.72  
    2.73 @@ -66,17 +92,51 @@
    2.74       *
    2.75       * @return a list of files that were generated
    2.76       * @throws IOException if an unhandled I/O error occurred in the compiler.
    2.77 +     * @throws IllegalStateException if the operation cannot be performed at this time.
    2.78       */
    2.79      public abstract Iterable<? extends JavaFileObject> generate() throws IOException;
    2.80  
    2.81      /**
    2.82 -     * The specified listener will receive events describing the progress of
    2.83 -     * this compilation task.
    2.84 +     * The specified listener will receive notification of events
    2.85 +     * describing the progress of this compilation task.
    2.86 +     *
    2.87 +     * If another listener is receiving notifications as a result of a prior
    2.88 +     * call of this method, then that listener will no longer receive notifications.
    2.89 +     *
    2.90 +     * Informally, this method is equivalent to calling {@code removeTaskListener} for
    2.91 +     * any listener that has been previously set, followed by {@code addTaskListener}
    2.92 +     * for the new listener.
    2.93 +     *
    2.94 +     * @throws IllegalStateException if the specified listener has already been added.
    2.95       */
    2.96      public abstract void setTaskListener(TaskListener taskListener);
    2.97  
    2.98      /**
    2.99 +     * The specified listener will receive notification of events
   2.100 +     * describing the progress of this compilation task.
   2.101 +     *
   2.102 +     * This method may be called at any time before or during the compilation.
   2.103 +     *
   2.104 +     * @throws IllegalStateException if the specified listener has already been added.
   2.105 +     * @since 1.8
   2.106 +     */
   2.107 +    public abstract void addTaskListener(TaskListener taskListener);
   2.108 +
   2.109 +    /**
   2.110 +     * The specified listener will no longer receive notification of events
   2.111 +     * describing the progress of this compilation task.
   2.112 +     *
   2.113 +     * This method may be called at any time before or during the compilation.
   2.114 +     *
   2.115 +     * @since 1.8
   2.116 +     */
   2.117 +    public abstract void removeTaskListener(TaskListener taskListener);
   2.118 +
   2.119 +    /**
   2.120       * Get a type mirror of the tree node determined by the specified path.
   2.121 +     * This method has been superceded by methods on
   2.122 +     * {@link com.sun.source.util.Trees Trees}.
   2.123 +     * @see com.sun.source.util.Trees#getTypeMirror
   2.124       */
   2.125      public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);
   2.126      /**
     3.1 --- a/src/share/classes/com/sun/tools/doclets/package.html	Thu Mar 01 12:23:33 2012 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/doclets/package.html	Mon Mar 05 17:04:48 2012 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  <!--
     3.5 - Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
     3.6 + Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3.7   DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8  
     3.9   This code is free software; you can redistribute it and/or modify it
    3.10 @@ -29,6 +29,6 @@
    3.11  </head>
    3.12  <body bgcolor="white">
    3.13          As of JDK version 1.5, replaced by 
    3.14 -        {@link com.sun.tools.doclets.internal.toolkit.util}.
    3.15 +        {@code com.sun.tools.doclets.internal.toolkit.util}.
    3.16      </body>
    3.17  </html>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/share/classes/com/sun/tools/javac/api/BasicJavacTask.java	Mon Mar 05 17:04:48 2012 -0800
     4.3 @@ -0,0 +1,139 @@
     4.4 +/*
     4.5 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.  Oracle designates this
    4.11 + * particular file as subject to the "Classpath" exception as provided
    4.12 + * by Oracle in the LICENSE file that accompanied this code.
    4.13 + *
    4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 + * version 2 for more details (a copy is included in the LICENSE file that
    4.18 + * accompanied this code).
    4.19 + *
    4.20 + * You should have received a copy of the GNU General Public License version
    4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 + *
    4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.25 + * or visit www.oracle.com if you need additional information or have any
    4.26 + * questions.
    4.27 + */
    4.28 +
    4.29 +package com.sun.tools.javac.api;
    4.30 +
    4.31 +import java.io.IOException;
    4.32 +import java.util.Locale;
    4.33 +
    4.34 +import javax.annotation.processing.Processor;
    4.35 +import javax.lang.model.element.Element;
    4.36 +import javax.lang.model.type.TypeMirror;
    4.37 +import javax.lang.model.util.Elements;
    4.38 +import javax.lang.model.util.Types;
    4.39 +import javax.tools.JavaFileObject;
    4.40 +
    4.41 +import com.sun.source.tree.CompilationUnitTree;
    4.42 +import com.sun.source.tree.Tree;
    4.43 +import com.sun.source.util.JavacTask;
    4.44 +import com.sun.source.util.TaskListener;
    4.45 +import com.sun.tools.javac.model.JavacElements;
    4.46 +import com.sun.tools.javac.model.JavacTypes;
    4.47 +import com.sun.tools.javac.tree.JCTree;
    4.48 +import com.sun.tools.javac.util.Context;
    4.49 +import java.util.Collection;
    4.50 +
    4.51 +/**
    4.52 + * Provides basic functionality for implementations of JavacTask.
    4.53 + *
    4.54 + * <p><b>This is NOT part of any supported API.
    4.55 + * If you write code that depends on this, you do so at your own
    4.56 + * risk.  This code and its internal interfaces are subject to change
    4.57 + * or deletion without notice.</b></p>
    4.58 + */
    4.59 +public class BasicJavacTask extends JavacTask {
    4.60 +    protected Context context;
    4.61 +    private TaskListener taskListener;
    4.62 +
    4.63 +    public BasicJavacTask(Context c, boolean register) {
    4.64 +        context = c;
    4.65 +        if (register)
    4.66 +            context.put(JavacTask.class, this);
    4.67 +    }
    4.68 +
    4.69 +    @Override
    4.70 +    public Iterable<? extends CompilationUnitTree> parse() throws IOException {
    4.71 +        throw new IllegalStateException();
    4.72 +    }
    4.73 +
    4.74 +    @Override
    4.75 +    public Iterable<? extends Element> analyze() throws IOException {
    4.76 +        throw new IllegalStateException();
    4.77 +    }
    4.78 +
    4.79 +    @Override
    4.80 +    public Iterable<? extends JavaFileObject> generate() throws IOException {
    4.81 +        throw new IllegalStateException();
    4.82 +    }
    4.83 +
    4.84 +    @Override
    4.85 +    public void setTaskListener(TaskListener tl) {
    4.86 +        MultiTaskListener mtl = MultiTaskListener.instance(context);
    4.87 +        if (taskListener != null)
    4.88 +            mtl.remove(taskListener);
    4.89 +        if (tl != null)
    4.90 +            mtl.add(tl);
    4.91 +        taskListener = tl;
    4.92 +    }
    4.93 +
    4.94 +    @Override
    4.95 +    public void addTaskListener(TaskListener taskListener) {
    4.96 +        MultiTaskListener mtl = MultiTaskListener.instance(context);
    4.97 +        mtl.add(taskListener);
    4.98 +    }
    4.99 +
   4.100 +    @Override
   4.101 +    public void removeTaskListener(TaskListener taskListener) {
   4.102 +        MultiTaskListener mtl = MultiTaskListener.instance(context);
   4.103 +        mtl.remove(taskListener);
   4.104 +    }
   4.105 +
   4.106 +    public Collection<TaskListener> getTaskListeners() {
   4.107 +        MultiTaskListener mtl = MultiTaskListener.instance(context);
   4.108 +        return mtl.getTaskListeners();
   4.109 +    }
   4.110 +
   4.111 +    @Override
   4.112 +    public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
   4.113 +        // TODO: Should complete attribution if necessary
   4.114 +        Tree last = null;
   4.115 +        for (Tree node : path)
   4.116 +            last = node;
   4.117 +        return ((JCTree)last).type;
   4.118 +    }
   4.119 +
   4.120 +    @Override
   4.121 +    public Elements getElements() {
   4.122 +        return JavacElements.instance(context);
   4.123 +    }
   4.124 +
   4.125 +    @Override
   4.126 +    public Types getTypes() {
   4.127 +        return JavacTypes.instance(context);
   4.128 +    }
   4.129 +
   4.130 +    public void setProcessors(Iterable<? extends Processor> processors) {
   4.131 +        throw new IllegalStateException();
   4.132 +    }
   4.133 +
   4.134 +    public void setLocale(Locale locale) {
   4.135 +        throw new IllegalStateException();
   4.136 +    }
   4.137 +
   4.138 +    public Boolean call() {
   4.139 +        throw new IllegalStateException();
   4.140 +    }
   4.141 +
   4.142 +}
     5.1 --- a/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java	Thu Mar 01 12:23:33 2012 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java	Mon Mar 05 17:04:48 2012 -0800
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -31,8 +31,13 @@
    5.11  import java.io.OutputStream;
    5.12  import java.io.Reader;
    5.13  import java.io.Writer;
    5.14 +import java.lang.annotation.ElementType;
    5.15 +import java.lang.annotation.Retention;
    5.16 +import java.lang.annotation.RetentionPolicy;
    5.17 +import java.lang.annotation.Target;
    5.18  import java.net.URI;
    5.19  import java.util.ArrayList;
    5.20 +import java.util.Collection;
    5.21  import java.util.Collections;
    5.22  import java.util.HashMap;
    5.23  import java.util.Iterator;
    5.24 @@ -41,25 +46,21 @@
    5.25  import java.util.Map;
    5.26  import java.util.Set;
    5.27  
    5.28 +import javax.lang.model.element.Modifier;
    5.29  import javax.lang.model.element.NestingKind;
    5.30  import javax.tools.Diagnostic;
    5.31 +import javax.tools.DiagnosticListener;
    5.32  import javax.tools.FileObject;
    5.33  import javax.tools.JavaFileManager;
    5.34  import javax.tools.JavaFileManager.Location;
    5.35  import javax.tools.JavaFileObject;
    5.36 +import javax.tools.JavaFileObject.Kind;
    5.37  
    5.38  import com.sun.source.util.TaskEvent;
    5.39  import com.sun.source.util.TaskListener;
    5.40  import com.sun.tools.javac.util.ClientCodeException;
    5.41  import com.sun.tools.javac.util.Context;
    5.42  import com.sun.tools.javac.util.JCDiagnostic;
    5.43 -import java.lang.annotation.ElementType;
    5.44 -import java.lang.annotation.Retention;
    5.45 -import java.lang.annotation.RetentionPolicy;
    5.46 -import java.lang.annotation.Target;
    5.47 -import javax.lang.model.element.Modifier;
    5.48 -import javax.tools.DiagnosticListener;
    5.49 -import javax.tools.JavaFileObject.Kind;
    5.50  
    5.51  /**
    5.52   *  Wrap objects to enable unchecked exceptions to be caught and handled.
    5.53 @@ -160,6 +161,20 @@
    5.54          return new WrappedTaskListener(tl);
    5.55      }
    5.56  
    5.57 +    TaskListener unwrap(TaskListener l) {
    5.58 +        if (l instanceof WrappedTaskListener)
    5.59 +            return ((WrappedTaskListener) l).clientTaskListener;
    5.60 +        else
    5.61 +            return l;
    5.62 +    }
    5.63 +
    5.64 +    Collection<TaskListener> unwrap(Collection<? extends TaskListener> listeners) {
    5.65 +        Collection<TaskListener> c = new ArrayList<TaskListener>(listeners.size());
    5.66 +        for (TaskListener l: listeners)
    5.67 +            c.add(unwrap(l));
    5.68 +        return c;
    5.69 +    }
    5.70 +
    5.71      @SuppressWarnings("unchecked")
    5.72      private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) {
    5.73          if (diagnostic instanceof JCDiagnostic) {
    5.74 @@ -181,6 +196,10 @@
    5.75          return trusted;
    5.76      }
    5.77  
    5.78 +    private String wrappedToString(Class<?> wrapperClass, Object wrapped) {
    5.79 +        return wrapperClass.getSimpleName() + "[" + wrapped + "]";
    5.80 +    }
    5.81 +
    5.82      // <editor-fold defaultstate="collapsed" desc="Wrapper classes">
    5.83  
    5.84      // FIXME: all these classes should be converted to use multi-catch when
    5.85 @@ -361,6 +380,11 @@
    5.86                  throw new ClientCodeException(e);
    5.87              }
    5.88          }
    5.89 +
    5.90 +        @Override
    5.91 +        public String toString() {
    5.92 +            return wrappedToString(getClass(), clientJavaFileManager);
    5.93 +        }
    5.94      }
    5.95  
    5.96      protected class WrappedFileObject implements FileObject {
    5.97 @@ -486,6 +510,11 @@
    5.98                  throw new ClientCodeException(e);
    5.99              }
   5.100          }
   5.101 +
   5.102 +        @Override
   5.103 +        public String toString() {
   5.104 +            return wrappedToString(getClass(), clientFileObject);
   5.105 +        }
   5.106      }
   5.107  
   5.108      protected class WrappedJavaFileObject extends WrappedFileObject implements JavaFileObject {
   5.109 @@ -544,6 +573,11 @@
   5.110                  throw new ClientCodeException(e);
   5.111              }
   5.112          }
   5.113 +
   5.114 +        @Override
   5.115 +        public String toString() {
   5.116 +            return wrappedToString(getClass(), clientFileObject);
   5.117 +        }
   5.118      }
   5.119  
   5.120      protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> {
   5.121 @@ -565,6 +599,11 @@
   5.122                  throw new ClientCodeException(e);
   5.123              }
   5.124          }
   5.125 +
   5.126 +        @Override
   5.127 +        public String toString() {
   5.128 +            return wrappedToString(getClass(), clientDiagnosticListener);
   5.129 +        }
   5.130      }
   5.131  
   5.132      public class DiagnosticSourceUnwrapper implements Diagnostic<JavaFileObject> {
   5.133 @@ -610,6 +649,7 @@
   5.134              return d.getMessage(locale);
   5.135          }
   5.136  
   5.137 +        @Override
   5.138          public String toString() {
   5.139              return d.toString();
   5.140          }
   5.141 @@ -647,6 +687,11 @@
   5.142                  throw new ClientCodeException(e);
   5.143              }
   5.144          }
   5.145 +
   5.146 +        @Override
   5.147 +        public String toString() {
   5.148 +            return wrappedToString(getClass(), clientTaskListener);
   5.149 +        }
   5.150      }
   5.151  
   5.152      // </editor-fold>
     6.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Mar 01 12:23:33 2012 -0800
     6.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Mon Mar 05 17:04:48 2012 -0800
     6.3 @@ -1,5 +1,5 @@
     6.4  /*
     6.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     6.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     6.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.8   *
     6.9   * This code is free software; you can redistribute it and/or modify it
    6.10 @@ -44,6 +44,7 @@
    6.11  import com.sun.tools.javac.comp.*;
    6.12  import com.sun.tools.javac.file.JavacFileManager;
    6.13  import com.sun.tools.javac.main.*;
    6.14 +import com.sun.tools.javac.main.JavaCompiler;
    6.15  import com.sun.tools.javac.model.*;
    6.16  import com.sun.tools.javac.parser.Parser;
    6.17  import com.sun.tools.javac.parser.ParserFactory;
    6.18 @@ -51,7 +52,6 @@
    6.19  import com.sun.tools.javac.tree.JCTree.*;
    6.20  import com.sun.tools.javac.util.*;
    6.21  import com.sun.tools.javac.util.List;
    6.22 -import com.sun.tools.javac.main.JavaCompiler;
    6.23  
    6.24  /**
    6.25   * Provides access to functionality specific to the JDK Java Compiler, javac.
    6.26 @@ -64,18 +64,16 @@
    6.27   * @author Peter von der Ah&eacute;
    6.28   * @author Jonathan Gibbons
    6.29   */
    6.30 -public class JavacTaskImpl extends JavacTask {
    6.31 +public class JavacTaskImpl extends BasicJavacTask {
    6.32      private ClientCodeWrapper ccw;
    6.33      private Main compilerMain;
    6.34      private JavaCompiler compiler;
    6.35      private Locale locale;
    6.36      private String[] args;
    6.37      private String[] classNames;
    6.38 -    private Context context;
    6.39      private List<JavaFileObject> fileObjects;
    6.40      private Map<JavaFileObject, JCCompilationUnit> notYetEntered;
    6.41      private ListBuffer<Env<AttrContext>> genList;
    6.42 -    private TaskListener taskListener;
    6.43      private AtomicBoolean used = new AtomicBoolean();
    6.44      private Iterable<? extends Processor> processors;
    6.45  
    6.46 @@ -86,6 +84,7 @@
    6.47                  String[] classNames,
    6.48                  Context context,
    6.49                  List<JavaFileObject> fileObjects) {
    6.50 +        super(null, false);
    6.51          this.ccw = ClientCodeWrapper.instance(context);
    6.52          this.compilerMain = compilerMain;
    6.53          this.args = args;
    6.54 @@ -190,11 +189,7 @@
    6.55      }
    6.56  
    6.57      private void initContext() {
    6.58 -        context.put(JavacTaskImpl.class, this);
    6.59 -        if (context.get(TaskListener.class) != null)
    6.60 -            context.put(TaskListener.class, (TaskListener)null);
    6.61 -        if (taskListener != null)
    6.62 -            context.put(TaskListener.class, ccw.wrap(taskListener));
    6.63 +        context.put(JavacTask.class, this);
    6.64          //initialize compiler's default locale
    6.65          context.put(Locale.class, locale);
    6.66      }
    6.67 @@ -224,10 +219,6 @@
    6.68          return fm.getRegularFile(file);
    6.69      }
    6.70  
    6.71 -    public void setTaskListener(TaskListener taskListener) {
    6.72 -        this.taskListener = taskListener;
    6.73 -    }
    6.74 -
    6.75      /**
    6.76       * Parse the specified files returning a list of abstract syntax trees.
    6.77       *
     7.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Thu Mar 01 12:23:33 2012 -0800
     7.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Mon Mar 05 17:04:48 2012 -0800
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -26,7 +26,7 @@
    7.11  package com.sun.tools.javac.api;
    7.12  
    7.13  import java.io.IOException;
    7.14 -import java.util.Map;
    7.15 +
    7.16  import javax.annotation.processing.ProcessingEnvironment;
    7.17  import javax.lang.model.element.AnnotationMirror;
    7.18  import javax.lang.model.element.AnnotationValue;
    7.19 @@ -44,13 +44,14 @@
    7.20  import com.sun.source.tree.CompilationUnitTree;
    7.21  import com.sun.source.tree.Scope;
    7.22  import com.sun.source.tree.Tree;
    7.23 +import com.sun.source.util.JavacTask;
    7.24  import com.sun.source.util.SourcePositions;
    7.25  import com.sun.source.util.TreePath;
    7.26  import com.sun.source.util.Trees;
    7.27  import com.sun.tools.javac.code.Flags;
    7.28 +import com.sun.tools.javac.code.Symbol;
    7.29  import com.sun.tools.javac.code.Symbol.ClassSymbol;
    7.30  import com.sun.tools.javac.code.Symbol.TypeSymbol;
    7.31 -import com.sun.tools.javac.code.Symbol;
    7.32  import com.sun.tools.javac.code.Type.UnionClassType;
    7.33  import com.sun.tools.javac.comp.Attr;
    7.34  import com.sun.tools.javac.comp.AttrContext;
    7.35 @@ -61,8 +62,8 @@
    7.36  import com.sun.tools.javac.model.JavacElements;
    7.37  import com.sun.tools.javac.parser.EndPosTable;
    7.38  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    7.39 +import com.sun.tools.javac.tree.JCTree;
    7.40  import com.sun.tools.javac.tree.JCTree.*;
    7.41 -import com.sun.tools.javac.tree.JCTree;
    7.42  import com.sun.tools.javac.tree.TreeCopier;
    7.43  import com.sun.tools.javac.tree.TreeInfo;
    7.44  import com.sun.tools.javac.tree.TreeMaker;
    7.45 @@ -95,12 +96,14 @@
    7.46      private JavacElements elements;
    7.47      private JavacTaskImpl javacTaskImpl;
    7.48  
    7.49 +    // called reflectively from Trees.instance(CompilationTask task)
    7.50      public static JavacTrees instance(JavaCompiler.CompilationTask task) {
    7.51          if (!(task instanceof JavacTaskImpl))
    7.52              throw new IllegalArgumentException();
    7.53          return instance(((JavacTaskImpl)task).getContext());
    7.54      }
    7.55  
    7.56 +    // called reflectively from Trees.instance(ProcessingEnvironment env)
    7.57      public static JavacTrees instance(ProcessingEnvironment env) {
    7.58          if (!(env instanceof JavacProcessingEnvironment))
    7.59              throw new IllegalArgumentException();
    7.60 @@ -131,7 +134,10 @@
    7.61          resolve = Resolve.instance(context);
    7.62          treeMaker = TreeMaker.instance(context);
    7.63          memberEnter = MemberEnter.instance(context);
    7.64 -        javacTaskImpl = context.get(JavacTaskImpl.class);
    7.65 +
    7.66 +        JavacTask t = context.get(JavacTask.class);
    7.67 +        if (t instanceof JavacTaskImpl)
    7.68 +            javacTaskImpl = (JavacTaskImpl) t;
    7.69      }
    7.70  
    7.71      public SourcePositions getSourcePositions() {
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java	Mon Mar 05 17:04:48 2012 -0800
     8.3 @@ -0,0 +1,120 @@
     8.4 +/*
     8.5 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.  Oracle designates this
    8.11 + * particular file as subject to the "Classpath" exception as provided
    8.12 + * by Oracle in the LICENSE file that accompanied this code.
    8.13 + *
    8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.17 + * version 2 for more details (a copy is included in the LICENSE file that
    8.18 + * accompanied this code).
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License version
    8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.23 + *
    8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.25 + * or visit www.oracle.com if you need additional information or have any
    8.26 + * questions.
    8.27 + */
    8.28 +
    8.29 +package com.sun.tools.javac.api;
    8.30 +
    8.31 +import java.util.Arrays;
    8.32 +import java.util.Collection;
    8.33 +
    8.34 +import com.sun.source.util.TaskEvent;
    8.35 +import com.sun.source.util.TaskListener;
    8.36 +import com.sun.tools.javac.util.Context;
    8.37 +
    8.38 +/**
    8.39 + * TODO.
    8.40 + *
    8.41 + * <p><b>This is NOT part of any supported API.
    8.42 + * If you write code that depends on this, you do so at your own risk.
    8.43 + * This code and its internal interfaces are subject to change or
    8.44 + * deletion without notice.</b>
    8.45 + */
    8.46 +public class MultiTaskListener implements TaskListener {
    8.47 +    /** The context key for the MultiTaskListener. */
    8.48 +    public static final Context.Key<MultiTaskListener> taskListenerKey =
    8.49 +        new Context.Key<MultiTaskListener>();
    8.50 +
    8.51 +    /** Get the MultiTaskListener instance for this context. */
    8.52 +    public static MultiTaskListener instance(Context context) {
    8.53 +        MultiTaskListener instance = context.get(taskListenerKey);
    8.54 +        if (instance == null)
    8.55 +            instance = new MultiTaskListener(context);
    8.56 +        return instance;
    8.57 +    }
    8.58 +
    8.59 +    protected MultiTaskListener(Context context) {
    8.60 +        context.put(taskListenerKey, this);
    8.61 +        ccw = ClientCodeWrapper.instance(context);
    8.62 +    }
    8.63 +
    8.64 +    /**
    8.65 +     * The current set of registered listeners.
    8.66 +     * This is a mutable reference to an immutable array.
    8.67 +     */
    8.68 +    TaskListener[] listeners = { };
    8.69 +
    8.70 +    ClientCodeWrapper ccw;
    8.71 +
    8.72 +    public Collection<TaskListener> getTaskListeners() {
    8.73 +        return Arrays.asList(listeners);
    8.74 +    }
    8.75 +
    8.76 +    public boolean isEmpty() {
    8.77 +        return (listeners.length == 0);
    8.78 +    }
    8.79 +
    8.80 +    public void add(TaskListener listener) {
    8.81 +        for (TaskListener l: listeners) {
    8.82 +            if (ccw.unwrap(l) == listener)
    8.83 +                throw new IllegalStateException();
    8.84 +        }
    8.85 +        TaskListener[] newListeners = new TaskListener[listeners.length + 1];
    8.86 +        System.arraycopy(listeners, 0, newListeners, 0, listeners.length);
    8.87 +        newListeners[newListeners.length - 1] = ccw.wrap(listener);
    8.88 +        listeners = newListeners;
    8.89 +    }
    8.90 +
    8.91 +    public void remove(TaskListener listener) {
    8.92 +        for (int i = 0; i < listeners.length; i++) {
    8.93 +            if (ccw.unwrap(listeners[i]) == listener) {
    8.94 +                TaskListener[] newListeners = new TaskListener[listeners.length - 1];
    8.95 +                System.arraycopy(listeners, 0, newListeners, 0, i);
    8.96 +                System.arraycopy(listeners, i + 1, newListeners, i, newListeners.length - i);
    8.97 +                listeners = newListeners;
    8.98 +                break;
    8.99 +            }
   8.100 +        }
   8.101 +    }
   8.102 +
   8.103 +    @Override
   8.104 +    public void started(TaskEvent e) {
   8.105 +        // guard against listeners being updated by a listener
   8.106 +        TaskListener[] ll = this.listeners;
   8.107 +        for (TaskListener l: ll)
   8.108 +            l.started(e);
   8.109 +    }
   8.110 +
   8.111 +    @Override
   8.112 +    public void finished(TaskEvent e) {
   8.113 +        // guard against listeners being updated by a listener
   8.114 +        TaskListener[] ll = this.listeners;
   8.115 +        for (TaskListener l: ll)
   8.116 +            l.finished(e);
   8.117 +    }
   8.118 +
   8.119 +    @Override
   8.120 +    public String toString() {
   8.121 +        return Arrays.toString(listeners);
   8.122 +    }
   8.123 +}
     9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 01 12:23:33 2012 -0800
     9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Mar 05 17:04:48 2012 -0800
     9.3 @@ -1146,7 +1146,8 @@
     9.4  
     9.5      void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
     9.6          if (!resource.isErroneous() &&
     9.7 -                types.asSuper(resource, syms.autoCloseableType.tsym) != null) {
     9.8 +            types.asSuper(resource, syms.autoCloseableType.tsym) != null &&
     9.9 +            !types.isSameType(resource, syms.autoCloseableType)) { // Don't emit warning for AutoCloseable itself
    9.10              Symbol close = syms.noSymbol;
    9.11              boolean prevDeferDiags = log.deferDiagnostics;
    9.12              Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics;
    10.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Mar 01 12:23:33 2012 -0800
    10.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Mon Mar 05 17:04:48 2012 -0800
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -28,8 +28,8 @@
   10.11  import java.io.*;
   10.12  import java.util.HashMap;
   10.13  import java.util.HashSet;
   10.14 +import java.util.LinkedHashMap;
   10.15  import java.util.LinkedHashSet;
   10.16 -import java.util.LinkedHashMap;
   10.17  import java.util.Map;
   10.18  import java.util.MissingResourceException;
   10.19  import java.util.Queue;
   10.20 @@ -41,13 +41,13 @@
   10.21  
   10.22  import javax.annotation.processing.Processor;
   10.23  import javax.lang.model.SourceVersion;
   10.24 +import javax.tools.DiagnosticListener;
   10.25  import javax.tools.JavaFileManager;
   10.26  import javax.tools.JavaFileObject;
   10.27 -import javax.tools.DiagnosticListener;
   10.28 +import static javax.tools.StandardLocation.CLASS_OUTPUT;
   10.29  
   10.30  import com.sun.source.util.TaskEvent;
   10.31 -import com.sun.source.util.TaskListener;
   10.32 -
   10.33 +import com.sun.tools.javac.api.MultiTaskListener;
   10.34  import com.sun.tools.javac.code.*;
   10.35  import com.sun.tools.javac.code.Lint.LintCategory;
   10.36  import com.sun.tools.javac.code.Symbol.*;
   10.37 @@ -60,8 +60,6 @@
   10.38  import com.sun.tools.javac.tree.JCTree.*;
   10.39  import com.sun.tools.javac.util.*;
   10.40  import com.sun.tools.javac.util.Log.WriterKind;
   10.41 -
   10.42 -import static javax.tools.StandardLocation.CLASS_OUTPUT;
   10.43  import static com.sun.tools.javac.main.Option.*;
   10.44  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
   10.45  import static com.sun.tools.javac.util.ListBuffer.lb;
   10.46 @@ -289,9 +287,9 @@
   10.47       */
   10.48      protected ParserFactory parserFactory;
   10.49  
   10.50 -    /** Optional listener for progress events
   10.51 +    /** Broadcasting listener for progress events
   10.52       */
   10.53 -    protected TaskListener taskListener;
   10.54 +    protected MultiTaskListener taskListener;
   10.55  
   10.56      /**
   10.57       * Annotation processing may require and provide a new instance
   10.58 @@ -356,7 +354,7 @@
   10.59          lower = Lower.instance(context);
   10.60          annotate = Annotate.instance(context);
   10.61          types = Types.instance(context);
   10.62 -        taskListener = context.get(TaskListener.class);
   10.63 +        taskListener = MultiTaskListener.instance(context);
   10.64  
   10.65          reader.sourceCompleter = this;
   10.66  
   10.67 @@ -592,7 +590,7 @@
   10.68              if (verbose) {
   10.69                  log.printVerbose("parsing.started", filename);
   10.70              }
   10.71 -            if (taskListener != null) {
   10.72 +            if (!taskListener.isEmpty()) {
   10.73                  TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
   10.74                  taskListener.started(e);
   10.75              }
   10.76 @@ -605,7 +603,7 @@
   10.77  
   10.78          tree.sourcefile = filename;
   10.79  
   10.80 -        if (content != null && taskListener != null) {
   10.81 +        if (content != null && !taskListener.isEmpty()) {
   10.82              TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree);
   10.83              taskListener.finished(e);
   10.84          }
   10.85 @@ -751,14 +749,14 @@
   10.86              log.useSource(prev);
   10.87          }
   10.88  
   10.89 -        if (taskListener != null) {
   10.90 +        if (!taskListener.isEmpty()) {
   10.91              TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
   10.92              taskListener.started(e);
   10.93          }
   10.94  
   10.95          enter.complete(List.of(tree), c);
   10.96  
   10.97 -        if (taskListener != null) {
   10.98 +        if (!taskListener.isEmpty()) {
   10.99              TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
  10.100              taskListener.finished(e);
  10.101          }
  10.102 @@ -924,7 +922,7 @@
  10.103       */
  10.104      public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
  10.105          //enter symbols for all files
  10.106 -        if (taskListener != null) {
  10.107 +        if (!taskListener.isEmpty()) {
  10.108              for (JCCompilationUnit unit: roots) {
  10.109                  TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
  10.110                  taskListener.started(e);
  10.111 @@ -933,7 +931,7 @@
  10.112  
  10.113          enter.main(roots);
  10.114  
  10.115 -        if (taskListener != null) {
  10.116 +        if (!taskListener.isEmpty()) {
  10.117              for (JCCompilationUnit unit: roots) {
  10.118                  TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
  10.119                  taskListener.finished(e);
  10.120 @@ -1002,7 +1000,7 @@
  10.121                  reader.saveParameterNames = true;
  10.122                  keepComments = true;
  10.123                  genEndPos = true;
  10.124 -                if (taskListener != null)
  10.125 +                if (!taskListener.isEmpty())
  10.126                      taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
  10.127                  log.deferDiagnostics = true;
  10.128              } else { // free resources
  10.129 @@ -1017,7 +1015,7 @@
  10.130      }
  10.131  
  10.132      /**
  10.133 -     * Process any anotations found in the specifed compilation units.
  10.134 +     * Process any annotations found in the specified compilation units.
  10.135       * @param roots a list of compilation units
  10.136       * @return an instance of the compiler in which to complete the compilation
  10.137       */
  10.138 @@ -1176,7 +1174,7 @@
  10.139          if (verbose)
  10.140              log.printVerbose("checking.attribution", env.enclClass.sym);
  10.141  
  10.142 -        if (taskListener != null) {
  10.143 +        if (!taskListener.isEmpty()) {
  10.144              TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
  10.145              taskListener.started(e);
  10.146          }
  10.147 @@ -1259,7 +1257,7 @@
  10.148              }
  10.149          }
  10.150          finally {
  10.151 -            if (taskListener != null) {
  10.152 +            if (!taskListener.isEmpty()) {
  10.153                  TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
  10.154                  taskListener.finished(e);
  10.155              }
  10.156 @@ -1440,7 +1438,7 @@
  10.157                                 + " " + cdef.sym + "]");
  10.158              }
  10.159  
  10.160 -            if (taskListener != null) {
  10.161 +            if (!taskListener.isEmpty()) {
  10.162                  TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
  10.163                  taskListener.started(e);
  10.164              }
  10.165 @@ -1464,7 +1462,7 @@
  10.166                  log.useSource(prev);
  10.167              }
  10.168  
  10.169 -            if (taskListener != null) {
  10.170 +            if (!taskListener.isEmpty()) {
  10.171                  TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
  10.172                  taskListener.finished(e);
  10.173              }
    11.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Mar 01 12:23:33 2012 -0800
    11.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon Mar 05 17:04:48 2012 -0800
    11.3 @@ -1,5 +1,5 @@
    11.4  /*
    11.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
    11.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
    11.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.8   *
    11.9   * This code is free software; you can redistribute it and/or modify it
   11.10 @@ -25,34 +25,33 @@
   11.11  
   11.12  package com.sun.tools.javac.processing;
   11.13  
   11.14 -import java.lang.reflect.*;
   11.15 -import java.util.*;
   11.16 -import java.util.regex.*;
   11.17 -
   11.18 -import java.net.URL;
   11.19  import java.io.Closeable;
   11.20  import java.io.File;
   11.21  import java.io.PrintWriter;
   11.22 -import java.io.IOException;
   11.23  import java.io.StringWriter;
   11.24  import java.net.MalformedURLException;
   11.25 +import java.net.URL;
   11.26 +import java.util.*;
   11.27 +import java.util.regex.*;
   11.28  
   11.29  import javax.annotation.processing.*;
   11.30  import javax.lang.model.SourceVersion;
   11.31  import javax.lang.model.element.AnnotationMirror;
   11.32  import javax.lang.model.element.Element;
   11.33 +import javax.lang.model.element.PackageElement;
   11.34  import javax.lang.model.element.TypeElement;
   11.35 -import javax.lang.model.element.PackageElement;
   11.36  import javax.lang.model.util.*;
   11.37 +import javax.tools.DiagnosticListener;
   11.38  import javax.tools.JavaFileManager;
   11.39 +import javax.tools.JavaFileObject;
   11.40  import javax.tools.StandardJavaFileManager;
   11.41 -import javax.tools.JavaFileObject;
   11.42 -import javax.tools.DiagnosticListener;
   11.43 +import static javax.tools.StandardLocation.*;
   11.44  
   11.45 +import com.sun.source.util.JavacTask;
   11.46  import com.sun.source.util.TaskEvent;
   11.47 -import com.sun.source.util.TaskListener;
   11.48  import com.sun.tools.javac.api.JavacTaskImpl;
   11.49  import com.sun.tools.javac.api.JavacTrees;
   11.50 +import com.sun.tools.javac.api.MultiTaskListener;
   11.51  import com.sun.tools.javac.code.*;
   11.52  import com.sun.tools.javac.code.Symbol.*;
   11.53  import com.sun.tools.javac.file.FSInfo;
   11.54 @@ -71,19 +70,16 @@
   11.55  import com.sun.tools.javac.util.ClientCodeException;
   11.56  import com.sun.tools.javac.util.Context;
   11.57  import com.sun.tools.javac.util.Convert;
   11.58 -import com.sun.tools.javac.util.FatalError;
   11.59  import com.sun.tools.javac.util.JCDiagnostic;
   11.60 +import com.sun.tools.javac.util.JavacMessages;
   11.61  import com.sun.tools.javac.util.List;
   11.62  import com.sun.tools.javac.util.Log;
   11.63 -import com.sun.tools.javac.util.JavacMessages;
   11.64  import com.sun.tools.javac.util.Name;
   11.65  import com.sun.tools.javac.util.Names;
   11.66  import com.sun.tools.javac.util.Options;
   11.67 -
   11.68 -import static javax.tools.StandardLocation.*;
   11.69 +import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
   11.70 +import static com.sun.tools.javac.main.Option.*;
   11.71  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
   11.72 -import static com.sun.tools.javac.main.Option.*;
   11.73 -import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
   11.74  
   11.75  /**
   11.76   * Objects of this class hold and manage the state needed to support
   11.77 @@ -157,6 +153,8 @@
   11.78       */
   11.79      private JavacMessages messages;
   11.80  
   11.81 +    private MultiTaskListener taskListener;
   11.82 +
   11.83      private Context context;
   11.84  
   11.85      public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
   11.86 @@ -185,6 +183,7 @@
   11.87          processorOptions = initProcessorOptions(context);
   11.88          unmatchedProcessorOptions = initUnmatchedProcessorOptions();
   11.89          messages = JavacMessages.instance(context);
   11.90 +        taskListener = MultiTaskListener.instance(context);
   11.91          initProcessorIterator(context, processors);
   11.92      }
   11.93  
   11.94 @@ -976,8 +975,7 @@
   11.95          void run(boolean lastRound, boolean errorStatus) {
   11.96              printRoundInfo(lastRound);
   11.97  
   11.98 -            TaskListener taskListener = context.get(TaskListener.class);
   11.99 -            if (taskListener != null)
  11.100 +            if (!taskListener.isEmpty())
  11.101                  taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
  11.102  
  11.103              try {
  11.104 @@ -993,7 +991,7 @@
  11.105                      discoverAndRunProcs(context, annotationsPresent, topLevelClasses, packageInfoFiles);
  11.106                  }
  11.107              } finally {
  11.108 -                if (taskListener != null)
  11.109 +                if (!taskListener.isEmpty())
  11.110                      taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
  11.111              }
  11.112  
  11.113 @@ -1051,9 +1049,9 @@
  11.114              if (dl != null)
  11.115                  next.put(DiagnosticListener.class, dl);
  11.116  
  11.117 -            TaskListener tl = context.get(TaskListener.class);
  11.118 -            if (tl != null)
  11.119 -                next.put(TaskListener.class, tl);
  11.120 +            MultiTaskListener mtl = context.get(MultiTaskListener.taskListenerKey);
  11.121 +            if (mtl != null)
  11.122 +                next.put(MultiTaskListener.taskListenerKey, mtl);
  11.123  
  11.124              FSInfo fsInfo = context.get(FSInfo.class);
  11.125              if (fsInfo != null)
  11.126 @@ -1086,9 +1084,9 @@
  11.127              elementUtils.setContext(next);
  11.128              typeUtils.setContext(next);
  11.129  
  11.130 -            JavacTaskImpl task = context.get(JavacTaskImpl.class);
  11.131 +            JavacTaskImpl task = (JavacTaskImpl) context.get(JavacTask.class);
  11.132              if (task != null) {
  11.133 -                next.put(JavacTaskImpl.class, task);
  11.134 +                next.put(JavacTask.class, task);
  11.135                  task.updateContext(next);
  11.136              }
  11.137  
  11.138 @@ -1110,8 +1108,6 @@
  11.139                                       List<JCCompilationUnit> roots,
  11.140                                       List<ClassSymbol> classSymbols,
  11.141                                       Iterable<? extends PackageSymbol> pckSymbols) {
  11.142 -
  11.143 -        TaskListener taskListener = context.get(TaskListener.class);
  11.144          log = Log.instance(context);
  11.145  
  11.146          Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
  11.147 @@ -1182,7 +1178,7 @@
  11.148          // Free resources
  11.149          this.close();
  11.150  
  11.151 -        if (taskListener != null)
  11.152 +        if (!taskListener.isEmpty())
  11.153              taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
  11.154  
  11.155          if (errorStatus) {
    12.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java	Thu Mar 01 12:23:33 2012 -0800
    12.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Mon Mar 05 17:04:48 2012 -0800
    12.3 @@ -1,5 +1,5 @@
    12.4  /*
    12.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
    12.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    12.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.8   *
    12.9   * This code is free software; you can redistribute it and/or modify it
   12.10 @@ -47,108 +47,127 @@
   12.11          return instance;
   12.12      }
   12.13  
   12.14 -    public final Name slash;
   12.15 +    // operators and punctuation
   12.16 +    public final Name asterisk;
   12.17 +    public final Name comma;
   12.18 +    public final Name empty;
   12.19      public final Name hyphen;
   12.20 -    public final Name T;
   12.21 -    public final Name slashequals;
   12.22 -    public final Name deprecated;
   12.23 -    public final Name init;
   12.24 -    public final Name clinit;
   12.25 -    public final Name error;
   12.26 -    public final Name any;
   12.27 -    public final Name empty;
   12.28      public final Name one;
   12.29      public final Name period;
   12.30 -    public final Name comma;
   12.31      public final Name semicolon;
   12.32 -    public final Name asterisk;
   12.33 +    public final Name slash;
   12.34 +    public final Name slashequals;
   12.35 +
   12.36 +    // keywords
   12.37 +    public final Name _class;
   12.38 +    public final Name _default;
   12.39 +    public final Name _super;
   12.40      public final Name _this;
   12.41 -    public final Name _super;
   12.42 -    public final Name _default;
   12.43 -    public final Name _class;
   12.44 -    public final Name java_lang;
   12.45 -    public final Name java_lang_Object;
   12.46 +
   12.47 +    // field and method names
   12.48 +    public final Name _name;
   12.49 +    public final Name addSuppressed;
   12.50 +    public final Name any;
   12.51 +    public final Name append;
   12.52 +    public final Name clinit;
   12.53 +    public final Name clone;
   12.54 +    public final Name close;
   12.55 +    public final Name compareTo;
   12.56 +    public final Name desiredAssertionStatus;
   12.57 +    public final Name equals;
   12.58 +    public final Name error;
   12.59 +    public final Name family;
   12.60 +    public final Name finalize;
   12.61 +    public final Name forName;
   12.62 +    public final Name getClass;
   12.63 +    public final Name getClassLoader;
   12.64 +    public final Name getComponentType;
   12.65 +    public final Name getDeclaringClass;
   12.66 +    public final Name getMessage;
   12.67 +    public final Name hasNext;
   12.68 +    public final Name hashCode;
   12.69 +    public final Name init;
   12.70 +    public final Name initCause;
   12.71 +    public final Name iterator;
   12.72 +    public final Name length;
   12.73 +    public final Name next;
   12.74 +    public final Name ordinal;
   12.75 +    public final Name serialVersionUID;
   12.76 +    public final Name toString;
   12.77 +    public final Name value;
   12.78 +    public final Name valueOf;
   12.79 +    public final Name values;
   12.80 +
   12.81 +    // class names
   12.82 +    public final Name java_io_Serializable;
   12.83 +    public final Name java_lang_AutoCloseable;
   12.84      public final Name java_lang_Class;
   12.85      public final Name java_lang_Cloneable;
   12.86 -    public final Name java_io_Serializable;
   12.87 -    public final Name serialVersionUID;
   12.88      public final Name java_lang_Enum;
   12.89 +    public final Name java_lang_Object;
   12.90      public final Name java_lang_invoke_MethodHandle;
   12.91 -    public final Name package_info;
   12.92 +
   12.93 +    // names of builtin classes
   12.94 +    public final Name Array;
   12.95 +    public final Name Bound;
   12.96 +    public final Name Method;
   12.97 +
   12.98 +    // package names
   12.99 +    public final Name java_lang;
  12.100 +
  12.101 +    // attribute names
  12.102 +    public final Name Annotation;
  12.103 +    public final Name AnnotationDefault;
  12.104 +    public final Name Bridge;
  12.105 +    public final Name CharacterRangeTable;
  12.106 +    public final Name Code;
  12.107 +    public final Name CompilationID;
  12.108      public final Name ConstantValue;
  12.109 +    public final Name Deprecated;
  12.110 +    public final Name EnclosingMethod;
  12.111 +    public final Name Enum;
  12.112 +    public final Name Exceptions;
  12.113 +    public final Name InnerClasses;
  12.114      public final Name LineNumberTable;
  12.115      public final Name LocalVariableTable;
  12.116      public final Name LocalVariableTypeTable;
  12.117 -    public final Name CharacterRangeTable;
  12.118 +    public final Name RuntimeInvisibleAnnotations;
  12.119 +    public final Name RuntimeInvisibleParameterAnnotations;
  12.120 +    public final Name RuntimeInvisibleTypeAnnotations;
  12.121 +    public final Name RuntimeVisibleAnnotations;
  12.122 +    public final Name RuntimeVisibleParameterAnnotations;
  12.123 +    public final Name RuntimeVisibleTypeAnnotations;
  12.124 +    public final Name Signature;
  12.125 +    public final Name SourceFile;
  12.126 +    public final Name SourceID;
  12.127      public final Name StackMap;
  12.128      public final Name StackMapTable;
  12.129 -    public final Name SourceID;
  12.130 -    public final Name CompilationID;
  12.131 -    public final Name Code;
  12.132 -    public final Name Exceptions;
  12.133 -    public final Name SourceFile;
  12.134 -    public final Name InnerClasses;
  12.135      public final Name Synthetic;
  12.136 -    public final Name Bridge;
  12.137 -    public final Name Deprecated;
  12.138 -    public final Name Enum;
  12.139 -    public final Name _name;
  12.140 -    public final Name Signature;
  12.141 +    public final Name Value;
  12.142      public final Name Varargs;
  12.143 -    public final Name Annotation;
  12.144 -    public final Name RuntimeVisibleAnnotations;
  12.145 -    public final Name RuntimeInvisibleAnnotations;
  12.146 -    public final Name RuntimeVisibleTypeAnnotations;
  12.147 -    public final Name RuntimeInvisibleTypeAnnotations;
  12.148 -    public final Name RuntimeVisibleParameterAnnotations;
  12.149 -    public final Name RuntimeInvisibleParameterAnnotations;
  12.150 -    public final Name Value;
  12.151 -    public final Name EnclosingMethod;
  12.152 -    public final Name desiredAssertionStatus;
  12.153 -    public final Name append;
  12.154 -    public final Name family;
  12.155 -    public final Name forName;
  12.156 -    public final Name toString;
  12.157 -    public final Name length;
  12.158 -    public final Name valueOf;
  12.159 -    public final Name value;
  12.160 -    public final Name getMessage;
  12.161 -    public final Name getClass;
  12.162 +
  12.163 +    // members of java.lang.annotation.ElementType
  12.164 +    public final Name ANNOTATION_TYPE;
  12.165 +    public final Name CONSTRUCTOR;
  12.166 +    public final Name FIELD;
  12.167 +    public final Name LOCAL_VARIABLE;
  12.168 +    public final Name METHOD;
  12.169 +    public final Name PACKAGE;
  12.170 +    public final Name PARAMETER;
  12.171      public final Name TYPE;
  12.172 +    public final Name TYPE_PARAMETER;
  12.173      public final Name TYPE_USE;
  12.174 -    public final Name TYPE_PARAMETER;
  12.175 -    public final Name FIELD;
  12.176 -    public final Name METHOD;
  12.177 -    public final Name PARAMETER;
  12.178 -    public final Name CONSTRUCTOR;
  12.179 -    public final Name LOCAL_VARIABLE;
  12.180 -    public final Name ANNOTATION_TYPE;
  12.181 -    public final Name PACKAGE;
  12.182 -    public final Name SOURCE;
  12.183 +
  12.184 +    // members of java.lang.annotation.RetentionPolicy
  12.185      public final Name CLASS;
  12.186      public final Name RUNTIME;
  12.187 -    public final Name Array;
  12.188 -    public final Name Method;
  12.189 -    public final Name Bound;
  12.190 -    public final Name clone;
  12.191 -    public final Name getComponentType;
  12.192 -    public final Name getClassLoader;
  12.193 -    public final Name initCause;
  12.194 -    public final Name values;
  12.195 -    public final Name iterator;
  12.196 -    public final Name hasNext;
  12.197 -    public final Name next;
  12.198 -    public final Name AnnotationDefault;
  12.199 -    public final Name ordinal;
  12.200 -    public final Name equals;
  12.201 -    public final Name hashCode;
  12.202 -    public final Name compareTo;
  12.203 -    public final Name getDeclaringClass;
  12.204 +    public final Name SOURCE;
  12.205 +
  12.206 +    // other identifiers
  12.207 +    public final Name T;
  12.208 +    public final Name deprecated;
  12.209      public final Name ex;
  12.210 -    public final Name finalize;
  12.211 -    public final Name java_lang_AutoCloseable;
  12.212 -    public final Name close;
  12.213 -    public final Name addSuppressed;
  12.214 +    public final Name package_info;
  12.215  
  12.216      public final Name.Table table;
  12.217  
  12.218 @@ -156,116 +175,127 @@
  12.219          Options options = Options.instance(context);
  12.220          table = createTable(options);
  12.221  
  12.222 -        slash = fromString("/");
  12.223 +        // operators and punctuation
  12.224 +        asterisk = fromString("*");
  12.225 +        comma = fromString(",");
  12.226 +        empty = fromString("");
  12.227          hyphen = fromString("-");
  12.228 -        T = fromString("T");
  12.229 -        slashequals = fromString("/=");
  12.230 -        deprecated = fromString("deprecated");
  12.231 -
  12.232 -        init = fromString("<init>");
  12.233 -        clinit = fromString("<clinit>");
  12.234 -        error = fromString("<error>");
  12.235 -        any = fromString("<any>");
  12.236 -        empty = fromString("");
  12.237          one = fromString("1");
  12.238          period = fromString(".");
  12.239 -        comma = fromString(",");
  12.240          semicolon = fromString(";");
  12.241 -        asterisk = fromString("*");
  12.242 +        slash = fromString("/");
  12.243 +        slashequals = fromString("/=");
  12.244 +
  12.245 +        // keywords
  12.246 +        _class = fromString("class");
  12.247 +        _default = fromString("default");
  12.248 +        _super = fromString("super");
  12.249          _this = fromString("this");
  12.250 -        _super = fromString("super");
  12.251 -        _default = fromString("default");
  12.252  
  12.253 -        _class = fromString("class");
  12.254 -        java_lang = fromString("java.lang");
  12.255 -        java_lang_Object = fromString("java.lang.Object");
  12.256 +        // field and method names
  12.257 +        _name = fromString("name");
  12.258 +        addSuppressed = fromString("addSuppressed");
  12.259 +        any = fromString("<any>");
  12.260 +        append = fromString("append");
  12.261 +        clinit = fromString("<clinit>");
  12.262 +        clone = fromString("clone");
  12.263 +        close = fromString("close");
  12.264 +        compareTo = fromString("compareTo");
  12.265 +        desiredAssertionStatus = fromString("desiredAssertionStatus");
  12.266 +        equals = fromString("equals");
  12.267 +        error = fromString("<error>");
  12.268 +        family = fromString("family");
  12.269 +        finalize = fromString("finalize");
  12.270 +        forName = fromString("forName");
  12.271 +        getClass = fromString("getClass");
  12.272 +        getClassLoader = fromString("getClassLoader");
  12.273 +        getComponentType = fromString("getComponentType");
  12.274 +        getDeclaringClass = fromString("getDeclaringClass");
  12.275 +        getMessage = fromString("getMessage");
  12.276 +        hasNext = fromString("hasNext");
  12.277 +        hashCode = fromString("hashCode");
  12.278 +        init = fromString("<init>");
  12.279 +        initCause = fromString("initCause");
  12.280 +        iterator = fromString("iterator");
  12.281 +        length = fromString("length");
  12.282 +        next = fromString("next");
  12.283 +        ordinal = fromString("ordinal");
  12.284 +        serialVersionUID = fromString("serialVersionUID");
  12.285 +        toString = fromString("toString");
  12.286 +        value = fromString("value");
  12.287 +        valueOf = fromString("valueOf");
  12.288 +        values = fromString("values");
  12.289 +
  12.290 +        // class names
  12.291 +        java_io_Serializable = fromString("java.io.Serializable");
  12.292 +        java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
  12.293          java_lang_Class = fromString("java.lang.Class");
  12.294          java_lang_Cloneable = fromString("java.lang.Cloneable");
  12.295 -        java_io_Serializable = fromString("java.io.Serializable");
  12.296          java_lang_Enum = fromString("java.lang.Enum");
  12.297 +        java_lang_Object = fromString("java.lang.Object");
  12.298          java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle");
  12.299 -        package_info = fromString("package-info");
  12.300 -        serialVersionUID = fromString("serialVersionUID");
  12.301 +
  12.302 +        // names of builtin classes
  12.303 +        Array = fromString("Array");
  12.304 +        Bound = fromString("Bound");
  12.305 +        Method = fromString("Method");
  12.306 +
  12.307 +        // package names
  12.308 +        java_lang = fromString("java.lang");
  12.309 +
  12.310 +        // attribute names
  12.311 +        Annotation = fromString("Annotation");
  12.312 +        AnnotationDefault = fromString("AnnotationDefault");
  12.313 +        Bridge = fromString("Bridge");
  12.314 +        CharacterRangeTable = fromString("CharacterRangeTable");
  12.315 +        Code = fromString("Code");
  12.316 +        CompilationID = fromString("CompilationID");
  12.317          ConstantValue = fromString("ConstantValue");
  12.318 +        Deprecated = fromString("Deprecated");
  12.319 +        EnclosingMethod = fromString("EnclosingMethod");
  12.320 +        Enum = fromString("Enum");
  12.321 +        Exceptions = fromString("Exceptions");
  12.322 +        InnerClasses = fromString("InnerClasses");
  12.323          LineNumberTable = fromString("LineNumberTable");
  12.324          LocalVariableTable = fromString("LocalVariableTable");
  12.325          LocalVariableTypeTable = fromString("LocalVariableTypeTable");
  12.326 -        CharacterRangeTable = fromString("CharacterRangeTable");
  12.327 +        RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
  12.328 +        RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
  12.329 +        RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
  12.330 +        RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
  12.331 +        RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
  12.332 +        RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
  12.333 +        Signature = fromString("Signature");
  12.334 +        SourceFile = fromString("SourceFile");
  12.335 +        SourceID = fromString("SourceID");
  12.336          StackMap = fromString("StackMap");
  12.337          StackMapTable = fromString("StackMapTable");
  12.338 -        SourceID = fromString("SourceID");
  12.339 -        CompilationID = fromString("CompilationID");
  12.340 -        Code = fromString("Code");
  12.341 -        Exceptions = fromString("Exceptions");
  12.342 -        SourceFile = fromString("SourceFile");
  12.343 -        InnerClasses = fromString("InnerClasses");
  12.344          Synthetic = fromString("Synthetic");
  12.345 -        Bridge = fromString("Bridge");
  12.346 -        Deprecated = fromString("Deprecated");
  12.347 -        Enum = fromString("Enum");
  12.348 -        _name = fromString("name");
  12.349 -        Signature = fromString("Signature");
  12.350 +        Value = fromString("Value");
  12.351          Varargs = fromString("Varargs");
  12.352 -        Annotation = fromString("Annotation");
  12.353 -        RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
  12.354 -        RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
  12.355 -        RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
  12.356 -        RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
  12.357 -        RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
  12.358 -        RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
  12.359 -        Value = fromString("Value");
  12.360 -        EnclosingMethod = fromString("EnclosingMethod");
  12.361  
  12.362 -        desiredAssertionStatus = fromString("desiredAssertionStatus");
  12.363 +        // members of java.lang.annotation.ElementType
  12.364 +        ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
  12.365 +        CONSTRUCTOR = fromString("CONSTRUCTOR");
  12.366 +        FIELD = fromString("FIELD");
  12.367 +        LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
  12.368 +        METHOD = fromString("METHOD");
  12.369 +        PACKAGE = fromString("PACKAGE");
  12.370 +        PARAMETER = fromString("PARAMETER");
  12.371 +        TYPE = fromString("TYPE");
  12.372 +        TYPE_PARAMETER = fromString("TYPE_PARAMETER");
  12.373 +        TYPE_USE = fromString("TYPE_USE");
  12.374  
  12.375 -        append = fromString("append");
  12.376 -        family = fromString("family");
  12.377 -        forName = fromString("forName");
  12.378 -        toString = fromString("toString");
  12.379 -        length = fromString("length");
  12.380 -        valueOf = fromString("valueOf");
  12.381 -        value = fromString("value");
  12.382 -        getMessage = fromString("getMessage");
  12.383 -        getClass = fromString("getClass");
  12.384 -
  12.385 -        TYPE = fromString("TYPE");
  12.386 -        TYPE_USE = fromString("TYPE_USE");
  12.387 -        TYPE_PARAMETER = fromString("TYPE_PARAMETER");
  12.388 -        FIELD = fromString("FIELD");
  12.389 -        METHOD = fromString("METHOD");
  12.390 -        PARAMETER = fromString("PARAMETER");
  12.391 -        CONSTRUCTOR = fromString("CONSTRUCTOR");
  12.392 -        LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
  12.393 -        ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
  12.394 -        PACKAGE = fromString("PACKAGE");
  12.395 -
  12.396 -        SOURCE = fromString("SOURCE");
  12.397 +        // members of java.lang.annotation.RetentionPolicy
  12.398          CLASS = fromString("CLASS");
  12.399          RUNTIME = fromString("RUNTIME");
  12.400 +        SOURCE = fromString("SOURCE");
  12.401  
  12.402 -        Array = fromString("Array");
  12.403 -        Method = fromString("Method");
  12.404 -        Bound = fromString("Bound");
  12.405 -        clone = fromString("clone");
  12.406 -        getComponentType = fromString("getComponentType");
  12.407 -        getClassLoader = fromString("getClassLoader");
  12.408 -        initCause = fromString("initCause");
  12.409 -        values = fromString("values");
  12.410 -        iterator = fromString("iterator");
  12.411 -        hasNext = fromString("hasNext");
  12.412 -        next = fromString("next");
  12.413 -        AnnotationDefault = fromString("AnnotationDefault");
  12.414 -        ordinal = fromString("ordinal");
  12.415 -        equals = fromString("equals");
  12.416 -        hashCode = fromString("hashCode");
  12.417 -        compareTo = fromString("compareTo");
  12.418 -        getDeclaringClass = fromString("getDeclaringClass");
  12.419 +        // other identifiers
  12.420 +        T = fromString("T");
  12.421 +        deprecated = fromString("deprecated");
  12.422          ex = fromString("ex");
  12.423 -        finalize = fromString("finalize");
  12.424 -
  12.425 -        java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
  12.426 -        close = fromString("close");
  12.427 -        addSuppressed = fromString("addSuppressed");
  12.428 +        package_info = fromString("package-info");
  12.429      }
  12.430  
  12.431      protected Name.Table createTable(Options options) {
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java	Mon Mar 05 17:04:48 2012 -0800
    13.3 @@ -0,0 +1,351 @@
    13.4 +/*
    13.5 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.23 + * or visit www.oracle.com if you need additional information or have any
   13.24 + * questions.
   13.25 + */
   13.26 +
   13.27 +/*
   13.28 + * @test
   13.29 + * @bug     7093891
   13.30 + * @summary support multiple task listeners
   13.31 + */
   13.32 +
   13.33 +import java.io.File;
   13.34 +import java.io.IOException;
   13.35 +import java.io.PrintWriter;
   13.36 +import java.io.StringWriter;
   13.37 +import java.net.URI;
   13.38 +import java.util.ArrayList;
   13.39 +import java.util.Arrays;
   13.40 +import java.util.EnumMap;
   13.41 +import java.util.List;
   13.42 +import java.util.Set;
   13.43 +
   13.44 +import javax.annotation.processing.AbstractProcessor;
   13.45 +import javax.annotation.processing.RoundEnvironment;
   13.46 +import javax.annotation.processing.SupportedAnnotationTypes;
   13.47 +import javax.lang.model.element.TypeElement;
   13.48 +import javax.tools.JavaFileObject;
   13.49 +import javax.tools.SimpleJavaFileObject;
   13.50 +import javax.tools.StandardJavaFileManager;
   13.51 +import javax.tools.StandardLocation;
   13.52 +import javax.tools.ToolProvider;
   13.53 +
   13.54 +import com.sun.source.util.JavacTask;
   13.55 +import com.sun.source.util.TaskEvent;
   13.56 +import com.sun.source.util.TaskListener;
   13.57 +import com.sun.tools.javac.api.JavacTool;
   13.58 +
   13.59 +public class TestSimpleAddRemove {
   13.60 +    enum AddKind {
   13.61 +        SET_IN_TASK,
   13.62 +        ADD_IN_TASK,
   13.63 +        ADD_IN_PROCESSOR,
   13.64 +        ADD_IN_LISTENER;
   13.65 +    }
   13.66 +
   13.67 +    enum RemoveKind {
   13.68 +        REMOVE_IN_TASK,
   13.69 +        REMOVE_IN_PROCESSOR,
   13.70 +        REMOVE_IN_LISTENER,
   13.71 +    }
   13.72 +
   13.73 +    enum CompileKind {
   13.74 +        CALL {
   13.75 +            void run(JavacTask t) {
   13.76 +                if (!t.call()) throw new Error("compilation failed");
   13.77 +            }
   13.78 +        },
   13.79 +        GENERATE {
   13.80 +            void run(JavacTask t) throws IOException {
   13.81 +                t.generate();
   13.82 +            }
   13.83 +        };
   13.84 +        abstract void run(JavacTask t) throws IOException;
   13.85 +    }
   13.86 +
   13.87 +    static class EventKindCounter extends EnumMap<TaskEvent.Kind, EventKindCounter.Count> {
   13.88 +        static class Count {
   13.89 +            int started;
   13.90 +            int finished;
   13.91 +
   13.92 +            @Override
   13.93 +            public String toString() {
   13.94 +                return started + ":" + finished;
   13.95 +            }
   13.96 +        }
   13.97 +
   13.98 +        EventKindCounter() {
   13.99 +            super(TaskEvent.Kind.class);
  13.100 +        }
  13.101 +
  13.102 +        void inc(TaskEvent.Kind k, boolean started) {
  13.103 +            Count c = get(k);
  13.104 +            if (c == null)
  13.105 +                put(k, c = new Count());
  13.106 +
  13.107 +            if (started)
  13.108 +                c.started++;
  13.109 +            else
  13.110 +                c.finished++;
  13.111 +        }
  13.112 +    }
  13.113 +
  13.114 +    static class TestListener implements TaskListener {
  13.115 +        EventKindCounter counter;
  13.116 +
  13.117 +        TestListener(EventKindCounter c) {
  13.118 +            counter = c;
  13.119 +        }
  13.120 +
  13.121 +        public void started(TaskEvent e) {
  13.122 +            counter.inc(e.getKind(), true);
  13.123 +        }
  13.124 +
  13.125 +        public void finished(TaskEvent e) {
  13.126 +            counter.inc(e.getKind(), false);
  13.127 +        }
  13.128 +    }
  13.129 +
  13.130 +    static void addInListener(final JavacTask task, final TaskEvent.Kind kind, final TaskListener listener) {
  13.131 +        task.addTaskListener(new TaskListener() {
  13.132 +            public void started(TaskEvent e) {
  13.133 +                if (e.getKind() == kind) {
  13.134 +                    task.addTaskListener(listener);
  13.135 +                    task.removeTaskListener(this);
  13.136 +                }
  13.137 +            }
  13.138 +
  13.139 +            public void finished(TaskEvent e) { }
  13.140 +        });
  13.141 +    }
  13.142 +
  13.143 +    static void removeInListener(final JavacTask task, final TaskEvent.Kind kind, final TaskListener listener) {
  13.144 +        task.addTaskListener(new TaskListener() {
  13.145 +            public void started(TaskEvent e) {
  13.146 +                if (e.getKind() == kind) {
  13.147 +                    task.removeTaskListener(listener);
  13.148 +                    task.removeTaskListener(this);
  13.149 +                }
  13.150 +            }
  13.151 +
  13.152 +            public void finished(TaskEvent e) { }
  13.153 +        });
  13.154 +    }
  13.155 +
  13.156 +    @SupportedAnnotationTypes("*")
  13.157 +    class TestProcessor extends AbstractProcessor {
  13.158 +        AddKind ak;
  13.159 +        RemoveKind rk;
  13.160 +        TaskListener listener;
  13.161 +
  13.162 +        TestProcessor(AddKind ak, RemoveKind rk, TaskListener listener) {
  13.163 +            this.ak = ak;
  13.164 +            this.rk = rk;
  13.165 +            this.listener = listener;
  13.166 +        }
  13.167 +
  13.168 +        int round = 0;
  13.169 +
  13.170 +        @Override
  13.171 +        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  13.172 +//            System.err.println("TestProcessor.process " + roundEnv);
  13.173 +            JavacTask task = JavacTask.instance(processingEnv);
  13.174 +            if (++round == 1) {
  13.175 +                switch (ak) {
  13.176 +                    case ADD_IN_PROCESSOR:
  13.177 +                        task.addTaskListener(listener);
  13.178 +                        break;
  13.179 +                    case ADD_IN_LISTENER:
  13.180 +                        addInListener(task, TaskEvent.Kind.ANALYZE, listener);
  13.181 +                        break;
  13.182 +                }
  13.183 +            } else if (roundEnv.processingOver()) {
  13.184 +                switch (rk) {
  13.185 +                    case REMOVE_IN_PROCESSOR:
  13.186 +                        task.removeTaskListener(listener);
  13.187 +                        break;
  13.188 +                    case REMOVE_IN_LISTENER:
  13.189 +                        removeInListener(task, TaskEvent.Kind.GENERATE, listener);
  13.190 +                        break;
  13.191 +                }
  13.192 +            }
  13.193 +            return true;
  13.194 +        }
  13.195 +    }
  13.196 +
  13.197 +    static class TestSource extends SimpleJavaFileObject {
  13.198 +        public TestSource() {
  13.199 +            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
  13.200 +        }
  13.201 +
  13.202 +        @Override
  13.203 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  13.204 +            return "class Test { }";
  13.205 +        }
  13.206 +    }
  13.207 +
  13.208 +    public static void main(String... args) throws Exception {
  13.209 +        new TestSimpleAddRemove().run();
  13.210 +    }
  13.211 +
  13.212 +    JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();
  13.213 +    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
  13.214 +
  13.215 +    void run() throws Exception {
  13.216 +        for (CompileKind ck: CompileKind.values()) {
  13.217 +            for (AddKind ak: AddKind.values()) {
  13.218 +                for (RemoveKind rk: RemoveKind.values()) {
  13.219 +                    test(ck, ak, rk);
  13.220 +                }
  13.221 +            }
  13.222 +        }
  13.223 +        if (errors > 0)
  13.224 +            throw new Exception(errors + " errors occurred");
  13.225 +    }
  13.226 +
  13.227 +    void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException {
  13.228 +        System.err.println("Test: " + ck + " " + ak + " " + rk);
  13.229 +
  13.230 +        File tmpDir = new File(ck + "-" + ak + "-" + rk);
  13.231 +        tmpDir.mkdirs();
  13.232 +        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir));
  13.233 +
  13.234 +        List<String> options = new ArrayList<String>();
  13.235 +        Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource());
  13.236 +        StringWriter sw = new StringWriter();
  13.237 +        PrintWriter pw = new PrintWriter(sw);
  13.238 +        JavacTask task = tool.getTask(pw, fm, null, options, null, files);
  13.239 +
  13.240 +        EventKindCounter ec = new EventKindCounter();
  13.241 +        TaskListener listener = new TestListener(ec);
  13.242 +        boolean needProcessor = false;
  13.243 +
  13.244 +        switch (ak) {
  13.245 +            case SET_IN_TASK:
  13.246 +                task.setTaskListener(listener);
  13.247 +                break;
  13.248 +            case ADD_IN_TASK:
  13.249 +                task.addTaskListener(listener);
  13.250 +                break;
  13.251 +            case ADD_IN_PROCESSOR:
  13.252 +            case ADD_IN_LISTENER:
  13.253 +                needProcessor = true;
  13.254 +        }
  13.255 +
  13.256 +        switch (rk) {
  13.257 +            case REMOVE_IN_TASK:
  13.258 +                task.removeTaskListener(listener);
  13.259 +                break;
  13.260 +            case REMOVE_IN_PROCESSOR:
  13.261 +            case REMOVE_IN_LISTENER:
  13.262 +                needProcessor = true;
  13.263 +        }
  13.264 +
  13.265 +        if (needProcessor)
  13.266 +            task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener)));
  13.267 +
  13.268 +        ck.run(task);
  13.269 +        System.err.println(ec);
  13.270 +
  13.271 +        check(ck, ak, rk, ec);
  13.272 +
  13.273 +        System.err.println();
  13.274 +    }
  13.275 +
  13.276 +    void check(CompileKind ck, AddKind ak, RemoveKind rk, EventKindCounter ec) {
  13.277 +        // All results should be independent of ck, so we can ignore that
  13.278 +
  13.279 +        // Quick way to compare expected values of ec, by comparing ec.toString()
  13.280 +        String expect = ec.toString();
  13.281 +        String found;
  13.282 +
  13.283 +        switch (ak) {
  13.284 +            // Add/set in task should record all events until the listener is removed
  13.285 +            case SET_IN_TASK:
  13.286 +            case ADD_IN_TASK:
  13.287 +                switch (rk) {
  13.288 +                    case REMOVE_IN_TASK:
  13.289 +                        // Remove will succeed, meaning no events will be recorded
  13.290 +                        found = "{}";
  13.291 +                        break;
  13.292 +                    case REMOVE_IN_PROCESSOR:
  13.293 +                        found = "{PARSE=1:1, ENTER=2:2, ANNOTATION_PROCESSING=1:0, ANNOTATION_PROCESSING_ROUND=2:1}";
  13.294 +                        break;
  13.295 +                    case REMOVE_IN_LISTENER:
  13.296 +                        found = "{PARSE=1:1, ENTER=3:3, ANALYZE=1:1, GENERATE=1:0, ANNOTATION_PROCESSING=1:1, ANNOTATION_PROCESSING_ROUND=2:2}";
  13.297 +                        break;
  13.298 +                    default:
  13.299 +                        throw new IllegalStateException();
  13.300 +                }
  13.301 +                break;
  13.302 +
  13.303 +            // "Add in processor" should skip initial PARSE/ENTER events
  13.304 +            case ADD_IN_PROCESSOR:
  13.305 +                switch (rk) {
  13.306 +                    // Remove will fail (too early), so events to end will be recorded
  13.307 +                    case REMOVE_IN_TASK:
  13.308 +                        found = "{ENTER=2:2, ANALYZE=1:1, GENERATE=1:1, ANNOTATION_PROCESSING=0:1, ANNOTATION_PROCESSING_ROUND=1:2}";
  13.309 +                        break;
  13.310 +                    case REMOVE_IN_PROCESSOR:
  13.311 +                        found = "{ENTER=1:1, ANNOTATION_PROCESSING_ROUND=1:1}";
  13.312 +                        break;
  13.313 +                    case REMOVE_IN_LISTENER:
  13.314 +                        found = "{ENTER=2:2, ANALYZE=1:1, GENERATE=1:0, ANNOTATION_PROCESSING=0:1, ANNOTATION_PROCESSING_ROUND=1:2}";
  13.315 +                        break;
  13.316 +                    default:
  13.317 +                        throw new IllegalStateException();
  13.318 +                }
  13.319 +                break;
  13.320 +
  13.321 +            // "Add in listener" will occur during "ANALYSE.started" event
  13.322 +            case ADD_IN_LISTENER:
  13.323 +                switch (rk) {
  13.324 +                    // Remove will fail (too early, so events to end will be recorded
  13.325 +                    case REMOVE_IN_TASK:
  13.326 +                    case REMOVE_IN_PROCESSOR:
  13.327 +                        found = "{ANALYZE=0:1, GENERATE=1:1}";
  13.328 +                        break;
  13.329 +                    // Remove will succeed during "GENERATE.finished" event
  13.330 +                    case REMOVE_IN_LISTENER:
  13.331 +                        found = "{ANALYZE=0:1, GENERATE=1:0}";
  13.332 +                        break;
  13.333 +                    default:
  13.334 +                        throw new IllegalStateException();
  13.335 +                }
  13.336 +                break;
  13.337 +            default:
  13.338 +                throw new IllegalStateException();
  13.339 +        }
  13.340 +
  13.341 +        if (!found.equals(expect)) {
  13.342 +            System.err.println("Expected: " + expect);
  13.343 +            System.err.println("   Found: " + found);
  13.344 +            error("unexpected value found");
  13.345 +        }
  13.346 +    }
  13.347 +
  13.348 +    int errors;
  13.349 +
  13.350 +    void error(String message) {
  13.351 +        System.err.println("Error: " + message);
  13.352 +        errors++;
  13.353 +    }
  13.354 +}
    14.1 --- a/test/tools/javac/apt.sh	Thu Mar 01 12:23:33 2012 -0800
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,68 +0,0 @@
    14.4 -#! /bin/sh -f
    14.5 -
    14.6 -#
    14.7 -# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
    14.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.9 -#
   14.10 -# This code is free software; you can redistribute it and/or modify it
   14.11 -# under the terms of the GNU General Public License version 2 only, as
   14.12 -# published by the Free Software Foundation.
   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   14.25 -# or visit www.oracle.com if you need additional information or have any
   14.26 -# questions.
   14.27 -#
   14.28 -
   14.29 -# 
   14.30 -# Usage:
   14.31 -#  @run apt.sh <apt-args>
   14.32 -#
   14.33 -# This script is to run apt for a regression test
   14.34 -
   14.35 -if [ "${TESTJAVA}" = "" ]
   14.36 -then
   14.37 -  echo "TESTJAVA not set.  Test cannot execute.  Failed."
   14.38 -  exit 1
   14.39 -fi
   14.40 -
   14.41 -# set platform-dependent variables
   14.42 -OS=`uname -s`
   14.43 -case "$OS" in
   14.44 -  SunOS | Linux )
   14.45 -    NULL=/dev/null
   14.46 -    PS=":"
   14.47 -    FS="/"
   14.48 -    ;;
   14.49 -  Windows* )
   14.50 -    NULL=NUL
   14.51 -    PS=";"
   14.52 -    FS="\\"
   14.53 -    ;;
   14.54 -  * )
   14.55 -    echo "Unrecognized system!"
   14.56 -    exit 1;
   14.57 -    ;;
   14.58 -esac
   14.59 -
   14.60 -CLASSPATH="${TESTCLASSES}${PS}${TESTJAVA}${FS}lib${FS}tools.jar" "${TESTJAVA}${FS}bin${FS}apt" ${TESTTOOLVMOPTS} $*
   14.61 -result=$?
   14.62 -
   14.63 -if [ $result -eq 0 ]
   14.64 -then
   14.65 -  echo "Passed"
   14.66 -else
   14.67 -  echo "Failed"
   14.68 -fi
   14.69 -exit $result
   14.70 -
   14.71 -
    15.1 --- a/test/tools/javac/processing/loader/testClose/TestClose.java	Thu Mar 01 12:23:33 2012 -0800
    15.2 +++ b/test/tools/javac/processing/loader/testClose/TestClose.java	Mon Mar 05 17:04:48 2012 -0800
    15.3 @@ -1,5 +1,5 @@
    15.4  /*
    15.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
    15.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
    15.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.8   *
    15.9   * This code is free software; you can redistribute it and/or modify it
   15.10 @@ -31,6 +31,7 @@
   15.11  import com.sun.source.util.TaskEvent;
   15.12  import com.sun.source.util.TaskListener;
   15.13  import com.sun.tools.javac.api.ClientCodeWrapper.Trusted;
   15.14 +import com.sun.tools.javac.api.BasicJavacTask;
   15.15  import com.sun.tools.javac.api.JavacTool;
   15.16  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
   15.17  import com.sun.tools.javac.util.Context;
   15.18 @@ -89,10 +90,10 @@
   15.19          "                public void run() {\n" +
   15.20          "                    System.out.println(getClass().getName() + \": run()\");\n" +
   15.21          "                    try {\n" +
   15.22 -        "                    cl.loadClass(\"Callback\")\n" +
   15.23 -        "                        .asSubclass(Runnable.class)\n" +
   15.24 -        "                        .newInstance()\n" +
   15.25 -        "                        .run();\n" +
   15.26 +        "                        cl.loadClass(\"Callback\")\n" +
   15.27 +        "                            .asSubclass(Runnable.class)\n" +
   15.28 +        "                            .newInstance()\n" +
   15.29 +        "                            .run();\n" +
   15.30          "                    } catch (ReflectiveOperationException e) {\n" +
   15.31          "                        throw new Error(e);\n" +
   15.32          "                    }\n" +
   15.33 @@ -184,25 +185,24 @@
   15.34              throw new AssertionError();
   15.35      }
   15.36  
   15.37 -
   15.38      public static void add(ProcessingEnvironment env, Runnable r) {
   15.39          try {
   15.40 -            Context c = ((JavacProcessingEnvironment) env).getContext();
   15.41 -            Object o = c.get(TaskListener.class);
   15.42 +            JavacTask task = JavacTask.instance(env);
   15.43 +            TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
   15.44              // The TaskListener is an instanceof TestClose, but when using the
   15.45              // default class loaders. the taskListener uses a different
   15.46              // instance of Class<TestClose> than the anno processor.
   15.47              // If you try to evaluate
   15.48 -            //      TestClose tc = (TestClose) (o).
   15.49 +            //      TestClose tc = (TestClose) (l).
   15.50              // you get the following somewhat confusing error:
   15.51              //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
   15.52              // The workaround is to access the fields of TestClose with reflection.
   15.53 -            Field f = o.getClass().getField("runnables");
   15.54 +            Field f = l.getClass().getField("runnables");
   15.55              @SuppressWarnings("unchecked")
   15.56 -            List<Runnable> runnables = (List<Runnable>) f.get(o);
   15.57 +            List<Runnable> runnables = (List<Runnable>) f.get(l);
   15.58              runnables.add(r);
   15.59          } catch (Throwable t) {
   15.60 -            System.err.println(t);
   15.61 +            t.printStackTrace();
   15.62          }
   15.63      }
   15.64  

mercurial