提交 00b7c1d1 编写于 作者: L lana

Merge

......@@ -215,6 +215,9 @@ public enum Source {
public boolean allowTypeAnnotations() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowAnnotationsAfterTypeParams() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowRepeatedAnnotations() {
return compareTo(JDK1_8) >= 0;
}
......
......@@ -3009,15 +3009,6 @@ public class Attr extends JCTree.Visitor {
Type ctype = cfolder.fold1(opc, argtype);
if (ctype != null) {
owntype = cfolder.coerce(ctype, owntype);
// Remove constant types from arguments to
// conserve space. The parser will fold concatenations
// of string literals; the code here also
// gets rid of intermediate results when some of the
// operands are constant identifiers.
if (tree.arg.type.tsym == syms.stringType.tsym) {
tree.arg.type = syms.stringType;
}
}
}
}
......@@ -3051,18 +3042,6 @@ public class Attr extends JCTree.Visitor {
Type ctype = cfolder.fold2(opc, left, right);
if (ctype != null) {
owntype = cfolder.coerce(ctype, owntype);
// Remove constant types from arguments to
// conserve space. The parser will fold concatenations
// of string literals; the code here also
// gets rid of intermediate results when some of the
// operands are constant identifiers.
if (tree.lhs.type.tsym == syms.stringType.tsym) {
tree.lhs.type = syms.stringType;
}
if (tree.rhs.type.tsym == syms.stringType.tsym) {
tree.rhs.type = syms.stringType;
}
}
}
......
......@@ -1895,11 +1895,11 @@ public class LambdaToMethod extends TreeTranslator {
};
break;
case LOCAL_VAR:
ret = new VarSymbol(FINAL, name, types.erasure(sym.type), translatedSym);
ret = new VarSymbol(sym.flags() & FINAL, name, types.erasure(sym.type), translatedSym);
((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
break;
case PARAM:
ret = new VarSymbol(FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym);
ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, name, types.erasure(sym.type), translatedSym);
((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
break;
default:
......
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, 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
......@@ -835,6 +835,8 @@ public class TransTypes extends TreeTranslator {
public void visitReference(JCMemberReference tree) {
tree.expr = translate(tree.expr, erasure(tree.expr.type));
tree.type = erasure(tree.type);
if (tree.varargsElement != null)
tree.varargsElement = erasure(tree.varargsElement);
result = tree;
}
......
......@@ -161,6 +161,7 @@ public class JavacParser implements Parser {
this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
this.allowTypeAnnotations = source.allowTypeAnnotations();
this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
this.keepDocComments = keepDocComments;
docComments = newDocCommentTable(keepDocComments, fac);
this.keepLineMap = keepLineMap;
......@@ -254,6 +255,10 @@ public class JavacParser implements Parser {
*/
boolean allowTypeAnnotations;
/** Switch: should we allow annotations after the method type parameters?
*/
boolean allowAnnotationsAfterTypeParams;
/** Switch: is "this" allowed as an identifier?
* This is needed to parse receiver types.
*/
......@@ -2020,7 +2025,7 @@ public class JavacParser implements Parser {
/** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
*/
JCExpression creator(int newpos, List<JCExpression> typeArgs) {
List<JCAnnotation> newAnnotations = annotationsOpt(Tag.ANNOTATION);
List<JCAnnotation> newAnnotations = typeAnnotationsOpt();
switch (token.kind) {
case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
......@@ -3450,6 +3455,7 @@ public class JavacParser implements Parser {
nextToken();
} else {
if (annosAfterParams.nonEmpty()) {
checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
mods.annotations = mods.annotations.appendList(annosAfterParams);
if (mods.pos == Position.NOPOS)
mods.pos = mods.annotations.head.pos;
......@@ -4041,6 +4047,12 @@ public class JavacParser implements Parser {
allowTypeAnnotations = true;
}
}
void checkAnnotationsAfterTypeParams(int pos) {
if (!allowAnnotationsAfterTypeParams) {
log.error(pos, "annotations.after.type.params.not.supported.in.source", source.name);
allowAnnotationsAfterTypeParams = true;
}
}
/*
* a functional source tree and end position mappings
......
......@@ -2310,6 +2310,11 @@ compiler.err.type.annotations.not.supported.in.source=\
type annotations are not supported in -source {0}\n\
(use -source 8 or higher to enable type annotations)
# 0: string
compiler.err.annotations.after.type.params.not.supported.in.source=\
annotations after method type parameters are not supported in -source {0}\n\
(use -source 8 or higher to enable annotations after method type parameters)
# 0: string
compiler.err.repeatable.annotations.not.supported.in.source=\
repeated annotations are not supported in -source {0}\n\
......
/*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, 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
......@@ -153,6 +153,8 @@ public abstract class Profiles {
final int maxProfile = 4; // Three compact profiles plus full JRE
MakefileProfiles(Properties p) {
// consider crypto, only if java/lang package exists
boolean foundJavaLang = false;
for (int profile = 1; profile <= maxProfile; profile++) {
String prefix = (profile < maxProfile ? "PROFILE_" + profile : "FULL_JRE");
String inclPackages = p.getProperty(prefix + "_RTJAR_INCLUDE_PACKAGES");
......@@ -161,6 +163,8 @@ public abstract class Profiles {
for (String pkg: inclPackages.substring(1).trim().split("\\s+")) {
if (pkg.endsWith("/"))
pkg = pkg.substring(0, pkg.length() - 1);
if (foundJavaLang == false && pkg.equals("java/lang"))
foundJavaLang = true;
includePackage(profile, pkg);
}
String inclTypes = p.getProperty(prefix + "_RTJAR_INCLUDE_TYPES");
......@@ -178,6 +182,15 @@ public abstract class Profiles {
}
}
}
/*
* A hack to force javax/crypto package into the compact1 profile,
* because this package exists in jce.jar, and therefore not in
* ct.sym. Note javax/crypto should exist in a profile along with
* javax/net/ssl package. Thus, this package is added to compact1,
* implying that it should exist in all three profiles.
*/
if (foundJavaLang)
includePackage(1, "javax/crypto");
}
@Override
......
......@@ -6,6 +6,7 @@ CantAnnotateScoping.java:47:18: compiler.err.cant.type.annotate.scoping.1: @TA
CantAnnotateScoping.java:56:37: compiler.err.cant.type.annotate.scoping: @TA,@TA2
CantAnnotateScoping.java:40:14: compiler.err.cant.type.annotate.scoping.1: @TA
CantAnnotateScoping.java:42:34: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2
CantAnnotateScoping.java:42:25: compiler.err.annotation.type.not.applicable
CantAnnotateScoping.java:44:38: compiler.err.cant.type.annotate.scoping: @TA,@DA
CantAnnotateScoping.java:44:34: compiler.err.annotation.type.not.applicable
10 errors
\ No newline at end of file
11 errors
/*
* Copyright (c) 2014, 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 8035890
* @summary Verify that the parser correctly checks for source level 8 on the new places where
* annotations can appear in 8.
* @run main CheckErrorsForSource7 CheckErrorsForSource7.java
*/
import java.io.File;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import com.sun.source.tree.AnnotationTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.file.JavacFileManager;
/**For each place where an annotation can syntactically appear with -source 8, but not with
* -source 7, this test verifies that an error is correctly emitted from the parser for
* the annotation for -source 7. This test first gathers the occurrences of @TA from
* the CheckErrorsForSource7Data class below, and then repeatedly removes all these annotations
* except one and checks the parser reports an expected error. This is needed as as the parser
* typically produces only one 'insufficient source level' error for each new feature used.
*/
public class CheckErrorsForSource7 {
public static void main(String... args) throws IOException, URISyntaxException {
new CheckErrorsForSource7().run(args);
}
private void run(String... args) throws IOException, URISyntaxException {
//the first and only parameter must be the name of the file to be analyzed:
if (args.length != 1) throw new IllegalStateException("Must provide source file!");
File testSrc = new File(System.getProperty("test.src"));
File testFile = new File(testSrc, args[0]);
if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
//gather spans of the @TA annotations into typeAnnotationSpans:
JavacTask task = JavacTool.create().getTask(null,
fm,
null,
Collections.<String>emptyList(),
null,
fm.getJavaFileObjects(testFile));
final Trees trees = Trees.instance(task);
final CompilationUnitTree cut = task.parse().iterator().next();
final List<int[]> typeAnnotationSpans = new ArrayList<>();
new TreePathScanner<Void, Void>() {
@Override
public Void visitAnnotation(AnnotationTree node, Void p) {
if (node.getAnnotationType().getKind() == Kind.IDENTIFIER &&
((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) {
int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
int end = (int) trees.getSourcePositions().getEndPosition(cut, node);
typeAnnotationSpans.add(new int[] {start, end});
}
return null;
}
}.scan(cut, null);
//sort the spans in the reverse order, to simplify removing them from the source:
Collections.sort(typeAnnotationSpans, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o2[0] - o1[0];
}
});
//verify the errors are produce correctly:
String originalSource = cut.getSourceFile().getCharContent(false).toString();
for (int[] toKeep : typeAnnotationSpans) {
//prepare updated source code by removing all the annotations except the toKeep one:
String updated = originalSource;
for (int[] span : typeAnnotationSpans) {
if (span == toKeep) continue;
updated = updated.substring(0, span[0]) + updated.substring(span[1]);
}
//parse and verify:
JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated);
DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>();
JavacTask task2 = JavacTool.create().getTask(null,
fm,
errors,
Arrays.asList("-source", "7"),
null,
Arrays.asList(updatedFile));
task2.parse();
boolean found = false;
for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
if (found) {
throw new IllegalStateException("More than one expected error found.");
}
found = true;
}
}
if (!found)
throw new IllegalStateException("Did not produce proper errors for: " + updated);
}
}
static final Set<String> EXPECTED_ERRORS = new HashSet<>(Arrays.asList(
"compiler.err.type.annotations.not.supported.in.source",
"compiler.err.annotations.after.type.params.not.supported.in.source"
));
class TestFO extends SimpleJavaFileObject {
private final String content;
public TestFO(URI uri, String content) {
super(uri, Kind.SOURCE);
this.content = content;
}
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return content;
}
@Override public boolean isNameCompatible(String simpleName, Kind kind) {
return true;
}
}
}
//data on which the source level check is verified:
class CheckErrorsForSource7Data {
@Target(ElementType.TYPE_USE)
@interface TA { }
Object n1 = new @TA ArrayList<@TA String>();
Object n2 = new @TA Object() {};
Object [] @TA [] arr @TA[];
<T> @TA int @TA[] ret(Object obj) @TA[] throws @TA Exception {
this.<@TA String>ret(null);
Object c1 = new @TA String[1];
int val = obj instanceof @TA String ? ((@TA String) obj).length() : 0;
List<@TA ?> l;
return null;
}
void vararg(String @TA ... args) { }
abstract class C<@TA T extends @TA Number & @TA Runnable>
extends @TA ArrayList<@TA String>
implements java.util. @TA Comparator<@TA T> { }
interface I extends java.util. @TA Comparator<@TA String> { }
}
DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable
DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable
DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable
DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable
DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable
4 errors
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, 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,6 +26,7 @@
* @bug 8005166
* @summary Add support for static interface methods
* Smoke test for static interface method hiding
* @run main/timeout=600 InterfaceMethodHidingTest
*/
import com.sun.source.util.JavacTask;
......
/*
* Copyright (c) 2014, 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.annotations.after.type.params.not.supported.in.source
// key: compiler.warn.source.no.bootclasspath
// options: -source 7
@interface Anno { }
class AnnotationsAfterTypeParamsNotSupportedInSource {
<T> @Anno int m() {
return 0;
}
}
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, 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
......@@ -30,7 +30,7 @@
* @author Maurizio Cimadamore
* @library ../lib
* @build JavacTestingAbstractThreadedTest
* @run main/othervm FunctionalInterfaceConversionTest
* @run main/timeout=600/othervm FunctionalInterfaceConversionTest
*/
// use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047)
......
/*
* Copyright (c) 2014, 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 8037935
* @summary Javac: final local String var referenced in binary/unary op in lambda produces code that does not verify
* @run main LambdaWithBinOpConstRefToConstString
*/
interface MyFI {
void accept();
}
public class LambdaWithBinOpConstRefToConstString {
public static void main(String[] args) {
final String CONSTANT_STRING_VALUE = "mwmwm";
MyFI consumeStrings = () -> {
System.out.println(" local constant: " + CONSTANT_STRING_VALUE);
};
}
}
/*
* Copyright (c) 2014, 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.
*/
/**
* @test
* @bug 8038420
* @summary Lambda returning post-increment generates wrong code
* @run main LambdaIncrement
*/
public class LambdaIncrement {
interface IntegerOp { Integer apply(Integer arg); }
private static void assertNotIncremented(IntegerOp lmb, String label) {
int result = lmb.apply(3);
if (result != 3) {
throw new AssertionError("Post-increment failure. Expected 3, got: " +
result + " " + label);
}
}
public static void main(String... args) throws Exception {
assertNotIncremented(x -> x++, "PostIncExpr");
assertNotIncremented(x -> { return x++; }, "PostIncReturn");
assertNotIncremented(x -> { int y = x; return y++; }, "PostIncLocal");
assertNotIncremented(x -> { Integer y = x; return y++; }, "PostIncLocalBox");
assertNotIncremented(x -> { int y = x; return y; }, "HASINIT");
}
}
/*
* Copyright (c) 2014, 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 8034048
* @summary javac crash with method references plus lambda plus var args
* @author govereau
*
* @compile MethodHandleCrash.java
*/
public interface MethodHandleCrash {
static<T> void functional(T... input) {
java.util.function.Consumer<T> c = MethodHandleCrash::functional;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册