# HG changeset patch # User lana # Date 1422170546 28800 # Node ID 6e2e298c50f1182c73797f615468d60fc212571b # Parent 7e4d689836cc524c144b2e88a21228b2ac2b2e9b# Parent f462f16627418748c98e06d2ef6b28de749efa50 Merge diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/make/tools/propertiesparser/gen/ClassGenerator.java --- a/langtools/make/tools/propertiesparser/gen/ClassGenerator.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/make/tools/propertiesparser/gen/ClassGenerator.java Sat Jan 24 23:22:26 2015 -0800 @@ -1,3 +1,26 @@ +/* + * Copyright (c) 2015, 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 propertiesparser.gen; import propertiesparser.parser.Message; diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Sat Jan 24 23:22:26 2015 -0800 @@ -2783,7 +2783,8 @@ @SuppressWarnings("fallthrough") void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { - Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); + InferenceContext inferenceContext = checkContext.inferenceContext(); + Type returnType = inferenceContext.asUndetVar(descriptor.getReturnType()); Type resType; switch (tree.getMode()) { @@ -2812,10 +2813,20 @@ if (incompatibleReturnType != null) { checkContext.report(tree, diags.fragment("incompatible.ret.type.in.mref", diags.fragment("inconvertible.types", resType, descriptor.getReturnType()))); + } else { + if (inferenceContext.free(refType)) { + // we need to wait for inference to finish and then replace inference vars in the referent type + inferenceContext.addFreeTypeListener(List.of(refType), + instantiatedContext -> { + tree.referentType = instantiatedContext.asInstType(refType); + }); + } else { + tree.referentType = refType; + } } if (!speculativeAttr) { - List thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes()); + List thrownTypes = inferenceContext.asUndetVars(descriptor.getThrownTypes()); if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) { log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes()); } diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Sat Jan 24 23:22:26 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -898,7 +898,7 @@ Type argtype = owntype.getParameterTypes().last(); if (!types.isReifiable(argtype) && (!allowSimplifiedVarargs || - sym.attribute(syms.trustMeType.tsym) == null || + sym.baseSymbol().attribute(syms.trustMeType.tsym) == null || !isTrustMeAllowedOnMethod(sym))) { warnUnchecked(env.tree.pos(), "unchecked.generic.array.creation", diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Sat Jan 24 23:22:26 2015 -0800 @@ -385,7 +385,7 @@ typeEnvs.put(c, localEnv); // Fill out class fields. - c.completer = typeEnter; + c.completer = null; // do not allow the initial completer linger on. c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree); c.sourcefile = env.toplevel.sourcefile; c.members_field = WriteableScope.create(c); @@ -409,6 +409,9 @@ // Enter type parameters. ct.typarams_field = classEnter(tree.typarams, localEnv); + // install further completer for this type. + c.completer = typeEnter; + // Add non-local class to uncompleted, to make sure it will be // completed later. if (!c.isLocal() && uncompleted != null) uncompleted.append(c); diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Sat Jan 24 23:22:26 2015 -0800 @@ -889,7 +889,9 @@ convertArgs(tree.sym, args.toList(), tree.varargsElement)). setType(tree.sym.erasure(types).getReturnType()); - apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType()); + apply = transTypes.coerce(attrEnv, apply, + types.erasure(localContext.tree.referentType.getReturnType())); + setVarargsIfNeeded(apply, tree.varargsElement); return apply; } diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Jan 24 23:22:26 2015 -0800 @@ -227,7 +227,7 @@ annotate.annotateTypeLater(tree, localEnv, m, tree.pos()); if (tree.defaultValue != null) - annotateDefaultValueLater(tree.defaultValue, localEnv, m); + annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos()); } /** Create a fresh environment for method bodies. @@ -438,7 +438,8 @@ /** Queue processing of an attribute default value. */ void annotateDefaultValueLater(final JCExpression defaultValue, final Env localEnv, - final MethodSymbol m) { + final MethodSymbol m, + final DiagnosticPosition deferPos) { annotate.normal(new Annotate.Worker() { @Override public String toString() { @@ -449,9 +450,11 @@ @Override public void run() { JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos); try { enterDefaultValue(defaultValue, localEnv, m); } finally { + deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } } diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Sat Jan 24 23:22:26 2015 -0800 @@ -85,7 +85,7 @@ private Names names; /** End position mappings container */ - private final AbstractEndPosTable endPosTable; + protected final AbstractEndPosTable endPosTable; // Because of javac's limited lookahead, some contexts are ambiguous in // the presence of type annotations even though they are not ambiguous diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java Sat Jan 24 23:22:26 2015 -0800 @@ -2101,6 +2101,7 @@ public PolyKind refPolyKind; public boolean ownerAccessible; public OverloadKind overloadKind; + public Type referentType; public enum OverloadKind { OVERLOADED, diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/8052070/DuplicateTypeParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/8052070/DuplicateTypeParameter.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,15 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8052070 + * @summary javac crashes when there are duplicated type parameters + * @compile/fail/ref=DuplicateTypeParameter.out -XDrawDiagnostics DuplicateTypeParameter.java + */ + +public class DuplicateTypeParameter { + class Inner {} + public void foo() { + class Local {}; + } +} + +class Secondary {} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/8052070/DuplicateTypeParameter.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/8052070/DuplicateTypeParameter.out Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,5 @@ +DuplicateTypeParameter.java:8:40: compiler.err.already.defined: kindname.type.variable, T, kindname.class, DuplicateTypeParameter +DuplicateTypeParameter.java:9:21: compiler.err.already.defined: kindname.type.variable, P, kindname.class, DuplicateTypeParameter.Inner +DuplicateTypeParameter.java:15:20: compiler.err.already.defined: kindname.type.variable, D, kindname.class, Secondary +DuplicateTypeParameter.java:11:25: compiler.err.already.defined: kindname.type.variable, M, kindname.class, Local +4 errors diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/lambda/LambdaLambdaSerialized.java --- a/langtools/test/tools/javac/lambda/LambdaLambdaSerialized.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/test/tools/javac/lambda/LambdaLambdaSerialized.java Sat Jan 24 23:22:26 2015 -0800 @@ -67,13 +67,13 @@ out.writeObject(lamb); } - static void readAssert(ObjectInputStream in, String expected) throws IOException, ClassNotFoundException { - LSI> ls = (LSI>) in.readObject(); + static void readAssert(ObjectInputStream in, String expected) throws IOException, ClassNotFoundException { + LSI> ls = (LSI>)in.readObject(); Map result = ls.get().get(); System.out.printf("Result: %s\n", result); } + + interface LSI extends Serializable { + T get(); + } } - -interface LSI extends Serializable { - T get(); -} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/lambda/MethodReferenceGenericTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/MethodReferenceGenericTarget.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, 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 8046977 8065303 + * @summary ClassCastException: typing information needed for method reference bridging not preserved + * @author Srikanth + * @run main MethodReferenceGenericTarget + */ + +public class MethodReferenceGenericTarget { + static String result = ""; + + interface ISi { int m(Short a); } + + public static void main(String[] args) { + (new MethodReferenceGenericTarget()).testUnboxObjectToNumberWiden(); + if (!result.equals("7775")) + throw new AssertionError("Incorrect result"); + MethodReferenceTestPrivateTypeConversion.main(null); + new InferenceHookTest().test(); + } + + void foo(ISi q) { + result += q.m((short)75); + } + + public void testUnboxObjectToNumberWiden() { + ISi q = (new E())::xI; + result += q.m((short)77); + // Verify poly invocation context to confirm we handle + // deferred/speculative attribution paths adequately. + foo((new E())::xI); + } + + class E { + private T xI(T t) { return t; } + } +} + +// snippet from https://bugs.openjdk.java.net/browse/JDK-8065303 +class MethodReferenceTestPrivateTypeConversion { + + class MethodReferenceTestTypeConversion_E { + private T xI(T t) { return t; } + } + + interface ISi { int m(Short a); } + + interface ICc { char m(Character a); } + + public void testUnboxObjectToNumberWiden() { + ISi q = (new MethodReferenceTestTypeConversion_E())::xI; + if ((q.m((short)77) != (short)77)) + throw new AssertionError("Incorrect result"); + } + + public void testUnboxObjectToChar() { + ICc q = (new MethodReferenceTestTypeConversion_E())::xI; + if (q.m('@') != '@') + throw new AssertionError("Incorrect result"); + } + + public static void main(String[] args) { + new MethodReferenceTestPrivateTypeConversion().testUnboxObjectToNumberWiden(); + new MethodReferenceTestPrivateTypeConversion().testUnboxObjectToChar(); + } +} + +class InferenceHookTestBase { + X m(Integer i) { return null; } +} + +class InferenceHookTest extends InferenceHookTestBase { + interface SAM1 { + R m(Integer i); + } + + Z g(SAM1 o) { return null; } + + void test() { + String s = g(super::m); + if (s != null) + throw new AssertionError("Incorrect result"); + } +} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/lambda/SerializedLambdaInInit.java --- a/langtools/test/tools/javac/lambda/SerializedLambdaInInit.java Fri Jan 23 18:50:51 2015 -0800 +++ b/langtools/test/tools/javac/lambda/SerializedLambdaInInit.java Sat Jan 24 23:22:26 2015 -0800 @@ -111,8 +111,8 @@ } } } + + interface LSI extends Serializable { + String convert(String x); + } } - -interface LSI extends Serializable { - String convert(String x); -} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/parser/extend/JavacExtensionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/parser/extend/JavacExtensionTest.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015, 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 com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.SourcePositions; +import com.sun.source.util.TreePath; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.JavacTaskImpl; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.util.Context; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import javax.lang.model.element.Element; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.ToolProvider; +import javax.tools.StandardJavaFileManager; +import com.sun.source.tree.ImportTree; +import java.util.Collections; +import java.io.PrintWriter; +import com.sun.source.tree.VariableTree; +import static javax.tools.StandardLocation.CLASS_OUTPUT; + +/* + * @test + * @bug 8067384 8068488 + * @summary Verify that JavacParser can be extended + */ +public class JavacExtensionTest { + + public static void main(String[] args) throws Exception { + PrintWriter pw = new PrintWriter("trialSource.java", "UTF-8"); + pw.println("int x = 9;"); + pw.close(); + List defs = parse("trialSource.java"); + if (defs.size() != 1) { + throw new AssertionError("Expected only one def, got: " + defs.size()); + } + Tree tree = defs.get(0); + if (tree instanceof VariableTree) { + System.out.println("Passes! --- " + tree); + } else { + throw new AssertionError("Expected VariableTree, got: " + tree); + } + } + + static List parse(String srcfile) throws Exception { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); + Iterable fileObjects = fileManager.getJavaFileObjects(srcfile); + String classPath = System.getProperty("java.class.path"); + List options = Arrays.asList("-classpath", classPath); + DiagnosticCollector diagnostics = new DiagnosticCollector<>(); + Context context = new Context(); + JavacTaskImpl task = (JavacTaskImpl) ((JavacTool) compiler).getTask(null, null, + diagnostics, options, null, fileObjects, context); + TrialParserFactory.instance(context); + Iterable asts = task.parse(); + Iterator it = asts.iterator(); + if (it.hasNext()) { + CompilationUnitTree cut = it.next(); + return cut.getTypeDecls(); + } else { + throw new AssertionError("Expected compilation unit"); + } + } +} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/parser/extend/TrialParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/parser/extend/TrialParser.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2015, 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 com.sun.tools.javac.code.TypeTag; +import com.sun.tools.javac.parser.JavacParser; +import com.sun.tools.javac.parser.ParserFactory; +import com.sun.tools.javac.parser.Tokens.Comment; +import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; +import com.sun.tools.javac.parser.Tokens.Token; +import static com.sun.tools.javac.parser.Tokens.TokenKind.CLASS; +import static com.sun.tools.javac.parser.Tokens.TokenKind.COLON; +import static com.sun.tools.javac.parser.Tokens.TokenKind.ENUM; +import static com.sun.tools.javac.parser.Tokens.TokenKind.EOF; +import static com.sun.tools.javac.parser.Tokens.TokenKind.IMPORT; +import static com.sun.tools.javac.parser.Tokens.TokenKind.INTERFACE; +import static com.sun.tools.javac.parser.Tokens.TokenKind.LPAREN; +import static com.sun.tools.javac.parser.Tokens.TokenKind.MONKEYS_AT; +import static com.sun.tools.javac.parser.Tokens.TokenKind.PACKAGE; +import static com.sun.tools.javac.parser.Tokens.TokenKind.SEMI; +import static com.sun.tools.javac.parser.Tokens.TokenKind.VOID; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCAnnotation; +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCExpressionStatement; +import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCPackageDecl; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.JCTree.Tag; +import static com.sun.tools.javac.tree.JCTree.Tag.IDENT; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Position; + +/** + * + * @author Robert Field + */ +class TrialParser extends JavacParser { + + public TrialParser(ParserFactory fac, + com.sun.tools.javac.parser.Lexer S, + boolean keepDocComments, + boolean keepLineMap, + boolean keepEndPositions) { + super(fac, S, keepDocComments, keepLineMap, keepEndPositions); + } + + @Override + public JCCompilationUnit parseCompilationUnit() { + Token firstToken = token; + JCModifiers mods = null; + boolean seenImport = false; + boolean seenPackage = false; + ListBuffer defs = new ListBuffer<>(); + if (token.kind == MONKEYS_AT) { + mods = modifiersOpt(); + } + + if (token.kind == PACKAGE) { + int packagePos = token.pos; + List annotations = List.nil(); + seenPackage = true; + if (mods != null) { + checkNoMods(mods.flags); + annotations = mods.annotations; + mods = null; + } + nextToken(); + JCExpression pid = qualident(false); + accept(SEMI); + JCPackageDecl pd = F.at(packagePos).PackageDecl(annotations, pid); + attach(pd, firstToken.comment(CommentStyle.JAVADOC)); + storeEnd(pd, token.pos); + defs.append(pd); + } + + boolean firstTypeDecl = true; + while (token.kind != EOF) { + if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) { + // error recovery + skip(true, false, false, false); + if (token.kind == EOF) { + break; + } + } + if (mods == null && token.kind == IMPORT) { + seenImport = true; + defs.append(importDeclaration()); + break; + } else { + Comment docComment = token.comment(CommentStyle.JAVADOC); + if (firstTypeDecl && !seenImport && !seenPackage) { + docComment = firstToken.comment(CommentStyle.JAVADOC); + } + List udefs = aUnit(mods, docComment); + for (JCTree def : udefs) { + defs.append(def); + } + mods = null; + firstTypeDecl = false; + break; + } + } + List rdefs = defs.toList(); + class TrialUnit extends JCCompilationUnit { + + public TrialUnit(List defs) { + super(defs); + } + } + JCCompilationUnit toplevel = new TrialUnit(rdefs); + if (rdefs.isEmpty()) { + storeEnd(toplevel, S.prevToken().endPos); + } + toplevel.lineMap = S.getLineMap(); + this.endPosTable.setParser(null); // remove reference to parser + toplevel.endPositions = this.endPosTable; + return toplevel; + } + + List aUnit(JCModifiers pmods, Comment dc) { + switch (token.kind) { + case EOF: + return List.nil(); + case RBRACE: + case CASE: + case DEFAULT: + // These are illegal, fall through to handle as illegal statement + case LBRACE: + case IF: + case FOR: + case WHILE: + case DO: + case TRY: + case SWITCH: + case SYNCHRONIZED: + case RETURN: + case THROW: + case BREAK: + case CONTINUE: + case SEMI: + case ELSE: + case FINALLY: + case CATCH: + case ASSERT: + return List.of(parseStatement()); + default: + JCModifiers mods = modifiersOpt(pmods); + if (token.kind == CLASS + || token.kind == INTERFACE + || token.kind == ENUM) { + return List.of(classOrInterfaceOrEnumDeclaration(mods, dc)); + } else { + int pos = token.pos; + List typarams = typeParametersOpt(); + // if there are type parameters but no modifiers, save the start + // position of the method in the modifiers. + if (typarams.nonEmpty() && mods.pos == Position.NOPOS) { + mods.pos = pos; + storeEnd(mods, pos); + } + List annosAfterParams = annotationsOpt(Tag.ANNOTATION); + + if (annosAfterParams.nonEmpty()) { + checkAnnotationsAfterTypeParams(annosAfterParams.head.pos); + mods.annotations = mods.annotations.appendList(annosAfterParams); + if (mods.pos == Position.NOPOS) { + mods.pos = mods.annotations.head.pos; + } + } + + Token prevToken = token; + pos = token.pos; + JCExpression t; + boolean isVoid = token.kind == VOID; + if (isVoid) { + t = to(F.at(pos).TypeIdent(TypeTag.VOID)); + nextToken(); + } else { + // return type of method, declared type of variable, or an expression + t = term(EXPR | TYPE); + } + if (token.kind == COLON && t.hasTag(IDENT)) { + // labelled statement + nextToken(); + JCStatement stat = parseStatement(); + return List.of(F.at(pos).Labelled(prevToken.name(), stat)); + } else if ((isVoid || (lastmode & TYPE) != 0) && LAX_IDENTIFIER.accepts(token.kind)) { + // we have "Type Ident", so we can assume it is variable or method declaration + pos = token.pos; + Name name = ident(); + if (token.kind == LPAREN) { + // method declaration + //mods.flags |= Flags.STATIC; + return List.of(methodDeclaratorRest( + pos, mods, t, name, typarams, + false, isVoid, dc)); + } else if (!isVoid && typarams.isEmpty()) { + // variable declaration + //mods.flags |= Flags.STATIC; + List defs + = variableDeclaratorsRest(pos, mods, t, name, false, dc, + new ListBuffer()).toList(); + accept(SEMI); + storeEnd(defs.last(), S.prevToken().endPos); + return defs; + } else { + // malformed declaration, return error + pos = token.pos; + List err = isVoid + ? List.of(toP(F.at(pos).MethodDef(mods, name, t, typarams, + List.nil(), List.nil(), null, null))) + : null; + return List.of(syntaxError(token.pos, err, "expected", LPAREN)); + } + } else if (!typarams.isEmpty()) { + // type parameters on non-variable non-method -- error + return List.of(syntaxError(token.pos, "illegal.start.of.type")); + } else { + // expression-statement or expression to evaluate + accept(SEMI); + JCExpressionStatement expr = toP(F.at(pos).Exec(t)); + return List.of(expr); + } + + } + } + } +} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/parser/extend/TrialParserFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/parser/extend/TrialParserFactory.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015, 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 com.sun.tools.javac.parser.JavacParser; +import com.sun.tools.javac.parser.ParserFactory; +import com.sun.tools.javac.parser.ScannerFactory; +import com.sun.tools.javac.util.Context; + +/** + * + * @author Robert Field + */ +class TrialParserFactory extends ParserFactory { + + public static ParserFactory instance(Context context) { + ParserFactory instance = context.get(parserFactoryKey); + if (instance == null) { + instance = new TrialParserFactory(context); + } + return instance; + } + + private final ScannerFactory scannerFactory; + + protected TrialParserFactory(Context context) { + super(context); + this.scannerFactory = ScannerFactory.instance(context); + } + + @Override + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { + com.sun.tools.javac.parser.Lexer lexer = scannerFactory.newScanner(input, keepDocComments); + return new TrialParser(this, lexer, keepDocComments, keepLineMap, keepEndPos); + } +} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/varargs/warning/Warn6.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/varargs/warning/Warn6.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, 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 8069254 + * @summary Ensure the generic array creation warning is not incorrectly produced for diamonds + * @compile -Xlint:unchecked -Werror Warn6.java + */ + +public class Warn6 { + @SafeVarargs + public Warn6(T... args) { + } + + public static void main(String[] args) { + Iterable i = null; + + Warn6> foo2 = new Warn6<>(i, i); + Warn6> foo3 = new Warn6>(i, i); + } +} + diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/warnings/suppress/T8069094.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/suppress/T8069094.java Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,17 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8069094 + * @summary Verify that \\@SuppressWarnings("unchecked") works correctly for annotation default values + * @build VerifySuppressWarnings + * @compile/ref=T8069094.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T8069094.java + * @run main VerifySuppressWarnings T8069094.java + */ + +@interface T8069094 { + T8069094A foo() default T8069094A.Bar; +} + +@Deprecated +enum T8069094A { + Bar +} diff -r 7e4d689836cc -r 6e2e298c50f1 langtools/test/tools/javac/warnings/suppress/T8069094.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/suppress/T8069094.out Sat Jan 24 23:22:26 2015 -0800 @@ -0,0 +1,3 @@ +T8069094.java:11:5: compiler.warn.has.been.deprecated: T8069094A, compiler.misc.unnamed.package +T8069094.java:11:29: compiler.warn.has.been.deprecated: T8069094A, compiler.misc.unnamed.package +2 warnings