Mercurial > hg > shenandoah-preopenjdk-archive > openjdk8 > langtools
changeset 1201:3b168225dfc0
Merge
author | asaha |
---|---|
date | Tue, 14 Feb 2012 10:29:36 -0800 |
parents | 34e175c1fabc (current diff) 8ff85191a7ac (diff) |
children | d903497bf389 |
files | src/share/classes/com/sun/tools/javac/Launcher.java |
diffstat | 167 files changed, 5822 insertions(+), 500 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Tue Jul 19 11:05:57 2011 -0700 +++ b/.hgtags Tue Feb 14 10:29:36 2012 -0800 @@ -122,3 +122,14 @@ c455e2ae5c93014ae3fc475aba4509b5f70465f7 jdk7-b145 9425dd4f53d5bfcd992d9aecea0eb7d8b2d4f62b jdk7-b146 58bc532d63418ac3c9b42460d89cdaf595c6f3e1 jdk7-b147 +e9f118c2bd3c4690d8d2e6b108b5bad7e226634c jdk8-b01 +b3c059de2a61fc122c99d555cdd8b85f112393c1 jdk8-b02 +f497fac86cf9ada4801ecaf49eb0d2307a2b61c8 jdk8-b03 +5df63fd8fa64741e829281ee6febe9954932841b jdk8-b04 +5304c2a17d4b001e365a8f0163082dc375f1abab jdk8-b05 +d2422276f9dabc848b7a079025719826d2f9a30f jdk8-b06 +116980ecec5cc7d52736f09cf332321e0773265f jdk8-b07 +e8acc2d6c32f0c8321e642e1a86672a2e196a056 jdk8-b08 +b7a7e47c8d3daf7822abf7c37e5179ccbbf53008 jdk8-b09 +f6c783e18bdf4d46a0ab273868afebbf32600ff7 jdk8-b10 +4bf01f1c4e3464f378959d10f3983a0469181d94 jdk8-b11
--- a/make/jprt.properties Tue Jul 19 11:05:57 2011 -0700 +++ b/make/jprt.properties Tue Feb 14 10:29:36 2012 -0800 @@ -25,12 +25,23 @@ # Properties for jprt -# Use whatever release that the submitted job requests -jprt.tools.default.release=${jprt.submit.release} +# The release to build +jprt.tools.default.release=jdk8 # The different build flavors we want, we override here so we just get these 2 jprt.build.flavors=product,fastdebug +# Standard list of jprt build targets for this source tree +jprt.build.targets= \ + solaris_sparc_5.10-{product|fastdebug}, \ + solaris_sparcv9_5.10-{product|fastdebug}, \ + solaris_i586_5.10-{product|fastdebug}, \ + solaris_x64_5.10-{product|fastdebug}, \ + linux_i586_2.6-{product|fastdebug}, \ + linux_x64_2.6-{product|fastdebug}, \ + windows_i586_5.1-{product|fastdebug}, \ + windows_x64_5.2-{product|fastdebug} + # Directories to be excluded from the source bundles jprt.bundle.exclude.src.dirs=build dist webrev
--- a/src/share/classes/com/sun/tools/javac/Launcher.java Tue Jul 19 11:05:57 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2006, 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package com.sun.tools.javac; - -import java.io.File; -import java.util.prefs.Preferences; -import javax.swing.JFileChooser; -import javax.tools.JavaCompiler; -import javax.tools.ToolProvider; - - -/** - * <b>Unsupported</b> entry point for starting javac from an IDE. - * - * <p><b>Note:</b> this class is not available in the JDK. It is not - * compiled by default and will not be in tools.jar. It is designed - * to be useful when editing the compiler sources in an IDE (as part - * of a <em>project</em>). Simply ensure that this class is added to - * the project and make it the main class of the project.</p> - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own - * risk. This code and its internal interfaces are subject to change - * or deletion without notice.</b></p> - * - * @author Peter von der Ahé - * @since 1.6 - */ -class Launcher { - public static void main(String... args) { - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - JFileChooser fileChooser; - Preferences prefs = Preferences.userNodeForPackage(Launcher.class); - if (args.length > 0) - fileChooser = new JFileChooser(args[0]); - else { - String fileName = prefs.get("recent.file", null); - fileChooser = new JFileChooser(); - if (fileName != null) { - fileChooser = new JFileChooser(); - fileChooser.setSelectedFile(new File(fileName)); - } - } - if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { - String fileName = fileChooser.getSelectedFile().getPath(); - prefs.put("recent.file", fileName); - javac.run(System.in, null, null, "-d", "/tmp", fileName); - } - } -}
--- a/src/share/classes/com/sun/tools/javac/Main.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/Main.java Tue Feb 14 10:29:36 2012 -0800 @@ -73,7 +73,7 @@ public static int compile(String[] args) { com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac"); - return compiler.compile(args); + return compiler.compile(args).exitCode; } @@ -91,6 +91,6 @@ public static int compile(String[] args, PrintWriter out) { com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac", out); - return compiler.compile(args); + return compiler.compile(args).exitCode; } }
--- a/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Tue Feb 14 10:29:36 2012 -0800 @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -51,6 +52,7 @@ import com.sun.source.util.TaskListener; import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -146,7 +148,7 @@ return fo; } - <T> DiagnosticListener<T> wrap(DiagnosticListener<T> dl) { + <T /*super JavaFileOject*/> DiagnosticListener<T> wrap(DiagnosticListener<T> dl) { if (isTrusted(dl)) return dl; return new WrappedDiagnosticListener<T>(dl); @@ -158,6 +160,16 @@ return new WrappedTaskListener(tl); } + @SuppressWarnings("unchecked") + private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) { + if (diagnostic instanceof JCDiagnostic) { + JCDiagnostic d = (JCDiagnostic) diagnostic; + return (Diagnostic<T>) new DiagnosticSourceUnwrapper(d); + } else { + return diagnostic; + } + } + protected boolean isTrusted(Object o) { Class<?> c = o.getClass(); Boolean trusted = trustedClasses.get(c); @@ -534,7 +546,7 @@ } } - protected class WrappedDiagnosticListener<T> implements DiagnosticListener<T> { + protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> { protected DiagnosticListener<T> clientDiagnosticListener; WrappedDiagnosticListener(DiagnosticListener<T> clientDiagnosticListener) { clientDiagnosticListener.getClass(); // null check @@ -544,7 +556,7 @@ @Override public void report(Diagnostic<? extends T> diagnostic) { try { - clientDiagnosticListener.report(diagnostic); + clientDiagnosticListener.report(unwrap(diagnostic)); } catch (ClientCodeException e) { throw e; } catch (RuntimeException e) { @@ -555,6 +567,54 @@ } } + public class DiagnosticSourceUnwrapper implements Diagnostic<JavaFileObject> { + public final JCDiagnostic d; + + DiagnosticSourceUnwrapper(JCDiagnostic d) { + this.d = d; + } + + public Diagnostic.Kind getKind() { + return d.getKind(); + } + + public JavaFileObject getSource() { + return unwrap(d.getSource()); + } + + public long getPosition() { + return d.getPosition(); + } + + public long getStartPosition() { + return d.getStartPosition(); + } + + public long getEndPosition() { + return d.getEndPosition(); + } + + public long getLineNumber() { + return d.getLineNumber(); + } + + public long getColumnNumber() { + return d.getColumnNumber(); + } + + public String getCode() { + return d.getCode(); + } + + public String getMessage(Locale locale) { + return d.getMessage(locale); + } + + public String toString() { + return d.toString(); + } + } + protected class WrappedTaskListener implements TaskListener { protected TaskListener clientTaskListener; WrappedTaskListener(TaskListener clientTaskListener) {
--- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -78,7 +78,7 @@ private AtomicBoolean used = new AtomicBoolean(); private Iterable<? extends Processor> processors; - private Integer result = null; + private Main.Result result = null; JavacTaskImpl(Main compilerMain, String[] args, @@ -131,7 +131,7 @@ compilerMain.setAPIMode(true); result = compilerMain.compile(args, context, fileObjects, processors); cleanup(); - return result == 0; + return result.isOK(); } else { throw new IllegalStateException("multiple calls to method 'call'"); } @@ -158,10 +158,10 @@ } else { initContext(); compilerMain.setOptions(Options.instance(context)); - compilerMain.filenames = new ListBuffer<File>(); - List<File> filenames = compilerMain.processArgs(CommandLine.parse(args)); + compilerMain.filenames = new LinkedHashSet<File>(); + Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args)); if (!filenames.isEmpty()) - throw new IllegalArgumentException("Malformed arguments " + filenames.toString(" ")); + throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); compiler = JavaCompiler.instance(context); compiler.keepComments = true; compiler.genEndPos = true; @@ -177,6 +177,17 @@ } } + <T> String toString(Iterable<T> items, String sep) { + String currSep = ""; + StringBuilder sb = new StringBuilder(); + for (T item: items) { + sb.append(currSep); + sb.append(item.toString()); + currSep = sep; + } + return sb.toString(); + } + private void initContext() { context.put(JavacTaskImpl.class, this); if (context.get(TaskListener.class) != null) @@ -263,6 +274,9 @@ public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees) throws IOException { + if (trees == null && notYetEntered != null && notYetEntered.isEmpty()) + return List.nil(); + prepareCompiler(); ListBuffer<JCCompilationUnit> roots = null;
--- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Tue Feb 14 10:29:36 2012 -0800 @@ -65,6 +65,7 @@ import com.sun.tools.javac.tree.TreeCopier; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeMaker; +import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.List; @@ -263,9 +264,10 @@ if (!(path.getLeaf() instanceof JCTree)) // implicit null-check throw new IllegalArgumentException(); - // if we're being invoked via from a JSR199 client, we need to make sure - // all the classes have been entered; if we're being invoked from JSR269, - // then the classes will already have been entered. + // if we're being invoked from a Tree API client via parse/enter/analyze, + // we need to make sure all the classes have been entered; + // if we're being invoked from JSR 199 or JSR 269, then the classes + // will already have been entered. if (javacTaskImpl != null) { try { javacTaskImpl.enter(null); @@ -313,10 +315,19 @@ break; case BLOCK: { // System.err.println("BLOCK: "); - if (method != null) - env = memberEnter.getMethodEnv(method, env); - JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf()); - env = attribStatToTree(body, env, copier.leafCopy); + if (method != null) { + try { + Assert.check(method.body == tree); + method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); + env = memberEnter.getMethodEnv(method, env); + env = attribStatToTree(method.body, env, copier.leafCopy); + } finally { + method.body = (JCBlock) tree; + } + } else { + JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); + env = attribStatToTree(body, env, copier.leafCopy); + } return env; } default: @@ -329,7 +340,7 @@ } } } - return field != null ? memberEnter.getInitEnv(field, env) : env; + return (field != null) ? memberEnter.getInitEnv(field, env) : env; } private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) {
--- a/src/share/classes/com/sun/tools/javac/code/Kinds.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Kinds.java Tue Feb 14 10:29:36 2012 -0800 @@ -103,6 +103,8 @@ VAL("kindname.value"), METHOD("kindname.method"), CLASS("kindname.class"), + STATIC_INIT("kindname.static.init"), + INSTANCE_INIT("kindname.instance.init"), PACKAGE("kindname.package"); private String name; @@ -170,9 +172,11 @@ return KindName.CONSTRUCTOR; case METHOD: + return KindName.METHOD; case STATIC_INIT: + return KindName.STATIC_INIT; case INSTANCE_INIT: - return KindName.METHOD; + return KindName.INSTANCE_INIT; default: if (sym.kind == VAL)
--- a/src/share/classes/com/sun/tools/javac/code/Printer.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java Tue Feb 14 10:29:36 2012 -0800 @@ -311,7 +311,7 @@ @Override public String visitMethodSymbol(MethodSymbol s, Locale locale) { - if ((s.flags() & BLOCK) != 0) { + if (s.isStaticOrInstanceInit()) { return s.owner.name.toString(); } else { String ms = (s.name == s.name.table.names.init)
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Tue Feb 14 10:29:36 2012 -0800 @@ -149,7 +149,8 @@ * the default package; otherwise, the owner symbol is returned */ public Symbol location() { - if (owner.name == null || (owner.name.isEmpty() && owner.kind != PCK && owner.kind != TYP)) { + if (owner.name == null || (owner.name.isEmpty() && + (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) { return null; } return owner; @@ -725,6 +726,11 @@ */ public JavaFileObject classfile; + /** the list of translated local classes (used for generating + * InnerClasses attribute) + */ + public List<ClassSymbol> trans_local; + /** the constant pool of the class */ public Pool pool; @@ -1299,10 +1305,17 @@ return ElementKind.CONSTRUCTOR; else if (name == name.table.names.clinit) return ElementKind.STATIC_INIT; + else if ((flags() & BLOCK) != 0) + return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; else return ElementKind.METHOD; } + public boolean isStaticOrInstanceInit() { + return getKind() == ElementKind.STATIC_INIT || + getKind() == ElementKind.INSTANCE_INIT; + } + public Attribute getDefaultValue() { return defaultValue; }
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Feb 14 10:29:36 2012 -0800 @@ -269,10 +269,12 @@ // <editor-fold defaultstate="collapsed" desc="isConvertible"> /** - * Is t a subtype of or convertiable via boxing/unboxing - * convertions to s? + * Is t a subtype of or convertible via boxing/unboxing + * conversion to s? */ public boolean isConvertible(Type t, Type s, Warner warn) { + if (t.tag == ERROR) + return true; boolean tPrimitive = t.isPrimitive(); boolean sPrimitive = s.isPrimitive(); if (tPrimitive == sPrimitive) { @@ -506,8 +508,13 @@ @Override public Boolean visitUndetVar(UndetVar t, Type s) { //todo: test against origin needed? or replace with substitution? - if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) + if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) { return true; + } else if (s.tag == BOT) { + //if 's' is 'null' there's no instantiated type U for which + //U <: s (but 'null' itself, which is not a valid type) + return false; + } if (t.inst != null) return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"? @@ -2117,6 +2124,8 @@ } } + List<TypeSymbol> seenTypes = List.nil(); + /** members closure visitor methods **/ public CompoundScope visitType(Type t, Boolean skipInterface) { @@ -2125,21 +2134,33 @@ @Override public CompoundScope visitClassType(ClassType t, Boolean skipInterface) { - ClassSymbol csym = (ClassSymbol)t.tsym; - Entry e = _map.get(csym); - if (e == null || !e.matches(skipInterface)) { - CompoundScope membersClosure = new CompoundScope(csym); - if (!skipInterface) { - for (Type i : interfaces(t)) { - membersClosure.addSubScope(visit(i, skipInterface)); + if (seenTypes.contains(t.tsym)) { + //this is possible when an interface is implemented in multiple + //superclasses, or when a classs hierarchy is circular - in such + //cases we don't need to recurse (empty scope is returned) + return new CompoundScope(t.tsym); + } + try { + seenTypes = seenTypes.prepend(t.tsym); + ClassSymbol csym = (ClassSymbol)t.tsym; + Entry e = _map.get(csym); + if (e == null || !e.matches(skipInterface)) { + CompoundScope membersClosure = new CompoundScope(csym); + if (!skipInterface) { + for (Type i : interfaces(t)) { + membersClosure.addSubScope(visit(i, skipInterface)); + } } + membersClosure.addSubScope(visit(supertype(t), skipInterface)); + membersClosure.addSubScope(csym.members()); + e = new Entry(skipInterface, membersClosure); + _map.put(csym, e); } - membersClosure.addSubScope(visit(supertype(t), skipInterface)); - membersClosure.addSubScope(csym.members()); - e = new Entry(skipInterface, membersClosure); - _map.put(csym, e); + return e.compoundScope; } - return e.compoundScope; + finally { + seenTypes = seenTypes.tail; + } } @Override
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Feb 14 10:29:36 2012 -0800 @@ -594,7 +594,15 @@ lintEnv = lintEnv.next; // Having found the enclosing lint value, we can initialize the lint value for this class - env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); + // ... but ... + // There's a problem with evaluating annotations in the right order, such that + // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be + // null. In that case, calling augment will throw an NPE. To avoid this, for now we + // revert to the jdk 6 behavior and ignore the (unevaluated) attributes. + if (env.info.enclVar.attributes_field == null) + env.info.lint = lintEnv.info.lint; + else + env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); Lint prevLint = chk.setLint(env.info.lint); JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); @@ -1837,7 +1845,7 @@ try { constructor = rs.resolveDiamond(tree.pos(), localEnv, - clazztype.tsym.type, + clazztype, argtypes, typeargtypes); } finally { @@ -2872,8 +2880,10 @@ if (clazztype.tag == CLASS) { List<Type> formals = clazztype.tsym.type.getTypeArguments(); - - if (actuals.length() == formals.length() || actuals.length() == 0) { + if (actuals.isEmpty()) //diamond + actuals = formals; + + if (actuals.length() == formals.length()) { List<Type> a = actuals; List<Type> f = formals; while (a.nonEmpty()) {
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Feb 14 10:29:36 2012 -0800 @@ -306,7 +306,16 @@ */ void duplicateError(DiagnosticPosition pos, Symbol sym) { if (!sym.type.isErroneous()) { - log.error(pos, "already.defined", sym, sym.location()); + Symbol location = sym.location(); + if (location.kind == MTH && + ((MethodSymbol)location).isStaticOrInstanceInit()) { + log.error(pos, "already.defined.in.clinit", kindName(sym), sym, + kindName(sym.location()), kindName(sym.location().enclClass()), + sym.location().enclClass()); + } else { + log.error(pos, "already.defined", kindName(sym), sym, + kindName(sym.location()), sym.location()); + } } } @@ -1160,12 +1169,17 @@ if (lint.isEnabled(LintCategory.RAW) && tree.type.tag == CLASS && !TreeInfo.isDiamond(tree) && - !env.enclClass.name.isEmpty() && //anonymous or intersection + !withinAnonConstr(env) && tree.type.isRaw()) { log.warning(LintCategory.RAW, tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type); } } + + boolean withinAnonConstr(Env<AttrContext> env) { + return env.enclClass.name.isEmpty() && + env.enclMethod != null && env.enclMethod.name == names.init; + } } /* *************************************************************************
--- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Feb 14 10:29:36 2012 -0800 @@ -269,21 +269,18 @@ // VGJ: sort of inlined maximizeInst() below. Adding // bounds can cause lobounds that are above hibounds. List<Type> hibounds = Type.filter(that.hibounds, errorFilter); + Type hb = null; if (hibounds.isEmpty()) - return; - Type hb = null; - if (hibounds.tail.isEmpty()) + hb = syms.objectType; + else if (hibounds.tail.isEmpty()) hb = hibounds.head; - else for (List<Type> bs = hibounds; - bs.nonEmpty() && hb == null; - bs = bs.tail) { - if (isSubClass(bs.head, hibounds)) - hb = types.fromUnknownFun.apply(bs.head); - } + else + hb = types.glb(hibounds); if (hb == null || - !types.isSubtypeUnchecked(hb, hibounds, warn) || - !types.isSubtypeUnchecked(that.inst, hb, warn)) - throw ambiguousNoInstanceException; + hb.isErroneous()) + throw ambiguousNoInstanceException + .setMessage("incompatible.upper.bounds", + that.qtype, hibounds); } }
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Feb 14 10:29:36 2012 -0800 @@ -2271,6 +2271,14 @@ tree.extending = translate(tree.extending); tree.implementing = translate(tree.implementing); + if (currentClass.isLocal()) { + ClassSymbol encl = currentClass.owner.enclClass(); + if (encl.trans_local == null) { + encl.trans_local = List.nil(); + } + encl.trans_local = encl.trans_local.prepend(currentClass); + } + // Recursively translate members, taking into account that new members // might be created during the translation and prepended to the member // list `tree.defs'. @@ -3450,6 +3458,7 @@ JCExpression expression = oneCase.getExpression(); if (expression != null) { // expression for a "default" case is null + expression = TreeInfo.skipParens(expression); String labelExpr = (String) expression.type.constValue(); Integer mapping = caseLabelToPosition.put(labelExpr, casePosition); Assert.checkNull(mapping); @@ -3555,8 +3564,8 @@ if (isDefault) caseExpr = null; else { - caseExpr = make.Literal(caseLabelToPosition.get((String)oneCase. - getExpression(). + caseExpr = make.Literal(caseLabelToPosition.get((String)TreeInfo.skipParens(oneCase. + getExpression()). type.constValue())); }
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Feb 14 10:29:36 2012 -0800 @@ -767,16 +767,13 @@ m2.erasure(types).getParameterTypes())) return ambiguityError(m1, m2); // both abstract, neither overridden; merge throws clause and result type - Symbol mostSpecific; - if (types.returnTypeSubstitutable(mt1, mt2)) - mostSpecific = m1; - else if (types.returnTypeSubstitutable(mt2, mt1)) - mostSpecific = m2; - else { + Type mst = mostSpecificReturnType(mt1, mt2); + if (mst == null) { // Theoretically, this can't happen, but it is possible // due to error recovery or mixing incompatible class files return ambiguityError(m1, m2); } + Symbol mostSpecific = mst == mt1 ? m1 : m2; List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes()); Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown); MethodSymbol result = new MethodSymbol( @@ -859,6 +856,28 @@ } } //where + Type mostSpecificReturnType(Type mt1, Type mt2) { + Type rt1 = mt1.getReturnType(); + Type rt2 = mt2.getReturnType(); + + if (mt1.tag == FORALL && mt2.tag == FORALL) { + //if both are generic methods, adjust return type ahead of subtyping check + rt1 = types.subst(rt1, mt1.getTypeArguments(), mt2.getTypeArguments()); + } + //first use subtyping, then return type substitutability + if (types.isSubtype(rt1, rt2)) { + return mt1; + } else if (types.isSubtype(rt2, rt1)) { + return mt2; + } else if (types.returnTypeSubstitutable(mt1, mt2)) { + return mt1; + } else if (types.returnTypeSubstitutable(mt2, mt1)) { + return mt2; + } else { + return null; + } + } + //where Symbol ambiguityError(Symbol m1, Symbol m2) { if (((m1.flags() | m2.flags()) & CLASH) != 0) { return (m1.flags() & CLASH) == 0 ? m1 : m2;
--- a/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -98,6 +98,7 @@ @Override public OutputStream openOutputStream() throws IOException { + fileManager.flushCache(this); ensureParentDirectoriesExist(); return new FileOutputStream(file); } @@ -128,6 +129,7 @@ @Override public Writer openWriter() throws IOException { + fileManager.flushCache(this); ensureParentDirectoriesExist(); return new OutputStreamWriter(new FileOutputStream(file), fileManager.getEncodingName()); }
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Feb 14 10:29:36 2012 -0800 @@ -863,10 +863,10 @@ } if (c.type.tag != CLASS) return; // arrays if (pool != null && // pool might be null if called from xClassName - c.owner.kind != PCK && + c.owner.enclClass() != null && (innerClasses == null || !innerClasses.contains(c))) { // log.errWriter.println("enter inner " + c);//DEBUG - if (c.owner.kind == TYP) enterInner((ClassSymbol)c.owner); + enterInner(c.owner.enclClass()); pool.put(c); pool.put(c.name); if (innerClasses == null) { @@ -1505,6 +1505,13 @@ default : Assert.error(); } } + + if (c.trans_local != null) { + for (ClassSymbol local : c.trans_local) { + enterInner(local); + } + } + databuf.appendChar(fieldsCount); writeFields(c.members().elems); databuf.appendChar(methodsCount);
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Feb 14 10:29:36 2012 -0800 @@ -1689,6 +1689,8 @@ // outer instance of a super(...) call appears as first parameter). genArgs(tree.args, TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes()); + code.statBegin(tree.pos); + code.markStatBegin(); result = m.invoke(); }
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Feb 14 10:29:36 2012 -0800 @@ -488,6 +488,10 @@ */ public Todo todo; + /** A list of items to be closed when the compilation is complete. + */ + public List<Closeable> closeables = List.nil(); + /** Ordered list of compiler phases for each compilation unit. */ public enum CompileState { PARSE(1), @@ -1581,6 +1585,19 @@ if (names != null && disposeNames) names.dispose(); names = null; + + for (Closeable c: closeables) { + try { + c.close(); + } catch (IOException e) { + // When javac uses JDK 7 as a baseline, this code would be + // better written to set any/all exceptions from all the + // Closeables as suppressed exceptions on the FatalError + // that is thrown. + JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close"); + throw new FatalError(msg, e); + } + } } } @@ -1615,6 +1632,8 @@ keepComments = prev.keepComments; start_msec = prev.start_msec; hasBeenUsed = true; + closeables = prev.closeables; + prev.closeables = List.nil(); } public static void enableLogging() {
--- a/src/share/classes/com/sun/tools/javac/main/Main.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Tue Feb 14 10:29:36 2012 -0800 @@ -31,7 +31,10 @@ import java.net.URL; import java.security.DigestInputStream; import java.security.MessageDigest; +import java.util.Collection; +import java.util.LinkedHashSet; import java.util.MissingResourceException; +import java.util.Set; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.annotation.processing.Processor; @@ -73,12 +76,23 @@ /** Result codes. */ - static final int - EXIT_OK = 0, // Compilation completed with no errors. - EXIT_ERROR = 1, // Completed but reported errors. - EXIT_CMDERR = 2, // Bad command-line arguments - EXIT_SYSERR = 3, // System error or resource exhaustion. - EXIT_ABNORMAL = 4; // Compiler terminated abnormally + public enum Result { + OK(0), // Compilation completed with no errors. + ERROR(1), // Completed but reported errors. + CMDERR(2), // Bad command-line arguments + SYSERR(3), // System error or resource exhaustion. + ABNORMAL(4); // Compiler terminated abnormally + + Result(int exitCode) { + this.exitCode = exitCode; + } + + public boolean isOK() { + return (exitCode == 0); + } + + public final int exitCode; + } private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() { @@ -107,8 +121,7 @@ } public void addFile(File f) { - if (!filenames.contains(f)) - filenames.append(f); + filenames.add(f); } public void addClassName(String s) { @@ -136,7 +149,7 @@ /** The list of source files to process */ - public ListBuffer<File> filenames = null; // XXX sb protected + public Set<File> filenames = null; // XXX sb protected /** List of class files names passed on the command line */ @@ -202,7 +215,7 @@ * in `options' table and return all source filenames. * @param flags The array of command line arguments. */ - public List<File> processArgs(String[] flags) { // XXX sb protected + public Collection<File> processArgs(String[] flags) { // XXX sb protected int ac = 0; while (ac < flags.length) { String flag = flags[ac]; @@ -294,7 +307,7 @@ showClass(showClass); } - return filenames.toList(); + return filenames; } // where private boolean checkDirectory(OptionName optName) { @@ -316,10 +329,10 @@ /** Programmatic interface for main function. * @param args The command line parameters. */ - public int compile(String[] args) { + public Result compile(String[] args) { Context context = new Context(); JavacFileManager.preRegister(context); // can't create it until Log has been set up - int result = compile(args, context); + Result result = compile(args, context); if (fileManager instanceof JavacFileManager) { // A fresh context was created above, so jfm must be a JavacFileManager ((JavacFileManager)fileManager).close(); @@ -327,14 +340,14 @@ return result; } - public int compile(String[] args, Context context) { + public Result compile(String[] args, Context context) { return compile(args, context, List.<JavaFileObject>nil(), null); } /** Programmatic interface for main function. * @param args The command line parameters. */ - public int compile(String[] args, + public Result compile(String[] args, Context context, List<JavaFileObject> fileObjects, Iterable<? extends Processor> processors) @@ -342,7 +355,7 @@ if (options == null) options = Options.instance(context); // creates a new one - filenames = new ListBuffer<File>(); + filenames = new LinkedHashSet<File>(); classnames = new ListBuffer<String>(); JavaCompiler comp = null; /* @@ -353,34 +366,34 @@ try { if (args.length == 0 && fileObjects.isEmpty()) { help(); - return EXIT_CMDERR; + return Result.CMDERR; } - List<File> files; + Collection<File> files; try { files = processArgs(CommandLine.parse(args)); if (files == null) { // null signals an error in options, abort - return EXIT_CMDERR; + return Result.CMDERR; } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { // it is allowed to compile nothing if just asking for help or version info if (options.isSet(HELP) || options.isSet(X) || options.isSet(VERSION) || options.isSet(FULLVERSION)) - return EXIT_OK; + return Result.OK; if (JavaCompiler.explicitAnnotationProcessingRequested(options)) { error("err.no.source.files.classes"); } else { error("err.no.source.files"); } - return EXIT_CMDERR; + return Result.CMDERR; } } catch (java.io.FileNotFoundException e) { Log.printLines(out, ownName + ": " + getLocalizedString("err.file.not.found", e.getMessage())); - return EXIT_SYSERR; + return Result.SYSERR; } boolean forceStdOut = options.isSet("stdout"); @@ -400,7 +413,7 @@ fileManager = context.get(JavaFileManager.class); comp = JavaCompiler.instance(context); - if (comp == null) return EXIT_SYSERR; + if (comp == null) return Result.SYSERR; Log log = Log.instance(context); @@ -421,32 +434,32 @@ if (log.expectDiagKeys != null) { if (log.expectDiagKeys.isEmpty()) { Log.printLines(log.noticeWriter, "all expected diagnostics found"); - return EXIT_OK; + return Result.OK; } else { Log.printLines(log.noticeWriter, "expected diagnostic keys not found: " + log.expectDiagKeys); - return EXIT_ERROR; + return Result.ERROR; } } if (comp.errorCount() != 0) - return EXIT_ERROR; + return Result.ERROR; } catch (IOException ex) { ioMessage(ex); - return EXIT_SYSERR; + return Result.SYSERR; } catch (OutOfMemoryError ex) { resourceMessage(ex); - return EXIT_SYSERR; + return Result.SYSERR; } catch (StackOverflowError ex) { resourceMessage(ex); - return EXIT_SYSERR; + return Result.SYSERR; } catch (FatalError ex) { feMessage(ex); - return EXIT_SYSERR; + return Result.SYSERR; } catch (AnnotationProcessingError ex) { if (apiMode) throw new RuntimeException(ex.getCause()); apMessage(ex); - return EXIT_SYSERR; + return Result.SYSERR; } catch (ClientCodeException ex) { // as specified by javax.tools.JavaCompiler#getTask // and javax.tools.JavaCompiler.CompilationTask#call @@ -460,7 +473,7 @@ if (comp == null || comp.errorCount() == 0 || options == null || options.isSet("dev")) bugMessage(ex); - return EXIT_ABNORMAL; + return Result.ABNORMAL; } finally { if (comp != null) { try { @@ -472,7 +485,7 @@ filenames = null; options = null; } - return EXIT_OK; + return Result.OK; } /** Print a message reporting an internal error.
--- a/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Tue Feb 14 10:29:36 2012 -0800 @@ -205,6 +205,7 @@ @Override public OutputStream openOutputStream() throws IOException { + fileManager.flushCache(this); ensureParentDirectoriesExist(); return Files.newOutputStream(path); } @@ -241,6 +242,7 @@ @Override public Writer openWriter() throws IOException { + fileManager.flushCache(this); ensureParentDirectoriesExist(); return new OutputStreamWriter(Files.newOutputStream(path), fileManager.getEncodingName()); }
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Feb 14 10:29:36 2012 -0800 @@ -27,15 +27,15 @@ import java.util.*; +import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; -import com.sun.tools.javac.code.*; +import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; -import static com.sun.tools.javac.util.ListBuffer.lb; -import com.sun.tools.javac.tree.JCTree.*; - +import static com.sun.tools.javac.util.ListBuffer.lb; import static com.sun.tools.javac.parser.Token.*; /** The parser maps a token sequence into an abstract syntax @@ -57,7 +57,7 @@ /** The scanner used for lexical analysis. */ - private Lexer S; + protected Lexer S; /** The factory to be used for abstract syntax tree construction. */ @@ -99,9 +99,9 @@ this.allowTWR = source.allowTryWithResources(); this.allowDiamond = source.allowDiamond(); this.allowMulticatch = source.allowMulticatch(); + this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true); this.keepDocComments = keepDocComments; - if (keepDocComments) - docComments = new HashMap<JCTree,String>(); + docComments = keepDocComments ? new HashMap<JCTree,String>() : null; this.keepLineMap = keepLineMap; this.errorTree = F.Erroneous(); } @@ -146,6 +146,10 @@ */ boolean allowTWR; + /** Switch: should we fold strings? + */ + boolean allowStringFolding; + /** Switch: should we keep docComments? */ boolean keepDocComments; @@ -250,26 +254,44 @@ } private JCErroneous syntaxError(int pos, String key, Token... args) { - return syntaxError(pos, null, key, args); + return syntaxError(pos, List.<JCTree>nil(), key, args); } private JCErroneous syntaxError(int pos, List<JCTree> errs, String key, Token... args) { setErrorEndPos(pos); - reportSyntaxError(pos, key, (Object[])args); - return toP(F.at(pos).Erroneous(errs)); + JCErroneous err = F.at(pos).Erroneous(errs); + reportSyntaxError(err, key, (Object[])args); + if (errs != null) { + JCTree last = errs.last(); + if (last != null) + storeEnd(last, pos); + } + return toP(err); } private int errorPos = Position.NOPOS; + /** - * Report a syntax error at given position using the given - * argument unless one was already reported at the same position. + * Report a syntax using the given the position parameter and arguments, + * unless one was already reported at the same position. */ private void reportSyntaxError(int pos, String key, Object... args) { + JCDiagnostic.DiagnosticPosition diag = new JCDiagnostic.SimpleDiagnosticPosition(pos); + reportSyntaxError(diag, key, args); + } + + /** + * Report a syntax error using the given DiagnosticPosition object and + * arguments, unless one was already reported at the same position. + */ + private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) { + int pos = diagPos.getPreferredPosition(); if (pos > S.errPos() || pos == Position.NOPOS) { - if (S.token() == EOF) - error(pos, "premature.eof"); - else - error(pos, key, args); + if (S.token() == EOF) { + error(diagPos, "premature.eof"); + } else { + error(diagPos, key, args); + } } S.errPos(pos); if (S.pos() == errorPos) @@ -307,7 +329,7 @@ /** Report an illegal start of expression/type error at given position. */ JCExpression illegal(int pos) { - setErrorEndPos(S.pos()); + setErrorEndPos(pos); if ((mode & EXPR) != 0) return syntaxError(pos, "illegal.start.of.expr"); else @@ -336,7 +358,7 @@ * indexed by the tree nodes they refer to. * defined only if option flag keepDocComment is set. */ - Map<JCTree, String> docComments; + private final Map<JCTree, String> docComments; /** Make an entry into docComments hashtable, * provided flag keepDocComments is set and given doc comment is non-null. @@ -458,6 +480,10 @@ return t; } + JCExpression literal(Name prefix) { + return literal(prefix, S.pos()); + } + /** * Literal = * INTLITERAL @@ -470,8 +496,7 @@ * | FALSE * | NULL */ - JCExpression literal(Name prefix) { - int pos = S.pos(); + JCExpression literal(Name prefix, int pos) { JCExpression t = errorTree; switch (S.token()) { case INTLITERAL: @@ -757,6 +782,8 @@ * by a single literal representing the concatenated string. */ protected StringBuffer foldStrings(JCTree tree) { + if (!allowStringFolding) + return null; List<String> buf = List.nil(); while (true) { if (tree.getTag() == JCTree.LITERAL) { @@ -863,7 +890,7 @@ (S.token() == INTLITERAL || S.token() == LONGLITERAL) && S.radix() == 10) { mode = EXPR; - t = literal(names.hyphen); + t = literal(names.hyphen, pos); } else { t = term3(); return F.at(pos).Unary(unoptag(token), t); @@ -1261,15 +1288,17 @@ case GTGT: S.token(GT); break; + case GT: + S.nextToken(); + break; default: - accept(GT); + args.append(syntaxError(S.pos(), "expected", GT)); break; } return args.toList(); } } else { - syntaxError(S.pos(), "expected", LT); - return List.nil(); + return List.<JCExpression>of(syntaxError(S.pos(), "expected", LT)); } } @@ -1294,12 +1323,12 @@ return F.at(pos).Wildcard(t, bound); } else if (S.token() == IDENTIFIER) { //error recovery - reportSyntaxError(S.prevEndPos(), "expected3", - GT, EXTENDS, SUPER); TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND); JCExpression wc = toP(F.at(pos).Wildcard(t, null)); JCIdent id = toP(F.at(S.pos()).Ident(ident())); - return F.at(pos).Erroneous(List.<JCTree>of(wc, id)); + JCErroneous err = F.at(pos).Erroneous(List.<JCTree>of(wc, id)); + reportSyntaxError(err, "expected3", GT, EXTENDS, SUPER); + return err; } else { TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND)); return toP(F.at(pos).Wildcard(t, null)); @@ -1375,20 +1404,23 @@ int oldmode = mode; mode = TYPE; boolean diamondFound = false; + int lastTypeargsPos = -1; if (S.token() == LT) { checkGenerics(); + lastTypeargsPos = S.pos(); t = typeArguments(t, true); diamondFound = (mode & DIAMOND) != 0; } while (S.token() == DOT) { if (diamondFound) { //cannot select after a diamond - illegal(S.pos()); + illegal(); } int pos = S.pos(); S.nextToken(); t = toP(F.at(pos).Select(t, ident())); if (S.token() == LT) { + lastTypeargsPos = S.pos(); checkGenerics(); t = typeArguments(t, true); diamondFound = (mode & DIAMOND) != 0; @@ -1397,7 +1429,11 @@ mode = oldmode; if (S.token() == LBRACKET) { JCExpression e = arrayCreatorRest(newpos, t); - if (typeArgs != null) { + if (diamondFound) { + reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond"); + return toP(F.at(newpos).Erroneous(List.of(e))); + } + else if (typeArgs != null) { int pos = newpos; if (!typeArgs.isEmpty() && typeArgs.head.pos != Position.NOPOS) { // note: this should always happen but we should @@ -1406,15 +1442,16 @@ pos = typeArgs.head.pos; } setErrorEndPos(S.prevEndPos()); - reportSyntaxError(pos, "cannot.create.array.with.type.arguments"); - return toP(F.at(newpos).Erroneous(typeArgs.prepend(e))); + JCErroneous err = F.at(pos).Erroneous(typeArgs.prepend(e)); + reportSyntaxError(err, "cannot.create.array.with.type.arguments"); + return toP(err); } return e; } else if (S.token() == LPAREN) { return classCreatorRest(newpos, null, typeArgs, t); } else { - reportSyntaxError(S.pos(), "expected2", - LPAREN, LBRACKET); + setErrorEndPos(S.pos()); + reportSyntaxError(S.pos(), "expected2", LPAREN, LBRACKET); t = toP(F.at(newpos).NewClass(null, typeArgs, t, List.<JCExpression>nil(), null)); return toP(F.at(newpos).Erroneous(List.<JCTree>of(t))); } @@ -1444,7 +1481,8 @@ if (S.token() == LBRACE) { return arrayInitializer(newpos, elemtype); } else { - return syntaxError(S.pos(), "array.dimension.missing"); + JCExpression t = toP(F.at(newpos).NewArray(elemtype, List.<JCExpression>nil(), null)); + return syntaxError(S.pos(), List.<JCTree>of(t), "array.dimension.missing"); } } else { ListBuffer<JCExpression> dims = new ListBuffer<JCExpression>(); @@ -1830,7 +1868,7 @@ /** CatchClause = CATCH "(" FormalParameter ")" Block */ - JCCatch catchClause() { + protected JCCatch catchClause() { int pos = S.pos(); accept(CATCH); accept(LPAREN); @@ -1960,7 +1998,7 @@ JCModifiers modifiersOpt() { return modifiersOpt(null); } - JCModifiers modifiersOpt(JCModifiers partial) { + protected JCModifiers modifiersOpt(JCModifiers partial) { long flags; ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>(); int pos; @@ -1993,6 +2031,7 @@ case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break; case STRICTFP : flag = Flags.STRICTFP; break; case MONKEYS_AT : flag = Flags.ANNOTATION; break; + case ERROR : flag = 0; S.nextToken(); break; default: break loop; } if ((flags & flag) != 0) error(S.pos(), "repeated.modifier"); @@ -2206,9 +2245,12 @@ /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression */ - JCTree resource() { - return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL), - parseType(), ident(), true, null); + protected JCTree resource() { + JCModifiers optFinal = optFinal(Flags.FINAL); + JCExpression type = parseType(); + int pos = S.pos(); + Name ident = ident(); + return variableDeclaratorRest(pos, optFinal, type, ident, true, null); } /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration} @@ -2555,7 +2597,7 @@ * | ModifiersOpt Type Ident * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) */ - List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { + protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { if (S.token() == SEMI) { S.nextToken(); return List.<JCTree>nil(); @@ -2757,7 +2799,7 @@ /** FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId * LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter */ - JCVariableDecl formalParameter() { + protected JCVariableDecl formalParameter() { JCModifiers mods = optFinal(Flags.PARAMETER); JCExpression type = parseType(); if (S.token() == ELLIPSIS) { @@ -2775,6 +2817,10 @@ log.error(DiagnosticFlag.SYNTAX, pos, key, args); } + void error(DiagnosticPosition pos, String key, Object ... args) { + log.error(DiagnosticFlag.SYNTAX, pos, key, args); + } + void warning(int pos, String key, Object ... args) { log.warning(pos, key, args); } @@ -2794,8 +2840,9 @@ case JCTree.ERRONEOUS: return t; default: - error(t.pos, "not.stmt"); - return F.at(t.pos).Erroneous(List.<JCTree>of(t)); + JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t)); + error(ret, "not.stmt"); + return ret; } }
--- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Tue Feb 14 10:29:36 2012 -0800 @@ -982,8 +982,16 @@ } /** Sets the current token. + * This method is primarily used to update the token stream when the + * parser is handling the end of nested type arguments such as + * {@code List<List<String>>} and needs to disambiguate between + * repeated use of ">" and relation operators such as ">>" and ">>>". Noting + * that this does not handle arbitrary tokens containing Unicode escape + * sequences. */ public void token(Token token) { + pos += this.token.name.length() - token.name.length(); + prevEndPos = pos; this.token = token; }
--- a/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -455,9 +455,24 @@ // TODO: Only support reading resources in selected output // locations? Only allow reading of non-source, non-class // files from the supported input locations? - FileObject fileObject = fileManager.getFileForInput(location, + + // In the following, getFileForInput is the "obvious" method + // to use, but it does not have the "obvious" semantics for + // SOURCE_OUTPUT and CLASS_OUTPUT. Conversely, getFileForOutput + // does not have the correct semantics for any "path" location + // with more than one component. So, for now, we use a hybrid + // invocation. + FileObject fileObject; + if (location.isOutputLocation()) { + fileObject = fileManager.getFileForOutput(location, + pkg.toString(), + relativeName.toString(), + null); + } else { + fileObject = fileManager.getFileForInput(location, pkg.toString(), relativeName.toString()); + } if (fileObject == null) { String name = (pkg.length() == 0) ? relativeName.toString() : (pkg + "/" + relativeName);
--- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Feb 14 10:29:36 2012 -0800 @@ -225,6 +225,11 @@ ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH) : fileManager.getClassLoader(CLASS_PATH); + if (processorClassLoader != null && processorClassLoader instanceof Closeable) { + JavaCompiler compiler = JavaCompiler.instance(context); + compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader); + } + /* * If the "-processor" option is used, search the appropriate * path for the named class. Otherwise, use a service @@ -720,7 +725,7 @@ * Leave class public for external testing purposes. */ public static class ComputeAnnotationSet extends - ElementScanner7<Set<TypeElement>, Set<TypeElement>> { + ElementScanner8<Set<TypeElement>, Set<TypeElement>> { final Elements elements; public ComputeAnnotationSet(Elements elements) { @@ -1211,14 +1216,6 @@ if (discoveredProcs != null) // Make calling close idempotent discoveredProcs.close(); discoveredProcs = null; - if (processorClassLoader != null && processorClassLoader instanceof Closeable) { - try { - ((Closeable) processorClassLoader).close(); - } catch (IOException e) { - JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader"); - throw new FatalError(msg, e); - } - } } private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
--- a/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -125,7 +125,7 @@ else throw new AssertionError("Bad implementation type for " + tm); - ElementScanner7<Set<Element>, DeclaredType> scanner = + ElementScanner8<Set<Element>, DeclaredType> scanner = new AnnotationSetScanner(result, typeUtil); for (Element element : rootElements) @@ -136,7 +136,7 @@ // Could be written as a local class inside getElementsAnnotatedWith private class AnnotationSetScanner extends - ElementScanner7<Set<Element>, DeclaredType> { + ElementScanner8<Set<Element>, DeclaredType> { // Insertion-order preserving set Set<Element> annotatedElements = new LinkedHashSet<Element>(); Types typeUtil;
--- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Tue Feb 14 10:29:36 2012 -0800 @@ -82,7 +82,7 @@ * Used for the -Xprint option and called by Elements.printElements */ public static class PrintingElementVisitor - extends SimpleElementVisitor7<PrintingElementVisitor, Boolean> { + extends SimpleElementVisitor8<PrintingElementVisitor, Boolean> { int indentation; // Indentation level; final PrintWriter writer; final Elements elementUtils;
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Feb 14 10:29:36 2012 -0800 @@ -68,9 +68,13 @@ compiler.err.already.annotated=\ {0} {1} has already been annotated -# 0: symbol, 1: symbol +# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol compiler.err.already.defined=\ - {0} is already defined in {1} + {0} {1} is already defined in {2} {3} + +# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol kind, 4: symbol +compiler.err.already.defined.in.clinit=\ + {0} {1} is already defined in {2} of {3} {4} # 0: string compiler.err.already.defined.single.import=\ @@ -462,6 +466,9 @@ compiler.err.cannot.create.array.with.type.arguments=\ cannot create array with type arguments +compiler.err.cannot.create.array.with.diamond=\ + cannot create array with ''<>'' + # # limits. We don't give the limits in the diagnostic because we expect # them to change, yet we want to use the same diagnostic. These are all @@ -888,8 +895,8 @@ compiler.misc.fatal.err.cant.locate.ctor=\ Fatal Error: Unable to find constructor for {0} -compiler.misc.fatal.err.cant.close.loader=\ - Fatal Error: Cannot close class loader for annotation processors +compiler.misc.fatal.err.cant.close=\ + Fatal Error: Cannot close compiler resources ##### @@ -1595,6 +1602,10 @@ compiler.misc.no.unique.minimal.instance.exists=\ no unique minimal instance exists for type variable {0} with lower bounds {1} +# 0: type, 1: list of type +compiler.misc.incompatible.upper.bounds=\ + inference variable {0} has incompatible upper bounds {1} + # 0: list of type, 1: type, 2: type compiler.misc.infer.no.conforming.instance.exists=\ no instance(s) of type variable(s) {0} exist so that {1} conforms to {2} @@ -1750,6 +1761,12 @@ compiler.misc.kindname.package=\ package +compiler.misc.kindname.static.init=\ + static initializer + +compiler.misc.kindname.instance.init=\ + instance initializer + ##### compiler.misc.no.args=\
--- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Tue Feb 14 10:29:36 2012 -0800 @@ -436,7 +436,6 @@ public PackageSymbol packge; public ImportScope namedImportScope; public StarImportScope starImportScope; - public long flags; public Position.LineMap lineMap = null; public Map<JCTree, String> docComments = null; public Map<JCTree, Integer> endPositions = null; @@ -1176,6 +1175,21 @@ public int getTag() { return EXEC; } + + /** Convert a expression-statement tree to a pretty-printed string. */ + @Override + public String toString() { + StringWriter s = new StringWriter(); + try { + new Pretty(s, false).printStat(this); + } + catch (IOException e) { + // should never happen, because StringWriter is defined + // never to throw any IOExceptions + throw new AssertionError(e); + } + return s.toString(); + } } /**
--- a/src/share/classes/com/sun/tools/javac/util/AbstractLog.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractLog.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 @@ -96,6 +96,19 @@ /** Report an error, unless another error was already reported at same * source position. + * @param flag A flag to set on the diagnostic + * @param pos The source position at which to report the error. + * @param key The key for the localized error message. + * @param args Fields of the error message. + */ + public void error(DiagnosticFlag flag, DiagnosticPosition pos, String key, Object ... args) { + JCDiagnostic d = diags.error(source, pos, key, args); + d.setFlag(flag); + report(d); + } + + /** Report an error, unless another error was already reported at same + * source position. * @param pos The source position at which to report the error. * @param key The key for the localized error message. * @param args Fields of the error message.
--- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, 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 @@ -322,16 +322,46 @@ // <editor-fold defaultstate="collapsed" desc="Content cache"> public CharBuffer getCachedContent(JavaFileObject file) { - SoftReference<CharBuffer> r = contentCache.get(file); - return (r == null ? null : r.get()); + ContentCacheEntry e = contentCache.get(file); + if (e == null) + return null; + + if (!e.isValid(file)) { + contentCache.remove(file); + return null; + } + + return e.getValue(); } public void cache(JavaFileObject file, CharBuffer cb) { - contentCache.put(file, new SoftReference<CharBuffer>(cb)); + contentCache.put(file, new ContentCacheEntry(file, cb)); + } + + public void flushCache(JavaFileObject file) { + contentCache.remove(file); } - protected final Map<JavaFileObject, SoftReference<CharBuffer>> contentCache - = new HashMap<JavaFileObject, SoftReference<CharBuffer>>(); + protected final Map<JavaFileObject, ContentCacheEntry> contentCache + = new HashMap<JavaFileObject, ContentCacheEntry>(); + + protected static class ContentCacheEntry { + final long timestamp; + final SoftReference<CharBuffer> ref; + + ContentCacheEntry(JavaFileObject file, CharBuffer cb) { + this.timestamp = file.getLastModified(); + this.ref = new SoftReference<CharBuffer>(cb); + } + + boolean isValid(JavaFileObject file) { + return timestamp == file.getLastModified(); + } + + CharBuffer getValue() { + return ref.get(); + } + } // </editor-fold> public static Kind getKind(String name) {
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Feb 14 10:29:36 2012 -0800 @@ -412,7 +412,7 @@ @Override public String visitMethodSymbol(MethodSymbol s, Locale locale) { String ownerName = visit(s.owner, locale); - if ((s.flags() & BLOCK) != 0) { + if (s.isStaticOrInstanceInit()) { return ownerName; } else { String ms = (s.name == s.name.table.names.init)
--- a/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -46,11 +46,11 @@ public class AnnotationTypeDocImpl extends ClassDocImpl implements AnnotationTypeDoc { - AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { + public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { this(env, sym, null, null, null); } - AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, + public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, String doc, JCClassDecl tree, Position.LineMap lineMap) { super(env, sym, doc, tree, lineMap); }
--- a/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -45,11 +45,11 @@ public class AnnotationTypeElementDocImpl extends MethodDocImpl implements AnnotationTypeElementDoc { - AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym) { + public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym) { super(env, sym); } - AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, + public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, String doc, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, doc, tree, lineMap); }
--- a/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -744,17 +744,16 @@ // search inner classes //### Add private entry point to avoid creating array? //### Replicate code in innerClasses here to avoid consing? - ClassDoc innerClasses[] = innerClasses(); - for (int i = 0; i < innerClasses.length; i++) { - if (innerClasses[i].name().equals(className) || - //### This is from original javadoc but it looks suspicious to me... - //### I believe it is attempting to compensate for the confused - //### convention of including the nested class qualifiers in the - //### 'name' of the inner class, rather than the true simple name. - innerClasses[i].name().endsWith(className)) { - return innerClasses[i]; + for (ClassDoc icd : innerClasses()) { + if (icd.name().equals(className) || + //### This is from original javadoc but it looks suspicious to me... + //### I believe it is attempting to compensate for the confused + //### convention of including the nested class qualifiers in the + //### 'name' of the inner class, rather than the true simple name. + icd.name().endsWith("." + className)) { + return icd; } else { - ClassDoc innercd = ((ClassDocImpl) innerClasses[i]).searchClass(className); + ClassDoc innercd = ((ClassDocImpl) icd).searchClass(className); if (innercd != null) { return innercd; }
--- a/src/share/classes/com/sun/tools/javadoc/Comment.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/Comment.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -25,10 +25,7 @@ package com.sun.tools.javadoc; -import java.util.Locale; - import com.sun.javadoc.*; - import com.sun.tools.javac.util.ListBuffer; /** @@ -115,7 +112,7 @@ state = TAG_NAME; } break; - }; + } if (ch == '\n') { newLine = true; } else if (!isWhite) { @@ -134,7 +131,7 @@ case IN_TEXT: parseCommentComponent(tagName, textStart, lastNonWhite+1); break; - }; + } } /** @@ -396,16 +393,15 @@ * else * return -1. */ - private static int inlineTagFound(DocImpl holder, String inlinetext, int start) { + private static int inlineTagFound(DocImpl holder, String inlinetext, int start) { DocEnv docenv = holder.env; - int linkstart; - if (start == inlinetext.length() || - (linkstart = inlinetext.indexOf("{@", start)) == -1) { + int linkstart = inlinetext.indexOf("{@", start); + if (start == inlinetext.length() || linkstart == -1) { return -1; - } else if(inlinetext.indexOf('}', start) == -1) { + } else if (inlinetext.indexOf('}', linkstart) == -1) { //Missing '}'. docenv.warning(holder, "tag.Improper_Use_Of_Link_Tag", - inlinetext.substring(linkstart, inlinetext.length())); + inlinetext.substring(linkstart, inlinetext.length())); return -1; } else { return linkstart; @@ -425,6 +421,7 @@ /** * Return text for this Doc comment. */ + @Override public String toString() { return text; }
--- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -84,7 +84,7 @@ final Symbol externalizableSym; /** Access filter (public, protected, ...). */ - ModifierFilter showAccess; + protected ModifierFilter showAccess; /** True if we are using a sentence BreakIterator. */ boolean breakiterator; @@ -102,7 +102,7 @@ boolean docClasses = false; /** Does the doclet only expect pre-1.5 doclet API? */ - boolean legacyDoclet = true; + protected boolean legacyDoclet = true; /** * Set this to true if you would like to not emit any errors, warnings and @@ -115,7 +115,7 @@ * * @param context Context for this javadoc instance. */ - private DocEnv(Context context) { + protected DocEnv(Context context) { context.put(docEnvKey, this); messager = Messager.instance0(context); @@ -517,7 +517,7 @@ messager.exit(); } - private Map<PackageSymbol, PackageDocImpl> packageMap = + protected Map<PackageSymbol, PackageDocImpl> packageMap = new HashMap<PackageSymbol, PackageDocImpl>(); /** * Return the PackageDoc of this package symbol. @@ -545,12 +545,12 @@ } - private Map<ClassSymbol, ClassDocImpl> classMap = + protected Map<ClassSymbol, ClassDocImpl> classMap = new HashMap<ClassSymbol, ClassDocImpl>(); /** * Return the ClassDoc (or a subtype) of this class symbol. */ - ClassDocImpl getClassDoc(ClassSymbol clazz) { + public ClassDocImpl getClassDoc(ClassSymbol clazz) { ClassDocImpl result = classMap.get(clazz); if (result != null) return result; if (isAnnotationType(clazz)) { @@ -565,7 +565,7 @@ /** * Create the ClassDoc (or a subtype) for a class symbol. */ - void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) { + protected void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) { ClassDocImpl result = classMap.get(clazz); if (result != null) { if (docComment != null) result.setRawCommentText(docComment); @@ -580,20 +580,20 @@ classMap.put(clazz, result); } - private static boolean isAnnotationType(ClassSymbol clazz) { + protected static boolean isAnnotationType(ClassSymbol clazz) { return ClassDocImpl.isAnnotationType(clazz); } - private static boolean isAnnotationType(JCClassDecl tree) { + protected static boolean isAnnotationType(JCClassDecl tree) { return (tree.mods.flags & Flags.ANNOTATION) != 0; } - private Map<VarSymbol, FieldDocImpl> fieldMap = + protected Map<VarSymbol, FieldDocImpl> fieldMap = new HashMap<VarSymbol, FieldDocImpl>(); /** * Return the FieldDoc of this var symbol. */ - FieldDocImpl getFieldDoc(VarSymbol var) { + public FieldDocImpl getFieldDoc(VarSymbol var) { FieldDocImpl result = fieldMap.get(var); if (result != null) return result; result = new FieldDocImpl(this, var); @@ -603,7 +603,7 @@ /** * Create a FieldDoc for a var symbol. */ - void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) { + protected void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) { FieldDocImpl result = fieldMap.get(var); if (result != null) { if (docComment != null) result.setRawCommentText(docComment); @@ -614,13 +614,13 @@ } } - private Map<MethodSymbol, ExecutableMemberDocImpl> methodMap = + protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap = new HashMap<MethodSymbol, ExecutableMemberDocImpl>(); /** * Create a MethodDoc for this MethodSymbol. * Should be called only on symbols representing methods. */ - void makeMethodDoc(MethodSymbol meth, String docComment, + protected void makeMethodDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); if (result != null) { @@ -649,7 +649,7 @@ * Create the ConstructorDoc for a MethodSymbol. * Should be called only on symbols representing constructors. */ - void makeConstructorDoc(MethodSymbol meth, String docComment, + protected void makeConstructorDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); if (result != null) { @@ -678,7 +678,7 @@ * Create the AnnotationTypeElementDoc for a MethodSymbol. * Should be called only on symbols representing annotation type elements. */ - void makeAnnotationTypeElementDoc(MethodSymbol meth, + protected void makeAnnotationTypeElementDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { AnnotationTypeElementDocImpl result = (AnnotationTypeElementDocImpl)methodMap.get(meth);
--- a/src/share/classes/com/sun/tools/javadoc/DocImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/DocImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -92,7 +92,7 @@ * So subclasses have the option to do lazy initialization of * "documentation" string. */ - String documentation() { + protected String documentation() { if (documentation == null) documentation = ""; return documentation; }
--- a/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java Tue Feb 14 10:29:36 2012 -0800 @@ -35,7 +35,7 @@ /** Javadoc uses an extended class reader that records package.html entries * @author Neal Gafter */ -class JavadocClassReader extends ClassReader { +public class JavadocClassReader extends ClassReader { public static JavadocClassReader instance0(Context context) { ClassReader instance = context.get(classReaderKey); @@ -59,7 +59,7 @@ private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.HTML); - private JavadocClassReader(Context context) { + public JavadocClassReader(Context context) { super(context, true); docenv = DocEnv.instance(context); preferSource = true;
--- a/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Tue Feb 14 10:29:36 2012 -0800 @@ -31,7 +31,6 @@ import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.comp.Enter; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; import javax.tools.JavaFileObject; @@ -65,6 +64,7 @@ final Messager messager; final DocEnv docenv; + @Override public void main(List<JCCompilationUnit> trees) { // count all Enter errors as warnings. int nerrors = messager.nerrors; @@ -73,6 +73,7 @@ messager.nerrors = nerrors; } + @Override public void visitTopLevel(JCCompilationUnit tree) { super.visitTopLevel(tree); if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { @@ -81,10 +82,11 @@ } } + @Override public void visitClassDef(JCClassDecl tree) { super.visitClassDef(tree); - if (tree.sym != null && tree.sym.kind == Kinds.TYP) { - if (tree.sym == null) return; + if (tree.sym == null) return; + if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) { String comment = env.toplevel.docComments.get(tree); ClassSymbol c = tree.sym; docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap); @@ -92,6 +94,7 @@ } /** Don't complain about a duplicate class. */ + @Override protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {} }
--- a/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Tue Feb 14 10:29:36 2012 -0800 @@ -38,7 +38,7 @@ * done by javac. * @author Neal Gafter */ -class JavadocMemberEnter extends MemberEnter { +public class JavadocMemberEnter extends MemberEnter { public static JavadocMemberEnter instance0(Context context) { MemberEnter instance = context.get(memberEnterKey); if (instance == null)
--- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 @@ -257,24 +257,15 @@ for (String p: excludedPackages) includedPackages.put(p, false); - if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { - searchSubPackages(subPackages, - includedPackages, - packages, packageFiles, - StandardLocation.SOURCE_PATH, - EnumSet.of(JavaFileObject.Kind.SOURCE)); - searchSubPackages(subPackages, - includedPackages, - packages, packageFiles, - StandardLocation.CLASS_PATH, - EnumSet.of(JavaFileObject.Kind.CLASS)); - } else { - searchSubPackages(subPackages, - includedPackages, - packages, packageFiles, - StandardLocation.CLASS_PATH, - EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS)); - } + StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) + ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; + + searchSubPackages(subPackages, + includedPackages, + packages, packageFiles, + path, + EnumSet.of(JavaFileObject.Kind.SOURCE)); + return packageFiles; }
--- a/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -96,7 +96,7 @@ /** * Do lazy initialization of "documentation" string. */ - String documentation() { + protected String documentation() { if (documentation != null) return documentation; if (docPath != null) {
--- a/src/share/classes/com/sun/tools/javadoc/ParamTagImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/ParamTagImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -44,6 +44,11 @@ private final String parameterComment; private final boolean isTypeParameter; + /** + * Cached inline tags. + */ + private Tag[] inlineTags; + ParamTagImpl(DocImpl holder, String name, String text) { super(holder, name, text); String[] sa = divideAtWhite(); @@ -71,6 +76,7 @@ /** * Return the kind of this tag. */ + @Override public String kind() { return "@param"; } @@ -85,6 +91,7 @@ /** * convert this object to a string. */ + @Override public String toString() { return name + ":" + text; } @@ -97,7 +104,11 @@ * @see TagImpl#inlineTagImpls() * @see ThrowsTagImpl#inlineTagImpls() */ + @Override public Tag[] inlineTags() { - return Comment.getInlineTags(holder, parameterComment); + if (inlineTags == null) { + inlineTags = Comment.getInlineTags(holder, parameterComment); + } + return inlineTags; } }
--- a/src/share/classes/com/sun/tools/javadoc/SerialFieldTagImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/SerialFieldTagImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 @@ -80,6 +80,9 @@ */ private void parseSerialFieldString() { int len = text.length(); + if (len == 0) { + return; + } // if no white space found /* Skip white space. */
--- a/src/share/classes/com/sun/tools/javadoc/ThrowsTagImpl.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/ThrowsTagImpl.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -43,6 +43,11 @@ private final String exceptionName; private final String exceptionComment; + /** + * Cached inline tags. + */ + private Tag[] inlineTags; + ThrowsTagImpl(DocImpl holder, String name, String text) { super(holder, name, text); String[] sa = divideAtWhite(); @@ -93,6 +98,7 @@ * Return the kind of this tag. Always "@throws" for instances * of ThrowsTagImpl. */ + @Override public String kind() { return "@throws"; } @@ -105,7 +111,11 @@ * @see TagImpl#inlineTagImpls() * @see ParamTagImpl#inlineTagImpls() */ + @Override public Tag[] inlineTags() { - return Comment.getInlineTags(holder, exceptionComment()); + if (inlineTags == null) { + inlineTags = Comment.getInlineTags(holder, exceptionComment()); + } + return inlineTags; } }
--- a/src/share/classes/com/sun/tools/javah/JavahTask.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javah/JavahTask.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -60,7 +60,7 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVisitor; import javax.lang.model.util.ElementFilter; -import javax.lang.model.util.SimpleTypeVisitor7; +import javax.lang.model.util.SimpleTypeVisitor8; import javax.lang.model.util.Types; import javax.tools.Diagnostic; @@ -753,7 +753,7 @@ } private TypeVisitor<Void,Types> checkMethodParametersVisitor = - new SimpleTypeVisitor7<Void,Types>() { + new SimpleTypeVisitor8<Void,Types>() { @Override public Void visitArray(ArrayType t, Types types) { visit(t.getComponentType(), types);
--- a/src/share/classes/com/sun/tools/javah/LLNI.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javah/LLNI.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -45,7 +45,7 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVisitor; import javax.lang.model.util.ElementFilter; -import javax.lang.model.util.SimpleTypeVisitor7; +import javax.lang.model.util.SimpleTypeVisitor8; /* * <p><b>This is NOT part of any supported API. @@ -628,7 +628,7 @@ } protected final boolean isLongOrDouble(TypeMirror t) { - TypeVisitor<Boolean,Void> v = new SimpleTypeVisitor7<Boolean,Void>() { + TypeVisitor<Boolean,Void> v = new SimpleTypeVisitor8<Boolean,Void>() { public Boolean defaultAction(TypeMirror t, Void p){ return false; }
--- a/src/share/classes/com/sun/tools/javah/TypeSignature.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/com/sun/tools/javah/TypeSignature.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -38,7 +38,7 @@ import javax.lang.model.type.TypeVariable; import javax.lang.model.type.TypeVisitor; import javax.lang.model.util.Elements; -import javax.lang.model.util.SimpleTypeVisitor7; +import javax.lang.model.util.SimpleTypeVisitor8; /** * Returns internal type signature. @@ -245,7 +245,7 @@ String qualifiedTypeName(TypeMirror type) { - TypeVisitor<Name, Void> v = new SimpleTypeVisitor7<Name, Void>() { + TypeVisitor<Name, Void> v = new SimpleTypeVisitor8<Name, Void>() { @Override public Name visitArray(ArrayType t, Void p) { return t.getComponentType().accept(this, p);
--- a/src/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -64,6 +64,7 @@ * @author Peter von der Ahé * * @see AbstractAnnotationValueVisitor7 + * @see AbstractAnnotationValueVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011 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 @@ -59,6 +59,7 @@ * @param <P> the type of the additional parameter to this visitor's methods. * * @see AbstractAnnotationValueVisitor6 + * @see AbstractAnnotationValueVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import java.util.List; +import javax.lang.model.element.*; + +import javax.lang.model.type.TypeMirror; +import static javax.lang.model.SourceVersion.*; +import javax.lang.model.SourceVersion; +import javax.annotation.processing.SupportedSourceVersion; + +/** + * A skeletal visitor for annotation values with default behavior + * appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8} + * source version. + * + * <p> <b>WARNING:</b> The {@code AnnotationValueVisitor} interface + * implemented by this class may have methods added to it in the + * future to accommodate new, currently unknown, language structures + * added to future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new abstract annotation + * value visitor class will also be introduced to correspond to the + * new language level; this visitor will have different default + * behavior for the visit method in question. When the new visitor is + * introduced, all or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods + * @param <P> the type of the additional parameter to this visitor's methods. + * + * @see AbstractAnnotationValueVisitor6 + * @see AbstractAnnotationValueVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public abstract class AbstractAnnotationValueVisitor8<R, P> extends AbstractAnnotationValueVisitor7<R, P> { + + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractAnnotationValueVisitor8() { + super(); + } +}
--- a/src/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -67,6 +67,7 @@ * @author Peter von der Ahé * * @see AbstractElementVisitor7 + * @see AbstractElementVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/AbstractElementVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractElementVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, 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 @@ -62,6 +62,7 @@ * additional parameter. * * @see AbstractElementVisitor6 + * @see AbstractElementVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/AbstractElementVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.element.*; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.element.*; +import static javax.lang.model.element.ElementKind.*; +import static javax.lang.model.SourceVersion.*; +import javax.lang.model.SourceVersion; + + +/** + * A skeletal visitor of program elements with default behavior + * appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8} + * source version. + * + * <p> <b>WARNING:</b> The {@code ElementVisitor} interface + * implemented by this class may have methods added to it in the + * future to accommodate new, currently unknown, language structures + * added to future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new abstract element visitor + * class will also be introduced to correspond to the new language + * level; this visitor will have different default behavior for the + * visit method in question. When the new visitor is introduced, all + * or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see AbstractElementVisitor6 + * @see AbstractElementVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public abstract class AbstractElementVisitor8<R, P> extends AbstractElementVisitor7<R, P> { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractElementVisitor8(){ + super(); + } +}
--- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -60,6 +60,7 @@ * @author Peter von der Ahé * * @see AbstractTypeVisitor7 + * @see AbstractTypeVisitor8 * @since 1.6 */ public abstract class AbstractTypeVisitor6<R, P> implements TypeVisitor<R, P> {
--- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -56,6 +56,7 @@ * additional parameter. * * @see AbstractTypeVisitor6 + * @see AbstractTypeVisitor8 * @since 1.7 */ public abstract class AbstractTypeVisitor7<R, P> extends AbstractTypeVisitor6<R, P> {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2011 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.type.*; + +/** + * A skeletal visitor of types with default behavior appropriate for + * the {@link javax.lang.model.SourceVersion#RELEASE_8 RELEASE_8} + * source version. + * + * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented + * by this class may have methods added to it in the future to + * accommodate new, currently unknown, language structures added to + * future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new abstract type visitor + * class will also be introduced to correspond to the new language + * level; this visitor will have different default behavior for the + * visit method in question. When the new visitor is introduced, all + * or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see AbstractTypeVisitor6 + * @see AbstractTypeVisitor7 + * @since 1.8 + */ +public abstract class AbstractTypeVisitor8<R, P> extends AbstractTypeVisitor7<R, P> { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractTypeVisitor8() { + super(); + } +}
--- a/src/share/classes/javax/lang/model/util/ElementKindVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/ElementKindVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -78,6 +78,7 @@ * @author Peter von der Ahé * * @see ElementKindVisitor7 + * @see ElementKindVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/ElementKindVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/ElementKindVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -73,6 +73,7 @@ * additional parameter. * * @see ElementKindVisitor6 + * @see ElementKindVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/ElementKindVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2011 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.element.*; +import static javax.lang.model.element.ElementKind.*; +import javax.annotation.processing.SupportedSourceVersion; +import static javax.lang.model.SourceVersion.*; +import javax.lang.model.SourceVersion; + +/** + * A visitor of program elements based on their {@linkplain + * ElementKind kind} with default behavior appropriate for the {@link + * SourceVersion#RELEASE_8 RELEASE_8} source version. For {@linkplain + * Element elements} <tt><i>XYZ</i></tt> that may have more than one + * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate + * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the + * first argument's kind. The <tt>visit<i>XYZKind</i></tt> methods + * call {@link #defaultAction defaultAction}, passing their arguments + * to {@code defaultAction}'s corresponding parameters. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code ElementVisitor} interface + * implemented by this class may have methods added to it or the + * {@code ElementKind} {@code enum} used in this case may have + * constants added to it in the future to accommodate new, currently + * unknown, language structures added to future versions of the + * Java™ programming language. Therefore, methods whose names + * begin with {@code "visit"} may be added to this class in the + * future; to avoid incompatibilities, classes which extend this class + * should not declare any instance methods with names beginning with + * {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new abstract element kind + * visitor class will also be introduced to correspond to the new + * language level; this visitor will have different default behavior + * for the visit method in question. When the new visitor is + * introduced, all or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see ElementKindVisitor6 + * @see ElementKindVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class ElementKindVisitor8<R, P> extends ElementKindVisitor7<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected ElementKindVisitor8() { + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected ElementKindVisitor8(R defaultValue) { + super(defaultValue); + } +}
--- a/src/share/classes/javax/lang/model/util/ElementScanner6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/ElementScanner6.java Tue Feb 14 10:29:36 2012 -0800 @@ -90,6 +90,7 @@ * @author Peter von der Ahé * * @see ElementScanner7 + * @see ElementScanner8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/ElementScanner7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/ElementScanner7.java Tue Feb 14 10:29:36 2012 -0800 @@ -86,6 +86,7 @@ * additional parameter. * * @see ElementScanner6 + * @see ElementScanner8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/ElementScanner8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.element.*; +import javax.annotation.processing.SupportedSourceVersion; +import static javax.lang.model.element.ElementKind.*; +import javax.lang.model.SourceVersion; +import static javax.lang.model.SourceVersion.*; + + +/** + * A scanning visitor of program elements with default behavior + * appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8} + * source version. The <tt>visit<i>XYZ</i></tt> methods in this + * class scan their component elements by calling {@code scan} on + * their {@linkplain Element#getEnclosedElements enclosed elements}, + * {@linkplain ExecutableElement#getParameters parameters}, etc., as + * indicated in the individual method specifications. A subclass can + * control the order elements are visited by overriding the + * <tt>visit<i>XYZ</i></tt> methods. Note that clients of a scanner + * may get the desired behavior be invoking {@code v.scan(e, p)} rather + * than {@code v.visit(e, p)} on the root objects of interest. + * + * <p>When a subclass overrides a <tt>visit<i>XYZ</i></tt> method, the + * new method can cause the enclosed elements to be scanned in the + * default way by calling <tt>super.visit<i>XYZ</i></tt>. In this + * fashion, the concrete visitor can control the ordering of traversal + * over the component elements with respect to the additional + * processing; for example, consistently calling + * <tt>super.visit<i>XYZ</i></tt> at the start of the overridden + * methods will yield a preorder traversal, etc. If the component + * elements should be traversed in some other order, instead of + * calling <tt>super.visit<i>XYZ</i></tt>, an overriding visit method + * should call {@code scan} with the elements in the desired order. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code ElementVisitor} interface + * implemented by this class may have methods added to it in the + * future to accommodate new, currently unknown, language structures + * added to future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new element scanner visitor + * class will also be introduced to correspond to the new language + * level; this visitor will have different default behavior for the + * visit method in question. When the new visitor is introduced, all + * or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see ElementScanner6 + * @see ElementScanner7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class ElementScanner8<R, P> extends ElementScanner7<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected ElementScanner8(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + */ + protected ElementScanner8(R defaultValue){ + super(defaultValue); + } +}
--- a/src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -71,6 +71,7 @@ * @author Peter von der Ahé * * @see SimpleAnnotationValueVisitor7 + * @see SimpleAnnotationValueVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -66,6 +66,7 @@ * @param <P> the type of the additional parameter to this visitor's methods. * * @see SimpleAnnotationValueVisitor6 + * @see SimpleAnnotationValueVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import java.util.List; +import javax.lang.model.element.*; + +import javax.lang.model.type.TypeMirror; +import static javax.lang.model.SourceVersion.*; +import javax.lang.model.SourceVersion; +import javax.annotation.processing.SupportedSourceVersion; + +/** + * A simple visitor for annotation values with default behavior + * appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8} + * source version. Visit methods call {@link #defaultAction + * defaultAction} passing their arguments to {@code defaultAction}'s + * corresponding parameters. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code AnnotationValueVisitor} interface + * implemented by this class may have methods added to it in the + * future to accommodate new, currently unknown, language structures + * added to future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new simple annotation + * value visitor class will also be introduced to correspond to the + * new language level; this visitor will have different default + * behavior for the visit method in question. When the new visitor is + * introduced, all or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods + * @param <P> the type of the additional parameter to this visitor's methods. + * + * @see SimpleAnnotationValueVisitor6 + * @see SimpleAnnotationValueVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class SimpleAnnotationValueVisitor8<R, P> extends SimpleAnnotationValueVisitor7<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleAnnotationValueVisitor8() { + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleAnnotationValueVisitor8(R defaultValue) { + super(defaultValue); + } +}
--- a/src/share/classes/javax/lang/model/util/SimpleElementVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleElementVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -76,6 +76,7 @@ * @author Peter von der Ahé * * @see SimpleElementVisitor7 + * @see SimpleElementVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/SimpleElementVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleElementVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -69,6 +69,7 @@ * for visitors that do not need an additional parameter. * * @see SimpleElementVisitor6 + * @see SimpleElementVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/SimpleElementVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.element.*; +import javax.annotation.processing.SupportedSourceVersion; +import static javax.lang.model.element.ElementKind.*; +import javax.lang.model.SourceVersion; +import static javax.lang.model.SourceVersion.*; + +/** + * A simple visitor of program elements with default behavior + * appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8} + * source version. + * + * Visit methods corresponding to {@code RELEASE_7} and earlier + * language constructs call {@link #defaultAction defaultAction}, + * passing their arguments to {@code defaultAction}'s corresponding + * parameters. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code ElementVisitor} interface + * implemented by this class may have methods added to it in the + * future to accommodate new, currently unknown, language structures + * added to future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new simple element visitor + * class will also be introduced to correspond to the new language + * level; this visitor will have different default behavior for the + * visit method in question. When the new visitor is introduced, all + * or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@code Void} + * for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's methods. Use {@code Void} + * for visitors that do not need an additional parameter. + * + * @see SimpleElementVisitor6 + * @see SimpleElementVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class SimpleElementVisitor8<R, P> extends SimpleElementVisitor7<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleElementVisitor8(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleElementVisitor8(R defaultValue){ + super(defaultValue); + } +}
--- a/src/share/classes/javax/lang/model/util/SimpleTypeVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleTypeVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -75,6 +75,7 @@ * @author Peter von der Ahé * * @see SimpleTypeVisitor7 + * @see SimpleTypeVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/SimpleTypeVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/SimpleTypeVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -68,6 +68,7 @@ * additional parameter. * * @see SimpleTypeVisitor6 + * @see SimpleTypeVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/SimpleTypeVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.type.*; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import static javax.lang.model.SourceVersion.*; + +/** + * A simple visitor of types with default behavior appropriate for the + * {@link SourceVersion#RELEASE_7 RELEASE_7} source version. + * + * Visit methods corresponding to {@code RELEASE_8} and earlier + * language constructs call {@link #defaultAction defaultAction}, + * passing their arguments to {@code defaultAction}'s corresponding + * parameters. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented + * by this class may have methods added to it in the future to + * accommodate new, currently unknown, language structures added to + * future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new simple type visitor + * class will also be introduced to correspond to the new language + * level; this visitor will have different default behavior for the + * visit method in question. When the new visitor is introduced, all + * or portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see SimpleTypeVisitor6 + * @see SimpleTypeVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class SimpleTypeVisitor8<R, P> extends SimpleTypeVisitor7<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleTypeVisitor8(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleTypeVisitor8(R defaultValue){ + super(defaultValue); + } +}
--- a/src/share/classes/javax/lang/model/util/TypeKindVisitor6.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/TypeKindVisitor6.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -76,6 +76,7 @@ * @author Peter von der Ahé * * @see TypeKindVisitor7 + * @see TypeKindVisitor8 * @since 1.6 */ @SupportedSourceVersion(RELEASE_6)
--- a/src/share/classes/javax/lang/model/util/TypeKindVisitor7.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/lang/model/util/TypeKindVisitor7.java Tue Feb 14 10:29:36 2012 -0800 @@ -71,6 +71,7 @@ * additional parameter. * * @see TypeKindVisitor6 + * @see TypeKindVisitor8 * @since 1.7 */ @SupportedSourceVersion(RELEASE_7)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/javax/lang/model/util/TypeKindVisitor8.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.lang.model.util; + +import javax.lang.model.type.*; +import javax.annotation.processing.SupportedSourceVersion; +import static javax.lang.model.element.ElementKind.*; +import static javax.lang.model.SourceVersion.*; +import javax.lang.model.SourceVersion; + +/** + * A visitor of types based on their {@linkplain TypeKind kind} with + * default behavior appropriate for the {@link SourceVersion#RELEASE_8 + * RELEASE_8} source version. For {@linkplain + * TypeMirror types} <tt><i>XYZ</i></tt> that may have more than one + * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate + * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the + * first argument's kind. The <tt>visit<i>XYZKind</i></tt> methods + * call {@link #defaultAction defaultAction}, passing their arguments + * to {@code defaultAction}'s corresponding parameters. + * + * <p> Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented + * by this class may have methods added to it in the future to + * accommodate new, currently unknown, language structures added to + * future versions of the Java™ programming language. + * Therefore, methods whose names begin with {@code "visit"} may be + * added to this class in the future; to avoid incompatibilities, + * classes which extend this class should not declare any instance + * methods with names beginning with {@code "visit"}. + * + * <p>When such a new visit method is added, the default + * implementation in this class will be to call the {@link + * #visitUnknown visitUnknown} method. A new type kind visitor class + * will also be introduced to correspond to the new language level; + * this visitor will have different default behavior for the visit + * method in question. When the new visitor is introduced, all or + * portions of this visitor may be deprecated. + * + * @param <R> the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param <P> the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see TypeKindVisitor6 + * @see TypeKindVisitor7 + * @since 1.8 + */ +@SupportedSourceVersion(RELEASE_8) +public class TypeKindVisitor8<R, P> extends TypeKindVisitor7<R, P> { + /** + * Constructor for concrete subclasses to call; uses {@code null} + * for the default value. + */ + protected TypeKindVisitor8() { + super(null); + } + + /** + * Constructor for concrete subclasses to call; uses the argument + * for the default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected TypeKindVisitor8(R defaultValue) { + super(defaultValue); + } +}
--- a/src/share/classes/javax/tools/JavaCompiler.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/classes/javax/tools/JavaCompiler.java Tue Feb 14 10:29:36 2012 -0800 @@ -26,10 +26,8 @@ package javax.tools; import java.io.File; -import java.io.InputStream; import java.io.Writer; import java.nio.charset.Charset; -import java.util.List; import java.util.Locale; import java.util.concurrent.Callable; import javax.annotation.processing.Processor;
--- a/src/share/sample/javac/processing/src/CheckNamesProcessor.java Tue Jul 19 11:05:57 2011 -0700 +++ b/src/share/sample/javac/processing/src/CheckNamesProcessor.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -138,7 +138,7 @@ public SourceVersion getSupportedSourceVersion() { /* * Return latest source version instead of a fixed version - * like RELEASE_7. To return a fixed version, this class + * like RELEASE_8. To return a fixed version, this class * could be annotated with a SupportedSourceVersion * annotation. * @@ -192,7 +192,7 @@ /** * Visitor to implement name checks. */ - private class NameCheckScanner extends ElementScanner7<Void, Void> { + private class NameCheckScanner extends ElementScanner8<Void, Void> { // The visitor could be enhanced to return true/false if // there were warnings reported or a count of the number // of warnings. This could be facilitated by using
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/T6735320/SerialFieldTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011, 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. + */ +import java.io.ObjectStreamField; +import java.io.Serializable; + +public class SerialFieldTest implements Serializable { + /** + * @serialField + */ + private static final ObjectStreamField[] serialPersistentFields = { + new ObjectStreamField("i", int.class), + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/T6735320/T6735320.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, 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 6735320 + * @summary javadoc throws exception if serialField value is missing + * @library ../lib/ + * @build JavadocTester T6735320 + * @run main T6735320 + */ +public class T6735320 extends JavadocTester { + + private static final String BUG_ID = "6735320"; + private static final String[] ARGS = new String[]{ + "-d", BUG_ID + ".out", + SRC_DIR + FS + "SerialFieldTest.java" + }; + + public String getBugId() { + return BUG_ID; + } + + public String getBugName() { + return getClass().getName(); + } + + public static void main(String... args) { + T6735320 tester = new T6735320(); + if (tester.runJavadoc(ARGS) != 0) { + throw new AssertionError("non-zero return code from javadoc"); + } + if (tester.getErrorOutput().contains("StringIndexOutOfBoundsException")) { + throw new AssertionError("javadoc threw StringIndexOutOfBoundsException"); + } + } +}
--- a/test/com/sun/javadoc/lib/JavadocTester.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/com/sun/javadoc/lib/JavadocTester.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -197,8 +197,13 @@ initOutputBuffers(); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - PrintStream prev = System.out; + PrintStream prevOut = System.out; System.setOut(new PrintStream(stdout)); + + ByteArrayOutputStream stderr = new ByteArrayOutputStream(); + PrintStream prevErr = System.err; + System.setErr(new PrintStream(stderr)); + int returnCode = com.sun.tools.javadoc.Main.execute( getBugName(), new PrintWriter(errors, true), @@ -207,8 +212,11 @@ docletClass, getClass().getClassLoader(), args); - System.setOut(prev); + System.setOut(prevOut); standardOut = new StringBuffer(stdout.toString()); + System.setErr(prevErr); + errors.write(NL + stderr.toString()); + printJavadocOutput(); return returnCode; }
--- a/test/com/sun/javadoc/testLinkTaglet/TestLinkTaglet.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/com/sun/javadoc/testLinkTaglet/TestLinkTaglet.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 @@ -23,9 +23,9 @@ /* * @test - * @bug 4732864 6280605 + * @bug 4732864 6280605 7064544 * @summary Make sure that you can link from one member to another using - * non-qualified name. + * non-qualified name, furthermore, ensure the right one is linked. * @author jamieh * @library ../lib/ * @build JavadocTester @@ -36,7 +36,7 @@ public class TestLinkTaglet extends JavadocTester { //Test information. - private static final String BUG_ID = "4732864-6280605"; + private static final String BUG_ID = "4732864-6280605-7064544"; //Javadoc arguments. private static final String[] ARGS = new String[] {
--- a/test/com/sun/javadoc/testLinkTaglet/pkg/C.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/com/sun/javadoc/testLinkTaglet/pkg/C.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 @@ -34,6 +34,11 @@ public class C { public InnerC MEMBER = new InnerC(); + /** + * A red herring inner class to confuse the matching, thus to + * ensure the right one is linked. + */ + public class RedHerringInnerC {} /** * Link to member in outer class: {@link #MEMBER} <br/>
--- a/test/tools/javac/6402516/CheckLocalElements.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/6402516/CheckLocalElements.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -95,7 +95,7 @@ return encl == null ? "" : encl.accept(qualNameVisitor, null); } - private ElementVisitor<String,Void> qualNameVisitor = new SimpleElementVisitor7<String,Void>() { + private ElementVisitor<String,Void> qualNameVisitor = new SimpleElementVisitor8<String,Void>() { protected String defaultAction(Element e, Void ignore) { return ""; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7003595/T7003595.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2011, 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 7003595 + * @summary IncompatibleClassChangeError with unreferenced local class with subclass + */ + +import com.sun.source.util.JavacTask; +import com.sun.tools.classfile.Attribute; +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.InnerClasses_attribute; +import com.sun.tools.classfile.ConstantPool.*; +import com.sun.tools.javac.api.JavacTool; + +import java.io.File; +import java.net.URI; +import java.util.Arrays; +import java.util.ArrayList; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + + +public class T7003595 { + + /** global decls ***/ + + // Create a single file manager and reuse it for each compile to save time. + static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); + + //statistics + static int checkCount = 0; + + enum ClassKind { + NESTED("static class #N { #B }", "$", true), + INNER("class #N { #B }", "$", false), + LOCAL_REF("void test() { class #N { #B }; new #N(); }", "$1", false), + LOCAL_NOREF("void test() { class #N { #B }; }", "$1", false), + ANON("void test() { new Object() { #B }; }", "$1", false), + NONE("", "", false); + + String memberInnerStr; + String sep; + boolean staticAllowed; + + private ClassKind(String memberInnerStr, String sep, boolean staticAllowed) { + this.memberInnerStr = memberInnerStr; + this.sep = sep; + this.staticAllowed = staticAllowed; + } + + String getSource(String className, String outerName, String nested) { + return memberInnerStr.replaceAll("#O", outerName). + replaceAll("#N", className).replaceAll("#B", nested); + } + + static String getClassfileName(String[] names, ClassKind[] outerKinds, int pos) { + System.out.println(" pos = " + pos + " kind = " + outerKinds[pos] + " sep = " + outerKinds[pos].sep); + String name = outerKinds[pos] != ANON ? + names[pos] : ""; + if (pos == 0) { + return "Test" + outerKinds[pos].sep + name; + } else { + String outerStr = getClassfileName(names, outerKinds, pos - 1); + return outerStr + outerKinds[pos].sep + name; + } + } + + boolean isAllowed(ClassKind nestedKind) { + return nestedKind != NESTED || + staticAllowed; + } + } + + enum LocalInnerClass { + LOCAL_REF("class L {}; new L();", "Test$1L"), + LOCAL_NOREF("class L {};", "Test$1L"), + ANON("new Object() {};", "Test$1"), + NONE("", ""); + + String localInnerStr; + String canonicalInnerStr; + + private LocalInnerClass(String localInnerStr, String canonicalInnerStr) { + this.localInnerStr = localInnerStr; + this.canonicalInnerStr = canonicalInnerStr; + } + } + + public static void main(String... args) throws Exception { + for (ClassKind ck1 : ClassKind.values()) { + String cname1 = "C1"; + for (ClassKind ck2 : ClassKind.values()) { + if (!ck1.isAllowed(ck2)) continue; + String cname2 = "C2"; + for (ClassKind ck3 : ClassKind.values()) { + if (!ck2.isAllowed(ck3)) continue; + String cname3 = "C3"; + new T7003595(new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck(); + } + } + } + + System.out.println("Total checks made: " + checkCount); + } + + /** instance decls **/ + + ClassKind[] cks; + String[] cnames; + + T7003595(ClassKind[] cks, String[] cnames) { + this.cks = cks; + this.cnames = cnames; + } + + void compileAndCheck() throws Exception { + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + JavaSource source = new JavaSource(); + JavacTask ct = (JavacTask)tool.getTask(null, fm, null, + null, null, Arrays.asList(source)); + ct.call(); + verifyBytecode(source); + } + + void verifyBytecode(JavaSource source) { + for (int i = 0; i < 3 ; i ++) { + if (cks[i] == ClassKind.NONE) break; + checkCount++; + String filename = cks[i].getClassfileName(cnames, cks, i); + File compiledTest = new File(filename + ".class"); + try { + ClassFile cf = ClassFile.read(compiledTest); + if (cf == null) { + throw new Error("Classfile not found: " + filename); + } + + InnerClasses_attribute innerClasses = (InnerClasses_attribute)cf.getAttribute(Attribute.InnerClasses); + + ArrayList<String> foundInnerSig = new ArrayList<>(); + if (innerClasses != null) { + for (InnerClasses_attribute.Info info : innerClasses.classes) { + String foundSig = info.getInnerClassInfo(cf.constant_pool).getName(); + foundInnerSig.add(foundSig); + } + } + + ArrayList<String> expectedInnerSig = new ArrayList<>(); + //add inner class (if any) + if (i < 2 && cks[i + 1] != ClassKind.NONE) { + expectedInnerSig.add(cks[i + 1].getClassfileName(cnames, cks, i + 1)); + } + //add inner classes + for (int j = 0 ; j != i + 1 && j < 3; j++) { + expectedInnerSig.add(cks[j].getClassfileName(cnames, cks, j)); + } + + if (expectedInnerSig.size() != foundInnerSig.size()) { + throw new Error("InnerClasses attribute for " + cnames[i] + " has wrong size\n" + + "expected " + expectedInnerSig.size() + "\n" + + "found " + innerClasses.number_of_classes + "\n" + + source); + } + + for (String foundSig : foundInnerSig) { + if (!expectedInnerSig.contains(foundSig)) { + throw new Error("InnerClasses attribute for " + cnames[i] + " has unexpected signature: " + + foundSig + "\n" + source + "\n" + expectedInnerSig); + } + } + + for (String expectedSig : expectedInnerSig) { + if (!foundInnerSig.contains(expectedSig)) { + throw new Error("InnerClasses attribute for " + cnames[i] + " does not contain expected signature: " + + expectedSig + "\n" + source); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new Error("error reading " + compiledTest +": " + e); + } + } + } + + class JavaSource extends SimpleJavaFileObject { + + static final String source_template = "class Test { #C }"; + + String source; + + public JavaSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + String c3 = cks[2].getSource(cnames[2], cnames[1], ""); + String c2 = cks[1].getSource(cnames[1], cnames[0], c3); + String c1 = cks[0].getSource(cnames[0], "Test", c2); + source = source_template.replace("#C", c1); + } + + @Override + public String toString() { + return source; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7003595/T7003595b.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011, 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 7003595 + * @summary IncompatibleClassChangeError with unreferenced local class with subclass + */ + +public class T7003595b { + public static void main(String... args) throws Exception { + class A {} + class B extends A {} + B.class.getSuperclass().getDeclaringClass(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7079713/TestCircularClassfile.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2011, 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 7079713 + * @summary javac hangs when compiling a class that references a cyclically inherited class + * @run main TestCircularClassfile + */ + +import java.io.*; +import java.net.URI; +import java.util.Arrays; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; + +public class TestCircularClassfile { + + enum SourceKind { + A_EXTENDS_B("class B {} class A extends B { void m() {} }"), + B_EXTENDS_A("class A { void m() {} } class B extends A {}"); + + String sourceStr; + + private SourceKind(String sourceStr) { + this.sourceStr = sourceStr; + } + + SimpleJavaFileObject getSource() { + return new SimpleJavaFileObject(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE) { + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return sourceStr; + } + }; + } + } + + enum TestKind { + REPLACE_A("A.class"), + REPLACE_B("B.class"); + + String targetClass; + + private TestKind(String targetClass) { + this.targetClass = targetClass; + } + } + + enum ClientKind { + METHOD_CALL1("A a = null; a.m();"), + METHOD_CALL2("B b = null; b.m();"), + CONSTR_CALL1("new A();"), + CONSTR_CALL2("new B();"), + ASSIGN1("A a = null; B b = a;"), + ASSIGN2("B b = null; A a = b;"); + + String mainMethod; + + private ClientKind(String mainMethod) { + this.mainMethod = mainMethod; + } + + SimpleJavaFileObject getSource() { + return new SimpleJavaFileObject(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE) { + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return "class Test { public static void main(String[] args) { #M } }" + .replace("#M", mainMethod); + } + }; + } + } + + public static void main(String... args) throws Exception { + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + int count = 0; + for (SourceKind sk1 : SourceKind.values()) { + for (SourceKind sk2 : SourceKind.values()) { + for (TestKind tk : TestKind.values()) { + for (ClientKind ck : ClientKind.values()) { + new TestCircularClassfile("sub_"+count++, sk1, sk2, tk, ck).check(comp, fm); + } + } + } + } + } + + static String workDir = System.getProperty("user.dir"); + + String destPath; + SourceKind sk1; + SourceKind sk2; + TestKind tk; + ClientKind ck; + + TestCircularClassfile(String destPath, SourceKind sk1, SourceKind sk2, TestKind tk, ClientKind ck) { + this.destPath = destPath; + this.sk1 = sk1; + this.sk2 = sk2; + this.tk = tk; + this.ck = ck; + } + + void check(JavaCompiler comp, StandardJavaFileManager fm) throws Exception { + //step 1: compile first source code in the test subfolder + File destDir = new File(workDir, destPath); destDir.mkdir(); + //output dir must be set explicitly as we are sharing the fm (see bug 7026941) + fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); + JavacTask ct = (JavacTask)comp.getTask(null, fm, null, + null, null, Arrays.asList(sk1.getSource())); + ct.generate(); + + //step 2: compile second source code in a temp folder + File tmpDir = new File(destDir, "tmp"); tmpDir.mkdir(); + //output dir must be set explicitly as we are sharing the fm (see bug 7026941) + fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir)); + ct = (JavacTask)comp.getTask(null, fm, null, + null, null, Arrays.asList(sk2.getSource())); + ct.generate(); + + //step 3: move a classfile from the temp folder to the test subfolder + File fileToMove = new File(tmpDir, tk.targetClass); + File target = new File(destDir, tk.targetClass); + target.delete(); + boolean success = fileToMove.renameTo(target); + + if (!success) { + throw new AssertionError("error when moving file " + tk.targetClass); + } + + //step 4: compile the client class against the classes in the test subfolder + //input/output dir must be set explicitly as we are sharing the fm (see bug 7026941) + fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); + fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(destDir)); + ct = (JavacTask)comp.getTask(null, fm, null, + null, null, Arrays.asList(ck.getSource())); + + ct.generate(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7085024/T7085024.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,12 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7085024 + * @summary internal error; cannot instantiate Foo + * @compile/fail/ref=T7085024.out -XDrawDiagnostics T7085024.java + */ + +class T7085024 { + T7085024 (boolean ret) { } //internal error goes away if constructor accepts a reference type + + T7085024 f = new T7085024((NonExistentClass) null ); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7085024/T7085024.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,2 @@ +T7085024.java:11:32: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, T7085024, null) +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7086595/T7086595.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,32 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7086595 + * @summary Error message bug: name of initializer is 'null' + * @compile/fail/ref=T7086595.out -XDrawDiagnostics T7086595.java + */ + +class T7086595 { + + String s = "x"; + String s = nonExistent; + + int foo() { + String s = "x"; + String s = nonExistent; + } + + static int bar() { + String s = "x"; + String s = nonExistent; + } + + { + String s = "x"; + String s = nonExistent; + } + + static { + String s = "x"; + String s = nonExistent; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/7086595/T7086595.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,11 @@ +T7086595.java:11:12: compiler.err.already.defined: kindname.variable, s, kindname.class, T7086595 +T7086595.java:11:16: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) +T7086595.java:15:16: compiler.err.already.defined: kindname.variable, s, kindname.method, foo() +T7086595.java:15:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) +T7086595.java:20:16: compiler.err.already.defined: kindname.variable, s, kindname.method, bar() +T7086595.java:20:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) +T7086595.java:25:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.instance.init, kindname.class, T7086595 +T7086595.java:25:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) +T7086595.java:30:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.static.init, kindname.class, T7086595 +T7086595.java:30:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) +10 errors
--- a/test/tools/javac/Diagnostics/6860795/T6860795.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/Diagnostics/6860795/T6860795.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -T6860795.java:10:27: compiler.err.already.defined: x, foo +T6860795.java:10:27: compiler.err.already.defined: kindname.variable, x, kindname.method, foo 1 error
--- a/test/tools/javac/Diagnostics/6862608/T6862608a.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,3 +1,3 @@ -T6862608a.java:19:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String> +T6862608a.java:19:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>) - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))} 1 error
--- a/test/tools/javac/LocalClasses_2.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/LocalClasses_2.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -LocalClasses_2.java:15:13: compiler.err.already.defined: Local, foo() +LocalClasses_2.java:15:13: compiler.err.already.defined: kindname.class, Local, kindname.method, foo() 1 error
--- a/test/tools/javac/NestedInnerClassNames.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/NestedInnerClassNames.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,18 +1,18 @@ -NestedInnerClassNames.java:16:5: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package -NestedInnerClassNames.java:23:9: compiler.err.already.defined: NestedInnerClassNames.foo, NestedInnerClassNames -NestedInnerClassNames.java:34:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package -NestedInnerClassNames.java:45:9: compiler.err.already.defined: NestedInnerClassNames.baz, NestedInnerClassNames -NestedInnerClassNames.java:46:13: compiler.err.already.defined: NestedInnerClassNames.baz.baz, NestedInnerClassNames.baz -NestedInnerClassNames.java:59:9: compiler.err.already.defined: NestedInnerClassNames.foo$bar, NestedInnerClassNames -NestedInnerClassNames.java:76:13: compiler.err.already.defined: NestedInnerClassNames.$bar, NestedInnerClassNames -NestedInnerClassNames.java:90:13: compiler.err.already.defined: NestedInnerClassNames.bar$bar.bar, NestedInnerClassNames.bar$bar +NestedInnerClassNames.java:16:5: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package +NestedInnerClassNames.java:23:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo, kindname.class, NestedInnerClassNames +NestedInnerClassNames.java:34:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package +NestedInnerClassNames.java:45:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz, kindname.class, NestedInnerClassNames +NestedInnerClassNames.java:46:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz.baz, kindname.class, NestedInnerClassNames.baz +NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames +NestedInnerClassNames.java:76:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.$bar, kindname.class, NestedInnerClassNames +NestedInnerClassNames.java:90:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.bar$bar.bar, kindname.class, NestedInnerClassNames.bar$bar NestedInnerClassNames.java:109:5: compiler.err.duplicate.class: NestedInnerClassNames.foo.foo -NestedInnerClassNames.java:19:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package -NestedInnerClassNames.java:28:13: compiler.err.already.defined: foo, m2() -NestedInnerClassNames.java:40:13: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package -NestedInnerClassNames.java:52:13: compiler.err.already.defined: baz, m4() -NestedInnerClassNames.java:53:17: compiler.err.already.defined: baz.baz, baz -NestedInnerClassNames.java:67:13: compiler.err.already.defined: foo$bar, m5() -NestedInnerClassNames.java:83:17: compiler.err.already.defined: $bar, m6() -NestedInnerClassNames.java:97:17: compiler.err.already.defined: bar$bar.bar, bar$bar +NestedInnerClassNames.java:19:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package +NestedInnerClassNames.java:28:13: compiler.err.already.defined: kindname.class, foo, kindname.method, m2() +NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package +NestedInnerClassNames.java:52:13: compiler.err.already.defined: kindname.class, baz, kindname.method, m4() +NestedInnerClassNames.java:53:17: compiler.err.already.defined: kindname.class, baz.baz, kindname.class, baz +NestedInnerClassNames.java:67:13: compiler.err.already.defined: kindname.class, foo$bar, kindname.method, m5() +NestedInnerClassNames.java:83:17: compiler.err.already.defined: kindname.class, $bar, kindname.method, m6() +NestedInnerClassNames.java:97:17: compiler.err.already.defined: kindname.class, bar$bar.bar, kindname.class, bar$bar 17 errors
--- a/test/tools/javac/StringsInSwitch/StringSwitches.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/StringsInSwitch/StringSwitches.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6827009 + * @bug 6827009 7071246 * @summary Positive tests for strings in switch. * @author Joseph D. Darcy */ @@ -36,6 +36,7 @@ failures += testPileup(); failures += testSwitchingTwoWays(); failures += testNamedBreak(); + failures += testExtraParens(); if (failures > 0) { throw new RuntimeException(); @@ -260,4 +261,19 @@ result |= (1<<5); return result; } + + private static int testExtraParens() { + int failures = 1; + String s = "first"; + + switch(s) { + case (("first")): + failures = 0; + break; + case ("second"): + throw new RuntimeException("Should not be reached."); + } + + return failures; + } }
--- a/test/tools/javac/T6358166.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/T6358166.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -61,7 +61,7 @@ Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); compilerMain.setOptions(Options.instance(context)); - compilerMain.filenames = new ListBuffer<File>(); + compilerMain.filenames = new LinkedHashSet<File>(); compilerMain.processArgs(args); JavaCompiler c = JavaCompiler.instance(context);
--- a/test/tools/javac/T6358168.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/T6358168.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -72,7 +72,7 @@ Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); compilerMain.setOptions(Options.instance(context)); - compilerMain.filenames = new ListBuffer<File>(); + compilerMain.filenames = new LinkedHashSet<File>(); compilerMain.processArgs(new String[] { "-d", "." }); JavaCompiler compiler = JavaCompiler.instance(context); @@ -91,7 +91,7 @@ Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); compilerMain.setOptions(Options.instance(context)); - compilerMain.filenames = new ListBuffer<File>(); + compilerMain.filenames = new LinkedHashSet<File>(); compilerMain.processArgs(new String[] { "-XprintRounds", "-processorpath", testClasses,
--- a/test/tools/javac/TryWithResources/BadTwr.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/BadTwr.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ -BadTwr.java:13:39: compiler.err.already.defined: r1, main(java.lang.String...) -BadTwr.java:18:13: compiler.err.already.defined: args, main(java.lang.String...) +BadTwr.java:13:46: compiler.err.already.defined: kindname.variable, r1, kindname.method, main(java.lang.String...) +BadTwr.java:18:20: compiler.err.already.defined: kindname.variable, args, kindname.method, main(java.lang.String...) BadTwr.java:21:13: compiler.err.cant.assign.val.to.final.var: thatsIt -BadTwr.java:26:17: compiler.err.already.defined: name, main(java.lang.String...) +BadTwr.java:26:24: compiler.err.already.defined: kindname.variable, name, kindname.method, main(java.lang.String...) 4 errors
--- a/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -DuplicateResourceDecl.java:12:45: compiler.err.already.defined: c, main(java.lang.String[]) +DuplicateResourceDecl.java:12:56: compiler.err.already.defined: kindname.variable, c, kindname.method, main(java.lang.String[]) 1 error
--- a/test/tools/javac/TryWithResources/ResourceInterface.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/ResourceInterface.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -ResourceInterface.java:38:13: compiler.err.unreported.exception.implicit.close: ResourceInterface.E1, r2 +ResourceInterface.java:38:23: compiler.err.unreported.exception.implicit.close: ResourceInterface.E1, r2 1 error
--- a/test/tools/javac/TryWithResources/TwrFlow.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/TwrFlow.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,3 +1,3 @@ TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException -TwrFlow.java:12:13: compiler.err.unreported.exception.implicit.close: CustomCloseException, twrFlow +TwrFlow.java:12:21: compiler.err.unreported.exception.implicit.close: CustomCloseException, twrFlow 2 errors
--- a/test/tools/javac/TryWithResources/TwrLint.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/TwrLint.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,3 +1,3 @@ TwrLint.java:14:15: compiler.warn.try.explicit.close.call -TwrLint.java:13:13: compiler.warn.try.resource.not.referenced: r3 +TwrLint.java:13:21: compiler.warn.try.resource.not.referenced: r3 2 warnings
--- a/test/tools/javac/TryWithResources/TwrOnNonResource.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,4 +1,4 @@ -TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable +TwrOnNonResource.java:12:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable +TwrOnNonResource.java:15:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable +TwrOnNonResource.java:18:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 3 errors
--- a/test/tools/javac/TryWithResources/UnusedResourcesTest.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/TryWithResources/UnusedResourcesTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -28,6 +28,7 @@ */ import com.sun.source.util.JavacTask; +import com.sun.tools.javac.api.ClientCodeWrapper; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.JCDiagnostic; import java.net.URI; @@ -236,7 +237,7 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.WARNING && diagnostic.getCode().contains("try.resource.not.referenced")) { - String varName = ((JCDiagnostic)diagnostic).getArgs()[0].toString(); + String varName = unwrap(diagnostic).getArgs()[0].toString(); if (varName.equals(TwrStmt.TWR1.resourceName)) { unused_r1 = true; } else if (varName.equals(TwrStmt.TWR2.resourceName)) { @@ -246,5 +247,13 @@ } } } + + private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic instanceof JCDiagnostic) + return (JCDiagnostic) diagnostic; + if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper) + return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d; + throw new IllegalArgumentException(); + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/T7043371.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2011, 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 7043371 + * @summary javac7 fails with NPE during compilation + * @compile T7043371.java + */ + +@interface Anno { + String value(); +} + +class B { + @Anno(value=A.a) + public static final int b = 0; +} + +class A { + @Deprecated + public static final String a = "a"; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/T7073477.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011, 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 7073477 + * @summary NPE in com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue + * @compile T7073477.java + */ + +@SuppressWarnings(T7073477A.S) +class T7073477 { +} + +class T7073477A { + @SuppressWarnings("") + static final String S = ""; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/api/7086261/T7086261.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 20011, 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 7086261 + * @summary javac doesn't report error as expected, it only reports ClientCodeWrapper$DiagnosticSourceUnwrapper + */ + +import javax.tools.*; + +import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper; +import com.sun.tools.javac.util.JCDiagnostic; + +import java.net.URI; +import java.util.Arrays; + +import static javax.tools.StandardLocation.*; +import static javax.tools.JavaFileObject.Kind.*; + + +public class T7086261 { + + static class ErroneousSource extends SimpleJavaFileObject { + public ErroneousSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + } + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return "class Test { NonexistentClass c = null; }"; + } + } + + static class DiagnosticChecker implements DiagnosticListener<javax.tools.JavaFileObject> { + public void report(Diagnostic message) { + if (!(message instanceof DiagnosticSourceUnwrapper)) { + throw new AssertionError("Wrapped diagnostic expected!"); + } + String actual = message.toString(); + JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d; + String expected = jd.toString(); + if (!actual.equals(expected)) { + throw new AssertionError("expected = " + expected + "\nfound = " + actual); + } + } + }; + + void test() throws Throwable { + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); + JavaFileManager jfm = javac.getStandardFileManager(null, null, null); + JavaCompiler.CompilationTask task = + javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource())); + task.call(); + } + + public static void main(String[] args) throws Throwable { + new T7086261().test(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/api/TestGetScope.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2011, 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 7090249 + * @summary IllegalStateException from Trees.getScope when called from JSR 199 + */ + +import com.sun.source.tree.IdentifierTree; +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; +import com.sun.source.util.TreePath; +import com.sun.source.util.TreePathScanner; +import com.sun.source.util.Trees; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; + +@SupportedAnnotationTypes("*") +public class TestGetScope extends AbstractProcessor { + public static void main(String... args) { + new TestGetScope().run(); + } + + public void run() { + File srcDir = new File(System.getProperty("test.src")); + File thisFile = new File(srcDir, getClass().getName() + ".java"); + + JavaCompiler c = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); + + List<String> opts = Arrays.asList("-proc:only", "-doe"); + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); + JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); + t.setProcessors(Collections.singleton(this)); + boolean ok = t.call(); + if (!ok) + throw new Error("compilation failed"); + } + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + Trees trees = Trees.instance(processingEnv); + if (round++ == 0) { + for (Element e: roundEnv.getRootElements()) { + TreePath p = trees.getPath(e); + new Scanner().scan(p, trees); + } + } + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + int round; + + static class Scanner extends TreePathScanner<Void,Trees> { + @Override + public Void visitIdentifier(IdentifierTree t, Trees trees) { + System.err.println("visitIdentifier: " + t); + trees.getScope(getCurrentPath()); + return null; + } + } +}
--- a/test/tools/javac/api/TestOperators.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/api/TestOperators.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -26,7 +26,8 @@ * @bug 6338064 6346249 6340951 6392177 * @summary Tree API: can't determine kind of operator * @author Peter von der Ah\u00e9 - * @compile TestOperators.java + * @library ../lib + * @build JavacTestingAbstractProcessor TestOperators * @compile -processor TestOperators -proc:only TestOperators.java */ @@ -46,7 +47,7 @@ } @SupportedAnnotationTypes("TestMe") -public class TestOperators extends AbstractProcessor { +public class TestOperators extends JavacTestingAbstractProcessor { @TestMe(POSTFIX_INCREMENT) public int test_POSTFIX_INCREMENT(int i) { @@ -299,7 +300,7 @@ final Trees trees = Trees.instance(processingEnv); final Messager log = processingEnv.getMessager(); final Elements elements = processingEnv.getElementUtils(); - class Scan extends ElementScanner7<Void,Void> { + class Scan extends ElementScanner<Void,Void> { @Override public Void visitExecutable(ExecutableElement e, Void p) { Object debug = e; // info for exception handler @@ -343,5 +344,4 @@ } return true; } - }
--- a/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Feb 14 10:29:36 2012 -0800 @@ -146,9 +146,9 @@ JavacFileManager.preRegister(c); // can't create it until Log has been set up ArgTypeJavaCompiler.preRegister(c); ArgTypeMessages.preRegister(c); - int result = main.compile(args.toArray(new String[args.size()]), c); + Main.Result result = main.compile(args.toArray(new String[args.size()]), c); - return (result == 0); + return result.isOK(); } } @@ -172,10 +172,10 @@ JavacFileManager.preRegister(c); // can't create it until Log has been set up ArgTypeJavaCompiler.preRegister(c); ArgTypeMessages.preRegister(c); - com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", out); - int rc = m.compile(args.toArray(new String[args.size()]), c); + Main m = new Main("javac", out); + Main.Result result = m.compile(args.toArray(new String[args.size()]), c); - return (rc == 0); + return result.isOK(); } }
--- a/test/tools/javac/diags/Example.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/diags/Example.java Tue Feb 14 10:29:36 2012 -0800 @@ -21,10 +21,12 @@ * questions. */ -import com.sun.tools.javac.file.JavacFileManager; import java.io.*; +import java.net.URL; +import java.net.URLClassLoader; import java.util.*; import java.util.regex.*; +import javax.annotation.processing.Processor; import javax.tools.Diagnostic; import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; @@ -37,12 +39,12 @@ // import com.sun.tools.javac.Main // import com.sun.tools.javac.main.Main +import com.sun.tools.javac.api.ClientCodeWrapper; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.main.Main; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JavacMessages; import com.sun.tools.javac.util.JCDiagnostic; -import java.net.URL; -import java.net.URLClassLoader; -import javax.annotation.processing.Processor; /** * Class to handle example code designed to illustrate javac diagnostic messages. @@ -397,7 +399,7 @@ if (keys != null) { for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) { - scanForKeys((JCDiagnostic) d, keys); + scanForKeys(unwrap(d), keys); } } @@ -418,6 +420,14 @@ for (JCDiagnostic sd: d.getSubdiagnostics()) scanForKeys(sd, keys); } + + private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic instanceof JCDiagnostic) + return (JCDiagnostic) diagnostic; + if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper) + return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d; + throw new IllegalArgumentException(); + } } /** @@ -506,14 +516,14 @@ Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); - com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", pw); - int rc = m.compile(args.toArray(new String[args.size()]), c); + Main m = new Main("javac", pw); + Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } - return (rc == 0); + return rc.isOK(); } static class MessageTracker extends JavacMessages {
--- a/test/tools/javac/diags/examples.not-yet.txt Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/diags/examples.not-yet.txt Tue Feb 14 10:29:36 2012 -0800 @@ -60,7 +60,7 @@ compiler.misc.fatal.err.cant.locate.ctor # Resolve, from Lower compiler.misc.fatal.err.cant.locate.field # Resolve, from Lower compiler.misc.fatal.err.cant.locate.meth # Resolve, from Lower -compiler.misc.fatal.err.cant.close.loader # JavacProcessingEnvironment +compiler.misc.fatal.err.cant.close # JavaCompiler compiler.misc.file.does.not.contain.package compiler.misc.illegal.start.of.class.file compiler.misc.kindname.annotation
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/AlreadyDefinedClinit.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011, 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. + */ + +// key: compiler.err.already.defined.in.clinit + +class AlreadyDefinedClinit { + static { + int i; + int i; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/CannotCreateArrayWithDiamond.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011, 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. + */ + +// key: compiler.err.cannot.create.array.with.diamond + +class CannotCreateArrayWithDiamond { + Object[] array = new Object<>[3]; +}
--- a/test/tools/javac/diags/examples/EmptyCharLiteral.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/diags/examples/EmptyCharLiteral.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, 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 @@ -23,7 +23,6 @@ // key: compiler.err.empty.char.lit // key: compiler.err.unclosed.char.lit -// key: compiler.err.expected // key: compiler.err.premature.eof class X {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/IncompatibleUpperBounds.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011, 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. + */ + +//key: compiler.err.cant.apply.symbols +//key: compiler.misc.inapplicable.method +//key: compiler.misc.arg.length.mismatch +//key: compiler.misc.incompatible.upper.bounds + +import java.util.List; + +class IncompatibleUpperBounds { + <S> void m(List<? super S> s1, List<? super S> s2) { } + void m(Object o) {} + + void test(List<Integer> li, List<String> ls) { + m(li, ls); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/KindnameInstanceInit.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011, 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. + */ + +// key: compiler.err.already.defined.in.clinit +// key: compiler.misc.kindname.instance.init +// key: compiler.misc.kindname.class +// key: compiler.misc.kindname.variable +// key: compiler.misc.count.error +// key: compiler.err.error +// run: backdoor + +class KindnameInstanceInit { + { + int i; + int i; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/KindnameStaticInit.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011, 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. + */ + +// key: compiler.err.already.defined.in.clinit +// key: compiler.misc.kindname.static.init +// key: compiler.misc.kindname.class +// key: compiler.misc.kindname.variable +// key: compiler.misc.count.error +// key: compiler.err.error +// run: backdoor + +class KindnameStaticInit { + static { + int i; + int i; + } +}
--- a/test/tools/javac/enum/6350057/T6350057.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/enum/6350057/T6350057.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -23,10 +23,11 @@ /* * @test - * @bug 6350057 + * @bug 6350057 7025809 * @summary Test that parameters on implicit enum methods have the right kind * @author Joseph D. Darcy - * @compile T6350057.java + * @library ../../lib + * @build JavacTestingAbstractProcessor T6350057 * @compile -processor T6350057 -proc:only TestEnum.java */ @@ -38,9 +39,8 @@ import javax.lang.model.util.*; import static javax.tools.Diagnostic.Kind.*; -@SupportedAnnotationTypes("*") -public class T6350057 extends AbstractProcessor { - static class LocalVarAllergy extends ElementKindVisitor6<Boolean, Void> { +public class T6350057 extends JavacTestingAbstractProcessor { + static class LocalVarAllergy extends ElementKindVisitor<Boolean, Void> { @Override public Boolean visitTypeAsEnum(TypeElement e, Void v) { System.out.println("visitTypeAsEnum: " + e.getSimpleName().toString());
--- a/test/tools/javac/enum/6424358/T6424358.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/enum/6424358/T6424358.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -23,10 +23,11 @@ /* * @test - * @bug 6424358 + * @bug 6424358 7025809 * @summary Synthesized static enum method values() is final * @author Peter von der Ah\u00e9 - * @compile T6424358.java + * @library ../../lib + * @build JavacTestingAbstractProcessor T6424358 * @compile -processor T6424358 -proc:only T6424358.java */ @@ -39,8 +40,7 @@ @interface TestMe {} -@SupportedAnnotationTypes("*") -public class T6424358 extends AbstractProcessor { +public class T6424358 extends JavacTestingAbstractProcessor { @TestMe enum Test { FOO; } public boolean process(Set<? extends TypeElement> annotations, @@ -48,7 +48,7 @@ final Messager log = processingEnv.getMessager(); final Elements elements = processingEnv.getElementUtils(); final TypeElement testMe = elements.getTypeElement("TestMe"); - class Scan extends ElementScanner7<Void,Void> { + class Scan extends ElementScanner<Void,Void> { @Override public Void visitExecutable(ExecutableElement e, Void p) { System.err.println("Looking at " + e); @@ -65,9 +65,4 @@ scan.scan(e); return true; } - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latest(); - } }
--- a/test/tools/javac/failover/FailOver15.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/failover/FailOver15.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,4 +1,3 @@ FailOver15.java:17:10: compiler.err.expected: ';' FailOver15.java:11:13: compiler.err.cant.resolve.location: kindname.class, UnknownClass, , , (compiler.misc.location: kindname.class, Test, null) 2 errors -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/file/T7068437.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2011, 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 7068437 + * @summary Filer.getResource(SOURCE_OUTPUT, ...) no longer works in JDK 7 w/o -s + */ + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Writer; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedOptions; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaCompiler; +import javax.tools.JavaCompiler.CompilationTask; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +public class T7068437 { + public static void main(String[] args) throws Exception { + new T7068437().run(); + } + + void run() throws Exception { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + System.err.println("using " + compiler.getClass() + + " from " + compiler.getClass().getProtectionDomain().getCodeSource()); + + CompilationTask task = compiler.getTask(null, null, null, + Collections.singleton("-proc:only"), + Collections.singleton("java.lang.Object"), + null); + task.setProcessors(Collections.singleton(new Proc())); + check("compilation", task.call()); + + task = compiler.getTask(null, null, null, + Arrays.asList("-proc:only", "-AexpectFile"), + Collections.singleton("java.lang.Object"), + null); + task.setProcessors(Collections.singleton(new Proc())); + check("compilation", task.call()); + } + + void check(String msg, boolean ok) { + System.err.println(msg + ": " + (ok ? "ok" : "failed")); + if (!ok) + throw new AssertionError(msg); + } + + @SupportedAnnotationTypes("*") + @SupportedOptions("expectFile") + private static class Proc extends AbstractProcessor { + int count; + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver() || count++ > 0) { + return false; + } + + Filer filer = processingEnv.getFiler(); + Messager messager = processingEnv.getMessager(); + Map<String, String> options = processingEnv.getOptions(); + System.err.println(options); + boolean expectFile = options.containsKey("expectFile"); + + System.err.println("running Proc: expectFile=" + expectFile); + + boolean found; + try { + messager.printMessage(Kind.NOTE, "found previous content of length " + + filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length()); + found = true; + } catch (FileNotFoundException x) { + messager.printMessage(Kind.NOTE, "not previously there"); + found = false; + } catch (IOException x) { + messager.printMessage(Kind.ERROR, "while reading: " + x); + found = false; + } + + if (expectFile && !found) { + messager.printMessage(Kind.ERROR, "expected file but file not found"); + } + + try { + Writer w = filer.createSourceFile("p.C").openWriter(); + w.write("/* hello! */ package p; class C {}"); + w.close(); + messager.printMessage(Kind.NOTE, "wrote new content"); + } catch (IOException x) { + messager.printMessage(Kind.ERROR, "while writing: " + x); + } + + return true; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/file/T7068451.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2011, 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 7068451 + * @summary Regression: javac compiles fixed sources against previous, + * not current, version of generated sources + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaCompiler; +import javax.tools.JavaCompiler.CompilationTask; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +public class T7068451 { + public static void main(String[] args) throws Exception { + new T7068451().run(); + } + + void run() throws Exception { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + System.err.println("using " + compiler.getClass() + " from " + compiler.getClass().getProtectionDomain().getCodeSource()); + + File tmp = new File("tmp"); + tmp.mkdir(); + for (File f: tmp.listFiles()) + f.delete(); + + File input = writeFile(tmp, "X.java", "package p; class X { { p.C.first(); } }"); + + List<String> opts = Arrays.asList( + "-s", tmp.getPath(), + "-d", tmp.getPath(), + "-XprintRounds"); + + System.err.println(); + System.err.println("FIRST compilation"); + System.err.println(); + + CompilationTask task = compiler.getTask(null, null, null, opts, null, + compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); + task.setProcessors(Collections.singleton(new Proc("first"))); + check("compilation", task.call()); + + writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }"); + + //Thread.sleep(2000); + + System.err.println(); + System.err.println("SECOND compilation"); + System.err.println(); + + task = compiler.getTask(null, null, null, opts, null, + compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); + task.setProcessors(Collections.singleton(new Proc("second"))); + check("compilation", task.call()); + + //Thread.sleep(2000); + + System.err.println(); + System.err.println("SECOND compilation, REPEATED"); + System.err.println(); + + task = compiler.getTask(null, null, null, opts, null, + compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); + task.setProcessors(Collections.singleton(new Proc("second"))); + check("compilation", task.call()); + } + + void check(String msg, boolean ok) { + System.err.println(msg + ": " + (ok ? "ok" : "failed")); + if (!ok) + throw new AssertionError(msg); + } + + static File writeFile(File base, String path, String body) throws IOException { + File f = new File(base, path); + FileWriter out = new FileWriter(f); + out.write(body); + out.close(); + System.err.println("wrote " + path + ": " + body); + return f; + } + + @SupportedAnnotationTypes("*") + private static class Proc extends AbstractProcessor { + final String m; + Proc(String m) { + this.m = m; + } + + int count; + @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver() || count++ > 0) { + return false; + } + + Filer filer = processingEnv.getFiler(); + Messager messager = processingEnv.getMessager(); + + System.err.println("running Proc"); + try { + int len = filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length(); + messager.printMessage(Kind.NOTE, "C.java: found previous content of length " + len); + } catch (FileNotFoundException x) { + messager.printMessage(Kind.NOTE, "C.java: not previously there"); + } catch (IOException x) { + messager.printMessage(Kind.ERROR, "while reading: " + x); + } + + try { + String body = "package p; public class C { public static void " + m + "() {} }"; + Writer w = filer.createSourceFile("p.C").openWriter(); + w.write(body); + w.close(); + messager.printMessage(Kind.NOTE, "C.java: wrote new content: " + body); + } catch (IOException x) { + messager.printMessage(Kind.ERROR, "while writing: " + x); + } + + return true; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + } +} +
--- a/test/tools/javac/generics/6910550/T6910550d.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/generics/6910550/T6910550d.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -T6910550d.java:12:14: compiler.err.already.defined: <X>m(X), T6910550d +T6910550d.java:12:14: compiler.err.already.defined: kindname.method, <X>m(X), kindname.class, T6910550d 1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2011, 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 7046778 + * @summary Project Coin: problem with diamond and member inner classes + */ + +import com.sun.source.util.JavacTask; +import java.net.URI; +import java.util.Arrays; +import javax.tools.Diagnostic; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +public class DiamondAndInnerClassTest { + + static int checkCount = 0; + + enum TypeArgumentKind { + NONE(""), + STRING("<String>"), + INTEGER("<Integer>"), + DIAMOND("<>"); + + String typeargStr; + + private TypeArgumentKind(String typeargStr) { + this.typeargStr = typeargStr; + } + + boolean compatible(TypeArgumentKind that) { + switch (this) { + case NONE: return true; + case STRING: return that != INTEGER; + case INTEGER: return that != STRING; + default: throw new AssertionError("Unexpected decl kind: " + this); + } + } + + boolean compatible(ArgumentKind that) { + switch (this) { + case NONE: return true; + case STRING: return that == ArgumentKind.STRING; + case INTEGER: return that == ArgumentKind.INTEGER; + default: throw new AssertionError("Unexpected decl kind: " + this); + } + } + } + + enum ArgumentKind { + OBJECT("(Object)null"), + STRING("(String)null"), + INTEGER("(Integer)null"); + + String argStr; + + private ArgumentKind(String argStr) { + this.argStr = argStr; + } + } + + enum TypeQualifierArity { + ONE(1, "A1#TA1"), + TWO(2, "A1#TA1.A2#TA2"), + THREE(3, "A1#TA1.A2#TA2.A3#TA3"); + + int n; + String qualifierStr; + + private TypeQualifierArity(int n, String qualifierStr) { + this.n = n; + this.qualifierStr = qualifierStr; + } + + String getType(TypeArgumentKind... typeArgumentKinds) { + String res = qualifierStr; + for (int i = 1 ; i <= typeArgumentKinds.length ; i++) { + res = res.replace("#TA" + i, typeArgumentKinds[i-1].typeargStr); + } + return res; + } + + boolean matches(InnerClassDeclArity innerClassDeclArity) { + return n ==innerClassDeclArity.n; + } + } + + enum InnerClassDeclArity { + ONE(1, "class A1<X> { A1(X x1) { } #B }"), + TWO(2, "class A1<X1> { class A2<X2> { A2(X1 x1, X2 x2) { } #B } }"), + THREE(3, "class A1<X1> { class A2<X2> { class A3<X3> { A3(X1 x1, X2 x2, X3 x3) { } #B } } }"); + + int n; + String classDeclStr; + + private InnerClassDeclArity(int n, String classDeclStr) { + this.n = n; + this.classDeclStr = classDeclStr; + } + } + + enum ArgumentListArity { + ONE(1, "(#A1)"), + TWO(2, "(#A1,#A2)"), + THREE(3, "(#A1,#A2,#A3)"); + + int n; + String argListStr; + + private ArgumentListArity(int n, String argListStr) { + this.n = n; + this.argListStr = argListStr; + } + + String getArgs(ArgumentKind... argumentKinds) { + String res = argListStr; + for (int i = 1 ; i <= argumentKinds.length ; i++) { + res = res.replace("#A" + i, argumentKinds[i-1].argStr); + } + return res; + } + + boolean matches(InnerClassDeclArity innerClassDeclArity) { + return n ==innerClassDeclArity.n; + } + } + + public static void main(String... args) throws Exception { + + //create default shared JavaCompiler - reused across multiple compilations + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + + for (InnerClassDeclArity innerClassDeclArity : InnerClassDeclArity.values()) { + for (TypeQualifierArity declType : TypeQualifierArity.values()) { + if (!declType.matches(innerClassDeclArity)) continue; + for (TypeQualifierArity newClassType : TypeQualifierArity.values()) { + if (!newClassType.matches(innerClassDeclArity)) continue; + for (ArgumentListArity argList : ArgumentListArity.values()) { + if (!argList.matches(innerClassDeclArity)) continue; + for (TypeArgumentKind taDecl1 : TypeArgumentKind.values()) { + boolean isDeclRaw = taDecl1 == TypeArgumentKind.NONE; + //no diamond on decl site + if (taDecl1 == TypeArgumentKind.DIAMOND) continue; + for (TypeArgumentKind taSite1 : TypeArgumentKind.values()) { + boolean isSiteRaw = taSite1 == TypeArgumentKind.NONE; + //diamond only allowed on the last type qualifier + if (taSite1 == TypeArgumentKind.DIAMOND && + innerClassDeclArity != InnerClassDeclArity.ONE) continue; + for (ArgumentKind arg1 : ArgumentKind.values()) { + if (innerClassDeclArity == innerClassDeclArity.ONE) { + new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType, + argList, new TypeArgumentKind[] {taDecl1}, + new TypeArgumentKind[] {taSite1}, new ArgumentKind[] {arg1}).run(comp, fm); + continue; + } + for (TypeArgumentKind taDecl2 : TypeArgumentKind.values()) { + //no rare types + if (isDeclRaw != (taDecl2 == TypeArgumentKind.NONE)) continue; + //no diamond on decl site + if (taDecl2 == TypeArgumentKind.DIAMOND) continue; + for (TypeArgumentKind taSite2 : TypeArgumentKind.values()) { + //no rare types + if (isSiteRaw != (taSite2 == TypeArgumentKind.NONE)) continue; + //diamond only allowed on the last type qualifier + if (taSite2 == TypeArgumentKind.DIAMOND && + innerClassDeclArity != InnerClassDeclArity.TWO) continue; + for (ArgumentKind arg2 : ArgumentKind.values()) { + if (innerClassDeclArity == innerClassDeclArity.TWO) { + new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType, + argList, new TypeArgumentKind[] {taDecl1, taDecl2}, + new TypeArgumentKind[] {taSite1, taSite2}, + new ArgumentKind[] {arg1, arg2}).run(comp, fm); + continue; + } + for (TypeArgumentKind taDecl3 : TypeArgumentKind.values()) { + //no rare types + if (isDeclRaw != (taDecl3 == TypeArgumentKind.NONE)) continue; + //no diamond on decl site + if (taDecl3 == TypeArgumentKind.DIAMOND) continue; + for (TypeArgumentKind taSite3 : TypeArgumentKind.values()) { + //no rare types + if (isSiteRaw != (taSite3 == TypeArgumentKind.NONE)) continue; + //diamond only allowed on the last type qualifier + if (taSite3 == TypeArgumentKind.DIAMOND && + innerClassDeclArity != InnerClassDeclArity.THREE) continue; + for (ArgumentKind arg3 : ArgumentKind.values()) { + if (innerClassDeclArity == innerClassDeclArity.THREE) { + new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType, + argList, new TypeArgumentKind[] {taDecl1, taDecl2, taDecl3}, + new TypeArgumentKind[] {taSite1, taSite2, taSite3}, + new ArgumentKind[] {arg1, arg2, arg3}).run(comp, fm); + continue; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + System.out.println("Total check executed: " + checkCount); + } + + InnerClassDeclArity innerClassDeclArity; + TypeQualifierArity declType; + TypeQualifierArity siteType; + ArgumentListArity argList; + TypeArgumentKind[] declTypeArgumentKinds; + TypeArgumentKind[] siteTypeArgumentKinds; + ArgumentKind[] argumentKinds; + JavaSource source; + DiagnosticChecker diagChecker; + + DiamondAndInnerClassTest(InnerClassDeclArity innerClassDeclArity, + TypeQualifierArity declType, TypeQualifierArity siteType, ArgumentListArity argList, + TypeArgumentKind[] declTypeArgumentKinds, TypeArgumentKind[] siteTypeArgumentKinds, + ArgumentKind[] argumentKinds) { + this.innerClassDeclArity = innerClassDeclArity; + this.declType = declType; + this.siteType = siteType; + this.argList = argList; + this.declTypeArgumentKinds = declTypeArgumentKinds; + this.siteTypeArgumentKinds = siteTypeArgumentKinds; + this.argumentKinds = argumentKinds; + this.source = new JavaSource(); + this.diagChecker = new DiagnosticChecker(); + } + + class JavaSource extends SimpleJavaFileObject { + + String bodyTemplate = "#D res = new #S#AL;"; + + String source; + + public JavaSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + source = innerClassDeclArity.classDeclStr.replace("#B", bodyTemplate) + .replace("#D", declType.getType(declTypeArgumentKinds)) + .replace("#S", siteType.getType(siteTypeArgumentKinds)) + .replace("#AL", argList.getArgs(argumentKinds)); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, + null, null, Arrays.asList(source)); + try { + ct.analyze(); + } catch (Throwable ex) { + throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true)); + } + check(); + } + + void check() { + checkCount++; + + boolean errorExpected = false; + + TypeArgumentKind[] expectedArgKinds = new TypeArgumentKind[innerClassDeclArity.n]; + + for (int i = 0 ; i < innerClassDeclArity.n ; i++) { + if (!declTypeArgumentKinds[i].compatible(siteTypeArgumentKinds[i])) { + errorExpected = true; + break; + } + expectedArgKinds[i] = siteTypeArgumentKinds[i] == TypeArgumentKind.DIAMOND ? + declTypeArgumentKinds[i] : siteTypeArgumentKinds[i]; + } + + if (!errorExpected) { + for (int i = 0 ; i < innerClassDeclArity.n ; i++) { + //System.out.println("check " + expectedArgKinds[i] + " against " + argumentKinds[i]); + if (!expectedArgKinds[i].compatible(argumentKinds[i])) { + errorExpected = true; + break; + } + } + } + + if (errorExpected != diagChecker.errorFound) { + throw new Error("invalid diagnostics for source:\n" + + source.getCharContent(true) + + "\nFound error: " + diagChecker.errorFound + + "\nExpected error: " + errorExpected); + } + } + + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { + + boolean errorFound; + + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { + errorFound = true; + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/7057297/T7057297.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,29 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7057297 + * + * @summary Project Coin: diamond erroneously accepts in array initializer expressions + * @compile/fail/ref=T7057297.out T7057297.java -XDrawDiagnostics + * + */ + +class T7205797<X> { + + class Inner<Y> {} + + T7205797<String>[] o1 = new T7205797<>[1]; //error + T7205797<String>[] o2 = new T7205797<>[1][1]; //error + T7205797<String>[] o3 = new T7205797<>[1][1][1]; //error + + T7205797<String>[] o4 = new T7205797<>[] { }; //error + T7205797<String>[] o5 = new T7205797<>[][] { }; //error + T7205797<String>[] o6 = new T7205797<>[][][] { }; //error + + T7205797<String>.Inner<String>[] o1 = new T7205797<String>.Inner<>[1]; //error + T7205797<String>.Inner<String>[] o2 = new T7205797<String>.Inner<>[1][1]; //error + T7205797<String>.Inner<String>[] o3 = new T7205797<String>.Inner<>[1][1][1]; //error + + T7205797<String>.Inner<String>[] o4 = new T7205797<String>.Inner<>[] { }; //error + T7205797<String>.Inner<String>[] o5 = new T7205797<String>.Inner<>[][] { }; //error + T7205797<String>.Inner<String>[] o6 = new T7205797<String>.Inner<>[][][] { }; //error +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/7057297/T7057297.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,13 @@ +T7057297.java:14:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:15:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:16:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:18:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:19:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:20:41: compiler.err.cannot.create.array.with.diamond +T7057297.java:22:69: compiler.err.cannot.create.array.with.diamond +T7057297.java:23:69: compiler.err.cannot.create.array.with.diamond +T7057297.java:24:69: compiler.err.cannot.create.array.with.diamond +T7057297.java:26:69: compiler.err.cannot.create.array.with.diamond +T7057297.java:27:69: compiler.err.cannot.create.array.with.diamond +T7057297.java:28:69: compiler.err.cannot.create.array.with.diamond +12 errors
--- a/test/tools/javac/generics/diamond/neg/Neg09.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/generics/diamond/neg/Neg09.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ -Neg09.java:17:34: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class: Neg09.Member) -Neg09.java:18:34: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class: Neg09.Nested) -Neg09.java:22:39: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class: Neg09.Member) -Neg09.java:23:40: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class: Neg09.Nested) +Neg09.java:17:34: compiler.err.cant.apply.diamond.1: Neg09.Member<X>, (compiler.misc.diamond.and.anon.class: Neg09.Member<X>) +Neg09.java:18:34: compiler.err.cant.apply.diamond.1: Neg09.Nested<X>, (compiler.misc.diamond.and.anon.class: Neg09.Nested<X>) +Neg09.java:22:39: compiler.err.cant.apply.diamond.1: Neg09.Member<X>, (compiler.misc.diamond.and.anon.class: Neg09.Member<X>) +Neg09.java:23:40: compiler.err.cant.apply.diamond.1: Neg09.Nested<X>, (compiler.misc.diamond.and.anon.class: Neg09.Nested<X>) 4 errors
--- a/test/tools/javac/generics/inference/6638712/T6638712a.out Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/generics/inference/6638712/T6638712a.out Tue Feb 14 10:29:36 2012 -0800 @@ -1,2 +1,2 @@ -T6638712a.java:16:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String> +T6638712a.java:16:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>) 1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086586/T7086586.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,19 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7086586 + * @summary Inference producing null type argument + * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java + */ +import java.util.List; + +class T7086586 { + + <T> List<T> m(List<? super T> dummy) { return null; } + + void test(List<?> l) { + String s = m(l).get(0); + Number n = m(l).get(0); + Exception e = m(l).get(0); + m(l).nonExistentMethod(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,5 @@ +T7086586.java:14:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) +T7086586.java:15:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) +T7086586.java:16:23: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) +T7086586.java:17:9: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) +4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086586/T7086586b.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2011, 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 7086586 + * + * @summary Inference producing null type argument + */ +import java.util.List; + +public class T7086586b { + + int assertionCount = 0; + + void assertTrue(boolean cond) { + if (!cond) { + throw new AssertionError(); + } + assertionCount++; + } + + <T> void m(List<? super T> dummy) { assertTrue(false); } + <T> void m(Object dummy) { assertTrue(true); } + + void test(List<?> l) { + m(l); + assertTrue(assertionCount == 1); + } + + public static void main(String[] args) { + new T7086586b().test(null); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086601/T7086601a.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,34 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7086601 + * @summary Error message bug: cause for method mismatch is 'null' + * @compile/fail/ref=T7086601a.out -XDrawDiagnostics T7086601a.java + */ + +class T7086601 { + static <S> void m1(Iterable<? super S> s1, Iterable<? super S> s2) { } + static void m1(Object o) {} + + static <S> void m2(Iterable<? super S> s1, Iterable<? super S> s2, Iterable<? super S> s3) { } + static void m2(Object o) {} + + @SafeVarargs + static <S> void m3(Iterable<? super S>... ss) { } + static void m3(Object o) {} + + static void test1(Iterable<String> is, Iterable<Integer> ii) { + m1(is, ii); + } + + static void test2(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) { + m2(is, ii, id); + } + + static void test3(Iterable<String> is, Iterable<Integer> ii) { + m3(is, ii); + } + + static void test4(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) { + m3(is, ii, id); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086601/T7086601a.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,5 @@ +T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))} +T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))} +T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))} +T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))} +4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/7086601/T7086601b.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2011, 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 7086601 + * @summary Error message bug: cause for method mismatch is 'null' + */ + +import com.sun.source.util.JavacTask; +import java.net.URI; +import java.util.Arrays; +import java.util.ArrayList; +import javax.tools.Diagnostic; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + + +public class T7086601b { + + static int checkCount = 0; + + enum TypeKind { + STRING("String", false), + INTEGER("Integer", false), + NUMBER("Number", false), + SERIALIZABLE("java.io.Serializable", true), + CLONEABLE("Cloneable", true), + X("X", false), + Y("Y", false), + Z("Z", false); + + String typeStr; + boolean isInterface; + + private TypeKind(String typeStr, boolean isInterface) { + this.typeStr = typeStr; + this.isInterface = isInterface; + } + + boolean isSubtypeof(TypeKind other) { + return (this == INTEGER && other == NUMBER || + this == Z && other == Y || + this == other); + } + } + + enum MethodCallKind { + ARITY_ONE("m(a1);", 1), + ARITY_TWO("m(a1, a2);", 2), + ARITY_THREE("m(a1, a2, a3);", 3); + + String invokeString; + int arity; + + private MethodCallKind(String invokeString, int arity) { + this.invokeString = invokeString; + this.arity = arity; + } + } + + public static void main(String... args) throws Exception { + + //create default shared JavaCompiler - reused across multiple compilations + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + + for (TypeKind a1 : TypeKind.values()) { + for (TypeKind a2 : TypeKind.values()) { + for (TypeKind a3 : TypeKind.values()) { + for (MethodCallKind mck : MethodCallKind.values()) { + new T7086601b(a1, a2, a3, mck).run(comp, fm); + } + } + } + } + System.out.println("Total check executed: " + checkCount); + } + + TypeKind a1; + TypeKind a2; + TypeKind a3; + MethodCallKind mck; + JavaSource source; + DiagnosticChecker diagChecker; + + T7086601b(TypeKind a1, TypeKind a2, TypeKind a3, MethodCallKind mck) { + this.a1 = a1; + this.a2 = a2; + this.a3 = a3; + this.mck = mck; + this.source = new JavaSource(); + this.diagChecker = new DiagnosticChecker(); + } + + class JavaSource extends SimpleJavaFileObject { + + final String bodyTemplate = "import java.util.List;\n"+ + "class Test {\n" + + " <Z> void m(List<? super Z> l1) { }\n" + + " <Z> void m(List<? super Z> l1, List<? super Z> l2) { }\n" + + " <Z> void m(List<? super Z> l1, List<? super Z> l2, List<? super Z> l3) { }\n" + + " <X,Y,Z extends Y> void test(List<#A1> a1, List<#A2> a2, List<#A3> a3) { #MC } }"; + + String source; + + public JavaSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + source = bodyTemplate.replace("#A1", a1.typeStr) + .replace("#A2", a2.typeStr).replace("#A3", a3.typeStr) + .replace("#MC", mck.invokeString); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, + null, null, Arrays.asList(source)); + try { + ct.analyze(); + } catch (Throwable ex) { + throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true)); + } + check(); + } + + void check() { + checkCount++; + + boolean errorExpected = false; + + if (mck.arity > 1) { + TypeKind[] argtypes = { a1, a2, a3 }; + ArrayList<TypeKind> classes = new ArrayList<>(); + for (int i = 0 ; i < mck.arity ; i ++ ) { + if (!argtypes[i].isInterface) { + classes.add(argtypes[i]); + } + } + boolean glb_exists = true; + for (TypeKind arg_i : classes) { + glb_exists = true; + for (TypeKind arg_j : classes) { + if (!arg_i.isSubtypeof(arg_j)) { + glb_exists = false; + break; + } + } + if (glb_exists) break; + } + errorExpected = !glb_exists; + } + + if (errorExpected != diagChecker.errorFound) { + throw new Error("invalid diagnostics for source:\n" + + source.getCharContent(true) + + "\nFound error: " + diagChecker.errorFound + + "\nExpected error: " + errorExpected); + } + } + + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { + + boolean errorFound; + + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { + errorFound = true; + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7062745/GenericOverrideTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2011, 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 7062745 + * @summary Regression: difference in overload resolution when two methods are maximally specific + */ + +import com.sun.source.util.JavacTask; +import java.net.URI; +import java.util.Arrays; +import javax.tools.Diagnostic; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +public class GenericOverrideTest { + + static int checkCount = 0; + + enum SignatureKind { + NON_GENERIC(""), + GENERIC("<X>"); + + String paramStr; + + private SignatureKind(String paramStr) { + this.paramStr = paramStr; + } + } + + enum ReturnTypeKind { + LIST("List"), + ARRAYLIST("ArrayList"); + + String retStr; + + private ReturnTypeKind(String retStr) { + this.retStr = retStr; + } + + boolean moreSpecificThan(ReturnTypeKind that) { + switch (this) { + case LIST: + return that == this; + case ARRAYLIST: + return that == LIST || that == ARRAYLIST; + default: throw new AssertionError("Unexpected ret kind: " + this); + } + } + } + + enum TypeArgumentKind { + NONE(""), + UNBOUND("<?>"), + INTEGER("<Number>"), + NUMBER("<Integer>"), + TYPEVAR("<X>"); + + String typeargStr; + + private TypeArgumentKind(String typeargStr) { + this.typeargStr = typeargStr; + } + + boolean compatibleWith(SignatureKind sig) { + switch (this) { + case TYPEVAR: return sig != SignatureKind.NON_GENERIC; + default: return true; + } + } + + boolean moreSpecificThan(TypeArgumentKind that, boolean strict) { + switch (this) { + case NONE: + return that == this || !strict; + case UNBOUND: + return that == this || that == NONE; + case INTEGER: + case NUMBER: + case TYPEVAR: + return that == this || that == NONE || that == UNBOUND; + default: throw new AssertionError("Unexpected typearg kind: " + this); + } + } + + boolean assignableTo(TypeArgumentKind that, SignatureKind sig) { + switch (this) { + case NONE: + //this case needs to workaround to javac's impl of 15.12.2.8 being too strict + //ideally should be just 'return true' (see 7067746) + return sig == SignatureKind.NON_GENERIC || that == NONE; + case UNBOUND: + return that == this || that == NONE; + case INTEGER: + case NUMBER: + return that == this || that == NONE || that == UNBOUND; + case TYPEVAR: + return true; + default: throw new AssertionError("Unexpected typearg kind: " + this); + } + } + } + + public static void main(String... args) throws Exception { + + //create default shared JavaCompiler - reused across multiple compilations + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + + for (SignatureKind sig1 : SignatureKind.values()) { + for (ReturnTypeKind rt1 : ReturnTypeKind.values()) { + for (TypeArgumentKind ta1 : TypeArgumentKind.values()) { + if (!ta1.compatibleWith(sig1)) continue; + for (SignatureKind sig2 : SignatureKind.values()) { + for (ReturnTypeKind rt2 : ReturnTypeKind.values()) { + for (TypeArgumentKind ta2 : TypeArgumentKind.values()) { + if (!ta2.compatibleWith(sig2)) continue; + for (ReturnTypeKind rt3 : ReturnTypeKind.values()) { + for (TypeArgumentKind ta3 : TypeArgumentKind.values()) { + if (!ta3.compatibleWith(SignatureKind.NON_GENERIC)) continue; + new GenericOverrideTest(sig1, rt1, ta1, sig2, rt2, ta2, rt3, ta3).run(comp, fm); + } + } + } + } + } + } + } + } + System.out.println("Total check executed: " + checkCount); + } + + SignatureKind sig1, sig2; + ReturnTypeKind rt1, rt2, rt3; + TypeArgumentKind ta1, ta2, ta3; + JavaSource source; + DiagnosticChecker diagChecker; + + GenericOverrideTest(SignatureKind sig1, ReturnTypeKind rt1, TypeArgumentKind ta1, + SignatureKind sig2, ReturnTypeKind rt2, TypeArgumentKind ta2, ReturnTypeKind rt3, TypeArgumentKind ta3) { + this.sig1 = sig1; + this.sig2 = sig2; + this.rt1 = rt1; + this.rt2 = rt2; + this.rt3 = rt3; + this.ta1 = ta1; + this.ta2 = ta2; + this.ta3 = ta3; + this.source = new JavaSource(); + this.diagChecker = new DiagnosticChecker(); + } + + class JavaSource extends SimpleJavaFileObject { + + String template = "import java.util.*;\n" + + "interface A { #S1 #R1#TA1 m(); }\n" + + "interface B { #S2 #R2#TA2 m(); }\n" + + "interface AB extends A, B {}\n" + + "class Test {\n" + + " void test(AB ab) { #R3#TA3 n = ab.m(); }\n" + + "}"; + + String source; + + public JavaSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + source = template.replace("#S1", sig1.paramStr). + replace("#S2", sig2.paramStr). + replace("#R1", rt1.retStr). + replace("#R2", rt2.retStr). + replace("#R3", rt3.retStr). + replace("#TA1", ta1.typeargStr). + replace("#TA2", ta2.typeargStr). + replace("#TA3", ta3.typeargStr); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, + null, null, Arrays.asList(source)); + try { + ct.analyze(); + } catch (Throwable ex) { + throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true)); + } + check(); + } + + void check() { + checkCount++; + + boolean errorExpected = false; + int mostSpecific = 0; + + //first check that either |R1| <: |R2| or |R2| <: |R1| + if (rt1 != rt2) { + if (!rt1.moreSpecificThan(rt2) && + !rt2.moreSpecificThan(rt1)) { + errorExpected = true; + } else { + mostSpecific = rt1.moreSpecificThan(rt2) ? 1 : 2; + } + } + + //check that either TA1 <= TA2 or TA2 <= TA1 (unless most specific return found above is raw) + if (!errorExpected) { + if (ta1 != ta2) { + boolean useStrictCheck = ta1.moreSpecificThan(ta2, true) || ta2.moreSpecificThan(ta1, true); + if (!ta1.moreSpecificThan(ta2, useStrictCheck) && + !ta2.moreSpecificThan(ta1, useStrictCheck)) { + errorExpected = true; + } else { + int mostSpecific2 = ta1.moreSpecificThan(ta2, useStrictCheck) ? 1 : 2; + if (mostSpecific != 0 && mostSpecific2 != mostSpecific) { + errorExpected = mostSpecific == 1 ? ta1 != TypeArgumentKind.NONE : ta2 != TypeArgumentKind.NONE; + } else { + mostSpecific = mostSpecific2; + } + } + } else if (mostSpecific == 0) { + //when no signature is better than the other, an arbitrary choice + //must be made - javac always picks the second signature + mostSpecific = 2; + } + } + + //finally, check that most specific return type is compatible with expected type + if (!errorExpected) { + ReturnTypeKind msrt = mostSpecific == 1 ? rt1 : rt2; + TypeArgumentKind msta = mostSpecific == 1 ? ta1 : ta2; + SignatureKind mssig = mostSpecific == 1 ? sig1 : sig2; + + if (!msrt.moreSpecificThan(rt3) || + !msta.assignableTo(ta3, mssig)) { + errorExpected = true; + } + } + + if (errorExpected != diagChecker.errorFound) { + throw new Error("invalid diagnostics for source:\n" + + source.getCharContent(true) + + "\nFound error: " + diagChecker.errorFound + + "\nExpected error: " + errorExpected); + } + } + + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { + + boolean errorFound; + + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { + errorFound = true; + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7062745/T7062745neg.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,18 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7062745 + * @summary Regression: difference in overload resolution when two methods are maximally specific + * @compile/fail/ref=T7062745neg.out -XDrawDiagnostics T7062745neg.java + */ + +import java.util.*; + +class T7062745neg { + interface A { List<Number> getList(); } + interface B { ArrayList getList(); } + interface AB extends A, B {} + + void test(AB ab) { + Number n = ab.getList().get(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7062745/T7062745neg.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,2 @@ +T7062745neg.java:16:36: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Object, java.lang.Number +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7062745/T7062745pos.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011, 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 7062745 + * @summary Regression: difference in overload resolution when two methods are maximally specific + * + * @compile T7062745pos.java + */ + +import java.util.*; + +class T7062745pos { + interface A { List<Number> getList(); } + interface B { List getList(); } + interface AB extends A, B {} + + void test(AB ab) { + Number n = ab.getList().get(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/jvm/T7024096.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,31 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7024096 + * @summary Stack trace has invalid line numbers + * @author Bruce Chapman + * @compile T7024096.java + * @run main T7024096 + */ + +public class T7024096 { + private static final int START = 14; // starting line number for the test + public static void main(String[] args) { + T7024096 m = new T7024096(); + m.nest(START); + m.nest(START + 1, m.nest(START + 1), m.nest(START + 1), + m.nest(START + 2), + m.nest(START + 3, m.nest(START + 3))); + } + + public T7024096 nest(int expectedline, T7024096... args) { + Exception e = new Exception("expected line#: " + expectedline); + int myline = e.getStackTrace()[1].getLineNumber(); + if( myline != expectedline) { + throw new RuntimeException("Incorrect line number " + + "expected: " + expectedline + + ", got: " + myline, e); + } + System.out.format("Got expected line number %d correct %n", myline); + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lib/CompileFail.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2011, 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. + */ + +import java.io.*; +import java.util.*; +import com.sun.tools.javac.main.Main; + +/* + * Utility class to emulate jtreg @compile/fail, but also checking the specific + * exit code, given as the first arg. + */ +public class CompileFail { + public static void main(String... args) { + if (args.length < 2) + throw new IllegalArgumentException("insufficient args"); + int expected_rc = getReturnCode(args[0]); + + List<String> javacArgs = new ArrayList<>(); + javacArgs.addAll(Arrays.asList( + "-bootclasspath", System.getProperty("sun.boot.class.path"), + "-d", "." + )); + + File testSrc = new File(System.getProperty("test.src")); + for (int i = 1; i < args.length; i++) { // skip first arg + String arg = args[i]; + if (arg.endsWith(".java")) + javacArgs.add(new File(testSrc, arg).getPath()); + else + javacArgs.add(arg); + } + + int rc = com.sun.tools.javac.Main.compile( + javacArgs.toArray(new String[javacArgs.size()])); + + if (rc != expected_rc) + throw new Error("unexpected exit code: " + rc + + ", expected: " + expected_rc); + } + + static int getReturnCode(String name) { + return Main.Result.valueOf(name).exitCode; + } + +}
--- a/test/tools/javac/lib/JavacTestingAbstractProcessor.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/lib/JavacTestingAbstractProcessor.java Tue Feb 14 10:29:36 2012 -0800 @@ -25,6 +25,7 @@ import javax.annotation.processing.*; import javax.lang.model.SourceVersion; import javax.lang.model.util.*; +import static javax.lang.model.SourceVersion.*; /** * An abstract annotation processor tailored to javac regression testing. @@ -95,4 +96,164 @@ messager = processingEnv.getMessager(); options = processingEnv.getOptions(); } + + /* + * The set of visitors below will directly extend the most recent + * corresponding platform visitor type. + */ + + @SupportedSourceVersion(RELEASE_8) + public static abstract class AbstractAnnotationValueVisitor<R, P> extends AbstractAnnotationValueVisitor8<R, P> { + + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractAnnotationValueVisitor() { + super(); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static abstract class AbstractElementVisitor<R, P> extends AbstractElementVisitor8<R, P> { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractElementVisitor(){ + super(); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static abstract class AbstractTypeVisitor<R, P> extends AbstractTypeVisitor8<R, P> { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractTypeVisitor() { + super(); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class ElementKindVisitor<R, P> extends ElementKindVisitor8<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected ElementKindVisitor() { + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected ElementKindVisitor(R defaultValue) { + super(defaultValue); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class ElementScanner<R, P> extends ElementScanner8<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected ElementScanner(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + */ + protected ElementScanner(R defaultValue){ + super(defaultValue); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class SimpleAnnotationValueVisitor<R, P> extends SimpleAnnotationValueVisitor8<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleAnnotationValueVisitor() { + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleAnnotationValueVisitor(R defaultValue) { + super(defaultValue); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class SimpleElementVisitor<R, P> extends SimpleElementVisitor8<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleElementVisitor(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleElementVisitor(R defaultValue){ + super(defaultValue); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class SimpleTypeVisitor<R, P> extends SimpleTypeVisitor8<R, P> { + /** + * Constructor for concrete subclasses; uses {@code null} for the + * default value. + */ + protected SimpleTypeVisitor(){ + super(null); + } + + /** + * Constructor for concrete subclasses; uses the argument for the + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected SimpleTypeVisitor(R defaultValue){ + super(defaultValue); + } + } + + @SupportedSourceVersion(RELEASE_8) + public static class TypeKindVisitor<R, P> extends TypeKindVisitor8<R, P> { + /** + * Constructor for concrete subclasses to call; uses {@code null} + * for the default value. + */ + protected TypeKindVisitor() { + super(null); + } + + /** + * Constructor for concrete subclasses to call; uses the argument + * for the default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} + */ + protected TypeKindVisitor(R defaultValue) { + super(defaultValue); + } + } }
--- a/test/tools/javac/multicatch/model/ModelChecker.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/multicatch/model/ModelChecker.java Tue Feb 14 10:29:36 2012 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 6993963 + * @bug 6993963 7025809 * @summary Project Coin: Use precise exception analysis for effectively final catch parameters * @library ../../lib * @build JavacTestingAbstractProcessor ModelChecker @@ -107,7 +107,7 @@ ; // Expected } - UnionType unionType = new SimpleTypeVisitor7<UnionType, Void>(){ + UnionType unionType = new SimpleTypeVisitor<UnionType, Void>(){ @Override protected UnionType defaultAction(TypeMirror e, Void p) {return null;}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/parser/StringFoldingTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2011, 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 7068902 + * @summary verify that string folding can be enabled or disabled + */ + +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.util.JavacTask; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +public class StringFoldingTest { + final JavaCompiler tool; + final JavaSource source; + + public StringFoldingTest() { + tool = ToolProvider.getSystemJavaCompiler(); + source = new JavaSource(); + } + + static class JavaSource extends SimpleJavaFileObject { + + final static String source = + "class C {String X=\"F\" + \"O\" + \"L\" + \"D\" + \"E\" + \"D\";}"; + + JavaSource() { + super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + public static void main(String... args) throws IOException { + StringFoldingTest t = new StringFoldingTest(); + t.run(false); + t.run(true); + } + + void run(boolean disableStringFolding) throws IOException { + List<String> argsList = new ArrayList<String>(); + if (disableStringFolding) { + argsList.add("-XDallowStringFolding=false"); + } + JavacTask ct = (JavacTask)tool.getTask(null, null, null, + argsList, + null, + Arrays.asList(source)); + Iterable<? extends CompilationUnitTree> trees = ct.parse(); + String text = trees.toString(); + System.out.println(text); + + if (disableStringFolding) { + if (text.contains("FOLDED")) { + throw new AssertionError("Expected string folding"); + } + } else { + if (!text.contains("FOLDED")) { + throw new AssertionError("Expected no string folding"); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/parser/netbeans/JavacParserTest.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,716 @@ +/* + * Copyright (c) 2011, 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 7073631 + * @summary tests error and diagnostics positions + * @author jan.lahoda@oracle.com + */ + +import com.sun.source.tree.BinaryTree; +import com.sun.source.tree.BlockTree; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.ExpressionStatementTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.ModifiersTree; +import com.sun.source.tree.StatementTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.Tree.Kind; +import com.sun.source.tree.VariableTree; +import com.sun.source.tree.WhileLoopTree; +import com.sun.source.util.SourcePositions; +import com.sun.source.util.TreeScanner; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.JavacTaskImpl; +import com.sun.tools.javac.tree.JCTree; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.DiagnosticListener; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +public class JavacParserTest extends TestCase { + final JavaCompiler tool; + public JavacParserTest(String testName) { + tool = ToolProvider.getSystemJavaCompiler(); + System.out.println("java.home=" + System.getProperty("java.home")); + } + + static class MyFileObject extends SimpleJavaFileObject { + + private String text; + + public MyFileObject(String text) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + this.text = text; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } + + public void testPositionForSuperConstructorCalls() throws IOException { + assert tool != null; + + String code = "package test; public class Test {public Test() {super();}}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + SourcePositions pos = Trees.instance(ct).getSourcePositions(); + + MethodTree method = + (MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); + ExpressionStatementTree es = + (ExpressionStatementTree) method.getBody().getStatements().get(0); + + assertEquals("testPositionForSuperConstructorCalls", + 72 - 24, pos.getStartPosition(cut, es)); + assertEquals("testPositionForSuperConstructorCalls", + 80 - 24, pos.getEndPosition(cut, es)); + + MethodInvocationTree mit = (MethodInvocationTree) es.getExpression(); + + assertEquals("testPositionForSuperConstructorCalls", + 72 - 24, pos.getStartPosition(cut, mit)); + assertEquals("testPositionForSuperConstructorCalls", + 79 - 24, pos.getEndPosition(cut, mit)); + + assertEquals("testPositionForSuperConstructorCalls", + 72 - 24, pos.getStartPosition(cut, mit.getMethodSelect())); + assertEquals("testPositionForSuperConstructorCalls", + 77 - 24, pos.getEndPosition(cut, mit.getMethodSelect())); + + } + + public void testPositionForEnumModifiers() throws IOException { + + String code = "package test; public enum Test {A;}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + SourcePositions pos = Trees.instance(ct).getSourcePositions(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + ModifiersTree mt = clazz.getModifiers(); + + assertEquals("testPositionForEnumModifiers", + 38 - 24, pos.getStartPosition(cut, mt)); + assertEquals("testPositionForEnumModifiers", + 44 - 24, pos.getEndPosition(cut, mt)); + } + + public void testNewClassWithEnclosing() throws IOException { + + + String code = "package test; class Test { " + + "class d {} private void method() { " + + "Object o = Test.this.new d(); } }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + SourcePositions pos = Trees.instance(ct).getSourcePositions(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + ExpressionTree est = + ((VariableTree) ((MethodTree) clazz.getMembers().get(1)).getBody().getStatements().get(0)).getInitializer(); + + assertEquals("testNewClassWithEnclosing", + 97 - 24, pos.getStartPosition(cut, est)); + assertEquals("testNewClassWithEnclosing", + 114 - 24, pos.getEndPosition(cut, est)); + } + + public void testPreferredPositionForBinaryOp() throws IOException { + + String code = "package test; public class Test {" + + "private void test() {" + + "Object o = null; boolean b = o != null && o instanceof String;" + + "} private Test() {}}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(0); + VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1); + BinaryTree cond = (BinaryTree) condSt.getInitializer(); + + JCTree condJC = (JCTree) cond; + + assertEquals("testNewClassWithEnclosing", + 117 - 24, condJC.pos); + } + + public void testPositionBrokenSource126732a() throws IOException { + String[] commands = new String[]{ + "return Runnable()", + "do { } while (true)", + "throw UnsupportedOperationException()", + "assert true", + "1 + 1",}; + + for (String command : commands) { + + String code = "package test;\n" + + "public class Test {\n" + + " public static void test() {\n" + + " " + command + " {\n" + + " new Runnable() {\n" + + " };\n" + + " }\n" + + "}"; + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, + null, null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(0); + List<? extends StatementTree> statements = + method.getBody().getStatements(); + + StatementTree ret = statements.get(0); + StatementTree block = statements.get(1); + + Trees t = Trees.instance(ct); + int len = code.indexOf(command + " {") + (command + " ").length(); + assertEquals(command, len, + t.getSourcePositions().getEndPosition(cut, ret)); + assertEquals(command, len, + t.getSourcePositions().getStartPosition(cut, block)); + } + } + + public void testPositionBrokenSource126732b() throws IOException { + String[] commands = new String[]{ + "break", + "break A", + "continue ", + "continue A",}; + + for (String command : commands) { + + String code = "package test;\n" + + "public class Test {\n" + + " public static void test() {\n" + + " while (true) {\n" + + " " + command + " {\n" + + " new Runnable() {\n" + + " };\n" + + " }\n" + + " }\n" + + "}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, + null, null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(0); + List<? extends StatementTree> statements = + ((BlockTree) ((WhileLoopTree) method.getBody().getStatements().get(0)).getStatement()).getStatements(); + + StatementTree ret = statements.get(0); + StatementTree block = statements.get(1); + + Trees t = Trees.instance(ct); + int len = code.indexOf(command + " {") + (command + " ").length(); + assertEquals(command, len, + t.getSourcePositions().getEndPosition(cut, ret)); + assertEquals(command, len, + t.getSourcePositions().getStartPosition(cut, block)); + } + } + + public void testErrorRecoveryForEnhancedForLoop142381() throws IOException { + + String code = "package test; class Test { " + + "private void method() { " + + "java.util.Set<String> s = null; for (a : s) {} } }"; + + final List<Diagnostic<? extends JavaFileObject>> errors = + new LinkedList<Diagnostic<? extends JavaFileObject>>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener<JavaFileObject>() { + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + CompilationUnitTree cut = ct.parse().iterator().next(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + StatementTree forStatement = + ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); + + assertEquals("testErrorRecoveryForEnhancedForLoop142381", + Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); + assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); + } + + public void testPositionAnnotationNoPackage187551() throws IOException { + + String code = "\n@interface Test {}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + + CompilationUnitTree cut = ct.parse().iterator().next(); + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + Trees t = Trees.instance(ct); + + assertEquals("testPositionAnnotationNoPackage187551", + 1, t.getSourcePositions().getStartPosition(cut, clazz)); + } + + public void testPositionsSane() throws IOException { + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List<? extends java.util.List<? extends String>> l; " + + "} }"); + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List<? super java.util.List<? super String>> l; " + + "} }"); + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List<? super java.util.List<?>> l; } }"); + } + + private void performPositionsSanityTest(String code) throws IOException { + + final List<Diagnostic<? extends JavaFileObject>> errors = + new LinkedList<Diagnostic<? extends JavaFileObject>>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener<JavaFileObject>() { + + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + final CompilationUnitTree cut = ct.parse().iterator().next(); + final Trees trees = Trees.instance(ct); + + new TreeScanner<Void, Void>() { + + private long parentStart = 0; + private long parentEnd = Integer.MAX_VALUE; + + @Override + public Void scan(Tree node, Void p) { + if (node == null) { + return null; + } + + long start = trees.getSourcePositions().getStartPosition(cut, node); + + if (start == (-1)) { + return null; //synthetic tree + } + assertTrue(node.toString() + ":" + start + "/" + parentStart, + parentStart <= start); + + long prevParentStart = parentStart; + + parentStart = start; + + long end = trees.getSourcePositions().getEndPosition(cut, node); + + assertTrue(node.toString() + ":" + end + "/" + parentEnd, + end <= parentEnd); + + long prevParentEnd = parentEnd; + + parentEnd = end; + + super.scan(node, p); + + parentStart = prevParentStart; + parentEnd = prevParentEnd; + + return null; + } + + private void assertTrue(String message, boolean b) { + if (!b) fail(message); + } + }.scan(cut, null); + } + + public void testCorrectWilcardPositions() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List<? extends List<? extends String>> l; } }", + + Arrays.asList("List<? extends List<? extends String>> l;", + "List<? extends List<? extends String>>", + "List", + "? extends List<? extends String>", + "List<? extends String>", + "List", + "? extends String", + "String")); + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List<? super List<? super String>> l; } }", + + Arrays.asList("List<? super List<? super String>> l;", + "List<? super List<? super String>>", + "List", + "? super List<? super String>", + "List<? super String>", + "List", + "? super String", + "String")); + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List<? super List<?>> l; } }", + + Arrays.asList("List<? super List<?>> l;", + "List<? super List<?>>", + "List", + "? super List<?>", + "List<?>", + "List", + "?")); + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { " + + "List<? extends List<? extends List<? extends String>>> l; } }", + + Arrays.asList("List<? extends List<? extends List<? extends String>>> l;", + "List<? extends List<? extends List<? extends String>>>", + "List", + "? extends List<? extends List<? extends String>>", + "List<? extends List<? extends String>>", + "List", + "? extends List<? extends String>", + "List<? extends String>", + "List", + "? extends String", + "String")); + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { " + + "List<? extends List<? extends List<? extends String >>> l; } }", + Arrays.asList("List<? extends List<? extends List<? extends String >>> l;", + "List<? extends List<? extends List<? extends String >>>", + "List", + "? extends List<? extends List<? extends String >>", + "List<? extends List<? extends String >>", + "List", + "? extends List<? extends String >", + "List<? extends String >", + "List", + "? extends String", + "String")); + } + + public void performWildcardPositionsTest(final String code, + List<String> golden) throws IOException { + + final List<Diagnostic<? extends JavaFileObject>> errors = + new LinkedList<Diagnostic<? extends JavaFileObject>>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener<JavaFileObject>() { + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + final CompilationUnitTree cut = ct.parse().iterator().next(); + final List<String> content = new LinkedList<String>(); + final Trees trees = Trees.instance(ct); + + new TreeScanner<Void, Void>() { + @Override + public Void scan(Tree node, Void p) { + if (node == null) { + return null; + } + long start = trees.getSourcePositions().getStartPosition(cut, node); + + if (start == (-1)) { + return null; //synthetic tree + } + long end = trees.getSourcePositions().getEndPosition(cut, node); + String s = code.substring((int) start, (int) end); + content.add(s); + + return super.scan(node, p); + } + }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); + + assertEquals("performWildcardPositionsTest",golden.toString(), + content.toString()); + } + + public void testStartPositionForMethodWithoutModifiers() throws IOException { + + String code = "package t; class Test { <T> void t() {} }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + MethodTree mt = (MethodTree) clazz.getMembers().get(0); + Trees t = Trees.instance(ct); + int start = (int) t.getSourcePositions().getStartPosition(cut, mt); + int end = (int) t.getSourcePositions().getEndPosition(cut, mt); + + assertEquals("testStartPositionForMethodWithoutModifiers", + "<T> void t() {}", code.substring(start, end)); + } + + public void testStartPositionEnumConstantInit() throws IOException { + + String code = "package t; enum Test { AAA; }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + VariableTree enumAAA = (VariableTree) clazz.getMembers().get(0); + Trees t = Trees.instance(ct); + int start = (int) t.getSourcePositions().getStartPosition(cut, + enumAAA.getInitializer()); + + assertEquals("testStartPositionEnumConstantInit", -1, start); + } + + public void testVariableInIfThen1() throws IOException { + + String code = "package t; class Test { " + + "private static void t(String name) { " + + "if (name != null) String nn = name.trim(); } }"; + + DiagnosticCollector<JavaFileObject> coll = + new DiagnosticCollector<JavaFileObject>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List<String> codes = new LinkedList<String>(); + + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen1", + Arrays.<String>asList("compiler.err.variable.not.allowed"), + codes); + } + + public void testVariableInIfThen2() throws IOException { + + String code = "package t; class Test { " + + "private static void t(String name) { " + + "if (name != null) class X {} } }"; + DiagnosticCollector<JavaFileObject> coll = + new DiagnosticCollector<JavaFileObject>(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List<String> codes = new LinkedList<String>(); + + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen2", + Arrays.<String>asList("compiler.err.class.not.allowed"), codes); + } + + public void testVariableInIfThen3() throws IOException { + + String code = "package t; class Test { "+ + "private static void t(String name) { " + + "if (name != null) abstract } }"; + DiagnosticCollector<JavaFileObject> coll = + new DiagnosticCollector<JavaFileObject>(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List<String> codes = new LinkedList<String>(); + + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen3", + Arrays.<String>asList("compiler.err.illegal.start.of.expr"), + codes); + } + + //see javac bug #6882235, NB bug #98234: + public void testMissingExponent() throws IOException { + + String code = "\nclass Test { { System.err.println(0e); } }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + + assertNotNull(ct.parse().iterator().next()); + } + + public void testTryResourcePos() throws IOException { + + final String code = "package t; class Test { " + + "{ try (java.io.InputStream in = null) { } } }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + + new TreeScanner<Void, Void>() { + @Override + public Void visitVariable(VariableTree node, Void p) { + if ("in".contentEquals(node.getName())) { + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; + System.out.println(node.getName() + "," + var.pos); + assertEquals("testTryResourcePos", "in = null) { } } }", + code.substring(var.pos)); + } + return super.visitVariable(node, p); + } + }.scan(cut, null); + } + + public void testVarPos() throws IOException { + + final String code = "package t; class Test { " + + "{ java.io.InputStream in = null; } }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + + new TreeScanner<Void, Void>() { + + @Override + public Void visitVariable(VariableTree node, Void p) { + if ("in".contentEquals(node.getName())) { + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; + assertEquals("testVarPos","in = null; } }", + code.substring(var.pos)); + } + return super.visitVariable(node, p); + } + }.scan(cut, null); + } + + void testsNotWorking() throws IOException { + + // Fails with nb-javac, needs further investigation + testPositionBrokenSource126732a(); + testPositionBrokenSource126732b(); + + // Fails, these tests yet to be addressed + testVariableInIfThen1(); + testVariableInIfThen2(); + testPositionForEnumModifiers(); + testStartPositionEnumConstantInit(); + } + void testPositions() throws IOException { + testPositionsSane(); + testCorrectWilcardPositions(); + testPositionAnnotationNoPackage187551(); + testPositionForSuperConstructorCalls(); + testPreferredPositionForBinaryOp(); + testStartPositionForMethodWithoutModifiers(); + testVarPos(); + testVariableInIfThen3(); + testTryResourcePos(); + } + + public static void main(String... args) throws IOException { + JavacParserTest jpt = new JavacParserTest("JavacParserTest"); + jpt.testPositions(); + System.out.println("PASS"); + } +} + +abstract class TestCase { + + void assertEquals(String message, int i, int pos) { + if (i != pos) { + fail(message); + } + } + + void assertFalse(String message, boolean empty) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + void assertEquals(String message, int i, long l) { + if (i != l) { + fail(message + ":" + i + ":" + l); + } + } + + void assertEquals(String message, Object o1, Object o2) { + System.out.println(o1); + System.out.println(o2); + if (o1 != null && o2 != null && !o1.equals(o2)) { + fail(message); + } + if (o1 == null && o2 != null) { + fail(message); + } + } + + void assertNotNull(Object o) { + if (o == null) { + fail(); + } + } + + void fail() { + fail("test failed"); + } + + void fail(String message) { + throw new RuntimeException(message); + } +}
--- a/test/tools/javac/processing/errors/TestOptionSyntaxErrors.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/errors/TestOptionSyntaxErrors.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -27,14 +27,14 @@ * @summary Test that annotation processor options with illegal syntax are rejected * @author Joseph D. Darcy * @library ../../lib - * @build JavacTestingAbstractProcessor + * @build JavacTestingAbstractProcessor CompileFail * @compile TestOptionSyntaxErrors.java - * @compile/fail -A TestOptionSyntaxErrors.java - * @compile/fail -A8adOption TestOptionSyntaxErrors.java - * @compile/fail -A8adOption=1worseOption TestOptionSyntaxErrors.java - * @compile/fail -processor TestOptionSyntaxErrors -proc:only -A TestOptionSyntaxErrors.java - * @compile/fail -processor TestOptionSyntaxErrors -proc:only -A8adOption TestOptionSyntaxErrors.java - * @compile/fail -processor TestOptionSyntaxErrors -proc:only -A8adOption=1worseOption TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -A TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -A8adOption TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -A8adOption=1worseOption TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A8adOption TestOptionSyntaxErrors.java + * @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A8adOption=1worseOption TestOptionSyntaxErrors.java */ import java.util.Set;
--- a/test/tools/javac/processing/errors/TestReturnCode.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/errors/TestReturnCode.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -27,25 +27,25 @@ * @summary Test that an erroneous return code results from raising an error. * @author Joseph D. Darcy * @library ../../lib - * @build JavacTestingAbstractProcessor + * @build JavacTestingAbstractProcessor CompileFail * @compile TestReturnCode.java * - * @compile -processor TestReturnCode -proc:only Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AErrorOnLast Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AErrorOnLast -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnFirst Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast Foo.java - * @compile/fail -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java + * @compile -processor TestReturnCode -proc:only Foo.java + * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnFirst Foo.java + * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast Foo.java + * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnFirst Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast Foo.java + * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java */ import java.util.Set;
--- a/test/tools/javac/processing/errors/TestSuppression.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/errors/TestSuppression.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, 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 @@ -35,6 +35,7 @@ import javax.tools.*; import com.sun.source.util.JavacTask; +import com.sun.tools.javac.api.ClientCodeWrapper; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.JCDiagnostic; @@ -171,7 +172,7 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) { System.err.println((++total) + ": " - + "resolveError:" + isResolveError((JCDiagnostic) diagnostic) + "\n" + + "resolveError:" + isResolveError(unwrap(diagnostic)) + "\n" + diagnostic); Diagnostic.Kind dk = diagnostic.getKind(); Integer c = counts.get(dk); @@ -181,6 +182,14 @@ private static boolean isResolveError(JCDiagnostic d) { return d.isFlagSet(RESOLVE_ERROR); } + + private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic instanceof JCDiagnostic) + return (JCDiagnostic) diagnostic; + if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper) + return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d; + throw new IllegalArgumentException(); + } } @SupportedAnnotationTypes("*")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/loader/testClose/TestClose.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2011, 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 7092965 + * @summary javac should not close processorClassLoader before end of compilation + */ + +import com.sun.source.util.JavacTask; +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.api.ClientCodeWrapper.Trusted; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.processing.JavacProcessingEnvironment; +import com.sun.tools.javac.util.Context; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.annotation.processing.ProcessingEnvironment; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +/* + * The test compiles an annotation processor and a helper class into a + * custom classes directory. + * + * It then uses them while compiling a dummy file, with the custom classes + * directory on the processor path, thus guaranteeing that references to + * these class are satisfied by the processor class loader. + * + * The annotation processor uses the javac TaskListener to run code + * after annotation processing has completed, to verify that the classloader + * is not closed until the end of the compilation. + */ + +@Trusted // avoids use of ClientCodeWrapper +public class TestClose implements TaskListener { + public static final String annoProc = + "import java.util.*;\n" + + "import javax.annotation.processing.*;\n" + + "import javax.lang.model.*;\n" + + "import javax.lang.model.element.*;\n" + + "import com.sun.source.util.*;\n" + + "import com.sun.tools.javac.processing.*;\n" + + "import com.sun.tools.javac.util.*;\n" + + "@SupportedAnnotationTypes(\"*\")\n" + + "public class AnnoProc extends AbstractProcessor {\n" + + " @Override\n" + + " public SourceVersion getSupportedSourceVersion() {\n" + + " return SourceVersion.latest();\n" + + " }\n" + + " @Override\n" + + " public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + + " System.out.println(\"in AnnoProc.process\");\n" + + " final ClassLoader cl = getClass().getClassLoader();\n" + + " if (roundEnv.processingOver()) {\n" + + " TestClose.add(processingEnv, new Runnable() {\n" + + " public void run() {\n" + + " System.out.println(getClass().getName() + \": run()\");\n" + + " try {\n" + + " cl.loadClass(\"Callback\")\n" + + " .asSubclass(Runnable.class)\n" + + " .newInstance()\n" + + " .run();\n" + + " } catch (ReflectiveOperationException e) {\n" + + " throw new Error(e);\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + " return true;\n" + + " }\n" + + "}\n"; + + public static final String callback = + "public class Callback implements Runnable {\n" + + " public void run() {\n" + + " System.out.println(getClass().getName() + \": run()\");\n" + + " }\n" + + "}"; + + public static void main(String... args) throws Exception { + new TestClose().run(); + } + + void run() throws IOException { + JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); + + File classes = new File("classes"); + classes.mkdirs(); + File extraClasses = new File("extraClasses"); + extraClasses.mkdirs(); + + System.out.println("compiling classes to extraClasses"); + { // setup class in extraClasses + fm.setLocation(StandardLocation.CLASS_OUTPUT, + Collections.singleton(extraClasses)); + List<? extends JavaFileObject> files = Arrays.asList( + new MemFile("AnnoProc.java", annoProc), + new MemFile("Callback.java", callback)); + JavacTask task = tool.getTask(null, fm, null, null, null, files); + check(task.call()); + } + + System.out.println("compiling dummy to classes with anno processor"); + { // use that class in a TaskListener after processing has completed + PrintStream prev = System.out; + String out; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (PrintStream ps = new PrintStream(baos)) { + System.setOut(ps); + File testClasses = new File(System.getProperty("test.classes")); + fm.setLocation(StandardLocation.CLASS_OUTPUT, + Collections.singleton(classes)); + fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, + Arrays.asList(extraClasses, testClasses)); + List<? extends JavaFileObject> files = Arrays.asList( + new MemFile("my://dummy", "class Dummy { }")); + List<String> options = Arrays.asList("-processor", "AnnoProc"); + JavacTask task = tool.getTask(null, fm, null, options, null, files); + task.setTaskListener(this); + check(task.call()); + } finally { + System.setOut(prev); + out = baos.toString(); + if (!out.isEmpty()) + System.out.println(out); + } + check(out.contains("AnnoProc$1: run()")); + check(out.contains("Callback: run()")); + } + } + + @Override + public void started(TaskEvent e) { + System.out.println("Started: " + e); + } + + @Override + public void finished(TaskEvent e) { + System.out.println("Finished: " + e); + if (e.getKind() == TaskEvent.Kind.ANALYZE) { + for (Runnable r: runnables) { + System.out.println("running " + r); + r.run(); + } + } + } + + void check(boolean b) { + if (!b) + throw new AssertionError(); + } + + + public static void add(ProcessingEnvironment env, Runnable r) { + try { + Context c = ((JavacProcessingEnvironment) env).getContext(); + Object o = c.get(TaskListener.class); + // The TaskListener is an instanceof TestClose, but when using the + // default class loaders. the taskListener uses a different + // instance of Class<TestClose> than the anno processor. + // If you try to evaluate + // TestClose tc = (TestClose) (o). + // you get the following somewhat confusing error: + // java.lang.ClassCastException: TestClose cannot be cast to TestClose + // The workaround is to access the fields of TestClose with reflection. + Field f = o.getClass().getField("runnables"); + @SuppressWarnings("unchecked") + List<Runnable> runnables = (List<Runnable>) f.get(o); + runnables.add(r); + } catch (Throwable t) { + System.err.println(t); + } + } + + public List<Runnable> runnables = new ArrayList<>(); + + class MemFile extends SimpleJavaFileObject { + public final String text; + + MemFile(String name, String text) { + super(URI.create(name), JavaFileObject.Kind.SOURCE); + this.text = text; + } + + @Override + public String getName() { + return uri.toString(); + } + + @Override + public String getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/loader/testClose/TestClose2.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2011, 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 7092965 + * @summary javac should not close processorClassLoader before end of compilation + */ + +import com.sun.source.util.JavacTask; +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.util.Context; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +@SupportedAnnotationTypes("*") +public class TestClose2 extends AbstractProcessor implements TaskListener { + + public static void main(String... args) throws Exception { + new TestClose2().run(); + } + + void run() throws IOException { + File testSrc = new File(System.getProperty("test.src")); + File testClasses = new File(System.getProperty("test.classes")); + + JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); + final ClassLoader cl = getClass().getClassLoader(); + Context c = new Context(); + StandardJavaFileManager fm = new JavacFileManager(c, true, null) { + @Override + protected ClassLoader getClassLoader(URL[] urls) { + return new URLClassLoader(urls, cl) { + @Override + public void close() throws IOException { + System.err.println(getClass().getName() + " closing"); + TestClose2.this.closedCount++; + TestClose2.this.closedIsLast = true; + super.close(); + } + }; + } + }; + + fm.setLocation(StandardLocation.CLASS_OUTPUT, + Collections.singleton(new File("."))); + fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, + Collections.singleton(testClasses)); + Iterable<? extends JavaFileObject> files = + fm.getJavaFileObjects(new File(testSrc, TestClose2.class.getName() + ".java")); + List<String> options = Arrays.asList( + "-processor", TestClose2.class.getName()); + + JavacTask task = tool.getTask(null, fm, null, options, null, files); + task.setTaskListener(this); + + if (!task.call()) + throw new Error("compilation failed"); + + if (closedCount == 0) + throw new Error("no closing message"); + else if (closedCount > 1) + throw new Error(closedCount + " closed messages"); + + if (!closedIsLast) + throw new Error("closing message not last"); + } + + // AbstractProcessor methods + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + Messager messager = processingEnv.getMessager(); + messager.printMessage(Diagnostic.Kind.NOTE, "processing"); + return true; + } + + // TaskListener methods + + @Override + public void started(TaskEvent e) { + System.err.println("Started: " + e); + closedIsLast = false; + } + + @Override + public void finished(TaskEvent e) { + System.err.println("Finished: " + e); + closedIsLast = false; + } + + // + + int closedCount = 0; + boolean closedIsLast = false; +}
--- a/test/tools/javac/processing/model/6194785/T6194785.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/6194785/T6194785.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -21,7 +21,7 @@ * questions. */ -/** +/* * @test * @bug 6194785 * @summary ParameterDeclaration.getSimpleName does not return actual name from class files @@ -40,9 +40,8 @@ public class T6194785 extends JavacTestingAbstractProcessor { public boolean process(Set<? extends TypeElement> annotations, - RoundEnvironment roundEnvironment) - { - class Scan extends ElementScanner7<Void,Void> { + RoundEnvironment roundEnvironment) { + class Scan extends ElementScanner<Void,Void> { @Override public Void visitExecutable(ExecutableElement e, Void ignored) { for (VariableElement p : e.getParameters())
--- a/test/tools/javac/processing/model/TestSymtabItems.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/TestSymtabItems.java Tue Feb 14 10:29:36 2012 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021183 + * @bug 7021183 7025809 * @summary 269: assertion failure getting enclosing element of an undefined name */ @@ -37,9 +37,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; import javax.lang.model.type.UnknownTypeException; -import javax.lang.model.util.ElementScanner7; -import javax.lang.model.util.SimpleTypeVisitor7; -import javax.lang.model.util.Types; +import javax.lang.model.util.*; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symtab; @@ -112,7 +110,7 @@ int errors; - class ElemPrinter extends ElementScanner7<Void, Void> { + class ElemPrinter extends ElementScanner8<Void, Void> { @Override public Void visitPackage(PackageElement e, Void p) { show("package", e);
--- a/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Tue Feb 14 10:29:36 2012 -0800 @@ -24,7 +24,7 @@ /* * @test - * @bug 6639645 7026414 + * @bug 6639645 7026414 7025809 * @summary Modeling type implementing missing interfaces * @library ../../../../lib * @build JavacTestingAbstractProcessor TestMissingElement @@ -104,7 +104,7 @@ private String asString(TypeMirror t) { if (t == null) return "[typ:null]"; - return t.accept(new SimpleTypeVisitor7<String, Void>() { + return t.accept(new SimpleTypeVisitor<String, Void>() { @Override public String defaultAction(TypeMirror t, Void ignore) { return "[typ:" + t.toString() + "]"; @@ -135,7 +135,7 @@ private String asString(Element e) { if (e == null) return "[elt:null]"; - return e.accept(new SimpleElementVisitor7<String, Void>() { + return e.accept(new SimpleElementVisitor<String, Void>() { @Override public String defaultAction(Element e, Void ignore) { return "[elt:" + e.getKind() + " " + e.toString() + "]";
--- a/test/tools/javac/processing/model/element/TestResourceVariable.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/element/TestResourceVariable.java Tue Feb 14 10:29:36 2012 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 6911256 6964740 6967842 6961571 + * @bug 6911256 6964740 6967842 6961571 7025809 * @summary Test that the resource variable kind is appropriately set * @author Joseph D. Darcy * @library ../../../lib @@ -44,8 +44,8 @@ /** * Using the tree API, retrieve element representations of the - * resource of an ARM block and verify their kind tags are set - * appropriately. + * resource of a try-with-resources statement and verify their kind + * tags are set appropriately. */ public class TestResourceVariable extends JavacTestingAbstractProcessor implements AutoCloseable { int resourceVariableCount = 0; @@ -82,7 +82,7 @@ /** * Verify that a resource variable modeled as an element behaves - * as expected under 6 and 7 specific visitors. + * as expected under 6 and latest specific visitors. */ private static void testResourceVariable(Element element) { ElementVisitor visitor6 = new ElementKindVisitor6<Void, Void>() {}; @@ -94,7 +94,8 @@ ; // Expected. } - ElementKindVisitor7 visitor7 = new ElementKindVisitor7<Object, Void>() { + ElementKindVisitor visitorLatest = + new ElementKindVisitor<Object, Void>() { @Override public Object visitVariableAsResourceVariable(VariableElement e, Void p) { @@ -102,7 +103,7 @@ } }; - if (visitor7.visit(element) == null) { + if (visitorLatest.visit(element) == null) { throw new RuntimeException("Null result of resource variable visitation."); } }
--- a/test/tools/javac/processing/model/type/NoTypes.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/type/NoTypes.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6418666 6423973 6453386 + * @bug 6418666 6423973 6453386 7025809 * @summary Test the NoTypes: VOID, PACKAGE, NONE * @author Scott Seligman * @library ../../../lib @@ -75,7 +75,7 @@ verifyKind(NONE, types.getNoType(NONE)); // The return type of a constructor or void method is VOID. - class Scanner extends ElementScanner7<Void, Void> { + class Scanner extends ElementScanner<Void, Void> { @Override public Void visitExecutable(ExecutableElement e, Void p) { verifyKind(VOID, e.getReturnType()); @@ -89,11 +89,11 @@ } /** - * Verify that a NoType instance is of a particular kind, - * and that TypeKindVisitor7 properly dispatches on it. + * Verify that a NoType instance is of a particular kind, and that + * the latest TypeKindVisitor properly dispatches on it. */ private void verifyKind(TypeKind kind, TypeMirror type) { - class Vis extends TypeKindVisitor7<TypeKind, Void> { + class Vis extends TypeKindVisitor<TypeKind, Void> { @Override public TypeKind visitNoTypeAsVoid(NoType t, Void p) { return VOID; @@ -111,9 +111,7 @@ throw new AssertionError(); } - // Fodder for the tests - interface I { }
--- a/test/tools/javac/processing/model/type/TestUnionType.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/type/TestUnionType.java Tue Feb 14 10:29:36 2012 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 7029150 + * @bug 7029150 7025809 * @summary Test support for union types * @library ../../../lib */ @@ -39,7 +39,6 @@ import com.sun.source.tree.*; import com.sun.source.util.*; - public class TestUnionType extends JavacTestingAbstractProcessor { enum TestKind { SingleType("E1", "E1", @@ -194,7 +193,7 @@ } } - class TypePrinter extends SimpleTypeVisitor7<String, Void> { + class TypePrinter extends SimpleTypeVisitor<String, Void> { @Override protected String defaultAction(TypeMirror tm, Void ignore) { return String.valueOf(tm.getKind());
--- a/test/tools/javac/processing/model/util/deprecation/TestDeprecation.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/processing/model/util/deprecation/TestDeprecation.java Tue Feb 14 10:29:36 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011 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 @@ -68,7 +68,7 @@ return true; } - private class DeprecationChecker extends ElementScanner7<Boolean,Void> { + private class DeprecationChecker extends ElementScanner<Boolean,Void> { private Elements elementUtils; private boolean failure; DeprecationChecker() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/tree/TestToString.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2011, 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 7080267 + * @summary Call to toString() from an ExpressionStatementTree doesn't take in + * consideration the ";" at the end + */ + +import com.sun.source.tree.BlockTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.StatementTree; +import com.sun.source.tree.Tree; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; + +import com.sun.source.util.JavacTask; +import com.sun.source.util.TreeScanner; +import com.sun.tools.javac.api.JavacTool; + +public class TestToString { + String[] statements = { + "i = i + 1;", + "i++;", + "m();", + ";", + "if (i == 0) return;", + "while (i > 0) i--;", + "{ }", + "{ i++; }", + "class C { }" + }; + + public static void main(String... args) throws Exception { + new TestToString().run(); + } + + void run() throws Exception { + for (String s: statements) { + test(s); + } + + if (errors > 0) + throw new Exception(errors + " errors found"); + } + + void test(String stmt) throws IOException { + System.err.println("Test: " + stmt); + List<String> options = Collections.<String>emptyList(); + List<? extends JavaFileObject> files = Arrays.asList(new JavaSource(stmt)); + JavacTask t = tool.getTask(null, fm, null, options, null, files); + checkEqual(scan(t.parse()), stmt); + } + + String scan(Iterable<? extends CompilationUnitTree> trees) { + class Scanner extends TreeScanner<Void,StringBuilder> { + String scan(Iterable<? extends Tree> trees) { + StringBuilder sb = new StringBuilder(); + scan(trees, sb); + return sb.toString(); + } + @Override + public Void scan(Tree tree, StringBuilder sb) { + if (print && tree instanceof StatementTree) { + sb.append(PREFIX); + sb.append(tree); + sb.append(SUFFIX); + return null; + } else { + return super.scan(tree, sb); + } + } + @Override + public Void visitBlock(BlockTree tree, StringBuilder sb) { + print = true; + try { + return super.visitBlock(tree, sb); + } finally { + print = false; + } + } + boolean print = false; + } + return new Scanner().scan(trees); + } + + void checkEqual(String found, String expect) { + boolean match = (found == null) ? (expect == null) : + expect.equals(found + .replaceAll("^\\Q" + PREFIX + "\\E\\s*", "") + .replaceAll("\\s*\\Q" + SUFFIX + "\\E$", "") + .replaceAll("\\s+", " ")); + + if (!match) + error("Mismatch: expected: " + expect + " found: " + found); + } + + + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + static final String PREFIX = "#<"; + static final String SUFFIX = "#>"; + + JavacTool tool = JavacTool.create(); + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); + int errors = 0; + + static class JavaSource extends SimpleJavaFileObject { + + String source = + "class Test {\n" + + " int i;\n" + + " void m() {\n" + + " #S\n" + + " }\n" + + "}"; + + public JavaSource(String stmt) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + source = source.replace("#S", stmt); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } +}
--- a/test/tools/javac/util/context/T7021650.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/util/context/T7021650.java Tue Feb 14 10:29:36 2012 -0800 @@ -101,13 +101,13 @@ StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); - int rc = m.compile(args, context); + Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); - if (rc != 0) - throw new Exception("compilation failed unexpectedly: rc=" + rc); + if (!res.isOK()) + throw new Exception("compilation failed unexpectedly: result=" + res); } void checkEqual(String label, int found, int expect) throws Exception {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/warnings/7090499/T7090499.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,37 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7094099 + * @summary -Xlint:rawtypes + * @compile/fail/ref=T7090499.out -XDrawDiagnostics -Xlint:rawtypes T7090499.java + */ + + +class T7090499<E> { + + static class B<X> {} + + class A<X> { + class X {} + class Z<Y> {} + } + + T7090499 t = new T7090499() { //raw warning (2) + + A.X x1;//raw warning + A.Z z1;//raw warning + + T7090499.B<Integer> b1;//ok + T7090499.B b2;//raw warning + + A<String>.X x2;//ok + A<String>.Z<Integer> z2;//ok + A<B>.Z<A<B>> z3;//raw warning (2) + + void test(Object arg1, B arg2) {//raw warning + boolean b = arg1 instanceof A;//ok + Object a = (A)arg1;//ok + A a2 = new A() {};//raw warning (2) + a2.new Z() {};//raw warning + } + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/warnings/7090499/T7090499.out Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,17 @@ +T7090499.java:18:5: compiler.warn.raw.class.use: T7090499, T7090499<E> +T7090499.java:18:22: compiler.warn.raw.class.use: T7090499, T7090499<E> +T7090499.java:20:10: compiler.warn.raw.class.use: T7090499.A.X, T7090499<E>.A<X>.X +T7090499.java:21:10: compiler.warn.raw.class.use: T7090499.A.Z, T7090499<E>.A<X>.Z<Y> +T7090499.java:24:17: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X> +T7090499.java:26:10: compiler.err.improperly.formed.type.inner.raw.param +T7090499.java:27:10: compiler.err.improperly.formed.type.inner.raw.param +T7090499.java:28:18: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X> +T7090499.java:28:17: compiler.err.improperly.formed.type.inner.raw.param +T7090499.java:28:11: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X> +T7090499.java:28:10: compiler.err.improperly.formed.type.inner.raw.param +T7090499.java:30:32: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X> +T7090499.java:33:13: compiler.warn.raw.class.use: T7090499.A, T7090499<E>.A<X> +T7090499.java:33:24: compiler.warn.raw.class.use: T7090499.A, T7090499<E>.A<X> +T7090499.java:34:20: compiler.warn.raw.class.use: T7090499.A.Z, T7090499<E>.A<X>.Z<Y> +4 errors +11 warnings
--- a/test/tools/javac/warnings/Serial.java Tue Jul 19 11:05:57 2011 -0700 +++ b/test/tools/javac/warnings/Serial.java Tue Feb 14 10:29:36 2012 -0800 @@ -29,7 +29,6 @@ * @compile -Xlint:all Serial.java * @compile -Werror Serial.java * @compile/fail -Werror -Xlint:serial Serial.java - * @compile/fail -Werror -Xlint:all,-path T4994049/ Serial.java */ import java.io.Serializable;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javadoc/parser/7091528/T7091528.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2009, 2011, 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 7091528 + * @summary javadoc attempts to parse .class files + * @compile p/C1.java p/q/C2.java + * @run main T7091528 + */ + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; + +public class T7091528 { + public static void main(String... args) { + new T7091528().run(); + } + + void run() { + File testSrc = new File(System.getProperty("test.src")); + File testClasses = new File(System.getProperty("test.classes")); + String[] args = { + "-d", ".", + "-sourcepath", testClasses + File.pathSeparator + testSrc, + "-subpackages", + "p" + }; + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + String doclet = com.sun.tools.doclets.standard.Standard.class.getName(); + int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, doclet, args); + pw.close(); + + String out = sw.toString(); + if (!out.isEmpty()) { + System.err.println(out); + } + + if (rc != 0) + System.err.println("javadoc failed: exit code = " + rc); + + if (out.matches("(?s).*p/[^ ]+\\.class.*")) + throw new Error("reading .class files"); + + if (!new File("index.html").exists()) + throw new Error("index.html not found"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javadoc/parser/7091528/p/C1.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011, 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. + */ + +package p1; + +/** This is class C1. */ +public class C1 { } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javadoc/parser/7091528/p/q/C2.java Tue Feb 14 10:29:36 2012 -0800 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011, 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. + */ + +package p.q; + +/** This is class p.q.C2. */ +public class C2 { } +