Merge jdk8-b30

Fri, 09 Mar 2012 11:59:26 -0800

author
lana
date
Fri, 09 Mar 2012 11:59:26 -0800
changeset 1227
08a3425f39f8
parent 1214
a1af4b95c287
parent 1226
97bec6ab1227
child 1228
b28cfbe7e8b1
child 1231
1fd57fcf2dbd

Merge

make/tools/CompileProperties/CompileProperties.java file | annotate | diff | comparison | revisions
make/tools/CompileProperties/CompilePropertiesTask.java file | annotate | diff | comparison | revisions
make/tools/GenStubs/GenStubs.java file | annotate | diff | comparison | revisions
make/tools/SelectTool/SelectToolTask.java file | annotate | diff | comparison | revisions
test/jprt.config file | annotate | diff | comparison | revisions
     1.1 --- a/.hgignore	Thu Mar 08 20:35:26 2012 -0800
     1.2 +++ b/.hgignore	Fri Mar 09 11:59:26 2012 -0800
     1.3 @@ -2,3 +2,4 @@
     1.4  ^dist/
     1.5  /nbproject/private/
     1.6  ^.hgtip
     1.7 +.DS_Store
     2.1 --- a/make/build.xml	Thu Mar 08 20:35:26 2012 -0800
     2.2 +++ b/make/build.xml	Fri Mar 09 11:59:26 2012 -0800
     2.3 @@ -862,7 +862,8 @@
     2.4                 source="${boot.javac.source}"
     2.5                 target="${boot.javac.target}"
     2.6                 executable="${boot.java.home}/bin/javac"
     2.7 -               srcdir="${make.tools.dir}/CompileProperties"
     2.8 +               srcdir="${make.tools.dir}"
     2.9 +               includes="compileproperties/* anttasks/CompileProperties*"
    2.10                 destdir="${build.toolclasses.dir}/"
    2.11                 classpath="${ant.core.lib}"
    2.12                 bootclasspath="${boot.java.home}/jre/lib/rt.jar"
    2.13 @@ -870,7 +871,7 @@
    2.14              <compilerarg line="${javac.lint.opts}"/>
    2.15          </javac>
    2.16          <taskdef name="pcompile"
    2.17 -                 classname="CompilePropertiesTask"
    2.18 +                 classname="anttasks.CompilePropertiesTask"
    2.19                   classpath="${build.toolclasses.dir}/"/>
    2.20      </target>
    2.21  
    2.22 @@ -880,7 +881,8 @@
    2.23                 source="${boot.javac.source}"
    2.24                 target="${boot.javac.target}"
    2.25                 executable="${boot.java.home}/bin/javac"
    2.26 -               srcdir="${make.tools.dir}/GenStubs"
    2.27 +               srcdir="${make.tools.dir}"
    2.28 +               includes="genstubs/* anttasks/GenStubs*"
    2.29                 destdir="${build.toolclasses.dir}/"
    2.30                 classpath="${ant.core.lib}"
    2.31                 includeantruntime="false">
    2.32 @@ -888,7 +890,7 @@
    2.33              <compilerarg line="${javac.lint.opts}"/>
    2.34          </javac>
    2.35          <taskdef name="genstubs"
    2.36 -                 classname="GenStubs$$Ant"
    2.37 +                 classname="anttasks.GenStubsTask"
    2.38                   classpath="${build.toolclasses.dir}/"/>
    2.39      </target>
    2.40  
     3.1 --- a/make/jprt.properties	Thu Mar 08 20:35:26 2012 -0800
     3.2 +++ b/make/jprt.properties	Fri Mar 09 11:59:26 2012 -0800
     3.3 @@ -39,6 +39,7 @@
     3.4      solaris_x64_5.10-{product|fastdebug},                       \
     3.5      linux_i586_2.6-{product|fastdebug},                         \
     3.6      linux_x64_2.6-{product|fastdebug},                          \
     3.7 +    macosx_x64_10.7-{product|fastdebug},                        \
     3.8      windows_i586_5.1-{product|fastdebug},                       \
     3.9      windows_x64_5.2-{product|fastdebug}
    3.10  
    3.11 @@ -50,6 +51,7 @@
    3.12      solaris_x64_5.10-product-c2-TESTNAME,                       \
    3.13      linux_i586_2.6-product-{c1|c2}-TESTNAME,                    \
    3.14      linux_x64_2.6-product-c2-TESTNAME,                          \
    3.15 +    macosx_x64_10.7-product-c2-TESTNAME,                        \
    3.16      windows_i586_5.1-product-c1-TESTNAME,                       \
    3.17      windows_x64_5.2-product-c2-TESTNAME
    3.18  
    3.19 @@ -60,3 +62,18 @@
    3.20  # Directories to be excluded from the source bundles
    3.21  jprt.bundle.exclude.src.dirs=build dist webrev
    3.22  
    3.23 +# Test target list (no fastdebug & limited c2 testing)
    3.24 +jprt.my.test.target.set= 					\
    3.25 +    solaris_sparc_5.10-product-c1-TESTNAME,                     \
    3.26 +    solaris_sparcv9_5.10-product-c2-TESTNAME,                   \
    3.27 +    solaris_i586_5.10-product-c1-TESTNAME,                      \
    3.28 +    solaris_x64_5.10-product-c2-TESTNAME,                       \
    3.29 +    linux_i586_2.6-product-{c1|c2}-TESTNAME,                    \
    3.30 +    linux_x64_2.6-product-c2-TESTNAME,                          \
    3.31 +    macosx_x64_10.7-product-c2-TESTNAME,                        \
    3.32 +    windows_i586_5.1-product-c1-TESTNAME,                       \
    3.33 +    windows_x64_5.2-product-c2-TESTNAME
    3.34 +
    3.35 +# Default test targets
    3.36 +jprt.make.rule.test.targets=					\
    3.37 +    ${jprt.my.test.target.set:TESTNAME=jtreg}
     4.1 --- a/make/netbeans/langtools/build.xml	Thu Mar 08 20:35:26 2012 -0800
     4.2 +++ b/make/netbeans/langtools/build.xml	Fri Mar 09 11:59:26 2012 -0800
     4.3 @@ -261,7 +261,8 @@
     4.4  
     4.5      <target name="-def-select-tool">
     4.6          <mkdir dir="${build.toolclasses.dir}"/>
     4.7 -        <javac srcdir="${make.tools.dir}/SelectTool"
     4.8 +        <javac srcdir="${make.tools.dir}"
     4.9 +               includes="anttasks/SelectTool*"
    4.10                 destdir="${build.toolclasses.dir}/"
    4.11                 classpath="${ant.core.lib}"
    4.12                 includeantruntime="false"
    4.13 @@ -270,7 +271,7 @@
    4.14                     <compilerarg line="-Xlint"/>
    4.15          </javac>
    4.16          <taskdef name="select-tool"
    4.17 -                 classname="SelectToolTask"
    4.18 +                 classname="anttasks.SelectToolTask"
    4.19                   classpath="${build.toolclasses.dir}/"/>
    4.20      </target>
    4.21  
     5.1 --- a/make/tools/CompileProperties/CompileProperties.java	Thu Mar 08 20:35:26 2012 -0800
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,402 +0,0 @@
     5.4 -/*
     5.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
     5.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 - *
     5.8 - * This code is free software; you can redistribute it and/or modify it
     5.9 - * under the terms of the GNU General Public License version 2 only, as
    5.10 - * published by the Free Software Foundation.  Oracle designates this
    5.11 - * particular file as subject to the "Classpath" exception as provided
    5.12 - * by Oracle in the LICENSE file that accompanied this code.
    5.13 - *
    5.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 - * version 2 for more details (a copy is included in the LICENSE file that
    5.18 - * accompanied this code).
    5.19 - *
    5.20 - * You should have received a copy of the GNU General Public License version
    5.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 - *
    5.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.25 - * or visit www.oracle.com if you need additional information or have any
    5.26 - * questions.
    5.27 - */
    5.28 -
    5.29 -import java.io.BufferedWriter;
    5.30 -import java.io.File;
    5.31 -import java.io.FileInputStream;
    5.32 -import java.io.FileNotFoundException;
    5.33 -import java.io.FileOutputStream;
    5.34 -import java.io.IOException;
    5.35 -import java.io.OutputStreamWriter;
    5.36 -import java.io.Writer;
    5.37 -import java.text.MessageFormat;
    5.38 -import java.util.ArrayList;
    5.39 -import java.util.Collections;
    5.40 -import java.util.Iterator;
    5.41 -import java.util.List;
    5.42 -import java.util.Properties;
    5.43 -
    5.44 -/** Translates a .properties file into a .java file containing the
    5.45 - *  definition of a java.util.Properties subclass which can then be
    5.46 - *  compiled with javac. <P>
    5.47 - *
    5.48 - *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
    5.49 - *
    5.50 - *  Infers the package by looking at the common suffix of the two
    5.51 - *  inputs, eliminating "classes" from it.
    5.52 - *
    5.53 - * @author Scott Violet
    5.54 - * @author Kenneth Russell
    5.55 - */
    5.56 -
    5.57 -public class CompileProperties {
    5.58 -
    5.59 -    public static void main(String[] args) {
    5.60 -        CompileProperties cp = new CompileProperties();
    5.61 -        boolean ok = cp.run(args);
    5.62 -        if ( !ok ) {
    5.63 -            System.exit(1);
    5.64 -        }
    5.65 -    }
    5.66 -
    5.67 -    static interface Log {
    5.68 -        void info(String msg);
    5.69 -        void verbose(String msg);
    5.70 -        void error(String msg, Exception e);
    5.71 -    }
    5.72 -
    5.73 -    private String propfiles[];
    5.74 -    private String outfiles[] ;
    5.75 -    private String supers[]   ;
    5.76 -    private int compileCount = 0;
    5.77 -    private boolean quiet = false;
    5.78 -    private Log log;
    5.79 -
    5.80 -    public void setLog(Log log) {
    5.81 -        this.log = log;
    5.82 -    }
    5.83 -
    5.84 -    public boolean run(String[] args) {
    5.85 -        if (log == null) {
    5.86 -            log = new Log() {
    5.87 -                public void error(String msg, Exception e) {
    5.88 -                    System.err.println("ERROR: CompileProperties: " + msg);
    5.89 -                    if ( e != null ) {
    5.90 -                        System.err.println("EXCEPTION: " + e.toString());
    5.91 -                        e.printStackTrace();
    5.92 -                    }
    5.93 -                }
    5.94 -                public void info(String msg) {
    5.95 -                    System.out.println(msg);
    5.96 -                }
    5.97 -                public void verbose(String msg) {
    5.98 -                    if (!quiet)
    5.99 -                        System.out.println(msg);
   5.100 -                }
   5.101 -            };
   5.102 -        }
   5.103 -
   5.104 -        boolean ok = true;
   5.105 -        /* Original usage */
   5.106 -        if (args.length == 2 && args[0].charAt(0) != '-' ) {
   5.107 -            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
   5.108 -        } else if (args.length == 3) {
   5.109 -            ok = createFile(args[0], args[1], args[2]);
   5.110 -        } else if (args.length == 0) {
   5.111 -            usage(log);
   5.112 -            ok = false;
   5.113 -        } else {
   5.114 -            /* New batch usage */
   5.115 -            ok = parseOptions(args);
   5.116 -            if ( ok && compileCount == 0 ) {
   5.117 -                log.error("options parsed but no files to compile", null);
   5.118 -                ok = false;
   5.119 -            }
   5.120 -            /* Need at least one file. */
   5.121 -            if ( !ok ) {
   5.122 -                usage(log);
   5.123 -            } else {
   5.124 -                /* Process files */
   5.125 -                for ( int i = 0; i < compileCount && ok ; i++ ) {
   5.126 -                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
   5.127 -                }
   5.128 -            }
   5.129 -        }
   5.130 -        return ok;
   5.131 -    }
   5.132 -
   5.133 -    private boolean parseOptions(String args[]) {
   5.134 -        boolean ok = true;
   5.135 -        if ( compileCount > 0 ) {
   5.136 -            String new_propfiles[] = new String[compileCount + args.length];
   5.137 -            String new_outfiles[]  = new String[compileCount + args.length];
   5.138 -            String new_supers[]    = new String[compileCount + args.length];
   5.139 -            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
   5.140 -            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
   5.141 -            System.arraycopy(supers, 0, new_supers, 0, compileCount);
   5.142 -            propfiles = new_propfiles;
   5.143 -            outfiles  = new_outfiles;
   5.144 -            supers    = new_supers;
   5.145 -        } else {
   5.146 -            propfiles = new String[args.length];
   5.147 -            outfiles  = new String[args.length];
   5.148 -            supers    = new String[args.length];
   5.149 -        }
   5.150 -
   5.151 -        for ( int i = 0; i < args.length ; i++ ) {
   5.152 -            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
   5.153 -                propfiles[compileCount] = args[++i];
   5.154 -                outfiles[compileCount]  = args[++i];
   5.155 -                supers[compileCount]    = args[++i];
   5.156 -                compileCount++;
   5.157 -            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
   5.158 -                String filename = args[++i];
   5.159 -                FileInputStream finput = null;
   5.160 -                byte contents[] = null;
   5.161 -                try {
   5.162 -                    finput = new FileInputStream(filename);
   5.163 -                    int byteCount = finput.available();
   5.164 -                    if ( byteCount <= 0 ) {
   5.165 -                        log.error("The -optionsfile file is empty", null);
   5.166 -                        ok = false;
   5.167 -                    } else {
   5.168 -                        contents = new byte[byteCount];
   5.169 -                        int bytesRead = finput.read(contents);
   5.170 -                        if ( byteCount != bytesRead ) {
   5.171 -                            log.error("Cannot read all of -optionsfile file", null);
   5.172 -                            ok = false;
   5.173 -                        }
   5.174 -                    }
   5.175 -                } catch ( IOException e ) {
   5.176 -                    log.error("cannot open " + filename, e);
   5.177 -                    ok = false;
   5.178 -                }
   5.179 -                if ( finput != null ) {
   5.180 -                    try {
   5.181 -                        finput.close();
   5.182 -                    } catch ( IOException e ) {
   5.183 -                        ok = false;
   5.184 -                        log.error("cannot close " + filename, e);
   5.185 -                    }
   5.186 -                }
   5.187 -                if ( ok = true && contents != null ) {
   5.188 -                    String tokens[] = (new String(contents)).split("\\s+");
   5.189 -                    if ( tokens.length > 0 ) {
   5.190 -                        ok = parseOptions(tokens);
   5.191 -                    }
   5.192 -                }
   5.193 -                if ( !ok ) {
   5.194 -                    break;
   5.195 -                }
   5.196 -            } else if ( "-quiet".equals(args[i]) ) {
   5.197 -                quiet = true;
   5.198 -            } else {
   5.199 -                log.error("argument error", null);
   5.200 -                ok = false;
   5.201 -            }
   5.202 -        }
   5.203 -        return ok;
   5.204 -    }
   5.205 -
   5.206 -    private boolean createFile(String propertiesPath, String outputPath,
   5.207 -            String superClass) {
   5.208 -        boolean ok = true;
   5.209 -        log.verbose("parsing: " + propertiesPath);
   5.210 -        Properties p = new Properties();
   5.211 -        try {
   5.212 -            p.load(new FileInputStream(propertiesPath));
   5.213 -        } catch ( FileNotFoundException e ) {
   5.214 -            ok = false;
   5.215 -            log.error("Cannot find file " + propertiesPath, e);
   5.216 -        } catch ( IOException e ) {
   5.217 -            ok = false;
   5.218 -            log.error("IO error on file " + propertiesPath, e);
   5.219 -        }
   5.220 -        if ( ok ) {
   5.221 -            String packageName = inferPackageName(propertiesPath, outputPath);
   5.222 -            log.verbose("inferred package name: " + packageName);
   5.223 -            List<String> sortedKeys = new ArrayList<String>();
   5.224 -            for ( Object key : p.keySet() ) {
   5.225 -                sortedKeys.add((String)key);
   5.226 -            }
   5.227 -            Collections.sort(sortedKeys);
   5.228 -            Iterator<String> keys = sortedKeys.iterator();
   5.229 -
   5.230 -            StringBuffer data = new StringBuffer();
   5.231 -
   5.232 -            while (keys.hasNext()) {
   5.233 -                String key = keys.next();
   5.234 -                data.append("            { \"" + escape(key) + "\", \"" +
   5.235 -                        escape((String)p.get(key)) + "\" },\n");
   5.236 -            }
   5.237 -
   5.238 -            // Get class name from java filename, not the properties filename.
   5.239 -            //   (zh_TW properties might be used to create zh_HK files)
   5.240 -            File file = new File(outputPath);
   5.241 -            String name = file.getName();
   5.242 -            int dotIndex = name.lastIndexOf('.');
   5.243 -            String className;
   5.244 -            if (dotIndex == -1) {
   5.245 -                className = name;
   5.246 -            } else {
   5.247 -                className = name.substring(0, dotIndex);
   5.248 -            }
   5.249 -
   5.250 -            String packageString = "";
   5.251 -            if (packageName != null && !packageName.equals("")) {
   5.252 -                packageString = "package " + packageName + ";\n\n";
   5.253 -            }
   5.254 -
   5.255 -            Writer writer = null;
   5.256 -            try {
   5.257 -                writer = new BufferedWriter(
   5.258 -                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
   5.259 -                MessageFormat format = new MessageFormat(FORMAT);
   5.260 -                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
   5.261 -            } catch ( IOException e ) {
   5.262 -                ok = false;
   5.263 -                log.error("IO error writing to file " + outputPath, e);
   5.264 -            }
   5.265 -            if ( writer != null ) {
   5.266 -                try {
   5.267 -                    writer.flush();
   5.268 -                } catch ( IOException e ) {
   5.269 -                    ok = false;
   5.270 -                    log.error("IO error flush " + outputPath, e);
   5.271 -                }
   5.272 -                try {
   5.273 -                    writer.close();
   5.274 -                } catch ( IOException e ) {
   5.275 -                    ok = false;
   5.276 -                    log.error("IO error close " + outputPath, e);
   5.277 -                }
   5.278 -            }
   5.279 -            log.verbose("wrote: " + outputPath);
   5.280 -        }
   5.281 -        return ok;
   5.282 -    }
   5.283 -
   5.284 -    private static void usage(Log log) {
   5.285 -        log.info("usage:");
   5.286 -        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
   5.287 -        log.info("      -OR-");
   5.288 -        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
   5.289 -        log.info("");
   5.290 -        log.info("Example:");
   5.291 -        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
   5.292 -        log.info("    java CompileProperties -optionsfile option_file");
   5.293 -        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
   5.294 -    }
   5.295 -
   5.296 -    private static String escape(String theString) {
   5.297 -        // This is taken from Properties.saveConvert with changes for Java strings
   5.298 -        int len = theString.length();
   5.299 -        StringBuffer outBuffer = new StringBuffer(len*2);
   5.300 -
   5.301 -        for(int x=0; x<len; x++) {
   5.302 -            char aChar = theString.charAt(x);
   5.303 -            switch(aChar) {
   5.304 -                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
   5.305 -                break;
   5.306 -                case '\t':outBuffer.append('\\'); outBuffer.append('t');
   5.307 -                break;
   5.308 -                case '\n':outBuffer.append('\\'); outBuffer.append('n');
   5.309 -                break;
   5.310 -                case '\r':outBuffer.append('\\'); outBuffer.append('r');
   5.311 -                break;
   5.312 -                case '\f':outBuffer.append('\\'); outBuffer.append('f');
   5.313 -                break;
   5.314 -                default:
   5.315 -                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
   5.316 -                        outBuffer.append('\\');
   5.317 -                        outBuffer.append('u');
   5.318 -                        outBuffer.append(toHex((aChar >> 12) & 0xF));
   5.319 -                        outBuffer.append(toHex((aChar >>  8) & 0xF));
   5.320 -                        outBuffer.append(toHex((aChar >>  4) & 0xF));
   5.321 -                        outBuffer.append(toHex( aChar        & 0xF));
   5.322 -                    } else {
   5.323 -                        if (specialSaveChars.indexOf(aChar) != -1) {
   5.324 -                            outBuffer.append('\\');
   5.325 -                        }
   5.326 -                        outBuffer.append(aChar);
   5.327 -                    }
   5.328 -            }
   5.329 -        }
   5.330 -        return outBuffer.toString();
   5.331 -    }
   5.332 -
   5.333 -    private static String inferPackageName(String inputPath, String outputPath) {
   5.334 -        // Normalize file names
   5.335 -        inputPath  = new File(inputPath).getPath();
   5.336 -        outputPath = new File(outputPath).getPath();
   5.337 -        // Split into components
   5.338 -        String sep;
   5.339 -        if (File.separatorChar == '\\') {
   5.340 -            sep = "\\\\";
   5.341 -        } else {
   5.342 -            sep = File.separator;
   5.343 -        }
   5.344 -        String[] inputs  = inputPath.split(sep);
   5.345 -        String[] outputs = outputPath.split(sep);
   5.346 -        // Match common names, eliminating first "classes" entry from
   5.347 -        // each if present
   5.348 -        int inStart  = 0;
   5.349 -        int inEnd    = inputs.length - 2;
   5.350 -        int outEnd   = outputs.length - 2;
   5.351 -        int i = inEnd;
   5.352 -        int j = outEnd;
   5.353 -        while (i >= 0 && j >= 0) {
   5.354 -            if (!inputs[i].equals(outputs[j]) ||
   5.355 -                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
   5.356 -                ++i;
   5.357 -                ++j;
   5.358 -                break;
   5.359 -            }
   5.360 -            --i;
   5.361 -            --j;
   5.362 -        }
   5.363 -        String result;
   5.364 -        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
   5.365 -            result = "";
   5.366 -        } else {
   5.367 -            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
   5.368 -                ++i;
   5.369 -            }
   5.370 -            inStart = i;
   5.371 -            StringBuffer buf = new StringBuffer();
   5.372 -            for (i = inStart; i <= inEnd; i++) {
   5.373 -                buf.append(inputs[i]);
   5.374 -                if (i < inEnd) {
   5.375 -                    buf.append('.');
   5.376 -                }
   5.377 -            }
   5.378 -            result = buf.toString();
   5.379 -        }
   5.380 -        return result;
   5.381 -    }
   5.382 -
   5.383 -    private static final String FORMAT =
   5.384 -            "{0}" +
   5.385 -            "public final class {1} extends {2} '{'\n" +
   5.386 -            "    protected final Object[][] getContents() '{'\n" +
   5.387 -            "        return new Object[][] '{'\n" +
   5.388 -            "{3}" +
   5.389 -            "        };\n" +
   5.390 -            "    }\n" +
   5.391 -            "}\n";
   5.392 -
   5.393 -    // This comes from Properties
   5.394 -    private static char toHex(int nibble) {
   5.395 -        return hexDigit[(nibble & 0xF)];
   5.396 -    }
   5.397 -
   5.398 -    // This comes from Properties
   5.399 -    private static final char[] hexDigit = {
   5.400 -        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
   5.401 -    };
   5.402 -
   5.403 -    // Note: different from that in Properties
   5.404 -    private static final String specialSaveChars = "\"";
   5.405 -}
     6.1 --- a/make/tools/CompileProperties/CompilePropertiesTask.java	Thu Mar 08 20:35:26 2012 -0800
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,97 +0,0 @@
     6.4 -/*
     6.5 - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 - *
     6.8 - * This code is free software; you can redistribute it and/or modify it
     6.9 - * under the terms of the GNU General Public License version 2 only, as
    6.10 - * published by the Free Software Foundation.  Oracle designates this
    6.11 - * particular file as subject to the "Classpath" exception as provided
    6.12 - * by Oracle in the LICENSE file that accompanied this code.
    6.13 - *
    6.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 - * version 2 for more details (a copy is included in the LICENSE file that
    6.18 - * accompanied this code).
    6.19 - *
    6.20 - * You should have received a copy of the GNU General Public License version
    6.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 - *
    6.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.25 - * or visit www.oracle.com if you need additional information or have any
    6.26 - * questions.
    6.27 - */
    6.28 -
    6.29 -import java.io.File;
    6.30 -import java.util.ArrayList;
    6.31 -import java.util.List;
    6.32 -
    6.33 -import org.apache.tools.ant.BuildException;
    6.34 -import org.apache.tools.ant.DirectoryScanner;
    6.35 -import org.apache.tools.ant.Project;
    6.36 -import org.apache.tools.ant.taskdefs.MatchingTask;
    6.37 -
    6.38 -public class CompilePropertiesTask extends MatchingTask {
    6.39 -    public void setSrcDir(File srcDir) {
    6.40 -        this.srcDir = srcDir;
    6.41 -    }
    6.42 -
    6.43 -    public void setDestDir(File destDir) {
    6.44 -        this.destDir = destDir;
    6.45 -    }
    6.46 -
    6.47 -    public void setSuperclass(String superclass) {
    6.48 -        this.superclass = superclass;
    6.49 -    }
    6.50 -
    6.51 -    @Override
    6.52 -    public void execute() {
    6.53 -        CompileProperties.Log log = new CompileProperties.Log() {
    6.54 -            public void error(String msg, Exception e) {
    6.55 -                log(msg, Project.MSG_ERR);
    6.56 -            }
    6.57 -            public void info(String msg) {
    6.58 -                log(msg, Project.MSG_INFO);
    6.59 -            }
    6.60 -            public void verbose(String msg) {
    6.61 -                log(msg, Project.MSG_VERBOSE);
    6.62 -            }
    6.63 -        };
    6.64 -        List<String> mainOpts = new ArrayList<String>();
    6.65 -        int count = 0;
    6.66 -        DirectoryScanner s = getDirectoryScanner(srcDir);
    6.67 -        for (String path: s.getIncludedFiles()) {
    6.68 -            if (path.endsWith(".properties")) {
    6.69 -                String destPath =
    6.70 -                        path.substring(0, path.length() - ".properties".length()) +
    6.71 -                        ".java";
    6.72 -                File srcFile = new File(srcDir, path);
    6.73 -                File destFile = new File(destDir, destPath);
    6.74 -                // Arguably, the comparison in the next line should be ">", not ">="
    6.75 -                // but that assumes the resolution of the last modified time is fine
    6.76 -                // grained enough; in practice, it is better to use ">=".
    6.77 -                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
    6.78 -                    continue;
    6.79 -                destFile.getParentFile().mkdirs();
    6.80 -                mainOpts.add("-compile");
    6.81 -                mainOpts.add(srcFile.getPath());
    6.82 -                mainOpts.add(destFile.getPath());
    6.83 -                mainOpts.add(superclass);
    6.84 -                count++;
    6.85 -            }
    6.86 -        }
    6.87 -        if (mainOpts.size() > 0) {
    6.88 -            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
    6.89 -            CompileProperties cp = new CompileProperties();
    6.90 -            cp.setLog(log);
    6.91 -            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
    6.92 -            if (!ok)
    6.93 -                throw new BuildException("CompileProperties failed.");
    6.94 -        }
    6.95 -    }
    6.96 -
    6.97 -    private File srcDir;
    6.98 -    private File destDir;
    6.99 -    private String superclass = "java.util.ListResourceBundle";
   6.100 -}
     7.1 --- a/make/tools/GenStubs/GenStubs.java	Thu Mar 08 20:35:26 2012 -0800
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,448 +0,0 @@
     7.4 -/*
     7.5 - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
     7.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 - *
     7.8 - * This code is free software; you can redistribute it and/or modify it
     7.9 - * under the terms of the GNU General Public License version 2 only, as
    7.10 - * published by the Free Software Foundation.  Oracle designates this
    7.11 - * particular file as subject to the "Classpath" exception as provided
    7.12 - * by Oracle in the LICENSE file that accompanied this code.
    7.13 - *
    7.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 - * version 2 for more details (a copy is included in the LICENSE file that
    7.18 - * accompanied this code).
    7.19 - *
    7.20 - * You should have received a copy of the GNU General Public License version
    7.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 - *
    7.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.25 - * or visit www.oracle.com if you need additional information or have any
    7.26 - * questions.
    7.27 - */
    7.28 -
    7.29 -import java.io.*;
    7.30 -import java.util.*;
    7.31 -import javax.tools.JavaFileObject;
    7.32 -import javax.tools.StandardJavaFileManager;
    7.33 -import javax.tools.StandardLocation;
    7.34 -
    7.35 -import org.apache.tools.ant.BuildException;
    7.36 -import org.apache.tools.ant.DirectoryScanner;
    7.37 -import org.apache.tools.ant.taskdefs.MatchingTask;
    7.38 -import org.apache.tools.ant.types.Path;
    7.39 -import org.apache.tools.ant.types.Reference;
    7.40 -
    7.41 -
    7.42 -import com.sun.source.tree.CompilationUnitTree;
    7.43 -import com.sun.source.util.JavacTask;
    7.44 -import com.sun.tools.javac.api.JavacTool;
    7.45 -import com.sun.tools.javac.code.Flags;
    7.46 -import com.sun.tools.javac.code.TypeTags;
    7.47 -import com.sun.tools.javac.tree.JCTree;
    7.48 -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
    7.49 -import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
    7.50 -import com.sun.tools.javac.tree.JCTree.JCIdent;
    7.51 -import com.sun.tools.javac.tree.JCTree.JCImport;
    7.52 -import com.sun.tools.javac.tree.JCTree.JCLiteral;
    7.53 -import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
    7.54 -import com.sun.tools.javac.tree.JCTree.JCModifiers;
    7.55 -import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
    7.56 -import com.sun.tools.javac.tree.Pretty;
    7.57 -import com.sun.tools.javac.tree.TreeMaker;
    7.58 -import com.sun.tools.javac.tree.TreeScanner;
    7.59 -import com.sun.tools.javac.tree.TreeTranslator;
    7.60 -import com.sun.tools.javac.util.Context;
    7.61 -import com.sun.tools.javac.util.ListBuffer;
    7.62 -import com.sun.tools.javac.util.Name;
    7.63 -import javax.tools.JavaFileManager;
    7.64 -
    7.65 -/**
    7.66 - * Generate stub source files by removing implementation details from input files.
    7.67 - *
    7.68 - * This is a special purpose stub generator, specific to the needs of generating
    7.69 - * stub files for JDK 7 API that are needed to compile langtools files that depend
    7.70 - * on that API. The stub generator works by removing as much of the API source code
    7.71 - * as possible without affecting the public signature, in order to reduce the
    7.72 - * transitive closure of the API being referenced. The resulting stubs can be
    7.73 - * put on the langtools sourcepath with -implicit:none to compile the langtools
    7.74 - * files that depend on the JDK 7 API.
    7.75 - *
    7.76 - * Usage:
    7.77 - *  genstubs -s <outdir> -sourcepath <path> <classnames>
    7.78 - *
    7.79 - * The specified class names are looked up on the sourcepath, and corresponding
    7.80 - * stubs are written to the source output directory.
    7.81 - *
    7.82 - * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
    7.83 - * to remove implementation details, and written out in the source output directory.
    7.84 - * Documentation comments and annotations are removed. Method bodies are removed
    7.85 - * and methods are marked native. Private and package-private field definitions
    7.86 - * have their initializers replace with 0, 0.0, false, null as appropriate.
    7.87 - *
    7.88 - * An Ant task, Main$Ant is also provided. Files are specified with an implicit
    7.89 - * fileset, using srcdir as a base directory. The set of files to be included
    7.90 - * is specified with an includes attribute or nested <includes> set. However,
    7.91 - * unlike a normal fileset, an empty includes attribute means "no files" instead
    7.92 - * of "all files".  The Ant task also accepts "fork=true" and classpath attribute
    7.93 - * or nested <classpath> element to run GenStubs in a separate VM with the specified
    7.94 - * path. This is likely necessary if a JDK 7 parser is required to read the
    7.95 - * JDK 7 input files.
    7.96 - */
    7.97 -
    7.98 -public class GenStubs {
    7.99 -    static class Fault extends Exception {
   7.100 -        private static final long serialVersionUID = 0;
   7.101 -        Fault(String message) {
   7.102 -            super(message);
   7.103 -        }
   7.104 -        Fault(String message, Throwable cause) {
   7.105 -            super(message);
   7.106 -            initCause(cause);
   7.107 -        }
   7.108 -    }
   7.109 -
   7.110 -    public static void main(String[] args) {
   7.111 -        boolean ok = new GenStubs().run(args);
   7.112 -        if (!ok)
   7.113 -            System.exit(1);
   7.114 -    }
   7.115 -
   7.116 -    boolean run(String... args) {
   7.117 -        File outdir = null;
   7.118 -        String sourcepath = null;
   7.119 -        List<String> classes = new ArrayList<String>();
   7.120 -        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
   7.121 -            String arg = iter.next();
   7.122 -            if (arg.equals("-s") && iter.hasNext())
   7.123 -                outdir = new File(iter.next());
   7.124 -            else if (arg.equals("-sourcepath") && iter.hasNext())
   7.125 -                sourcepath = iter.next();
   7.126 -            else if (arg.startsWith("-"))
   7.127 -                throw new IllegalArgumentException(arg);
   7.128 -            else {
   7.129 -                classes.add(arg);
   7.130 -                while (iter.hasNext())
   7.131 -                    classes.add(iter.next());
   7.132 -            }
   7.133 -        }
   7.134 -
   7.135 -        return run(sourcepath, outdir, classes);
   7.136 -    }
   7.137 -
   7.138 -    boolean run(String sourcepath, File outdir, List<String> classes) {
   7.139 -        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
   7.140 -        if (sourcepath == null)
   7.141 -            throw new IllegalArgumentException("sourcepath not set");
   7.142 -        if (outdir == null)
   7.143 -            throw new IllegalArgumentException("source output dir not set");
   7.144 -
   7.145 -        JavacTool tool = JavacTool.create();
   7.146 -        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
   7.147 -
   7.148 -        try {
   7.149 -            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
   7.150 -            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
   7.151 -            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
   7.152 -            for (String c: classes) {
   7.153 -                JavaFileObject fo = fm.getJavaFileForInput(
   7.154 -                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
   7.155 -                if (fo == null)
   7.156 -                    error("class not found: " + c);
   7.157 -                else
   7.158 -                    files.add(fo);
   7.159 -            }
   7.160 -
   7.161 -            JavacTask t = tool.getTask(null, fm, null, null, null, files);
   7.162 -            Iterable<? extends CompilationUnitTree> trees = t.parse();
   7.163 -            for (CompilationUnitTree tree: trees) {
   7.164 -                makeStub(fm, tree);
   7.165 -            }
   7.166 -        } catch (IOException e) {
   7.167 -            error("IO error " + e, e);
   7.168 -        }
   7.169 -
   7.170 -        return (errors == 0);
   7.171 -    }
   7.172 -
   7.173 -    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
   7.174 -        CompilationUnitTree tree2 = new StubMaker().translate(tree);
   7.175 -        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
   7.176 -
   7.177 -        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
   7.178 -        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
   7.179 -                className, JavaFileObject.Kind.SOURCE, null);
   7.180 -        // System.err.println("Writing " + className + " to " + fo.getName());
   7.181 -        Writer out = fo.openWriter();
   7.182 -        try {
   7.183 -            new Pretty(out, true).printExpr((JCTree) tree3);
   7.184 -        } finally {
   7.185 -            out.close();
   7.186 -        }
   7.187 -    }
   7.188 -
   7.189 -    List<File> splitPath(String path) {
   7.190 -        List<File> list = new ArrayList<File>();
   7.191 -        for (String p: path.split(File.pathSeparator)) {
   7.192 -            if (p.length() > 0)
   7.193 -                list.add(new File(p));
   7.194 -        }
   7.195 -        return list;
   7.196 -    }
   7.197 -
   7.198 -    void error(String message) {
   7.199 -        System.err.println(message);
   7.200 -        errors++;
   7.201 -    }
   7.202 -
   7.203 -    void error(String message, Throwable cause) {
   7.204 -        error(message);
   7.205 -    }
   7.206 -
   7.207 -    int errors;
   7.208 -
   7.209 -    class StubMaker extends TreeTranslator {
   7.210 -        CompilationUnitTree translate(CompilationUnitTree tree) {
   7.211 -            return super.translate((JCCompilationUnit) tree);
   7.212 -        }
   7.213 -
   7.214 -        /**
   7.215 -         * compilation units: remove javadoc comments
   7.216 -         * -- required, in order to remove @deprecated tags, since we
   7.217 -         * (separately) remove all annotations, including @Deprecated
   7.218 -         */
   7.219 -        public void visitTopLevel(JCCompilationUnit tree) {
   7.220 -            super.visitTopLevel(tree);
   7.221 -            tree.docComments = Collections.emptyMap();
   7.222 -        }
   7.223 -
   7.224 -        /**
   7.225 -         * methods: remove method bodies, make methods native
   7.226 -         */
   7.227 -        @Override
   7.228 -        public void visitMethodDef(JCMethodDecl tree) {
   7.229 -            tree.mods = translate(tree.mods);
   7.230 -            tree.restype = translate(tree.restype);
   7.231 -            tree.typarams = translateTypeParams(tree.typarams);
   7.232 -            tree.params = translateVarDefs(tree.params);
   7.233 -            tree.thrown = translate(tree.thrown);
   7.234 -            if (tree.restype != null && tree.body != null) {
   7.235 -                tree.mods.flags |= Flags.NATIVE;
   7.236 -                tree.body = null;
   7.237 -            }
   7.238 -            result = tree;
   7.239 -        }
   7.240 -
   7.241 -        /**
   7.242 -         * modifiers: remove annotations
   7.243 -         */
   7.244 -        @Override
   7.245 -        public void visitModifiers(JCModifiers tree) {
   7.246 -            tree.annotations = com.sun.tools.javac.util.List.nil();
   7.247 -            result = tree;
   7.248 -        }
   7.249 -
   7.250 -        /**
   7.251 -         * field definitions: replace initializers with 0, 0.0, false etc
   7.252 -         * when possible -- i.e. leave public, protected initializers alone
   7.253 -         */
   7.254 -        @Override
   7.255 -        public void visitVarDef(JCVariableDecl tree) {
   7.256 -            tree.mods = translate(tree.mods);
   7.257 -            tree.vartype = translate(tree.vartype);
   7.258 -            if (tree.init != null) {
   7.259 -                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
   7.260 -                    tree.init = translate(tree.init);
   7.261 -                else {
   7.262 -                    String t = tree.vartype.toString();
   7.263 -                    if (t.equals("boolean"))
   7.264 -                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
   7.265 -                    else if (t.equals("byte"))
   7.266 -                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
   7.267 -                    else if (t.equals("char"))
   7.268 -                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
   7.269 -                    else if (t.equals("double"))
   7.270 -                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
   7.271 -                    else if (t.equals("float"))
   7.272 -                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
   7.273 -                    else if (t.equals("int"))
   7.274 -                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
   7.275 -                    else if (t.equals("long"))
   7.276 -                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
   7.277 -                    else if (t.equals("short"))
   7.278 -                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
   7.279 -                    else
   7.280 -                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
   7.281 -                }
   7.282 -            }
   7.283 -            result = tree;
   7.284 -        }
   7.285 -    }
   7.286 -
   7.287 -    class ImportCleaner extends TreeScanner {
   7.288 -        private Set<Name> names = new HashSet<Name>();
   7.289 -        private TreeMaker m;
   7.290 -
   7.291 -        ImportCleaner(JavaFileManager fm) {
   7.292 -            // ImportCleaner itself doesn't require a filemanager, but instantiating
   7.293 -            // a TreeMaker does, indirectly (via ClassReader, sigh)
   7.294 -            Context c = new Context();
   7.295 -            c.put(JavaFileManager.class, fm);
   7.296 -            m = TreeMaker.instance(c);
   7.297 -        }
   7.298 -
   7.299 -        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
   7.300 -            JCCompilationUnit tree = (JCCompilationUnit) t;
   7.301 -            tree.accept(this);
   7.302 -            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
   7.303 -            for (JCTree def: tree.defs) {
   7.304 -                if (def.getTag() == JCTree.IMPORT) {
   7.305 -                    JCImport imp = (JCImport) def;
   7.306 -                    if (imp.qualid.getTag() == JCTree.SELECT) {
   7.307 -                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
   7.308 -                        if (!qualid.name.toString().equals("*")
   7.309 -                                && !names.contains(qualid.name)) {
   7.310 -                            continue;
   7.311 -                        }
   7.312 -                    }
   7.313 -                }
   7.314 -                defs.add(def);
   7.315 -            }
   7.316 -            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
   7.317 -        }
   7.318 -
   7.319 -        @Override
   7.320 -        public void visitImport(JCImport tree) { } // ignore names found in imports
   7.321 -
   7.322 -        @Override
   7.323 -        public void visitIdent(JCIdent tree) {
   7.324 -            names.add(tree.name);
   7.325 -        }
   7.326 -
   7.327 -        @Override
   7.328 -        public void visitSelect(JCFieldAccess tree) {
   7.329 -            super.visitSelect(tree);
   7.330 -            names.add(tree.name);
   7.331 -        }
   7.332 -    }
   7.333 -
   7.334 -    //---------- Ant Invocation ------------------------------------------------
   7.335 -
   7.336 -    public static class Ant extends MatchingTask {
   7.337 -        private File srcDir;
   7.338 -        private File destDir;
   7.339 -        private boolean fork;
   7.340 -        private Path classpath;
   7.341 -        private String includes;
   7.342 -
   7.343 -        public void setSrcDir(File dir) {
   7.344 -            this.srcDir = dir;
   7.345 -        }
   7.346 -
   7.347 -        public void setDestDir(File dir) {
   7.348 -            this.destDir = dir;
   7.349 -        }
   7.350 -
   7.351 -        public void setFork(boolean v) {
   7.352 -            this.fork = v;
   7.353 -        }
   7.354 -
   7.355 -        public void setClasspath(Path cp) {
   7.356 -            if (classpath == null)
   7.357 -                classpath = cp;
   7.358 -            else
   7.359 -                classpath.append(cp);
   7.360 -        }
   7.361 -
   7.362 -        public Path createClasspath() {
   7.363 -            if (classpath == null) {
   7.364 -                classpath = new Path(getProject());
   7.365 -            }
   7.366 -            return classpath.createPath();
   7.367 -        }
   7.368 -
   7.369 -        public void setClasspathRef(Reference r) {
   7.370 -            createClasspath().setRefid(r);
   7.371 -        }
   7.372 -
   7.373 -        public void setIncludes(String includes) {
   7.374 -            super.setIncludes(includes);
   7.375 -            this.includes = includes;
   7.376 -        }
   7.377 -
   7.378 -        @Override
   7.379 -        public void execute() {
   7.380 -            if (includes != null && includes.trim().isEmpty())
   7.381 -                return;
   7.382 -
   7.383 -            DirectoryScanner s = getDirectoryScanner(srcDir);
   7.384 -            String[] files = s.getIncludedFiles();
   7.385 -//            System.err.println("Ant.execute: srcDir " + srcDir);
   7.386 -//            System.err.println("Ant.execute: destDir " + destDir);
   7.387 -//            System.err.println("Ant.execute: files " + Arrays.asList(files));
   7.388 -
   7.389 -            files = filter(srcDir, destDir, files);
   7.390 -            if (files.length == 0)
   7.391 -                return;
   7.392 -            System.out.println("Generating " + files.length + " stub files to " + destDir);
   7.393 -
   7.394 -            List<String> classNames = new ArrayList<String>();
   7.395 -            for (String file: files) {
   7.396 -                classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
   7.397 -            }
   7.398 -
   7.399 -            if (!fork) {
   7.400 -                GenStubs m = new GenStubs();
   7.401 -                boolean ok = m.run(srcDir.getPath(), destDir, classNames);
   7.402 -                if (!ok)
   7.403 -                    throw new BuildException("genstubs failed");
   7.404 -            } else {
   7.405 -                List<String> cmd = new ArrayList<String>();
   7.406 -                String java_home = System.getProperty("java.home");
   7.407 -                cmd.add(new File(new File(java_home, "bin"), "java").getPath());
   7.408 -                if (classpath != null)
   7.409 -                    cmd.add("-Xbootclasspath/p:" + classpath);
   7.410 -                cmd.add(GenStubs.class.getName());
   7.411 -                cmd.add("-sourcepath");
   7.412 -                cmd.add(srcDir.getPath());
   7.413 -                cmd.add("-s");
   7.414 -                cmd.add(destDir.getPath());
   7.415 -                cmd.addAll(classNames);
   7.416 -                //System.err.println("GenStubs exec " + cmd);
   7.417 -                ProcessBuilder pb = new ProcessBuilder(cmd);
   7.418 -                pb.redirectErrorStream(true);
   7.419 -                try {
   7.420 -                    Process p = pb.start();
   7.421 -                    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
   7.422 -                    try {
   7.423 -                        String line;
   7.424 -                        while ((line = in.readLine()) != null)
   7.425 -                            System.out.println(line);
   7.426 -                    } finally {
   7.427 -                        in.close();
   7.428 -                    }
   7.429 -                    int rc = p.waitFor();
   7.430 -                    if (rc != 0)
   7.431 -                        throw new BuildException("genstubs failed");
   7.432 -                } catch (IOException e) {
   7.433 -                    throw new BuildException("genstubs failed", e);
   7.434 -                } catch (InterruptedException e) {
   7.435 -                    throw new BuildException("genstubs failed", e);
   7.436 -                }
   7.437 -            }
   7.438 -        }
   7.439 -
   7.440 -        String[] filter(File srcDir, File destDir, String[] files) {
   7.441 -            List<String> results = new ArrayList<String>();
   7.442 -            for (String f: files) {
   7.443 -                long srcTime = new File(srcDir, f).lastModified();
   7.444 -                long destTime = new File(destDir, f).lastModified();
   7.445 -                if (srcTime > destTime)
   7.446 -                    results.add(f);
   7.447 -            }
   7.448 -            return results.toArray(new String[results.size()]);
   7.449 -        }
   7.450 -    }
   7.451 -}
     8.1 --- a/make/tools/SelectTool/SelectToolTask.java	Thu Mar 08 20:35:26 2012 -0800
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,284 +0,0 @@
     8.4 -/*
     8.5 - * Copyright (c) 2008, 2009, 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 -import java.awt.GridBagConstraints;
    8.30 -import java.awt.GridBagLayout;
    8.31 -import java.awt.event.ActionEvent;
    8.32 -import java.awt.event.ActionListener;
    8.33 -import java.awt.event.FocusEvent;
    8.34 -import java.awt.event.FocusListener;
    8.35 -import java.awt.event.ItemEvent;
    8.36 -import java.awt.event.ItemListener;
    8.37 -import java.io.BufferedReader;
    8.38 -import java.io.BufferedWriter;
    8.39 -import java.io.File;
    8.40 -import java.io.FileReader;
    8.41 -import java.io.FileWriter;
    8.42 -import java.io.IOException;
    8.43 -import java.io.Reader;
    8.44 -import java.io.Writer;
    8.45 -import java.util.ArrayList;
    8.46 -import java.util.Arrays;
    8.47 -import java.util.List;
    8.48 -import java.util.Properties;
    8.49 -import javax.swing.JButton;
    8.50 -import javax.swing.JCheckBox;
    8.51 -import javax.swing.JComboBox;
    8.52 -import javax.swing.JDialog;
    8.53 -import javax.swing.JLabel;
    8.54 -import javax.swing.JOptionPane;
    8.55 -import javax.swing.JPanel;
    8.56 -import javax.swing.JTextField;
    8.57 -
    8.58 -import javax.swing.SwingUtilities;
    8.59 -import org.apache.tools.ant.BuildException;
    8.60 -import org.apache.tools.ant.Project;
    8.61 -import org.apache.tools.ant.Task;
    8.62 -
    8.63 -/**
    8.64 - * Task to allow the user to control langtools tools built when using NetBeans.
    8.65 - *
    8.66 - * There are two primary modes.
    8.67 - * 1) Property mode. In this mode, property names are provided to get values
    8.68 - * that may be specified by the user, either directly in a GUI dialog, or
    8.69 - * read from a properties file. If the GUI dialog is invoked, values may
    8.70 - * optionally be set for future use.
    8.71 - * 2) Setup mode. In this mode, no property names are provided, and the GUI
    8.72 - * is invoked to allow the user to set or reset values for use in property mode.
    8.73 - */
    8.74 -public class SelectToolTask extends Task {
    8.75 -    /**
    8.76 -     * Set the location of the private properties file used to keep the retain
    8.77 -     * user preferences for this repository.
    8.78 -     */
    8.79 -    public void setPropertyFile(File propertyFile) {
    8.80 -        this.propertyFile = propertyFile;
    8.81 -    }
    8.82 -
    8.83 -    /**
    8.84 -     * Set the name of the property which will be set to the name of the
    8.85 -     * selected tool, if any. If no tool is selected, the property will
    8.86 -     * remain unset.
    8.87 -     */
    8.88 -    public void setToolProperty(String toolProperty) {
    8.89 -        this.toolProperty = toolProperty;
    8.90 -    }
    8.91 -
    8.92 -    /**
    8.93 -     * Set the name of the property which will be set to the execution args of the
    8.94 -     * selected tool, if any. The args default to an empty string.
    8.95 -     */
    8.96 -    public void setArgsProperty(String argsProperty) {
    8.97 -        this.argsProperty = argsProperty;
    8.98 -    }
    8.99 -
   8.100 -    /**
   8.101 -     * Specify whether or not to pop up a dialog if the user has not specified
   8.102 -     * a default value for a property.
   8.103 -     */
   8.104 -    public void setAskIfUnset(boolean askIfUnset) {
   8.105 -        this.askIfUnset = askIfUnset;
   8.106 -    }
   8.107 -
   8.108 -    @Override
   8.109 -    public void execute() {
   8.110 -        Project p = getProject();
   8.111 -
   8.112 -        Properties props = readProperties(propertyFile);
   8.113 -        toolName = props.getProperty("tool.name");
   8.114 -        if (toolName != null) {
   8.115 -            toolArgs = props.getProperty(toolName + ".args", "");
   8.116 -        }
   8.117 -
   8.118 -        if (toolProperty == null ||
   8.119 -            askIfUnset && (toolName == null
   8.120 -                || (argsProperty != null && toolArgs == null))) {
   8.121 -            showGUI(props);
   8.122 -        }
   8.123 -
   8.124 -        // finally, return required values, if any
   8.125 -        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
   8.126 -            p.setProperty(toolProperty, toolName);
   8.127 -
   8.128 -            if (argsProperty != null && toolArgs != null)
   8.129 -                p.setProperty(argsProperty, toolArgs);
   8.130 -        }
   8.131 -    }
   8.132 -
   8.133 -    void showGUI(Properties fileProps) {
   8.134 -        Properties guiProps = new Properties(fileProps);
   8.135 -        JOptionPane p = createPane(guiProps);
   8.136 -        p.createDialog("Select Tool").setVisible(true);
   8.137 -
   8.138 -        toolName = (String) toolChoice.getSelectedItem();
   8.139 -        toolArgs = argsField.getText();
   8.140 -
   8.141 -        if (defaultCheck.isSelected()) {
   8.142 -            if (toolName.equals("")) {
   8.143 -                fileProps.remove("tool.name");
   8.144 -            } else {
   8.145 -                fileProps.put("tool.name", toolName);
   8.146 -                fileProps.put(toolName + ".args", toolArgs);
   8.147 -            }
   8.148 -            writeProperties(propertyFile, fileProps);
   8.149 -        }
   8.150 -    }
   8.151 -
   8.152 -    JOptionPane createPane(final Properties props) {
   8.153 -        JPanel body = new JPanel(new GridBagLayout());
   8.154 -        GridBagConstraints lc = new GridBagConstraints();
   8.155 -        lc.insets.right = 10;
   8.156 -        lc.insets.bottom = 3;
   8.157 -        GridBagConstraints fc = new GridBagConstraints();
   8.158 -        fc.anchor = GridBagConstraints.WEST;
   8.159 -        fc.gridx = 1;
   8.160 -        fc.gridwidth = GridBagConstraints.REMAINDER;
   8.161 -        fc.insets.bottom = 3;
   8.162 -
   8.163 -        JLabel toolLabel = new JLabel("Tool:");
   8.164 -        body.add(toolLabel, lc);
   8.165 -        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
   8.166 -        if (true || toolProperty == null) {
   8.167 -            // include empty value in setup mode
   8.168 -            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
   8.169 -            l.add(0, "");
   8.170 -            toolChoices = l.toArray(new String[l.size()]);
   8.171 -        }
   8.172 -        toolChoice = new JComboBox(toolChoices);
   8.173 -        if (toolName != null)
   8.174 -            toolChoice.setSelectedItem(toolName);
   8.175 -        toolChoice.addItemListener(new ItemListener() {
   8.176 -            public void itemStateChanged(ItemEvent e) {
   8.177 -                String tn = (String) e.getItem();
   8.178 -                argsField.setText(getDefaultArgsForTool(props, tn));
   8.179 -                if (toolProperty != null)
   8.180 -                    okButton.setEnabled(!tn.equals(""));
   8.181 -            }
   8.182 -        });
   8.183 -        body.add(toolChoice, fc);
   8.184 -
   8.185 -        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
   8.186 -        if (toolProperty == null || argsProperty != null) {
   8.187 -            JLabel argsLabel = new JLabel("Args:");
   8.188 -            body.add(argsLabel, lc);
   8.189 -            body.add(argsField, fc);
   8.190 -            argsField.addFocusListener(new FocusListener() {
   8.191 -                public void focusGained(FocusEvent e) {
   8.192 -                }
   8.193 -                public void focusLost(FocusEvent e) {
   8.194 -                    String toolName = (String) toolChoice.getSelectedItem();
   8.195 -                    if (toolName.length() > 0)
   8.196 -                        props.put(toolName + ".args", argsField.getText());
   8.197 -                }
   8.198 -            });
   8.199 -        }
   8.200 -
   8.201 -        defaultCheck = new JCheckBox("Set as default");
   8.202 -        if (toolProperty == null)
   8.203 -            defaultCheck.setSelected(true);
   8.204 -        else
   8.205 -            body.add(defaultCheck, fc);
   8.206 -
   8.207 -        final JOptionPane p = new JOptionPane(body);
   8.208 -        okButton = new JButton("OK");
   8.209 -        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
   8.210 -        okButton.addActionListener(new ActionListener() {
   8.211 -            public void actionPerformed(ActionEvent e) {
   8.212 -                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
   8.213 -                d.setVisible(false);
   8.214 -            }
   8.215 -        });
   8.216 -        p.setOptions(new Object[] { okButton });
   8.217 -
   8.218 -        return p;
   8.219 -    }
   8.220 -
   8.221 -    Properties readProperties(File file) {
   8.222 -        Properties p = new Properties();
   8.223 -        if (file != null && file.exists()) {
   8.224 -            Reader in = null;
   8.225 -            try {
   8.226 -                in = new BufferedReader(new FileReader(file));
   8.227 -                p.load(in);
   8.228 -                in.close();
   8.229 -            } catch (IOException e) {
   8.230 -                throw new BuildException("error reading property file", e);
   8.231 -            } finally {
   8.232 -                if (in != null) {
   8.233 -                    try {
   8.234 -                        in.close();
   8.235 -                    } catch (IOException e) {
   8.236 -                        throw new BuildException("cannot close property file", e);
   8.237 -                    }
   8.238 -                }
   8.239 -            }
   8.240 -        }
   8.241 -        return p;
   8.242 -    }
   8.243 -
   8.244 -    void writeProperties(File file, Properties p) {
   8.245 -        if (file != null) {
   8.246 -            Writer out = null;
   8.247 -            try {
   8.248 -                File dir = file.getParentFile();
   8.249 -                if (dir != null && !dir.exists())
   8.250 -                    dir.mkdirs();
   8.251 -                out = new BufferedWriter(new FileWriter(file));
   8.252 -                p.store(out, "langtools properties");
   8.253 -                out.close();
   8.254 -            } catch (IOException e) {
   8.255 -                throw new BuildException("error writing property file", e);
   8.256 -            } finally {
   8.257 -                if (out != null) {
   8.258 -                    try {
   8.259 -                        out.close();
   8.260 -                    } catch (IOException e) {
   8.261 -                        throw new BuildException("cannot close property file", e);
   8.262 -                    }
   8.263 -                }
   8.264 -            }
   8.265 -        }
   8.266 -    }
   8.267 -
   8.268 -    String getDefaultArgsForTool(Properties props, String tn) {
   8.269 -        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
   8.270 -    }
   8.271 -
   8.272 -    // Ant task parameters
   8.273 -    private boolean askIfUnset;
   8.274 -    private String toolProperty;
   8.275 -    private String argsProperty;
   8.276 -    private File propertyFile;
   8.277 -
   8.278 -    // GUI components
   8.279 -    private JComboBox toolChoice;
   8.280 -    private JTextField argsField;
   8.281 -    private JCheckBox defaultCheck;
   8.282 -    private JButton okButton;
   8.283 -
   8.284 -    // Result values for the client
   8.285 -    private String toolName;
   8.286 -    private String toolArgs;
   8.287 -}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/make/tools/anttasks/CompilePropertiesTask.java	Fri Mar 09 11:59:26 2012 -0800
     9.3 @@ -0,0 +1,101 @@
     9.4 +/*
     9.5 + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.  Oracle designates this
    9.11 + * particular file as subject to the "Classpath" exception as provided
    9.12 + * by Oracle in the LICENSE file that accompanied this code.
    9.13 + *
    9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.17 + * version 2 for more details (a copy is included in the LICENSE file that
    9.18 + * accompanied this code).
    9.19 + *
    9.20 + * You should have received a copy of the GNU General Public License version
    9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.23 + *
    9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.25 + * or visit www.oracle.com if you need additional information or have any
    9.26 + * questions.
    9.27 + */
    9.28 +
    9.29 +package anttasks;
    9.30 +
    9.31 +import compileproperties.CompileProperties;
    9.32 +
    9.33 +import java.io.File;
    9.34 +import java.util.ArrayList;
    9.35 +import java.util.List;
    9.36 +
    9.37 +import org.apache.tools.ant.BuildException;
    9.38 +import org.apache.tools.ant.DirectoryScanner;
    9.39 +import org.apache.tools.ant.Project;
    9.40 +import org.apache.tools.ant.taskdefs.MatchingTask;
    9.41 +
    9.42 +public class CompilePropertiesTask extends MatchingTask {
    9.43 +    public void setSrcDir(File srcDir) {
    9.44 +        this.srcDir = srcDir;
    9.45 +    }
    9.46 +
    9.47 +    public void setDestDir(File destDir) {
    9.48 +        this.destDir = destDir;
    9.49 +    }
    9.50 +
    9.51 +    public void setSuperclass(String superclass) {
    9.52 +        this.superclass = superclass;
    9.53 +    }
    9.54 +
    9.55 +    @Override
    9.56 +    public void execute() {
    9.57 +        CompileProperties.Log log = new CompileProperties.Log() {
    9.58 +            public void error(String msg, Exception e) {
    9.59 +                log(msg, Project.MSG_ERR);
    9.60 +            }
    9.61 +            public void info(String msg) {
    9.62 +                log(msg, Project.MSG_INFO);
    9.63 +            }
    9.64 +            public void verbose(String msg) {
    9.65 +                log(msg, Project.MSG_VERBOSE);
    9.66 +            }
    9.67 +        };
    9.68 +        List<String> mainOpts = new ArrayList<String>();
    9.69 +        int count = 0;
    9.70 +        DirectoryScanner s = getDirectoryScanner(srcDir);
    9.71 +        for (String path: s.getIncludedFiles()) {
    9.72 +            if (path.endsWith(".properties")) {
    9.73 +                String destPath =
    9.74 +                        path.substring(0, path.length() - ".properties".length()) +
    9.75 +                        ".java";
    9.76 +                File srcFile = new File(srcDir, path);
    9.77 +                File destFile = new File(destDir, destPath);
    9.78 +                // Arguably, the comparison in the next line should be ">", not ">="
    9.79 +                // but that assumes the resolution of the last modified time is fine
    9.80 +                // grained enough; in practice, it is better to use ">=".
    9.81 +                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
    9.82 +                    continue;
    9.83 +                destFile.getParentFile().mkdirs();
    9.84 +                mainOpts.add("-compile");
    9.85 +                mainOpts.add(srcFile.getPath());
    9.86 +                mainOpts.add(destFile.getPath());
    9.87 +                mainOpts.add(superclass);
    9.88 +                count++;
    9.89 +            }
    9.90 +        }
    9.91 +        if (mainOpts.size() > 0) {
    9.92 +            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
    9.93 +            CompileProperties cp = new CompileProperties();
    9.94 +            cp.setLog(log);
    9.95 +            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
    9.96 +            if (!ok)
    9.97 +                throw new BuildException("CompileProperties failed.");
    9.98 +        }
    9.99 +    }
   9.100 +
   9.101 +    private File srcDir;
   9.102 +    private File destDir;
   9.103 +    private String superclass = "java.util.ListResourceBundle";
   9.104 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/make/tools/anttasks/GenStubsTask.java	Fri Mar 09 11:59:26 2012 -0800
    10.3 @@ -0,0 +1,162 @@
    10.4 +/*
    10.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.  Oracle designates this
   10.11 + * particular file as subject to the "Classpath" exception as provided
   10.12 + * by Oracle in the LICENSE file that accompanied this code.
   10.13 + *
   10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.17 + * version 2 for more details (a copy is included in the LICENSE file that
   10.18 + * accompanied this code).
   10.19 + *
   10.20 + * You should have received a copy of the GNU General Public License version
   10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.23 + *
   10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.25 + * or visit www.oracle.com if you need additional information or have any
   10.26 + * questions.
   10.27 + */
   10.28 +
   10.29 +package anttasks;
   10.30 +
   10.31 +import genstubs.GenStubs;
   10.32 +
   10.33 +import java.io.*;
   10.34 +import java.util.*;
   10.35 +
   10.36 +import org.apache.tools.ant.BuildException;
   10.37 +import org.apache.tools.ant.DirectoryScanner;
   10.38 +import org.apache.tools.ant.taskdefs.MatchingTask;
   10.39 +import org.apache.tools.ant.types.Path;
   10.40 +import org.apache.tools.ant.types.Reference;
   10.41 +
   10.42 +/**
   10.43 + * Files are specified with an implicit fileset, using srcdir as a base directory.
   10.44 + * The set of files to be included is specified with an includes attribute or
   10.45 + * nested <includes> set. However, unlike a normal fileset, an empty includes attribute
   10.46 + * means "no files" instead of "all files".  The Ant task also accepts "fork=true" and
   10.47 + * classpath attribute or nested <classpath> element to run GenStubs in a separate VM
   10.48 + * with the specified path. This is likely necessary if a JDK 7 parser is required to read the
   10.49 + * JDK 7 input files.
   10.50 + */
   10.51 +public class GenStubsTask extends MatchingTask {
   10.52 +    private File srcDir;
   10.53 +    private File destDir;
   10.54 +    private boolean fork;
   10.55 +    private Path classpath;
   10.56 +    private String includes;
   10.57 +
   10.58 +    public void setSrcDir(File dir) {
   10.59 +        this.srcDir = dir;
   10.60 +    }
   10.61 +
   10.62 +    public void setDestDir(File dir) {
   10.63 +        this.destDir = dir;
   10.64 +    }
   10.65 +
   10.66 +    public void setFork(boolean v) {
   10.67 +        this.fork = v;
   10.68 +    }
   10.69 +
   10.70 +    public void setClasspath(Path cp) {
   10.71 +        if (classpath == null)
   10.72 +            classpath = cp;
   10.73 +        else
   10.74 +            classpath.append(cp);
   10.75 +    }
   10.76 +
   10.77 +    public Path createClasspath() {
   10.78 +        if (classpath == null) {
   10.79 +            classpath = new Path(getProject());
   10.80 +        }
   10.81 +        return classpath.createPath();
   10.82 +    }
   10.83 +
   10.84 +    public void setClasspathRef(Reference r) {
   10.85 +        createClasspath().setRefid(r);
   10.86 +    }
   10.87 +
   10.88 +    public void setIncludes(String includes) {
   10.89 +        super.setIncludes(includes);
   10.90 +        this.includes = includes;
   10.91 +    }
   10.92 +
   10.93 +    @Override
   10.94 +    public void execute() {
   10.95 +        if (includes != null && includes.trim().isEmpty())
   10.96 +            return;
   10.97 +
   10.98 +        DirectoryScanner s = getDirectoryScanner(srcDir);
   10.99 +        String[] files = s.getIncludedFiles();
  10.100 +//            System.err.println("Ant.execute: srcDir " + srcDir);
  10.101 +//            System.err.println("Ant.execute: destDir " + destDir);
  10.102 +//            System.err.println("Ant.execute: files " + Arrays.asList(files));
  10.103 +
  10.104 +        files = filter(srcDir, destDir, files);
  10.105 +        if (files.length == 0)
  10.106 +            return;
  10.107 +        System.out.println("Generating " + files.length + " stub files to " + destDir);
  10.108 +
  10.109 +        List<String> classNames = new ArrayList<String>();
  10.110 +        for (String file: files) {
  10.111 +            classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
  10.112 +        }
  10.113 +
  10.114 +        if (!fork) {
  10.115 +            GenStubs m = new GenStubs();
  10.116 +            boolean ok = m.run(srcDir.getPath(), destDir, classNames);
  10.117 +            if (!ok)
  10.118 +                throw new BuildException("genstubs failed");
  10.119 +        } else {
  10.120 +            List<String> cmd = new ArrayList<String>();
  10.121 +            String java_home = System.getProperty("java.home");
  10.122 +            cmd.add(new File(new File(java_home, "bin"), "java").getPath());
  10.123 +            if (classpath != null)
  10.124 +                cmd.add("-Xbootclasspath/p:" + classpath);
  10.125 +            cmd.add(GenStubs.class.getName());
  10.126 +            cmd.add("-sourcepath");
  10.127 +            cmd.add(srcDir.getPath());
  10.128 +            cmd.add("-s");
  10.129 +            cmd.add(destDir.getPath());
  10.130 +            cmd.addAll(classNames);
  10.131 +            //System.err.println("GenStubs exec " + cmd);
  10.132 +            ProcessBuilder pb = new ProcessBuilder(cmd);
  10.133 +            pb.redirectErrorStream(true);
  10.134 +            try {
  10.135 +                Process p = pb.start();
  10.136 +                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
  10.137 +                try {
  10.138 +                    String line;
  10.139 +                    while ((line = in.readLine()) != null)
  10.140 +                        System.out.println(line);
  10.141 +                } finally {
  10.142 +                    in.close();
  10.143 +                }
  10.144 +                int rc = p.waitFor();
  10.145 +                if (rc != 0)
  10.146 +                    throw new BuildException("genstubs failed");
  10.147 +            } catch (IOException e) {
  10.148 +                throw new BuildException("genstubs failed", e);
  10.149 +            } catch (InterruptedException e) {
  10.150 +                throw new BuildException("genstubs failed", e);
  10.151 +            }
  10.152 +        }
  10.153 +    }
  10.154 +
  10.155 +    String[] filter(File srcDir, File destDir, String[] files) {
  10.156 +        List<String> results = new ArrayList<String>();
  10.157 +        for (String f: files) {
  10.158 +            long srcTime = new File(srcDir, f).lastModified();
  10.159 +            long destTime = new File(destDir, f).lastModified();
  10.160 +            if (srcTime > destTime)
  10.161 +                results.add(f);
  10.162 +        }
  10.163 +        return results.toArray(new String[results.size()]);
  10.164 +    }
  10.165 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/make/tools/anttasks/SelectToolTask.java	Fri Mar 09 11:59:26 2012 -0800
    11.3 @@ -0,0 +1,286 @@
    11.4 +/*
    11.5 + * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.  Oracle designates this
   11.11 + * particular file as subject to the "Classpath" exception as provided
   11.12 + * by Oracle in the LICENSE file that accompanied this code.
   11.13 + *
   11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.17 + * version 2 for more details (a copy is included in the LICENSE file that
   11.18 + * accompanied this code).
   11.19 + *
   11.20 + * You should have received a copy of the GNU General Public License version
   11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.23 + *
   11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.25 + * or visit www.oracle.com if you need additional information or have any
   11.26 + * questions.
   11.27 + */
   11.28 +
   11.29 +package anttasks;
   11.30 +
   11.31 +import java.awt.GridBagConstraints;
   11.32 +import java.awt.GridBagLayout;
   11.33 +import java.awt.event.ActionEvent;
   11.34 +import java.awt.event.ActionListener;
   11.35 +import java.awt.event.FocusEvent;
   11.36 +import java.awt.event.FocusListener;
   11.37 +import java.awt.event.ItemEvent;
   11.38 +import java.awt.event.ItemListener;
   11.39 +import java.io.BufferedReader;
   11.40 +import java.io.BufferedWriter;
   11.41 +import java.io.File;
   11.42 +import java.io.FileReader;
   11.43 +import java.io.FileWriter;
   11.44 +import java.io.IOException;
   11.45 +import java.io.Reader;
   11.46 +import java.io.Writer;
   11.47 +import java.util.ArrayList;
   11.48 +import java.util.Arrays;
   11.49 +import java.util.List;
   11.50 +import java.util.Properties;
   11.51 +import javax.swing.JButton;
   11.52 +import javax.swing.JCheckBox;
   11.53 +import javax.swing.JComboBox;
   11.54 +import javax.swing.JDialog;
   11.55 +import javax.swing.JLabel;
   11.56 +import javax.swing.JOptionPane;
   11.57 +import javax.swing.JPanel;
   11.58 +import javax.swing.JTextField;
   11.59 +
   11.60 +import javax.swing.SwingUtilities;
   11.61 +import org.apache.tools.ant.BuildException;
   11.62 +import org.apache.tools.ant.Project;
   11.63 +import org.apache.tools.ant.Task;
   11.64 +
   11.65 +/**
   11.66 + * Task to allow the user to control langtools tools built when using NetBeans.
   11.67 + *
   11.68 + * There are two primary modes.
   11.69 + * 1) Property mode. In this mode, property names are provided to get values
   11.70 + * that may be specified by the user, either directly in a GUI dialog, or
   11.71 + * read from a properties file. If the GUI dialog is invoked, values may
   11.72 + * optionally be set for future use.
   11.73 + * 2) Setup mode. In this mode, no property names are provided, and the GUI
   11.74 + * is invoked to allow the user to set or reset values for use in property mode.
   11.75 + */
   11.76 +public class SelectToolTask extends Task {
   11.77 +    /**
   11.78 +     * Set the location of the private properties file used to keep the retain
   11.79 +     * user preferences for this repository.
   11.80 +     */
   11.81 +    public void setPropertyFile(File propertyFile) {
   11.82 +        this.propertyFile = propertyFile;
   11.83 +    }
   11.84 +
   11.85 +    /**
   11.86 +     * Set the name of the property which will be set to the name of the
   11.87 +     * selected tool, if any. If no tool is selected, the property will
   11.88 +     * remain unset.
   11.89 +     */
   11.90 +    public void setToolProperty(String toolProperty) {
   11.91 +        this.toolProperty = toolProperty;
   11.92 +    }
   11.93 +
   11.94 +    /**
   11.95 +     * Set the name of the property which will be set to the execution args of the
   11.96 +     * selected tool, if any. The args default to an empty string.
   11.97 +     */
   11.98 +    public void setArgsProperty(String argsProperty) {
   11.99 +        this.argsProperty = argsProperty;
  11.100 +    }
  11.101 +
  11.102 +    /**
  11.103 +     * Specify whether or not to pop up a dialog if the user has not specified
  11.104 +     * a default value for a property.
  11.105 +     */
  11.106 +    public void setAskIfUnset(boolean askIfUnset) {
  11.107 +        this.askIfUnset = askIfUnset;
  11.108 +    }
  11.109 +
  11.110 +    @Override
  11.111 +    public void execute() {
  11.112 +        Project p = getProject();
  11.113 +
  11.114 +        Properties props = readProperties(propertyFile);
  11.115 +        toolName = props.getProperty("tool.name");
  11.116 +        if (toolName != null) {
  11.117 +            toolArgs = props.getProperty(toolName + ".args", "");
  11.118 +        }
  11.119 +
  11.120 +        if (toolProperty == null ||
  11.121 +            askIfUnset && (toolName == null
  11.122 +                || (argsProperty != null && toolArgs == null))) {
  11.123 +            showGUI(props);
  11.124 +        }
  11.125 +
  11.126 +        // finally, return required values, if any
  11.127 +        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
  11.128 +            p.setProperty(toolProperty, toolName);
  11.129 +
  11.130 +            if (argsProperty != null && toolArgs != null)
  11.131 +                p.setProperty(argsProperty, toolArgs);
  11.132 +        }
  11.133 +    }
  11.134 +
  11.135 +    void showGUI(Properties fileProps) {
  11.136 +        Properties guiProps = new Properties(fileProps);
  11.137 +        JOptionPane p = createPane(guiProps);
  11.138 +        p.createDialog("Select Tool").setVisible(true);
  11.139 +
  11.140 +        toolName = (String) toolChoice.getSelectedItem();
  11.141 +        toolArgs = argsField.getText();
  11.142 +
  11.143 +        if (defaultCheck.isSelected()) {
  11.144 +            if (toolName.equals("")) {
  11.145 +                fileProps.remove("tool.name");
  11.146 +            } else {
  11.147 +                fileProps.put("tool.name", toolName);
  11.148 +                fileProps.put(toolName + ".args", toolArgs);
  11.149 +            }
  11.150 +            writeProperties(propertyFile, fileProps);
  11.151 +        }
  11.152 +    }
  11.153 +
  11.154 +    JOptionPane createPane(final Properties props) {
  11.155 +        JPanel body = new JPanel(new GridBagLayout());
  11.156 +        GridBagConstraints lc = new GridBagConstraints();
  11.157 +        lc.insets.right = 10;
  11.158 +        lc.insets.bottom = 3;
  11.159 +        GridBagConstraints fc = new GridBagConstraints();
  11.160 +        fc.anchor = GridBagConstraints.WEST;
  11.161 +        fc.gridx = 1;
  11.162 +        fc.gridwidth = GridBagConstraints.REMAINDER;
  11.163 +        fc.insets.bottom = 3;
  11.164 +
  11.165 +        JLabel toolLabel = new JLabel("Tool:");
  11.166 +        body.add(toolLabel, lc);
  11.167 +        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
  11.168 +        if (true || toolProperty == null) {
  11.169 +            // include empty value in setup mode
  11.170 +            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
  11.171 +            l.add(0, "");
  11.172 +            toolChoices = l.toArray(new String[l.size()]);
  11.173 +        }
  11.174 +        toolChoice = new JComboBox(toolChoices);
  11.175 +        if (toolName != null)
  11.176 +            toolChoice.setSelectedItem(toolName);
  11.177 +        toolChoice.addItemListener(new ItemListener() {
  11.178 +            public void itemStateChanged(ItemEvent e) {
  11.179 +                String tn = (String) e.getItem();
  11.180 +                argsField.setText(getDefaultArgsForTool(props, tn));
  11.181 +                if (toolProperty != null)
  11.182 +                    okButton.setEnabled(!tn.equals(""));
  11.183 +            }
  11.184 +        });
  11.185 +        body.add(toolChoice, fc);
  11.186 +
  11.187 +        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
  11.188 +        if (toolProperty == null || argsProperty != null) {
  11.189 +            JLabel argsLabel = new JLabel("Args:");
  11.190 +            body.add(argsLabel, lc);
  11.191 +            body.add(argsField, fc);
  11.192 +            argsField.addFocusListener(new FocusListener() {
  11.193 +                public void focusGained(FocusEvent e) {
  11.194 +                }
  11.195 +                public void focusLost(FocusEvent e) {
  11.196 +                    String toolName = (String) toolChoice.getSelectedItem();
  11.197 +                    if (toolName.length() > 0)
  11.198 +                        props.put(toolName + ".args", argsField.getText());
  11.199 +                }
  11.200 +            });
  11.201 +        }
  11.202 +
  11.203 +        defaultCheck = new JCheckBox("Set as default");
  11.204 +        if (toolProperty == null)
  11.205 +            defaultCheck.setSelected(true);
  11.206 +        else
  11.207 +            body.add(defaultCheck, fc);
  11.208 +
  11.209 +        final JOptionPane p = new JOptionPane(body);
  11.210 +        okButton = new JButton("OK");
  11.211 +        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
  11.212 +        okButton.addActionListener(new ActionListener() {
  11.213 +            public void actionPerformed(ActionEvent e) {
  11.214 +                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
  11.215 +                d.setVisible(false);
  11.216 +            }
  11.217 +        });
  11.218 +        p.setOptions(new Object[] { okButton });
  11.219 +
  11.220 +        return p;
  11.221 +    }
  11.222 +
  11.223 +    Properties readProperties(File file) {
  11.224 +        Properties p = new Properties();
  11.225 +        if (file != null && file.exists()) {
  11.226 +            Reader in = null;
  11.227 +            try {
  11.228 +                in = new BufferedReader(new FileReader(file));
  11.229 +                p.load(in);
  11.230 +                in.close();
  11.231 +            } catch (IOException e) {
  11.232 +                throw new BuildException("error reading property file", e);
  11.233 +            } finally {
  11.234 +                if (in != null) {
  11.235 +                    try {
  11.236 +                        in.close();
  11.237 +                    } catch (IOException e) {
  11.238 +                        throw new BuildException("cannot close property file", e);
  11.239 +                    }
  11.240 +                }
  11.241 +            }
  11.242 +        }
  11.243 +        return p;
  11.244 +    }
  11.245 +
  11.246 +    void writeProperties(File file, Properties p) {
  11.247 +        if (file != null) {
  11.248 +            Writer out = null;
  11.249 +            try {
  11.250 +                File dir = file.getParentFile();
  11.251 +                if (dir != null && !dir.exists())
  11.252 +                    dir.mkdirs();
  11.253 +                out = new BufferedWriter(new FileWriter(file));
  11.254 +                p.store(out, "langtools properties");
  11.255 +                out.close();
  11.256 +            } catch (IOException e) {
  11.257 +                throw new BuildException("error writing property file", e);
  11.258 +            } finally {
  11.259 +                if (out != null) {
  11.260 +                    try {
  11.261 +                        out.close();
  11.262 +                    } catch (IOException e) {
  11.263 +                        throw new BuildException("cannot close property file", e);
  11.264 +                    }
  11.265 +                }
  11.266 +            }
  11.267 +        }
  11.268 +    }
  11.269 +
  11.270 +    String getDefaultArgsForTool(Properties props, String tn) {
  11.271 +        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
  11.272 +    }
  11.273 +
  11.274 +    // Ant task parameters
  11.275 +    private boolean askIfUnset;
  11.276 +    private String toolProperty;
  11.277 +    private String argsProperty;
  11.278 +    private File propertyFile;
  11.279 +
  11.280 +    // GUI components
  11.281 +    private JComboBox toolChoice;
  11.282 +    private JTextField argsField;
  11.283 +    private JCheckBox defaultCheck;
  11.284 +    private JButton okButton;
  11.285 +
  11.286 +    // Result values for the client
  11.287 +    private String toolName;
  11.288 +    private String toolArgs;
  11.289 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/make/tools/compileproperties/CompileProperties.java	Fri Mar 09 11:59:26 2012 -0800
    12.3 @@ -0,0 +1,404 @@
    12.4 +/*
    12.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.  Oracle designates this
   12.11 + * particular file as subject to the "Classpath" exception as provided
   12.12 + * by Oracle in the LICENSE file that accompanied this code.
   12.13 + *
   12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.17 + * version 2 for more details (a copy is included in the LICENSE file that
   12.18 + * accompanied this code).
   12.19 + *
   12.20 + * You should have received a copy of the GNU General Public License version
   12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.23 + *
   12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.25 + * or visit www.oracle.com if you need additional information or have any
   12.26 + * questions.
   12.27 + */
   12.28 +
   12.29 +package compileproperties;
   12.30 +
   12.31 +import java.io.BufferedWriter;
   12.32 +import java.io.File;
   12.33 +import java.io.FileInputStream;
   12.34 +import java.io.FileNotFoundException;
   12.35 +import java.io.FileOutputStream;
   12.36 +import java.io.IOException;
   12.37 +import java.io.OutputStreamWriter;
   12.38 +import java.io.Writer;
   12.39 +import java.text.MessageFormat;
   12.40 +import java.util.ArrayList;
   12.41 +import java.util.Collections;
   12.42 +import java.util.Iterator;
   12.43 +import java.util.List;
   12.44 +import java.util.Properties;
   12.45 +
   12.46 +/** Translates a .properties file into a .java file containing the
   12.47 + *  definition of a java.util.Properties subclass which can then be
   12.48 + *  compiled with javac. <P>
   12.49 + *
   12.50 + *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
   12.51 + *
   12.52 + *  Infers the package by looking at the common suffix of the two
   12.53 + *  inputs, eliminating "classes" from it.
   12.54 + *
   12.55 + * @author Scott Violet
   12.56 + * @author Kenneth Russell
   12.57 + */
   12.58 +
   12.59 +public class CompileProperties {
   12.60 +
   12.61 +    public static void main(String[] args) {
   12.62 +        CompileProperties cp = new CompileProperties();
   12.63 +        boolean ok = cp.run(args);
   12.64 +        if ( !ok ) {
   12.65 +            System.exit(1);
   12.66 +        }
   12.67 +    }
   12.68 +
   12.69 +    public static interface Log {
   12.70 +        void info(String msg);
   12.71 +        void verbose(String msg);
   12.72 +        void error(String msg, Exception e);
   12.73 +    }
   12.74 +
   12.75 +    private String propfiles[];
   12.76 +    private String outfiles[] ;
   12.77 +    private String supers[]   ;
   12.78 +    private int compileCount = 0;
   12.79 +    private boolean quiet = false;
   12.80 +    public Log log;
   12.81 +
   12.82 +    public void setLog(Log log) {
   12.83 +        this.log = log;
   12.84 +    }
   12.85 +
   12.86 +    public boolean run(String[] args) {
   12.87 +        if (log == null) {
   12.88 +            log = new Log() {
   12.89 +                public void error(String msg, Exception e) {
   12.90 +                    System.err.println("ERROR: CompileProperties: " + msg);
   12.91 +                    if ( e != null ) {
   12.92 +                        System.err.println("EXCEPTION: " + e.toString());
   12.93 +                        e.printStackTrace();
   12.94 +                    }
   12.95 +                }
   12.96 +                public void info(String msg) {
   12.97 +                    System.out.println(msg);
   12.98 +                }
   12.99 +                public void verbose(String msg) {
  12.100 +                    if (!quiet)
  12.101 +                        System.out.println(msg);
  12.102 +                }
  12.103 +            };
  12.104 +        }
  12.105 +
  12.106 +        boolean ok = true;
  12.107 +        /* Original usage */
  12.108 +        if (args.length == 2 && args[0].charAt(0) != '-' ) {
  12.109 +            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
  12.110 +        } else if (args.length == 3) {
  12.111 +            ok = createFile(args[0], args[1], args[2]);
  12.112 +        } else if (args.length == 0) {
  12.113 +            usage(log);
  12.114 +            ok = false;
  12.115 +        } else {
  12.116 +            /* New batch usage */
  12.117 +            ok = parseOptions(args);
  12.118 +            if ( ok && compileCount == 0 ) {
  12.119 +                log.error("options parsed but no files to compile", null);
  12.120 +                ok = false;
  12.121 +            }
  12.122 +            /* Need at least one file. */
  12.123 +            if ( !ok ) {
  12.124 +                usage(log);
  12.125 +            } else {
  12.126 +                /* Process files */
  12.127 +                for ( int i = 0; i < compileCount && ok ; i++ ) {
  12.128 +                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
  12.129 +                }
  12.130 +            }
  12.131 +        }
  12.132 +        return ok;
  12.133 +    }
  12.134 +
  12.135 +    private boolean parseOptions(String args[]) {
  12.136 +        boolean ok = true;
  12.137 +        if ( compileCount > 0 ) {
  12.138 +            String new_propfiles[] = new String[compileCount + args.length];
  12.139 +            String new_outfiles[]  = new String[compileCount + args.length];
  12.140 +            String new_supers[]    = new String[compileCount + args.length];
  12.141 +            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
  12.142 +            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
  12.143 +            System.arraycopy(supers, 0, new_supers, 0, compileCount);
  12.144 +            propfiles = new_propfiles;
  12.145 +            outfiles  = new_outfiles;
  12.146 +            supers    = new_supers;
  12.147 +        } else {
  12.148 +            propfiles = new String[args.length];
  12.149 +            outfiles  = new String[args.length];
  12.150 +            supers    = new String[args.length];
  12.151 +        }
  12.152 +
  12.153 +        for ( int i = 0; i < args.length ; i++ ) {
  12.154 +            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
  12.155 +                propfiles[compileCount] = args[++i];
  12.156 +                outfiles[compileCount]  = args[++i];
  12.157 +                supers[compileCount]    = args[++i];
  12.158 +                compileCount++;
  12.159 +            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
  12.160 +                String filename = args[++i];
  12.161 +                FileInputStream finput = null;
  12.162 +                byte contents[] = null;
  12.163 +                try {
  12.164 +                    finput = new FileInputStream(filename);
  12.165 +                    int byteCount = finput.available();
  12.166 +                    if ( byteCount <= 0 ) {
  12.167 +                        log.error("The -optionsfile file is empty", null);
  12.168 +                        ok = false;
  12.169 +                    } else {
  12.170 +                        contents = new byte[byteCount];
  12.171 +                        int bytesRead = finput.read(contents);
  12.172 +                        if ( byteCount != bytesRead ) {
  12.173 +                            log.error("Cannot read all of -optionsfile file", null);
  12.174 +                            ok = false;
  12.175 +                        }
  12.176 +                    }
  12.177 +                } catch ( IOException e ) {
  12.178 +                    log.error("cannot open " + filename, e);
  12.179 +                    ok = false;
  12.180 +                }
  12.181 +                if ( finput != null ) {
  12.182 +                    try {
  12.183 +                        finput.close();
  12.184 +                    } catch ( IOException e ) {
  12.185 +                        ok = false;
  12.186 +                        log.error("cannot close " + filename, e);
  12.187 +                    }
  12.188 +                }
  12.189 +                if ( ok = true && contents != null ) {
  12.190 +                    String tokens[] = (new String(contents)).split("\\s+");
  12.191 +                    if ( tokens.length > 0 ) {
  12.192 +                        ok = parseOptions(tokens);
  12.193 +                    }
  12.194 +                }
  12.195 +                if ( !ok ) {
  12.196 +                    break;
  12.197 +                }
  12.198 +            } else if ( "-quiet".equals(args[i]) ) {
  12.199 +                quiet = true;
  12.200 +            } else {
  12.201 +                log.error("argument error", null);
  12.202 +                ok = false;
  12.203 +            }
  12.204 +        }
  12.205 +        return ok;
  12.206 +    }
  12.207 +
  12.208 +    private boolean createFile(String propertiesPath, String outputPath,
  12.209 +            String superClass) {
  12.210 +        boolean ok = true;
  12.211 +        log.verbose("parsing: " + propertiesPath);
  12.212 +        Properties p = new Properties();
  12.213 +        try {
  12.214 +            p.load(new FileInputStream(propertiesPath));
  12.215 +        } catch ( FileNotFoundException e ) {
  12.216 +            ok = false;
  12.217 +            log.error("Cannot find file " + propertiesPath, e);
  12.218 +        } catch ( IOException e ) {
  12.219 +            ok = false;
  12.220 +            log.error("IO error on file " + propertiesPath, e);
  12.221 +        }
  12.222 +        if ( ok ) {
  12.223 +            String packageName = inferPackageName(propertiesPath, outputPath);
  12.224 +            log.verbose("inferred package name: " + packageName);
  12.225 +            List<String> sortedKeys = new ArrayList<String>();
  12.226 +            for ( Object key : p.keySet() ) {
  12.227 +                sortedKeys.add((String)key);
  12.228 +            }
  12.229 +            Collections.sort(sortedKeys);
  12.230 +            Iterator<String> keys = sortedKeys.iterator();
  12.231 +
  12.232 +            StringBuffer data = new StringBuffer();
  12.233 +
  12.234 +            while (keys.hasNext()) {
  12.235 +                String key = keys.next();
  12.236 +                data.append("            { \"" + escape(key) + "\", \"" +
  12.237 +                        escape((String)p.get(key)) + "\" },\n");
  12.238 +            }
  12.239 +
  12.240 +            // Get class name from java filename, not the properties filename.
  12.241 +            //   (zh_TW properties might be used to create zh_HK files)
  12.242 +            File file = new File(outputPath);
  12.243 +            String name = file.getName();
  12.244 +            int dotIndex = name.lastIndexOf('.');
  12.245 +            String className;
  12.246 +            if (dotIndex == -1) {
  12.247 +                className = name;
  12.248 +            } else {
  12.249 +                className = name.substring(0, dotIndex);
  12.250 +            }
  12.251 +
  12.252 +            String packageString = "";
  12.253 +            if (packageName != null && !packageName.equals("")) {
  12.254 +                packageString = "package " + packageName + ";\n\n";
  12.255 +            }
  12.256 +
  12.257 +            Writer writer = null;
  12.258 +            try {
  12.259 +                writer = new BufferedWriter(
  12.260 +                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
  12.261 +                MessageFormat format = new MessageFormat(FORMAT);
  12.262 +                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
  12.263 +            } catch ( IOException e ) {
  12.264 +                ok = false;
  12.265 +                log.error("IO error writing to file " + outputPath, e);
  12.266 +            }
  12.267 +            if ( writer != null ) {
  12.268 +                try {
  12.269 +                    writer.flush();
  12.270 +                } catch ( IOException e ) {
  12.271 +                    ok = false;
  12.272 +                    log.error("IO error flush " + outputPath, e);
  12.273 +                }
  12.274 +                try {
  12.275 +                    writer.close();
  12.276 +                } catch ( IOException e ) {
  12.277 +                    ok = false;
  12.278 +                    log.error("IO error close " + outputPath, e);
  12.279 +                }
  12.280 +            }
  12.281 +            log.verbose("wrote: " + outputPath);
  12.282 +        }
  12.283 +        return ok;
  12.284 +    }
  12.285 +
  12.286 +    private static void usage(Log log) {
  12.287 +        log.info("usage:");
  12.288 +        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
  12.289 +        log.info("      -OR-");
  12.290 +        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
  12.291 +        log.info("");
  12.292 +        log.info("Example:");
  12.293 +        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
  12.294 +        log.info("    java CompileProperties -optionsfile option_file");
  12.295 +        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
  12.296 +    }
  12.297 +
  12.298 +    private static String escape(String theString) {
  12.299 +        // This is taken from Properties.saveConvert with changes for Java strings
  12.300 +        int len = theString.length();
  12.301 +        StringBuffer outBuffer = new StringBuffer(len*2);
  12.302 +
  12.303 +        for(int x=0; x<len; x++) {
  12.304 +            char aChar = theString.charAt(x);
  12.305 +            switch(aChar) {
  12.306 +                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
  12.307 +                break;
  12.308 +                case '\t':outBuffer.append('\\'); outBuffer.append('t');
  12.309 +                break;
  12.310 +                case '\n':outBuffer.append('\\'); outBuffer.append('n');
  12.311 +                break;
  12.312 +                case '\r':outBuffer.append('\\'); outBuffer.append('r');
  12.313 +                break;
  12.314 +                case '\f':outBuffer.append('\\'); outBuffer.append('f');
  12.315 +                break;
  12.316 +                default:
  12.317 +                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
  12.318 +                        outBuffer.append('\\');
  12.319 +                        outBuffer.append('u');
  12.320 +                        outBuffer.append(toHex((aChar >> 12) & 0xF));
  12.321 +                        outBuffer.append(toHex((aChar >>  8) & 0xF));
  12.322 +                        outBuffer.append(toHex((aChar >>  4) & 0xF));
  12.323 +                        outBuffer.append(toHex( aChar        & 0xF));
  12.324 +                    } else {
  12.325 +                        if (specialSaveChars.indexOf(aChar) != -1) {
  12.326 +                            outBuffer.append('\\');
  12.327 +                        }
  12.328 +                        outBuffer.append(aChar);
  12.329 +                    }
  12.330 +            }
  12.331 +        }
  12.332 +        return outBuffer.toString();
  12.333 +    }
  12.334 +
  12.335 +    private static String inferPackageName(String inputPath, String outputPath) {
  12.336 +        // Normalize file names
  12.337 +        inputPath  = new File(inputPath).getPath();
  12.338 +        outputPath = new File(outputPath).getPath();
  12.339 +        // Split into components
  12.340 +        String sep;
  12.341 +        if (File.separatorChar == '\\') {
  12.342 +            sep = "\\\\";
  12.343 +        } else {
  12.344 +            sep = File.separator;
  12.345 +        }
  12.346 +        String[] inputs  = inputPath.split(sep);
  12.347 +        String[] outputs = outputPath.split(sep);
  12.348 +        // Match common names, eliminating first "classes" entry from
  12.349 +        // each if present
  12.350 +        int inStart  = 0;
  12.351 +        int inEnd    = inputs.length - 2;
  12.352 +        int outEnd   = outputs.length - 2;
  12.353 +        int i = inEnd;
  12.354 +        int j = outEnd;
  12.355 +        while (i >= 0 && j >= 0) {
  12.356 +            if (!inputs[i].equals(outputs[j]) ||
  12.357 +                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
  12.358 +                ++i;
  12.359 +                ++j;
  12.360 +                break;
  12.361 +            }
  12.362 +            --i;
  12.363 +            --j;
  12.364 +        }
  12.365 +        String result;
  12.366 +        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
  12.367 +            result = "";
  12.368 +        } else {
  12.369 +            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
  12.370 +                ++i;
  12.371 +            }
  12.372 +            inStart = i;
  12.373 +            StringBuffer buf = new StringBuffer();
  12.374 +            for (i = inStart; i <= inEnd; i++) {
  12.375 +                buf.append(inputs[i]);
  12.376 +                if (i < inEnd) {
  12.377 +                    buf.append('.');
  12.378 +                }
  12.379 +            }
  12.380 +            result = buf.toString();
  12.381 +        }
  12.382 +        return result;
  12.383 +    }
  12.384 +
  12.385 +    private static final String FORMAT =
  12.386 +            "{0}" +
  12.387 +            "public final class {1} extends {2} '{'\n" +
  12.388 +            "    protected final Object[][] getContents() '{'\n" +
  12.389 +            "        return new Object[][] '{'\n" +
  12.390 +            "{3}" +
  12.391 +            "        };\n" +
  12.392 +            "    }\n" +
  12.393 +            "}\n";
  12.394 +
  12.395 +    // This comes from Properties
  12.396 +    private static char toHex(int nibble) {
  12.397 +        return hexDigit[(nibble & 0xF)];
  12.398 +    }
  12.399 +
  12.400 +    // This comes from Properties
  12.401 +    private static final char[] hexDigit = {
  12.402 +        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  12.403 +    };
  12.404 +
  12.405 +    // Note: different from that in Properties
  12.406 +    private static final String specialSaveChars = "\"";
  12.407 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/make/tools/genstubs/GenStubs.java	Fri Mar 09 11:59:26 2012 -0800
    13.3 @@ -0,0 +1,316 @@
    13.4 +/*
    13.5 + * Copyright (c) 2009, 2010, 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.  Oracle designates this
   13.11 + * particular file as subject to the "Classpath" exception as provided
   13.12 + * by Oracle in the LICENSE file that accompanied this code.
   13.13 + *
   13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.17 + * version 2 for more details (a copy is included in the LICENSE file that
   13.18 + * accompanied this code).
   13.19 + *
   13.20 + * You should have received a copy of the GNU General Public License version
   13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.23 + *
   13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.25 + * or visit www.oracle.com if you need additional information or have any
   13.26 + * questions.
   13.27 + */
   13.28 +
   13.29 +package genstubs;
   13.30 +
   13.31 +import java.io.*;
   13.32 +import java.util.*;
   13.33 +import javax.tools.JavaFileObject;
   13.34 +import javax.tools.StandardJavaFileManager;
   13.35 +import javax.tools.StandardLocation;
   13.36 +
   13.37 +import com.sun.source.tree.CompilationUnitTree;
   13.38 +import com.sun.source.util.JavacTask;
   13.39 +import com.sun.tools.javac.api.JavacTool;
   13.40 +import com.sun.tools.javac.code.Flags;
   13.41 +import com.sun.tools.javac.code.TypeTags;
   13.42 +import com.sun.tools.javac.tree.JCTree;
   13.43 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
   13.44 +import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
   13.45 +import com.sun.tools.javac.tree.JCTree.JCIdent;
   13.46 +import com.sun.tools.javac.tree.JCTree.JCImport;
   13.47 +import com.sun.tools.javac.tree.JCTree.JCLiteral;
   13.48 +import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
   13.49 +import com.sun.tools.javac.tree.JCTree.JCModifiers;
   13.50 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
   13.51 +import com.sun.tools.javac.tree.Pretty;
   13.52 +import com.sun.tools.javac.tree.TreeMaker;
   13.53 +import com.sun.tools.javac.tree.TreeScanner;
   13.54 +import com.sun.tools.javac.tree.TreeTranslator;
   13.55 +import com.sun.tools.javac.util.Context;
   13.56 +import com.sun.tools.javac.util.ListBuffer;
   13.57 +import com.sun.tools.javac.util.Name;
   13.58 +import javax.tools.JavaFileManager;
   13.59 +
   13.60 +/**
   13.61 + * Generate stub source files by removing implementation details from input files.
   13.62 + *
   13.63 + * This is a special purpose stub generator, specific to the needs of generating
   13.64 + * stub files for JDK 7 API that are needed to compile langtools files that depend
   13.65 + * on that API. The stub generator works by removing as much of the API source code
   13.66 + * as possible without affecting the public signature, in order to reduce the
   13.67 + * transitive closure of the API being referenced. The resulting stubs can be
   13.68 + * put on the langtools sourcepath with -implicit:none to compile the langtools
   13.69 + * files that depend on the JDK 7 API.
   13.70 + *
   13.71 + * Usage:
   13.72 + *  genstubs -s <outdir> -sourcepath <path> <classnames>
   13.73 + *
   13.74 + * The specified class names are looked up on the sourcepath, and corresponding
   13.75 + * stubs are written to the source output directory.
   13.76 + *
   13.77 + * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
   13.78 + * to remove implementation details, and written out in the source output directory.
   13.79 + * Documentation comments and annotations are removed. Method bodies are removed
   13.80 + * and methods are marked native. Private and package-private field definitions
   13.81 + * have their initializers replace with 0, 0.0, false, null as appropriate.
   13.82 + */
   13.83 +
   13.84 +public class GenStubs {
   13.85 +    static class Fault extends Exception {
   13.86 +        private static final long serialVersionUID = 0;
   13.87 +        Fault(String message) {
   13.88 +            super(message);
   13.89 +        }
   13.90 +        Fault(String message, Throwable cause) {
   13.91 +            super(message);
   13.92 +            initCause(cause);
   13.93 +        }
   13.94 +    }
   13.95 +
   13.96 +    public static void main(String[] args) {
   13.97 +        boolean ok = new GenStubs().run(args);
   13.98 +        if (!ok)
   13.99 +            System.exit(1);
  13.100 +    }
  13.101 +
  13.102 +    public boolean run(String... args) {
  13.103 +        File outdir = null;
  13.104 +        String sourcepath = null;
  13.105 +        List<String> classes = new ArrayList<String>();
  13.106 +        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
  13.107 +            String arg = iter.next();
  13.108 +            if (arg.equals("-s") && iter.hasNext())
  13.109 +                outdir = new File(iter.next());
  13.110 +            else if (arg.equals("-sourcepath") && iter.hasNext())
  13.111 +                sourcepath = iter.next();
  13.112 +            else if (arg.startsWith("-"))
  13.113 +                throw new IllegalArgumentException(arg);
  13.114 +            else {
  13.115 +                classes.add(arg);
  13.116 +                while (iter.hasNext())
  13.117 +                    classes.add(iter.next());
  13.118 +            }
  13.119 +        }
  13.120 +
  13.121 +        return run(sourcepath, outdir, classes);
  13.122 +    }
  13.123 +
  13.124 +    public boolean run(String sourcepath, File outdir, List<String> classes) {
  13.125 +        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
  13.126 +        if (sourcepath == null)
  13.127 +            throw new IllegalArgumentException("sourcepath not set");
  13.128 +        if (outdir == null)
  13.129 +            throw new IllegalArgumentException("source output dir not set");
  13.130 +
  13.131 +        JavacTool tool = JavacTool.create();
  13.132 +        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
  13.133 +
  13.134 +        try {
  13.135 +            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
  13.136 +            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
  13.137 +            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
  13.138 +            for (String c: classes) {
  13.139 +                JavaFileObject fo = fm.getJavaFileForInput(
  13.140 +                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
  13.141 +                if (fo == null)
  13.142 +                    error("class not found: " + c);
  13.143 +                else
  13.144 +                    files.add(fo);
  13.145 +            }
  13.146 +
  13.147 +            JavacTask t = tool.getTask(null, fm, null, null, null, files);
  13.148 +            Iterable<? extends CompilationUnitTree> trees = t.parse();
  13.149 +            for (CompilationUnitTree tree: trees) {
  13.150 +                makeStub(fm, tree);
  13.151 +            }
  13.152 +        } catch (IOException e) {
  13.153 +            error("IO error " + e, e);
  13.154 +        }
  13.155 +
  13.156 +        return (errors == 0);
  13.157 +    }
  13.158 +
  13.159 +    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
  13.160 +        CompilationUnitTree tree2 = new StubMaker().translate(tree);
  13.161 +        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
  13.162 +
  13.163 +        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
  13.164 +        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
  13.165 +                className, JavaFileObject.Kind.SOURCE, null);
  13.166 +        // System.err.println("Writing " + className + " to " + fo.getName());
  13.167 +        Writer out = fo.openWriter();
  13.168 +        try {
  13.169 +            new Pretty(out, true).printExpr((JCTree) tree3);
  13.170 +        } finally {
  13.171 +            out.close();
  13.172 +        }
  13.173 +    }
  13.174 +
  13.175 +    List<File> splitPath(String path) {
  13.176 +        List<File> list = new ArrayList<File>();
  13.177 +        for (String p: path.split(File.pathSeparator)) {
  13.178 +            if (p.length() > 0)
  13.179 +                list.add(new File(p));
  13.180 +        }
  13.181 +        return list;
  13.182 +    }
  13.183 +
  13.184 +    void error(String message) {
  13.185 +        System.err.println(message);
  13.186 +        errors++;
  13.187 +    }
  13.188 +
  13.189 +    void error(String message, Throwable cause) {
  13.190 +        error(message);
  13.191 +    }
  13.192 +
  13.193 +    int errors;
  13.194 +
  13.195 +    class StubMaker extends TreeTranslator {
  13.196 +        CompilationUnitTree translate(CompilationUnitTree tree) {
  13.197 +            return super.translate((JCCompilationUnit) tree);
  13.198 +        }
  13.199 +
  13.200 +        /**
  13.201 +         * compilation units: remove javadoc comments
  13.202 +         * -- required, in order to remove @deprecated tags, since we
  13.203 +         * (separately) remove all annotations, including @Deprecated
  13.204 +         */
  13.205 +        public void visitTopLevel(JCCompilationUnit tree) {
  13.206 +            super.visitTopLevel(tree);
  13.207 +            tree.docComments = Collections.emptyMap();
  13.208 +        }
  13.209 +
  13.210 +        /**
  13.211 +         * methods: remove method bodies, make methods native
  13.212 +         */
  13.213 +        @Override
  13.214 +        public void visitMethodDef(JCMethodDecl tree) {
  13.215 +            tree.mods = translate(tree.mods);
  13.216 +            tree.restype = translate(tree.restype);
  13.217 +            tree.typarams = translateTypeParams(tree.typarams);
  13.218 +            tree.params = translateVarDefs(tree.params);
  13.219 +            tree.thrown = translate(tree.thrown);
  13.220 +            if (tree.restype != null && tree.body != null) {
  13.221 +                tree.mods.flags |= Flags.NATIVE;
  13.222 +                tree.body = null;
  13.223 +            }
  13.224 +            result = tree;
  13.225 +        }
  13.226 +
  13.227 +        /**
  13.228 +         * modifiers: remove annotations
  13.229 +         */
  13.230 +        @Override
  13.231 +        public void visitModifiers(JCModifiers tree) {
  13.232 +            tree.annotations = com.sun.tools.javac.util.List.nil();
  13.233 +            result = tree;
  13.234 +        }
  13.235 +
  13.236 +        /**
  13.237 +         * field definitions: replace initializers with 0, 0.0, false etc
  13.238 +         * when possible -- i.e. leave public, protected initializers alone
  13.239 +         */
  13.240 +        @Override
  13.241 +        public void visitVarDef(JCVariableDecl tree) {
  13.242 +            tree.mods = translate(tree.mods);
  13.243 +            tree.vartype = translate(tree.vartype);
  13.244 +            if (tree.init != null) {
  13.245 +                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
  13.246 +                    tree.init = translate(tree.init);
  13.247 +                else {
  13.248 +                    String t = tree.vartype.toString();
  13.249 +                    if (t.equals("boolean"))
  13.250 +                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
  13.251 +                    else if (t.equals("byte"))
  13.252 +                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
  13.253 +                    else if (t.equals("char"))
  13.254 +                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
  13.255 +                    else if (t.equals("double"))
  13.256 +                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
  13.257 +                    else if (t.equals("float"))
  13.258 +                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
  13.259 +                    else if (t.equals("int"))
  13.260 +                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
  13.261 +                    else if (t.equals("long"))
  13.262 +                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
  13.263 +                    else if (t.equals("short"))
  13.264 +                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
  13.265 +                    else
  13.266 +                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
  13.267 +                }
  13.268 +            }
  13.269 +            result = tree;
  13.270 +        }
  13.271 +    }
  13.272 +
  13.273 +    class ImportCleaner extends TreeScanner {
  13.274 +        private Set<Name> names = new HashSet<Name>();
  13.275 +        private TreeMaker m;
  13.276 +
  13.277 +        ImportCleaner(JavaFileManager fm) {
  13.278 +            // ImportCleaner itself doesn't require a filemanager, but instantiating
  13.279 +            // a TreeMaker does, indirectly (via ClassReader, sigh)
  13.280 +            Context c = new Context();
  13.281 +            c.put(JavaFileManager.class, fm);
  13.282 +            m = TreeMaker.instance(c);
  13.283 +        }
  13.284 +
  13.285 +        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
  13.286 +            JCCompilationUnit tree = (JCCompilationUnit) t;
  13.287 +            tree.accept(this);
  13.288 +            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
  13.289 +            for (JCTree def: tree.defs) {
  13.290 +                if (def.getTag() == JCTree.Tag.IMPORT) {
  13.291 +                    JCImport imp = (JCImport) def;
  13.292 +                    if (imp.qualid.getTag() == JCTree.Tag.SELECT) {
  13.293 +                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
  13.294 +                        if (!qualid.name.toString().equals("*")
  13.295 +                                && !names.contains(qualid.name)) {
  13.296 +                            continue;
  13.297 +                        }
  13.298 +                    }
  13.299 +                }
  13.300 +                defs.add(def);
  13.301 +            }
  13.302 +            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
  13.303 +        }
  13.304 +
  13.305 +        @Override
  13.306 +        public void visitImport(JCImport tree) { } // ignore names found in imports
  13.307 +
  13.308 +        @Override
  13.309 +        public void visitIdent(JCIdent tree) {
  13.310 +            names.add(tree.name);
  13.311 +        }
  13.312 +
  13.313 +        @Override
  13.314 +        public void visitSelect(JCFieldAccess tree) {
  13.315 +            super.visitSelect(tree);
  13.316 +            names.add(tree.name);
  13.317 +        }
  13.318 +    }
  13.319 +}
    14.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Mar 08 20:35:26 2012 -0800
    14.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Mar 09 11:59:26 2012 -0800
    14.3 @@ -1235,7 +1235,7 @@
    14.4              // if origin is derived from a raw type, we might have missed
    14.5              // an implementation because we do not know enough about instantiations.
    14.6              // in this case continue with the supertype as origin.
    14.7 -            if (types.isDerivedRaw(origin.type))
    14.8 +            if (types.isDerivedRaw(origin.type) && !origin.isInterface())
    14.9                  return implementation(types.supertype(origin.type).tsym, types, checkResult);
   14.10              else
   14.11                  return null;
    15.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 08 20:35:26 2012 -0800
    15.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Mar 09 11:59:26 2012 -0800
    15.3 @@ -1,5 +1,5 @@
    15.4  /*
    15.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
    15.6 + * Copyright (c) 1999, 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 @@ -199,16 +199,15 @@
   15.11       *  @param tree     The tree whose kind and type is checked
   15.12       *  @param owntype  The computed type of the tree
   15.13       *  @param ownkind  The computed kind of the tree
   15.14 -     *  @param pkind    The expected kind (or: protokind) of the tree
   15.15 -     *  @param pt       The expected type (or: prototype) of the tree
   15.16 +     *  @param resultInfo  The expected result of the tree
   15.17       */
   15.18 -    Type check(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) {
   15.19 -        if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) {
   15.20 -            if ((ownkind & ~pkind) == 0) {
   15.21 -                owntype = chk.checkType(tree.pos(), owntype, pt, errKey);
   15.22 +    Type check(JCTree tree, Type owntype, int ownkind, ResultInfo resultInfo) {
   15.23 +        if (owntype.tag != ERROR && resultInfo.pt.tag != METHOD && resultInfo.pt.tag != FORALL) {
   15.24 +            if ((ownkind & ~resultInfo.pkind) == 0) {
   15.25 +                owntype = chk.checkType(tree.pos(), owntype, resultInfo.pt, errKey);
   15.26              } else {
   15.27                  log.error(tree.pos(), "unexpected.type",
   15.28 -                          kindNames(pkind),
   15.29 +                          kindNames(resultInfo.pkind),
   15.30                            kindName(ownkind));
   15.31                  owntype = types.createErrorType(owntype);
   15.32              }
   15.33 @@ -333,7 +332,16 @@
   15.34      public Type attribType(JCTree node, TypeSymbol sym) {
   15.35          Env<AttrContext> env = enter.typeEnvs.get(sym);
   15.36          Env<AttrContext> localEnv = env.dup(node, env.info.dup());
   15.37 -        return attribTree(node, localEnv, Kinds.TYP, Type.noType);
   15.38 +        return attribTree(node, localEnv, unknownTypeInfo);
   15.39 +    }
   15.40 +
   15.41 +    public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) {
   15.42 +        // Attribute qualifying package or class.
   15.43 +        JCFieldAccess s = (JCFieldAccess)tree.qualid;
   15.44 +        return attribTree(s.selected,
   15.45 +                       env,
   15.46 +                       new ResultInfo(tree.staticImport ? TYP : (TYP | PCK),
   15.47 +                       Type.noType));
   15.48      }
   15.49  
   15.50      public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
   15.51 @@ -386,6 +394,28 @@
   15.52          }
   15.53      }
   15.54  
   15.55 +    static class ResultInfo {
   15.56 +        int pkind;
   15.57 +        Type pt;
   15.58 +
   15.59 +        ResultInfo(int pkind, Type pt) {
   15.60 +            this.pkind = pkind;
   15.61 +            this.pt = pt;
   15.62 +        }
   15.63 +    }
   15.64 +
   15.65 +    private final ResultInfo statInfo = new ResultInfo(NIL, Type.noType);
   15.66 +    private final ResultInfo varInfo = new ResultInfo(VAR, Type.noType);
   15.67 +    private final ResultInfo unknownExprInfo = new ResultInfo(VAL, Type.noType);
   15.68 +    private final ResultInfo unknownTypeInfo = new ResultInfo(TYP, Type.noType);
   15.69 +
   15.70 +    Type pt() {
   15.71 +        return resultInfo.pt;
   15.72 +    }
   15.73 +
   15.74 +    int pkind() {
   15.75 +        return resultInfo.pkind;
   15.76 +    }
   15.77  
   15.78  /* ************************************************************************
   15.79   * Visitor methods
   15.80 @@ -395,13 +425,9 @@
   15.81       */
   15.82      Env<AttrContext> env;
   15.83  
   15.84 -    /** Visitor argument: the currently expected proto-kind.
   15.85 +    /** Visitor argument: the currently expected attribution result.
   15.86       */
   15.87 -    int pkind;
   15.88 -
   15.89 -    /** Visitor argument: the currently expected proto-type.
   15.90 -     */
   15.91 -    Type pt;
   15.92 +    ResultInfo resultInfo;
   15.93  
   15.94      /** Visitor argument: the error key to be generated when a type error occurs
   15.95       */
   15.96 @@ -416,22 +442,19 @@
   15.97       *
   15.98       *  @param tree    The tree to be visited.
   15.99       *  @param env     The environment visitor argument.
  15.100 -     *  @param pkind   The protokind visitor argument.
  15.101 -     *  @param pt      The prototype visitor argument.
  15.102 +     *  @param resultInfo   The result info visitor argument.
  15.103       */
  15.104 -    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt) {
  15.105 -        return attribTree(tree, env, pkind, pt, "incompatible.types");
  15.106 +    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
  15.107 +        return attribTree(tree, env, resultInfo, "incompatible.types");
  15.108      }
  15.109  
  15.110 -    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt, String errKey) {
  15.111 +    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, String errKey) {
  15.112          Env<AttrContext> prevEnv = this.env;
  15.113 -        int prevPkind = this.pkind;
  15.114 -        Type prevPt = this.pt;
  15.115 +        ResultInfo prevResult = this.resultInfo;
  15.116          String prevErrKey = this.errKey;
  15.117          try {
  15.118              this.env = env;
  15.119 -            this.pkind = pkind;
  15.120 -            this.pt = pt;
  15.121 +            this.resultInfo = resultInfo;
  15.122              this.errKey = errKey;
  15.123              tree.accept(this);
  15.124              if (tree == breakTree)
  15.125 @@ -442,8 +465,7 @@
  15.126              return chk.completionError(tree.pos(), ex);
  15.127          } finally {
  15.128              this.env = prevEnv;
  15.129 -            this.pkind = prevPkind;
  15.130 -            this.pt = prevPt;
  15.131 +            this.resultInfo = prevResult;
  15.132              this.errKey = prevErrKey;
  15.133          }
  15.134      }
  15.135 @@ -451,18 +473,18 @@
  15.136      /** Derived visitor method: attribute an expression tree.
  15.137       */
  15.138      public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) {
  15.139 -        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType);
  15.140 +        return attribExpr(tree, env, pt, "incompatible.types");
  15.141      }
  15.142  
  15.143      public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt, String key) {
  15.144 -        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType, key);
  15.145 +        return attribTree(tree, env, new ResultInfo(VAL, pt.tag != ERROR ? pt : Type.noType), key);
  15.146      }
  15.147  
  15.148      /** Derived visitor method: attribute an expression tree with
  15.149       *  no constraints on the computed type.
  15.150       */
  15.151      Type attribExpr(JCTree tree, Env<AttrContext> env) {
  15.152 -        return attribTree(tree, env, VAL, Type.noType);
  15.153 +        return attribTree(tree, env, unknownExprInfo);
  15.154      }
  15.155  
  15.156      /** Derived visitor method: attribute a type tree.
  15.157 @@ -475,14 +497,14 @@
  15.158      /** Derived visitor method: attribute a type tree.
  15.159       */
  15.160      Type attribType(JCTree tree, Env<AttrContext> env, Type pt) {
  15.161 -        Type result = attribTree(tree, env, TYP, pt);
  15.162 +        Type result = attribTree(tree, env, new ResultInfo(TYP, pt));
  15.163          return result;
  15.164      }
  15.165  
  15.166      /** Derived visitor method: attribute a statement or definition tree.
  15.167       */
  15.168      public Type attribStat(JCTree tree, Env<AttrContext> env) {
  15.169 -        return attribTree(tree, env, NIL, Type.noType);
  15.170 +        return attribTree(tree, env, statInfo);
  15.171      }
  15.172  
  15.173      /** Attribute a list of expressions, returning a list of types.
  15.174 @@ -507,7 +529,7 @@
  15.175          ListBuffer<Type> argtypes = new ListBuffer<Type>();
  15.176          for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
  15.177              argtypes.append(chk.checkNonVoid(
  15.178 -                l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly))));
  15.179 +                l.head.pos(), types.upperBound(attribExpr(l.head, env, Infer.anyPoly))));
  15.180          return argtypes.toList();
  15.181      }
  15.182  
  15.183 @@ -1181,7 +1203,7 @@
  15.184          result = check(tree,
  15.185                         capture(condType(tree.pos(), tree.cond.type,
  15.186                                          tree.truepart.type, tree.falsepart.type)),
  15.187 -                       VAL, pkind, pt);
  15.188 +                       VAL, resultInfo);
  15.189      }
  15.190      //where
  15.191          /** Compute the type of a conditional expression, after
  15.192 @@ -1500,8 +1522,8 @@
  15.193                      // ...and check that it is legal in the current context.
  15.194                      // (this will also set the tree's type)
  15.195                      Type mpt = newMethTemplate(argtypes, typeargtypes);
  15.196 -                    checkId(tree.meth, site, sym, localEnv, MTH,
  15.197 -                            mpt, tree.varargsElement != null);
  15.198 +                    checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt),
  15.199 +                            tree.varargsElement != null);
  15.200                  }
  15.201                  // Otherwise, `site' is an error type and we do nothing
  15.202              }
  15.203 @@ -1518,8 +1540,6 @@
  15.204              Type mpt = newMethTemplate(argtypes, typeargtypes);
  15.205              localEnv.info.varArgs = false;
  15.206              Type mtype = attribExpr(tree.meth, localEnv, mpt);
  15.207 -            if (localEnv.info.varArgs)
  15.208 -                Assert.check(mtype.isErroneous() || tree.varargsElement != null);
  15.209  
  15.210              // Compute the result type.
  15.211              Type restype = mtype.getReturnType();
  15.212 @@ -1552,7 +1572,10 @@
  15.213  
  15.214              // Check that value of resulting type is admissible in the
  15.215              // current context.  Also, capture the return type
  15.216 -            result = check(tree, capture(restype), VAL, pkind, pt);
  15.217 +            result = check(tree, capture(restype), VAL, resultInfo);
  15.218 +
  15.219 +            if (localEnv.info.varArgs)
  15.220 +                Assert.check(result.isErroneous() || tree.varargsElement != null);
  15.221          }
  15.222          chk.validate(tree.typeargs, localEnv);
  15.223      }
  15.224 @@ -1627,7 +1650,6 @@
  15.225          // Attribute clazz expression and store
  15.226          // symbol + type back into the attributed tree.
  15.227          Type clazztype = attribType(clazz, env);
  15.228 -        Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
  15.229          clazztype = chk.checkDiamond(tree, clazztype);
  15.230          chk.validate(clazz, localEnv);
  15.231          if (tree.encl != null) {
  15.232 @@ -1654,7 +1676,7 @@
  15.233          List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
  15.234  
  15.235          if (TreeInfo.isDiamond(tree) && !clazztype.isErroneous()) {
  15.236 -            clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes);
  15.237 +            clazztype = attribDiamond(localEnv, tree, clazztype, argtypes, typeargtypes);
  15.238              clazz.type = clazztype;
  15.239          } else if (allowDiamondFinder &&
  15.240                  tree.def == null &&
  15.241 @@ -1671,7 +1693,6 @@
  15.242                  inferred = attribDiamond(localEnv,
  15.243                          tree,
  15.244                          clazztype,
  15.245 -                        mapping,
  15.246                          argtypes,
  15.247                          typeargtypes);
  15.248              }
  15.249 @@ -1682,7 +1703,7 @@
  15.250              if (inferred != null &&
  15.251                      !inferred.isErroneous() &&
  15.252                      inferred.tag == CLASS &&
  15.253 -                    types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings)) {
  15.254 +                    types.isAssignable(inferred, pt().tag == NONE ? clazztype : pt(), Warner.noWarnings)) {
  15.255                  String key = types.isSameType(clazztype, inferred) ?
  15.256                      "diamond.redundant.args" :
  15.257                      "diamond.redundant.args.1";
  15.258 @@ -1732,7 +1753,7 @@
  15.259                      tree.pos(), rsEnv, clazztype, argtypes, typeargtypes);
  15.260                  tree.constructorType = tree.constructor.type.isErroneous() ?
  15.261                      syms.errType :
  15.262 -                    checkMethod(clazztype,
  15.263 +                    checkConstructor(clazztype,
  15.264                          tree.constructor,
  15.265                          rsEnv,
  15.266                          tree.args,
  15.267 @@ -1807,7 +1828,7 @@
  15.268                      tree.constructorType =  syms.errType;
  15.269                  }
  15.270                  else {
  15.271 -                    tree.constructorType = checkMethod(clazztype,
  15.272 +                    tree.constructorType = checkConstructor(clazztype,
  15.273                              tree.constructor,
  15.274                              localEnv,
  15.275                              tree.args,
  15.276 @@ -1820,19 +1841,17 @@
  15.277              if (tree.constructor != null && tree.constructor.kind == MTH)
  15.278                  owntype = clazztype;
  15.279          }
  15.280 -        result = check(tree, owntype, VAL, pkind, pt);
  15.281 +        result = check(tree, owntype, VAL, resultInfo);
  15.282          chk.validate(tree.typeargs, localEnv);
  15.283      }
  15.284  
  15.285      Type attribDiamond(Env<AttrContext> env,
  15.286                          JCNewClass tree,
  15.287                          Type clazztype,
  15.288 -                        Pair<Scope, Scope> mapping,
  15.289                          List<Type> argtypes,
  15.290                          List<Type> typeargtypes) {
  15.291          if (clazztype.isErroneous() ||
  15.292 -                clazztype.isInterface() ||
  15.293 -                mapping == erroneousMapping) {
  15.294 +                clazztype.isInterface()) {
  15.295              //if the type of the instance creation expression is erroneous,
  15.296              //or if it's an interface, or if something prevented us to form a valid
  15.297              //mapping, return the (possibly erroneous) type unchanged
  15.298 @@ -1841,27 +1860,22 @@
  15.299  
  15.300          //dup attribution environment and augment the set of inference variables
  15.301          Env<AttrContext> localEnv = env.dup(tree);
  15.302 -        localEnv.info.tvars = clazztype.tsym.type.getTypeArguments();
  15.303 +
  15.304 +        ClassType site = new ClassType(clazztype.getEnclosingType(),
  15.305 +                    clazztype.tsym.type.getTypeArguments(),
  15.306 +                    clazztype.tsym);
  15.307  
  15.308          //if the type of the instance creation expression is a class type
  15.309          //apply method resolution inference (JLS 15.12.2.7). The return type
  15.310          //of the resolved constructor will be a partially instantiated type
  15.311 -        ((ClassSymbol) clazztype.tsym).members_field = mapping.snd;
  15.312 -        Symbol constructor;
  15.313 -        try {
  15.314 -            constructor = rs.resolveDiamond(tree.pos(),
  15.315 +        Symbol constructor = rs.resolveDiamond(tree.pos(),
  15.316                      localEnv,
  15.317 -                    clazztype,
  15.318 +                    site,
  15.319                      argtypes,
  15.320                      typeargtypes);
  15.321 -        } finally {
  15.322 -            ((ClassSymbol) clazztype.tsym).members_field = mapping.fst;
  15.323 -        }
  15.324 +
  15.325          if (constructor.kind == MTH) {
  15.326 -            ClassType ct = new ClassType(clazztype.getEnclosingType(),
  15.327 -                    clazztype.tsym.type.getTypeArguments(),
  15.328 -                    clazztype.tsym);
  15.329 -            clazztype = checkMethod(ct,
  15.330 +            clazztype = checkMethod(site,
  15.331                      constructor,
  15.332                      localEnv,
  15.333                      tree.args,
  15.334 @@ -1872,13 +1886,13 @@
  15.335              clazztype = syms.errType;
  15.336          }
  15.337  
  15.338 -        if (clazztype.tag == FORALL && !pt.isErroneous()) {
  15.339 +        if (clazztype.tag == FORALL && !pt().isErroneous()) {
  15.340              //if the resolved constructor's return type has some uninferred
  15.341              //type-variables, infer them using the expected type and declared
  15.342              //bounds (JLS 15.12.2.8).
  15.343              try {
  15.344                  clazztype = infer.instantiateExpr((ForAll) clazztype,
  15.345 -                        pt.tag == NONE ? syms.objectType : pt,
  15.346 +                        pt().tag == NONE ? syms.objectType : pt(),
  15.347                          Warner.noWarnings);
  15.348              } catch (Infer.InferenceException ex) {
  15.349                  //an error occurred while inferring uninstantiated type-variables
  15.350 @@ -1893,42 +1907,6 @@
  15.351                  true);
  15.352      }
  15.353  
  15.354 -    /** Creates a synthetic scope containing fake generic constructors.
  15.355 -     *  Assuming that the original scope contains a constructor of the kind:
  15.356 -     *  Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
  15.357 -     *  the synthetic scope is added a generic constructor of the kind:
  15.358 -     *  <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
  15.359 -     *  inference. The inferred return type of the synthetic constructor IS
  15.360 -     *  the inferred type for the diamond operator.
  15.361 -     */
  15.362 -    private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
  15.363 -        if (ctype.tag != CLASS) {
  15.364 -            return erroneousMapping;
  15.365 -        }
  15.366 -
  15.367 -        Pair<Scope, Scope> mapping =
  15.368 -                new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
  15.369 -
  15.370 -        //for each constructor in the original scope, create a synthetic constructor
  15.371 -        //whose return type is the type of the class in which the constructor is
  15.372 -        //declared, and insert it into the new scope.
  15.373 -        for (Scope.Entry e = mapping.fst.lookup(names.init);
  15.374 -                e.scope != null;
  15.375 -                e = e.next()) {
  15.376 -            Type synthRestype = new ClassType(ctype.getEnclosingType(),
  15.377 -                        ctype.tsym.type.getTypeArguments(),
  15.378 -                        ctype.tsym);
  15.379 -            MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(),
  15.380 -                    names.init,
  15.381 -                    types.createMethodTypeWithReturn(e.sym.type, synthRestype),
  15.382 -                    e.sym.owner);
  15.383 -            mapping.snd.enter(synhConstr);
  15.384 -        }
  15.385 -        return mapping;
  15.386 -    }
  15.387 -
  15.388 -    private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
  15.389 -
  15.390      /** Make an attributed null check tree.
  15.391       */
  15.392      public JCExpression makeNullCheck(JCExpression arg) {
  15.393 @@ -1957,14 +1935,14 @@
  15.394          } else {
  15.395              // we are seeing an untyped aggregate { ... }
  15.396              // this is allowed only if the prototype is an array
  15.397 -            if (pt.tag == ARRAY) {
  15.398 -                elemtype = types.elemtype(pt);
  15.399 +            if (pt().tag == ARRAY) {
  15.400 +                elemtype = types.elemtype(pt());
  15.401              } else {
  15.402 -                if (pt.tag != ERROR) {
  15.403 +                if (pt().tag != ERROR) {
  15.404                      log.error(tree.pos(), "illegal.initializer.for.type",
  15.405 -                              pt);
  15.406 +                              pt());
  15.407                  }
  15.408 -                elemtype = types.createErrorType(pt);
  15.409 +                elemtype = types.createErrorType(pt());
  15.410              }
  15.411          }
  15.412          if (tree.elems != null) {
  15.413 @@ -1973,7 +1951,7 @@
  15.414          }
  15.415          if (!types.isReifiable(elemtype))
  15.416              log.error(tree.pos(), "generic.array.creation");
  15.417 -        result = check(tree, owntype, VAL, pkind, pt);
  15.418 +        result = check(tree, owntype, VAL, resultInfo);
  15.419      }
  15.420  
  15.421      @Override
  15.422 @@ -1987,23 +1965,23 @@
  15.423      }
  15.424  
  15.425      public void visitParens(JCParens tree) {
  15.426 -        Type owntype = attribTree(tree.expr, env, pkind, pt);
  15.427 -        result = check(tree, owntype, pkind, pkind, pt);
  15.428 +        Type owntype = attribTree(tree.expr, env, resultInfo);
  15.429 +        result = check(tree, owntype, pkind(), resultInfo);
  15.430          Symbol sym = TreeInfo.symbol(tree);
  15.431          if (sym != null && (sym.kind&(TYP|PCK)) != 0)
  15.432              log.error(tree.pos(), "illegal.start.of.type");
  15.433      }
  15.434  
  15.435      public void visitAssign(JCAssign tree) {
  15.436 -        Type owntype = attribTree(tree.lhs, env.dup(tree), VAR, Type.noType);
  15.437 +        Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo);
  15.438          Type capturedType = capture(owntype);
  15.439          attribExpr(tree.rhs, env, owntype);
  15.440 -        result = check(tree, capturedType, VAL, pkind, pt);
  15.441 +        result = check(tree, capturedType, VAL, resultInfo);
  15.442      }
  15.443  
  15.444      public void visitAssignop(JCAssignOp tree) {
  15.445          // Attribute arguments.
  15.446 -        Type owntype = attribTree(tree.lhs, env, VAR, Type.noType);
  15.447 +        Type owntype = attribTree(tree.lhs, env, varInfo);
  15.448          Type operand = attribExpr(tree.rhs, env);
  15.449          // Find operator.
  15.450          Symbol operator = tree.operator = rs.resolveBinaryOperator(
  15.451 @@ -2023,13 +2001,13 @@
  15.452                                operator.type.getReturnType(),
  15.453                                owntype);
  15.454          }
  15.455 -        result = check(tree, owntype, VAL, pkind, pt);
  15.456 +        result = check(tree, owntype, VAL, resultInfo);
  15.457      }
  15.458  
  15.459      public void visitUnary(JCUnary tree) {
  15.460          // Attribute arguments.
  15.461          Type argtype = (tree.getTag().isIncOrDecUnaryOp())
  15.462 -            ? attribTree(tree.arg, env, VAR, Type.noType)
  15.463 +            ? attribTree(tree.arg, env, varInfo)
  15.464              : chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env));
  15.465  
  15.466          // Find operator.
  15.467 @@ -2061,7 +2039,7 @@
  15.468                  }
  15.469              }
  15.470          }
  15.471 -        result = check(tree, owntype, VAL, pkind, pt);
  15.472 +        result = check(tree, owntype, VAL, resultInfo);
  15.473      }
  15.474  
  15.475      public void visitBinary(JCBinary tree) {
  15.476 @@ -2114,7 +2092,7 @@
  15.477  
  15.478              chk.checkDivZero(tree.rhs.pos(), operator, right);
  15.479          }
  15.480 -        result = check(tree, owntype, VAL, pkind, pt);
  15.481 +        result = check(tree, owntype, VAL, resultInfo);
  15.482      }
  15.483  
  15.484      public void visitTypeCast(JCTypeCast tree) {
  15.485 @@ -2127,7 +2105,7 @@
  15.486          Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
  15.487          if (exprtype.constValue() != null)
  15.488              owntype = cfolder.coerce(exprtype, owntype);
  15.489 -        result = check(tree, capture(owntype), VAL, pkind, pt);
  15.490 +        result = check(tree, capture(owntype), VAL, resultInfo);
  15.491      }
  15.492  
  15.493      public void visitTypeTest(JCInstanceOf tree) {
  15.494 @@ -2137,7 +2115,7 @@
  15.495              tree.clazz.pos(), attribType(tree.clazz, env));
  15.496          chk.validate(tree.clazz, env, false);
  15.497          chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
  15.498 -        result = check(tree, syms.booleanType, VAL, pkind, pt);
  15.499 +        result = check(tree, syms.booleanType, VAL, resultInfo);
  15.500      }
  15.501  
  15.502      public void visitIndexed(JCArrayAccess tree) {
  15.503 @@ -2148,8 +2126,8 @@
  15.504              owntype = types.elemtype(atype);
  15.505          else if (atype.tag != ERROR)
  15.506              log.error(tree.pos(), "array.req.but.found", atype);
  15.507 -        if ((pkind & VAR) == 0) owntype = capture(owntype);
  15.508 -        result = check(tree, owntype, VAR, pkind, pt);
  15.509 +        if ((pkind() & VAR) == 0) owntype = capture(owntype);
  15.510 +        result = check(tree, owntype, VAR, resultInfo);
  15.511      }
  15.512  
  15.513      public void visitIdent(JCIdent tree) {
  15.514 @@ -2157,16 +2135,16 @@
  15.515          boolean varArgs = false;
  15.516  
  15.517          // Find symbol
  15.518 -        if (pt.tag == METHOD || pt.tag == FORALL) {
  15.519 +        if (pt().tag == METHOD || pt().tag == FORALL) {
  15.520              // If we are looking for a method, the prototype `pt' will be a
  15.521              // method type with the type of the call's arguments as parameters.
  15.522              env.info.varArgs = false;
  15.523 -            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt.getParameterTypes(), pt.getTypeArguments());
  15.524 +            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments());
  15.525              varArgs = env.info.varArgs;
  15.526          } else if (tree.sym != null && tree.sym.kind != VAR) {
  15.527              sym = tree.sym;
  15.528          } else {
  15.529 -            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind);
  15.530 +            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind());
  15.531          }
  15.532          tree.sym = sym;
  15.533  
  15.534 @@ -2213,7 +2191,7 @@
  15.535  
  15.536              // If we are expecting a variable (as opposed to a value), check
  15.537              // that the variable is assignable in the current environment.
  15.538 -            if (pkind == VAR)
  15.539 +            if (pkind() == VAR)
  15.540                  checkAssignable(tree.pos(), v, null, env);
  15.541          }
  15.542  
  15.543 @@ -2234,7 +2212,7 @@
  15.544              while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym))
  15.545                  env1 = env1.outer;
  15.546          }
  15.547 -        result = checkId(tree, env1.enclClass.sym.type, sym, env, pkind, pt, varArgs);
  15.548 +        result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo, varArgs);
  15.549      }
  15.550  
  15.551      public void visitSelect(JCFieldAccess tree) {
  15.552 @@ -2245,14 +2223,14 @@
  15.553          {
  15.554              skind = TYP;
  15.555          } else {
  15.556 -            if ((pkind & PCK) != 0) skind = skind | PCK;
  15.557 -            if ((pkind & TYP) != 0) skind = skind | TYP | PCK;
  15.558 -            if ((pkind & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
  15.559 +            if ((pkind() & PCK) != 0) skind = skind | PCK;
  15.560 +            if ((pkind() & TYP) != 0) skind = skind | TYP | PCK;
  15.561 +            if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
  15.562          }
  15.563  
  15.564          // Attribute the qualifier expression, and determine its symbol (if any).
  15.565 -        Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
  15.566 -        if ((pkind & (PCK | TYP)) == 0)
  15.567 +        Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly));
  15.568 +        if ((pkind() & (PCK | TYP)) == 0)
  15.569              site = capture(site); // Capture field access
  15.570  
  15.571          // don't allow T.class T[].class, etc
  15.572 @@ -2287,10 +2265,10 @@
  15.573  
  15.574          // Determine the symbol represented by the selection.
  15.575          env.info.varArgs = false;
  15.576 -        Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
  15.577 -        if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
  15.578 +        Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
  15.579 +        if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) {
  15.580              site = capture(site);
  15.581 -            sym = selectSym(tree, sitesym, site, env, pt, pkind);
  15.582 +            sym = selectSym(tree, sitesym, site, env, resultInfo);
  15.583          }
  15.584          boolean varArgs = env.info.varArgs;
  15.585          tree.sym = sym;
  15.586 @@ -2310,7 +2288,7 @@
  15.587  
  15.588              // If we are expecting a variable (as opposed to a value), check
  15.589              // that the variable is assignable in the current environment.
  15.590 -            if (pkind == VAR)
  15.591 +            if (pkind() == VAR)
  15.592                  checkAssignable(tree.pos(), v, tree.selected, env);
  15.593          }
  15.594  
  15.595 @@ -2326,8 +2304,8 @@
  15.596  
  15.597          // Disallow selecting a type from an expression
  15.598          if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) {
  15.599 -            tree.type = check(tree.selected, pt,
  15.600 -                              sitesym == null ? VAL : sitesym.kind, TYP|PCK, pt);
  15.601 +            tree.type = check(tree.selected, pt(),
  15.602 +                              sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt()));
  15.603          }
  15.604  
  15.605          if (isType(sitesym)) {
  15.606 @@ -2367,7 +2345,7 @@
  15.607          }
  15.608  
  15.609          env.info.selectSuper = selectSuperPrev;
  15.610 -        result = checkId(tree, site, sym, env, pkind, pt, varArgs);
  15.611 +        result = checkId(tree, site, sym, env, resultInfo, varArgs);
  15.612          env.info.tvars = List.nil();
  15.613      }
  15.614      //where
  15.615 @@ -2376,34 +2354,25 @@
  15.616           *  @param tree   The select tree.
  15.617           *  @param site   The type of the selected expression,
  15.618           *  @param env    The current environment.
  15.619 -         *  @param pt     The current prototype.
  15.620 -         *  @param pkind  The expected kind(s) of the Select expression.
  15.621 +         *  @param resultInfo The current result.
  15.622           */
  15.623          private Symbol selectSym(JCFieldAccess tree,
  15.624 -                                     Type site,
  15.625 -                                     Env<AttrContext> env,
  15.626 -                                     Type pt,
  15.627 -                                     int pkind) {
  15.628 -            return selectSym(tree, site.tsym, site, env, pt, pkind);
  15.629 -        }
  15.630 -        private Symbol selectSym(JCFieldAccess tree,
  15.631                                   Symbol location,
  15.632                                   Type site,
  15.633                                   Env<AttrContext> env,
  15.634 -                                 Type pt,
  15.635 -                                 int pkind) {
  15.636 +                                 ResultInfo resultInfo) {
  15.637              DiagnosticPosition pos = tree.pos();
  15.638              Name name = tree.name;
  15.639              switch (site.tag) {
  15.640              case PACKAGE:
  15.641                  return rs.access(
  15.642 -                    rs.findIdentInPackage(env, site.tsym, name, pkind),
  15.643 +                    rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind),
  15.644                      pos, location, site, name, true);
  15.645              case ARRAY:
  15.646              case CLASS:
  15.647 -                if (pt.tag == METHOD || pt.tag == FORALL) {
  15.648 +                if (resultInfo.pt.tag == METHOD || resultInfo.pt.tag == FORALL) {
  15.649                      return rs.resolveQualifiedMethod(
  15.650 -                        pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
  15.651 +                        pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments());
  15.652                  } else if (name == names._this || name == names._super) {
  15.653                      return rs.resolveSelf(pos, env, site.tsym, name);
  15.654                  } else if (name == names._class) {
  15.655 @@ -2418,8 +2387,8 @@
  15.656                          STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
  15.657                  } else {
  15.658                      // We are seeing a plain identifier as selector.
  15.659 -                    Symbol sym = rs.findIdentInType(env, site, name, pkind);
  15.660 -                    if ((pkind & ERRONEOUS) == 0)
  15.661 +                    Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind);
  15.662 +                    if ((resultInfo.pkind & ERRONEOUS) == 0)
  15.663                          sym = rs.access(sym, pos, location, site, name, true);
  15.664                      return sym;
  15.665                  }
  15.666 @@ -2433,7 +2402,7 @@
  15.667                  // other words, we are seeing this illegal program:
  15.668                  // class B<T> extends A<T.foo> {}
  15.669                  Symbol sym = (site.getUpperBound() != null)
  15.670 -                    ? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind)
  15.671 +                    ? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo)
  15.672                      : null;
  15.673                  if (sym == null) {
  15.674                      log.error(pos, "type.var.cant.be.deref");
  15.675 @@ -2487,17 +2456,15 @@
  15.676           *                    expression, otherwise the type of the current class.
  15.677           *  @param sym        The symbol representing the identifier.
  15.678           *  @param env        The current environment.
  15.679 -         *  @param pkind      The set of expected kinds.
  15.680 -         *  @param pt         The expected type.
  15.681 +         *  @param resultInfo    The expected result
  15.682           */
  15.683          Type checkId(JCTree tree,
  15.684                       Type site,
  15.685                       Symbol sym,
  15.686                       Env<AttrContext> env,
  15.687 -                     int pkind,
  15.688 -                     Type pt,
  15.689 +                     ResultInfo resultInfo,
  15.690                       boolean useVarargs) {
  15.691 -            if (pt.isErroneous()) return types.createErrorType(site);
  15.692 +            if (resultInfo.pt.isErroneous()) return types.createErrorType(site);
  15.693              Type owntype; // The computed type of this identifier occurrence.
  15.694              switch (sym.kind) {
  15.695              case TYP:
  15.696 @@ -2542,7 +2509,7 @@
  15.697                  // which is being assigned to, issue an unchecked warning if
  15.698                  // its type changes under erasure.
  15.699                  if (allowGenerics &&
  15.700 -                    pkind == VAR &&
  15.701 +                    resultInfo.pkind == VAR &&
  15.702                      v.owner.kind == TYP &&
  15.703                      (v.flags() & STATIC) == 0 &&
  15.704                      (site.tag == CLASS || site.tag == TYPEVAR)) {
  15.705 @@ -2577,14 +2544,14 @@
  15.706                  if (v.getConstValue() != null && isStaticReference(tree))
  15.707                      owntype = owntype.constType(v.getConstValue());
  15.708  
  15.709 -                if (pkind == VAL) {
  15.710 +                if (resultInfo.pkind == VAL) {
  15.711                      owntype = capture(owntype); // capture "names as expressions"
  15.712                  }
  15.713                  break;
  15.714              case MTH: {
  15.715                  JCMethodInvocation app = (JCMethodInvocation)env.tree;
  15.716                  owntype = checkMethod(site, sym, env, app.args,
  15.717 -                                      pt.getParameterTypes(), pt.getTypeArguments(),
  15.718 +                                      resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments(),
  15.719                                        env.info.varArgs);
  15.720                  break;
  15.721              }
  15.722 @@ -2607,7 +2574,7 @@
  15.723  
  15.724              // Test (3): if symbol is a variable, check that its type and
  15.725              // kind are compatible with the prototype and protokind.
  15.726 -            return check(tree, owntype, sym.kind, pkind, pt);
  15.727 +            return check(tree, owntype, sym.kind, resultInfo);
  15.728          }
  15.729  
  15.730          /** Check that variable is initialized and evaluate the variable's
  15.731 @@ -2720,7 +2687,7 @@
  15.732      Warner noteWarner = new Warner();
  15.733  
  15.734      /**
  15.735 -     * Check that method arguments conform to its instantation.
  15.736 +     * Check that method arguments conform to its instantiation.
  15.737       **/
  15.738      public Type checkMethod(Type site,
  15.739                              Symbol sym,
  15.740 @@ -2757,112 +2724,44 @@
  15.741                                        true,
  15.742                                        useVarargs,
  15.743                                        noteWarner);
  15.744 -        boolean warned = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
  15.745 +
  15.746 +        boolean unchecked = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
  15.747  
  15.748          // If this fails, something went wrong; we should not have
  15.749          // found the identifier in the first place.
  15.750          if (owntype == null) {
  15.751 -            if (!pt.isErroneous())
  15.752 +            if (!pt().isErroneous())
  15.753                  log.error(env.tree.pos(),
  15.754 -                          "internal.error.cant.instantiate",
  15.755 -                          sym, site,
  15.756 -                          Type.toString(pt.getParameterTypes()));
  15.757 +                           "internal.error.cant.instantiate",
  15.758 +                           sym, site,
  15.759 +                          Type.toString(pt().getParameterTypes()));
  15.760              owntype = types.createErrorType(site);
  15.761 +            return types.createErrorType(site);
  15.762 +        } else if (owntype.getReturnType().tag == FORALL && !unchecked) {
  15.763 +            return owntype;
  15.764          } else {
  15.765 -            // System.out.println("call   : " + env.tree);
  15.766 -            // System.out.println("method : " + owntype);
  15.767 -            // System.out.println("actuals: " + argtypes);
  15.768 -            List<Type> formals = owntype.getParameterTypes();
  15.769 -            Type last = useVarargs ? formals.last() : null;
  15.770 -            if (sym.name==names.init &&
  15.771 -                sym.owner == syms.enumSym)
  15.772 -                formals = formals.tail.tail;
  15.773 -            List<JCExpression> args = argtrees;
  15.774 -            while (formals.head != last) {
  15.775 -                JCTree arg = args.head;
  15.776 -                Warner warn = chk.convertWarner(arg.pos(), arg.type, formals.head);
  15.777 -                assertConvertible(arg, arg.type, formals.head, warn);
  15.778 -                warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
  15.779 -                args = args.tail;
  15.780 -                formals = formals.tail;
  15.781 -            }
  15.782 -            if (useVarargs) {
  15.783 -                Type varArg = types.elemtype(last);
  15.784 -                while (args.tail != null) {
  15.785 -                    JCTree arg = args.head;
  15.786 -                    Warner warn = chk.convertWarner(arg.pos(), arg.type, varArg);
  15.787 -                    assertConvertible(arg, arg.type, varArg, warn);
  15.788 -                    warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
  15.789 -                    args = args.tail;
  15.790 -                }
  15.791 -            } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
  15.792 -                // non-varargs call to varargs method
  15.793 -                Type varParam = owntype.getParameterTypes().last();
  15.794 -                Type lastArg = argtypes.last();
  15.795 -                if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
  15.796 -                    !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
  15.797 -                    log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
  15.798 -                                types.elemtype(varParam),
  15.799 -                                varParam);
  15.800 -            }
  15.801 -
  15.802 -            if (warned && sym.type.tag == FORALL) {
  15.803 -                chk.warnUnchecked(env.tree.pos(),
  15.804 -                                  "unchecked.meth.invocation.applied",
  15.805 -                                  kindName(sym),
  15.806 -                                  sym.name,
  15.807 -                                  rs.methodArguments(sym.type.getParameterTypes()),
  15.808 -                                  rs.methodArguments(argtypes),
  15.809 -                                  kindName(sym.location()),
  15.810 -                                  sym.location());
  15.811 -                owntype = new MethodType(owntype.getParameterTypes(),
  15.812 -                                         types.erasure(owntype.getReturnType()),
  15.813 -                                         types.erasure(owntype.getThrownTypes()),
  15.814 -                                         syms.methodClass);
  15.815 -            }
  15.816 -            if (useVarargs) {
  15.817 -                JCTree tree = env.tree;
  15.818 -                Type argtype = owntype.getParameterTypes().last();
  15.819 -                if (owntype.getReturnType().tag != FORALL || warned) {
  15.820 -                    chk.checkVararg(env.tree.pos(), owntype.getParameterTypes(), sym);
  15.821 -                }
  15.822 -                Type elemtype = types.elemtype(argtype);
  15.823 -                switch (tree.getTag()) {
  15.824 -                case APPLY:
  15.825 -                    ((JCMethodInvocation) tree).varargsElement = elemtype;
  15.826 -                    break;
  15.827 -                case NEWCLASS:
  15.828 -                    ((JCNewClass) tree).varargsElement = elemtype;
  15.829 -                    break;
  15.830 -                default:
  15.831 -                    throw new AssertionError(""+tree);
  15.832 -                }
  15.833 -            }
  15.834 +            return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked);
  15.835          }
  15.836 +    }
  15.837 +
  15.838 +    /**
  15.839 +     * Check that constructor arguments conform to its instantiation.
  15.840 +     **/
  15.841 +    public Type checkConstructor(Type site,
  15.842 +                            Symbol sym,
  15.843 +                            Env<AttrContext> env,
  15.844 +                            final List<JCExpression> argtrees,
  15.845 +                            List<Type> argtypes,
  15.846 +                            List<Type> typeargtypes,
  15.847 +                            boolean useVarargs) {
  15.848 +        Type owntype = checkMethod(site, sym, env, argtrees, argtypes, typeargtypes, useVarargs);
  15.849 +        chk.checkType(env.tree.pos(), owntype.getReturnType(), syms.voidType);
  15.850          return owntype;
  15.851      }
  15.852  
  15.853 -    private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
  15.854 -        if (types.isConvertible(actual, formal, warn))
  15.855 -            return;
  15.856 -
  15.857 -        if (formal.isCompound()
  15.858 -            && types.isSubtype(actual, types.supertype(formal))
  15.859 -            && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
  15.860 -            return;
  15.861 -
  15.862 -        if (false) {
  15.863 -            // TODO: make assertConvertible work
  15.864 -            chk.typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal);
  15.865 -            throw new AssertionError("Tree: " + tree
  15.866 -                                     + " actual:" + actual
  15.867 -                                     + " formal: " + formal);
  15.868 -        }
  15.869 -    }
  15.870 -
  15.871      public void visitLiteral(JCLiteral tree) {
  15.872          result = check(
  15.873 -            tree, litType(tree.typetag).constType(tree.value), VAL, pkind, pt);
  15.874 +            tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo);
  15.875      }
  15.876      //where
  15.877      /** Return the type of a literal with given type tag.
  15.878 @@ -2872,13 +2771,13 @@
  15.879      }
  15.880  
  15.881      public void visitTypeIdent(JCPrimitiveTypeTree tree) {
  15.882 -        result = check(tree, syms.typeOfTag[tree.typetag], TYP, pkind, pt);
  15.883 +        result = check(tree, syms.typeOfTag[tree.typetag], TYP, resultInfo);
  15.884      }
  15.885  
  15.886      public void visitTypeArray(JCArrayTypeTree tree) {
  15.887          Type etype = attribType(tree.elemtype, env);
  15.888          Type type = new ArrayType(etype, syms.arrayClass);
  15.889 -        result = check(tree, type, TYP, pkind, pt);
  15.890 +        result = check(tree, type, TYP, resultInfo);
  15.891      }
  15.892  
  15.893      /** Visitor method for parameterized types.
  15.894 @@ -2936,7 +2835,7 @@
  15.895                  owntype = types.createErrorType(tree.type);
  15.896              }
  15.897          }
  15.898 -        result = check(tree, owntype, TYP, pkind, pt);
  15.899 +        result = check(tree, owntype, TYP, resultInfo);
  15.900      }
  15.901  
  15.902      public void visitTypeUnion(JCTypeUnion tree) {
  15.903 @@ -2973,7 +2872,7 @@
  15.904                  all_multicatchTypes.append(ctype);
  15.905              }
  15.906          }
  15.907 -        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
  15.908 +        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo);
  15.909          if (t.tag == CLASS) {
  15.910              List<Type> alternatives =
  15.911                  ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList();
  15.912 @@ -3059,18 +2958,18 @@
  15.913          result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type),
  15.914                                                tree.kind.kind,
  15.915                                                syms.boundClass),
  15.916 -                       TYP, pkind, pt);
  15.917 +                       TYP, resultInfo);
  15.918      }
  15.919  
  15.920      public void visitAnnotation(JCAnnotation tree) {
  15.921 -        log.error(tree.pos(), "annotation.not.valid.for.type", pt);
  15.922 +        log.error(tree.pos(), "annotation.not.valid.for.type", pt());
  15.923          result = tree.type = syms.errType;
  15.924      }
  15.925  
  15.926      public void visitErroneous(JCErroneous tree) {
  15.927          if (tree.errs != null)
  15.928              for (JCTree err : tree.errs)
  15.929 -                attribTree(err, env, ERR, pt);
  15.930 +                attribTree(err, env, new ResultInfo(ERR, pt()));
  15.931          result = tree.type = syms.errType;
  15.932      }
  15.933  
    16.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Mar 08 20:35:26 2012 -0800
    16.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Mar 09 11:59:26 2012 -0800
    16.3 @@ -63,6 +63,7 @@
    16.4  
    16.5      private final Names names;
    16.6      private final Log log;
    16.7 +    private final Resolve rs;
    16.8      private final Symtab syms;
    16.9      private final Enter enter;
   16.10      private final Infer infer;
   16.11 @@ -95,6 +96,7 @@
   16.12  
   16.13          names = Names.instance(context);
   16.14          log = Log.instance(context);
   16.15 +        rs = Resolve.instance(context);
   16.16          syms = Symtab.instance(context);
   16.17          enter = Enter.instance(context);
   16.18          infer = Infer.instance(context);
   16.19 @@ -106,6 +108,7 @@
   16.20  
   16.21          Source source = Source.instance(context);
   16.22          allowGenerics = source.allowGenerics();
   16.23 +        allowVarargs = source.allowVarargs();
   16.24          allowAnnotations = source.allowAnnotations();
   16.25          allowCovariantReturns = source.allowCovariantReturns();
   16.26          allowSimplifiedVarargs = source.allowSimplifiedVarargs();
   16.27 @@ -137,6 +140,10 @@
   16.28       */
   16.29      boolean allowGenerics;
   16.30  
   16.31 +    /** Switch: varargs enabled?
   16.32 +     */
   16.33 +    boolean allowVarargs;
   16.34 +
   16.35      /** Switch: annotations enabled?
   16.36       */
   16.37      boolean allowAnnotations;
   16.38 @@ -525,16 +532,16 @@
   16.39       *  @param a             The type that should be bounded by bs.
   16.40       *  @param bs            The bound.
   16.41       */
   16.42 -    private boolean checkExtends(Type a, TypeVar bs) {
   16.43 +    private boolean checkExtends(Type a, Type bound) {
   16.44           if (a.isUnbound()) {
   16.45               return true;
   16.46           } else if (a.tag != WILDCARD) {
   16.47               a = types.upperBound(a);
   16.48 -             return types.isSubtype(a, bs.bound);
   16.49 +             return types.isSubtype(a, bound);
   16.50           } else if (a.isExtendsBound()) {
   16.51 -             return types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings);
   16.52 +             return types.isCastable(bound, types.upperBound(a), Warner.noWarnings);
   16.53           } else if (a.isSuperBound()) {
   16.54 -             return !types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound());
   16.55 +             return !types.notSoftSubtype(types.lowerBound(a), bound);
   16.56           }
   16.57           return true;
   16.58       }
   16.59 @@ -743,22 +750,103 @@
   16.60                      (s.flags() & (STATIC | FINAL)) != 0);
   16.61          }
   16.62  
   16.63 -    /**
   16.64 -     * Check that vararg method call is sound
   16.65 -     * @param pos Position to be used for error reporting.
   16.66 -     * @param argtypes Actual arguments supplied to vararg method.
   16.67 -     */
   16.68 -    void checkVararg(DiagnosticPosition pos, List<Type> argtypes, Symbol msym) {
   16.69 -        Type argtype = argtypes.last();
   16.70 -        if (!types.isReifiable(argtype) &&
   16.71 -                (!allowSimplifiedVarargs ||
   16.72 -                msym.attribute(syms.trustMeType.tsym) == null ||
   16.73 -                !isTrustMeAllowedOnMethod(msym))) {
   16.74 -            warnUnchecked(pos,
   16.75 -                              "unchecked.generic.array.creation",
   16.76 -                              argtype);
   16.77 +    Type checkMethod(Type owntype,
   16.78 +                            Symbol sym,
   16.79 +                            Env<AttrContext> env,
   16.80 +                            final List<JCExpression> argtrees,
   16.81 +                            List<Type> argtypes,
   16.82 +                            boolean useVarargs,
   16.83 +                            boolean unchecked) {
   16.84 +        // System.out.println("call   : " + env.tree);
   16.85 +        // System.out.println("method : " + owntype);
   16.86 +        // System.out.println("actuals: " + argtypes);
   16.87 +        List<Type> formals = owntype.getParameterTypes();
   16.88 +        Type last = useVarargs ? formals.last() : null;
   16.89 +        if (sym.name==names.init &&
   16.90 +                sym.owner == syms.enumSym)
   16.91 +                formals = formals.tail.tail;
   16.92 +        List<JCExpression> args = argtrees;
   16.93 +        while (formals.head != last) {
   16.94 +            JCTree arg = args.head;
   16.95 +            Warner warn = convertWarner(arg.pos(), arg.type, formals.head);
   16.96 +            assertConvertible(arg, arg.type, formals.head, warn);
   16.97 +            args = args.tail;
   16.98 +            formals = formals.tail;
   16.99          }
  16.100 +        if (useVarargs) {
  16.101 +            Type varArg = types.elemtype(last);
  16.102 +            while (args.tail != null) {
  16.103 +                JCTree arg = args.head;
  16.104 +                Warner warn = convertWarner(arg.pos(), arg.type, varArg);
  16.105 +                assertConvertible(arg, arg.type, varArg, warn);
  16.106 +                args = args.tail;
  16.107 +            }
  16.108 +        } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
  16.109 +            // non-varargs call to varargs method
  16.110 +            Type varParam = owntype.getParameterTypes().last();
  16.111 +            Type lastArg = argtypes.last();
  16.112 +            if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
  16.113 +                    !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
  16.114 +                log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
  16.115 +                        types.elemtype(varParam), varParam);
  16.116 +        }
  16.117 +        if (unchecked) {
  16.118 +            warnUnchecked(env.tree.pos(),
  16.119 +                    "unchecked.meth.invocation.applied",
  16.120 +                    kindName(sym),
  16.121 +                    sym.name,
  16.122 +                    rs.methodArguments(sym.type.getParameterTypes()),
  16.123 +                    rs.methodArguments(argtypes),
  16.124 +                    kindName(sym.location()),
  16.125 +                    sym.location());
  16.126 +           owntype = new MethodType(owntype.getParameterTypes(),
  16.127 +                   types.erasure(owntype.getReturnType()),
  16.128 +                   types.erasure(owntype.getThrownTypes()),
  16.129 +                   syms.methodClass);
  16.130 +        }
  16.131 +        if (useVarargs) {
  16.132 +            JCTree tree = env.tree;
  16.133 +            Type argtype = owntype.getParameterTypes().last();
  16.134 +            if (!types.isReifiable(argtype) &&
  16.135 +                    (!allowSimplifiedVarargs ||
  16.136 +                    sym.attribute(syms.trustMeType.tsym) == null ||
  16.137 +                    !isTrustMeAllowedOnMethod(sym))) {
  16.138 +                warnUnchecked(env.tree.pos(),
  16.139 +                                  "unchecked.generic.array.creation",
  16.140 +                                  argtype);
  16.141 +            }
  16.142 +            Type elemtype = types.elemtype(argtype);
  16.143 +            switch (tree.getTag()) {
  16.144 +                case APPLY:
  16.145 +                    ((JCMethodInvocation) tree).varargsElement = elemtype;
  16.146 +                    break;
  16.147 +                case NEWCLASS:
  16.148 +                    ((JCNewClass) tree).varargsElement = elemtype;
  16.149 +                    break;
  16.150 +                default:
  16.151 +                    throw new AssertionError(""+tree);
  16.152 +            }
  16.153 +         }
  16.154 +         return owntype;
  16.155      }
  16.156 +    //where
  16.157 +        private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
  16.158 +            if (types.isConvertible(actual, formal, warn))
  16.159 +                return;
  16.160 +
  16.161 +            if (formal.isCompound()
  16.162 +                && types.isSubtype(actual, types.supertype(formal))
  16.163 +                && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
  16.164 +                return;
  16.165 +
  16.166 +            if (false) {
  16.167 +                // TODO: make assertConvertible work
  16.168 +                typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal);
  16.169 +                throw new AssertionError("Tree: " + tree
  16.170 +                                         + " actual:" + actual
  16.171 +                                         + " formal: " + formal);
  16.172 +            }
  16.173 +        }
  16.174  
  16.175      /**
  16.176       * Check that type 't' is a valid instantiation of a generic class
  16.177 @@ -776,18 +864,16 @@
  16.178              List<Type> actuals = type.allparams();
  16.179              List<Type> args = type.getTypeArguments();
  16.180              List<Type> forms = type.tsym.type.getTypeArguments();
  16.181 -            ListBuffer<Type> tvars_buf = new ListBuffer<Type>();
  16.182 +            ListBuffer<Type> bounds_buf = new ListBuffer<Type>();
  16.183  
  16.184              // For matching pairs of actual argument types `a' and
  16.185              // formal type parameters with declared bound `b' ...
  16.186              while (args.nonEmpty() && forms.nonEmpty()) {
  16.187                  // exact type arguments needs to know their
  16.188                  // bounds (for upper and lower bound
  16.189 -                // calculations).  So we create new TypeVars with
  16.190 -                // bounds substed with actuals.
  16.191 -                tvars_buf.append(types.substBound(((TypeVar)forms.head),
  16.192 -                                                  formals,
  16.193 -                                                  actuals));
  16.194 +                // calculations).  So we create new bounds where
  16.195 +                // type-parameters are replaced with actuals argument types.
  16.196 +                bounds_buf.append(types.subst(forms.head.getUpperBound(), formals, actuals));
  16.197                  args = args.tail;
  16.198                  forms = forms.tail;
  16.199              }
  16.200 @@ -804,32 +890,30 @@
  16.201              }
  16.202  
  16.203              args = type.getTypeArguments();
  16.204 -            List<Type> tvars = tvars_buf.toList();
  16.205 +            List<Type> bounds = bounds_buf.toList();
  16.206  
  16.207 -            while (args.nonEmpty() && tvars.nonEmpty()) {
  16.208 -                Type actual = types.subst(args.head,
  16.209 -                    type.tsym.type.getTypeArguments(),
  16.210 -                    tvars_buf.toList());
  16.211 +            while (args.nonEmpty() && bounds.nonEmpty()) {
  16.212 +                Type actual = args.head;
  16.213                  if (!isTypeArgErroneous(actual) &&
  16.214 -                        !tvars.head.getUpperBound().isErroneous() &&
  16.215 -                        !checkExtends(actual, (TypeVar)tvars.head)) {
  16.216 +                        !bounds.head.isErroneous() &&
  16.217 +                        !checkExtends(actual, bounds.head)) {
  16.218                      return args.head;
  16.219                  }
  16.220                  args = args.tail;
  16.221 -                tvars = tvars.tail;
  16.222 +                bounds = bounds.tail;
  16.223              }
  16.224  
  16.225              args = type.getTypeArguments();
  16.226 -            tvars = tvars_buf.toList();
  16.227 +            bounds = bounds_buf.toList();
  16.228  
  16.229              for (Type arg : types.capture(type).getTypeArguments()) {
  16.230                  if (arg.tag == TYPEVAR &&
  16.231                          arg.getUpperBound().isErroneous() &&
  16.232 -                        !tvars.head.getUpperBound().isErroneous() &&
  16.233 +                        !bounds.head.isErroneous() &&
  16.234                          !isTypeArgErroneous(args.head)) {
  16.235                      return args.head;
  16.236                  }
  16.237 -                tvars = tvars.tail;
  16.238 +                bounds = bounds.tail;
  16.239                  args = args.tail;
  16.240              }
  16.241  
  16.242 @@ -2492,7 +2576,7 @@
  16.243                      if (enableSunApiLintControl)
  16.244                        warnSunApi(pos, "sun.proprietary", s);
  16.245                      else
  16.246 -                      log.strictWarning(pos, "sun.proprietary", s);
  16.247 +                      log.mandatoryWarning(pos, "sun.proprietary", s);
  16.248                  }
  16.249              });
  16.250          }
    17.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Mar 08 20:35:26 2012 -0800
    17.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Mar 09 11:59:26 2012 -0800
    17.3 @@ -385,7 +385,6 @@
    17.4                                    final Warner warn) throws InferenceException {
    17.5          //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
    17.6          List<Type> undetvars = Type.map(tvars, fromTypeVarFun);
    17.7 -        //final List<Type> capturedArgs = types.capture(argtypes);
    17.8  
    17.9          final List<Type> capturedArgs =
   17.10                  rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(),
   17.11 @@ -445,16 +444,20 @@
   17.12                      return List.nil();
   17.13                  }
   17.14                  @Override
   17.15 -                void check(List<Type> inferred, Types types) throws NoInstanceException {
   17.16 +                void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
   17.17 +                    Type owntype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
   17.18 +                                       restype,
   17.19 +                                       types.subst(getThrownTypes(), tvars, inferred),
   17.20 +                                       qtype.tsym);
   17.21                      // check that actuals conform to inferred formals
   17.22 -                    checkArgumentsAcceptable(env, capturedArgs, getParameterTypes(), allowBoxing, useVarargs, warn);
   17.23 +                    warn.clear();
   17.24 +                    checkArgumentsAcceptable(env, capturedArgs, owntype.getParameterTypes(), allowBoxing, useVarargs, warn);
   17.25                      // check that inferred bounds conform to their bounds
   17.26                      checkWithinBounds(all_tvars,
   17.27                             types.subst(inferredTypes, tvars, inferred), warn);
   17.28 -                    if (useVarargs) {
   17.29 -                        chk.checkVararg(env.tree.pos(), getParameterTypes(), msym);
   17.30 -                    }
   17.31 -            }};
   17.32 +                    qtype = chk.checkMethod(owntype, msym, env, TreeInfo.args(env.tree), capturedArgs, useVarargs, warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED));
   17.33 +                }
   17.34 +            };
   17.35          }
   17.36          else {
   17.37              // check that actuals conform to inferred formals
   17.38 @@ -520,16 +523,7 @@
   17.39                  return qtype.map(f);
   17.40              }
   17.41  
   17.42 -            void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
   17.43 -                //update method type with newly inferred type-arguments
   17.44 -                qtype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
   17.45 -                                       restype,
   17.46 -                                       types.subst(UninferredMethodType.this.getThrownTypes(), tvars, inferred),
   17.47 -                                       UninferredMethodType.this.qtype.tsym);
   17.48 -                check(inferred, types);
   17.49 -            }
   17.50 -
   17.51 -            abstract void check(List<Type> inferred, Types types) throws NoInstanceException;
   17.52 +            abstract void instantiateReturnType(Type restype, List<Type> inferred, Types types);
   17.53  
   17.54              abstract List<Type> getConstraints(TypeVar tv, ConstraintKind ck);
   17.55  
   17.56 @@ -544,7 +538,7 @@
   17.57                      if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
   17.58                          log.note(pos, "deferred.method.inst", msym, UninferredMethodType.this.qtype, newRestype);
   17.59                      }
   17.60 -                    return newRestype;
   17.61 +                    return UninferredMethodType.this.qtype.getReturnType();
   17.62                  }
   17.63                  @Override
   17.64                  public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
    18.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Thu Mar 08 20:35:26 2012 -0800
    18.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Mar 09 11:59:26 2012 -0800
    18.3 @@ -529,24 +529,17 @@
    18.4  
    18.5      // process the non-static imports and the static imports of types.
    18.6      public void visitImport(JCImport tree) {
    18.7 -        JCTree imp = tree.qualid;
    18.8 +        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
    18.9          Name name = TreeInfo.name(imp);
   18.10 -        TypeSymbol p;
   18.11  
   18.12          // Create a local environment pointing to this tree to disable
   18.13          // effects of other imports in Resolve.findGlobalType
   18.14          Env<AttrContext> localEnv = env.dup(tree);
   18.15  
   18.16 -        // Attribute qualifying package or class.
   18.17 -        JCFieldAccess s = (JCFieldAccess) imp;
   18.18 -        p = attr.
   18.19 -            attribTree(s.selected,
   18.20 -                       localEnv,
   18.21 -                       tree.staticImport ? TYP : (TYP | PCK),
   18.22 -                       Type.noType).tsym;
   18.23 +        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
   18.24          if (name == names.asterisk) {
   18.25              // Import on demand.
   18.26 -            chk.checkCanonical(s.selected);
   18.27 +            chk.checkCanonical(imp.selected);
   18.28              if (tree.staticImport)
   18.29                  importStaticAll(tree.pos, p, env);
   18.30              else
   18.31 @@ -555,7 +548,7 @@
   18.32              // Named type import.
   18.33              if (tree.staticImport) {
   18.34                  importNamedStatic(tree.pos(), p, name, localEnv);
   18.35 -                chk.checkCanonical(s.selected);
   18.36 +                chk.checkCanonical(imp.selected);
   18.37              } else {
   18.38                  TypeSymbol c = attribImportType(imp, localEnv).tsym;
   18.39                  chk.checkCanonical(imp);
    19.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Mar 08 20:35:26 2012 -0800
    19.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Mar 09 11:59:26 2012 -0800
    19.3 @@ -29,6 +29,7 @@
    19.4  import com.sun.tools.javac.code.*;
    19.5  import com.sun.tools.javac.code.Type.*;
    19.6  import com.sun.tools.javac.code.Symbol.*;
    19.7 +import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate;
    19.8  import com.sun.tools.javac.jvm.*;
    19.9  import com.sun.tools.javac.tree.*;
   19.10  import com.sun.tools.javac.tree.JCTree.*;
   19.11 @@ -39,10 +40,9 @@
   19.12  
   19.13  import java.util.Arrays;
   19.14  import java.util.Collection;
   19.15 +import java.util.EnumMap;
   19.16  import java.util.EnumSet;
   19.17 -import java.util.HashMap;
   19.18  import java.util.HashSet;
   19.19 -import java.util.LinkedHashMap;
   19.20  import java.util.Map;
   19.21  import java.util.Set;
   19.22  
   19.23 @@ -84,6 +84,58 @@
   19.24  
   19.25      Scope polymorphicSignatureScope;
   19.26  
   19.27 +    protected Resolve(Context context) {
   19.28 +        context.put(resolveKey, this);
   19.29 +        syms = Symtab.instance(context);
   19.30 +
   19.31 +        varNotFound = new
   19.32 +            SymbolNotFoundError(ABSENT_VAR);
   19.33 +        wrongMethod = new
   19.34 +            InapplicableSymbolError();
   19.35 +        wrongMethods = new
   19.36 +            InapplicableSymbolsError();
   19.37 +        methodNotFound = new
   19.38 +            SymbolNotFoundError(ABSENT_MTH);
   19.39 +        typeNotFound = new
   19.40 +            SymbolNotFoundError(ABSENT_TYP);
   19.41 +
   19.42 +        names = Names.instance(context);
   19.43 +        log = Log.instance(context);
   19.44 +        chk = Check.instance(context);
   19.45 +        infer = Infer.instance(context);
   19.46 +        reader = ClassReader.instance(context);
   19.47 +        treeinfo = TreeInfo.instance(context);
   19.48 +        types = Types.instance(context);
   19.49 +        diags = JCDiagnostic.Factory.instance(context);
   19.50 +        Source source = Source.instance(context);
   19.51 +        boxingEnabled = source.allowBoxing();
   19.52 +        varargsEnabled = source.allowVarargs();
   19.53 +        Options options = Options.instance(context);
   19.54 +        debugResolve = options.isSet("debugresolve");
   19.55 +        verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
   19.56 +        Target target = Target.instance(context);
   19.57 +        allowMethodHandles = target.hasMethodHandles();
   19.58 +        polymorphicSignatureScope = new Scope(syms.noSymbol);
   19.59 +
   19.60 +        inapplicableMethodException = new InapplicableMethodException(diags);
   19.61 +    }
   19.62 +
   19.63 +    /** error symbols, which are returned when resolution fails
   19.64 +     */
   19.65 +    private final SymbolNotFoundError varNotFound;
   19.66 +    private final InapplicableSymbolError wrongMethod;
   19.67 +    private final InapplicableSymbolsError wrongMethods;
   19.68 +    private final SymbolNotFoundError methodNotFound;
   19.69 +    private final SymbolNotFoundError typeNotFound;
   19.70 +
   19.71 +    public static Resolve instance(Context context) {
   19.72 +        Resolve instance = context.get(resolveKey);
   19.73 +        if (instance == null)
   19.74 +            instance = new Resolve(context);
   19.75 +        return instance;
   19.76 +    }
   19.77 +
   19.78 +    // <editor-fold defaultstate="collapsed" desc="Verbose resolution diagnostics support">
   19.79      enum VerboseResolutionMode {
   19.80          SUCCESS("success"),
   19.81          FAILURE("failure"),
   19.82 @@ -119,56 +171,74 @@
   19.83          }
   19.84      }
   19.85  
   19.86 -    public static Resolve instance(Context context) {
   19.87 -        Resolve instance = context.get(resolveKey);
   19.88 -        if (instance == null)
   19.89 -            instance = new Resolve(context);
   19.90 -        return instance;
   19.91 +    void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site,
   19.92 +            List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
   19.93 +        boolean success = bestSoFar.kind < ERRONEOUS;
   19.94 +
   19.95 +        if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
   19.96 +            return;
   19.97 +        } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
   19.98 +            return;
   19.99 +        }
  19.100 +
  19.101 +        if (bestSoFar.name == names.init &&
  19.102 +                bestSoFar.owner == syms.objectType.tsym &&
  19.103 +                !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
  19.104 +            return; //skip diags for Object constructor resolution
  19.105 +        } else if (site == syms.predefClass.type &&
  19.106 +                !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
  19.107 +            return; //skip spurious diags for predef symbols (i.e. operators)
  19.108 +        } else if (currentResolutionContext.internalResolution &&
  19.109 +                !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
  19.110 +            return;
  19.111 +        }
  19.112 +
  19.113 +        int pos = 0;
  19.114 +        int mostSpecificPos = -1;
  19.115 +        ListBuffer<JCDiagnostic> subDiags = ListBuffer.lb();
  19.116 +        for (Candidate c : currentResolutionContext.candidates) {
  19.117 +            if (currentResolutionContext.step != c.step ||
  19.118 +                    (c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) ||
  19.119 +                    (!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) {
  19.120 +                continue;
  19.121 +            } else {
  19.122 +                subDiags.append(c.isApplicable() ?
  19.123 +                        getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) :
  19.124 +                        getVerboseInapplicableCandidateDiag(pos, c.sym, c.details));
  19.125 +                if (c.sym == bestSoFar)
  19.126 +                    mostSpecificPos = pos;
  19.127 +                pos++;
  19.128 +            }
  19.129 +        }
  19.130 +        String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
  19.131 +        JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name,
  19.132 +                site.tsym, mostSpecificPos, currentResolutionContext.step,
  19.133 +                methodArguments(argtypes), methodArguments(typeargtypes));
  19.134 +        JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList());
  19.135 +        log.report(d);
  19.136      }
  19.137  
  19.138 -    protected Resolve(Context context) {
  19.139 -        context.put(resolveKey, this);
  19.140 -        syms = Symtab.instance(context);
  19.141 +    JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) {
  19.142 +        JCDiagnostic subDiag = null;
  19.143 +        if (inst.getReturnType().tag == FORALL) {
  19.144 +            Type diagType = types.createMethodTypeWithReturn(inst.asMethodType(),
  19.145 +                                                            ((ForAll)inst.getReturnType()).qtype);
  19.146 +            subDiag = diags.fragment("partial.inst.sig", diagType);
  19.147 +        } else if (sym.type.tag == FORALL) {
  19.148 +            subDiag = diags.fragment("full.inst.sig", inst.asMethodType());
  19.149 +        }
  19.150  
  19.151 -        varNotFound = new
  19.152 -            SymbolNotFoundError(ABSENT_VAR);
  19.153 -        wrongMethod = new
  19.154 -            InapplicableSymbolError(syms.errSymbol);
  19.155 -        wrongMethods = new
  19.156 -            InapplicableSymbolsError(syms.errSymbol);
  19.157 -        methodNotFound = new
  19.158 -            SymbolNotFoundError(ABSENT_MTH);
  19.159 -        typeNotFound = new
  19.160 -            SymbolNotFoundError(ABSENT_TYP);
  19.161 +        String key = subDiag == null ?
  19.162 +                "applicable.method.found" :
  19.163 +                "applicable.method.found.1";
  19.164  
  19.165 -        names = Names.instance(context);
  19.166 -        log = Log.instance(context);
  19.167 -        chk = Check.instance(context);
  19.168 -        infer = Infer.instance(context);
  19.169 -        reader = ClassReader.instance(context);
  19.170 -        treeinfo = TreeInfo.instance(context);
  19.171 -        types = Types.instance(context);
  19.172 -        diags = JCDiagnostic.Factory.instance(context);
  19.173 -        Source source = Source.instance(context);
  19.174 -        boxingEnabled = source.allowBoxing();
  19.175 -        varargsEnabled = source.allowVarargs();
  19.176 -        Options options = Options.instance(context);
  19.177 -        debugResolve = options.isSet("debugresolve");
  19.178 -        verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
  19.179 -        Target target = Target.instance(context);
  19.180 -        allowMethodHandles = target.hasMethodHandles();
  19.181 -        polymorphicSignatureScope = new Scope(syms.noSymbol);
  19.182 -
  19.183 -        inapplicableMethodException = new InapplicableMethodException(diags);
  19.184 +        return diags.fragment(key, pos, sym, subDiag);
  19.185      }
  19.186  
  19.187 -    /** error symbols, which are returned when resolution fails
  19.188 -     */
  19.189 -    final SymbolNotFoundError varNotFound;
  19.190 -    final InapplicableSymbolError wrongMethod;
  19.191 -    final InapplicableSymbolsError wrongMethods;
  19.192 -    final SymbolNotFoundError methodNotFound;
  19.193 -    final SymbolNotFoundError typeNotFound;
  19.194 +    JCDiagnostic getVerboseInapplicableCandidateDiag(int pos, Symbol sym, JCDiagnostic subDiag) {
  19.195 +        return diags.fragment("not.applicable.method.found", pos, sym, subDiag);
  19.196 +    }
  19.197 +    // </editor-fold>
  19.198  
  19.199  /* ************************************************************************
  19.200   * Identifier resolution
  19.201 @@ -804,17 +874,18 @@
  19.202          try {
  19.203              Type mt = rawInstantiate(env, site, sym, argtypes, typeargtypes,
  19.204                                 allowBoxing, useVarargs, Warner.noWarnings);
  19.205 -            if (!operator) addVerboseApplicableCandidateDiag(sym ,mt);
  19.206 +            if (!operator)
  19.207 +                currentResolutionContext.addApplicableCandidate(sym, mt);
  19.208          } catch (InapplicableMethodException ex) {
  19.209 -            if (!operator) addVerboseInapplicableCandidateDiag(sym, ex.getDiagnostic());
  19.210 +            if (!operator)
  19.211 +                currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic());
  19.212              switch (bestSoFar.kind) {
  19.213              case ABSENT_MTH:
  19.214 -                return wrongMethod.setWrongSym(sym, ex.getDiagnostic());
  19.215 +                return wrongMethod;
  19.216              case WRONG_MTH:
  19.217                  if (operator) return bestSoFar;
  19.218 -                wrongMethods.addCandidate(currentStep, wrongMethod.sym, wrongMethod.explanation);
  19.219              case WRONG_MTHS:
  19.220 -                return wrongMethods.addCandidate(currentStep, sym, ex.getDiagnostic());
  19.221 +                return wrongMethods;
  19.222              default:
  19.223                  return bestSoFar;
  19.224              }
  19.225 @@ -823,40 +894,12 @@
  19.226              return (bestSoFar.kind == ABSENT_MTH)
  19.227                  ? new AccessError(env, site, sym)
  19.228                  : bestSoFar;
  19.229 -            }
  19.230 +        }
  19.231          return (bestSoFar.kind > AMBIGUOUS)
  19.232              ? sym
  19.233              : mostSpecific(sym, bestSoFar, env, site,
  19.234                             allowBoxing && operator, useVarargs);
  19.235      }
  19.236 -    //where
  19.237 -        void addVerboseApplicableCandidateDiag(Symbol sym, Type inst) {
  19.238 -            if (!verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE))
  19.239 -                return;
  19.240 -
  19.241 -            JCDiagnostic subDiag = null;
  19.242 -            if (inst.getReturnType().tag == FORALL) {
  19.243 -                Type diagType = types.createMethodTypeWithReturn(inst.asMethodType(),
  19.244 -                                                                ((ForAll)inst.getReturnType()).qtype);
  19.245 -                subDiag = diags.fragment("partial.inst.sig", diagType);
  19.246 -            } else if (sym.type.tag == FORALL) {
  19.247 -                subDiag = diags.fragment("full.inst.sig", inst.asMethodType());
  19.248 -            }
  19.249 -
  19.250 -            String key = subDiag == null ?
  19.251 -                    "applicable.method.found" :
  19.252 -                    "applicable.method.found.1";
  19.253 -
  19.254 -            verboseResolutionCandidateDiags.put(sym,
  19.255 -                    diags.fragment(key, verboseResolutionCandidateDiags.size(), sym, subDiag));
  19.256 -        }
  19.257 -
  19.258 -        void addVerboseInapplicableCandidateDiag(Symbol sym, JCDiagnostic subDiag) {
  19.259 -            if (!verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))
  19.260 -                return;
  19.261 -            verboseResolutionCandidateDiags.put(sym,
  19.262 -                    diags.fragment("not.applicable.method.found", verboseResolutionCandidateDiags.size(), sym, subDiag));
  19.263 -        }
  19.264  
  19.265      /* Return the most specific of the two methods for a call,
  19.266       *  given that both are accessible and applicable.
  19.267 @@ -1054,7 +1097,6 @@
  19.268                        boolean allowBoxing,
  19.269                        boolean useVarargs,
  19.270                        boolean operator) {
  19.271 -        verboseResolutionCandidateDiags.clear();
  19.272          Symbol bestSoFar = methodNotFound;
  19.273          bestSoFar = findMethod(env,
  19.274                            site,
  19.275 @@ -1127,37 +1169,6 @@
  19.276          }
  19.277          return bestSoFar;
  19.278      }
  19.279 -    //where
  19.280 -        void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
  19.281 -            boolean success = bestSoFar.kind < ERRONEOUS;
  19.282 -
  19.283 -            if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
  19.284 -                return;
  19.285 -            } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
  19.286 -                return;
  19.287 -            }
  19.288 -
  19.289 -            if (bestSoFar.name == names.init &&
  19.290 -                    bestSoFar.owner == syms.objectType.tsym &&
  19.291 -                    !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
  19.292 -                return; //skip diags for Object constructor resolution
  19.293 -            } else if (site == syms.predefClass.type && !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
  19.294 -                return; //skip spurious diags for predef symbols (i.e. operators)
  19.295 -            } else if (internalResolution && !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
  19.296 -                return;
  19.297 -            }
  19.298 -
  19.299 -            int pos = 0;
  19.300 -            for (Symbol s : verboseResolutionCandidateDiags.keySet()) {
  19.301 -                if (s == bestSoFar) break;
  19.302 -                pos++;
  19.303 -            }
  19.304 -            String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
  19.305 -            JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, site.tsym, pos, currentStep,
  19.306 -                    methodArguments(argtypes), methodArguments(typeargtypes));
  19.307 -            JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, List.from(verboseResolutionCandidateDiags.values().toArray(new JCDiagnostic[verboseResolutionCandidateDiags.size()])));
  19.308 -            log.report(d);
  19.309 -        }
  19.310  
  19.311      /** Find unqualified method matching given name, type and value arguments.
  19.312       *  @param env       The current environment.
  19.313 @@ -1591,32 +1602,33 @@
  19.314                           Name name,
  19.315                           List<Type> argtypes,
  19.316                           List<Type> typeargtypes) {
  19.317 -        Symbol sym = startResolution();
  19.318 -        List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.319 -        while (steps.nonEmpty() &&
  19.320 -               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.321 -               sym.kind >= ERRONEOUS) {
  19.322 -            currentStep = steps.head;
  19.323 -            sym = findFun(env, name, argtypes, typeargtypes,
  19.324 -                    steps.head.isBoxingRequired,
  19.325 -                    env.info.varArgs = steps.head.isVarargsRequired);
  19.326 -            methodResolutionCache.put(steps.head, sym);
  19.327 -            steps = steps.tail;
  19.328 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.329 +        try {
  19.330 +            currentResolutionContext = new MethodResolutionContext();
  19.331 +            Symbol sym = methodNotFound;
  19.332 +            List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.333 +            while (steps.nonEmpty() &&
  19.334 +                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.335 +                   sym.kind >= ERRONEOUS) {
  19.336 +                currentResolutionContext.step = steps.head;
  19.337 +                sym = findFun(env, name, argtypes, typeargtypes,
  19.338 +                        steps.head.isBoxingRequired,
  19.339 +                        env.info.varArgs = steps.head.isVarargsRequired);
  19.340 +                currentResolutionContext.resolutionCache.put(steps.head, sym);
  19.341 +                steps = steps.tail;
  19.342 +            }
  19.343 +            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
  19.344 +                MethodResolutionPhase errPhase =
  19.345 +                        currentResolutionContext.firstErroneousResolutionPhase();
  19.346 +                sym = access(currentResolutionContext.resolutionCache.get(errPhase),
  19.347 +                        pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
  19.348 +                env.info.varArgs = errPhase.isVarargsRequired;
  19.349 +            }
  19.350 +            return sym;
  19.351          }
  19.352 -        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
  19.353 -            MethodResolutionPhase errPhase =
  19.354 -                    firstErroneousResolutionPhase();
  19.355 -            sym = access(methodResolutionCache.get(errPhase),
  19.356 -                    pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
  19.357 -            env.info.varArgs = errPhase.isVarargsRequired;
  19.358 +        finally {
  19.359 +            currentResolutionContext = prevResolutionContext;
  19.360          }
  19.361 -        return sym;
  19.362 -    }
  19.363 -
  19.364 -    private Symbol startResolution() {
  19.365 -        wrongMethod.clear();
  19.366 -        wrongMethods.clear();
  19.367 -        return methodNotFound;
  19.368      }
  19.369  
  19.370      /** Resolve a qualified method identifier
  19.371 @@ -1636,40 +1648,53 @@
  19.372      Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
  19.373                                    Symbol location, Type site, Name name, List<Type> argtypes,
  19.374                                    List<Type> typeargtypes) {
  19.375 -        Symbol sym = startResolution();
  19.376 -        List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.377 -        while (steps.nonEmpty() &&
  19.378 -               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.379 -               sym.kind >= ERRONEOUS) {
  19.380 -            currentStep = steps.head;
  19.381 -            sym = findMethod(env, site, name, argtypes, typeargtypes,
  19.382 -                    steps.head.isBoxingRequired(),
  19.383 -                    env.info.varArgs = steps.head.isVarargsRequired(), false);
  19.384 -            methodResolutionCache.put(steps.head, sym);
  19.385 -            steps = steps.tail;
  19.386 -        }
  19.387 -        if (sym.kind >= AMBIGUOUS) {
  19.388 -            if (site.tsym.isPolymorphicSignatureGeneric()) {
  19.389 -                //polymorphic receiver - synthesize new method symbol
  19.390 +        return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
  19.391 +    }
  19.392 +    private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
  19.393 +                                  DiagnosticPosition pos, Env<AttrContext> env,
  19.394 +                                  Symbol location, Type site, Name name, List<Type> argtypes,
  19.395 +                                  List<Type> typeargtypes) {
  19.396 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.397 +        try {
  19.398 +            currentResolutionContext = resolveContext;
  19.399 +            Symbol sym = methodNotFound;
  19.400 +            List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.401 +            while (steps.nonEmpty() &&
  19.402 +                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.403 +                   sym.kind >= ERRONEOUS) {
  19.404 +                currentResolutionContext.step = steps.head;
  19.405 +                sym = findMethod(env, site, name, argtypes, typeargtypes,
  19.406 +                        steps.head.isBoxingRequired(),
  19.407 +                        env.info.varArgs = steps.head.isVarargsRequired(), false);
  19.408 +                currentResolutionContext.resolutionCache.put(steps.head, sym);
  19.409 +                steps = steps.tail;
  19.410 +            }
  19.411 +            if (sym.kind >= AMBIGUOUS) {
  19.412 +                if (site.tsym.isPolymorphicSignatureGeneric()) {
  19.413 +                    //polymorphic receiver - synthesize new method symbol
  19.414 +                    env.info.varArgs = false;
  19.415 +                    sym = findPolymorphicSignatureInstance(env,
  19.416 +                            site, name, null, argtypes);
  19.417 +                }
  19.418 +                else {
  19.419 +                    //if nothing is found return the 'first' error
  19.420 +                    MethodResolutionPhase errPhase =
  19.421 +                            currentResolutionContext.firstErroneousResolutionPhase();
  19.422 +                    sym = access(currentResolutionContext.resolutionCache.get(errPhase),
  19.423 +                            pos, location, site, name, true, argtypes, typeargtypes);
  19.424 +                    env.info.varArgs = errPhase.isVarargsRequired;
  19.425 +                }
  19.426 +            } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
  19.427 +                //non-instantiated polymorphic signature - synthesize new method symbol
  19.428                  env.info.varArgs = false;
  19.429                  sym = findPolymorphicSignatureInstance(env,
  19.430 -                        site, name, null, argtypes);
  19.431 +                        site, name, (MethodSymbol)sym, argtypes);
  19.432              }
  19.433 -            else {
  19.434 -                //if nothing is found return the 'first' error
  19.435 -                MethodResolutionPhase errPhase =
  19.436 -                        firstErroneousResolutionPhase();
  19.437 -                sym = access(methodResolutionCache.get(errPhase),
  19.438 -                        pos, location, site, name, true, argtypes, typeargtypes);
  19.439 -                env.info.varArgs = errPhase.isVarargsRequired;
  19.440 -            }
  19.441 -        } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
  19.442 -            //non-instantiated polymorphic signature - synthesize new method symbol
  19.443 -            env.info.varArgs = false;
  19.444 -            sym = findPolymorphicSignatureInstance(env,
  19.445 -                    site, name, (MethodSymbol)sym, argtypes);
  19.446 +            return sym;
  19.447          }
  19.448 -        return sym;
  19.449 +        finally {
  19.450 +            currentResolutionContext = prevResolutionContext;
  19.451 +        }
  19.452      }
  19.453  
  19.454      /** Find or create an implicit method of exactly the given type (after erasure).
  19.455 @@ -1726,19 +1751,14 @@
  19.456                                          Type site, Name name,
  19.457                                          List<Type> argtypes,
  19.458                                          List<Type> typeargtypes) {
  19.459 -        boolean prevInternal = internalResolution;
  19.460 -        try {
  19.461 -            internalResolution = true;
  19.462 -            Symbol sym = resolveQualifiedMethod(
  19.463 -                pos, env, site.tsym, site, name, argtypes, typeargtypes);
  19.464 -            if (sym.kind == MTH) return (MethodSymbol)sym;
  19.465 -            else throw new FatalError(
  19.466 -                     diags.fragment("fatal.err.cant.locate.meth",
  19.467 -                                    name));
  19.468 -        }
  19.469 -        finally {
  19.470 -            internalResolution = prevInternal;
  19.471 -        }
  19.472 +        MethodResolutionContext resolveContext = new MethodResolutionContext();
  19.473 +        resolveContext.internalResolution = true;
  19.474 +        Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym,
  19.475 +                site, name, argtypes, typeargtypes);
  19.476 +        if (sym.kind == MTH) return (MethodSymbol)sym;
  19.477 +        else throw new FatalError(
  19.478 +                 diags.fragment("fatal.err.cant.locate.meth",
  19.479 +                                name));
  19.480      }
  19.481  
  19.482      /** Resolve constructor.
  19.483 @@ -1755,25 +1775,40 @@
  19.484                                Type site,
  19.485                                List<Type> argtypes,
  19.486                                List<Type> typeargtypes) {
  19.487 -        Symbol sym = startResolution();
  19.488 -        List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.489 -        while (steps.nonEmpty() &&
  19.490 -               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.491 -               sym.kind >= ERRONEOUS) {
  19.492 -            currentStep = steps.head;
  19.493 -            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
  19.494 -                    steps.head.isBoxingRequired(),
  19.495 -                    env.info.varArgs = steps.head.isVarargsRequired());
  19.496 -            methodResolutionCache.put(steps.head, sym);
  19.497 -            steps = steps.tail;
  19.498 +        return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes);
  19.499 +    }
  19.500 +    private Symbol resolveConstructor(MethodResolutionContext resolveContext,
  19.501 +                              DiagnosticPosition pos,
  19.502 +                              Env<AttrContext> env,
  19.503 +                              Type site,
  19.504 +                              List<Type> argtypes,
  19.505 +                              List<Type> typeargtypes) {
  19.506 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.507 +        try {
  19.508 +            currentResolutionContext = resolveContext;
  19.509 +            Symbol sym = methodNotFound;
  19.510 +            List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.511 +            while (steps.nonEmpty() &&
  19.512 +                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.513 +                   sym.kind >= ERRONEOUS) {
  19.514 +                currentResolutionContext.step = steps.head;
  19.515 +                sym = findConstructor(pos, env, site, argtypes, typeargtypes,
  19.516 +                        steps.head.isBoxingRequired(),
  19.517 +                        env.info.varArgs = steps.head.isVarargsRequired());
  19.518 +                currentResolutionContext.resolutionCache.put(steps.head, sym);
  19.519 +                steps = steps.tail;
  19.520 +            }
  19.521 +            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
  19.522 +                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
  19.523 +                sym = access(currentResolutionContext.resolutionCache.get(errPhase),
  19.524 +                        pos, site, names.init, true, argtypes, typeargtypes);
  19.525 +                env.info.varArgs = errPhase.isVarargsRequired();
  19.526 +            }
  19.527 +            return sym;
  19.528          }
  19.529 -        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
  19.530 -            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
  19.531 -            sym = access(methodResolutionCache.get(errPhase),
  19.532 -                    pos, site, names.init, true, argtypes, typeargtypes);
  19.533 -            env.info.varArgs = errPhase.isVarargsRequired();
  19.534 +        finally {
  19.535 +            currentResolutionContext = prevResolutionContext;
  19.536          }
  19.537 -        return sym;
  19.538      }
  19.539  
  19.540      /** Resolve constructor using diamond inference.
  19.541 @@ -1791,38 +1826,82 @@
  19.542                                Type site,
  19.543                                List<Type> argtypes,
  19.544                                List<Type> typeargtypes) {
  19.545 -        Symbol sym = startResolution();
  19.546 -        List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.547 -        while (steps.nonEmpty() &&
  19.548 -               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.549 -               sym.kind >= ERRONEOUS) {
  19.550 -            currentStep = steps.head;
  19.551 -            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
  19.552 -                    steps.head.isBoxingRequired(),
  19.553 -                    env.info.varArgs = steps.head.isVarargsRequired());
  19.554 -            methodResolutionCache.put(steps.head, sym);
  19.555 -            steps = steps.tail;
  19.556 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.557 +        try {
  19.558 +            currentResolutionContext = new MethodResolutionContext();
  19.559 +            Symbol sym = methodNotFound;
  19.560 +            List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.561 +            while (steps.nonEmpty() &&
  19.562 +                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.563 +                   sym.kind >= ERRONEOUS) {
  19.564 +                currentResolutionContext.step = steps.head;
  19.565 +                sym = findDiamond(env, site, argtypes, typeargtypes,
  19.566 +                        steps.head.isBoxingRequired(),
  19.567 +                        env.info.varArgs = steps.head.isVarargsRequired());
  19.568 +                currentResolutionContext.resolutionCache.put(steps.head, sym);
  19.569 +                steps = steps.tail;
  19.570 +            }
  19.571 +            if (sym.kind >= AMBIGUOUS) {
  19.572 +                final JCDiagnostic details = sym.kind == WRONG_MTH ?
  19.573 +                                currentResolutionContext.candidates.head.details :
  19.574 +                                null;
  19.575 +                Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
  19.576 +                    @Override
  19.577 +                    JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
  19.578 +                            Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
  19.579 +                        String key = details == null ?
  19.580 +                            "cant.apply.diamond" :
  19.581 +                            "cant.apply.diamond.1";
  19.582 +                        return diags.create(dkind, log.currentSource(), pos, key,
  19.583 +                                diags.fragment("diamond", site.tsym), details);
  19.584 +                    }
  19.585 +                };
  19.586 +                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
  19.587 +                sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
  19.588 +                env.info.varArgs = errPhase.isVarargsRequired();
  19.589 +            }
  19.590 +            return sym;
  19.591          }
  19.592 -        if (sym.kind >= AMBIGUOUS) {
  19.593 -            final JCDiagnostic details = sym.kind == WRONG_MTH ?
  19.594 -                ((InapplicableSymbolError)sym).explanation :
  19.595 -                null;
  19.596 -            Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
  19.597 -                @Override
  19.598 -                JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
  19.599 -                        Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
  19.600 -                    String key = details == null ?
  19.601 -                        "cant.apply.diamond" :
  19.602 -                        "cant.apply.diamond.1";
  19.603 -                    return diags.create(dkind, log.currentSource(), pos, key,
  19.604 -                            diags.fragment("diamond", site.tsym), details);
  19.605 -                }
  19.606 -            };
  19.607 -            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
  19.608 -            sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
  19.609 -            env.info.varArgs = errPhase.isVarargsRequired();
  19.610 +        finally {
  19.611 +            currentResolutionContext = prevResolutionContext;
  19.612          }
  19.613 -        return sym;
  19.614 +    }
  19.615 +
  19.616 +    /** This method scans all the constructor symbol in a given class scope -
  19.617 +     *  assuming that the original scope contains a constructor of the kind:
  19.618 +     *  Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
  19.619 +     *  a method check is executed against the modified constructor type:
  19.620 +     *  <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
  19.621 +     *  inference. The inferred return type of the synthetic constructor IS
  19.622 +     *  the inferred type for the diamond operator.
  19.623 +     */
  19.624 +    private Symbol findDiamond(Env<AttrContext> env,
  19.625 +                              Type site,
  19.626 +                              List<Type> argtypes,
  19.627 +                              List<Type> typeargtypes,
  19.628 +                              boolean allowBoxing,
  19.629 +                              boolean useVarargs) {
  19.630 +        Symbol bestSoFar = methodNotFound;
  19.631 +        for (Scope.Entry e = site.tsym.members().lookup(names.init);
  19.632 +             e.scope != null;
  19.633 +             e = e.next()) {
  19.634 +            //- System.out.println(" e " + e.sym);
  19.635 +            if (e.sym.kind == MTH &&
  19.636 +                (e.sym.flags_field & SYNTHETIC) == 0) {
  19.637 +                    List<Type> oldParams = e.sym.type.tag == FORALL ?
  19.638 +                            ((ForAll)e.sym.type).tvars :
  19.639 +                            List.<Type>nil();
  19.640 +                    Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams),
  19.641 +                            types.createMethodTypeWithReturn(e.sym.type.asMethodType(), site));
  19.642 +                    bestSoFar = selectBest(env, site, argtypes, typeargtypes,
  19.643 +                            new MethodSymbol(e.sym.flags(), names.init, constrType, site.tsym),
  19.644 +                            bestSoFar,
  19.645 +                            allowBoxing,
  19.646 +                            useVarargs,
  19.647 +                            false);
  19.648 +            }
  19.649 +        }
  19.650 +        return bestSoFar;
  19.651      }
  19.652  
  19.653      /** Resolve constructor.
  19.654 @@ -1841,10 +1920,25 @@
  19.655                                List<Type> typeargtypes,
  19.656                                boolean allowBoxing,
  19.657                                boolean useVarargs) {
  19.658 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.659 +        try {
  19.660 +            currentResolutionContext = new MethodResolutionContext();
  19.661 +            return findConstructor(pos, env, site, argtypes, typeargtypes, allowBoxing, useVarargs);
  19.662 +        }
  19.663 +        finally {
  19.664 +            currentResolutionContext = prevResolutionContext;
  19.665 +        }
  19.666 +    }
  19.667 +
  19.668 +    Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
  19.669 +                              Type site, List<Type> argtypes,
  19.670 +                              List<Type> typeargtypes,
  19.671 +                              boolean allowBoxing,
  19.672 +                              boolean useVarargs) {
  19.673          Symbol sym = findMethod(env, site,
  19.674 -                                names.init, argtypes,
  19.675 -                                typeargtypes, allowBoxing,
  19.676 -                                useVarargs, false);
  19.677 +                                    names.init, argtypes,
  19.678 +                                    typeargtypes, allowBoxing,
  19.679 +                                    useVarargs, false);
  19.680          chk.checkDeprecated(pos, env.info.scope.owner, sym);
  19.681          return sym;
  19.682      }
  19.683 @@ -1860,8 +1954,9 @@
  19.684                                          Type site,
  19.685                                          List<Type> argtypes,
  19.686                                          List<Type> typeargtypes) {
  19.687 -        Symbol sym = resolveConstructor(
  19.688 -            pos, env, site, argtypes, typeargtypes);
  19.689 +        MethodResolutionContext resolveContext = new MethodResolutionContext();
  19.690 +        resolveContext.internalResolution = true;
  19.691 +        Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
  19.692          if (sym.kind == MTH) return (MethodSymbol)sym;
  19.693          else throw new FatalError(
  19.694                   diags.fragment("fatal.err.cant.locate.ctor", site));
  19.695 @@ -1875,15 +1970,21 @@
  19.696       */
  19.697      Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
  19.698                             Env<AttrContext> env, List<Type> argtypes) {
  19.699 -        startResolution();
  19.700 -        Name name = treeinfo.operatorName(optag);
  19.701 -        Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
  19.702 -                                null, false, false, true);
  19.703 -        if (boxingEnabled && sym.kind >= WRONG_MTHS)
  19.704 -            sym = findMethod(env, syms.predefClass.type, name, argtypes,
  19.705 -                             null, true, false, true);
  19.706 -        return access(sym, pos, env.enclClass.sym.type, name,
  19.707 -                      false, argtypes, null);
  19.708 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
  19.709 +        try {
  19.710 +            currentResolutionContext = new MethodResolutionContext();
  19.711 +            Name name = treeinfo.operatorName(optag);
  19.712 +            Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
  19.713 +                                    null, false, false, true);
  19.714 +            if (boxingEnabled && sym.kind >= WRONG_MTHS)
  19.715 +                sym = findMethod(env, syms.predefClass.type, name, argtypes,
  19.716 +                                 null, true, false, true);
  19.717 +            return access(sym, pos, env.enclClass.sym.type, name,
  19.718 +                          false, argtypes, null);
  19.719 +        }
  19.720 +        finally {
  19.721 +            currentResolutionContext = prevResolutionContext;
  19.722 +        }
  19.723      }
  19.724  
  19.725      /** Resolve operator.
  19.726 @@ -1996,9 +2097,10 @@
  19.727   *  ResolveError classes, indicating error situations when accessing symbols
  19.728   ****************************************************************************/
  19.729  
  19.730 -    public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) {
  19.731 -        AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym);
  19.732 -        logResolveError(error, tree.pos(), type.getEnclosingType().tsym, type.getEnclosingType(), null, null, null);
  19.733 +    //used by TransTypes when checking target type of synthetic cast
  19.734 +    public void logAccessErrorInternal(Env<AttrContext> env, JCTree tree, Type type) {
  19.735 +        AccessError error = new AccessError(env, env.enclClass.type, type.tsym);
  19.736 +        logResolveError(error, tree.pos(), env.enclClass.sym, env.enclClass.type, null, null, null);
  19.737      }
  19.738      //where
  19.739      private void logResolveError(ResolveError error,
  19.740 @@ -2227,34 +2329,24 @@
  19.741       * (either a method, a constructor or an operand) is not applicable
  19.742       * given an actual arguments/type argument list.
  19.743       */
  19.744 -    class InapplicableSymbolError extends InvalidSymbolError {
  19.745 +    class InapplicableSymbolError extends ResolveError {
  19.746  
  19.747 -        /** An auxiliary explanation set in case of instantiation errors. */
  19.748 -        JCDiagnostic explanation;
  19.749 -
  19.750 -        InapplicableSymbolError(Symbol sym) {
  19.751 -            super(WRONG_MTH, sym, "inapplicable symbol error");
  19.752 +        InapplicableSymbolError() {
  19.753 +            super(WRONG_MTH, "inapplicable symbol error");
  19.754          }
  19.755  
  19.756 -        /** Update sym and explanation and return this.
  19.757 -         */
  19.758 -        InapplicableSymbolError setWrongSym(Symbol sym, JCDiagnostic explanation) {
  19.759 -            this.sym = sym;
  19.760 -            if (this.sym == sym && explanation != null)
  19.761 -                this.explanation = explanation; //update the details
  19.762 -            return this;
  19.763 -        }
  19.764 -
  19.765 -        /** Update sym and return this.
  19.766 -         */
  19.767 -        InapplicableSymbolError setWrongSym(Symbol sym) {
  19.768 -            this.sym = sym;
  19.769 -            return this;
  19.770 +        protected InapplicableSymbolError(int kind, String debugName) {
  19.771 +            super(kind, debugName);
  19.772          }
  19.773  
  19.774          @Override
  19.775          public String toString() {
  19.776 -            return super.toString() + " explanation=" + explanation;
  19.777 +            return super.toString();
  19.778 +        }
  19.779 +
  19.780 +        @Override
  19.781 +        public boolean exists() {
  19.782 +            return true;
  19.783          }
  19.784  
  19.785          @Override
  19.786 @@ -2279,27 +2371,40 @@
  19.787                          key, name, first, second);
  19.788              }
  19.789              else {
  19.790 -                Symbol ws = sym.asMemberOf(site, types);
  19.791 +                Candidate c = errCandidate();
  19.792 +                Symbol ws = c.sym.asMemberOf(site, types);
  19.793                  return diags.create(dkind, log.currentSource(), pos,
  19.794 -                          "cant.apply.symbol" + (explanation != null ? ".1" : ""),
  19.795 +                          "cant.apply.symbol" + (c.details != null ? ".1" : ""),
  19.796                            kindName(ws),
  19.797                            ws.name == names.init ? ws.owner.name : ws.name,
  19.798                            methodArguments(ws.type.getParameterTypes()),
  19.799                            methodArguments(argtypes),
  19.800                            kindName(ws.owner),
  19.801                            ws.owner.type,
  19.802 -                          explanation);
  19.803 +                          c.details);
  19.804              }
  19.805          }
  19.806  
  19.807 -        void clear() {
  19.808 -            explanation = null;
  19.809 -        }
  19.810 -
  19.811          @Override
  19.812          public Symbol access(Name name, TypeSymbol location) {
  19.813              return types.createErrorType(name, location, syms.errSymbol.type).tsym;
  19.814          }
  19.815 +
  19.816 +        protected boolean shouldReport(Candidate c) {
  19.817 +            return !c.isApplicable() &&
  19.818 +                    (((c.sym.flags() & VARARGS) != 0 && c.step == VARARITY) ||
  19.819 +                      (c.sym.flags() & VARARGS) == 0 && c.step == (boxingEnabled ? BOX : BASIC));
  19.820 +        }
  19.821 +
  19.822 +        private Candidate errCandidate() {
  19.823 +            for (Candidate c : currentResolutionContext.candidates) {
  19.824 +                if (shouldReport(c)) {
  19.825 +                    return c;
  19.826 +                }
  19.827 +            }
  19.828 +            Assert.error();
  19.829 +            return null;
  19.830 +        }
  19.831      }
  19.832  
  19.833      /**
  19.834 @@ -2307,11 +2412,9 @@
  19.835       * (either methods, constructors or operands) is not applicable
  19.836       * given an actual arguments/type argument list.
  19.837       */
  19.838 -    class InapplicableSymbolsError extends ResolveError {
  19.839 +    class InapplicableSymbolsError extends InapplicableSymbolError {
  19.840  
  19.841 -        private List<Candidate> candidates = List.nil();
  19.842 -
  19.843 -        InapplicableSymbolsError(Symbol sym) {
  19.844 +        InapplicableSymbolsError() {
  19.845              super(WRONG_MTHS, "inapplicable symbols");
  19.846          }
  19.847  
  19.848 @@ -2323,7 +2426,7 @@
  19.849                  Name name,
  19.850                  List<Type> argtypes,
  19.851                  List<Type> typeargtypes) {
  19.852 -            if (candidates.nonEmpty()) {
  19.853 +            if (currentResolutionContext.candidates.nonEmpty()) {
  19.854                  JCDiagnostic err = diags.create(dkind,
  19.855                          log.currentSource(),
  19.856                          pos,
  19.857 @@ -2341,68 +2444,24 @@
  19.858          //where
  19.859          List<JCDiagnostic> candidateDetails(Type site) {
  19.860              List<JCDiagnostic> details = List.nil();
  19.861 -            for (Candidate c : candidates)
  19.862 -                details = details.prepend(c.getDiagnostic(site));
  19.863 +            for (Candidate c : currentResolutionContext.candidates) {
  19.864 +                if (!shouldReport(c)) continue;
  19.865 +                JCDiagnostic detailDiag = diags.fragment("inapplicable.method",
  19.866 +                        Kinds.kindName(c.sym),
  19.867 +                        c.sym.location(site, types),
  19.868 +                        c.sym.asMemberOf(site, types),
  19.869 +                        c.details);
  19.870 +                details = details.prepend(detailDiag);
  19.871 +            }
  19.872              return details.reverse();
  19.873          }
  19.874  
  19.875 -        Symbol addCandidate(MethodResolutionPhase currentStep, Symbol sym, JCDiagnostic details) {
  19.876 -            Candidate c = new Candidate(currentStep, sym, details);
  19.877 -            if (c.isValid() && !candidates.contains(c))
  19.878 -                candidates = candidates.append(c);
  19.879 -            return this;
  19.880 -        }
  19.881 -
  19.882 -        void clear() {
  19.883 -            candidates = List.nil();
  19.884 -        }
  19.885 -
  19.886          private Name getName() {
  19.887 -            Symbol sym = candidates.head.sym;
  19.888 +            Symbol sym = currentResolutionContext.candidates.head.sym;
  19.889              return sym.name == names.init ?
  19.890                  sym.owner.name :
  19.891                  sym.name;
  19.892          }
  19.893 -
  19.894 -        private class Candidate {
  19.895 -
  19.896 -            final MethodResolutionPhase step;
  19.897 -            final Symbol sym;
  19.898 -            final JCDiagnostic details;
  19.899 -
  19.900 -            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details) {
  19.901 -                this.step = step;
  19.902 -                this.sym = sym;
  19.903 -                this.details = details;
  19.904 -            }
  19.905 -
  19.906 -            JCDiagnostic getDiagnostic(Type site) {
  19.907 -                return diags.fragment("inapplicable.method",
  19.908 -                        Kinds.kindName(sym),
  19.909 -                        sym.location(site, types),
  19.910 -                        sym.asMemberOf(site, types),
  19.911 -                        details);
  19.912 -            }
  19.913 -
  19.914 -            @Override
  19.915 -            public boolean equals(Object o) {
  19.916 -                if (o instanceof Candidate) {
  19.917 -                    Symbol s1 = this.sym;
  19.918 -                    Symbol s2 = ((Candidate)o).sym;
  19.919 -                    if  ((s1 != s2 &&
  19.920 -                        (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
  19.921 -                        (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
  19.922 -                        ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
  19.923 -                        return true;
  19.924 -                }
  19.925 -                return false;
  19.926 -            }
  19.927 -
  19.928 -            boolean isValid() {
  19.929 -                return  (((sym.flags() & VARARGS) != 0 && step == VARARITY) ||
  19.930 -                          (sym.flags() & VARARGS) == 0 && step == (boxingEnabled ? BOX : BASIC));
  19.931 -            }
  19.932 -        }
  19.933      }
  19.934  
  19.935      /**
  19.936 @@ -2563,29 +2622,91 @@
  19.937          }
  19.938      }
  19.939  
  19.940 -    private Map<MethodResolutionPhase, Symbol> methodResolutionCache =
  19.941 -        new HashMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.values().length);
  19.942 -
  19.943 -    private Map<Symbol, JCDiagnostic> verboseResolutionCandidateDiags =
  19.944 -        new LinkedHashMap<Symbol, JCDiagnostic>();
  19.945 -
  19.946      final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
  19.947  
  19.948 -    private MethodResolutionPhase currentStep = null;
  19.949 +    /**
  19.950 +     * A resolution context is used to keep track of intermediate results of
  19.951 +     * overload resolution, such as list of method that are not applicable
  19.952 +     * (used to generate more precise diagnostics) and so on. Resolution contexts
  19.953 +     * can be nested - this means that when each overload resolution routine should
  19.954 +     * work within the resolution context it created.
  19.955 +     */
  19.956 +    class MethodResolutionContext {
  19.957  
  19.958 -    private boolean internalResolution = false;
  19.959 +        private List<Candidate> candidates = List.nil();
  19.960  
  19.961 -    private MethodResolutionPhase firstErroneousResolutionPhase() {
  19.962 -        MethodResolutionPhase bestSoFar = BASIC;
  19.963 -        Symbol sym = methodNotFound;
  19.964 -        List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.965 -        while (steps.nonEmpty() &&
  19.966 -               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.967 -               sym.kind >= WRONG_MTHS) {
  19.968 -            sym = methodResolutionCache.get(steps.head);
  19.969 -            bestSoFar = steps.head;
  19.970 -            steps = steps.tail;
  19.971 +        private Map<MethodResolutionPhase, Symbol> resolutionCache =
  19.972 +            new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class);
  19.973 +
  19.974 +        private MethodResolutionPhase step = null;
  19.975 +
  19.976 +        private boolean internalResolution = false;
  19.977 +
  19.978 +        private MethodResolutionPhase firstErroneousResolutionPhase() {
  19.979 +            MethodResolutionPhase bestSoFar = BASIC;
  19.980 +            Symbol sym = methodNotFound;
  19.981 +            List<MethodResolutionPhase> steps = methodResolutionSteps;
  19.982 +            while (steps.nonEmpty() &&
  19.983 +                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
  19.984 +                   sym.kind >= WRONG_MTHS) {
  19.985 +                sym = resolutionCache.get(steps.head);
  19.986 +                bestSoFar = steps.head;
  19.987 +                steps = steps.tail;
  19.988 +            }
  19.989 +            return bestSoFar;
  19.990          }
  19.991 -        return bestSoFar;
  19.992 +
  19.993 +        void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
  19.994 +            Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
  19.995 +            if (!candidates.contains(c))
  19.996 +                candidates = candidates.append(c);
  19.997 +        }
  19.998 +
  19.999 +        void addApplicableCandidate(Symbol sym, Type mtype) {
 19.1000 +            Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
 19.1001 +            candidates = candidates.append(c);
 19.1002 +        }
 19.1003 +
 19.1004 +        /**
 19.1005 +         * This class represents an overload resolution candidate. There are two
 19.1006 +         * kinds of candidates: applicable methods and inapplicable methods;
 19.1007 +         * applicable methods have a pointer to the instantiated method type,
 19.1008 +         * while inapplicable candidates contain further details about the
 19.1009 +         * reason why the method has been considered inapplicable.
 19.1010 +         */
 19.1011 +        class Candidate {
 19.1012 +
 19.1013 +            final MethodResolutionPhase step;
 19.1014 +            final Symbol sym;
 19.1015 +            final JCDiagnostic details;
 19.1016 +            final Type mtype;
 19.1017 +
 19.1018 +            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details, Type mtype) {
 19.1019 +                this.step = step;
 19.1020 +                this.sym = sym;
 19.1021 +                this.details = details;
 19.1022 +                this.mtype = mtype;
 19.1023 +            }
 19.1024 +
 19.1025 +            @Override
 19.1026 +            public boolean equals(Object o) {
 19.1027 +                if (o instanceof Candidate) {
 19.1028 +                    Symbol s1 = this.sym;
 19.1029 +                    Symbol s2 = ((Candidate)o).sym;
 19.1030 +                    if  ((s1 != s2 &&
 19.1031 +                        (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
 19.1032 +                        (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
 19.1033 +                        ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
 19.1034 +                        return true;
 19.1035 +                }
 19.1036 +                return false;
 19.1037 +            }
 19.1038 +
 19.1039 +            boolean isApplicable() {
 19.1040 +                return mtype != null;
 19.1041 +            }
 19.1042 +        }
 19.1043      }
 19.1044 +
 19.1045 +    MethodResolutionContext currentResolutionContext = null;
 19.1046  }
    20.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Thu Mar 08 20:35:26 2012 -0800
    20.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Fri Mar 09 11:59:26 2012 -0800
    20.3 @@ -107,7 +107,7 @@
    20.4          make.at(tree.pos);
    20.5          if (!types.isSameType(tree.type, target)) {
    20.6              if (!resolve.isAccessible(env, target.tsym))
    20.7 -                resolve.logAccessError(env, tree, target);
    20.8 +                resolve.logAccessErrorInternal(env, tree, target);
    20.9              tree = make.TypeCast(make.Type(target), tree).setType(target);
   20.10          }
   20.11          make.pos = oldpos;
    21.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Thu Mar 08 20:35:26 2012 -0800
    21.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Fri Mar 09 11:59:26 2012 -0800
    21.3 @@ -1,5 +1,5 @@
    21.4  /*
    21.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
    21.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    21.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    21.8   *
    21.9   * This code is free software; you can redistribute it and/or modify it
   21.10 @@ -102,6 +102,16 @@
   21.11          setOpname(MOD, "%", names);
   21.12      }
   21.13  
   21.14 +    public static List<JCExpression> args(JCTree t) {
   21.15 +        switch (t.getTag()) {
   21.16 +            case APPLY:
   21.17 +                return ((JCMethodInvocation)t).args;
   21.18 +            case NEWCLASS:
   21.19 +                return ((JCNewClass)t).args;
   21.20 +            default:
   21.21 +                return null;
   21.22 +        }
   21.23 +    }
   21.24  
   21.25      /** Return name of operator with given tree tag.
   21.26       */
    22.1 --- a/test/Makefile	Thu Mar 08 20:35:26 2012 -0800
    22.2 +++ b/test/Makefile	Fri Mar 09 11:59:26 2012 -0800
    22.3 @@ -36,6 +36,14 @@
    22.4      ARCH=i586
    22.5    endif
    22.6  endif
    22.7 +ifeq ($(OSNAME), Darwin)
    22.8 +  PLATFORM = bsd
    22.9 +  JT_PLATFORM = linux
   22.10 +  ARCH = $(shell uname -m)
   22.11 +  ifeq ($(ARCH), i386)
   22.12 +    ARCH=i586
   22.13 +  endif
   22.14 +endif
   22.15  ifeq ($(OSNAME), Windows_NT)
   22.16    # MKS
   22.17    PLATFORM=windows
   22.18 @@ -251,6 +259,7 @@
   22.19  # JTREG_REFERENCE
   22.20  #	(Optional) reference results (e.g. work, report or summary.txt)
   22.21  #
   22.22 +jtreg_tests: jtreg-tests
   22.23  jtreg-tests: check-jtreg FRC
   22.24  	@rm -f -r $(JTREG_OUTPUT_DIR)/JTwork $(JTREG_OUTPUT_DIR)/JTreport \
   22.25  	    $(JTREG_OUTPUT_DIR)/diff.html $(JTREG_OUTPUT_DIR)/status.txt
    23.1 --- a/test/jprt.config	Thu Mar 08 20:35:26 2012 -0800
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,159 +0,0 @@
    23.4 -#!echo "This is not a shell script"
    23.5 -#############################################################################
    23.6 -# Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
    23.7 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.8 -#
    23.9 -# This code is free software; you can redistribute it and/or modify it
   23.10 -# under the terms of the GNU General Public License version 2 only, as
   23.11 -# published by the Free Software Foundation.
   23.12 -#
   23.13 -# This code is distributed in the hope that it will be useful, but WITHOUT
   23.14 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.15 -# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.16 -# version 2 for more details (a copy is included in the LICENSE file that
   23.17 -# accompanied this code).
   23.18 -#
   23.19 -# You should have received a copy of the GNU General Public License version
   23.20 -# 2 along with this work; if not, write to the Free Software Foundation,
   23.21 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.22 -#
   23.23 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.24 -# or visit www.oracle.com if you need additional information or have any
   23.25 -# questions.
   23.26 -#############################################################################
   23.27 -#
   23.28 -# JPRT shell configuration for testing.
   23.29 -#
   23.30 -# Input environment variables:
   23.31 -#    Windows Only:
   23.32 -#      PATH
   23.33 -#      ROOTDIR
   23.34 -#
   23.35 -# Output variable settings:
   23.36 -#    make    Full path to GNU make
   23.37 -#
   23.38 -# Output environment variables:
   23.39 -#    PATH
   23.40 -#
   23.41 -#############################################################################
   23.42 -
   23.43 -#############################################################################
   23.44 -# Error
   23.45 -error() # message
   23.46 -{
   23.47 -  echo "ERROR: $1"
   23.48 -  exit 6
   23.49 -}
   23.50 -# Directory must exist
   23.51 -dirMustExist() # dir name
   23.52 -{
   23.53 -  if [ ! -d "$1" ] ; then
   23.54 -    error "Directory for $2 does not exist: $1"
   23.55 -  fi
   23.56 -}
   23.57 -# File must exist
   23.58 -fileMustExist() # dir name
   23.59 -{
   23.60 -  if [ ! -f "$1" ] ; then
   23.61 -    error "File for $2 does not exist: $1"
   23.62 -  fi
   23.63 -}
   23.64 -#############################################################################
   23.65 -
   23.66 -# Should be set by JPRT as the 3 basic inputs
   23.67 -slashjava="${ALT_SLASH_JAVA}"
   23.68 -if [ "${slashjava}" = "" ] ; then
   23.69 -  slashjava=/java
   23.70 -fi
   23.71 -
   23.72 -# Check input
   23.73 -dirMustExist "${slashjava}"  ALT_SLASH_JAVA
   23.74 -
   23.75 -# Uses 'uname -s', but only expect SunOS or Linux, assume Windows otherwise.
   23.76 -osname=`uname -s`
   23.77 -if [ "${osname}" = SunOS ] ; then
   23.78 -   
   23.79 -    # SOLARIS: Sparc or X86
   23.80 -    osarch=`uname -p`
   23.81 -    if [ "${osarch}" = sparc ] ; then
   23.82 -	solaris_arch=sparc
   23.83 -    else
   23.84 -	solaris_arch=i386
   23.85 -    fi
   23.86 -
   23.87 -    # Add basic solaris system paths
   23.88 -    path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin
   23.89 -
   23.90 -    # Find GNU make
   23.91 -    make=/usr/sfw/bin/gmake
   23.92 -    if [ ! -f ${make} ] ; then
   23.93 -	make=/opt/sfw/bin/gmake
   23.94 -	if [ ! -f ${make} ] ; then
   23.95 -	    make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
   23.96 -        fi 
   23.97 -    fi
   23.98 -    fileMustExist "${make}" make
   23.99 -
  23.100 -    # File creation mask
  23.101 -    umask 002
  23.102 -
  23.103 -elif [ "${osname}" = Linux ] ; then
  23.104 -   
  23.105 -    # Add basic paths
  23.106 -    path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
  23.107 -
  23.108 -    # Find GNU make
  23.109 -    make=/usr/bin/make
  23.110 -    fileMustExist "${make}" make
  23.111 -
  23.112 -    umask 002
  23.113 -
  23.114 -else
  23.115 -
  23.116 -    # Windows: Differs on CYGWIN vs. MKS.
  23.117 -   
  23.118 -    # We need to determine if we are running a CYGWIN shell or an MKS shell
  23.119 -    #    (if uname isn't available, then it will be unix_toolset=unknown)
  23.120 -    unix_toolset=unknown
  23.121 -    if [ "`uname -a | fgrep Cygwin`" = "" -a -d "${ROOTDIR}" ] ; then
  23.122 -        # We kind of assume ROOTDIR is where MKS is and it's ok
  23.123 -        unix_toolset=MKS
  23.124 -        mkshome=`dosname -s "${ROOTDIR}"`
  23.125 -        # Most unix utilities are in the mksnt directory of ROOTDIR
  23.126 -        unixcommand_path="${mkshome}/mksnt"
  23.127 -        path4sdk="${unixcommand_path}"
  23.128 -	devtools_path="${slashjava}/devtools/win32/bin"
  23.129 -	path4sdk="${devtools_path};${path4sdk}"
  23.130 -        # Find GNU make
  23.131 -        make="${devtools_path}/gnumake.exe"
  23.132 -        fileMustExist "${make}" make
  23.133 -    elif [ "`uname -a | fgrep Cygwin`" != "" -a -f /bin/cygpath ] ; then
  23.134 -        # For CYGWIN, uname will have "Cygwin" in it, and /bin/cygpath should exist
  23.135 -        unix_toolset=CYGWIN
  23.136 -        # Most unix utilities are in the /usr/bin
  23.137 -        unixcommand_path="/usr/bin"
  23.138 -        path4sdk="${unixcommand_path}"
  23.139 -        # Find GNU make
  23.140 -        make="${unixcommand_path}/make.exe"
  23.141 -        fileMustExist "${make}" make
  23.142 -    else
  23.143 -      echo "WARNING: Cannot figure out if this is MKS or CYGWIN"
  23.144 -    fi
  23.145 -
  23.146 -    
  23.147 -    # For windows, it's hard to know where the system is, so we just add this
  23.148 -    #    to PATH.
  23.149 -    slash_path="`echo ${path4sdk} | sed -e 's@\\\\@/@g' -e 's@//@/@g' -e 's@/$@@' -e 's@/;@;@g'`"
  23.150 -    path4sdk="${slash_path};${PATH}"
  23.151 -    
  23.152 -    # Convert path4sdk to cygwin style
  23.153 -    if [ "${unix_toolset}" = CYGWIN ] ; then
  23.154 -	path4sdk="`/usr/bin/cygpath -p ${path4sdk}`"
  23.155 -    fi
  23.156 -
  23.157 -fi
  23.158 -
  23.159 -# Export PATH setting
  23.160 -PATH="${path4sdk}"
  23.161 -export PATH
  23.162 -
    24.1 --- a/test/tools/javac/4846262/Test.sh	Thu Mar 08 20:35:26 2012 -0800
    24.2 +++ b/test/tools/javac/4846262/Test.sh	Fri Mar 09 11:59:26 2012 -0800
    24.3 @@ -44,7 +44,7 @@
    24.4  # set platform-dependent variables
    24.5  OS=`uname -s`
    24.6  case "$OS" in
    24.7 -  SunOS | Linux )
    24.8 +  SunOS | Linux | Darwin )
    24.9      FS="/"
   24.10      ;;
   24.11    CYGWIN* )
    25.1 --- a/test/tools/javac/6302184/T6302184.sh	Thu Mar 08 20:35:26 2012 -0800
    25.2 +++ b/test/tools/javac/6302184/T6302184.sh	Fri Mar 09 11:59:26 2012 -0800
    25.3 @@ -41,7 +41,7 @@
    25.4  # set platform-dependent variables
    25.5  OS=`uname -s`
    25.6  case "$OS" in
    25.7 -  SunOS | Linux )
    25.8 +  SunOS | Linux | Darwin )
    25.9      FS="/"
   25.10      ;;
   25.11    CYGWIN* )
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/tools/javac/7132880/T7132880.java	Fri Mar 09 11:59:26 2012 -0800
    26.3 @@ -0,0 +1,60 @@
    26.4 +/*
    26.5 + * @test /nodynamiccopyright/
    26.6 + * @bug 7132880
    26.7 + * @summary Resolve should support nested resolution contexts
    26.8 + * @compile/fail/ref=T7132880.out -XDrawDiagnostics T7132880.java
    26.9 + */
   26.10 +class Outer {
   26.11 +    void m1(String s) { }
   26.12 +    void m2(int i1, int i2) { }
   26.13 +
   26.14 +    class Inner {
   26.15 +        void test() {
   26.16 +           //ok - no method named 'm' in Inner - hence, class to search is Outer
   26.17 +           m1("");
   26.18 +        }
   26.19 +    }
   26.20 +
   26.21 +    class Inner1 {
   26.22 +        void m1(Integer i) { }
   26.23 +
   26.24 +        void test() {
   26.25 +           //error - Inner1 defines an incompatible method - hence, class to search is Inner1
   26.26 +           m1("");
   26.27 +        }
   26.28 +    }
   26.29 +
   26.30 +    class Inner2 {
   26.31 +        private void m1(Integer i) { }
   26.32 +        private void m1(Double d) { }
   26.33 +
   26.34 +        void test() {
   26.35 +           //error - Inner2 defines multiple incompatible methods - hence, class to search is Inner2
   26.36 +           m1("");
   26.37 +        }
   26.38 +    }
   26.39 +
   26.40 +    class Inner3 {
   26.41 +        private void m2(Object o, int i) { }
   26.42 +        private void m2(int i, Object o) { }
   26.43 +
   26.44 +        void test() {
   26.45 +           //error - Inner3 defines multiple ambiguous methods - hence, class to search is Inner3
   26.46 +           m2(1, 1);
   26.47 +        }
   26.48 +    }
   26.49 +
   26.50 +    class Inner4 extends Inner2 {
   26.51 +        void test() {
   26.52 +           //ok - Inner2 defines multiple incompatible inaccessible methods - hence, class to search is Outer
   26.53 +           m1("");
   26.54 +        }
   26.55 +    }
   26.56 +
   26.57 +    class Inner5 extends Inner3 {
   26.58 +        void test() {
   26.59 +           //ok - Inner3 defines multiple inaccessible ambiguous methods - hence, class to search is Outer
   26.60 +           m2(1, 1);
   26.61 +        }
   26.62 +    }
   26.63 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/tools/javac/7132880/T7132880.out	Fri Mar 09 11:59:26 2012 -0800
    27.3 @@ -0,0 +1,4 @@
    27.4 +T7132880.java:23:12: compiler.err.cant.apply.symbol.1: kindname.method, m1, java.lang.Integer, java.lang.String, kindname.class, Outer.Inner1, (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Integer)
    27.5 +T7132880.java:33:12: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Double), (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Double)),(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Integer))}
    27.6 +T7132880.java:43:12: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Object,int), Outer.Inner3, kindname.method, m2(int,java.lang.Object), Outer.Inner3
    27.7 +3 errors
    28.1 --- a/test/tools/javac/ClassPathTest/ClassPathTest.sh	Thu Mar 08 20:35:26 2012 -0800
    28.2 +++ b/test/tools/javac/ClassPathTest/ClassPathTest.sh	Fri Mar 09 11:59:26 2012 -0800
    28.3 @@ -56,7 +56,7 @@
    28.4  # set platform-dependent variables
    28.5  OS=`uname -s`
    28.6  case "$OS" in
    28.7 -  SunOS | Linux | CYGWIN* )
    28.8 +  SunOS | Linux | Darwin | CYGWIN* )
    28.9      FS="/"
   28.10      ;;
   28.11    Windows* )
    29.1 --- a/test/tools/javac/ExtDirs/ExtDirs.sh	Thu Mar 08 20:35:26 2012 -0800
    29.2 +++ b/test/tools/javac/ExtDirs/ExtDirs.sh	Fri Mar 09 11:59:26 2012 -0800
    29.3 @@ -54,7 +54,7 @@
    29.4  # set platform-dependent variables
    29.5  OS=`uname -s`
    29.6  case "$OS" in
    29.7 -  SunOS | Linux )
    29.8 +  SunOS | Linux | Darwin )
    29.9      PS=":"
   29.10      FS="/"
   29.11      ;;
    30.1 --- a/test/tools/javac/MissingInclude.sh	Thu Mar 08 20:35:26 2012 -0800
    30.2 +++ b/test/tools/javac/MissingInclude.sh	Fri Mar 09 11:59:26 2012 -0800
    30.3 @@ -47,7 +47,7 @@
    30.4  # set platform-dependent variables
    30.5  OS=`uname -s`
    30.6  case "$OS" in
    30.7 -  SunOS | Linux | CYGWIN* )
    30.8 +  SunOS | Linux | Darwin | CYGWIN* )
    30.9      FS="/"
   30.10      ;;
   30.11    Windows* )
    31.1 --- a/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh	Thu Mar 08 20:35:26 2012 -0800
    31.2 +++ b/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh	Fri Mar 09 11:59:26 2012 -0800
    31.3 @@ -52,7 +52,7 @@
    31.4  # set platform-dependent variables
    31.5  OS=`uname -s`
    31.6  case "$OS" in
    31.7 -  SunOS | Linux )
    31.8 +  SunOS | Linux | Darwin )
    31.9      PS=":"
   31.10      FS="/"
   31.11      ;;
    32.1 --- a/test/tools/javac/T5090006/compiler.sh	Thu Mar 08 20:35:26 2012 -0800
    32.2 +++ b/test/tools/javac/T5090006/compiler.sh	Fri Mar 09 11:59:26 2012 -0800
    32.3 @@ -47,7 +47,7 @@
    32.4  # set platform-dependent variables
    32.5  OS=`uname -s`
    32.6  case "$OS" in
    32.7 -  SunOS | Linux | CYGWIN* )
    32.8 +  SunOS | Linux | Darwin | CYGWIN* )
    32.9      FS="/"
   32.10      ;;
   32.11    Windows* )
    33.1 --- a/test/tools/javac/constDebug/ConstDebug.sh	Thu Mar 08 20:35:26 2012 -0800
    33.2 +++ b/test/tools/javac/constDebug/ConstDebug.sh	Fri Mar 09 11:59:26 2012 -0800
    33.3 @@ -47,7 +47,7 @@
    33.4  # set platform-dependent variables
    33.5  OS=`uname -s`
    33.6  case "$OS" in
    33.7 -  SunOS | Linux )
    33.8 +  SunOS | Linux | Darwin )
    33.9      PS=":"
   33.10      FS="/"
   33.11      ;;
    34.1 --- a/test/tools/javac/fatalErrors/NoJavaLang.sh	Thu Mar 08 20:35:26 2012 -0800
    34.2 +++ b/test/tools/javac/fatalErrors/NoJavaLang.sh	Fri Mar 09 11:59:26 2012 -0800
    34.3 @@ -48,7 +48,7 @@
    34.4  # set platform-dependent variables
    34.5  OS=`uname -s`
    34.6  case "$OS" in
    34.7 -  SunOS | Linux )
    34.8 +  SunOS | Linux | Darwin )
    34.9      FS="/"
   34.10      ;;
   34.11    CYGWIN* )
    35.1 --- a/test/tools/javac/generics/6723444/T6723444.out	Thu Mar 08 20:35:26 2012 -0800
    35.2 +++ b/test/tools/javac/generics/6723444/T6723444.out	Fri Mar 09 11:59:26 2012 -0800
    35.3 @@ -1,5 +1,5 @@
    35.4 -T6723444.java:42:9: compiler.err.unreported.exception.need.to.catch.or.throw: X2
    35.5 -T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: X2
    35.6 +T6723444.java:42:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    35.7 +T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    35.8  T6723444.java:45:32: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    35.9  T6723444.java:46:17: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
   35.10  T6723444.java:48:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/tools/javac/generics/7151070/T7151070.java	Fri Mar 09 11:59:26 2012 -0800
    36.3 @@ -0,0 +1,25 @@
    36.4 +/*
    36.5 + * @test /nodynamiccopyright/
    36.6 + * @bug     7151070
    36.7 + * @summary NullPointerException in Resolve.isAccessible
    36.8 + * @compile/fail/ref=T7151070.out -XDrawDiagnostics T7151070.java
    36.9 + */
   36.10 +
   36.11 +class T7151070a {
   36.12 +    private static class PrivateCls { }
   36.13 +    public static class PublicCls extends PrivateCls { }
   36.14 +
   36.15 +    public void m(PrivateCls p) { }
   36.16 +}
   36.17 +
   36.18 +class T7151070b {
   36.19 +    public void test(Test<T7151070a.PublicCls> obj, T7151070a outer) {
   36.20 +        outer.m(obj.get());
   36.21 +    }
   36.22 +
   36.23 +    public static class Test<T> {
   36.24 +        public T get() {
   36.25 +            return null;
   36.26 +        }
   36.27 +    }
   36.28 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/tools/javac/generics/7151070/T7151070.out	Fri Mar 09 11:59:26 2012 -0800
    37.3 @@ -0,0 +1,2 @@
    37.4 +T7151070.java:17:24: compiler.err.report.access: T7151070a.PrivateCls, private, T7151070a
    37.5 +1 error
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/tools/javac/generics/7151802/T7151802.java	Fri Mar 09 11:59:26 2012 -0800
    38.3 @@ -0,0 +1,43 @@
    38.4 +/*
    38.5 + * @test /nodynamiccopyright/
    38.6 + * @bug     7151802
    38.7 + * @summary compiler update caused sqe test failed
    38.8 + * @compile/fail/ref=T7151802.out -Werror -Xlint:unchecked -XDrawDiagnostics T7151802.java
    38.9 + */
   38.10 +class T7151802 {
   38.11 +    static class Foo<X> { }
   38.12 +
   38.13 +    static class SubFoo<X> extends Foo<X> { }
   38.14 +
   38.15 +    //generic - bound - arg - non-slilent
   38.16 +    <Z extends Foo<String>> void get1(Z fz) { }
   38.17 +    void test1(Foo foo) { get1(foo); }
   38.18 +
   38.19 +    //generic - bound - arg - silent
   38.20 +    <Z extends Foo<?>> void get2(Z fz) { }
   38.21 +    void test2(Foo foo) { get2(foo); }
   38.22 +
   38.23 +    //generic - nobound - arg - non-slilent
   38.24 +    <Z> void get3(Foo<Z> fz) { }
   38.25 +    void test(Foo foo) { get3(foo); }
   38.26 +
   38.27 +    //generic - nobound - arg - slilent
   38.28 +    <Z> void get4(Foo<?> fz) { }
   38.29 +    void test4(Foo foo) { get4(foo); }
   38.30 +
   38.31 +    //generic - bound - ret - non-slilent
   38.32 +    <Z extends Foo<String>> Z get5() { return null; }
   38.33 +    void test5() { SubFoo sf = get5(); }
   38.34 +
   38.35 +    //generic - bound - ret - slilent
   38.36 +    static <Z extends Foo<?>> Z get6() { return null; }
   38.37 +    void test6() { SubFoo sf = get6(); }
   38.38 +
   38.39 +    //nogeneric - nobound - arg - non-slilent
   38.40 +    void get7(Foo<String> fz) { }
   38.41 +    void test7(Foo foo) { get7(foo); }
   38.42 +
   38.43 +    //nogeneric - nobound - arg - slilent
   38.44 +    static void get8(Foo<?> fz) { }
   38.45 +    void test8(Foo foo) { get8(foo); }
   38.46 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/test/tools/javac/generics/7151802/T7151802.out	Fri Mar 09 11:59:26 2012 -0800
    39.3 @@ -0,0 +1,9 @@
    39.4 +T7151802.java:14:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get1, Z, T7151802.Foo, kindname.class, T7151802
    39.5 +T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<Z>
    39.6 +T7151802.java:22:30: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get3, T7151802.Foo<Z>, T7151802.Foo, kindname.class, T7151802
    39.7 +T7151802.java:30:36: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get5, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T7151802
    39.8 +T7151802.java:38:32: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.String>
    39.9 +T7151802.java:38:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get7, T7151802.Foo<java.lang.String>, T7151802.Foo, kindname.class, T7151802
   39.10 +- compiler.err.warnings.and.werror
   39.11 +1 error
   39.12 +6 warnings
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/test/tools/javac/generics/rawOverride/T7148556.java	Fri Mar 09 11:59:26 2012 -0800
    40.3 @@ -0,0 +1,42 @@
    40.4 +/*
    40.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
    40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    40.7 + *
    40.8 + * This code is free software; you can redistribute it and/or modify it
    40.9 + * under the terms of the GNU General Public License version 2 only, as
   40.10 + * published by the Free Software Foundation.
   40.11 + *
   40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   40.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   40.15 + * version 2 for more details (a copy is included in the LICENSE file that
   40.16 + * accompanied this code).
   40.17 + *
   40.18 + * You should have received a copy of the GNU General Public License version
   40.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   40.21 + *
   40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   40.23 + * or visit www.oracle.com if you need additional information or have any
   40.24 + * questions.
   40.25 + */
   40.26 +
   40.27 +/*
   40.28 + * @test
   40.29 + * @bug 7148556
   40.30 + * @summary Implementing a generic interface causes a public clone() to become inaccessible
   40.31 + * @compile T7148556.java
   40.32 + */
   40.33 +
   40.34 +class T7148556 {
   40.35 +
   40.36 +    interface A extends Cloneable {
   40.37 +       public Object clone();
   40.38 +    }
   40.39 +
   40.40 +    interface B extends A, java.util.List { }
   40.41 +
   40.42 +    void test(B b) {
   40.43 +        b.clone();
   40.44 +    }
   40.45 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/test/tools/javac/generics/typevars/T7148242.java	Fri Mar 09 11:59:26 2012 -0800
    41.3 @@ -0,0 +1,35 @@
    41.4 +/*
    41.5 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    41.7 + *
    41.8 + * This code is free software; you can redistribute it and/or modify it
    41.9 + * under the terms of the GNU General Public License version 2 only, as
   41.10 + * published by the Free Software Foundation.
   41.11 + *
   41.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   41.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   41.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   41.15 + * version 2 for more details (a copy is included in the LICENSE file that
   41.16 + * accompanied this code).
   41.17 + *
   41.18 + * You should have received a copy of the GNU General Public License version
   41.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   41.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   41.21 + *
   41.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   41.23 + * or visit www.oracle.com if you need additional information or have any
   41.24 + * questions.
   41.25 + */
   41.26 +
   41.27 +/*
   41.28 + * @test
   41.29 + * @bug     7148242
   41.30 + * @summary Regression: valid code rejected during generic type well-formedness check
   41.31 + * @compile T7148242.java
   41.32 + */
   41.33 +class T7148242 {
   41.34 +   static abstract class A<K, V, I extends Pair<K, V>, I2 extends Pair<V, K>> {
   41.35 +      abstract A<V, K, I2, I> test();
   41.36 +   }
   41.37 +   static class Pair<K, V> { }
   41.38 +}
    42.1 --- a/test/tools/javac/innerClassFile/Driver.sh	Thu Mar 08 20:35:26 2012 -0800
    42.2 +++ b/test/tools/javac/innerClassFile/Driver.sh	Fri Mar 09 11:59:26 2012 -0800
    42.3 @@ -53,7 +53,7 @@
    42.4  # set platform-dependent variables
    42.5  OS=`uname -s`
    42.6  case "$OS" in
    42.7 -  SunOS | Linux | CYGWIN* )
    42.8 +  SunOS | Linux | Darwin | CYGWIN* )
    42.9      FS="/"
   42.10      ;;
   42.11    Windows* )
    43.1 --- a/test/tools/javac/javazip/Test.sh	Thu Mar 08 20:35:26 2012 -0800
    43.2 +++ b/test/tools/javac/javazip/Test.sh	Fri Mar 09 11:59:26 2012 -0800
    43.3 @@ -41,7 +41,7 @@
    43.4  # set platform-dependent variables
    43.5  OS=`uname -s`
    43.6  case "$OS" in
    43.7 -  SunOS | Linux )
    43.8 +  SunOS | Linux | Darwin )
    43.9      FS="/"
   43.10      SCR=`pwd`
   43.11      ;;
    44.1 --- a/test/tools/javac/links/links.sh	Thu Mar 08 20:35:26 2012 -0800
    44.2 +++ b/test/tools/javac/links/links.sh	Fri Mar 09 11:59:26 2012 -0800
    44.3 @@ -53,7 +53,7 @@
    44.4  # set platform-dependent variables
    44.5  OS=`uname -s`
    44.6  case "$OS" in
    44.7 -  SunOS | Linux )
    44.8 +  SunOS | Linux | Darwin )
    44.9      NULL=/dev/null
   44.10      PS=":"
   44.11      FS="/"
    45.1 --- a/test/tools/javac/newlines/Newlines.sh	Thu Mar 08 20:35:26 2012 -0800
    45.2 +++ b/test/tools/javac/newlines/Newlines.sh	Fri Mar 09 11:59:26 2012 -0800
    45.3 @@ -50,7 +50,7 @@
    45.4  # set platform-dependent variables
    45.5  OS=`uname -s`
    45.6  case "$OS" in
    45.7 -  SunOS | Linux | CYGWIN* )
    45.8 +  SunOS | Linux | Darwin | CYGWIN* )
    45.9      FS="/"
   45.10      ;;
   45.11    Windows* )
    46.1 --- a/test/tools/javac/stackmap/T4955930.sh	Thu Mar 08 20:35:26 2012 -0800
    46.2 +++ b/test/tools/javac/stackmap/T4955930.sh	Fri Mar 09 11:59:26 2012 -0800
    46.3 @@ -41,7 +41,7 @@
    46.4  # set platform-dependent variables
    46.5  OS=`uname -s`
    46.6  case "$OS" in
    46.7 -  SunOS | Linux | CYGWIN* )
    46.8 +  SunOS | Linux | Darwin | CYGWIN* )
    46.9      FS="/"
   46.10      ;;
   46.11    Windows_95 | Windows_98 | Windows_NT )
    47.1 --- a/test/tools/javac/unicode/SupplementaryJavaID6.sh	Thu Mar 08 20:35:26 2012 -0800
    47.2 +++ b/test/tools/javac/unicode/SupplementaryJavaID6.sh	Fri Mar 09 11:59:26 2012 -0800
    47.3 @@ -55,7 +55,7 @@
    47.4  # set platform-dependent variables
    47.5  OS=`uname -s`
    47.6  case "$OS" in
    47.7 -  SunOS | Linux )
    47.8 +  SunOS | Linux | Darwin )
    47.9      if [ -d /usr/lib/locale/en_US.UTF-8 -o -d /usr/lib/locale/en_US.utf8 ]
   47.10      then
   47.11          ENV="env LANG=en_US.UTF-8"
    48.1 --- a/test/tools/javah/6257087/foo.sh	Thu Mar 08 20:35:26 2012 -0800
    48.2 +++ b/test/tools/javah/6257087/foo.sh	Fri Mar 09 11:59:26 2012 -0800
    48.3 @@ -41,7 +41,7 @@
    48.4  # set platform-dependent variables
    48.5  OS=`uname -s`
    48.6  case "$OS" in
    48.7 -  SunOS | Linux )
    48.8 +  SunOS | Linux | Darwin )
    48.9      PS=":"
   48.10      FS="/"
   48.11      ;;
    49.1 --- a/test/tools/javah/ConstMacroTest.sh	Thu Mar 08 20:35:26 2012 -0800
    49.2 +++ b/test/tools/javah/ConstMacroTest.sh	Fri Mar 09 11:59:26 2012 -0800
    49.3 @@ -56,7 +56,7 @@
    49.4  # set platform-dependent variables
    49.5  OS=`uname -s`
    49.6  case "$OS" in
    49.7 -  SunOS | Linux )
    49.8 +  SunOS | Linux | Darwin )
    49.9      PS=":"
   49.10      FS="/"
   49.11      ;;
    50.1 --- a/test/tools/javah/MissingParamClassTest.sh	Thu Mar 08 20:35:26 2012 -0800
    50.2 +++ b/test/tools/javah/MissingParamClassTest.sh	Fri Mar 09 11:59:26 2012 -0800
    50.3 @@ -58,7 +58,7 @@
    50.4  # set platform-dependent variables
    50.5  OS=`uname -s`
    50.6  case "$OS" in
    50.7 -  SunOS | Linux | CYGWIN* )
    50.8 +  SunOS | Linux | Darwin | CYGWIN* )
    50.9      PS=":"
   50.10      FS="/"
   50.11      ;;
    51.1 --- a/test/tools/javah/ReadOldClass.sh	Thu Mar 08 20:35:26 2012 -0800
    51.2 +++ b/test/tools/javah/ReadOldClass.sh	Fri Mar 09 11:59:26 2012 -0800
    51.3 @@ -43,7 +43,7 @@
    51.4  # set platform-dependent variables
    51.5  OS=`uname -s`
    51.6  case "$OS" in
    51.7 -  SunOS | Linux | CYGWIN* )
    51.8 +  SunOS | Linux | Darwin | CYGWIN* )
    51.9      PS=":"
   51.10      FS="/"
   51.11      ;;
    52.1 --- a/test/tools/javap/pathsep.sh	Thu Mar 08 20:35:26 2012 -0800
    52.2 +++ b/test/tools/javap/pathsep.sh	Fri Mar 09 11:59:26 2012 -0800
    52.3 @@ -40,7 +40,7 @@
    52.4  # set platform-dependent variables
    52.5  OS=`uname -s`
    52.6  case "$OS" in
    52.7 -  SunOS | Linux | CYGWIN* )
    52.8 +  SunOS | Linux | Darwin | CYGWIN* )
    52.9      FS="/"
   52.10      ;;
   52.11    Windows* )

mercurial