Merge
This commit is contained in:
commit
3db9cfa542
@ -422,6 +422,8 @@
|
||||
<isset property="jtreg.home"/>
|
||||
</condition>
|
||||
<replace file=".idea/ant.xml" token="@@@" value="${jtreg.idea.home}"/>
|
||||
<replace file=".idea/workspace.xml" token="@FILE_SEP@" value="${file.separator}"/>
|
||||
<replace file=".idea/workspace.xml" token="@PATH_SEP@" value="${path.separator}"/>
|
||||
<mkdir dir=".idea/classes"/>
|
||||
<javac srcdir="make/intellij/src"
|
||||
destdir=".idea/classes"/>
|
||||
|
@ -14,14 +14,14 @@
|
||||
<sequential>
|
||||
<java classname="org.apache.tools.ant.Main" fork="true" spawn="true">
|
||||
<arg value="-f"/>
|
||||
<arg value="@{antfile}"/>
|
||||
<arg value="@{antfile}"/>
|
||||
<arg value="-Dboot.java.home=${boot.java.home}"/>
|
||||
<arg value="-Dtarget.java.home=${target.java.home}"/>
|
||||
<arg value="-Djtreg.home=${jtreg.home}"/>
|
||||
<arg value="-Djtreg.tests=${jtreg.tests}"/>
|
||||
<arg value="-Djtreg.jpda.jvmargs=${jtreg.jpda.jvmargs}"/>
|
||||
<arg value="@{target}"/>
|
||||
<classpath>
|
||||
<classpath>
|
||||
<pathelement path="${java.class.path}"/>
|
||||
</classpath>
|
||||
</java>
|
||||
|
@ -13,6 +13,6 @@
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
@ -6,4 +6,4 @@
|
||||
<option name="myName" value="langtools" />
|
||||
<option name="myLocal" value="true" />
|
||||
</copyright>
|
||||
</component>
|
||||
</component>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true">
|
||||
<output url="file://$PROJECT_DIR$/build" />
|
||||
</component>
|
||||
</project>
|
||||
|
@ -93,7 +93,9 @@ public final class LangtoolsIdeaAntLogger extends DefaultLogger {
|
||||
/** jtreg test failure */
|
||||
JTREG_TEST_FAILED(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "FAILED: "),
|
||||
/** jtreg test error */
|
||||
JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: ");
|
||||
JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: "),
|
||||
/** jtreg report */
|
||||
JTREG_TEST_REPORT(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Report written");
|
||||
|
||||
StringBinaryPredicate sbp;
|
||||
int priority;
|
||||
@ -126,7 +128,7 @@ public final class LangtoolsIdeaAntLogger extends DefaultLogger {
|
||||
JAVAC("javac", MessageKind.JAVAC_ERROR, MessageKind.JAVAC_WARNING, MessageKind.JAVAC_NOTE,
|
||||
MessageKind.JAVAC_NESTED_DIAG, MessageKind.JAVAC_CRASH),
|
||||
/** jtreg task - invoked during test execution */
|
||||
JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR),
|
||||
JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR, MessageKind.JTREG_TEST_REPORT),
|
||||
/** initial synthetic task when the logger is created */
|
||||
ROOT("") {
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<ignored path=".idea/" />
|
||||
</component>
|
||||
@ -10,7 +10,7 @@
|
||||
<!-- standard tools -->
|
||||
<configuration default="false" name="javac" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/java.compiler/classes:build/jdk.compiler/classes:build/java.base/classes:build/jdk.javadoc/classes:build/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -29,7 +29,7 @@
|
||||
</configuration>
|
||||
<configuration default="false" name="javadoc" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.javadoc.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/java.compiler/classes:build/jdk.compiler/classes:build/java.base/classes:build/jdk.javadoc/classes:build/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -44,11 +44,11 @@
|
||||
<method>
|
||||
<option name="Make" enabled="false" />
|
||||
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" />
|
||||
</method>
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="false" name="javap" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.javap.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/java.compiler/classes:build/jdk.compiler/classes:build/java.base/classes:build/jdk.javadoc/classes:build/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -63,11 +63,11 @@
|
||||
<method>
|
||||
<option name="Make" enabled="false" />
|
||||
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" />
|
||||
</method>
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="false" name="javah" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.javah.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/java.compiler/classes:build/jdk.compiler/classes:build/java.base/classes:build/jdk.javadoc/classes:build/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -82,11 +82,11 @@
|
||||
<method>
|
||||
<option name="Make" enabled="false" />
|
||||
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" />
|
||||
</method>
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="false" name="sjavac" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.sjavac.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/java.compiler/classes:build/jdk.compiler/classes:build/java.base/classes:build/jdk.javadoc/classes:build/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -101,12 +101,12 @@
|
||||
<method>
|
||||
<option name="Make" enabled="false" />
|
||||
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" />
|
||||
</method>
|
||||
</method>
|
||||
</configuration>
|
||||
<!-- bootstrap javac -->
|
||||
<configuration default="false" name="javac (bootstrap)" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/bootstrap/java.compiler/classes:build/bootstrap/jdk.compiler/classes:build/bootstrap/java.base/classes:build/bootstrap/jdk.javadoc/classes:build/bootstrap/jdk.dev/classes" />
|
||||
<option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@bootstrap@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@java.base@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.dev@FILE_SEP@classes" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
@ -121,7 +121,7 @@
|
||||
<method>
|
||||
<option name="Make" enabled="false" />
|
||||
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-bootstrap-javac" />
|
||||
</method>
|
||||
</method>
|
||||
</configuration>
|
||||
<!-- jtreg debug -->
|
||||
<configuration default="false" name="jtreg (debug)" type="Remote" factoryName="Remote" singleton="true">
|
||||
|
@ -209,6 +209,9 @@ public enum Source {
|
||||
public boolean allowPrivateSafeVarargs() {
|
||||
return compareTo(JDK1_9) >= 0;
|
||||
}
|
||||
public boolean allowUnderscoreIdentifier() {
|
||||
return compareTo(JDK1_8) <= 0;
|
||||
}
|
||||
public static SourceVersion toSourceVersion(Source source) {
|
||||
switch(source) {
|
||||
case JDK1_2:
|
||||
|
@ -157,6 +157,7 @@ public class JavacParser implements Parser {
|
||||
this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
|
||||
this.allowTypeAnnotations = source.allowTypeAnnotations();
|
||||
this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
|
||||
this.allowUnderscoreIdentifier = source.allowUnderscoreIdentifier();
|
||||
this.keepDocComments = keepDocComments;
|
||||
docComments = newDocCommentTable(keepDocComments, fac);
|
||||
this.keepLineMap = keepLineMap;
|
||||
@ -230,6 +231,10 @@ public class JavacParser implements Parser {
|
||||
*/
|
||||
boolean allowAnnotationsAfterTypeParams;
|
||||
|
||||
/** Switch: should we allow '_' as an identifier?
|
||||
*/
|
||||
boolean allowUnderscoreIdentifier;
|
||||
|
||||
/** Switch: is "this" allowed as an identifier?
|
||||
* This is needed to parse receiver types.
|
||||
*/
|
||||
@ -595,7 +600,11 @@ public class JavacParser implements Parser {
|
||||
return names.error;
|
||||
}
|
||||
} else if (token.kind == UNDERSCORE) {
|
||||
warning(token.pos, "underscore.as.identifier");
|
||||
if (allowUnderscoreIdentifier) {
|
||||
warning(token.pos, "underscore.as.identifier");
|
||||
} else {
|
||||
error(token.pos, "underscore.as.identifier");
|
||||
}
|
||||
Name name = token.name();
|
||||
nextToken();
|
||||
return name;
|
||||
@ -3067,7 +3076,7 @@ public class JavacParser implements Parser {
|
||||
boolean checkForImports = true;
|
||||
boolean firstTypeDecl = true;
|
||||
while (token.kind != EOF) {
|
||||
if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
|
||||
if (token.pos <= endPosTable.errorEndPos) {
|
||||
// error recovery
|
||||
skip(checkForImports, false, false, false);
|
||||
if (token.kind == EOF)
|
||||
@ -4083,7 +4092,7 @@ public class JavacParser implements Parser {
|
||||
/**
|
||||
* Store the last error position.
|
||||
*/
|
||||
protected int errorEndPos;
|
||||
protected int errorEndPos = Position.NOPOS;
|
||||
|
||||
public AbstractEndPosTable(JavacParser parser) {
|
||||
this.parser = parser;
|
||||
|
@ -2276,8 +2276,10 @@ compiler.err.var.in.try.with.resources.not.supported.in.source=\
|
||||
(use -source 9 or higher to enable variables in try-with-resources)
|
||||
|
||||
compiler.warn.underscore.as.identifier=\
|
||||
''_'' used as an identifier\n\
|
||||
(use of ''_'' as an identifier might not be supported in releases after Java SE 8)
|
||||
as of release 9, ''_'' is a keyword, and may not be used as an identifier
|
||||
|
||||
compiler.err.underscore.as.identifier=\
|
||||
as of release 9, ''_'' is a keyword, and may not be used as an identifier
|
||||
|
||||
compiler.err.underscore.as.identifier.in.lambda=\
|
||||
''_'' used as an identifier\n\
|
||||
|
@ -46,6 +46,7 @@ public class TestAnchorNames extends JavadocTester {
|
||||
void test() {
|
||||
javadoc("-d", "out",
|
||||
"-sourcepath", testSrc,
|
||||
"-source", "8", //so that '_' can be used as an identifier
|
||||
"-use",
|
||||
"pkg1");
|
||||
checkExit(Exit.OK);
|
||||
|
@ -102,6 +102,9 @@ public class DetectMutableStaticFields {
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/file/ZipFileIndexCache",
|
||||
Arrays.asList("sharedInstance"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/file/JRTIndex",
|
||||
Arrays.asList("sharedInstance"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/main/JavaCompiler",
|
||||
Arrays.asList("versionRB"));
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.underscore.as.identifier
|
||||
|
||||
class UnderscoreAsIdentifierError {
|
||||
String _ = null;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 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
|
||||
@ -22,7 +22,8 @@
|
||||
*/
|
||||
|
||||
// key: compiler.warn.underscore.as.identifier
|
||||
// options: -source 8 -Xlint:-options
|
||||
|
||||
class UnderscoreAsIdentifier {
|
||||
class UnderscoreAsIdentifierWarning {
|
||||
String _ = null;
|
||||
}
|
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* 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 8065360
|
||||
* @summary The test checks dependencies through type parameters and implements/extends statements.
|
||||
* @library /tools/lib
|
||||
* @build ToolBox ImportDependenciesTest
|
||||
* @run main ImportDependenciesTest
|
||||
*/
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The test checks that code which contains dependencies through type parameters,
|
||||
* implements/extends statements compiles properly. All combinations of
|
||||
* import types are tested. In addition, the test checks various combinations
|
||||
* of classes.
|
||||
*/
|
||||
public class ImportDependenciesTest {
|
||||
|
||||
private static final String sourceTemplate =
|
||||
"package pkg;\n" +
|
||||
"#IMPORT\n" +
|
||||
"public class Test {\n" +
|
||||
" static #CLASS_TYPE InnerClass#TYPE_PARAMETER #PARENT {\n" +
|
||||
" static class Inner1 {\n" +
|
||||
" }\n" +
|
||||
" interface Inner2 {\n" +
|
||||
" }\n" +
|
||||
" interface Inner3 {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class InnerClass1 {\n" +
|
||||
" static class IInner1 {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class InnerInterface1 {\n" +
|
||||
" interface IInner2 {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class InnerInterface2 {\n" +
|
||||
" interface IInner3 {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ImportDependenciesTest().test();
|
||||
}
|
||||
|
||||
public void test() {
|
||||
List<List<InnerClass>> typeParameters = InnerClass.getAllCombinationsForTypeParameter();
|
||||
List<List<InnerClass>> parents = InnerClass.getAllCombinationsForInheritance();
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
for (ClassType classType : ClassType.values()) {
|
||||
for (List<InnerClass> parent : parents) {
|
||||
if (!classType.canBeInherited(parent)) {
|
||||
continue;
|
||||
}
|
||||
for (List<InnerClass> typeParameter : typeParameters) {
|
||||
List<InnerClass> innerClasses = new ArrayList<>(typeParameter);
|
||||
innerClasses.addAll(parent);
|
||||
for (ImportType importType : ImportType.values()) {
|
||||
++total;
|
||||
String source = sourceTemplate
|
||||
.replace("#IMPORT", importType.generateImports(innerClasses))
|
||||
.replace("#CLASS_TYPE", classType.getClassType())
|
||||
.replace("#TYPE_PARAMETER", generateTypeParameter(typeParameter))
|
||||
.replace("#PARENT", classType.generateInheritanceString(parent));
|
||||
CompilationResult result = compile(new ToolBox.JavaSource("pkg/Test.java", source));
|
||||
if (!result.isSuccessful) {
|
||||
echo("Compilation failed!");
|
||||
echo(source);
|
||||
echo(result.message);
|
||||
echo();
|
||||
} else {
|
||||
++passed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String message = String.format(
|
||||
"Total test cases run: %d, passed: %d, failed: %d.",
|
||||
total, passed, total - passed);
|
||||
if (passed != total) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
echo(message);
|
||||
}
|
||||
|
||||
private String generateTypeParameter(List<InnerClass> typeParameters) {
|
||||
if (typeParameters.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return String.format("<T extends %s>", typeParameters.stream()
|
||||
.map(InnerClass::getSimpleName)
|
||||
.collect(Collectors.joining(" & ")));
|
||||
}
|
||||
|
||||
private static class CompilationResult {
|
||||
public final boolean isSuccessful;
|
||||
public final String message;
|
||||
|
||||
public CompilationResult(boolean isSuccessful, String message) {
|
||||
this.isSuccessful = isSuccessful;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
private CompilationResult compile(ToolBox.JavaSource...sources) {
|
||||
StringWriter writer = new StringWriter();
|
||||
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
|
||||
Boolean call = jc.getTask(writer, null, null, null, null, Arrays.asList(sources)).call();
|
||||
return new CompilationResult(call, writer.toString().replace(ToolBox.lineSeparator, "\n"));
|
||||
}
|
||||
|
||||
public void echo() {
|
||||
echo("");
|
||||
}
|
||||
|
||||
public void echo(String output) {
|
||||
printf(output + "\n");
|
||||
}
|
||||
|
||||
public void printf(String template, Object...args) {
|
||||
System.err.print(String.format(template, args).replace("\n", ToolBox.lineSeparator));
|
||||
}
|
||||
|
||||
enum ImportType {
|
||||
IMPORT("import"), STATIC_IMPORT("import static"),
|
||||
IMPORT_ON_DEMAND("import"), STATIC_IMPORT_ON_DEMAND("import static");
|
||||
|
||||
private final String importType;
|
||||
private ImportType(String importType) {
|
||||
this.importType = importType;
|
||||
}
|
||||
|
||||
private boolean isOnDemand() {
|
||||
return this == IMPORT_ON_DEMAND || this == STATIC_IMPORT_ON_DEMAND;
|
||||
}
|
||||
|
||||
public String generateImports(List<InnerClass> innerClasses) {
|
||||
return innerClasses.stream()
|
||||
.map(i -> isOnDemand() ? i.getPackageName() + ".*" : i.getCanonicalName())
|
||||
.distinct()
|
||||
.map(s -> String.format("%s %s;", importType, s))
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
enum ClassType {
|
||||
CLASS("class") {
|
||||
@Override
|
||||
public boolean canBeInherited(List<InnerClass> innerClasses) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateInheritanceString(List<InnerClass> innerClasses) {
|
||||
if (innerClasses.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
InnerClass firstClass = innerClasses.get(0);
|
||||
if (firstClass.isClass()) {
|
||||
sb.append("extends ").append(firstClass.getSimpleName()).append(" ");
|
||||
}
|
||||
String str = innerClasses.stream()
|
||||
.filter(x -> !x.isClass())
|
||||
.map(InnerClass::getSimpleName)
|
||||
.collect(Collectors.joining(", "));
|
||||
if (!str.isEmpty()) {
|
||||
sb.append("implements ").append(str);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}, INTERFACE("interface") {
|
||||
@Override
|
||||
public boolean canBeInherited(List<InnerClass> innerClasses) {
|
||||
return !innerClasses.stream().anyMatch(InnerClass::isClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateInheritanceString(List<InnerClass> innerClasses) {
|
||||
if (innerClasses.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return "extends " + innerClasses.stream()
|
||||
.map(InnerClass::getSimpleName)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
};
|
||||
|
||||
private final String classType;
|
||||
private ClassType(String classType) {
|
||||
this.classType = classType;
|
||||
}
|
||||
|
||||
public String getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
public abstract boolean canBeInherited(List<InnerClass> innerClasses);
|
||||
|
||||
public abstract String generateInheritanceString(List<InnerClass> innerClasses);
|
||||
}
|
||||
|
||||
enum InnerClass {
|
||||
INNER_1("pkg.Test.InnerClass.Inner1", true),
|
||||
INNER_2("pkg.Test.InnerClass.Inner2", true),
|
||||
INNER_3("pkg.Test.InnerClass.Inner3", true),
|
||||
IINNER_1("pkg.Test.InnerClass1.IInner1", false),
|
||||
IINNER_2("pkg.Test.InnerInterface1.IInner2", false),
|
||||
IINNER_3("pkg.Test.InnerInterface2.IInner3", false);
|
||||
|
||||
private final String canonicalName;
|
||||
private final boolean isForTypeParameter;
|
||||
|
||||
private InnerClass(String canonicalName, boolean isForTypeParameter) {
|
||||
this.canonicalName = canonicalName;
|
||||
this.isForTypeParameter = isForTypeParameter;
|
||||
}
|
||||
|
||||
private static List<List<InnerClass>> getAllCombinations(boolean isTypeParameter) {
|
||||
List<List<InnerClass>> result = new ArrayList<>();
|
||||
List<InnerClass> tmpl = Stream.of(InnerClass.values())
|
||||
.filter(i -> i.isForTypeParameter() == isTypeParameter)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
result.add(Arrays.asList());
|
||||
for (int i = 0; i < tmpl.size(); ++i) {
|
||||
result.add(Arrays.asList(tmpl.get(i)));
|
||||
for (int j = i + 1; j < tmpl.size(); ++j) {
|
||||
result.add(Arrays.asList(tmpl.get(i), tmpl.get(j)));
|
||||
}
|
||||
}
|
||||
result.add(tmpl);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<List<InnerClass>> getAllCombinationsForTypeParameter() {
|
||||
return getAllCombinations(true);
|
||||
}
|
||||
|
||||
public static List<List<InnerClass>> getAllCombinationsForInheritance() {
|
||||
return getAllCombinations(false);
|
||||
}
|
||||
|
||||
public String getCanonicalName() {
|
||||
return canonicalName;
|
||||
}
|
||||
|
||||
public String getSimpleName() {
|
||||
String cName = getCanonicalName();
|
||||
return cName.substring(cName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
String cName = getCanonicalName();
|
||||
int dotIndex = cName.lastIndexOf('.');
|
||||
return dotIndex == -1 ? "" : cName.substring(0, dotIndex);
|
||||
}
|
||||
|
||||
public boolean isClass() {
|
||||
return this == INNER_1 || this == IINNER_1;
|
||||
}
|
||||
private boolean isForTypeParameter() {
|
||||
return isForTypeParameter;
|
||||
}
|
||||
}
|
||||
}
|
330
langtools/test/tools/javac/importscope/ImportMembersTest.java
Normal file
330
langtools/test/tools/javac/importscope/ImportMembersTest.java
Normal file
@ -0,0 +1,330 @@
|
||||
/*
|
||||
* 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 8065360
|
||||
* @summary The test checks possibility of class members to be imported.
|
||||
* @library /tools/lib
|
||||
* @build ToolBox ImportMembersTest
|
||||
* @run main ImportMembersTest
|
||||
*/
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The test checks that members of a class, an enum, an interface or annotation
|
||||
* can be imported with help of a static import or an import statement.
|
||||
* The tests generates a code, compiles it and checks whether it can be compiled
|
||||
* successfully or fails with a proper message.
|
||||
* The following is the example of a test case:
|
||||
* package pkg;
|
||||
* class ChildA extends A {}
|
||||
*
|
||||
* package pkg;
|
||||
* class A {
|
||||
* static class Inner {}
|
||||
* static Object field;
|
||||
* static void method() {}
|
||||
* }
|
||||
*
|
||||
* package pkg;
|
||||
* import static pkg.ChildA.method;
|
||||
* public class Test {{
|
||||
* method();
|
||||
* }}
|
||||
*
|
||||
*/
|
||||
public class ImportMembersTest {
|
||||
|
||||
private static final String[] expectedErrorMessages = {
|
||||
"Test.java:\\d+:\\d+: compiler.err.cant.resolve.location: .*\n1 error\n",
|
||||
"Test.java:\\d+:\\d+: compiler.err.import.requires.canonical: .*\n1 error\n"
|
||||
};
|
||||
|
||||
private static final String sourceTemplate =
|
||||
"package pkg;\n" +
|
||||
"#IMPORT\n" +
|
||||
"public class Test {{\n" +
|
||||
" #STATEMENT\n" +
|
||||
"}}\n";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ImportMembersTest().test();
|
||||
}
|
||||
|
||||
public void test() {
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
for (ClassType classType : ClassType.values()) {
|
||||
for (ImportType importType : ImportType.values()) {
|
||||
for (MemberType memberType : MemberType.values()) {
|
||||
++total;
|
||||
List<ToolBox.JavaSource> sources = classType.getSources();
|
||||
sources.add(new ToolBox.JavaSource("Test.java",
|
||||
generateSource(classType, memberType, importType)));
|
||||
|
||||
CompilationResult compilationResult = compile(sources);
|
||||
boolean isErrorExpected = importType.hasError(classType, memberType);
|
||||
if (!compilationResult.isSuccessful) {
|
||||
if (isErrorExpected) {
|
||||
String expectedErrorMessage =
|
||||
getExpectedErrorMessage(classType, importType, memberType);
|
||||
if (compilationResult.message.matches(expectedErrorMessage)) {
|
||||
++passed;
|
||||
} else {
|
||||
reportFailure(sources, String.format("Expected compilation failure message:\n" +
|
||||
"%s\ngot message:\n%s",
|
||||
expectedErrorMessage, compilationResult.message));
|
||||
}
|
||||
} else {
|
||||
reportFailure(sources, String.format("Unexpected compilation failure:\n%s",
|
||||
compilationResult.message));
|
||||
}
|
||||
} else {
|
||||
if (isErrorExpected) {
|
||||
reportFailure(sources, "Expected compilation failure.");
|
||||
} else {
|
||||
++passed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String message = String.format(
|
||||
"Total test cases run: %d, passed: %d, failed: %d.",
|
||||
total, passed, total - passed);
|
||||
if (passed != total) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
echo(message);
|
||||
}
|
||||
|
||||
private String getExpectedErrorMessage(ClassType classType, ImportType importType, MemberType memberType) {
|
||||
String expectedErrorMessage;
|
||||
if (importType == ImportType.IMPORT && classType == ClassType.CHILD_A &&
|
||||
memberType == MemberType.CLASS) {
|
||||
expectedErrorMessage = expectedErrorMessages[1];
|
||||
} else {
|
||||
expectedErrorMessage = expectedErrorMessages[0];
|
||||
}
|
||||
return expectedErrorMessage;
|
||||
}
|
||||
|
||||
private void reportFailure(List<ToolBox.JavaSource> sources, String message) {
|
||||
echo("Test case failed!");
|
||||
printSources(sources);
|
||||
echo(message);
|
||||
echo();
|
||||
}
|
||||
|
||||
private String generateSource(ClassType classType, MemberType memberType, ImportType importType) {
|
||||
String importString = importType.generateImport(classType.getClassName(), memberType.getMemberType());
|
||||
String statement;
|
||||
if (importType.hasError(classType, memberType)) {
|
||||
// if the source code has a compilation error, nothing is added.
|
||||
// just to prevent the compiler from appending additional
|
||||
// compilation errors to output
|
||||
statement = "";
|
||||
} else if (memberType == MemberType.STAR) {
|
||||
// in case of import-on-demand, every class member is used
|
||||
if (importType == ImportType.STATIC_IMPORT) {
|
||||
statement = MemberType.CLASS.getStatement() + "\n "
|
||||
+ MemberType.FIELD.getStatement();
|
||||
// an annotation does not have a static method.
|
||||
if (classType != ClassType.D) {
|
||||
statement += "\n " + MemberType.METHOD.getStatement() + "\n";
|
||||
}
|
||||
} else {
|
||||
statement = classType != ClassType.CHILD_A
|
||||
? MemberType.CLASS.getStatement() : "";
|
||||
}
|
||||
} else {
|
||||
statement = memberType.getStatement();
|
||||
}
|
||||
return sourceTemplate
|
||||
.replace("#IMPORT", importString)
|
||||
.replace("#STATEMENT", statement);
|
||||
}
|
||||
|
||||
private static class CompilationResult {
|
||||
public final boolean isSuccessful;
|
||||
public final String message;
|
||||
|
||||
public CompilationResult(boolean isSuccessful, String message) {
|
||||
this.isSuccessful = isSuccessful;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
private CompilationResult compile(List<ToolBox.JavaSource> sources) {
|
||||
StringWriter writer = new StringWriter();
|
||||
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
|
||||
Boolean call = jc.getTask(writer, null, null, Arrays.asList("-XDrawDiagnostics"), null, sources).call();
|
||||
return new CompilationResult(call, writer.toString().replace(ToolBox.lineSeparator, "\n"));
|
||||
}
|
||||
|
||||
public void printSources(List<ToolBox.JavaSource> sources) {
|
||||
for (ToolBox.JavaSource javaSource : sources) {
|
||||
echo(javaSource.getCharContent(true).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void echo() {
|
||||
echo("");
|
||||
}
|
||||
|
||||
public void echo(String output) {
|
||||
printf(output + "\n");
|
||||
}
|
||||
|
||||
public void printf(String template, Object...args) {
|
||||
System.err.print(String.format(template, args).replace("\n", ToolBox.lineSeparator));
|
||||
}
|
||||
|
||||
enum ClassType {
|
||||
A("A",
|
||||
"package pkg;\n" +
|
||||
"class A {\n" +
|
||||
" static class Inner {}\n" +
|
||||
" static Object field;\n" +
|
||||
" static void method() {}\n" +
|
||||
"}\n"
|
||||
),
|
||||
B("B",
|
||||
"package pkg;\n" +
|
||||
"interface B {\n" +
|
||||
" static class Inner {}\n" +
|
||||
" static Object field = null;\n" +
|
||||
" static void method() {}\n" +
|
||||
"}\n"
|
||||
),
|
||||
C("C",
|
||||
"package pkg;\n" +
|
||||
"enum C {field;\n" +
|
||||
" static class Inner {}\n" +
|
||||
" static void method() {}\n" +
|
||||
"}\n"
|
||||
),
|
||||
D("D",
|
||||
"package pkg;\n" +
|
||||
"@interface D {\n" +
|
||||
" static class Inner {}\n" +
|
||||
" static Object field = null;\n" +
|
||||
"}\n"
|
||||
),
|
||||
CHILD_A("ChildA",
|
||||
"package pkg;\n" +
|
||||
"class ChildA extends A {}\n",
|
||||
A);
|
||||
|
||||
private final String className;
|
||||
private final String source;
|
||||
private final ClassType parentType;
|
||||
|
||||
private ClassType(String className, String source) {
|
||||
this(className, source, null);
|
||||
}
|
||||
|
||||
private ClassType(String className, String source, ClassType classType) {
|
||||
this.className = className;
|
||||
this.source = source;
|
||||
this.parentType = classType;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public List<ToolBox.JavaSource> getSources() {
|
||||
List<ToolBox.JavaSource> sourceList = new ArrayList<>();
|
||||
ClassType current = this;
|
||||
while (current != null) {
|
||||
sourceList.add(new ToolBox.JavaSource(current.className, current.source));
|
||||
current = current.parentType;
|
||||
}
|
||||
return sourceList;
|
||||
}
|
||||
}
|
||||
|
||||
enum MemberType {
|
||||
CLASS("Inner", "Inner inner = null;"),
|
||||
FIELD("field", "Object o = field;"),
|
||||
METHOD("method", "method();"),
|
||||
STAR("*", ""),
|
||||
NOT_EXIST("NotExist", "");
|
||||
|
||||
private final String memberType;
|
||||
private final String statement;
|
||||
|
||||
private MemberType(String memberType, String statement) {
|
||||
this.memberType = memberType;
|
||||
this.statement = statement;
|
||||
}
|
||||
|
||||
public String getStatement() {
|
||||
return statement;
|
||||
}
|
||||
|
||||
public String getMemberType() {
|
||||
return memberType;
|
||||
}
|
||||
}
|
||||
|
||||
enum ImportType {
|
||||
IMPORT("import pkg.#CLASS_NAME.#MEMBER_NAME;"),
|
||||
STATIC_IMPORT("import static pkg.#CLASS_NAME.#MEMBER_NAME;");
|
||||
|
||||
private final String importType;
|
||||
|
||||
private ImportType(String importType) {
|
||||
this.importType = importType;
|
||||
}
|
||||
|
||||
public String generateImport(String className, String memberName) {
|
||||
return importType
|
||||
.replace("#CLASS_NAME", className)
|
||||
.replace("#MEMBER_NAME", memberName);
|
||||
}
|
||||
|
||||
public boolean hasError(ClassType classType, MemberType memberType) {
|
||||
switch (memberType) {
|
||||
case FIELD:
|
||||
return this != ImportType.STATIC_IMPORT;
|
||||
case METHOD:
|
||||
return this != ImportType.STATIC_IMPORT || classType == ClassType.D;
|
||||
case NOT_EXIST:
|
||||
return true;
|
||||
case CLASS:
|
||||
return classType.parentType != null && this != STATIC_IMPORT;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,335 @@
|
||||
/*
|
||||
* 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 8064794
|
||||
* @summary The negative test against cyclic dependencies.
|
||||
* @library /tools/lib
|
||||
* @build ToolBox NegativeCyclicDependencyTest
|
||||
* @run main NegativeCyclicDependencyTest
|
||||
*/
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The test generates the following code:
|
||||
*
|
||||
* package pkg;
|
||||
* import pkg.B.InnerB;
|
||||
* class A extends InnerB {
|
||||
* static class InnerA {}
|
||||
* }
|
||||
*
|
||||
* package pkg;
|
||||
* import pkg.A.InnerA;
|
||||
* class B extends InnerA {
|
||||
* static class InnerB {}
|
||||
* }
|
||||
*
|
||||
* compiles and checks whether compilation fails with the correct message.
|
||||
* The test generates all possible combination of inheritance:
|
||||
* 1. A extends InnerB, B extends InnerA;
|
||||
* 2. InnerA extends InnerB, InnerB extends InnerA;
|
||||
* 3. A extends InnerB, InnerB extends InnerA;
|
||||
* 4. B extends InnerA, InnerA extends InnerB;
|
||||
* 5. A extends InnerA.
|
||||
* The test checks class, enum and interface as parent class, and checks all
|
||||
* possible import statements.
|
||||
*/
|
||||
public class NegativeCyclicDependencyTest {
|
||||
private final static String expectedErrorMessage =
|
||||
"\\w+:\\d+:\\d+: compiler.err.cyclic.inheritance: [\\w.]+\n1 error\n";
|
||||
|
||||
private final static String[] sourceTemplatesA = {
|
||||
"package pkg;\n" +
|
||||
"#IMPORT_TYPE\n" +
|
||||
"#OUTER_CLASS A #INHERIT InnerB {#ENUM_SEMI\n" +
|
||||
" static #INNER_CLASS InnerA {}\n" +
|
||||
"}",
|
||||
"package pkg;\n" +
|
||||
"#IMPORT_TYPE\n" +
|
||||
"#OUTER_CLASS A {#ENUM_SEMI\n" +
|
||||
" static #INNER_CLASS InnerA #INHERIT InnerB {}\n" +
|
||||
"}"
|
||||
};
|
||||
|
||||
private final static String[] sourceTemplatesB = {
|
||||
"package pkg;\n" +
|
||||
"#IMPORT_TYPE\n" +
|
||||
"#OUTER_CLASS B #INHERIT InnerA {#ENUM_SEMI\n" +
|
||||
" static #INNER_CLASS InnerB {}\n" +
|
||||
"}",
|
||||
"package pkg;\n" +
|
||||
"#IMPORT_TYPE\n" +
|
||||
"#OUTER_CLASS B {#ENUM_SEMI\n" +
|
||||
" static #INNER_CLASS InnerB #INHERIT InnerA {}\n" +
|
||||
"}"
|
||||
};
|
||||
|
||||
private final static String sourceTemplate =
|
||||
"package pkg;\n" +
|
||||
"#IMPORT_TYPE\n" +
|
||||
"#OUTER_CLASS A #INHERIT InnerA {#ENUM_SEMI\n" +
|
||||
" static #INNER_CLASS InnerA {}\n" +
|
||||
"}";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new NegativeCyclicDependencyTest().test();
|
||||
}
|
||||
|
||||
public void test() {
|
||||
int passed = 0;
|
||||
List<TestCase> testCases = generateTestCases();
|
||||
for (TestCase testCase : testCases) {
|
||||
try {
|
||||
String output = compile(testCase.sources);
|
||||
if (!output.matches(testCase.expectedMessage)) {
|
||||
reportFailure(testCase);
|
||||
printf(String.format("Message: %s, does not match regexp: %s\n",
|
||||
output, testCase.expectedMessage));
|
||||
} else {
|
||||
++passed;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
reportFailure(testCase);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String message = String.format(
|
||||
"Total test cases run: %d, passed: %d, failed: %d.",
|
||||
testCases.size(), passed, testCases.size() - passed);
|
||||
if (passed != testCases.size()) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
echo(message);
|
||||
}
|
||||
|
||||
private void reportFailure(TestCase testCase) {
|
||||
echo("Test case failed.");
|
||||
for (ToolBox.JavaSource source : testCase.sources) {
|
||||
echo(source.getCharContent(true));
|
||||
echo();
|
||||
}
|
||||
}
|
||||
|
||||
public List<TestCase> generateTestCases() {
|
||||
List<TestCase> testCases = generateTestCasesWithTwoClasses();
|
||||
testCases.addAll(generateTestCasesWithOneClass());
|
||||
return testCases;
|
||||
}
|
||||
|
||||
private List<TestCase> generateTestCasesWithOneClass() {
|
||||
String importedClassName = "pkg.A.InnerA";
|
||||
List<TestCase> testCases = new ArrayList<>();
|
||||
for (ClassType outerClass : ClassType.values()) {
|
||||
for (ClassType innerClass : ClassType.values()) {
|
||||
if (!outerClass.canInherit(innerClass)) {
|
||||
continue;
|
||||
}
|
||||
for (ImportType importType : ImportType.values()) {
|
||||
String source = generateSource(
|
||||
sourceTemplate,
|
||||
outerClass,
|
||||
innerClass,
|
||||
outerClass.inheritedString(innerClass),
|
||||
importType,
|
||||
importedClassName);
|
||||
testCases.add(new TestCase(expectedErrorMessage,
|
||||
new ToolBox.JavaSource("A", source)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return testCases;
|
||||
}
|
||||
|
||||
private List<TestCase> generateTestCasesWithTwoClasses() {
|
||||
String importedClassName1 = "pkg.A.InnerA";
|
||||
String importedClassName2 = "pkg.B.InnerB";
|
||||
List<TestCase> testCases = new ArrayList<>();
|
||||
for (int i = 0; i < sourceTemplatesA.length; ++i) {
|
||||
for (int j = 0; j < sourceTemplatesB.length; ++j) {
|
||||
for (ClassType outerClass1 : ClassType.values()) {
|
||||
for (ClassType outerClass2 : ClassType.values()) {
|
||||
for (ClassType innerClass1 : ClassType.values()) {
|
||||
for (ClassType innerClass2 : ClassType.values()) {
|
||||
ClassType childClass1 = i == 0 ? outerClass1 : innerClass1;
|
||||
ClassType childClass2 = j == 0 ? outerClass2 : innerClass2;
|
||||
if (!childClass1.canInherit(innerClass2) ||
|
||||
!childClass2.canInherit(innerClass1)) {
|
||||
continue;
|
||||
}
|
||||
for (ImportType importType1 : ImportType.values()) {
|
||||
for (ImportType importType2 : ImportType.values()) {
|
||||
String sourceA = generateSource(
|
||||
sourceTemplatesA[i],
|
||||
outerClass1,
|
||||
innerClass1,
|
||||
childClass1.inheritedString(innerClass2),
|
||||
importType1,
|
||||
importedClassName2);
|
||||
String sourceB = generateSource(
|
||||
sourceTemplatesB[j],
|
||||
outerClass2,
|
||||
innerClass2,
|
||||
childClass2.inheritedString(innerClass1),
|
||||
importType2,
|
||||
importedClassName1);
|
||||
testCases.add(new TestCase(expectedErrorMessage,
|
||||
new ToolBox.JavaSource("A", sourceA),
|
||||
new ToolBox.JavaSource("B", sourceB)));
|
||||
testCases.add(new TestCase(expectedErrorMessage,
|
||||
new ToolBox.JavaSource("B", sourceB),
|
||||
new ToolBox.JavaSource("A", sourceA)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return testCases;
|
||||
}
|
||||
|
||||
public String generateSource(String template,
|
||||
ClassType outerClass,
|
||||
ClassType innerClass,
|
||||
String inheritString,
|
||||
ImportType importType,
|
||||
String innerClassName) {
|
||||
return template
|
||||
.replace("#OUTER_CLASS", outerClass.getType())
|
||||
.replace("#INNER_CLASS", innerClass.getType())
|
||||
.replace("#INHERIT", inheritString)
|
||||
.replace("#IMPORT_TYPE", importType.getImport(innerClassName))
|
||||
.replace("#ENUM_SEMI", outerClass == ClassType.ENUM ? ";" : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles sources with -XDrawDiagnostics flag and
|
||||
* returns the output of compilation.
|
||||
*
|
||||
* @param sources sources
|
||||
* @return the result of compilation
|
||||
*/
|
||||
private String compile(ToolBox.JavaSource...sources) {
|
||||
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
|
||||
StringWriter writer = new StringWriter();
|
||||
JavaCompiler.CompilationTask ct = jc.getTask(writer, null, null,
|
||||
Arrays.asList("-XDrawDiagnostics"),
|
||||
null, Arrays.asList(sources));
|
||||
if (ct.call()) {
|
||||
throw new RuntimeException("Expected compilation failure.");
|
||||
}
|
||||
return writer.toString().replace(ToolBox.lineSeparator, "\n");
|
||||
}
|
||||
|
||||
public void echo() {
|
||||
echo("");
|
||||
}
|
||||
|
||||
public void echo(CharSequence message) {
|
||||
echo(message.toString());
|
||||
}
|
||||
|
||||
public void echo(String message) {
|
||||
printf(message + "\n");
|
||||
}
|
||||
|
||||
public void printf(String template, Object...args) {
|
||||
System.err.print(String.format(template, args).replace("\n", ToolBox.lineSeparator));
|
||||
}
|
||||
|
||||
/**
|
||||
* The class represents a test case.
|
||||
*/
|
||||
public static class TestCase {
|
||||
public final ToolBox.JavaSource[] sources;
|
||||
public final String expectedMessage;
|
||||
|
||||
public TestCase(String expectedMessage, ToolBox.JavaSource...sources) {
|
||||
this.sources = sources;
|
||||
this.expectedMessage = expectedMessage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The enum represents all possible imports.
|
||||
*/
|
||||
public enum ImportType {
|
||||
SINGLE_IMPORT("import %s;"),
|
||||
IMPORT_ON_DEMAND("import %s.*;"),
|
||||
SINGLE_STATIC_IMPORT("import static %s;"),
|
||||
STATIC_IMPORT_ON_DEMAND("import static %s.*;");
|
||||
|
||||
private final String type;
|
||||
|
||||
private ImportType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getImport(String className) {
|
||||
if (this == ImportType.IMPORT_ON_DEMAND || this == ImportType.STATIC_IMPORT_ON_DEMAND) {
|
||||
int lastDot = className.lastIndexOf('.');
|
||||
className = className.substring(0, lastDot);
|
||||
}
|
||||
return String.format(type, className);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The enum represents all possible class types that can be used in
|
||||
* inheritance.
|
||||
*/
|
||||
public enum ClassType {
|
||||
CLASS("class"), INTERFACE("interface"), ENUM("enum");
|
||||
|
||||
public boolean canInherit(ClassType innerClass) {
|
||||
return innerClass != ENUM && !(this == ENUM && innerClass == ClassType.CLASS
|
||||
|| this == INTERFACE && innerClass == ClassType.CLASS);
|
||||
}
|
||||
|
||||
public String inheritedString(ClassType innerClass) {
|
||||
if (!canInherit(innerClass)) {
|
||||
throw new IllegalArgumentException(String.format("%s cannot inherit %s", this, innerClass));
|
||||
}
|
||||
return this == innerClass ? "extends" : "implements";
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
private ClassType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8007401 8007427
|
||||
* @bug 8007401 8007427 8061549
|
||||
* @author sogoel
|
||||
* @summary Test generation of warnings when '_' is used an identifier
|
||||
* @compile/fail/ref=IdentifierTest.out -Werror -XDrawDiagnostics IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest8.out -source 8 -Xlint:-options -Werror -XDrawDiagnostics IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest9.out -XDrawDiagnostics IdentifierTest.java
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,47 +0,0 @@
|
||||
IdentifierTest.java:40:11: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:43:16: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:44:20: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:45:22: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:50:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:50:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:50:23: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:52:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:54:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:60:21: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:61:42: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:62:67: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:69:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:70:14: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:71:18: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:76:22: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:78:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:78:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:80:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:80:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:87:10: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:87:38: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:93:14: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:100:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:100:26: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:117:20: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:122:10: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:127:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:130:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:137:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:137:24: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:137:33: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:138:39: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:142:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:143:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:144:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:149:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:150:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:156:16: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:158:25: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:167:5: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:171:26: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:173:19: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:179:11: compiler.warn.underscore.as.identifier
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
44 warnings
|
47
langtools/test/tools/javac/lambda/IdentifierTest8.out
Normal file
47
langtools/test/tools/javac/lambda/IdentifierTest8.out
Normal file
@ -0,0 +1,47 @@
|
||||
IdentifierTest.java:41:11: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:44:16: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:45:20: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:46:22: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:51:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:51:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:51:23: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:53:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:55:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:61:21: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:62:42: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:63:67: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:70:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:71:14: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:72:18: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:77:22: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:79:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:79:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:81:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:81:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:88:10: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:88:38: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:94:14: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:101:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:101:26: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:118:20: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:123:10: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:128:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:131:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:138:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:138:24: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:138:33: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:139:39: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:143:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:144:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:145:13: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:150:15: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:151:17: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:157:16: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:159:25: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:168:5: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:172:26: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:174:19: compiler.warn.underscore.as.identifier
|
||||
IdentifierTest.java:180:11: compiler.warn.underscore.as.identifier
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
44 warnings
|
45
langtools/test/tools/javac/lambda/IdentifierTest9.out
Normal file
45
langtools/test/tools/javac/lambda/IdentifierTest9.out
Normal file
@ -0,0 +1,45 @@
|
||||
IdentifierTest.java:41:11: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:44:16: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:45:20: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:46:22: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:51:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:51:15: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:51:23: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:53:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:55:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:61:21: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:62:42: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:63:67: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:70:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:71:14: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:72:18: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:77:22: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:79:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:79:15: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:81:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:81:15: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:88:10: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:88:38: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:94:14: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:101:17: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:101:26: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:118:20: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:123:10: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:128:17: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:131:17: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:138:17: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:138:24: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:138:33: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:139:39: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:143:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:144:15: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:145:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:150:15: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:151:17: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:157:16: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:159:25: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:168:5: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:172:26: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:174:19: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:180:11: compiler.err.underscore.as.identifier
|
||||
44 errors
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 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
|
||||
@ -24,7 +24,8 @@
|
||||
/*
|
||||
* @test
|
||||
* @summary Check usages of underscore as identifier generate warnings
|
||||
* @compile/fail/ref=WarnUnderscoreAsIdent.out -XDrawDiagnostics -Werror WarnUnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent8.out -source 8 -Xlint:-options -XDrawDiagnostics -Werror UnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent9.out -XDrawDiagnostics -Werror UnderscoreAsIdent.java
|
||||
*/
|
||||
package _._;
|
||||
|
20
langtools/test/tools/javac/lambda/UnderscoreAsIdent8.out
Normal file
20
langtools/test/tools/javac/lambda/UnderscoreAsIdent8.out
Normal file
@ -0,0 +1,20 @@
|
||||
UnderscoreAsIdent.java:30:9: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:30:11: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:32:8: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:32:10: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:34:7: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:35:12: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:36:10: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:36:19: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:38:16: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:18: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:25: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:33: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:44:34: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:47:9: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:49:19: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:51:9: compiler.warn.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:53:22: compiler.warn.underscore.as.identifier
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
17 warnings
|
18
langtools/test/tools/javac/lambda/UnderscoreAsIdent9.out
Normal file
18
langtools/test/tools/javac/lambda/UnderscoreAsIdent9.out
Normal file
@ -0,0 +1,18 @@
|
||||
UnderscoreAsIdent.java:30:9: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:30:11: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:32:8: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:32:10: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:34:7: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:35:12: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:36:10: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:36:19: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:38:16: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:18: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:25: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:41:33: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:44:34: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:47:9: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:49:19: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:51:9: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:53:22: compiler.err.underscore.as.identifier
|
||||
17 errors
|
@ -1,20 +0,0 @@
|
||||
WarnUnderscoreAsIdent.java:29:9: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:29:11: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:31:8: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:31:10: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:33:7: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:34:12: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:35:10: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:35:19: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:37:16: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:40:18: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:40:25: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:40:33: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:43:34: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:46:9: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:48:19: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:50:9: compiler.warn.underscore.as.identifier
|
||||
WarnUnderscoreAsIdent.java:52:22: compiler.warn.underscore.as.identifier
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
17 warnings
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7073631 7159445 7156633 8028235
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753
|
||||
* @summary tests error and diagnostics positions
|
||||
* @author Jan Lahoda
|
||||
*/
|
||||
@ -49,8 +49,11 @@ 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.main.Main;
|
||||
import com.sun.tools.javac.main.Main.Result;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -941,6 +944,21 @@ public class JavacParserTest extends TestCase {
|
||||
TypeKind.VOID);
|
||||
}
|
||||
|
||||
@Test //JDK-8065753
|
||||
void testWrongFirstToken() throws IOException {
|
||||
String code = "<";
|
||||
String expectedErrors = "Test.java:1:1: compiler.err.expected3: class, interface, enum\n" +
|
||||
"1 error\n";
|
||||
StringWriter out = new StringWriter();
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null,
|
||||
Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
|
||||
|
||||
Result errorCode = ct.doCall();
|
||||
assertEquals("the error code is not correct; actual:" + errorCode, Main.Result.ERROR, errorCode);
|
||||
String actualErrors = normalize(out.toString());
|
||||
assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
|
||||
}
|
||||
|
||||
void run(String[] args) throws Exception {
|
||||
int passed = 0, failed = 0;
|
||||
final Pattern p = (args != null && args.length > 0)
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.element.*;
|
||||
@ -176,6 +177,7 @@ public class T6348193 extends AbstractProcessor
|
||||
public void checkPropertyAccess(String key) { /*OK*/ }
|
||||
|
||||
public void checkDelete(String file) { /*OK*/ }
|
||||
public void checkPermission(Permission perm) { /*OK*/ }
|
||||
public void checkRead(FileDescriptor fd) { /*OK*/ }
|
||||
public void checkRead(String file) { /*OK*/ }
|
||||
public void checkRead(String file, Object context) { /*OK*/ }
|
||||
|
@ -265,19 +265,19 @@ public class TestDocComments extends JavacTestingAbstractProcessor {
|
||||
|
||||
class TestElementScanner extends ElementScanner<Void, Void> {
|
||||
@Override
|
||||
public Void visitExecutable(ExecutableElement e, Void _) {
|
||||
public Void visitExecutable(ExecutableElement e, Void p) {
|
||||
check(e);
|
||||
return super.visitExecutable(e, _);
|
||||
return super.visitExecutable(e, p);
|
||||
}
|
||||
@Override
|
||||
public Void visitType(TypeElement e, Void _) {
|
||||
public Void visitType(TypeElement e, Void p) {
|
||||
check(e);
|
||||
return super.visitType(e, _);
|
||||
return super.visitType(e, p);
|
||||
}
|
||||
@Override
|
||||
public Void visitVariable(VariableElement e, Void _) {
|
||||
public Void visitVariable(VariableElement e, Void p) {
|
||||
check(e);
|
||||
return super.visitVariable(e, _);
|
||||
return super.visitVariable(e, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,5 +27,5 @@
|
||||
* @summary javac does not detect cyclic inheritance involving static inner classes after import clause
|
||||
* @author Maurizio Cimadamore
|
||||
*
|
||||
* @compile/fail a/FooInterface.java
|
||||
* @compile/fail/ref=T6695838.out -XDrawDiagnostics a/FooInterface.java
|
||||
*/
|
||||
|
@ -0,0 +1,2 @@
|
||||
Foo.java:26:1: compiler.err.cyclic.inheritance: a.Foo
|
||||
1 error
|
@ -140,9 +140,9 @@ public class TreePosRoundsTest extends AbstractProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitVariable(VariableTree tree, Void _) {
|
||||
public Void visitVariable(VariableTree tree, Void p) {
|
||||
check(getCurrentPath());
|
||||
return super.visitVariable(tree, _);
|
||||
return super.visitVariable(tree, p);
|
||||
}
|
||||
|
||||
void check(TreePath tp) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 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
|
||||
@ -22,5 +22,5 @@
|
||||
*/
|
||||
|
||||
public class JavacWarning {
|
||||
String _ = null; // this will cause a warning. It may be deprecated in JDK8
|
||||
String _ = null; // this will cause a warning with -source 8 (this is an error as of -source 9)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 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
|
||||
@ -46,6 +46,7 @@ public class Test {
|
||||
File testSrc = new File(System.getProperty("test.src"));
|
||||
String[] args = {
|
||||
"-Xdoclint:none",
|
||||
"-source", "8",
|
||||
"-bootclasspath", System.getProperty("sun.boot.class.path"),
|
||||
"-classpath", ".",
|
||||
"-package",
|
||||
|
Loading…
x
Reference in New Issue
Block a user