Mercurial > hg > openjdk > jdk6 > langtools
changeset 104:1f8b3cc0489d
Merge
author | jjg |
---|---|
date | Mon, 21 Jun 2010 11:28:17 -0700 |
parents | c28b5920263c (current diff) e7e6982abb38 (diff) |
children | 7e27c39553e1 |
files | src/share/classes/com/sun/tools/javac/main/JavaCompiler.java test/tools/javac/policy/A.java test/tools/javac/policy/B.java test/tools/javac/policy/C.java test/tools/javac/policy/D.java test/tools/javac/policy/Test.java test/tools/javac/policy/byfile.ABD.out test/tools/javac/policy/byfile.ACD.out test/tools/javac/policy/bytodo.ABD.out test/tools/javac/policy/bytodo.ACD.out test/tools/javac/policy/simple.ABD.out test/tools/javac/policy/simple.ACD.out |
diffstat | 41 files changed, 1106 insertions(+), 402 deletions(-) [+] |
line wrap: on
line diff
--- a/make/Makefile Fri Jun 18 16:56:47 2010 -0700 +++ b/make/Makefile Mon Jun 21 11:28:17 2010 -0700 @@ -40,15 +40,16 @@ SYSTEM_UNAME := $(shell uname) +# Where is unwanted output to be delivered? +# On Windows, MKS uses the special file "NUL", cygwin uses the customary unix file. ifeq ($(SYSTEM_UNAME), Windows_NT) DEV_NULL = NUL else +DEV_NULL = /dev/null +endif + ifneq (,$(findstring CYGWIN,$(SYSTEM_UNAME))) -DEV_NULL = NUL USING_CYGWIN = true -else -DEV_NULL = /dev/null -endif endif ifdef USING_CYGWIN
--- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Fri Jun 18 16:56:47 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Mon Jun 21 11:28:17 2010 -0700 @@ -472,23 +472,22 @@ } abstract class Filter { - void run(ListBuffer<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) { + void run(Queue<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) { Set<TypeElement> set = new HashSet<TypeElement>(); for (TypeElement item: classes) set.add(item); - List<Env<AttrContext>> defer = List.<Env<AttrContext>>nil(); - while (list.nonEmpty()) { - Env<AttrContext> env = list.next(); + ListBuffer<Env<AttrContext>> defer = ListBuffer.<Env<AttrContext>>lb(); + while (list.peek() != null) { + Env<AttrContext> env = list.remove(); ClassSymbol csym = env.enclClass.sym; if (csym != null && set.contains(csym.outermostClass())) process(env); else - defer = defer.prepend(env); + defer = defer.append(env); } - for (List<Env<AttrContext>> l = defer; l.nonEmpty(); l = l.tail) - list.prepend(l.head); + list.addAll(defer); } abstract void process(Env<AttrContext> env);
--- a/src/share/classes/com/sun/tools/javac/comp/Todo.java Fri Jun 18 16:56:47 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Todo.java Mon Jun 21 11:28:17 2010 -0700 @@ -25,7 +25,14 @@ package com.sun.tools.javac.comp; -import com.sun.tools.javac.util.*; +import java.util.AbstractQueue; +import com.sun.tools.javac.util.Context; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; +import javax.tools.JavaFileObject; /** A queue of all as yet unattributed classes. * @@ -34,7 +41,7 @@ * This code and its internal interfaces are subject to change or * deletion without notice.</b> */ -public class Todo extends ListBuffer<Env<AttrContext>> { +public class Todo extends AbstractQueue<Env<AttrContext>> { /** The context key for the todo list. */ protected static final Context.Key<Todo> todoKey = new Context.Key<Todo>(); @@ -51,4 +58,115 @@ protected Todo(Context context) { context.put(todoKey, this); } + + public void append(Env<AttrContext> env) { + add(env); + } + + @Override + public Iterator<Env<AttrContext>> iterator() { + return contents.iterator(); + } + + @Override + public int size() { + return contents.size(); + } + + public boolean offer(Env<AttrContext> e) { + if (contents.add(e)) { + if (contentsByFile != null) + addByFile(e); + return true; + } else { + return false; + } + } + + public Env<AttrContext> poll() { + if (size() == 0) + return null; + Env<AttrContext> env = contents.remove(0); + if (contentsByFile != null) + removeByFile(env); + return env; + } + + public Env<AttrContext> peek() { + return (size() == 0 ? null : contents.get(0)); + } + + public Queue<Queue<Env<AttrContext>>> groupByFile() { + if (contentsByFile == null) { + contentsByFile = new LinkedList<Queue<Env<AttrContext>>>(); + for (Env<AttrContext> env: contents) { + addByFile(env); + } + } + return contentsByFile; + } + + private void addByFile(Env<AttrContext> env) { + JavaFileObject file = env.toplevel.sourcefile; + if (fileMap == null) + fileMap = new HashMap<JavaFileObject, FileQueue>(); + FileQueue fq = fileMap.get(file); + if (fq == null) { + fq = new FileQueue(); + fileMap.put(file, fq); + contentsByFile.add(fq); + } + fq.fileContents.add(env); + } + + private void removeByFile(Env<AttrContext> env) { + JavaFileObject file = env.toplevel.sourcefile; + FileQueue fq = fileMap.get(file); + if (fq == null) + return; + if (fq.fileContents.remove(env)) { + if (fq.isEmpty()) { + fileMap.remove(file); + contentsByFile.remove(fq); + } + } + } + + LinkedList<Env<AttrContext>> contents = new LinkedList<Env<AttrContext>>(); + LinkedList<Queue<Env<AttrContext>>> contentsByFile; + Map<JavaFileObject, FileQueue> fileMap; + + class FileQueue extends AbstractQueue<Env<AttrContext>> { + @Override + public Iterator<Env<AttrContext>> iterator() { + return fileContents.iterator(); + } + + @Override + public int size() { + return fileContents.size(); + } + + public boolean offer(Env<AttrContext> e) { + if (fileContents.offer(e)) { + contents.add(e); + return true; + } + return false; + } + + public Env<AttrContext> poll() { + if (fileContents.size() == 0) + return null; + Env<AttrContext> env = fileContents.remove(0); + contents.remove(env); + return env; + } + + public Env<AttrContext> peek() { + return (fileContents.size() == 0 ? null : fileContents.get(0)); + } + + LinkedList<Env<AttrContext>> fileContents = new LinkedList<Env<AttrContext>>(); + } }
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Jun 18 16:56:47 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon Jun 21 11:28:17 2010 -0700 @@ -121,35 +121,47 @@ } } - private static enum CompilePolicy { - /* - * Just attribute the parse trees + /** + * Control how the compiler's latter phases (attr, flow, desugar, generate) + * are connected. Each individual file is processed by each phase in turn, + * but with different compile policies, you can control the order in which + * each class is processed through its next phase. + * + * <p>Generally speaking, the compiler will "fail fast" in the face of + * errors, although not aggressively so. flow, desugar, etc become no-ops + * once any errors have occurred. No attempt is currently made to determine + * if it might be safe to process a class through its next phase because + * it does not depend on any unrelated errors that might have occurred. + */ + protected static enum CompilePolicy { + /** + * Just attribute the parse trees. */ ATTR_ONLY, - /* + /** * Just attribute and do flow analysis on the parse trees. * This should catch most user errors. */ CHECK_ONLY, - /* + /** * Attribute everything, then do flow analysis for everything, * then desugar everything, and only then generate output. - * Means nothing is generated if there are any errors in any classes. + * This means no output will be generated if there are any + * errors in any classes. */ SIMPLE, - /* - * After attributing everything and doing flow analysis, - * group the work by compilation unit. - * Then, process the work for each compilation unit together. - * Means nothing is generated for a compilation unit if the are any errors - * in the compilation unit (or in any preceding compilation unit.) + /** + * Groups the classes for each source file together, then process + * each group in a manner equivalent to the {@code SIMPLE} policy. + * This means no output will be generated if there are any + * errors in any of the classes in a source file. */ BY_FILE, - /* + /** * Completely process each entry on the todo list in turn. * -- this is the same for 1.5. * Means output might be generated for some classes in a compilation unit @@ -177,7 +189,7 @@ private static CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO; - private static enum ImplicitSourcePolicy { + protected static enum ImplicitSourcePolicy { /** Don't generate or process implicitly read source files. */ NONE, /** Generate classes for implicitly read source files. */ @@ -247,11 +259,11 @@ /** The type eraser. */ - TransTypes transTypes; + protected TransTypes transTypes; /** The syntactic sugar desweetener. */ - Lower lower; + protected Lower lower; /** The annotation annotator. */ @@ -368,6 +380,11 @@ (options.get("failcomplete") != null) ? names.fromString(options.get("failcomplete")) : null; + + shouldStopPolicy = + (options.get("shouldStopPolicy") != null) + ? CompileState.valueOf(options.get("shouldStopPolicy")) + : null; } /* Switches: @@ -441,14 +458,26 @@ */ public boolean verboseCompilePolicy; + /** + * Policy of how far to continue processing. null means until first + * error. + */ + public CompileState shouldStopPolicy; + /** A queue of all as yet unattributed classes. */ public Todo todo; + /** Ordered list of compiler phases for each compilation unit. */ protected enum CompileState { - TODO(0), - ATTR(1), - FLOW(2); + PARSE(1), + ENTER(2), + PROCESS(3), + ATTR(4), + FLOW(5), + TRANSTYPES(6), + LOWER(7), + GENERATE(8); CompileState(int value) { this.value = value; } @@ -457,6 +486,9 @@ } private int value; }; + /** Partial map to record which compiler phases have been executed + * for each compilation unit. Used for ATTR and FLOW phases. + */ protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { boolean isDone(Env<AttrContext> env, CompileState cs) { CompileState ecs = get(env); @@ -471,6 +503,13 @@ */ protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>(); + protected boolean shouldStop(CompileState cs) { + if (shouldStopPolicy == null) + return (errorCount() > 0); + else + return cs.ordinal() > shouldStopPolicy.ordinal(); + } + /** The number of errors reported so far. */ public int errorCount() { @@ -484,18 +523,12 @@ } } - protected final <T> Queue<T> stopIfError(Queue<T> queue) { - if (errorCount() == 0) - return queue; - else - return ListBuffer.lb(); + protected final <T> Queue<T> stopIfError(CompileState cs, Queue<T> queue) { + return shouldStop(cs) ? ListBuffer.<T>lb() : queue; } - protected final <T> List<T> stopIfError(List<T> list) { - if (errorCount() == 0) - return list; - else - return List.nil(); + protected final <T> List<T> stopIfError(CompileState cs, List<T> list) { + return shouldStop(cs) ? List.<T>nil() : list; } /** The number of warnings reported so far. @@ -652,7 +685,7 @@ */ JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { try { - if (gen.genClass(env, cdef)) + if (gen.genClass(env, cdef) && (errorCount() == 0)) return writer.writeClass(cdef.sym); } catch (ClassWriter.PoolOverflow ex) { log.error(cdef.pos(), "limit.pool"); @@ -759,8 +792,10 @@ initProcessAnnotations(processors); // These method calls must be chained to avoid memory leaks - delegateCompiler = processAnnotations(enterTrees(stopIfError(parseFiles(sourceFileObjects))), - classnames); + delegateCompiler = + processAnnotations( + enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))), + classnames); delegateCompiler.compile2(); delegateCompiler.close(); @@ -793,14 +828,17 @@ generate(desugar(flow(attribute(todo)))); break; - case BY_FILE: - for (Queue<Env<AttrContext>> queue : groupByFile(flow(attribute(todo))).values()) - generate(desugar(queue)); + case BY_FILE: { + Queue<Queue<Env<AttrContext>>> q = todo.groupByFile(); + while (!q.isEmpty() && !shouldStop(CompileState.ATTR)) { + generate(desugar(flow(attribute(q.remove())))); + } + } break; case BY_TODO: - while (todo.nonEmpty()) - generate(desugar(flow(attribute(todo.next())))); + while (!todo.isEmpty()) + generate(desugar(flow(attribute(todo.remove())))); break; default: @@ -830,7 +868,7 @@ * Parses a list of files. */ public List<JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects) throws IOException { - if (errorCount() > 0) + if (shouldStop(CompileState.PARSE)) return List.nil(); //parse all files @@ -943,7 +981,7 @@ public JavaCompiler processAnnotations(List<JCCompilationUnit> roots, List<String> classnames) throws IOException { // TODO: see TEMP note in JavacProcessingEnvironment - if (errorCount() != 0) { + if (shouldStop(CompileState.PROCESS)) { // Errors were encountered. If todo is empty, then the // encountered errors were parse errors. Otherwise, the // errors were found during the enter phase which should @@ -1054,7 +1092,7 @@ ListBuffer<Env<AttrContext>> results = lb(); while (!envs.isEmpty()) results.append(attribute(envs.remove())); - return results; + return stopIfError(CompileState.ATTR, results); } /** @@ -1101,7 +1139,7 @@ for (Env<AttrContext> env: envs) { flow(env, results); } - return stopIfError(results); + return stopIfError(CompileState.FLOW, results); } /** @@ -1110,24 +1148,24 @@ public Queue<Env<AttrContext>> flow(Env<AttrContext> env) { ListBuffer<Env<AttrContext>> results = lb(); flow(env, results); - return stopIfError(results); + return stopIfError(CompileState.FLOW, results); } /** * Perform dataflow checks on an attributed parse tree. */ - protected void flow(Env<AttrContext> env, ListBuffer<Env<AttrContext>> results) { + protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) { try { - if (errorCount() > 0) + if (shouldStop(CompileState.FLOW)) return; if (relax || compileStates.isDone(env, CompileState.FLOW)) { - results.append(env); + results.add(env); return; } if (verboseCompilePolicy) - log.printLines(log.noticeWriter, "[flow " + env.enclClass.sym + "]"); + printNote("[flow " + env.enclClass.sym + "]"); JavaFileObject prev = log.useSource( env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : @@ -1138,10 +1176,10 @@ flow.analyzeTree(env.tree, localMake); compileStates.put(env, CompileState.FLOW); - if (errorCount() > 0) + if (shouldStop(CompileState.FLOW)) return; - results.append(env); + results.add(env); } finally { log.useSource(prev); @@ -1165,7 +1203,7 @@ ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = lb(); for (Env<AttrContext> env: envs) desugar(env, results); - return stopIfError(results); + return stopIfError(CompileState.FLOW, results); } /** @@ -1175,7 +1213,7 @@ * The preparation stops as soon as an error is found. */ protected void desugar(final Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) { - if (errorCount() > 0) + if (shouldStop(CompileState.TRANSTYPES)) return; if (implicitSourcePolicy == ImplicitSourcePolicy.NONE @@ -1190,6 +1228,7 @@ */ class ScanNested extends TreeScanner { Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); + @Override public void visitClassDef(JCClassDecl node) { Type st = types.supertype(node.sym.type); if (st.tag == TypeTags.CLASS) { @@ -1212,11 +1251,11 @@ //We need to check for error another time as more classes might //have been attributed and analyzed at this stage - if (errorCount() > 0) + if (shouldStop(CompileState.TRANSTYPES)) return; if (verboseCompilePolicy) - log.printLines(log.noticeWriter, "[desugar " + env.enclClass.sym + "]"); + printNote("[desugar " + env.enclClass.sym + "]"); JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : @@ -1230,6 +1269,8 @@ if (env.tree instanceof JCCompilationUnit) { if (!(stubOutput || sourceOutput || printFlat)) { + if (shouldStop(CompileState.LOWER)) + return; List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake); if (pdef.head != null) { assert pdef.tail.isEmpty(); @@ -1252,9 +1293,12 @@ return; } + if (shouldStop(CompileState.TRANSTYPES)) + return; + env.tree = transTypes.translateTopLevelClass(env.tree, localMake); - if (errorCount() != 0) + if (shouldStop(CompileState.LOWER)) return; if (sourceOutput) { @@ -1271,7 +1315,7 @@ //translate out inner classes List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake); - if (errorCount() != 0) + if (shouldStop(CompileState.LOWER)) return; //generate code for each class @@ -1295,7 +1339,10 @@ generate(queue, null); } - public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, ListBuffer<JavaFileObject> results) { + public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) { + if (shouldStop(CompileState.GENERATE)) + return; + boolean usePrintSource = (stubOutput || sourceOutput || printFlat); for (Pair<Env<AttrContext>, JCClassDecl> x: queue) { @@ -1303,9 +1350,9 @@ JCClassDecl cdef = x.snd; if (verboseCompilePolicy) { - log.printLines(log.noticeWriter, "[generate " + printNote("[generate " + (usePrintSource ? " source" : "code") - + " " + env.enclClass.sym + "]"); + + " " + cdef.sym + "]"); } if (taskListener != null) { @@ -1323,7 +1370,7 @@ else file = genCode(env, cdef); if (results != null && file != null) - results.append(file); + results.add(file); } catch (IOException ex) { log.error(cdef.pos(), "class.cant.write", cdef.sym, ex.getMessage()); @@ -1357,6 +1404,7 @@ JCClassDecl removeMethodBodies(JCClassDecl cdef) { final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0; class MethodBodyRemover extends TreeTranslator { + @Override public void visitMethodDef(JCMethodDecl tree) { tree.mods.flags &= ~Flags.SYNCHRONIZED; for (JCVariableDecl vd : tree.params) @@ -1364,11 +1412,13 @@ tree.body = null; super.visitMethodDef(tree); } + @Override public void visitVarDef(JCVariableDecl tree) { if (tree.init != null && tree.init.type.constValue() == null) tree.init = null; super.visitVarDef(tree); } + @Override public void visitClassDef(JCClassDecl tree) { ListBuffer<JCTree> newdefs = lb(); for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) { @@ -1455,12 +1505,16 @@ } } + protected void printNote(String lines) { + Log.printLines(log.noticeWriter, lines); + } + /** Output for "-verbose" option. * @param key The key to look up the correct internationalized string. * @param arg An argument for substitution into the output string. */ protected void printVerbose(String key, Object arg) { - Log.printLines(log.noticeWriter, log.getLocalizedString("verbose." + key, arg)); + Log.printLines(log.noticeWriter, Log.getLocalizedString("verbose." + key, arg)); } /** Print numbers of errors and warnings. @@ -1469,9 +1523,9 @@ if (count != 0) { String text; if (count == 1) - text = log.getLocalizedString("count." + kind, String.valueOf(count)); + text = Log.getLocalizedString("count." + kind, String.valueOf(count)); else - text = log.getLocalizedString("count." + kind + ".plural", String.valueOf(count)); + text = Log.getLocalizedString("count." + kind + ".plural", String.valueOf(count)); Log.printLines(log.errWriter, text); log.errWriter.flush(); }
--- a/src/share/classes/com/sun/tools/javadoc/JavadocTodo.java Fri Jun 18 16:56:47 2010 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTodo.java Mon Jun 21 11:28:17 2010 -0700 @@ -46,8 +46,13 @@ super(context); } - public ListBuffer<Env<AttrContext>> append(Env<AttrContext> e) { + @Override + public void append(Env<AttrContext> e) { // do nothing; Javadoc doesn't perform attribution. - return this; + } + + @Override + public boolean offer(Env<AttrContext> e) { + return false; } }
--- a/test/tools/javac/6734819/T6734819a.java Fri Jun 18 16:56:47 2010 -0700 +++ b/test/tools/javac/6734819/T6734819a.java Mon Jun 21 11:28:17 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /*
--- a/test/tools/javac/6734819/T6734819b.java Fri Jun 18 16:56:47 2010 -0700 +++ b/test/tools/javac/6734819/T6734819b.java Mon Jun 21 11:28:17 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /*
--- a/test/tools/javac/6734819/T6734819b.out Fri Jun 18 16:56:47 2010 -0700 +++ b/test/tools/javac/6734819/T6734819b.out Mon Jun 21 11:28:17 2010 -0700 @@ -5,5 +5,5 @@ [desugar A] [generate code A] [desugar B] +[generate code B.C] [generate code B] -[generate code B]
--- a/test/tools/javac/6734819/T6734819c.java Fri Jun 18 16:56:47 2010 -0700 +++ b/test/tools/javac/6734819/T6734819c.java Mon Jun 21 11:28:17 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /*
--- a/test/tools/javac/policy/A.java Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -class A -{ - A() { - D d = new D(); - } -} - -class A1 -{ - A1() { - } -} - -class A2 -{ - A2() { - } -}
--- a/test/tools/javac/policy/B.java Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* /nodynamiccopyright/ */ -class B -{ - B() { - } -} - - -class B1 -{ - B1() { - x = 1; - } -} - -class B2 -{ - B2() { - } -}
--- a/test/tools/javac/policy/C.java Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* /nodynamiccopyright/ */ -class C -{ - C() { - } -} - - -class C1 -{ - C1() { - return; return; - } -} - -class C2 -{ - C2() { - } -}
--- a/test/tools/javac/policy/D.java Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -class D -{ - D() { - } -} - -class D1 -{ - D1() { - } -} - -class D2 -{ - D2() { - } -}
--- a/test/tools/javac/policy/Test.java Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 6260188 6290772 - * @summary provide variable policies for javac operation - * Default compile policy is now "by file" (reverted to "todo" for 6382700) - * Because of attr errors in B, no code should be generated - * @compile/fail/ref=bytodo.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy A.java B.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Generate code for A, A1, A2, B - * @compile/fail/ref=bytodo.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java B.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Because of attr errors in B, no code should be generated - * @compile/fail/ref=simple.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=simple A.java B.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Because of attr errors in B, no code should be generated - * @compile/fail/ref=byfile.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java B.java D.java - */ - - - - -/* - * @test - * @bug 6260188 6290772 - * @summary provide variable policies for javac operation - * Default compile policy is now "by file" (reverted to "todo" for 6382700) - * Generate code for A, A1, A2, but because of flow errors in C, no more code should be generated - * @compile/fail/ref=bytodo.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy A.java C.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Generate code for A, A1, A2, C - * @compile/fail/ref=bytodo.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java C.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Because of flow errors in C, no code should be generated - * @compile/fail/ref=simple.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=simple A.java C.java D.java - */ - -/* - * @test - * @bug 6260188 - * @summary provide variable policies for javac operation - * Generate code for A, A1, A2, but because of flow errors in C, no more code should be generated - * @compile/fail/ref=byfile.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java C.java D.java - */
--- a/test/tools/javac/policy/byfile.ABD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -[attribute A] -[attribute A1] -[attribute A2] -[attribute B] -[attribute B1] -B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 -[attribute B2] -[attribute D] -[attribute D1] -[attribute D2] -1 error
--- a/test/tools/javac/policy/byfile.ACD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -[attribute A] -[attribute A1] -[attribute A2] -[attribute C] -[attribute C1] -[attribute C2] -[attribute D] -[attribute D1] -[attribute D2] -[flow A] -[flow A1] -[flow A2] -[flow C] -[flow C1] -C.java:12:17: compiler.err.unreachable.stmt -1 error
--- a/test/tools/javac/policy/bytodo.ABD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -[attribute A] -[flow A] -[desugar A] -[generate code A] -[attribute A1] -[flow A1] -[desugar A1] -[generate code A1] -[attribute A2] -[flow A2] -[desugar A2] -[generate code A2] -[attribute B] -[flow B] -[desugar B] -[generate code B] -[attribute B1] -B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 -[attribute B2] -[attribute D] -[attribute D1] -[attribute D2] -1 error
--- a/test/tools/javac/policy/bytodo.ACD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -[attribute A] -[flow A] -[desugar A] -[generate code A] -[attribute A1] -[flow A1] -[desugar A1] -[generate code A1] -[attribute A2] -[flow A2] -[desugar A2] -[generate code A2] -[attribute C] -[flow C] -[desugar C] -[generate code C] -[attribute C1] -[flow C1] -C.java:12:17: compiler.err.unreachable.stmt -[attribute C2] -[attribute D] -[attribute D1] -[attribute D2] -1 error
--- a/test/tools/javac/policy/simple.ABD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -[attribute A] -[attribute A1] -[attribute A2] -[attribute B] -[attribute B1] -B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 -[attribute B2] -[attribute D] -[attribute D1] -[attribute D2] -1 error
--- a/test/tools/javac/policy/simple.ACD.out Fri Jun 18 16:56:47 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -[attribute A] -[attribute A1] -[attribute A2] -[attribute C] -[attribute C1] -[attribute C2] -[attribute D] -[attribute D1] -[attribute D2] -[flow A] -[flow A1] -[flow A2] -[flow C] -[flow C1] -C.java:12:17: compiler.err.unreachable.stmt -1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/A.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +class A +{ + A() { + D d = new D(); + } +} + +class A1 +{ + A1() { + } +} + +class A2 +{ + A2() { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/B.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,20 @@ +/* /nodynamiccopyright/ */ +class B +{ + B() { + } +} + + +class B1 +{ + B1() { + x = 1; + } +} + +class B2 +{ + B2() { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/C.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,20 @@ +/* /nodynamiccopyright/ */ +class C +{ + C() { + } +} + + +class C1 +{ + C1() { + return; return; + } +} + +class C2 +{ + C2() { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/D.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +class D +{ + D() { + } +} + +class D1 +{ + D1() { + } +} + +class D2 +{ + D2() { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/Test1a.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// These tests exercise the various compile policies available via +// JavaCompiler.CompilePolicy. Like any golden file tests, they are +// somewhat fragile and susceptible to breakage, but like the canary +// in the mine, it is useful to know when something is not as it used +// to be. The golden files should not be taken as a guarantee of +// future behavior, and should be updated, with due care, if the +// behavior of the compile policy is deliberately changed. + +/* + * @test + * @bug 6260188 6290772 + * @summary provide variable policies for javac operation + * Default compile policy is now "by file" (reverted to "todo" for 6382700) + * Because of attr errors in B, no code should be generated + * @compile/fail/ref=bytodo.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy A.java B.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Generate code for A, A1, A2, B + * @compile/fail/ref=bytodo.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java B.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Because of attr errors in B, no code should be generated + * @compile/fail/ref=simple.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=simple A.java B.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Because of attr errors in B, no code should be generated + * @compile/fail/ref=byfile.ABD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java B.java D.java + */ + + + + +/* + * @test + * @bug 6260188 6290772 + * @summary provide variable policies for javac operation + * Default compile policy is now "by file" (reverted to "todo" for 6382700) + * Generate code for A, A1, A2, but because of flow errors in C, no more code should be generated + * @compile/fail/ref=bytodo.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy A.java C.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Generate code for A, A1, A2, C + * @compile/fail/ref=bytodo.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java C.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Because of flow errors in C, no code should be generated + * @compile/fail/ref=simple.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=simple A.java C.java D.java + */ + +/* + * @test + * @bug 6260188 + * @summary provide variable policies for javac operation + * Generate code for A, A1, A2, but because of flow errors in C, no more code should be generated + * @compile/fail/ref=byfile.ACD.out -XDstdout -XDrawDiagnostics -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java C.java D.java + */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/Test1b.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test 6420151 + * @summary Compile a group of files and validate the set of class files produced + * @run main Test1b -XDcompilePolicy=byfile A.java B.java D.java + */ + +/* + * @test 6420151 + * @summary Compile a group of files and validate the set of class files produced + * @run main Test1b -XDcompilePolicy=byfile A.java C.java D.java + */ + +/* + * @test 6420151 + * @summary Compile a group of files and validate the set of class files produced + * @run main Test1b -XDcompilePolicy=simple A.java B.java D.java + */ + +/* + * @test 6420151 + * @summary Compile a group of files and validate the set of class files produced + * @run main Test1b -XDcompilePolicy=simple A.java C.java D.java + */ + +// These test cases should be uncommented when the default compile policy is +// changed to "byfile". While the default policy is "bytodo", the test cases fail +///* +// * @test 6420151 +// * @summary Compile a group of files and validate the set of class files produced +// * @run main Test1b A.java B.java D.java +// */ +// +///* +// * @test 6420151 +// * @summary Compile a group of files and validate the set of class files produced +// * @run main Test1b A.java C.java D.java +// */ + +// These test cases are retained for debugging; if uncommented, they show that +// to bytodo mode fails the "all or none" class file test +///* +// * @test 6420151 +// * @summary Compile a group of files and validate the set of class files produced +// * @run main Test1b -XDcompilePolicy=bytodo A.java B.java D.java +// */ +// +///* +// * @test 6420151 +// * @summary Compile a group of files and validate the set of class files produced +// * @run main Test1b -XDcompilePolicy=bytodo A.java C.java D.java +// */ + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Test1b +{ + public static void main(String... args) throws Exception { + new Test1b().run(args); + } + + void run(String... args) throws Exception { + File testSrcDir = new File(System.getProperty("test.src")); + File tmpClassDir = new File("."); + List<String> l = new ArrayList<String>(); + l.add("-d"); + l.add(tmpClassDir.getPath()); + for (String a: args) { + if (a.endsWith(".java")) + l.add(new File(testSrcDir, a).getPath()); + else + l.add(a); + } + + StringWriter sw = new StringWriter(); + int rc = com.sun.tools.javac.Main.compile(l.toArray(new String[l.size()]), new PrintWriter(sw)); + System.err.println(sw); + + Pattern p = Pattern.compile("([A-Z]+).*"); + for (String name: tmpClassDir.list()) { + if (name.endsWith(".class")) { + Matcher m = p.matcher(name); + if (m.matches()) { + found(m.group(1), name); + } + } + } + + // for all classes that might have been compiled, check that + // all the classes in the source file get generated, or none do. + check("A", 3); + check("B", 3); + check("C", 3); + check("D", 3); + + if (errors > 0) + throw new Exception(errors + " errors"); + } + + void check(String prefix, int expect) { + List<String> names = map.get(prefix); + int found = (names == null ? 0 : names.size()); + if (found == 0 || found == expect) { + System.err.println("Found " + found + " files for " + prefix + ": OK"); + return; + } + error("Found " + found + " files for " + prefix + ": expected 0 or " + expect + " " + names); + } + + void found(String prefix, String name) { + List<String> names = map.get(prefix); + if (names == null) { + names = new ArrayList<String>(); + map.put(prefix, names); + } + names.add(name); + } + + void error(String message) { + System.err.println(message); + errors++; + } + + Map<String,List<String>> map = new HashMap<String,List<String>>(); + int errors; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/byfile.ABD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,17 @@ +[attribute A] +[attribute A1] +[attribute A2] +[flow A] +[flow A1] +[flow A2] +[desugar A] +[desugar A1] +[desugar A2] +[generate code A] +[generate code A1] +[generate code A2] +[attribute B] +[attribute B1] +B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 +[attribute B2] +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/byfile.ACD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,19 @@ +[attribute A] +[attribute A1] +[attribute A2] +[flow A] +[flow A1] +[flow A2] +[desugar A] +[desugar A1] +[desugar A2] +[generate code A] +[generate code A1] +[generate code A2] +[attribute C] +[attribute C1] +[attribute C2] +[flow C] +[flow C1] +C.java:12:17: compiler.err.unreachable.stmt +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/bytodo.ABD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,23 @@ +[attribute A] +[flow A] +[desugar A] +[generate code A] +[attribute A1] +[flow A1] +[desugar A1] +[generate code A1] +[attribute A2] +[flow A2] +[desugar A2] +[generate code A2] +[attribute B] +[flow B] +[desugar B] +[generate code B] +[attribute B1] +B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 +[attribute B2] +[attribute D] +[attribute D1] +[attribute D2] +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/bytodo.ACD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,24 @@ +[attribute A] +[flow A] +[desugar A] +[generate code A] +[attribute A1] +[flow A1] +[desugar A1] +[generate code A1] +[attribute A2] +[flow A2] +[desugar A2] +[generate code A2] +[attribute C] +[flow C] +[desugar C] +[generate code C] +[attribute C1] +[flow C1] +C.java:12:17: compiler.err.unreachable.stmt +[attribute C2] +[attribute D] +[attribute D1] +[attribute D2] +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/simple.ABD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,11 @@ +[attribute A] +[attribute A1] +[attribute A2] +[attribute B] +[attribute B1] +B.java:12:9: compiler.err.cant.resolve.location: (- compiler.misc.kindname.variable), x, , , (- compiler.misc.kindname.class), B1 +[attribute B2] +[attribute D] +[attribute D1] +[attribute D2] +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test1/simple.ACD.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,16 @@ +[attribute A] +[attribute A1] +[attribute A2] +[attribute C] +[attribute C1] +[attribute C2] +[attribute D] +[attribute D1] +[attribute D2] +[flow A] +[flow A1] +[flow A2] +[flow C] +[flow C1] +C.java:12:17: compiler.err.unreachable.stmt +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/A.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +class A { + + class A1 { + } + + static class A2 extends B { + } + + static class A3 extends B.Inner { + } + + class A4 { + void m1() { + class A3m1 { } + } + + void m2() { + new B() { + }; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/B.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +class B { + static class Inner { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/Test.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @compile/ref=byfile.AB.out -XDstdout -XDverboseCompilePolicy -XDcompile.policy=byfile A.java B.java + */ + +/* + * @test + * @compile/ref=byfile.BA.out -XDstdout -XDverboseCompilePolicy -XDcompile.policy=byfile B.java A.java + */ + +/* + * @test + * @compile/ref=bytodo.AB.out -XDstdout -XDverboseCompilePolicy -XDcompile.policy=bytodo A.java B.java + */ + +/* + * @test + * @compile/ref=bytodo.BA.out -XDstdout -XDverboseCompilePolicy -XDcompile.policy=bytodo B.java A.java + */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/byfile.AB.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,15 @@ +[attribute A] +[flow A] +[attribute B] +[flow B] +[desugar A] +[generate code A.A1] +[generate code A.A2] +[generate code A.A3] +[generate code A3m1] +[generate code <anonymous A$A4$1>] +[generate code A.A4] +[generate code A] +[desugar B] +[generate code B.Inner] +[generate code B]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/byfile.BA.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,15 @@ +[attribute B] +[flow B] +[desugar B] +[generate code B.Inner] +[generate code B] +[attribute A] +[flow A] +[desugar A] +[generate code A.A1] +[generate code A.A2] +[generate code A.A3] +[generate code A3m1] +[generate code <anonymous A$A4$1>] +[generate code A.A4] +[generate code A]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/bytodo.AB.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,15 @@ +[attribute A] +[flow A] +[attribute B] +[flow B] +[desugar A] +[generate code A.A1] +[generate code A.A2] +[generate code A.A3] +[generate code A3m1] +[generate code <anonymous A$A4$1>] +[generate code A.A4] +[generate code A] +[desugar B] +[generate code B.Inner] +[generate code B]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test2/bytodo.BA.out Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,15 @@ +[attribute B] +[flow B] +[desugar B] +[generate code B.Inner] +[generate code B] +[attribute A] +[flow A] +[desugar A] +[generate code A.A1] +[generate code A.A2] +[generate code A.A3] +[generate code A3m1] +[generate code <anonymous A$A4$1>] +[generate code A.A4] +[generate code A]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test3/A.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,10 @@ +class A { + void m1() { + System.err.println("hello"); + 0 // syntax error + System.err.println("world"); + } + + void m2() { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/policy/test3/Test.java Mon Jun 21 11:28:17 2010 -0700 @@ -0,0 +1,169 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* @test + * @bug 6813059 + * @summary + */ + +import java.io.*; +import java.util.*; + +// Simple test of -XDshouldStopPolicy. +// For each of the permissable values, we compile a file with an error in it, +// then using -XDverboseCompilePolicy we check that the compilation gets as +// far as expected, but no further. + +public class Test { + enum ShouldStopPolicy { + BLANK(false, null, "attr"), + PROCESS(true, null, "attr"), + ATTR(true, "attr", "flow"), + FLOW(true, "flow", "desugar"), + TRANSTYPES(true, "desugar", "generate"), + LOWER(true, "desugar", "generate"), + GENERATE(true, "generate", null); + ShouldStopPolicy(boolean needOption, String expect, String dontExpect) { + this.needOption = needOption; + this.expect = expect; + this.dontExpect = dontExpect; + } + boolean needOption; + String expect; + String dontExpect; + } + + enum CompilePolicy { + BYFILE, + BYTODO + } + + public static void main(String... args) throws Exception { + new Test().run(); + } + + public void run() throws Exception { + for (CompilePolicy cp: CompilePolicy.values()) { + for (ShouldStopPolicy ssp: ShouldStopPolicy.values()) { + test(cp, ssp); + } + } + + if (errors > 0) + throw new Exception(errors + " errors occurred"); + } + + public void test(CompilePolicy cp, ShouldStopPolicy ssp) { + System.err.println(); + System.err.println("test " + cp + " " + ssp); + List<String> args = new ArrayList<String>(); + args.add("-XDverboseCompilePolicy"); + args.add("-XDcompilePolicy=" + cp.toString().toLowerCase()); + args.add("-d"); + args.add("."); + if (ssp.needOption) + args.add("-XDshouldStopPolicy=" + ssp); + args.add(new File(System.getProperty("test.src", "."), "A.java").getPath()); + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + System.err.println("compile " + args); + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); + if (rc == 0) + throw new Error("compilation succeeded unexpectedly"); + //System.err.println(sw); + + // The following is a workaround for the current javac implementation, + // that in bytodo mode, it will still attribute files after syntax errors. + // Changing that behavior may surprise existing users, so for now, we + // work around it. + if (cp == CompilePolicy.BYTODO && ssp == ShouldStopPolicy.PROCESS) + ssp = ShouldStopPolicy.ATTR; + + boolean foundExpected = (ssp.expect == null); + String[] lines = sw.toString().split("\n"); + for (String line: lines) { + if (ssp.expect != null && line.startsWith("[" + ssp.expect)) + foundExpected = true; + if (ssp.dontExpect != null && line.startsWith("[" + ssp.dontExpect)) { + error("Unexpected output: " + ssp.dontExpect + "\n" + sw); + return; + } + } + + if (!foundExpected) + error("Expected output not found: " + ssp.expect + "\n" + sw); + } + + void error(String message) { + System.err.println(message); + errors++; + } + + int errors; +} + + + + + + + + + + + + +// These tests test the ability of the compiler to continue in the face of +// errors, accordining to the shouldStopPolicy + +/* @ test /nodynamiccopyright/ + * @bug 6813059 + * @summary + * @compile/fail/ref=flow.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=FLOW Test.java + + * @compile/fail/ref=default.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy Test.java + * @compile/fail/ref=enter.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=ENTER Test.java + * @compile/fail/ref=attr.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=ATTR Test.java + * @compile/fail/ref=transtypes.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=TRANSTYPES Test.java + * @compile/fail/ref=lower.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=LOWER Test.java + * @compile/fail/ref=generate.out -XDrawDiagnostics -XDcompilePolicy=byfile -XDverboseCompilePolicy -XDshouldStopPolicy=GENERATE Test.java + */ + +/* +class Test { + void m1() { + System.err.println("hello"); + 0 // syntax error + System.err.println("world"); + } + + void m2() { + } +} + +class Test2 { +} +*/ +