OpenJDK / type-annotations / type-annotations / langtools
changeset 3499:27a6c3c4ab84 tip
Automated merge with http://hg.openjdk.java.net/jdk9/dev/langtools
line wrap: on
line diff
--- a/.hgtags Wed Jul 23 09:19:23 2014 -0700 +++ b/.hgtags Wed Jul 23 15:10:11 2014 -0400 @@ -140,6 +140,7 @@ 1cbe86c11ba69521875c0b0357d7540781eb334d jdk8-b17 ec2c0973cc31e143cffc05ceb63d98fae76f97d4 jdk8-b16 ab1b1cc7857716914f2bb20b3128e5a8978290f7 jdk8-b18 +2a2d6ac056cfde7326f309ab73b8cddf518cc729 308-jdk8-sync 77b2c066084cbc75150efc6603a713c558329813 jdk8-b19 ffd294128a48cbb90ce8f0569f82b61f1f164a18 jdk8-b20 bcb21abf1c4177baf4574f99709513dcd4474727 jdk8-b21
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,6 +25,7 @@ package com.sun.tools.javac.code; +import java.util.Arrays; import java.util.Iterator; import com.sun.tools.javac.tree.JCTree.JCLambda; @@ -158,7 +159,7 @@ // the catch type index. Then in // com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions we // use that value to determine the exception table index. - private int exception_index = Integer.MIN_VALUE; + public int exception_index = Integer.MIN_VALUE; // If this type annotation is within a lambda expression, // store a pointer to the lambda expression tree in order @@ -389,6 +390,27 @@ } /** + * Create a new TypeAnnotationPosition with the same values as the input, deeply copied. + * + * @param tapos The input value. + * @return A new copy of the input. + */ + public static TypeAnnotationPosition copy(final TypeAnnotationPosition tapos) { + TypeAnnotationPosition res = new TypeAnnotationPosition(tapos.type, tapos.pos, tapos.parameter_index, + tapos.onLambda, tapos.type_index, tapos.bound_index, List.from(tapos.location)); + res.isValidOffset = tapos.isValidOffset; + res.exception_index = tapos.exception_index; + if (tapos.lvarIndex != null) + res.lvarIndex = Arrays.copyOf(tapos.lvarIndex, tapos.lvarIndex.length); + if (tapos.lvarLength != null) + res.lvarLength = Arrays.copyOf(tapos.lvarLength, tapos.lvarLength.length); + if (tapos.lvarOffset != null) + res.lvarOffset = Arrays.copyOf(tapos.lvarOffset, tapos.lvarOffset.length); + res.offset = tapos.offset; + return res; + } + + /** * Create a {@code TypeAnnotationPosition} for a method return. * * @param location The type path.
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jul 23 15:10:11 2014 -0400 @@ -2765,7 +2765,7 @@ } public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { - Assert.checkNonNull(a.type, "annotation tree hasn't been attributed yet: " + a); + Assert.checkNonNull(a.type); // , "annotation tree hasn't been attributed yet: " + a); validateAnnotationTree(a); if (a.hasTag(TYPE_ANNOTATION) &&
--- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Wed Jul 23 15:10:11 2014 -0400 @@ -123,8 +123,8 @@ throw new IllegalArgumentException(t.toString()); Type unboxed = types.unboxedType((Type) t); if (! unboxed.isPrimitive()) // only true primitives, not void - throw new IllegalArgumentException(t.toString()); - return (PrimitiveType)unboxed; + throw new IllegalArgumentException(String.format("unboxed (%s) is not primitive: t=%s, this=%s, this.types=%s", unboxed, t, this, this.types)); + return (PrimitiveType) unboxed; } public TypeMirror capture(TypeMirror t) {
--- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Wed Jul 23 15:10:11 2014 -0400 @@ -30,7 +30,6 @@ import java.util.ArrayList; import com.sun.tools.javac.util.Position.LineMap; -import com.sun.tools.javac.parser.JavaTokenizer.*; import static com.sun.tools.javac.parser.Tokens.*;
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Wed Jul 23 15:10:11 2014 -0400 @@ -47,7 +47,7 @@ /** * A rich diagnostic formatter is a formatter that provides better integration - * with javac's type system. A diagostic is first preprocessed in order to keep + * with javac's type system. A diagnostic is first preprocessed in order to keep * track of each types/symbols in it; after these informations are collected, * the diagnostic is rendered using a standard formatter, whose type/symbol printer * has been replaced by a more refined version provided by this rich formatter.
--- a/src/share/classes/javax/annotation/processing/Messager.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/annotation/processing/Messager.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,9 +25,10 @@ package javax.annotation.processing; -import javax.annotation.*; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; import javax.tools.Diagnostic; -import javax.lang.model.element.*; /** * A {@code Messager} provides the way for an annotation processor to
--- a/src/share/classes/javax/lang/model/element/Element.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/element/Element.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,16 +25,11 @@ package javax.lang.model.element; - import java.lang.annotation.Annotation; -import java.lang.annotation.AnnotationTypeMismatchException; -import java.lang.annotation.IncompleteAnnotationException; import java.util.List; import java.util.Set; -import javax.lang.model.type.*; -import javax.lang.model.util.*; - +import javax.lang.model.type.TypeMirror; /** * Represents a program element such as a package, class, or method.
--- a/src/share/classes/javax/lang/model/type/TypeMirror.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeMirror.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,8 +25,6 @@ package javax.lang.model.type; -import java.lang.annotation.Annotation; -import java.util.List; import javax.lang.model.element.*; import javax.lang.model.util.Types;
--- a/src/share/classes/javax/lang/model/type/TypeVariable.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeVariable.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,11 +25,8 @@ package javax.lang.model.type; - import javax.lang.model.element.Element; import javax.lang.model.element.TypeParameterElement; -import javax.lang.model.util.Types; - /** * Represents a type variable.
--- a/src/share/classes/javax/lang/model/type/TypeVisitor.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeVisitor.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,8 +25,6 @@ package javax.lang.model.type; -import javax.lang.model.element.*; - /** * A visitor of types, in the style of the * visitor design pattern. Classes implementing this
--- a/src/share/classes/javax/lang/model/util/Elements.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/util/Elements.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,13 +25,16 @@ package javax.lang.model.util; - import java.util.List; import java.util.Map; -import javax.lang.model.element.*; -import javax.lang.model.type.*; - +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Name; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; /** * Utility methods for operating on program elements.
--- a/src/share/classes/javax/lang/model/util/Types.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/lang/model/util/Types.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,12 +25,19 @@ package javax.lang.model.util; -import java.lang.annotation.Annotation; -import java.lang.annotation.AnnotationTypeMismatchException; -import java.lang.annotation.IncompleteAnnotationException; import java.util.List; -import javax.lang.model.element.*; -import javax.lang.model.type.*; + +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.ArrayType; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.ExecutableType; +import javax.lang.model.type.NoType; +import javax.lang.model.type.NullType; +import javax.lang.model.type.PrimitiveType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.WildcardType; /** * Utility methods for operating on types.
--- a/src/share/classes/javax/tools/JavaCompiler.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/tools/JavaCompiler.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,7 +25,6 @@ package javax.tools; -import java.io.File; import java.io.Writer; import java.nio.charset.Charset; import java.util.Locale;
--- a/src/share/classes/javax/tools/SimpleJavaFileObject.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/tools/SimpleJavaFileObject.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,12 +25,19 @@ package javax.tools; -import java.io.*; +import java.io.CharArrayReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.Writer; import java.net.URI; import java.nio.CharBuffer; + import javax.lang.model.element.Modifier; import javax.lang.model.element.NestingKind; -import javax.tools.JavaFileObject.Kind; /** * Provides simple implementations for most methods in JavaFileObject.
--- a/src/share/classes/javax/tools/StandardJavaFileManager.java Wed Jul 23 09:19:23 2014 -0700 +++ b/src/share/classes/javax/tools/StandardJavaFileManager.java Wed Jul 23 15:10:11 2014 -0400 @@ -27,7 +27,6 @@ import java.io.File; import java.io.IOException; -import java.util.*; /** * File manager based on {@linkplain File java.io.File}. A common way
--- a/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java Wed Jul 23 15:10:11 2014 -0400 @@ -61,12 +61,12 @@ static class Test { Object mtest( Test t){ return null; } public void test() { - mtest( new Test() { + mtest( new Test() { class InnerAnon { // Test1$1$InnerAnon.class - @A @B String ai_data = null; - @A @B String ai_m(){ return null; }; + @A @B String ai_data = null; + @A @B String ai_m(){ return null; }; } - InnerAnon IA = new InnerAnon(); + InnerAnon IA = new InnerAnon(); }); } @Retention(RUNTIME) @Target(TYPE_USE) @interface A { }
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java Wed Jul 23 15:10:11 2014 -0400 @@ -7,6 +7,7 @@ */ import java.lang.annotation.*; + import java.@A util.List; import @A java.util.Map; import java.util.@A HashMap;
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out Wed Jul 23 15:10:11 2014 -0400 @@ -1,7 +1,7 @@ -AnnotatedImport.java:10:13: compiler.err.expected: token.identifier -AnnotatedImport.java:10:16: compiler.err.expected3: class, interface, enum -AnnotatedImport.java:11:7: compiler.err.expected: token.identifier -AnnotatedImport.java:11:11: compiler.err.expected3: class, interface, enum -AnnotatedImport.java:12:18: compiler.err.expected: token.identifier -AnnotatedImport.java:12:21: compiler.err.expected3: class, interface, enum +AnnotatedImport.java:11:13: compiler.err.expected: token.identifier +AnnotatedImport.java:11:16: compiler.err.expected3: class, interface, enum +AnnotatedImport.java:12:7: compiler.err.expected: token.identifier +AnnotatedImport.java:12:11: compiler.err.expected3: class, interface, enum +AnnotatedImport.java:13:18: compiler.err.expected: token.identifier +AnnotatedImport.java:13:21: compiler.err.expected3: class, interface, enum 6 errors
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java Wed Jul 23 15:10:11 2014 -0400 @@ -6,7 +6,9 @@ * @compile/fail/ref=AnnotatedPackage1.out -XDrawDiagnostics AnnotatedPackage1.java */ -package name.@A p1.p2; +package name. @A p1.p2; + +import java.lang.annotation.*; import java.lang.annotation.*;
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out Wed Jul 23 15:10:11 2014 -0400 @@ -1,3 +1,3 @@ AnnotatedPackage1.java:9:14: compiler.err.expected: token.identifier -AnnotatedPackage1.java:9:17: compiler.err.expected3: class, interface, enum +AnnotatedPackage1.java:9:18: compiler.err.expected3: class, interface, enum 2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Enums.java Wed Jul 23 15:10:11 2014 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; + +/* + * @test + * bug 8030751 + * @ignore + * @summary Test population of reference info for enums + * @author wmdietl + * @compile -g Driver.java ReferenceInfoUtil.java Enums.java + * @run main Driver Enums + */ +public class Enums { + + @TADescription(annotation = "TA", type = FIELD) + public String enums1() { + return "enum Test { @TA E }"; + } + + @TADescriptions({ + @TADescription(annotation = "TA", type = FIELD), + @TADescription(annotation = "TB", type = FIELD) + }) + public String enums2() { + return "enum Test { @TA E1, @TB E2 }"; + } + + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String enums3() { + return "enum Test { E(new @TA Object()); Test(Object o) {} }"; + } +}
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java Wed Jul 23 15:10:11 2014 -0400 @@ -71,6 +71,58 @@ return "@TC String test @TA [] @TB [];"; } + @TADescriptions({ + @TADescription(annotation = "TA", type = FIELD), + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String fieldAsArray2() { + return "@TD String @TA [] @TB [] @TC [] test;"; + } + + @TADescriptions({ + @TADescription(annotation = "TC", type = FIELD), + @TADescription(annotation = "TA", type = FIELD, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String fieldAsArray2aOld() { + return "@TD String @TA [] @TB [] test @TC [];"; + } + + @TADescriptions({ + @TADescription(annotation = "TB", type = FIELD), + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TA", type = FIELD, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String fieldAsArray2bOld() { + return "@TD String @TA [] test @TB [] @TC [];"; + } + + @TADescriptions({ + @TADescription(annotation = "TA", type = FIELD), + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String fieldAsArray2cOld() { + return "@TD String test @TA [] @TB [] @TC [];"; + } + @TADescriptions({}) public String fieldWithDeclarationAnnotatin() { return "@Decl String test;";
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java Wed Jul 23 15:10:11 2014 -0400 @@ -72,6 +72,58 @@ return "@TC String test() @TA [] @TB [] { return null; }"; } + @TADescriptions({ + @TADescription(annotation = "TA", type = METHOD_RETURN), + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String methodReturnAsArray2() { + return "@TD String @TA [] @TB [] @TC [] test() { return null; }"; + } + + @TADescriptions({ + @TADescription(annotation = "TC", type = METHOD_RETURN), + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String methodReturnAsArray2aOld() { + return "@TD String @TA [] @TB [] test() @TC [] { return null; } "; + } + + @TADescriptions({ + @TADescription(annotation = "TB", type = METHOD_RETURN), + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String methodReturnAsArray2bOld() { + return "@TD String @TA [] test() @TB [] @TC [] { return null; } "; + } + + @TADescriptions({ + @TADescription(annotation = "TA", type = METHOD_RETURN), + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 0, 0 }), + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }), + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0, 0, 0 }) + }) + public String methodReturnAsArray2cOld() { + return "@TD String test() @TA [] @TB [] @TC [] { return null; } "; + } + @TADescriptions({}) public String methodWithDeclarationAnnotation() { return "@Decl String test() { return null; }";
--- a/test/tools/javac/processing/model/type/BasicAnnoTests.java Wed Jul 23 09:19:23 2014 -0700 +++ b/test/tools/javac/processing/model/type/BasicAnnoTests.java Wed Jul 23 15:10:11 2014 -0400 @@ -25,8 +25,8 @@ * @test * @bug 8013852 * @summary Annotations on types + * @ignore Test will be fixed in Java 8 update release. * @library /tools/javac/lib - * @ignore * @build JavacTestingAbstractProcessor DPrinter BasicAnnoTests * @compile/process -processor BasicAnnoTests -proc:only BasicAnnoTests.java */ @@ -47,6 +47,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.ArrayType; +import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVariable; @@ -234,6 +235,12 @@ return super.visitWildcard(t, p); } + @Override + public R visitDeclared(DeclaredType t, P p) { + scan(t.getTypeArguments(), p); + return super.visitDeclared(t, p); + } + R scan(TypeMirror t) { return scan(t, null); } @@ -285,4 +292,10 @@ @Test(posn=3, annoType=TA.class, expect="6") public int m3(float a) throws @TA(6) Exception { return 0; } + + @Test(posn=1, annoType=TA.class, expect="7") + public java.util.List<@TA(7) String> f7; + + @Test(posn=2, annoType=TA.class, expect="8") + public void m8(java.util.List<@TA(8) String> a) { } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/versions/check.sh Wed Jul 23 15:10:11 2014 -0400 @@ -0,0 +1,156 @@ +# +# Copyright (c) 2004, 2013, 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 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 +# @summary Check interpretation of -target and -source options +# @build CheckClassFileVersion +# @run shell check.sh + +TESTJAVA=${TESTJAVA:?} +TC=${TESTCLASSES-.} + +J="$TESTJAVA/bin/java" +JC="$TESTJAVA/bin/javac" +CFV="${TESTVMOPTS} -cp $TC CheckClassFileVersion" + +rm -f $TC/X.java $TC/X.java +echo 'public class X { }' > $TC/X.java +echo 'public enum Y { }' > $TC/Y.java + + +# Check class-file versions + +check() { + V=$1; shift + echo "+ javac $* [$V]" + "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $* $TC/X.java && "$J" $CFV $TC/X.class $V || exit 2 +} + +# check for all combinations of target values +check_target() { + check $1 -source $2 -target $3 + check $1 -source $2 -target 1.${3} +} +# check for all combinations of source and target values +check_source_target() { + check_target $1 $2 $3 + check_target $1 1.${2} $3 +} + +check 48.0 -source 1.4 + +check 49.0 -source 1.4 -target 1.5 +check 49.0 -source 1.5 -target 1.5 + +check_target 50.0 1.4 6 +check_target 50.0 1.5 6 +check_source_target 50.0 6 6 + +check_target 51.0 1.4 7 +check_target 51.0 1.5 7 +check_source_target 51.0 6 7 +check_source_target 51.0 7 7 + +check_target 52.0 1.4 8 +check_target 52.0 1.5 8 +check_source_target 52.0 6 8 +check_source_target 52.0 7 8 +check_source_target 52.0 8 8 + +check_target 52.0 1.5 9 +check_source_target 52.0 8 9 +check_source_target 52.0 9 9 + +# and finally the default with no options +check 52.0 + +# Check source versions + +fail() { + echo "+ javac $*" + if "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $*; then + echo "-- did not fail as expected" + exit 3 + else + echo "-- failed as expected" + fi +} + +pass() { + echo "+ javac $*" + if "$JC" ${TESTTOOLVMOPTS} -Xlint:options -d $TC $*; then + echo "-- passed" + else + echo "-- failed" + exit 4 + fi +} + +# the following need to be updated when -source 7 features are available +checksrc14() { pass $* $TC/X.java; fail $* $TC/Y.java; } +checksrc15() { pass $* $TC/X.java; pass $* $TC/Y.java; } +checksrc16() { checksrc15 $* ; } +checksrc17() { checksrc15 $* ; } +checksrc18() { checksrc15 $* ; } +checksrc19() { checksrc15 $* ; } + +checksrc14 -source 1.4 +checksrc14 -source 1.4 -target 1.5 + +checksrc15 -source 1.5 +checksrc15 -source 1.5 -target 1.5 + +checksrc16 -source 1.6 +checksrc16 -source 6 +checksrc16 -source 1.6 -target 1.6 +checksrc16 -source 6 -target 6 + +checksrc17 -source 1.7 +checksrc17 -source 7 +checksrc17 -source 1.7 -target 1.7 +checksrc17 -source 7 -target 7 + +checksrc18 -source 1.8 +checksrc18 -source 8 +checksrc18 -source 1.8 -target 1.8 +checksrc18 -source 8 -target 8 + +checksrc19 +checksrc19 -source 1.9 +checksrc19 -source 9 +checksrc19 -source 1.9 -target 1.9 +checksrc19 -source 9 -target 9 +checksrc19 -target 1.9 +checksrc19 -target 9 + +fail -source 1.5 -target 1.4 $TC/X.java +fail -source 1.6 -target 1.4 $TC/X.java +fail -source 6 -target 1.4 $TC/X.java +fail -source 1.6 -target 1.5 $TC/X.java +fail -source 6 -target 1.5 $TC/X.java +fail -source 7 -target 1.6 $TC/X.java +fail -source 8 -target 1.6 $TC/X.java +fail -source 8 -target 1.7 $TC/X.java +fail -source 9 -target 1.7 $TC/X.java +fail -source 9 -target 1.8 $TC/X.java