changeset 402:31ae4d53b775

support array class literals
author mali
date Tue, 24 Mar 2009 17:30:06 -0400
parents 17f445e54028
children 6fe31dab5a9c
files src/share/classes/com/sun/tools/javac/comp/TransTypes.java test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateTypeAnnotation.java test/tools/javac/typeAnnotations/failures/common/arrayclass/InvalidLocation.java test/tools/javac/typeAnnotations/failures/common/arrayclass/MissingAnnotationValue.java test/tools/javac/typeAnnotations/newlocations/ClassLiterals.java
diffstat 6 files changed, 159 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Mar 24 17:22:12 2009 -0400
+++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Mar 24 17:30:06 2009 -0400
@@ -906,9 +906,13 @@
                     JCFieldAccess fieldContext = (JCFieldAccess)context;
                     if (fieldContext.name == names._class) {
                         p.type = TargetType.CLASS_LITERAL;
-                        assert fieldContext.selected instanceof JCAnnotatedType;
-                        JCAnnotatedType fieldType = (JCAnnotatedType)fieldContext.selected;
-                        p.pos = fieldType.underlyingType.pos;
+                        if (fieldContext.selected instanceof JCAnnotatedType) {
+                            assert fieldContext.selected instanceof JCAnnotatedType;
+                            JCAnnotatedType fieldType = (JCAnnotatedType)fieldContext.selected;
+                            p.pos = fieldType.underlyingType.pos;
+                        } else if (fieldContext.selected instanceof JCArrayTypeTree) {
+                            p.pos = fieldContext.selected.pos;
+                        }
                     } else throw new AssertionError();
                     return p;
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java	Tue Mar 24 17:30:06 2009 -0400
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary check for duplicate annotation values
+ * @author Mahmood Ali
+ * @compile/fail DuplicateAnnotationValue.java
+ */
+class DuplicateAnnotationValue {
+  void test() {
+    Object a = String @A(value = 2, value = 1) [].class;
+  }
+}
+
+@interface A { int value(); }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateTypeAnnotation.java	Tue Mar 24 17:30:06 2009 -0400
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary check for duplicate annotations
+ * @author Mahmood Ali
+ * @compile/fail DuplicateTypeAnnotation.java
+ */
+
+class DuplicateTypeAnnotation {
+  void test() {
+    Object a = String @A @A [].class;
+  }
+}
+
+@interface A { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/InvalidLocation.java	Tue Mar 24 17:30:06 2009 -0400
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary check for invalid annotatins given the target
+ * @author Mahmood Ali
+ * @compile/fail InvalidLocation.java
+ */
+
+class InvalidLocation {
+  void test() {
+    Object a = String @A [].class;
+  }
+}
+
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE)
+@interface A { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/typeAnnotations/failures/common/arrayclass/MissingAnnotationValue.java	Tue Mar 24 17:30:06 2009 -0400
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary check for missing annotation value
+ * @author Mahmood Ali
+ * @compile/fail MissingAnnotationValue.java
+ */
+class MissingAnnotationValue {
+  void test() {
+    Object a = String @A [].class;
+  }
+}
+
+@interface A { int field(); }
--- a/test/tools/javac/typeAnnotations/newlocations/ClassLiterals.java	Tue Mar 24 17:22:12 2009 -0400
+++ b/test/tools/javac/typeAnnotations/newlocations/ClassLiterals.java	Tue Mar 24 17:30:06 2009 -0400
@@ -35,6 +35,11 @@
     if (@A int.class != int.class) throw new Error();
     if (@A int.class != Integer.TYPE) throw new Error();
     if (@A int @B(0) [].class != int[].class) throw new Error();
+
+    if (String[].class != @A String[].class) throw new Error();
+    if (String[].class != String @A [].class) throw new Error();
+    if (@A int[].class != int[].class) throw new Error();
+    if (@A int @B(0) [].class != int[].class) throw new Error();
   }
 }