6990134: minor (but red) findbugs warnings

Sun, 12 Dec 2010 10:05:40 -0800

author
jjg
date
Sun, 12 Dec 2010 10:05:40 -0800
changeset 789
878c8f760ded
parent 788
8ec3a824f925
child 791
dd9b5f767559

6990134: minor (but red) findbugs warnings
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/apt/main/AptJavaCompiler.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/apt/main/JavaCompiler.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/apt/main/Main.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/apt/mirror/apt/FilerImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Type.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/apt/main/AptJavaCompiler.java	Sun Dec 12 10:05:40 2010 -0800
     1.3 @@ -0,0 +1,292 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.apt.main;
    1.30 +
    1.31 +import java.io.*;
    1.32 +import java.util.Map;
    1.33 +
    1.34 +import javax.tools.JavaFileManager;
    1.35 +import javax.tools.JavaFileObject;
    1.36 +
    1.37 +import com.sun.tools.javac.file.JavacFileManager;
    1.38 +import com.sun.tools.javac.util.*;
    1.39 +import com.sun.tools.javac.code.*;
    1.40 +import com.sun.tools.javac.jvm.*;
    1.41 +
    1.42 +import com.sun.tools.javac.code.Symbol.*;
    1.43 +import com.sun.tools.javac.tree.JCTree.*;
    1.44 +
    1.45 +import com.sun.tools.apt.comp.*;
    1.46 +import com.sun.tools.apt.util.Bark;
    1.47 +import com.sun.mirror.apt.AnnotationProcessorFactory;
    1.48 +import com.sun.tools.javac.parser.DocCommentScanner;
    1.49 +
    1.50 +/**
    1.51 + *  <p><b>This is NOT part of any supported API.
    1.52 + *  If you write code that depends on this, you do so at your own
    1.53 + *  risk.  This code and its internal interfaces are subject to change
    1.54 + *  or deletion without notice.</b>
    1.55 + */
    1.56 +@SuppressWarnings("deprecation")
    1.57 +public class AptJavaCompiler extends com.sun.tools.javac.main.JavaCompiler {
    1.58 +    /** The context key for the compiler. */
    1.59 +    protected static final Context.Key<AptJavaCompiler> compilerKey =
    1.60 +        new Context.Key<AptJavaCompiler>();
    1.61 +
    1.62 +    /** Get the JavaCompiler instance for this context. */
    1.63 +    public static AptJavaCompiler instance(Context context) {
    1.64 +        AptJavaCompiler instance = context.get(compilerKey);
    1.65 +        if (instance == null)
    1.66 +            instance = new AptJavaCompiler(context);
    1.67 +        return instance;
    1.68 +    }
    1.69 +
    1.70 +
    1.71 +    java.util.Set<String> genSourceFileNames;
    1.72 +    java.util.Set<String> genClassFileNames;
    1.73 +
    1.74 +    public java.util.Set<String> getSourceFileNames() {
    1.75 +        return genSourceFileNames;
    1.76 +    }
    1.77 +
    1.78 +    /** List of names of generated class files.
    1.79 +     */
    1.80 +    public java.util.Set<String> getClassFileNames() {
    1.81 +        return genClassFileNames;
    1.82 +    }
    1.83 +
    1.84 +    java.util.Set<java.io.File> aggregateGenFiles = java.util.Collections.emptySet();
    1.85 +
    1.86 +    public java.util.Set<java.io.File> getAggregateGenFiles() {
    1.87 +        return aggregateGenFiles;
    1.88 +    }
    1.89 +
    1.90 +    /** The bark to be used for error reporting.
    1.91 +     */
    1.92 +    Bark bark;
    1.93 +
    1.94 +    /** The log to be used for error reporting.
    1.95 +     */
    1.96 +    Log log;
    1.97 +
    1.98 +    /** The annotation framework
    1.99 +     */
   1.100 +    Apt apt;
   1.101 +
   1.102 +    private static Context preRegister(Context context) {
   1.103 +        Bark.preRegister(context);
   1.104 +
   1.105 +        if (context.get(JavaFileManager.class) == null)
   1.106 +            JavacFileManager.preRegister(context);
   1.107 +
   1.108 +        return context;
   1.109 +    }
   1.110 +
   1.111 +    /** Construct a new compiler from a shared context.
   1.112 +     */
   1.113 +    public AptJavaCompiler(Context context) {
   1.114 +        super(preRegister(context));
   1.115 +
   1.116 +        context.put(compilerKey, this);
   1.117 +        apt = Apt.instance(context);
   1.118 +
   1.119 +        ClassReader classReader = ClassReader.instance(context);
   1.120 +        classReader.preferSource = true;
   1.121 +
   1.122 +        // TEMPORARY NOTE: bark==log, but while refactoring, we maintain their
   1.123 +        // original identities, to remember the original intent.
   1.124 +        log = Log.instance(context);
   1.125 +        bark = Bark.instance(context);
   1.126 +
   1.127 +        Options options = Options.instance(context);
   1.128 +        classOutput   = options.get("-retrofit")      == null;
   1.129 +        nocompile     = options.get("-nocompile")     != null;
   1.130 +        print         = options.get("-print")         != null;
   1.131 +        classesAsDecls= options.get("-XclassesAsDecls") != null;
   1.132 +
   1.133 +        genSourceFileNames = new java.util.LinkedHashSet<String>();
   1.134 +        genClassFileNames  = new java.util.LinkedHashSet<String>();
   1.135 +
   1.136 +        // this forces a copy of the line map to be kept in the tree,
   1.137 +        // for use by com.sun.mirror.util.SourcePosition.
   1.138 +        lineDebugInfo = true;
   1.139 +    }
   1.140 +
   1.141 +    /* Switches:
   1.142 +     */
   1.143 +
   1.144 +    /** Emit class files. This switch is always set, except for the first
   1.145 +     *  phase of retrofitting, where signatures are parsed.
   1.146 +     */
   1.147 +    public boolean classOutput;
   1.148 +
   1.149 +    /** The internal printing annotation processor should be used.
   1.150 +     */
   1.151 +    public boolean print;
   1.152 +
   1.153 +    /** Compilation should not be done after annotation processing.
   1.154 +     */
   1.155 +    public boolean nocompile;
   1.156 +
   1.157 +    /** Are class files being treated as declarations
   1.158 +     */
   1.159 +    public boolean classesAsDecls;
   1.160 +
   1.161 +    /** Try to open input stream with given name.
   1.162 +     *  Report an error if this fails.
   1.163 +     *  @param filename   The file name of the input stream to be opened.
   1.164 +     */
   1.165 +    // PROVIDED FOR EXTREME BACKWARDS COMPATIBILITY
   1.166 +    // There are some very obscure errors that can arise while translating
   1.167 +    // the contents of a file from bytes to characters. In Tiger, these
   1.168 +    // diagnostics were ignored. This method provides compatibility with
   1.169 +    // that behavior. It would be better to honor those diagnostics, in which
   1.170 +    // case, this method can be deleted.
   1.171 +    @Override
   1.172 +    public CharSequence readSource(JavaFileObject filename) {
   1.173 +        try {
   1.174 +            inputFiles.add(filename);
   1.175 +            boolean prev = bark.setDiagnosticsIgnored(true);
   1.176 +            try {
   1.177 +                return filename.getCharContent(false);
   1.178 +            }
   1.179 +            finally {
   1.180 +                bark.setDiagnosticsIgnored(prev);
   1.181 +            }
   1.182 +        } catch (IOException e) {
   1.183 +            bark.error(Position.NOPOS, "cant.read.file", filename);
   1.184 +            return null;
   1.185 +        }
   1.186 +    }
   1.187 +
   1.188 +    /** Parse contents of input stream.
   1.189 +     *  @param filename     The name of the file from which input stream comes.
   1.190 +     *  @param input        The input stream to be parsed.
   1.191 +     */
   1.192 +    // PROVIDED FOR BACKWARDS COMPATIBILITY
   1.193 +    // In Tiger, diagnostics from the scanner and parser were ignored.
   1.194 +    // This method provides compatibility with that behavior.
   1.195 +    // It would be better to honor those diagnostics, in which
   1.196 +    // case, this method can be deleted.
   1.197 +    @Override
   1.198 +    protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
   1.199 +        boolean prev = bark.setDiagnosticsIgnored(true);
   1.200 +        try {
   1.201 +            return super.parse(filename, content);
   1.202 +        }
   1.203 +        finally {
   1.204 +            bark.setDiagnosticsIgnored(prev);
   1.205 +        }
   1.206 +    }
   1.207 +
   1.208 +    @Override
   1.209 +    protected boolean keepComments() {
   1.210 +        return true;  // make doc comments available to mirror API impl.
   1.211 +    }
   1.212 +
   1.213 +    /** Track when the JavaCompiler has been used to compile something. */
   1.214 +    private boolean hasBeenUsed = false;
   1.215 +
   1.216 +    /** Main method: compile a list of files, return all compiled classes
   1.217 +     *  @param filenames     The names of all files to be compiled.
   1.218 +     */
   1.219 +    public List<ClassSymbol> compile(List<String> filenames,
   1.220 +                                     Map<String, String> origOptions,
   1.221 +                                     ClassLoader aptCL,
   1.222 +                                     AnnotationProcessorFactory providedFactory,
   1.223 +                                     java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories,
   1.224 +                                     java.util.Set<java.io.File> aggregateGenFiles)
   1.225 +        throws Throwable {
   1.226 +        // as a JavaCompiler can only be used once, throw an exception if
   1.227 +        // it has been used before.
   1.228 +        assert !hasBeenUsed : "attempt to reuse JavaCompiler";
   1.229 +        hasBeenUsed = true;
   1.230 +
   1.231 +        this.aggregateGenFiles = aggregateGenFiles;
   1.232 +
   1.233 +        long msec = System.currentTimeMillis();
   1.234 +
   1.235 +        ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
   1.236 +        try {
   1.237 +            JavacFileManager fm = (JavacFileManager)fileManager;
   1.238 +            //parse all files
   1.239 +            ListBuffer<JCCompilationUnit> trees = new ListBuffer<JCCompilationUnit>();
   1.240 +            for (List<String> l = filenames; l.nonEmpty(); l = l.tail) {
   1.241 +                if (classesAsDecls) {
   1.242 +                    if (! l.head.endsWith(".java") ) { // process as class file
   1.243 +                        ClassSymbol cs = reader.enterClass(names.fromString(l.head));
   1.244 +                        try {
   1.245 +                            cs.complete();
   1.246 +                        } catch(Symbol.CompletionFailure cf) {
   1.247 +                            bark.aptError("CantFindClass", l);
   1.248 +                            continue;
   1.249 +                        }
   1.250 +
   1.251 +                        classes.append(cs); // add to list of classes
   1.252 +                        continue;
   1.253 +                    }
   1.254 +                }
   1.255 +                JavaFileObject fo = fm.getJavaFileObjectsFromStrings(List.of(l.head)).iterator().next();
   1.256 +                trees.append(parse(fo));
   1.257 +            }
   1.258 +
   1.259 +            //enter symbols for all files
   1.260 +            List<JCCompilationUnit> roots = trees.toList();
   1.261 +
   1.262 +            if (errorCount() == 0) {
   1.263 +                boolean prev = bark.setDiagnosticsIgnored(true);
   1.264 +                try {
   1.265 +                    enter.main(roots);
   1.266 +                }
   1.267 +                finally {
   1.268 +                    bark.setDiagnosticsIgnored(prev);
   1.269 +                }
   1.270 +            }
   1.271 +
   1.272 +            if (errorCount() == 0) {
   1.273 +                apt.main(roots,
   1.274 +                         classes,
   1.275 +                         origOptions, aptCL,
   1.276 +                         providedFactory,
   1.277 +                         productiveFactories);
   1.278 +                genSourceFileNames.addAll(apt.getSourceFileNames());
   1.279 +                genClassFileNames.addAll(apt.getClassFileNames());
   1.280 +            }
   1.281 +
   1.282 +        } catch (Abort ex) {
   1.283 +        }
   1.284 +
   1.285 +        if (verbose)
   1.286 +            printVerbose("total", Long.toString(System.currentTimeMillis() - msec));
   1.287 +
   1.288 +        chk.reportDeferredDiagnostics();
   1.289 +
   1.290 +        printCount("error", errorCount());
   1.291 +        printCount("warn", warningCount());
   1.292 +
   1.293 +        return classes.toList();
   1.294 +    }
   1.295 +}
     2.1 --- a/src/share/classes/com/sun/tools/apt/main/JavaCompiler.java	Fri Dec 10 07:38:28 2010 -0800
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,292 +0,0 @@
     2.4 -/*
     2.5 - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
     2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 - *
     2.8 - * This code is free software; you can redistribute it and/or modify it
     2.9 - * under the terms of the GNU General Public License version 2 only, as
    2.10 - * published by the Free Software Foundation.  Oracle designates this
    2.11 - * particular file as subject to the "Classpath" exception as provided
    2.12 - * by Oracle in the LICENSE file that accompanied this code.
    2.13 - *
    2.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 - * version 2 for more details (a copy is included in the LICENSE file that
    2.18 - * accompanied this code).
    2.19 - *
    2.20 - * You should have received a copy of the GNU General Public License version
    2.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 - *
    2.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 - * or visit www.oracle.com if you need additional information or have any
    2.26 - * questions.
    2.27 - */
    2.28 -
    2.29 -package com.sun.tools.apt.main;
    2.30 -
    2.31 -import java.io.*;
    2.32 -import java.util.Map;
    2.33 -
    2.34 -import javax.tools.JavaFileManager;
    2.35 -import javax.tools.JavaFileObject;
    2.36 -
    2.37 -import com.sun.tools.javac.file.JavacFileManager;
    2.38 -import com.sun.tools.javac.util.*;
    2.39 -import com.sun.tools.javac.code.*;
    2.40 -import com.sun.tools.javac.jvm.*;
    2.41 -
    2.42 -import com.sun.tools.javac.code.Symbol.*;
    2.43 -import com.sun.tools.javac.tree.JCTree.*;
    2.44 -
    2.45 -import com.sun.tools.apt.comp.*;
    2.46 -import com.sun.tools.apt.util.Bark;
    2.47 -import com.sun.mirror.apt.AnnotationProcessorFactory;
    2.48 -import com.sun.tools.javac.parser.DocCommentScanner;
    2.49 -
    2.50 -/**
    2.51 - *  <p><b>This is NOT part of any supported API.
    2.52 - *  If you write code that depends on this, you do so at your own
    2.53 - *  risk.  This code and its internal interfaces are subject to change
    2.54 - *  or deletion without notice.</b>
    2.55 - */
    2.56 -@SuppressWarnings("deprecation")
    2.57 -public class JavaCompiler extends com.sun.tools.javac.main.JavaCompiler {
    2.58 -    /** The context key for the compiler. */
    2.59 -    protected static final Context.Key<JavaCompiler> compilerKey =
    2.60 -        new Context.Key<JavaCompiler>();
    2.61 -
    2.62 -    /** Get the JavaCompiler instance for this context. */
    2.63 -    public static JavaCompiler instance(Context context) {
    2.64 -        JavaCompiler instance = context.get(compilerKey);
    2.65 -        if (instance == null)
    2.66 -            instance = new JavaCompiler(context);
    2.67 -        return instance;
    2.68 -    }
    2.69 -
    2.70 -
    2.71 -    java.util.Set<String> genSourceFileNames;
    2.72 -    java.util.Set<String> genClassFileNames;
    2.73 -
    2.74 -    public java.util.Set<String> getSourceFileNames() {
    2.75 -        return genSourceFileNames;
    2.76 -    }
    2.77 -
    2.78 -    /** List of names of generated class files.
    2.79 -     */
    2.80 -    public java.util.Set<String> getClassFileNames() {
    2.81 -        return genClassFileNames;
    2.82 -    }
    2.83 -
    2.84 -    java.util.Set<java.io.File> aggregateGenFiles = java.util.Collections.emptySet();
    2.85 -
    2.86 -    public java.util.Set<java.io.File> getAggregateGenFiles() {
    2.87 -        return aggregateGenFiles;
    2.88 -    }
    2.89 -
    2.90 -    /** The bark to be used for error reporting.
    2.91 -     */
    2.92 -    Bark bark;
    2.93 -
    2.94 -    /** The log to be used for error reporting.
    2.95 -     */
    2.96 -    Log log;
    2.97 -
    2.98 -    /** The annotation framework
    2.99 -     */
   2.100 -    Apt apt;
   2.101 -
   2.102 -    private static Context preRegister(Context context) {
   2.103 -        Bark.preRegister(context);
   2.104 -
   2.105 -        if (context.get(JavaFileManager.class) == null)
   2.106 -            JavacFileManager.preRegister(context);
   2.107 -
   2.108 -        return context;
   2.109 -    }
   2.110 -
   2.111 -    /** Construct a new compiler from a shared context.
   2.112 -     */
   2.113 -    public JavaCompiler(Context context) {
   2.114 -        super(preRegister(context));
   2.115 -
   2.116 -        context.put(compilerKey, this);
   2.117 -        apt = Apt.instance(context);
   2.118 -
   2.119 -        ClassReader classReader = ClassReader.instance(context);
   2.120 -        classReader.preferSource = true;
   2.121 -
   2.122 -        // TEMPORARY NOTE: bark==log, but while refactoring, we maintain their
   2.123 -        // original identities, to remember the original intent.
   2.124 -        log = Log.instance(context);
   2.125 -        bark = Bark.instance(context);
   2.126 -
   2.127 -        Options options = Options.instance(context);
   2.128 -        classOutput   = options.get("-retrofit")      == null;
   2.129 -        nocompile     = options.get("-nocompile")     != null;
   2.130 -        print         = options.get("-print")         != null;
   2.131 -        classesAsDecls= options.get("-XclassesAsDecls") != null;
   2.132 -
   2.133 -        genSourceFileNames = new java.util.LinkedHashSet<String>();
   2.134 -        genClassFileNames  = new java.util.LinkedHashSet<String>();
   2.135 -
   2.136 -        // this forces a copy of the line map to be kept in the tree,
   2.137 -        // for use by com.sun.mirror.util.SourcePosition.
   2.138 -        lineDebugInfo = true;
   2.139 -    }
   2.140 -
   2.141 -    /* Switches:
   2.142 -     */
   2.143 -
   2.144 -    /** Emit class files. This switch is always set, except for the first
   2.145 -     *  phase of retrofitting, where signatures are parsed.
   2.146 -     */
   2.147 -    public boolean classOutput;
   2.148 -
   2.149 -    /** The internal printing annotation processor should be used.
   2.150 -     */
   2.151 -    public boolean print;
   2.152 -
   2.153 -    /** Compilation should not be done after annotation processing.
   2.154 -     */
   2.155 -    public boolean nocompile;
   2.156 -
   2.157 -    /** Are class files being treated as declarations
   2.158 -     */
   2.159 -    public boolean classesAsDecls;
   2.160 -
   2.161 -    /** Try to open input stream with given name.
   2.162 -     *  Report an error if this fails.
   2.163 -     *  @param filename   The file name of the input stream to be opened.
   2.164 -     */
   2.165 -    // PROVIDED FOR EXTREME BACKWARDS COMPATIBILITY
   2.166 -    // There are some very obscure errors that can arise while translating
   2.167 -    // the contents of a file from bytes to characters. In Tiger, these
   2.168 -    // diagnostics were ignored. This method provides compatibility with
   2.169 -    // that behavior. It would be better to honor those diagnostics, in which
   2.170 -    // case, this method can be deleted.
   2.171 -    @Override
   2.172 -    public CharSequence readSource(JavaFileObject filename) {
   2.173 -        try {
   2.174 -            inputFiles.add(filename);
   2.175 -            boolean prev = bark.setDiagnosticsIgnored(true);
   2.176 -            try {
   2.177 -                return filename.getCharContent(false);
   2.178 -            }
   2.179 -            finally {
   2.180 -                bark.setDiagnosticsIgnored(prev);
   2.181 -            }
   2.182 -        } catch (IOException e) {
   2.183 -            bark.error(Position.NOPOS, "cant.read.file", filename);
   2.184 -            return null;
   2.185 -        }
   2.186 -    }
   2.187 -
   2.188 -    /** Parse contents of input stream.
   2.189 -     *  @param filename     The name of the file from which input stream comes.
   2.190 -     *  @param input        The input stream to be parsed.
   2.191 -     */
   2.192 -    // PROVIDED FOR BACKWARDS COMPATIBILITY
   2.193 -    // In Tiger, diagnostics from the scanner and parser were ignored.
   2.194 -    // This method provides compatibility with that behavior.
   2.195 -    // It would be better to honor those diagnostics, in which
   2.196 -    // case, this method can be deleted.
   2.197 -    @Override
   2.198 -    protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
   2.199 -        boolean prev = bark.setDiagnosticsIgnored(true);
   2.200 -        try {
   2.201 -            return super.parse(filename, content);
   2.202 -        }
   2.203 -        finally {
   2.204 -            bark.setDiagnosticsIgnored(prev);
   2.205 -        }
   2.206 -    }
   2.207 -
   2.208 -    @Override
   2.209 -    protected boolean keepComments() {
   2.210 -        return true;  // make doc comments available to mirror API impl.
   2.211 -    }
   2.212 -
   2.213 -    /** Track when the JavaCompiler has been used to compile something. */
   2.214 -    private boolean hasBeenUsed = false;
   2.215 -
   2.216 -    /** Main method: compile a list of files, return all compiled classes
   2.217 -     *  @param filenames     The names of all files to be compiled.
   2.218 -     */
   2.219 -    public List<ClassSymbol> compile(List<String> filenames,
   2.220 -                                     Map<String, String> origOptions,
   2.221 -                                     ClassLoader aptCL,
   2.222 -                                     AnnotationProcessorFactory providedFactory,
   2.223 -                                     java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories,
   2.224 -                                     java.util.Set<java.io.File> aggregateGenFiles)
   2.225 -        throws Throwable {
   2.226 -        // as a JavaCompiler can only be used once, throw an exception if
   2.227 -        // it has been used before.
   2.228 -        assert !hasBeenUsed : "attempt to reuse JavaCompiler";
   2.229 -        hasBeenUsed = true;
   2.230 -
   2.231 -        this.aggregateGenFiles = aggregateGenFiles;
   2.232 -
   2.233 -        long msec = System.currentTimeMillis();
   2.234 -
   2.235 -        ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
   2.236 -        try {
   2.237 -            JavacFileManager fm = (JavacFileManager)fileManager;
   2.238 -            //parse all files
   2.239 -            ListBuffer<JCCompilationUnit> trees = new ListBuffer<JCCompilationUnit>();
   2.240 -            for (List<String> l = filenames; l.nonEmpty(); l = l.tail) {
   2.241 -                if (classesAsDecls) {
   2.242 -                    if (! l.head.endsWith(".java") ) { // process as class file
   2.243 -                        ClassSymbol cs = reader.enterClass(names.fromString(l.head));
   2.244 -                        try {
   2.245 -                            cs.complete();
   2.246 -                        } catch(Symbol.CompletionFailure cf) {
   2.247 -                            bark.aptError("CantFindClass", l);
   2.248 -                            continue;
   2.249 -                        }
   2.250 -
   2.251 -                        classes.append(cs); // add to list of classes
   2.252 -                        continue;
   2.253 -                    }
   2.254 -                }
   2.255 -                JavaFileObject fo = fm.getJavaFileObjectsFromStrings(List.of(l.head)).iterator().next();
   2.256 -                trees.append(parse(fo));
   2.257 -            }
   2.258 -
   2.259 -            //enter symbols for all files
   2.260 -            List<JCCompilationUnit> roots = trees.toList();
   2.261 -
   2.262 -            if (errorCount() == 0) {
   2.263 -                boolean prev = bark.setDiagnosticsIgnored(true);
   2.264 -                try {
   2.265 -                    enter.main(roots);
   2.266 -                }
   2.267 -                finally {
   2.268 -                    bark.setDiagnosticsIgnored(prev);
   2.269 -                }
   2.270 -            }
   2.271 -
   2.272 -            if (errorCount() == 0) {
   2.273 -                apt.main(roots,
   2.274 -                         classes,
   2.275 -                         origOptions, aptCL,
   2.276 -                         providedFactory,
   2.277 -                         productiveFactories);
   2.278 -                genSourceFileNames.addAll(apt.getSourceFileNames());
   2.279 -                genClassFileNames.addAll(apt.getClassFileNames());
   2.280 -            }
   2.281 -
   2.282 -        } catch (Abort ex) {
   2.283 -        }
   2.284 -
   2.285 -        if (verbose)
   2.286 -            printVerbose("total", Long.toString(System.currentTimeMillis() - msec));
   2.287 -
   2.288 -        chk.reportDeferredDiagnostics();
   2.289 -
   2.290 -        printCount("error", errorCount());
   2.291 -        printCount("warn", warningCount());
   2.292 -
   2.293 -        return classes.toList();
   2.294 -    }
   2.295 -}
     3.1 --- a/src/share/classes/com/sun/tools/apt/main/Main.java	Fri Dec 10 07:38:28 2010 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/apt/main/Main.java	Sun Dec 12 10:05:40 2010 -0800
     3.3 @@ -421,7 +421,7 @@
     3.4          },
     3.5          new AptOption("-version",               "opt.version") {
     3.6              boolean process(String option) {
     3.7 -                Bark.printLines(out, ownName + " " + JavaCompiler.version());
     3.8 +                Bark.printLines(out, ownName + " " + AptJavaCompiler.version());
     3.9                  return super.process(option);
    3.10              }
    3.11          },
    3.12 @@ -1111,11 +1111,11 @@
    3.13          }
    3.14          int exitCode = EXIT_OK;
    3.15  
    3.16 -        JavaCompiler comp = null;
    3.17 +        AptJavaCompiler comp = null;
    3.18          try {
    3.19              context.put(Bark.outKey, out);
    3.20  
    3.21 -            comp = JavaCompiler.instance(context);
    3.22 +            comp = AptJavaCompiler.instance(context);
    3.23              if (comp == null)
    3.24                  return EXIT_SYSERR;
    3.25  
    3.26 @@ -1184,7 +1184,7 @@
    3.27       */
    3.28      void bugMessage(Throwable ex) {
    3.29          Bark.printLines(out, getLocalizedString("msg.bug",
    3.30 -                                               JavaCompiler.version()));
    3.31 +                                               AptJavaCompiler.version()));
    3.32          ex.printStackTrace(out);
    3.33      }
    3.34  
     4.1 --- a/src/share/classes/com/sun/tools/apt/mirror/apt/FilerImpl.java	Fri Dec 10 07:38:28 2010 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/apt/mirror/apt/FilerImpl.java	Sun Dec 12 10:05:40 2010 -0800
     4.3 @@ -120,7 +120,7 @@
     4.4  
     4.5      private final Options opts;
     4.6      private final DeclarationMaker declMaker;
     4.7 -    private final com.sun.tools.apt.main.JavaCompiler comp;
     4.8 +    private final com.sun.tools.apt.main.AptJavaCompiler comp;
     4.9  
    4.10      // Platform's default encoding
    4.11      private final static String DEFAULT_ENCODING =
    4.12 @@ -177,7 +177,7 @@
    4.13          opts = Options.instance(context);
    4.14          declMaker = DeclarationMaker.instance(context);
    4.15          bark = Bark.instance(context);
    4.16 -        comp = com.sun.tools.apt.main.JavaCompiler.instance(context);
    4.17 +        comp = com.sun.tools.apt.main.AptJavaCompiler.instance(context);
    4.18          roundOver = false;
    4.19          this.filesCreated = comp.getAggregateGenFiles();
    4.20  
     5.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Fri Dec 10 07:38:28 2010 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Sun Dec 12 10:05:40 2010 -0800
     5.3 @@ -245,7 +245,7 @@
     5.4      public String argtypes(boolean varargs) {
     5.5          List<Type> args = getParameterTypes();
     5.6          if (!varargs) return args.toString();
     5.7 -        StringBuffer buf = new StringBuffer();
     5.8 +        StringBuilder buf = new StringBuilder();
     5.9          while (args.tail.nonEmpty()) {
    5.10              buf.append(args.head);
    5.11              args = args.tail;
    5.12 @@ -935,7 +935,7 @@
    5.13  
    5.14      public static class TypeVar extends Type implements TypeVariable {
    5.15  
    5.16 -        /** The bound of this type variable; set from outside.
    5.17 +        /** The upper bound of this type variable; set from outside.
    5.18           *  Must be nonempty once it is set.
    5.19           *  For a bound, `bound' is the bound type itself.
    5.20           *  Multiple bounds are expressed as a single class type which has the
    5.21 @@ -946,6 +946,12 @@
    5.22           *  points to the first class or interface bound.
    5.23           */
    5.24          public Type bound = null;
    5.25 +
    5.26 +        /** The lower bound of this type variable.
    5.27 +         *  TypeVars don't normally have a lower bound, so it is normally set
    5.28 +         *  to syms.botType.
    5.29 +         *  Subtypes, such as CapturedType, may provide a different value.
    5.30 +         */
    5.31          public Type lower;
    5.32  
    5.33          public TypeVar(Name name, Symbol owner, Type lower) {
    5.34 @@ -965,10 +971,12 @@
    5.35              return v.visitTypeVar(this, s);
    5.36          }
    5.37  
    5.38 +        @Override
    5.39          public Type getUpperBound() { return bound; }
    5.40  
    5.41          int rank_field = -1;
    5.42  
    5.43 +        @Override
    5.44          public Type getLowerBound() {
    5.45              return lower;
    5.46          }
    5.47 @@ -992,7 +1000,6 @@
    5.48       */
    5.49      public static class CapturedType extends TypeVar {
    5.50  
    5.51 -        public Type lower;
    5.52          public WildcardType wildcard;
    5.53  
    5.54          public CapturedType(Name name,
    5.55 @@ -1012,10 +1019,6 @@
    5.56              return v.visitCapturedType(this, s);
    5.57          }
    5.58  
    5.59 -        public Type getLowerBound() {
    5.60 -            return lower;
    5.61 -        }
    5.62 -
    5.63          @Override
    5.64          public boolean isCaptured() {
    5.65              return true;
     6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Dec 10 07:38:28 2010 -0800
     6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Sun Dec 12 10:05:40 2010 -0800
     6.3 @@ -641,7 +641,7 @@
     6.4                          if (!set.remove(new SingletonType(x)))
     6.5                              return false;
     6.6                      }
     6.7 -                    return (set.size() == 0);
     6.8 +                    return (set.isEmpty());
     6.9                  }
    6.10                  return t.tsym == s.tsym
    6.11                      && visit(t.getEnclosingType(), s.getEnclosingType())
    6.12 @@ -838,26 +838,26 @@
    6.13                      return isSameType(t, s);
    6.14              }
    6.15  
    6.16 -            void debugContainsType(WildcardType t, Type s) {
    6.17 -                System.err.println();
    6.18 -                System.err.format(" does %s contain %s?%n", t, s);
    6.19 -                System.err.format(" %s U(%s) <: U(%s) %s = %s%n",
    6.20 -                                  upperBound(s), s, t, U(t),
    6.21 -                                  t.isSuperBound()
    6.22 -                                  || isSubtypeNoCapture(upperBound(s), U(t)));
    6.23 -                System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
    6.24 -                                  L(t), t, s, lowerBound(s),
    6.25 -                                  t.isExtendsBound()
    6.26 -                                  || isSubtypeNoCapture(L(t), lowerBound(s)));
    6.27 -                System.err.println();
    6.28 -            }
    6.29 +//            void debugContainsType(WildcardType t, Type s) {
    6.30 +//                System.err.println();
    6.31 +//                System.err.format(" does %s contain %s?%n", t, s);
    6.32 +//                System.err.format(" %s U(%s) <: U(%s) %s = %s%n",
    6.33 +//                                  upperBound(s), s, t, U(t),
    6.34 +//                                  t.isSuperBound()
    6.35 +//                                  || isSubtypeNoCapture(upperBound(s), U(t)));
    6.36 +//                System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
    6.37 +//                                  L(t), t, s, lowerBound(s),
    6.38 +//                                  t.isExtendsBound()
    6.39 +//                                  || isSubtypeNoCapture(L(t), lowerBound(s)));
    6.40 +//                System.err.println();
    6.41 +//            }
    6.42  
    6.43              @Override
    6.44              public Boolean visitWildcardType(WildcardType t, Type s) {
    6.45                  if (s.tag >= firstPartialTag)
    6.46                      return containedBy(s, t);
    6.47                  else {
    6.48 -                    // debugContainsType(t, s);
    6.49 +//                    debugContainsType(t, s);
    6.50                      return isSameWildcard(t, s)
    6.51                          || isCaptureOf(s, t)
    6.52                          || ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) &&
     7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Dec 10 07:38:28 2010 -0800
     7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Sun Dec 12 10:05:40 2010 -0800
     7.3 @@ -197,7 +197,7 @@
     7.4          }
     7.5          return (checkInner == false || c.type.getEnclosingType() == Type.noType) ?
     7.6              isAccessible :
     7.7 -            isAccessible & isAccessible(env, c.type.getEnclosingType(), checkInner);
     7.8 +            isAccessible && isAccessible(env, c.type.getEnclosingType(), checkInner);
     7.9      }
    7.10      //where
    7.11          /** Is given class a subclass of given base class, or an inner class
    7.12 @@ -234,7 +234,6 @@
    7.13      }
    7.14      public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) {
    7.15          if (sym.name == names.init && sym.owner != site.tsym) return false;
    7.16 -        ClassSymbol sub;
    7.17          switch ((short)(sym.flags() & AccessFlags)) {
    7.18          case PRIVATE:
    7.19              return

mercurial