Tue, 07 Feb 2012 10:39:26 -0800
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Feb 02 09:39:44 2012 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Tue Feb 07 10:39:26 2012 -0800 1.3 @@ -70,6 +70,7 @@ 1.4 private JavaCompiler compiler; 1.5 private Locale locale; 1.6 private String[] args; 1.7 + private String[] classNames; 1.8 private Context context; 1.9 private List<JavaFileObject> fileObjects; 1.10 private Map<JavaFileObject, JCCompilationUnit> notYetEntered; 1.11 @@ -82,11 +83,13 @@ 1.12 1.13 JavacTaskImpl(Main compilerMain, 1.14 String[] args, 1.15 + String[] classNames, 1.16 Context context, 1.17 List<JavaFileObject> fileObjects) { 1.18 this.ccw = ClientCodeWrapper.instance(context); 1.19 this.compilerMain = compilerMain; 1.20 this.args = args; 1.21 + this.classNames = classNames; 1.22 this.context = context; 1.23 this.fileObjects = fileObjects; 1.24 setLocale(Locale.getDefault()); 1.25 @@ -101,17 +104,14 @@ 1.26 Context context, 1.27 Iterable<String> classes, 1.28 Iterable<? extends JavaFileObject> fileObjects) { 1.29 - this(compilerMain, toArray(flags, classes), context, toList(fileObjects)); 1.30 + this(compilerMain, toArray(flags), toArray(classes), context, toList(fileObjects)); 1.31 } 1.32 1.33 - static private String[] toArray(Iterable<String> flags, Iterable<String> classes) { 1.34 + static private String[] toArray(Iterable<String> iter) { 1.35 ListBuffer<String> result = new ListBuffer<String>(); 1.36 - if (flags != null) 1.37 - for (String flag : flags) 1.38 - result.append(flag); 1.39 - if (classes != null) 1.40 - for (String cls : classes) 1.41 - result.append(cls); 1.42 + if (iter != null) 1.43 + for (String s : iter) 1.44 + result.append(s); 1.45 return result.toArray(new String[result.length()]); 1.46 } 1.47 1.48 @@ -129,7 +129,7 @@ 1.49 initContext(); 1.50 notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>(); 1.51 compilerMain.setAPIMode(true); 1.52 - result = compilerMain.compile(args, context, fileObjects, processors); 1.53 + result = compilerMain.compile(args, classNames, context, fileObjects, processors); 1.54 cleanup(); 1.55 return result.isOK(); 1.56 } else { 1.57 @@ -159,7 +159,7 @@ 1.58 initContext(); 1.59 compilerMain.setOptions(Options.instance(context)); 1.60 compilerMain.filenames = new LinkedHashSet<File>(); 1.61 - Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args)); 1.62 + Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args), classNames); 1.63 if (!filenames.isEmpty()) 1.64 throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); 1.65 compiler = JavaCompiler.instance(context); 1.66 @@ -174,6 +174,7 @@ 1.67 // endContext will be called when all classes have been generated 1.68 // TODO: should handle the case after each phase if errors have occurred 1.69 args = null; 1.70 + classNames = null; 1.71 } 1.72 } 1.73 1.74 @@ -204,6 +205,7 @@ 1.75 compiler = null; 1.76 compilerMain = null; 1.77 args = null; 1.78 + classNames = null; 1.79 context = null; 1.80 fileObjects = null; 1.81 notYetEntered = null;
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Feb 02 09:39:44 2012 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Feb 07 10:39:26 2012 -0800 2.3 @@ -34,6 +34,7 @@ 2.4 import com.sun.tools.javac.code.Type.*; 2.5 import com.sun.tools.javac.code.Type.ForAll.ConstraintKind; 2.6 import com.sun.tools.javac.code.Symbol.*; 2.7 +import com.sun.tools.javac.comp.Resolve.InapplicableMethodException; 2.8 import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode; 2.9 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 2.10 2.11 @@ -84,7 +85,7 @@ 2.12 2.13 } 2.14 2.15 - public static class InferenceException extends Resolve.InapplicableMethodException { 2.16 + public static class InferenceException extends InapplicableMethodException { 2.17 private static final long serialVersionUID = 0; 2.18 2.19 InferenceException(JCDiagnostic.Factory diags) { 2.20 @@ -287,6 +288,18 @@ 2.21 } 2.22 } 2.23 2.24 + Type asUndetType(Type t, List<Type> undetvars) { 2.25 + return types.subst(t, inferenceVars(undetvars), undetvars); 2.26 + } 2.27 + 2.28 + List<Type> inferenceVars(List<Type> undetvars) { 2.29 + ListBuffer<Type> tvars = ListBuffer.lb(); 2.30 + for (Type uv : undetvars) { 2.31 + tvars.append(((UndetVar)uv).qtype); 2.32 + } 2.33 + return tvars.toList(); 2.34 + } 2.35 + 2.36 /*************************************************************************** 2.37 * Exported Methods 2.38 ***************************************************************************/ 2.39 @@ -372,62 +385,11 @@ 2.40 final Warner warn) throws InferenceException { 2.41 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG 2.42 List<Type> undetvars = Type.map(tvars, fromTypeVarFun); 2.43 - List<Type> formals = mt.argtypes; 2.44 - //need to capture exactly once - otherwise subsequent 2.45 - //applicability checks might fail 2.46 - final List<Type> capturedArgs = types.capture(argtypes); 2.47 - List<Type> actuals = capturedArgs; 2.48 - List<Type> actualsNoCapture = argtypes; 2.49 - // instantiate all polymorphic argument types and 2.50 - // set up lower bounds constraints for undetvars 2.51 - Type varargsFormal = useVarargs ? formals.last() : null; 2.52 - if (varargsFormal == null && 2.53 - actuals.size() != formals.size()) { 2.54 - throw unambiguousNoInstanceException 2.55 - .setMessage("infer.arg.length.mismatch"); 2.56 - } 2.57 - while (actuals.nonEmpty() && formals.head != varargsFormal) { 2.58 - Type formal = formals.head; 2.59 - Type actual = actuals.head.baseType(); 2.60 - Type actualNoCapture = actualsNoCapture.head.baseType(); 2.61 - if (actual.tag == FORALL) 2.62 - actual = instantiateArg((ForAll)actual, formal, tvars, warn); 2.63 - Type undetFormal = types.subst(formal, tvars, undetvars); 2.64 - boolean works = allowBoxing 2.65 - ? types.isConvertible(actual, undetFormal, warn) 2.66 - : types.isSubtypeUnchecked(actual, undetFormal, warn); 2.67 - if (!works) { 2.68 - throw unambiguousNoInstanceException 2.69 - .setMessage("infer.no.conforming.assignment.exists", 2.70 - tvars, actualNoCapture, formal); 2.71 - } 2.72 - formals = formals.tail; 2.73 - actuals = actuals.tail; 2.74 - actualsNoCapture = actualsNoCapture.tail; 2.75 - } 2.76 + //final List<Type> capturedArgs = types.capture(argtypes); 2.77 2.78 - if (formals.head != varargsFormal) // not enough args 2.79 - throw unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch"); 2.80 - 2.81 - // for varargs arguments as well 2.82 - if (useVarargs) { 2.83 - Type elemType = types.elemtype(varargsFormal); 2.84 - Type elemUndet = types.subst(elemType, tvars, undetvars); 2.85 - while (actuals.nonEmpty()) { 2.86 - Type actual = actuals.head.baseType(); 2.87 - Type actualNoCapture = actualsNoCapture.head.baseType(); 2.88 - if (actual.tag == FORALL) 2.89 - actual = instantiateArg((ForAll)actual, elemType, tvars, warn); 2.90 - boolean works = types.isConvertible(actual, elemUndet, warn); 2.91 - if (!works) { 2.92 - throw unambiguousNoInstanceException 2.93 - .setMessage("infer.no.conforming.assignment.exists", 2.94 - tvars, actualNoCapture, elemType); 2.95 - } 2.96 - actuals = actuals.tail; 2.97 - actualsNoCapture = actualsNoCapture.tail; 2.98 - } 2.99 - } 2.100 + final List<Type> capturedArgs = 2.101 + rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(), 2.102 + allowBoxing, useVarargs, warn, new InferenceCheckHandler(undetvars)); 2.103 2.104 // minimize as yet undetermined type variables 2.105 for (Type t : undetvars) 2.106 @@ -503,6 +465,31 @@ 2.107 } 2.108 //where 2.109 2.110 + /** inference check handler **/ 2.111 + class InferenceCheckHandler implements Resolve.MethodCheckHandler { 2.112 + 2.113 + List<Type> undetvars; 2.114 + 2.115 + public InferenceCheckHandler(List<Type> undetvars) { 2.116 + this.undetvars = undetvars; 2.117 + } 2.118 + 2.119 + public InapplicableMethodException arityMismatch() { 2.120 + return unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch"); 2.121 + } 2.122 + public InapplicableMethodException argumentMismatch(boolean varargs, Type found, Type expected) { 2.123 + String key = varargs ? 2.124 + "infer.varargs.argument.mismatch" : 2.125 + "infer.no.conforming.assignment.exists"; 2.126 + return unambiguousNoInstanceException.setMessage(key, 2.127 + inferenceVars(undetvars), found, expected); 2.128 + } 2.129 + public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { 2.130 + return unambiguousNoInstanceException.setMessage("inaccessible.varargs.type", 2.131 + expected, Kinds.kindName(location), location); 2.132 + } 2.133 + } 2.134 + 2.135 /** 2.136 * A delegated type representing a partially uninferred method type. 2.137 * The return type of a partially uninferred method type is a ForAll 2.138 @@ -572,7 +559,7 @@ 2.139 rs.checkRawArgumentsAcceptable(env, actuals, formals, 2.140 allowBoxing, useVarargs, warn); 2.141 } 2.142 - catch (Resolve.InapplicableMethodException ex) { 2.143 + catch (InapplicableMethodException ex) { 2.144 // inferred method is not applicable 2.145 throw invalidInstanceException.setMessage(ex.getDiagnostic()); 2.146 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Feb 02 09:39:44 2012 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Tue Feb 07 10:39:26 2012 -0800 3.3 @@ -44,6 +44,7 @@ 3.4 import static com.sun.tools.javac.code.Kinds.*; 3.5 import static com.sun.tools.javac.code.TypeTags.*; 3.6 import static com.sun.tools.javac.tree.JCTree.Tag.*; 3.7 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; 3.8 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 3.9 3.10 /** This is the second phase of Enter, in which classes are completed 3.11 @@ -142,7 +143,7 @@ 3.12 JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang"); 3.13 throw new FatalError(msg); 3.14 } else { 3.15 - log.error(pos, "doesnt.exist", tsym); 3.16 + log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym); 3.17 } 3.18 } 3.19 env.toplevel.starImportScope.importAll(tsym.members());
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 02 09:39:44 2012 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Feb 07 10:39:26 2012 -0800 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -474,52 +474,126 @@ 4.11 return false; 4.12 } 4.13 } 4.14 + /** 4.15 + * A check handler is used by the main method applicability routine in order 4.16 + * to handle specific method applicability failures. It is assumed that a class 4.17 + * implementing this interface should throw exceptions that are a subtype of 4.18 + * InapplicableMethodException (see below). Such exception will terminate the 4.19 + * method applicability check and propagate important info outwards (for the 4.20 + * purpose of generating better diagnostics). 4.21 + */ 4.22 + interface MethodCheckHandler { 4.23 + /* The number of actuals and formals differ */ 4.24 + InapplicableMethodException arityMismatch(); 4.25 + /* An actual argument type does not conform to the corresponding formal type */ 4.26 + InapplicableMethodException argumentMismatch(boolean varargs, Type found, Type expected); 4.27 + /* The element type of a varargs is not accessible in the current context */ 4.28 + InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected); 4.29 + } 4.30 + 4.31 + /** 4.32 + * Basic method check handler used within Resolve - all methods end up 4.33 + * throwing InapplicableMethodException; a diagnostic fragment that describes 4.34 + * the cause as to why the method is not applicable is set on the exception 4.35 + * before it is thrown. 4.36 + */ 4.37 + MethodCheckHandler resolveHandler = new MethodCheckHandler() { 4.38 + public InapplicableMethodException arityMismatch() { 4.39 + return inapplicableMethodException.setMessage("arg.length.mismatch"); 4.40 + } 4.41 + public InapplicableMethodException argumentMismatch(boolean varargs, Type found, Type expected) { 4.42 + String key = varargs ? 4.43 + "varargs.argument.mismatch" : 4.44 + "no.conforming.assignment.exists"; 4.45 + return inapplicableMethodException.setMessage(key, 4.46 + found, expected); 4.47 + } 4.48 + public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { 4.49 + return inapplicableMethodException.setMessage("inaccessible.varargs.type", 4.50 + expected, Kinds.kindName(location), location); 4.51 + } 4.52 + }; 4.53 + 4.54 void checkRawArgumentsAcceptable(Env<AttrContext> env, 4.55 List<Type> argtypes, 4.56 List<Type> formals, 4.57 boolean allowBoxing, 4.58 boolean useVarargs, 4.59 Warner warn) { 4.60 + checkRawArgumentsAcceptable(env, List.<Type>nil(), argtypes, formals, 4.61 + allowBoxing, useVarargs, warn, resolveHandler); 4.62 + } 4.63 + 4.64 + /** 4.65 + * Main method applicability routine. Given a list of actual types A, 4.66 + * a list of formal types F, determines whether the types in A are 4.67 + * compatible (by method invocation conversion) with the types in F. 4.68 + * 4.69 + * Since this routine is shared between overload resolution and method 4.70 + * type-inference, it is crucial that actual types are converted to the 4.71 + * corresponding 'undet' form (i.e. where inference variables are replaced 4.72 + * with undetvars) so that constraints can be propagated and collected. 4.73 + * 4.74 + * Moreover, if one or more types in A is a poly type, this routine calls 4.75 + * Infer.instantiateArg in order to complete the poly type (this might involve 4.76 + * deferred attribution). 4.77 + * 4.78 + * A method check handler (see above) is used in order to report errors. 4.79 + */ 4.80 + List<Type> checkRawArgumentsAcceptable(Env<AttrContext> env, 4.81 + List<Type> undetvars, 4.82 + List<Type> argtypes, 4.83 + List<Type> formals, 4.84 + boolean allowBoxing, 4.85 + boolean useVarargs, 4.86 + Warner warn, 4.87 + MethodCheckHandler handler) { 4.88 Type varargsFormal = useVarargs ? formals.last() : null; 4.89 + ListBuffer<Type> checkedArgs = ListBuffer.lb(); 4.90 + 4.91 if (varargsFormal == null && 4.92 argtypes.size() != formals.size()) { 4.93 - throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args 4.94 + throw handler.arityMismatch(); // not enough args 4.95 } 4.96 4.97 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 4.98 - boolean works = allowBoxing 4.99 - ? types.isConvertible(argtypes.head, formals.head, warn) 4.100 - : types.isSubtypeUnchecked(argtypes.head, formals.head, warn); 4.101 - if (!works) 4.102 - throw inapplicableMethodException.setMessage("no.conforming.assignment.exists", 4.103 - argtypes.head, 4.104 - formals.head); 4.105 + Type undetFormal = infer.asUndetType(formals.head, undetvars); 4.106 + Type capturedActual = types.capture(argtypes.head); 4.107 + boolean works = allowBoxing ? 4.108 + types.isConvertible(capturedActual, undetFormal, warn) : 4.109 + types.isSubtypeUnchecked(capturedActual, undetFormal, warn); 4.110 + if (!works) { 4.111 + throw handler.argumentMismatch(false, argtypes.head, formals.head); 4.112 + } 4.113 + checkedArgs.append(capturedActual); 4.114 argtypes = argtypes.tail; 4.115 formals = formals.tail; 4.116 } 4.117 4.118 - if (formals.head != varargsFormal) 4.119 - throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args 4.120 + if (formals.head != varargsFormal) { 4.121 + throw handler.arityMismatch(); // not enough args 4.122 + } 4.123 4.124 if (useVarargs) { 4.125 + //note: if applicability check is triggered by most specific test, 4.126 + //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 4.127 Type elt = types.elemtype(varargsFormal); 4.128 + Type eltUndet = infer.asUndetType(elt, undetvars); 4.129 while (argtypes.nonEmpty()) { 4.130 - if (!types.isConvertible(argtypes.head, elt, warn)) 4.131 - throw inapplicableMethodException.setMessage("varargs.argument.mismatch", 4.132 - argtypes.head, 4.133 - elt); 4.134 + Type capturedActual = types.capture(argtypes.head); 4.135 + if (!types.isConvertible(capturedActual, eltUndet, warn)) { 4.136 + throw handler.argumentMismatch(true, argtypes.head, elt); 4.137 + } 4.138 + checkedArgs.append(capturedActual); 4.139 argtypes = argtypes.tail; 4.140 } 4.141 //check varargs element type accessibility 4.142 - if (!isAccessible(env, elt)) { 4.143 + if (undetvars.isEmpty() && !isAccessible(env, elt)) { 4.144 Symbol location = env.enclClass.sym; 4.145 - throw inapplicableMethodException.setMessage("inaccessible.varargs.type", 4.146 - elt, 4.147 - Kinds.kindName(location), 4.148 - location); 4.149 + throw handler.inaccessibleVarargs(location, elt); 4.150 } 4.151 } 4.152 - return; 4.153 + return checkedArgs.toList(); 4.154 } 4.155 // where 4.156 public static class InapplicableMethodException extends RuntimeException {
5.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Thu Feb 02 09:39:44 2012 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Tue Feb 07 10:39:26 2012 -0800 5.3 @@ -31,6 +31,7 @@ 5.4 import java.net.URL; 5.5 import java.security.DigestInputStream; 5.6 import java.security.MessageDigest; 5.7 +import java.util.Arrays; 5.8 import java.util.Collection; 5.9 import java.util.LinkedHashSet; 5.10 import java.util.Set; 5.11 @@ -208,6 +209,10 @@ 5.12 * @param flags The array of command line arguments. 5.13 */ 5.14 public Collection<File> processArgs(String[] flags) { // XXX sb protected 5.15 + return processArgs(flags, null); 5.16 + } 5.17 + 5.18 + public Collection<File> processArgs(String[] flags, String[] classNames) { // XXX sb protected 5.19 int ac = 0; 5.20 while (ac < flags.length) { 5.21 String flag = flags[ac]; 5.22 @@ -248,6 +253,10 @@ 5.23 } 5.24 } 5.25 5.26 + if (this.classnames != null && classNames != null) { 5.27 + this.classnames.addAll(Arrays.asList(classNames)); 5.28 + } 5.29 + 5.30 if (!checkDirectory(D)) 5.31 return null; 5.32 if (!checkDirectory(S)) 5.33 @@ -346,6 +355,15 @@ 5.34 List<JavaFileObject> fileObjects, 5.35 Iterable<? extends Processor> processors) 5.36 { 5.37 + return compile(args, null, context, fileObjects, processors); 5.38 + } 5.39 + 5.40 + public Result compile(String[] args, 5.41 + String[] classNames, 5.42 + Context context, 5.43 + List<JavaFileObject> fileObjects, 5.44 + Iterable<? extends Processor> processors) 5.45 + { 5.46 context.put(Log.outKey, out); 5.47 log = Log.instance(context); 5.48 5.49 @@ -361,14 +379,16 @@ 5.50 * into account. 5.51 */ 5.52 try { 5.53 - if (args.length == 0 && fileObjects.isEmpty()) { 5.54 + if (args.length == 0 5.55 + && (classNames == null || classNames.length == 0) 5.56 + && fileObjects.isEmpty()) { 5.57 Option.HELP.process(optionHelper, "-help"); 5.58 return Result.CMDERR; 5.59 } 5.60 5.61 Collection<File> files; 5.62 try { 5.63 - files = processArgs(CommandLine.parse(args)); 5.64 + files = processArgs(CommandLine.parse(args), classNames); 5.65 if (files == null) { 5.66 // null signals an error in options, abort 5.67 return Result.CMDERR;
6.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Feb 02 09:39:44 2012 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Feb 07 10:39:26 2012 -0800 6.3 @@ -1,5 +1,5 @@ 6.4 # 6.5 -# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 6.6 +# Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 6.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 # 6.9 # This code is free software; you can redistribute it and/or modify it 6.10 @@ -1620,6 +1620,10 @@ 6.11 compiler.misc.infer.arg.length.mismatch=\ 6.12 cannot instantiate from arguments because actual and formal argument lists differ in length 6.13 6.14 +# 0: list of type, 1: type, 2: type 6.15 +compiler.misc.infer.varargs.argument.mismatch=\ 6.16 + no instance(s) of type variable(s) {0} exist so that argument type {1} conforms to vararg element type {2} 6.17 + 6.18 # 0: type, 1: list of type 6.19 compiler.misc.inferred.do.not.conform.to.bounds=\ 6.20 inferred type does not conform to declared bound(s)\n\
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/7129225/Anno.java Tue Feb 07 10:39:26 2012 -0800 7.3 @@ -0,0 +1,31 @@ 7.4 +/* 7.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. Oracle designates this 7.11 + * particular file as subject to the "Classpath" exception as provided 7.12 + * by Oracle in the LICENSE file that accompanied this code. 7.13 + * 7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 + * version 2 for more details (a copy is included in the LICENSE file that 7.18 + * accompanied this code). 7.19 + * 7.20 + * You should have received a copy of the GNU General Public License version 7.21 + * 2 along with this work; if not, write to the Free Software Foundation, 7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 + * 7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.25 + * or visit www.oracle.com if you need additional information or have any 7.26 + * questions. 7.27 + */ 7.28 + 7.29 +import java.lang.annotation.ElementType; 7.30 +import java.lang.annotation.Target; 7.31 + 7.32 +@Target(ElementType.TYPE) 7.33 +public @interface Anno { 7.34 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/7129225/AnnoProcessor.java Tue Feb 07 10:39:26 2012 -0800 8.3 @@ -0,0 +1,45 @@ 8.4 +/* 8.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. Oracle designates this 8.11 + * particular file as subject to the "Classpath" exception as provided 8.12 + * by Oracle in the LICENSE file that accompanied this code. 8.13 + * 8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 + * version 2 for more details (a copy is included in the LICENSE file that 8.18 + * accompanied this code). 8.19 + * 8.20 + * You should have received a copy of the GNU General Public License version 8.21 + * 2 along with this work; if not, write to the Free Software Foundation, 8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 + * 8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.25 + * or visit www.oracle.com if you need additional information or have any 8.26 + * questions. 8.27 + */ 8.28 + 8.29 +import java.util.Set; 8.30 +import javax.annotation.processing.*; 8.31 +import javax.lang.model.SourceVersion; 8.32 +import javax.lang.model.element.TypeElement; 8.33 +import javax.tools.Diagnostic.Kind; 8.34 + 8.35 +@SupportedAnnotationTypes("Anno") 8.36 +public class AnnoProcessor extends JavacTestingAbstractProcessor { 8.37 + @Override 8.38 + public SourceVersion getSupportedSourceVersion() { 8.39 + return SourceVersion.latest(); 8.40 + } 8.41 + 8.42 + @Override 8.43 + public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) { 8.44 + messager.printMessage(Kind.NOTE, "RUNNING - lastRound = " + re.processingOver()); 8.45 + return true; 8.46 + } 8.47 +} 8.48 +
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/7129225/NegTest.ref Tue Feb 07 10:39:26 2012 -0800 9.3 @@ -0,0 +1,2 @@ 9.4 +TestImportStar.java:39:1: compiler.err.doesnt.exist: xxx 9.5 +1 error
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/7129225/TestImportStar.java Tue Feb 07 10:39:26 2012 -0800 10.3 @@ -0,0 +1,43 @@ 10.4 +/* 10.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. Oracle designates this 10.11 + * particular file as subject to the "Classpath" exception as provided 10.12 + * by Oracle in the LICENSE file that accompanied this code. 10.13 + * 10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.17 + * version 2 for more details (a copy is included in the LICENSE file that 10.18 + * accompanied this code). 10.19 + * 10.20 + * You should have received a copy of the GNU General Public License version 10.21 + * 2 along with this work; if not, write to the Free Software Foundation, 10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.23 + * 10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.25 + * or visit www.oracle.com if you need additional information or have any 10.26 + * questions. 10.27 + */ 10.28 + 10.29 +/* @test 10.30 + * @bug 7129225 10.31 + * @summary import xxx.* isn't handled correctly by annotation processing 10.32 + * @library ../lib 10.33 + * @build JavacTestingAbstractProcessor 10.34 + * @compile/fail/ref=NegTest.ref -XDrawDiagnostics TestImportStar.java 10.35 + * @compile Anno.java AnnoProcessor.java 10.36 + * @compile/ref=TestImportStar.ref -XDrawDiagnostics -processor AnnoProcessor -proc:only TestImportStar.java 10.37 + */ 10.38 + 10.39 + //The @compile/fail... verifies that the fix doesn't break the normal compilation of import xxx.* 10.40 + //The @comple/ref... verifies the fix fixes the bug 10.41 + 10.42 +import xxx.*; 10.43 + 10.44 +@Anno 10.45 +public class TestImportStar { 10.46 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/7129225/TestImportStar.ref Tue Feb 07 10:39:26 2012 -0800 11.3 @@ -0,0 +1,3 @@ 11.4 +- compiler.note.proc.messager: RUNNING - lastRound = false 11.5 +TestImportStar.java:39:1: compiler.err.doesnt.exist: xxx 11.6 +- compiler.note.proc.messager: RUNNING - lastRound = true
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/diags/examples/InferVarargsArgumentMismatch.java Tue Feb 07 10:39:26 2012 -0800 12.3 @@ -0,0 +1,30 @@ 12.4 +/* 12.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +// key: compiler.err.cant.apply.symbol.1 12.28 +// key: compiler.misc.infer.varargs.argument.mismatch 12.29 + 12.30 +class InferVarargsArgumentMismatch { 12.31 + <X> void m(X x1, String... xs) {} 12.32 + { this.m("", 1); } 12.33 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javah/T7126832/T7126832.java Tue Feb 07 10:39:26 2012 -0800 13.3 @@ -0,0 +1,107 @@ 13.4 +/* 13.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/* 13.28 + * @test 13.29 + * @bug 7126832 13.30 + * @compile java.java 13.31 + * @summary com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast 13.32 + * @run main T7126832 13.33 + */ 13.34 + 13.35 +import java.io.*; 13.36 +import java.util.*; 13.37 + 13.38 +public class T7126832 { 13.39 + public static void main(String... args) throws Exception { 13.40 + new T7126832().run(); 13.41 + } 13.42 + 13.43 + void run() throws Exception { 13.44 + Locale prev = Locale.getDefault(); 13.45 + Locale.setDefault(Locale.ENGLISH); 13.46 + try { 13.47 + // Verify that a .java file is correctly diagnosed 13.48 + File ff = writeFile(new File("JavahTest.java"), "class JavahTest {}"); 13.49 + test(Arrays.asList(ff.getPath()), 1, "Could not find class file for 'JavahTest.java'."); 13.50 + 13.51 + // Verify that a class named 'xx.java' is accepted. 13.52 + // Note that ./xx/java.class exists, so this should work ok 13.53 + test(Arrays.asList("xx.java"), 0, null); 13.54 + 13.55 + if (errors > 0) { 13.56 + throw new Exception(errors + " errors occurred"); 13.57 + } 13.58 + } finally { 13.59 + Locale.setDefault(prev); 13.60 + } 13.61 + } 13.62 + 13.63 + void test(List<String> args, int expectRC, String expectOut) { 13.64 + System.err.println("Test: " + args 13.65 + + " rc:" + expectRC 13.66 + + ((expectOut != null) ? " out:" + expectOut : "")); 13.67 + 13.68 + StringWriter sw = new StringWriter(); 13.69 + PrintWriter pw = new PrintWriter(sw); 13.70 + int rc = 0; 13.71 + String out = null; 13.72 + try { 13.73 + rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw); 13.74 + out = sw.toString(); 13.75 + } catch(Exception ee) { 13.76 + rc = 1; 13.77 + out = ee.toString();; 13.78 + } 13.79 + pw.close(); 13.80 + if (!out.isEmpty()) { 13.81 + System.err.println(out); 13.82 + } 13.83 + if (rc != expectRC) { 13.84 + error("Unexpected exit code: " + rc + "; expected: " + expectRC); 13.85 + } 13.86 + if (expectOut != null && !out.contains(expectOut)) { 13.87 + error("Expected string not found: " + expectOut); 13.88 + } 13.89 + 13.90 + System.err.println(); 13.91 + } 13.92 + 13.93 + File writeFile(File ff, String ss) throws IOException { 13.94 + if (ff.getParentFile() != null) 13.95 + ff.getParentFile().mkdirs(); 13.96 + 13.97 + try (FileWriter out = new FileWriter(ff)) { 13.98 + out.write(ss); 13.99 + } 13.100 + return ff; 13.101 + } 13.102 + 13.103 + void error(String msg) { 13.104 + System.err.println(msg); 13.105 + errors++; 13.106 + } 13.107 + 13.108 + int errors; 13.109 +} 13.110 +
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javah/T7126832/java.java Tue Feb 07 10:39:26 2012 -0800 14.3 @@ -0,0 +1,27 @@ 14.4 +/* 14.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +package xx; 14.28 +class java { 14.29 + int fred; 14.30 +}