From 1a3734cdfafb753a581e052c233f6a55d8073159 Mon Sep 17 00:00:00 2001 From: Yumin Qi Date: Tue, 27 May 2014 21:58:23 -0700 Subject: [PATCH 01/90] 8043896: Error reporting for insufficient shared region size is incorrect In SharedSpaceType, we have three enum types which are used in report_out_of_shared_space(SharedSpaceType type). In fact we supplied more than three messages and flags. This leads the warning always gives wrong message with the first not used. Reviewed-by: iklam, coleenp --- hotspot/src/share/vm/utilities/debug.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/hotspot/src/share/vm/utilities/debug.cpp b/hotspot/src/share/vm/utilities/debug.cpp index 604018f8dd9..ff3bc5d4c81 100644 --- a/hotspot/src/share/vm/utilities/debug.cpp +++ b/hotspot/src/share/vm/utilities/debug.cpp @@ -263,13 +263,11 @@ void report_untested(const char* file, int line, const char* message) { void report_out_of_shared_space(SharedSpaceType shared_space) { static const char* name[] = { - "native memory for metadata", "shared read only space", "shared read write space", "shared miscellaneous data space" }; static const char* flag[] = { - "Metaspace", "SharedReadOnlySize", "SharedReadWriteSize", "SharedMiscDataSize" From 39a66950594e30e74003f1e7c43c08a18c16ee61 Mon Sep 17 00:00:00 2001 From: Poonam Bajaj Date: Wed, 28 May 2014 06:26:05 -0700 Subject: [PATCH 02/90] 8043086: Hotspot is expected to report OOM which is occurred String.intern(), but crashes in JDK8u5 In case of allocation failure, restore the value of _chunk in Arena Reviewed-by: dholmes, dcubed --- hotspot/src/share/vm/memory/allocation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/src/share/vm/memory/allocation.cpp b/hotspot/src/share/vm/memory/allocation.cpp index 2a3f4135617..c0254d9123f 100644 --- a/hotspot/src/share/vm/memory/allocation.cpp +++ b/hotspot/src/share/vm/memory/allocation.cpp @@ -563,6 +563,7 @@ void* Arena::grow(size_t x, AllocFailType alloc_failmode) { _chunk = new (alloc_failmode, len) Chunk(len); if (_chunk == NULL) { + _chunk = k; // restore the previous value of _chunk return NULL; } if (k) k->set_next(_chunk); // Append new chunk to end of linked list From c291efb1dfddec04517441d707c4457a7dfc557a Mon Sep 17 00:00:00 2001 From: Dmitry Samersoff Date: Wed, 28 May 2014 07:36:32 -0700 Subject: [PATCH 03/90] 6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM Don't assert if one of classes in hierarhy was redefined Reviewed-by: coleenp, sspitsyn --- .../share/vm/classfile/classFileParser.cpp | 10 +- hotspot/src/share/vm/oops/instanceKlass.cpp | 15 +++ hotspot/src/share/vm/oops/instanceKlass.hpp | 9 +- .../test/runtime/RedefineFinalizer/Agent.java | 94 +++++++++++++++++++ .../test/runtime/RedefineFinalizer/Main.java | 34 +++++++ .../runtime/RedefineFinalizer/Martyr.java | 33 +++++++ .../runtime/RedefineFinalizer/MartyrSon.java | 28 ++++++ .../runtime/RedefineFinalizer/manifest.mf | 5 + .../test/runtime/RedefineFinalizer/testme.sh | 49 ++++++++++ 9 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 hotspot/test/runtime/RedefineFinalizer/Agent.java create mode 100644 hotspot/test/runtime/RedefineFinalizer/Main.java create mode 100644 hotspot/test/runtime/RedefineFinalizer/Martyr.java create mode 100644 hotspot/test/runtime/RedefineFinalizer/MartyrSon.java create mode 100644 hotspot/test/runtime/RedefineFinalizer/manifest.mf create mode 100644 hotspot/test/runtime/RedefineFinalizer/testme.sh diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index 61d9875c283..608b43ae150 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -4359,9 +4359,15 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) { Method* m = k->lookup_method(vmSymbols::finalize_method_name(), vmSymbols::void_method_signature()); if (m != NULL && !m->is_empty_method()) { - f = true; + f = true; + } + + // Spec doesn't prevent agent from redefinition of empty finalizer. + // Despite the fact that it's generally bad idea and redefined finalizer + // will not work as expected we shouldn't abort vm in this case + if (!k->has_redefined_this_or_super()) { + assert(f == k->has_finalizer(), "inconsistent has_finalizer"); } - assert(f == k->has_finalizer(), "inconsistent has_finalizer"); #endif // Check if this klass supports the java.lang.Cloneable interface diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index 34907dd55a5..bcf9dc0a097 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -1501,6 +1501,21 @@ Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, M return NULL; } +#ifdef ASSERT +// search through class hierarchy and return true if this class or +// one of the superclasses was redefined +bool InstanceKlass::has_redefined_this_or_super() const { + const InstanceKlass* klass = this; + while (klass != NULL) { + if (klass->has_been_redefined()) { + return true; + } + klass = InstanceKlass::cast(klass->super()); + } + return false; +} +#endif + // lookup a method in the default methods list then in all transitive interfaces // Do NOT return private or static methods Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name, diff --git a/hotspot/src/share/vm/oops/instanceKlass.hpp b/hotspot/src/share/vm/oops/instanceKlass.hpp index 9010b9171ac..57b06870290 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceKlass.hpp @@ -754,6 +754,11 @@ class InstanceKlass: public Klass { bool implements_interface(Klass* k) const; bool is_same_or_direct_interface(Klass* k) const; +#ifdef ASSERT + // check whether this class or one of its superclasses was redefined + bool has_redefined_this_or_super() const; +#endif + // Access to the implementor of an interface. Klass* implementor() const { @@ -811,8 +816,8 @@ class InstanceKlass: public Klass { // Casting from Klass* static InstanceKlass* cast(Klass* k) { - assert(k->is_klass(), "must be"); - assert(k->oop_is_instance(), "cast to InstanceKlass"); + assert(k == NULL || k->is_klass(), "must be"); + assert(k == NULL || k->oop_is_instance(), "cast to InstanceKlass"); return (InstanceKlass*) k; } diff --git a/hotspot/test/runtime/RedefineFinalizer/Agent.java b/hotspot/test/runtime/RedefineFinalizer/Agent.java new file mode 100644 index 00000000000..92b274ab02c --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/Agent.java @@ -0,0 +1,94 @@ +/* + * 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. + */ + +import java.lang.instrument.Instrumentation; +import java.lang.instrument.ClassDefinition; + +import jdk.internal.org.objectweb.asm.ClassWriter; +import jdk.internal.org.objectweb.asm.Label; +import jdk.internal.org.objectweb.asm.MethodVisitor; +import jdk.internal.org.objectweb.asm.Opcodes; + +public class Agent implements Opcodes { + + private static byte[] makeNewMartyr() { + ClassWriter cw = new ClassWriter(0); + MethodVisitor mv; + + cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "Martyr", null, "java/lang/Object", null); + cw.visitSource(null, null); + + { + mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); + mv.visitCode(); + Label lab0 = new Label(); + mv.visitLabel(lab0); + mv.visitLineNumber(1, lab0); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V"); + mv.visitInsn(RETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } + + { + mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null); + mv.visitCode(); + Label lab0 = new Label(); + mv.visitLabel(lab0); + mv.visitLineNumber(6, lab0); + mv.visitLdcInsn("Redefinition done"); + mv.visitInsn(ARETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } + + { + mv = cw.visitMethod(ACC_PROTECTED, "finalize", "()V", null, null); + mv.visitCode(); + Label lab0 = new Label(); + mv.visitLabel(lab0); + mv.visitLineNumber(8, lab0); + mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); + mv.visitLdcInsn("Finalizer called"); + mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); + mv.visitInsn(RETURN); + mv.visitMaxs(2, 1); + mv.visitEnd(); + } + + cw.visitEnd(); + return cw.toByteArray(); + } + + + public static void premain(String args, Instrumentation inst) throws Exception { + agentmain(args, inst); + } + + public static void agentmain(String args, Instrumentation inst) throws Exception { + ClassDefinition martyrDef = + new ClassDefinition(Class.forName("Martyr"), makeNewMartyr()); + inst.redefineClasses(martyrDef); + } +} diff --git a/hotspot/test/runtime/RedefineFinalizer/Main.java b/hotspot/test/runtime/RedefineFinalizer/Main.java new file mode 100644 index 00000000000..77f9f926d75 --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/Main.java @@ -0,0 +1,34 @@ +/* + * 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. + */ + +public class Main { + public static void main(String[] args) { + try { + MartyrSon m = new MartyrSon(); + System.out.println(m.getName()); + System.runFinalization(); + } catch (Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/hotspot/test/runtime/RedefineFinalizer/Martyr.java b/hotspot/test/runtime/RedefineFinalizer/Martyr.java new file mode 100644 index 00000000000..95f8ff2e056 --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/Martyr.java @@ -0,0 +1,33 @@ +/* + * 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. + */ + +public class Martyr { + public String getName() { + return "Redefinition NOT done"; + } + + protected void finalize() { + // should be empty + } + +} diff --git a/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java b/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java new file mode 100644 index 00000000000..22fd4e3e275 --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java @@ -0,0 +1,28 @@ +/* + * 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. + */ + +class MartyrSon extends Martyr { + public String getName() { + return super.getName(); + } +} diff --git a/hotspot/test/runtime/RedefineFinalizer/manifest.mf b/hotspot/test/runtime/RedefineFinalizer/manifest.mf new file mode 100644 index 00000000000..e337a65c01a --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/manifest.mf @@ -0,0 +1,5 @@ +Main-Class: Main +Agent-Class: Agent +Can-Redefine-Classes: true +Can-Retransform-Classes: true +Premain-Class: Agent diff --git a/hotspot/test/runtime/RedefineFinalizer/testme.sh b/hotspot/test/runtime/RedefineFinalizer/testme.sh new file mode 100644 index 00000000000..3b50f5050db --- /dev/null +++ b/hotspot/test/runtime/RedefineFinalizer/testme.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# 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 6904403 +# @summary Don't assert if we redefine finalize method +# @run shell testme.sh + +# This test shouldn't provoke and assert(f == k->has_finalizer()) failed: inconsistent has_finalizer + +. ${TESTSRC}/../../test_env.sh + +JAVAC=${COMPILEJAVA}${FS}bin${FS}javac +JAR=${COMPILEJAVA}${FS}bin${FS}jar +JAVA=${TESTJAVA}${FS}bin${FS}java + +TOOLS_JAR=${TESTJAVA}${FS}lib${FS}tools.jar + +cp ${TESTSRC}${FS}*.java . +${JAVAC} -XDignore.symbol.file -classpath ${TOOLS_JAR} -sourcepath ${TESTSRC} *.java +if [ $? -eq 1 ] + then + echo "Compilation failed" + exit +fi + +${JAR} cvfm testcase.jar ${TESTSRC}/manifest.mf . +${JAVA} -Xbootclasspath/a:${TOOLS_JAR} -javaagent:${PWD}/testcase.jar Main From 436e1ecdf25870ce9aecd85cf22c29151ea00f87 Mon Sep 17 00:00:00 2001 From: Christian Tornqvist Date: Wed, 28 May 2014 22:59:29 +0200 Subject: [PATCH 04/90] 8043786: [TESTBUG] runtime/CommandLine/TestHexArguments.java test fails in nightly Changed test to not pass on external flags to child processes Reviewed-by: coleenp, hseigel --- hotspot/test/runtime/CommandLine/TestHexArguments.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hotspot/test/runtime/CommandLine/TestHexArguments.java b/hotspot/test/runtime/CommandLine/TestHexArguments.java index 1fd33466662..f62435ed28d 100644 --- a/hotspot/test/runtime/CommandLine/TestHexArguments.java +++ b/hotspot/test/runtime/CommandLine/TestHexArguments.java @@ -35,14 +35,14 @@ import com.oracle.java.testlibrary.*; public class TestHexArguments { public static void main(String args[]) throws Exception { String[] javaArgs = {"-XX:SharedBaseAddress=0x1D000000", "-version"}; - ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, javaArgs); + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Could not create the Java Virtual Machine"); output.shouldHaveExitValue(0); String[] javaArgs1 = {"-XX:SharedBaseAddress=1D000000", "-version"}; - pb = ProcessTools.createJavaProcessBuilder(true, javaArgs1); + pb = ProcessTools.createJavaProcessBuilder(javaArgs1); output = new OutputAnalyzer(pb.start()); output.shouldContain("Could not create the Java Virtual Machine"); } From 06a856ab8aa71fdb0be36dac3672c709878fcc47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Fri, 30 May 2014 10:37:39 +0200 Subject: [PATCH 05/90] 8044132: Quarantine unstable/broken GC tests Reviewed-by: ehelin, jwilhelm --- hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java | 1 + hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java | 1 + hotspot/test/gc/g1/TestHumongousShrinkHeap.java | 1 + hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java | 1 + 4 files changed, 4 insertions(+) diff --git a/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java b/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java index 2de2826ed5b..947fd0f9c88 100644 --- a/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java +++ b/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java @@ -22,6 +22,7 @@ */ /* + * @ignore 8027915 * @test TestParallelHeapSizeFlags * @key gc * @bug 8006088 diff --git a/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java b/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java index 852076e768e..14ca6ed8d3b 100644 --- a/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java +++ b/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java @@ -22,6 +22,7 @@ */ /* + * @ignore 8025645 * @test TestUseCompressedOopsErgo * @key gc * @bug 8010722 diff --git a/hotspot/test/gc/g1/TestHumongousShrinkHeap.java b/hotspot/test/gc/g1/TestHumongousShrinkHeap.java index c790c6464bd..4cf6c4187c4 100644 --- a/hotspot/test/gc/g1/TestHumongousShrinkHeap.java +++ b/hotspot/test/gc/g1/TestHumongousShrinkHeap.java @@ -22,6 +22,7 @@ */ /** + * @ignore 8041506, 8041946, 8042051 * @test TestHumongousShrinkHeap * @bug 8036025 * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects diff --git a/hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java b/hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java index 6f9b02de270..7a23509712d 100644 --- a/hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java +++ b/hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java @@ -22,6 +22,7 @@ */ /** + * @ignore 8042051 * @test TestDynShrinkHeap * @bug 8016479 * @summary Verify that the heap shrinks after full GC according to the current values of the Min/MaxHeapFreeRatio flags From 44fc435b7ecfd5c19c18e4b7c72ac9282f885632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Fri, 30 May 2014 10:43:51 +0200 Subject: [PATCH 06/90] 8042310: TestStringDeduplicationMemoryUsage test failing Reviewed-by: ehelin, jwilhelm --- .../TestStringDeduplicationMemoryUsage.java | 36 -------- .../gc/g1/TestStringDeduplicationTools.java | 89 ------------------- 2 files changed, 125 deletions(-) delete mode 100644 hotspot/test/gc/g1/TestStringDeduplicationMemoryUsage.java diff --git a/hotspot/test/gc/g1/TestStringDeduplicationMemoryUsage.java b/hotspot/test/gc/g1/TestStringDeduplicationMemoryUsage.java deleted file mode 100644 index ba3428986e2..00000000000 --- a/hotspot/test/gc/g1/TestStringDeduplicationMemoryUsage.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 TestStringDeduplicationMemoryUsage - * @summary Test string deduplication memory usage - * @bug 8029075 - * @key gc - * @library /testlibrary - */ - -public class TestStringDeduplicationMemoryUsage { - public static void main(String[] args) throws Exception { - TestStringDeduplicationTools.testMemoryUsage(); - } -} diff --git a/hotspot/test/gc/g1/TestStringDeduplicationTools.java b/hotspot/test/gc/g1/TestStringDeduplicationTools.java index 5b27aa68590..1f8347bf4a1 100644 --- a/hotspot/test/gc/g1/TestStringDeduplicationTools.java +++ b/hotspot/test/gc/g1/TestStringDeduplicationTools.java @@ -294,55 +294,6 @@ class TestStringDeduplicationTools { } } - private static class MemoryUsageTest { - public static void main(String[] args) { - System.out.println("Begin: MemoryUsageTest"); - - final boolean useStringDeduplication = Boolean.parseBoolean(args[0]); - final int numberOfStrings = LargeNumberOfStrings; - final int numberOfUniqueStrings = 1; - - ArrayList list = createStrings(numberOfStrings, numberOfUniqueStrings); - forceDeduplication(DefaultAgeThreshold, FullGC); - - if (useStringDeduplication) { - verifyStrings(list, numberOfUniqueStrings); - } - - System.gc(); - - System.out.println("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed()); - System.out.println("Array Header Size: " + unsafe.ARRAY_CHAR_BASE_OFFSET); - - System.out.println("End: MemoryUsageTest"); - } - - public static OutputAnalyzer run(boolean useStringDeduplication) throws Exception { - String[] extraArgs = new String[0]; - - if (useStringDeduplication) { - extraArgs = new String[] { - "-XX:+UseStringDeduplication", - "-XX:+PrintStringDeduplicationStatistics", - "-XX:StringDeduplicationAgeThreshold=" + DefaultAgeThreshold - }; - } - - String[] defaultArgs = new String[] { - "-XX:+PrintGC", - "-XX:+PrintGCDetails", - MemoryUsageTest.class.getName(), - "" + useStringDeduplication - }; - - ArrayList args = new ArrayList(); - args.addAll(Arrays.asList(extraArgs)); - args.addAll(Arrays.asList(defaultArgs)); - - return runTest(args.toArray(new String[args.size()])); - } - } - /* * Tests */ @@ -480,44 +431,4 @@ class TestStringDeduplicationTools { OutputAnalyzer output = InternedTest.run(); output.shouldHaveExitValue(0); } - - public static void testMemoryUsage() throws Exception { - // Test that memory usage is reduced after deduplication - OutputAnalyzer output; - final String heapMemoryUsagePattern = "Heap Memory Usage: (\\d+)"; - final String arrayHeaderSizePattern = "Array Header Size: (\\d+)"; - - // Run without deduplication - output = MemoryUsageTest.run(false); - output.shouldHaveExitValue(0); - final long heapMemoryUsageWithoutDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1)); - final long arrayHeaderSizeWithoutDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1)); - - // Run with deduplication - output = MemoryUsageTest.run(true); - output.shouldHaveExitValue(0); - final long heapMemoryUsageWithDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1)); - final long arrayHeaderSizeWithDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1)); - - // Sanity check to make sure one instance isn't using compressed class pointers and the other not - if (arrayHeaderSizeWithoutDedup != arrayHeaderSizeWithDedup) { - throw new Exception("Unexpected difference between array header sizes"); - } - - // Calculate expected memory usage with deduplication enabled. This calculation does - // not take alignment and padding into account, so it's a conservative estimate. - final long sizeOfChar = unsafe.ARRAY_CHAR_INDEX_SCALE; - final long sizeOfCharArray = StringLength * sizeOfChar + arrayHeaderSizeWithoutDedup; - final long bytesSaved = (LargeNumberOfStrings - 1) * sizeOfCharArray; - final long heapMemoryUsageWithDedupExpected = heapMemoryUsageWithoutDedup - bytesSaved; - - System.out.println("Memory usage summary:"); - System.out.println(" heapMemoryUsageWithoutDedup: " + heapMemoryUsageWithoutDedup); - System.out.println(" heapMemoryUsageWithDedup: " + heapMemoryUsageWithDedup); - System.out.println(" heapMemoryUsageWithDedupExpected: " + heapMemoryUsageWithDedupExpected); - - if (heapMemoryUsageWithDedup > heapMemoryUsageWithDedupExpected) { - throw new Exception("Unexpected memory usage, heapMemoryUsageWithDedup should be less or equal to heapMemoryUsageWithDedupExpected"); - } - } } From 265262330861847d9bb24d57580680c3c2ebc0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Tue, 3 Jun 2014 10:37:46 +0200 Subject: [PATCH 07/90] 8040807: G1: Enable G1CollectedHeap::stop() Reviewed-by: brutisso, jmasa, tschatzl --- .../vm/gc_implementation/g1/concurrentMark.cpp | 4 ++-- .../vm/gc_implementation/g1/concurrentMark.hpp | 4 +++- .../vm/gc_implementation/g1/g1CollectedHeap.cpp | 16 +++++----------- hotspot/src/share/vm/runtime/java.cpp | 9 ++------- hotspot/src/share/vm/runtime/thread.cpp | 10 ++-------- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index 24c62d775bd..7478a1e163c 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -901,7 +901,7 @@ void ConcurrentMark::checkpointRootsInitialPre() { G1CollectedHeap* g1h = G1CollectedHeap::heap(); G1CollectorPolicy* g1p = g1h->g1_policy(); - _has_aborted = false; + clear_has_aborted(); #ifndef PRODUCT if (G1PrintReachableAtInitialMark) { @@ -3261,7 +3261,7 @@ void ConcurrentMark::abort() { } _first_overflow_barrier_sync.abort(); _second_overflow_barrier_sync.abort(); - _has_aborted = true; + set_has_aborted(); SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); satb_mq_set.abandon_partial_marking(); diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp index 9d049a2a255..c4dbcda557f 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp @@ -822,7 +822,9 @@ public: // Called to abort the marking cycle after a Full GC takes place. void abort(); - bool has_aborted() { return _has_aborted; } + bool has_aborted() { return _has_aborted; } + void set_has_aborted() { _has_aborted = true; } + void clear_has_aborted() { _has_aborted = false; } // This prints the global/local fingers. It is used for debugging. NOT_PRODUCT(void print_finger();) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 060ffb0b4a6..cef2ee0a8f0 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2174,20 +2174,14 @@ jint G1CollectedHeap::initialize() { } void G1CollectedHeap::stop() { -#if 0 - // Stopping concurrent worker threads is currently disabled until - // some bugs in concurrent mark has been resolve. Without fixing - // those bugs first we risk haning during VM exit when trying to - // stop these threads. - - // Abort any ongoing concurrent root region scanning and stop all - // concurrent threads. We do this to make sure these threads do - // not continue to execute and access resources (e.g. gclog_or_tty) - // that are destroyed during shutdown. + // Abort any ongoing concurrent mark and stop all concurrent threads. + // We do this to make sure these threads do not continue to execute + // and access resources (e.g. gclog_or_tty) that are destroyed during + // shutdown. + _cm->set_has_aborted(); _cm->root_regions()->abort(); _cm->root_regions()->wait_until_scan_finished(); stop_conc_gc_threads(); -#endif } size_t G1CollectedHeap::conservative_max_heap_alignment() { diff --git a/hotspot/src/share/vm/runtime/java.cpp b/hotspot/src/share/vm/runtime/java.cpp index e852b56ef54..3a075117afe 100644 --- a/hotspot/src/share/vm/runtime/java.cpp +++ b/hotspot/src/share/vm/runtime/java.cpp @@ -501,9 +501,6 @@ void before_exit(JavaThread * thread) { os::infinite_sleep(); } - // Stop any ongoing concurrent GC work - Universe::heap()->stop(); - // Terminate watcher thread - must before disenrolling any periodic task if (PeriodicTask::num_tasks() > 0) WatcherThread::stop(); @@ -518,10 +515,8 @@ void before_exit(JavaThread * thread) { StatSampler::disengage(); StatSampler::destroy(); - // We do not need to explicitly stop concurrent GC threads because the - // JVM will be taken down at a safepoint when such threads are inactive -- - // except for some concurrent G1 threads, see (comment in) - // Threads::destroy_vm(). + // Stop concurrent GC threads + Universe::heap()->stop(); // Print GC/heap related information. if (PrintGCDetails) { diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index e6d9eee7927..3591b35ece9 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3966,14 +3966,8 @@ bool Threads::destroy_vm() { // GC vm_operations can get caught at the safepoint, and the // heap is unparseable if they are caught. Grab the Heap_lock // to prevent this. The GC vm_operations will not be able to - // queue until after the vm thread is dead. - // After this point, we'll never emerge out of the safepoint before - // the VM exits, so concurrent GC threads do not need to be explicitly - // stopped; they remain inactive until the process exits. - // Note: some concurrent G1 threads may be running during a safepoint, - // but these will not be accessing the heap, just some G1-specific side - // data structures that are not accessed by any other threads but them - // after this point in a terminal safepoint. + // queue until after the vm thread is dead. After this point, + // we'll never emerge out of the safepoint before the VM exits. MutexLocker ml(Heap_lock); From 426151a22e29e9eea719e09c2a3109a7b9f01bc8 Mon Sep 17 00:00:00 2001 From: Bengt Rutisson Date: Tue, 3 Jun 2014 10:44:36 +0200 Subject: [PATCH 08/90] 8043239: G1: Missing post barrier in processing of j.l.ref.Reference objects Removed all write barriers during reference processing and added explicit write barriers when iterating through the discovered list. Reviewed-by: pliden, jmasa, tschatzl --- .../concurrentMarkSweepGeneration.cpp | 3 +- .../gc_implementation/g1/g1CollectedHeap.cpp | 10 +-- .../parNew/parNewGeneration.cpp | 3 +- .../parallelScavenge/psParallelCompact.cpp | 3 +- .../parallelScavenge/psScavenge.cpp | 3 +- .../share/vm/memory/referenceProcessor.cpp | 89 ++++++------------- .../share/vm/memory/referenceProcessor.hpp | 23 +---- 7 files changed, 38 insertions(+), 96 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index 43d6e923a7b..dba6f8ca7d7 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -311,8 +311,7 @@ void CMSCollector::ref_processor_init() { _cmsGen->refs_discovery_is_mt(), // mt discovery (int) MAX2(ConcGCThreads, ParallelGCThreads), // mt discovery degree _cmsGen->refs_discovery_is_atomic(), // discovery is not atomic - &_is_alive_closure, // closure for liveness info - false); // next field updates do not need write barrier + &_is_alive_closure); // closure for liveness info // Initialize the _ref_processor field of CMSGen _cmsGen->set_ref_processor(_ref_processor); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 060ffb0b4a6..83f819b3919 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2246,12 +2246,9 @@ void G1CollectedHeap::ref_processing_init() { // degree of mt discovery false, // Reference discovery is not atomic - &_is_alive_closure_cm, + &_is_alive_closure_cm); // is alive closure // (for efficiency/performance) - true); - // Setting next fields of discovered - // lists requires a barrier. // STW ref processor _ref_processor_stw = @@ -2266,12 +2263,9 @@ void G1CollectedHeap::ref_processing_init() { // degree of mt discovery true, // Reference discovery is atomic - &_is_alive_closure_stw, + &_is_alive_closure_stw); // is alive closure // (for efficiency/performance) - false); - // Setting next fields of discovered - // lists does not require a barrier. } size_t G1CollectedHeap::capacity() const { diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 2661e1280b6..5e979965731 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -1636,8 +1636,7 @@ void ParNewGeneration::ref_processor_init() { refs_discovery_is_mt(), // mt discovery (int) ParallelGCThreads, // mt discovery degree refs_discovery_is_atomic(), // atomic_discovery - NULL, // is_alive_non_header - false); // write barrier for next field updates + NULL); // is_alive_non_header } } diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp index de4c8bcdfd6..a9ffe54bd25 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @@ -854,8 +854,7 @@ void PSParallelCompact::post_initialize() { true, // mt discovery (int) ParallelGCThreads, // mt discovery degree true, // atomic_discovery - &_is_alive_closure, // non-header is alive closure - false); // write barrier for next field updates + &_is_alive_closure); // non-header is alive closure _counters = new CollectorCounters("PSParallelCompact", 1); // Initialize static fields in ParCompactionManager. diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp index 81510c905a1..fd3030462b8 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp @@ -864,8 +864,7 @@ void PSScavenge::initialize() { true, // mt discovery (int) ParallelGCThreads, // mt discovery degree true, // atomic_discovery - NULL, // header provides liveness info - false); // next field updates do not need write barrier + NULL); // header provides liveness info // Cache the cardtable BarrierSet* bs = Universe::heap()->barrier_set(); diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp index 2a87b4b65b6..2a074f21f15 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp @@ -96,12 +96,10 @@ ReferenceProcessor::ReferenceProcessor(MemRegion span, bool mt_discovery, uint mt_discovery_degree, bool atomic_discovery, - BoolObjectClosure* is_alive_non_header, - bool discovered_list_needs_post_barrier) : + BoolObjectClosure* is_alive_non_header) : _discovering_refs(false), _enqueuing_is_done(false), _is_alive_non_header(is_alive_non_header), - _discovered_list_needs_post_barrier(discovered_list_needs_post_barrier), _processing_is_mt(mt_processing), _next_id(0) { @@ -340,10 +338,18 @@ void ReferenceProcessor::enqueue_discovered_reflist(DiscoveredList& refs_list, // (java.lang.ref.Reference.discovered), self-loop their "next" field // thus distinguishing them from active References, then // prepend them to the pending list. + // + // The Java threads will see the Reference objects linked together through + // the discovered field. Instead of trying to do the write barrier updates + // in all places in the reference processor where we manipulate the discovered + // field we make sure to do the barrier here where we anyway iterate through + // all linked Reference objects. Note that it is important to not dirty any + // cards during reference processing since this will cause card table + // verification to fail for G1. + // // BKWRD COMPATIBILITY NOTE: For older JDKs (prior to the fix for 4956777), // the "next" field is used to chain the pending list, not the discovered // field. - if (TraceReferenceGC && PrintGCDetails) { gclog_or_tty->print_cr("ReferenceProcessor::enqueue_discovered_reflist list " INTPTR_FORMAT, (address)refs_list.head()); @@ -365,15 +371,15 @@ void ReferenceProcessor::enqueue_discovered_reflist(DiscoveredList& refs_list, assert(java_lang_ref_Reference::next(obj) == NULL, "Reference not active; should not be discovered"); // Self-loop next, so as to make Ref not active. - // Post-barrier not needed when looping to self. java_lang_ref_Reference::set_next_raw(obj, obj); - if (next_d == obj) { // obj is last + if (next_d != obj) { + oopDesc::bs()->write_ref_field(java_lang_ref_Reference::discovered_addr(obj), next_d); + } else { + // This is the last object. // Swap refs_list into pending_list_addr and // set obj's discovered to what we read from pending_list_addr. oop old = oopDesc::atomic_exchange_oop(refs_list.head(), pending_list_addr); - // Need post-barrier on pending_list_addr above; - // see special post-barrier code at the end of - // enqueue_discovered_reflists() further below. + // Need post-barrier on pending_list_addr. See enqueue_discovered_ref_helper() above. java_lang_ref_Reference::set_discovered_raw(obj, old); // old may be NULL oopDesc::bs()->write_ref_field(java_lang_ref_Reference::discovered_addr(obj), old); } @@ -496,20 +502,15 @@ void DiscoveredListIterator::remove() { // pre-barrier here because we know the Reference has already been found/marked, // that's how it ended up in the discovered list in the first place. oop_store_raw(_prev_next, new_next); - if (_discovered_list_needs_post_barrier && _prev_next != _refs_list.adr_head()) { - // Needs post-barrier and this is not the list head (which is not on the heap) - oopDesc::bs()->write_ref_field(_prev_next, new_next); - } NOT_PRODUCT(_removed++); _refs_list.dec_length(1); } // Make the Reference object active again. void DiscoveredListIterator::make_active() { - // For G1 we don't want to use set_next - it - // will dirty the card for the next field of - // the reference object and will fail - // CT verification. + // The pre barrier for G1 is probably just needed for the old + // reference processing behavior. Should we guard this with + // ReferenceProcessor::pending_list_uses_discovered_field() ? if (UseG1GC) { HeapWord* next_addr = java_lang_ref_Reference::next_addr(_ref); if (UseCompressedOops) { @@ -517,10 +518,8 @@ void DiscoveredListIterator::make_active() { } else { oopDesc::bs()->write_ref_field_pre((oop*)next_addr, NULL); } - java_lang_ref_Reference::set_next_raw(_ref, NULL); - } else { - java_lang_ref_Reference::set_next(_ref, NULL); } + java_lang_ref_Reference::set_next_raw(_ref, NULL); } void DiscoveredListIterator::clear_referent() { @@ -546,7 +545,7 @@ ReferenceProcessor::process_phase1(DiscoveredList& refs_list, OopClosure* keep_alive, VoidClosure* complete_gc) { assert(policy != NULL, "Must have a non-NULL policy"); - DiscoveredListIterator iter(refs_list, keep_alive, is_alive, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, keep_alive, is_alive); // Decide which softly reachable refs should be kept alive. while (iter.has_next()) { iter.load_ptrs(DEBUG_ONLY(!discovery_is_atomic() /* allow_null_referent */)); @@ -586,7 +585,7 @@ ReferenceProcessor::pp2_work(DiscoveredList& refs_list, BoolObjectClosure* is_alive, OopClosure* keep_alive) { assert(discovery_is_atomic(), "Error"); - DiscoveredListIterator iter(refs_list, keep_alive, is_alive, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, keep_alive, is_alive); while (iter.has_next()) { iter.load_ptrs(DEBUG_ONLY(false /* allow_null_referent */)); DEBUG_ONLY(oop next = java_lang_ref_Reference::next(iter.obj());) @@ -623,7 +622,7 @@ ReferenceProcessor::pp2_work_concurrent_discovery(DiscoveredList& refs_list, OopClosure* keep_alive, VoidClosure* complete_gc) { assert(!discovery_is_atomic(), "Error"); - DiscoveredListIterator iter(refs_list, keep_alive, is_alive, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, keep_alive, is_alive); while (iter.has_next()) { iter.load_ptrs(DEBUG_ONLY(true /* allow_null_referent */)); HeapWord* next_addr = java_lang_ref_Reference::next_addr(iter.obj()); @@ -666,7 +665,7 @@ ReferenceProcessor::process_phase3(DiscoveredList& refs_list, OopClosure* keep_alive, VoidClosure* complete_gc) { ResourceMark rm; - DiscoveredListIterator iter(refs_list, keep_alive, is_alive, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, keep_alive, is_alive); while (iter.has_next()) { iter.update_discovered(); iter.load_ptrs(DEBUG_ONLY(false /* allow_null_referent */)); @@ -782,13 +781,6 @@ private: bool _clear_referent; }; -void ReferenceProcessor::set_discovered(oop ref, oop value) { - java_lang_ref_Reference::set_discovered_raw(ref, value); - if (_discovered_list_needs_post_barrier) { - oopDesc::bs()->write_ref_field(java_lang_ref_Reference::discovered_addr(ref), value); - } -} - // Balances reference queues. // Move entries from all queues[0, 1, ..., _max_num_q-1] to // queues[0, 1, ..., _num_q-1] because only the first _num_q @@ -846,9 +838,9 @@ void ReferenceProcessor::balance_queues(DiscoveredList ref_lists[]) // Add the chain to the to list. if (ref_lists[to_idx].head() == NULL) { // to list is empty. Make a loop at the end. - set_discovered(move_tail, move_tail); + java_lang_ref_Reference::set_discovered_raw(move_tail, move_tail); } else { - set_discovered(move_tail, ref_lists[to_idx].head()); + java_lang_ref_Reference::set_discovered_raw(move_tail, ref_lists[to_idx].head()); } ref_lists[to_idx].set_head(move_head); ref_lists[to_idx].inc_length(refs_to_move); @@ -982,7 +974,7 @@ void ReferenceProcessor::clean_up_discovered_references() { void ReferenceProcessor::clean_up_discovered_reflist(DiscoveredList& refs_list) { assert(!discovery_is_atomic(), "Else why call this method?"); - DiscoveredListIterator iter(refs_list, NULL, NULL, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, NULL, NULL); while (iter.has_next()) { iter.load_ptrs(DEBUG_ONLY(true /* allow_null_referent */)); oop next = java_lang_ref_Reference::next(iter.obj()); @@ -1071,16 +1063,6 @@ ReferenceProcessor::add_to_discovered_list_mt(DiscoveredList& refs_list, // The last ref must have its discovered field pointing to itself. oop next_discovered = (current_head != NULL) ? current_head : obj; - // Note: In the case of G1, this specific pre-barrier is strictly - // not necessary because the only case we are interested in - // here is when *discovered_addr is NULL (see the CAS further below), - // so this will expand to nothing. As a result, we have manually - // elided this out for G1, but left in the test for some future - // collector that might have need for a pre-barrier here, e.g.:- - // oopDesc::bs()->write_ref_field_pre((oop* or narrowOop*)discovered_addr, next_discovered); - assert(!_discovered_list_needs_post_barrier || UseG1GC, - "Need to check non-G1 collector: " - "may need a pre-write-barrier for CAS from NULL below"); oop retest = oopDesc::atomic_compare_exchange_oop(next_discovered, discovered_addr, NULL); if (retest == NULL) { @@ -1089,9 +1071,6 @@ ReferenceProcessor::add_to_discovered_list_mt(DiscoveredList& refs_list, // is necessary. refs_list.set_head(obj); refs_list.inc_length(1); - if (_discovered_list_needs_post_barrier) { - oopDesc::bs()->write_ref_field((void*)discovered_addr, next_discovered); - } if (TraceReferenceGC) { gclog_or_tty->print_cr("Discovered reference (mt) (" INTPTR_FORMAT ": %s)", @@ -1242,24 +1221,14 @@ bool ReferenceProcessor::discover_reference(oop obj, ReferenceType rt) { if (_discovery_is_mt) { add_to_discovered_list_mt(*list, obj, discovered_addr); } else { - // If "_discovered_list_needs_post_barrier", we do write barriers when - // updating the discovered reference list. Otherwise, we do a raw store - // here: the field will be visited later when processing the discovered - // references. + // We do a raw store here: the field will be visited later when processing + // the discovered references. oop current_head = list->head(); // The last ref must have its discovered field pointing to itself. oop next_discovered = (current_head != NULL) ? current_head : obj; - // As in the case further above, since we are over-writing a NULL - // pre-value, we can safely elide the pre-barrier here for the case of G1. - // e.g.:- oopDesc::bs()->write_ref_field_pre((oop* or narrowOop*)discovered_addr, next_discovered); assert(discovered == NULL, "control point invariant"); - assert(!_discovered_list_needs_post_barrier || UseG1GC, - "For non-G1 collector, may need a pre-write-barrier for CAS from NULL below"); oop_store_raw(discovered_addr, next_discovered); - if (_discovered_list_needs_post_barrier) { - oopDesc::bs()->write_ref_field((void*)discovered_addr, next_discovered); - } list->set_head(obj); list->inc_length(1); @@ -1353,7 +1322,7 @@ ReferenceProcessor::preclean_discovered_reflist(DiscoveredList& refs_list, OopClosure* keep_alive, VoidClosure* complete_gc, YieldClosure* yield) { - DiscoveredListIterator iter(refs_list, keep_alive, is_alive, _discovered_list_needs_post_barrier); + DiscoveredListIterator iter(refs_list, keep_alive, is_alive); while (iter.has_next()) { iter.load_ptrs(DEBUG_ONLY(true /* allow_null_referent */)); oop obj = iter.obj(); diff --git a/hotspot/src/share/vm/memory/referenceProcessor.hpp b/hotspot/src/share/vm/memory/referenceProcessor.hpp index f9f69f07142..26ac9f1c5d4 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.hpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.hpp @@ -99,7 +99,6 @@ private: oop _referent; OopClosure* _keep_alive; BoolObjectClosure* _is_alive; - bool _discovered_list_needs_post_barrier; DEBUG_ONLY( oop _first_seen; // cyclic linked list check @@ -113,8 +112,7 @@ private: public: inline DiscoveredListIterator(DiscoveredList& refs_list, OopClosure* keep_alive, - BoolObjectClosure* is_alive, - bool discovered_list_needs_post_barrier = false): + BoolObjectClosure* is_alive): _refs_list(refs_list), _prev_next(refs_list.adr_head()), _prev(NULL), @@ -128,8 +126,7 @@ public: #endif _next(NULL), _keep_alive(keep_alive), - _is_alive(is_alive), - _discovered_list_needs_post_barrier(discovered_list_needs_post_barrier) + _is_alive(is_alive) { } // End Of List. @@ -230,14 +227,6 @@ class ReferenceProcessor : public CHeapObj { // other collectors in configuration bool _discovery_is_mt; // true if reference discovery is MT. - // If true, setting "next" field of a discovered refs list requires - // write post barrier. (Must be true if used in a collector in which - // elements of a discovered list may be moved during discovery: for - // example, a collector like Garbage-First that moves objects during a - // long-term concurrent marking phase that does weak reference - // discovery.) - bool _discovered_list_needs_post_barrier; - bool _enqueuing_is_done; // true if all weak references enqueued bool _processing_is_mt; // true during phases when // reference processing is MT. @@ -382,11 +371,6 @@ class ReferenceProcessor : public CHeapObj { void enqueue_discovered_reflists(HeapWord* pending_list_addr, AbstractRefProcTaskExecutor* task_executor); protected: - // Set the 'discovered' field of the given reference to - // the given value - emitting post barriers depending upon - // the value of _discovered_list_needs_post_barrier. - void set_discovered(oop ref, oop value); - // "Preclean" the given discovered reference list // by removing references with strongly reachable referents. // Currently used in support of CMS only. @@ -427,8 +411,7 @@ class ReferenceProcessor : public CHeapObj { bool mt_processing = false, uint mt_processing_degree = 1, bool mt_discovery = false, uint mt_discovery_degree = 1, bool atomic_discovery = true, - BoolObjectClosure* is_alive_non_header = NULL, - bool discovered_list_needs_post_barrier = false); + BoolObjectClosure* is_alive_non_header = NULL); // RefDiscoveryPolicy values enum DiscoveryPolicy { From 65cf6a8edc40772e189bb212877e8e1170b3159b Mon Sep 17 00:00:00 2001 From: Erik Helin Date: Thu, 29 May 2014 14:31:28 +0200 Subject: [PATCH 09/90] 8042933: assert(capacity_until_gc >= committed_bytes) failed Reviewed-by: stefank, jmasa --- hotspot/src/share/vm/memory/metaspace.cpp | 44 +++++++++++------ hotspot/src/share/vm/memory/metaspace.hpp | 4 +- hotspot/src/share/vm/runtime/thread.cpp | 2 + .../TestMetaspaceInitialization.java | 48 +++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 hotspot/test/gc/metaspace/TestMetaspaceInitialization.java diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index cd5fceff2d0..d2d1ba7992e 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -1423,6 +1423,17 @@ size_t MetaspaceGC::dec_capacity_until_GC(size_t v) { return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC); } +void MetaspaceGC::initialize() { + // Set the high-water mark to MaxMetapaceSize during VM initializaton since + // we can't do a GC during initialization. + _capacity_until_GC = MaxMetaspaceSize; +} + +void MetaspaceGC::post_initialize() { + // Reset the high-water mark once the VM initialization is done. + _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize); +} + bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { // Check if the compressed class space is full. if (is_class && Metaspace::using_class_space()) { @@ -1443,21 +1454,13 @@ bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { size_t MetaspaceGC::allowed_expansion() { size_t committed_bytes = MetaspaceAux::committed_bytes(); - - size_t left_until_max = MaxMetaspaceSize - committed_bytes; - - // Always grant expansion if we are initiating the JVM, - // or if the GC_locker is preventing GCs. - if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) { - return left_until_max / BytesPerWord; - } - size_t capacity_until_gc = capacity_until_GC(); - if (capacity_until_gc <= committed_bytes) { - return 0; - } + assert(capacity_until_gc >= committed_bytes, + err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT, + capacity_until_gc, committed_bytes)); + size_t left_until_max = MaxMetaspaceSize - committed_bytes; size_t left_until_GC = capacity_until_gc - committed_bytes; size_t left_to_commit = MIN2(left_until_GC, left_until_max); @@ -1469,7 +1472,15 @@ void MetaspaceGC::compute_new_size() { uint current_shrink_factor = _shrink_factor; _shrink_factor = 0; - const size_t used_after_gc = MetaspaceAux::capacity_bytes(); + // Using committed_bytes() for used_after_gc is an overestimation, since the + // chunk free lists are included in committed_bytes() and the memory in an + // un-fragmented chunk free list is available for future allocations. + // However, if the chunk free lists becomes fragmented, then the memory may + // not be available for future allocations and the memory is therefore "in use". + // Including the chunk free lists in the definition of "in use" is therefore + // necessary. Not including the chunk free lists can cause capacity_until_GC to + // shrink below committed_bytes() and this has caused serious bugs in the past. + const size_t used_after_gc = MetaspaceAux::committed_bytes(); const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC(); const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; @@ -3094,6 +3105,8 @@ void Metaspace::ergo_initialize() { } void Metaspace::global_initialize() { + MetaspaceGC::initialize(); + // Initialize the alignment for shared spaces. int max_alignment = os::vm_allocation_granularity(); size_t cds_total = 0; @@ -3201,10 +3214,13 @@ void Metaspace::global_initialize() { } } - MetaspaceGC::initialize(); _tracer = new MetaspaceTracer(); } +void Metaspace::post_initialize() { + MetaspaceGC::post_initialize(); +} + Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype, size_t chunk_word_size, size_t chunk_bunch) { diff --git a/hotspot/src/share/vm/memory/metaspace.hpp b/hotspot/src/share/vm/memory/metaspace.hpp index 22e21b80d3d..baa25cd6d35 100644 --- a/hotspot/src/share/vm/memory/metaspace.hpp +++ b/hotspot/src/share/vm/memory/metaspace.hpp @@ -208,6 +208,7 @@ class Metaspace : public CHeapObj { static void ergo_initialize(); static void global_initialize(); + static void post_initialize(); static size_t first_chunk_word_size() { return _first_chunk_word_size; } static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } @@ -398,7 +399,8 @@ class MetaspaceGC : AllStatic { public: - static void initialize() { _capacity_until_GC = MetaspaceSize; } + static void initialize(); + static void post_initialize(); static size_t capacity_until_GC(); static size_t inc_capacity_until_GC(size_t v); diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index 3591b35ece9..1716ed5e572 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3543,6 +3543,8 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { // debug stuff, that does not work until all basic classes have been initialized. set_init_completed(); + Metaspace::post_initialize(); + HOTSPOT_VM_INIT_END(); // record VM initialization completion time diff --git a/hotspot/test/gc/metaspace/TestMetaspaceInitialization.java b/hotspot/test/gc/metaspace/TestMetaspaceInitialization.java new file mode 100644 index 00000000000..c7bbcec0829 --- /dev/null +++ b/hotspot/test/gc/metaspace/TestMetaspaceInitialization.java @@ -0,0 +1,48 @@ +/* + * 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 java.util.ArrayList; + +/* @test TestMetaspaceInitialization + * @bug 8042933 + * @summary Tests to initialize metaspace with a very low MetaspaceSize + * @library /testlibrary + * @run main/othervm -XX:MetaspaceSize=2m TestMetaspaceInitialization + */ +public class TestMetaspaceInitialization { + private class Internal { + public int x; + public Internal(int x) { + this.x = x; + } + } + + private void test() { + ArrayList l = new ArrayList<>(); + l.add(new Internal(17)); + } + + public static void main(String[] args) { + new TestMetaspaceInitialization().test(); + } +} From 5ff7186a1c768a898f696602d052c907fdd433cd Mon Sep 17 00:00:00 2001 From: Lois Foltan Date: Thu, 29 May 2014 08:58:51 -0400 Subject: [PATCH 10/90] 8041623: Solaris Studio 12.4 C++ 5.13, CHECK_UNHANDLED_OOPS use of class oop's copy constructor definitions causing error level diagnostic Fix several minor compilation issues with volatile oops for CHECK_UNHANDLED_OOPS support. Reviewed-by: coleenp, hseigel --- hotspot/src/share/vm/classfile/javaClasses.hpp | 2 +- hotspot/src/share/vm/oops/oopsHierarchy.hpp | 10 +++------- hotspot/src/share/vm/runtime/thread.cpp | 2 +- hotspot/src/share/vm/services/memoryManager.cpp | 4 ++-- hotspot/src/share/vm/services/memoryPool.cpp | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hotspot/src/share/vm/classfile/javaClasses.hpp b/hotspot/src/share/vm/classfile/javaClasses.hpp index b4da42c423d..60c65fe968a 100644 --- a/hotspot/src/share/vm/classfile/javaClasses.hpp +++ b/hotspot/src/share/vm/classfile/javaClasses.hpp @@ -1181,7 +1181,7 @@ public: static oop target( oop site) { return site->obj_field( _target_offset); } static void set_target( oop site, oop target) { site->obj_field_put( _target_offset, target); } - static volatile oop target_volatile(oop site) { return site->obj_field_volatile( _target_offset); } + static volatile oop target_volatile(oop site) { return oop((oopDesc *)(site->obj_field_volatile(_target_offset))); } static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); } // Testers diff --git a/hotspot/src/share/vm/oops/oopsHierarchy.hpp b/hotspot/src/share/vm/oops/oopsHierarchy.hpp index ef0d2ed2bba..cd63547c38c 100644 --- a/hotspot/src/share/vm/oops/oopsHierarchy.hpp +++ b/hotspot/src/share/vm/oops/oopsHierarchy.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -112,9 +112,7 @@ public: // Assignment oop& operator=(const oop& o) { _o = o.obj(); return *this; } -#ifndef SOLARIS volatile oop& operator=(const oop& o) volatile { _o = o.obj(); return *this; } -#endif volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; } // Explict user conversions @@ -123,11 +121,10 @@ public: operator void* () const volatile { return (void *)obj(); } #endif operator HeapWord* () const { return (HeapWord*)obj(); } - operator oopDesc* () const { return obj(); } + operator oopDesc* () const volatile { return obj(); } operator intptr_t* () const { return (intptr_t*)obj(); } operator PromotedObject* () const { return (PromotedObject*)obj(); } operator markOop () const { return markOop(obj()); } - operator address () const { return (address)obj(); } // from javaCalls.cpp @@ -161,11 +158,10 @@ public: oop::operator=(o); \ return *this; \ } \ - NOT_SOLARIS( \ volatile type##Oop& operator=(const type##Oop& o) volatile { \ (void)const_cast(oop::operator=(o)); \ return *this; \ - }) \ + } \ volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\ (void)const_cast(oop::operator=(o)); \ return *this; \ diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index e6d9eee7927..dffe1fe85f8 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -1434,7 +1434,7 @@ void JavaThread::initialize() { _in_deopt_handler = 0; _doing_unsafe_access = false; _stack_guard_state = stack_guard_unused; - (void)const_cast(_exception_oop = NULL); + (void)const_cast(_exception_oop = oop(NULL)); _exception_pc = 0; _exception_handler_pc = 0; _is_method_handle_return = 0; diff --git a/hotspot/src/share/vm/services/memoryManager.cpp b/hotspot/src/share/vm/services/memoryManager.cpp index 646b5e12ebb..0469c937013 100644 --- a/hotspot/src/share/vm/services/memoryManager.cpp +++ b/hotspot/src/share/vm/services/memoryManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -39,7 +39,7 @@ MemoryManager::MemoryManager() { _num_pools = 0; - (void)const_cast(_memory_mgr_obj = NULL); + (void)const_cast(_memory_mgr_obj = instanceOop(NULL)); } void MemoryManager::add_pool(MemoryPool* pool) { diff --git a/hotspot/src/share/vm/services/memoryPool.cpp b/hotspot/src/share/vm/services/memoryPool.cpp index 1510cd596b4..2d686cbdc9a 100644 --- a/hotspot/src/share/vm/services/memoryPool.cpp +++ b/hotspot/src/share/vm/services/memoryPool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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,7 +46,7 @@ MemoryPool::MemoryPool(const char* name, _name = name; _initial_size = init_size; _max_size = max_size; - (void)const_cast(_memory_pool_obj = NULL); + (void)const_cast(_memory_pool_obj = instanceOop(NULL)); _available_for_allocation = true; _num_managers = 0; _type = type; From ad6d8d6abd2be9aaf7f966258f1f8974523600ef Mon Sep 17 00:00:00 2001 From: "Daniel D. Daugherty" Date: Fri, 30 May 2014 07:20:51 -0700 Subject: [PATCH 11/90] 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock' Add a !owner check for 'waiting to lock' to catch current_pending_monitor corner cases. Co-authored-by: Krystal Mok Co-authored-by: Zhengyu Gu Reviewed-by: dholmes, sspitsyn, kmo, zgu --- .../src/share/vm/runtime/objectMonitor.cpp | 9 + hotspot/src/share/vm/runtime/vframe.cpp | 7 +- hotspot/test/TEST.groups | 1 + .../TestThreadDumpMonitorContention.java | 405 ++++++++++++++++++ 4 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java diff --git a/hotspot/src/share/vm/runtime/objectMonitor.cpp b/hotspot/src/share/vm/runtime/objectMonitor.cpp index 1f16ee4ad1c..6f2323c8668 100644 --- a/hotspot/src/share/vm/runtime/objectMonitor.cpp +++ b/hotspot/src/share/vm/runtime/objectMonitor.cpp @@ -385,6 +385,15 @@ void ATTR ObjectMonitor::enter(TRAPS) { jt->java_suspend_self(); } Self->set_current_pending_monitor(NULL); + + // We cleared the pending monitor info since we've just gotten past + // the enter-check-for-suspend dance and we now own the monitor free + // and clear, i.e., it is no longer pending. The ThreadBlockInVM + // destructor can go to a safepoint at the end of this block. If we + // do a thread dump during that safepoint, then this thread will show + // as having "-locked" the monitor, but the OS and java.lang.Thread + // states will still report that the thread is blocked trying to + // acquire it. } Atomic::dec_ptr(&_count); diff --git a/hotspot/src/share/vm/runtime/vframe.cpp b/hotspot/src/share/vm/runtime/vframe.cpp index 8b4d72f728e..a32d03a7b21 100644 --- a/hotspot/src/share/vm/runtime/vframe.cpp +++ b/hotspot/src/share/vm/runtime/vframe.cpp @@ -199,6 +199,7 @@ void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) { continue; } if (monitor->owner() != NULL) { + // the monitor is associated with an object, i.e., it is locked // First, assume we have the monitor locked. If we haven't found an // owned monitor before and this is the first frame, then we need to @@ -209,7 +210,11 @@ void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) { if (!found_first_monitor && frame_count == 0) { markOop mark = monitor->owner()->mark(); if (mark->has_monitor() && - mark->monitor() == thread()->current_pending_monitor()) { + ( // we have marked ourself as pending on this monitor + mark->monitor() == thread()->current_pending_monitor() || + // we are not the owner of this monitor + !mark->monitor()->is_entered(thread()) + )) { lock_state = "waiting to lock"; } } diff --git a/hotspot/test/TEST.groups b/hotspot/test/TEST.groups index 2982e82b694..69f771130a0 100644 --- a/hotspot/test/TEST.groups +++ b/hotspot/test/TEST.groups @@ -81,6 +81,7 @@ needs_jdk = \ runtime/NMT/ThreadedVirtualAllocTestType.java \ runtime/NMT/VirtualAllocTestType.java \ runtime/RedefineObject/TestRedefineObject.java \ + runtime/Thread/TestThreadDumpMonitorContention.java \ runtime/XCheckJniJsig/XCheckJSig.java \ serviceability/attach/AttachWithStalePidFile.java \ serviceability/jvmti/8036666/GetObjectLockCount.java \ diff --git a/hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java b/hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java new file mode 100644 index 00000000000..06b2274d823 --- /dev/null +++ b/hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java @@ -0,0 +1,405 @@ +/* + * 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 8036823 + * @summary Creates two threads contending for the same lock and checks + * whether jstack reports "locked" by more than one thread. + * + * @library /testlibrary + * @run main/othervm TestThreadDumpMonitorContention + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.oracle.java.testlibrary.*; + +public class TestThreadDumpMonitorContention { + // jstack tends to be closely bound to the VM that we are running + // so use getTestJDKTool() instead of getCompileJDKTool() or even + // getJDKTool() which can fall back to "compile.jdk". + final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack"); + final static String PID = getPid(); + + // looking for header lines with these patterns: + // "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000] + // "ContendingThread-2" #21 prio=5 os_prio=64 tid=0x0000000000780000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] + final static Pattern HEADER_PREFIX_PATTERN = Pattern.compile( + "^\"ContendingThread-.*"); + final static Pattern HEADER_WAITING_PATTERN = Pattern.compile( + "^\"ContendingThread-.* waiting for monitor entry .*"); + final static Pattern HEADER_RUNNABLE_PATTERN = Pattern.compile( + "^\"ContendingThread-.* runnable .*"); + + // looking for thread state lines with these patterns: + // java.lang.Thread.State: RUNNABLE + // java.lang.Thread.State: BLOCKED (on object monitor) + final static Pattern THREAD_STATE_PREFIX_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: .*"); + final static Pattern THREAD_STATE_BLOCKED_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: BLOCKED \\(on object monitor\\)"); + final static Pattern THREAD_STATE_RUNNABLE_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: RUNNABLE"); + + // looking for duplicates of this pattern: + // - locked <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) + final static Pattern LOCK_PATTERN = Pattern.compile( + ".* locked \\<.*\\(a TestThreadDumpMonitorContention.*"); + + // sanity checking header and thread state lines associated + // with this pattern: + // - waiting to lock <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) + final static Pattern WAITING_PATTERN = Pattern.compile( + ".* waiting to lock \\<.*\\(a TestThreadDumpMonitorContention.*"); + + volatile static boolean done = false; + + static int error_cnt = 0; + static String header_line = null; + static boolean have_header_line = false; + static boolean have_thread_state_line = false; + static int match_cnt = 0; + static String[] match_list = new String[2]; + static int n_samples = 15; + static String thread_state_line = null; + static boolean verbose = false; + + public static void main(String[] args) throws Exception { + if (args.length != 0) { + int arg_i = 0; + if (args[arg_i].equals("-v")) { + verbose = true; + arg_i++; + } + + try { + n_samples = Integer.parseInt(args[arg_i]); + } catch (NumberFormatException nfe) { + System.err.println(nfe); + usage(); + } + } + + Runnable runnable = new Runnable() { + public void run() { + while (!done) { + synchronized (this) { } + } + } + }; + Thread[] thread_list = new Thread[2]; + thread_list[0] = new Thread(runnable, "ContendingThread-1"); + thread_list[1] = new Thread(runnable, "ContendingThread-2"); + thread_list[0].start(); + thread_list[1].start(); + + doSamples(); + + done = true; + + thread_list[0].join(); + thread_list[1].join(); + + if (error_cnt == 0) { + System.out.println("Test PASSED."); + } else { + System.out.println("Test FAILED."); + throw new AssertionError("error_cnt=" + error_cnt); + } + } + + // Reached a blank line which is the end of the + // stack trace without matching either LOCK_PATTERN + // or WAITING_PATTERN. Rare, but it's not an error. + // + // Example: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] + // java.lang.Thread.State: RUNNABLE + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkBlankLine(String line) { + if (line.length() == 0) { + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + // Process the locked line here if we found one. + // + // Example 1: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] + // java.lang.Thread.State: RUNNABLE + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + // Example 2: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] + // java.lang.Thread.State: BLOCKED (on object monitor) + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkLockedLine(String line) { + Matcher matcher = LOCK_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("locked_line='" + line + "'"); + } + match_list[match_cnt] = new String(line); + match_cnt++; + + matcher = HEADER_RUNNABLE_PATTERN.matcher(header_line); + if (!matcher.matches()) { + // It's strange, but a locked line can also + // match the HEADER_WAITING_PATTERN. + matcher = HEADER_WAITING_PATTERN.matcher(header_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: header line does " + + "not match runnable or waiting patterns."); + System.err.println("ERROR: header_line='" + + header_line + "'"); + System.err.println("ERROR: locked_line='" + line + "'"); + error_cnt++; + } + } + + matcher = THREAD_STATE_RUNNABLE_PATTERN.matcher(thread_state_line); + if (!matcher.matches()) { + // It's strange, but a locked line can also + // match the THREAD_STATE_BLOCKED_PATTERN. + matcher = THREAD_STATE_BLOCKED_PATTERN.matcher( + thread_state_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: thread state line does not " + + "match runnable or waiting patterns."); + System.err.println("ERROR: " + "thread_state_line='" + + thread_state_line + "'"); + System.err.println("ERROR: locked_line='" + line + "'"); + error_cnt++; + } + } + + // Have everything we need from this thread stack + // that matches the LOCK_PATTERN. + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + // Process the waiting line here if we found one. + // + // Example: + // "ContendingThread-2" #22 prio=5 os_prio=64 tid=0x00000000007b9800 nid=0x30 waiting for monitor entry [0xfffffd7fc1010000] + // java.lang.Thread.State: BLOCKED (on object monitor) + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - waiting to lock <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkWaitingLine(String line) { + Matcher matcher = WAITING_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("waiting_line='" + line + "'"); + } + + matcher = HEADER_WAITING_PATTERN.matcher(header_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: header line does " + + "not match a waiting pattern."); + System.err.println("ERROR: header_line='" + header_line + "'"); + System.err.println("ERROR: waiting_line='" + line + "'"); + error_cnt++; + } + + matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(thread_state_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: thread state line " + + "does not match a waiting pattern."); + System.err.println("ERROR: thread_state_line='" + + thread_state_line + "'"); + System.err.println("ERROR: waiting_line='" + line + "'"); + error_cnt++; + } + + // Have everything we need from this thread stack + // that matches the WAITING_PATTERN. + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + static void doSamples() throws Exception { + for (int count = 0; count < n_samples; count++) { + match_cnt = 0; + // verbose mode or an error has a lot of output so add more space + if (verbose || error_cnt > 0) System.out.println(); + System.out.println("Sample #" + count); + + // We don't use the ProcessTools, OutputBuffer or + // OutputAnalyzer classes from the testlibrary because + // we have a complicated multi-line parse to perform + // on a narrow subset of the JSTACK output. + // + // - we only care about stack traces that match + // HEADER_PREFIX_PATTERN; only two should match + // - we care about at most three lines from each stack trace + // - if both stack traces match LOCKED_PATTERN, then that's + // a failure and we report it + // - for a stack trace that matches LOCKED_PATTERN, we verify: + // - the header line matches HEADER_RUNNABLE_PATTERN + // or HEADER_WAITING_PATTERN + // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN + // or THREAD_STATE_RUNNABLE_PATTERN + // - we report any mismatches as failures + // - for a stack trace that matches WAITING_PATTERN, we verify: + // - the header line matches HEADER_WAITING_PATTERN + // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN + // - we report any mismatches as failures + // - the stack traces that match HEADER_PREFIX_PATTERN may + // not match either LOCKED_PATTERN or WAITING_PATTERN + // because we might observe the thread outside of + // monitor operations; this is not considered a failure + // + // When we do observe LOCKED_PATTERN or WAITING_PATTERN, + // then we are checking the header and thread state patterns + // that occurred earlier in the current stack trace that + // matched HEADER_PREFIX_PATTERN. We don't use data from + // stack traces that don't match HEADER_PREFIX_PATTERN and + // we don't mix data between the two stack traces that do + // match HEADER_PREFIX_PATTERN. + // + Process process = new ProcessBuilder(JSTACK, PID) + .redirectErrorStream(true).start(); + + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + Matcher matcher = null; + + // process the header line here + if (!have_header_line) { + matcher = HEADER_PREFIX_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println(); + System.out.println("header='" + line + "'"); + } + header_line = new String(line); + have_header_line = true; + continue; + } + continue; // skip until have a header line + } + + // process the thread state line here + if (!have_thread_state_line) { + matcher = THREAD_STATE_PREFIX_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("thread_state='" + line + "'"); + } + thread_state_line = new String(line); + have_thread_state_line = true; + continue; + } + continue; // skip until we have a thread state line + } + + // process the locked line here if we find one + if (checkLockedLine(line)) { + continue; + } + + // process the waiting line here if we find one + if (checkWaitingLine(line)) { + continue; + } + + // process the blank line here if we find one + if (checkBlankLine(line)) { + continue; + } + } + process.waitFor(); + + if (match_cnt == 2) { + if (match_list[0].equals(match_list[1])) { + System.err.println(); + System.err.println("ERROR: matching lock lines:"); + System.err.println("ERROR: line[0]'" + match_list[0] + "'"); + System.err.println("ERROR: line[1]'" + match_list[1] + "'"); + error_cnt++; + } + } + + // slight delay between jstack launches + Thread.sleep(500); + } + } + + // This helper relies on RuntimeMXBean.getName() returning a string + // that looks like this: 5436@mt-haku + // + // The testlibrary has tryFindJvmPid(), but that uses a separate + // process which is much more expensive for finding out your own PID. + // + static String getPid() { + RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean(); + String vmname = runtimebean.getName(); + int i = vmname.indexOf('@'); + if (i != -1) { + vmname = vmname.substring(0, i); + } + return vmname; + } + + static void usage() { + System.err.println("Usage: " + + "java TestThreadDumpMonitorContention [-v] [n_samples]"); + System.exit(1); + } +} From 7142b60efc2f5d9f398d416897127d7d5f144e6a Mon Sep 17 00:00:00 2001 From: Staffan Larsen Date: Fri, 30 May 2014 19:13:07 +0200 Subject: [PATCH 12/90] 8044398: Attach code should propagate errors in Diagnostic Commands as errors Reviewed-by: dcubed, mgronlun --- hotspot/src/share/vm/services/attachListener.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hotspot/src/share/vm/services/attachListener.cpp b/hotspot/src/share/vm/services/attachListener.cpp index 9d68175518a..2321f084dc5 100644 --- a/hotspot/src/share/vm/services/attachListener.cpp +++ b/hotspot/src/share/vm/services/attachListener.cpp @@ -162,10 +162,7 @@ static jint jcmd(AttachOperation* op, outputStream* out) { java_lang_Throwable::print(PENDING_EXCEPTION, out); out->cr(); CLEAR_PENDING_EXCEPTION; - // The exception has been printed on the output stream - // If the JVM returns JNI_ERR, the attachAPI throws a generic I/O - // exception and the content of the output stream is not processed. - // By returning JNI_OK, the exception will be displayed on the client side + return JNI_ERR; } return JNI_OK; } From d48bda2c524b80515f4a7bbf6aec581b2116cfb1 Mon Sep 17 00:00:00 2001 From: Katja Kantserova Date: Mon, 2 Jun 2014 11:20:14 +0200 Subject: [PATCH 13/90] 8043915: Tests get ClassNotFoundException: com.oracle.java.testlibrary.StreamPumper Reviewed-by: sla, allwin --- hotspot/test/serviceability/ParserTest.java | 4 ++-- .../test/serviceability/attach/AttachWithStalePidFile.java | 2 +- hotspot/test/serviceability/dcmd/DynLibDcmdTest.java | 2 +- hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java | 2 +- .../serviceability/jvmti/TestRedefineWithUnresolvedClass.java | 2 +- hotspot/test/serviceability/sa/jmap-hashcode/Test8028623.java | 1 + .../serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java | 2 +- hotspot/test/testlibrary/ctw/test/ClassesDirTest.java | 4 ++-- hotspot/test/testlibrary/ctw/test/ClassesListTest.java | 4 ++-- hotspot/test/testlibrary/ctw/test/JarDirTest.java | 4 ++-- hotspot/test/testlibrary/ctw/test/JarsTest.java | 4 ++-- 11 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hotspot/test/serviceability/ParserTest.java b/hotspot/test/serviceability/ParserTest.java index 63ee9210e40..8db151f4d3f 100644 --- a/hotspot/test/serviceability/ParserTest.java +++ b/hotspot/test/serviceability/ParserTest.java @@ -22,10 +22,10 @@ */ /* - * @test ParserTest + * @test * @summary Test that the diagnostic command arguemnt parser works * @library /testlibrary /testlibrary/whitebox - * @build ParserTest + * @build ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.parser.* * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest */ diff --git a/hotspot/test/serviceability/attach/AttachWithStalePidFile.java b/hotspot/test/serviceability/attach/AttachWithStalePidFile.java index fa74379b3a7..69dff6d9888 100644 --- a/hotspot/test/serviceability/attach/AttachWithStalePidFile.java +++ b/hotspot/test/serviceability/attach/AttachWithStalePidFile.java @@ -27,7 +27,7 @@ * @key regression * @summary Regression test for attach issue where stale pid files in /tmp lead to connection issues * @library /testlibrary - * @compile AttachWithStalePidFileTarget.java + * @build com.oracle.java.testlibrary.* AttachWithStalePidFileTarget * @run main AttachWithStalePidFile */ diff --git a/hotspot/test/serviceability/dcmd/DynLibDcmdTest.java b/hotspot/test/serviceability/dcmd/DynLibDcmdTest.java index a5c71839952..069b06f1937 100644 --- a/hotspot/test/serviceability/dcmd/DynLibDcmdTest.java +++ b/hotspot/test/serviceability/dcmd/DynLibDcmdTest.java @@ -29,7 +29,7 @@ import com.oracle.java.testlibrary.Platform; * @test * @summary Test of VM.dynlib diagnostic command via MBean * @library /testlibrary - * @compile DcmdUtil.java + * @build com.oracle.java.testlibrary.* DcmdUtil * @run main DynLibDcmdTest */ diff --git a/hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java b/hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java index ec33d813541..9acefe511f5 100644 --- a/hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java +++ b/hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java @@ -29,7 +29,7 @@ import com.oracle.java.testlibrary.*; * @test * @bug 8027230 * @library /testlibrary - * @build GetObjectSizeOverflowAgent + * @build ClassFileInstaller com.oracle.java.testlibrary.* GetObjectSizeOverflowAgent * @run main ClassFileInstaller GetObjectSizeOverflowAgent * @run main GetObjectSizeOverflow */ diff --git a/hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java b/hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java index 4f929c49af6..14ffea90bd5 100644 --- a/hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java +++ b/hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java @@ -26,7 +26,7 @@ * @summary Redefine a class with an UnresolvedClass reference in the constant pool. * @bug 8035150 * @library /testlibrary - * @build UnresolvedClassAgent com.oracle.java.testlibrary.ProcessTools com.oracle.java.testlibrary.OutputAnalyzer + * @build com.oracle.java.testlibrary.* UnresolvedClassAgent * @run main TestRedefineWithUnresolvedClass */ diff --git a/hotspot/test/serviceability/sa/jmap-hashcode/Test8028623.java b/hotspot/test/serviceability/sa/jmap-hashcode/Test8028623.java index bd743ab1c1f..6f4b2fd689a 100644 --- a/hotspot/test/serviceability/sa/jmap-hashcode/Test8028623.java +++ b/hotspot/test/serviceability/sa/jmap-hashcode/Test8028623.java @@ -26,6 +26,7 @@ * @bug 8028623 * @summary Test hashing of extended characters in Serviceability Agent. * @library /testlibrary + * @build com.oracle.java.testlibrary.* * @compile -encoding utf8 Test8028623.java * @run main Test8028623 */ diff --git a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java index df6ecb28f14..eeeecba0da4 100644 --- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java +++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java @@ -44,7 +44,7 @@ import com.oracle.java.testlibrary.ProcessTools; * @key regression * @summary Regression test for hprof export issue due to large heaps (>2G) * @library /testlibrary - * @compile JMapHProfLargeHeapProc.java + * @build com.oracle.java.testlibrary.* JMapHProfLargeHeapProc * @run main JMapHProfLargeHeapTest */ diff --git a/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java b/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java index ae5eaf0f2e4..cc28d403400 100644 --- a/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java +++ b/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java @@ -22,10 +22,10 @@ */ /* - * @test ClassesDirTest + * @test * @bug 8012447 * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src - * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox ClassesDirTest Foo Bar + * @build ClassFileInstaller sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox Foo Bar * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar * @run main ClassesDirTest prepare * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes diff --git a/hotspot/test/testlibrary/ctw/test/ClassesListTest.java b/hotspot/test/testlibrary/ctw/test/ClassesListTest.java index a98cd53a3f6..64c5203cf10 100644 --- a/hotspot/test/testlibrary/ctw/test/ClassesListTest.java +++ b/hotspot/test/testlibrary/ctw/test/ClassesListTest.java @@ -22,10 +22,10 @@ */ /* - * @test ClassesListTest + * @test * @bug 8012447 * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src - * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox ClassesListTest Foo Bar + * @build ClassFileInstaller sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox Foo Bar * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar * @run main ClassesListTest prepare * @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes.lst diff --git a/hotspot/test/testlibrary/ctw/test/JarDirTest.java b/hotspot/test/testlibrary/ctw/test/JarDirTest.java index 76f682fd755..abc5a0843d2 100644 --- a/hotspot/test/testlibrary/ctw/test/JarDirTest.java +++ b/hotspot/test/testlibrary/ctw/test/JarDirTest.java @@ -22,10 +22,10 @@ */ /* - * @test JarDirTest + * @test * @bug 8012447 * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src - * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox JarDirTest Foo Bar + * @build ClassFileInstaller com.oracle.java.testlibrary.* sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox Foo Bar * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar * @run main JarDirTest prepare * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld jars/* diff --git a/hotspot/test/testlibrary/ctw/test/JarsTest.java b/hotspot/test/testlibrary/ctw/test/JarsTest.java index 04792729f4e..c9bfb303132 100644 --- a/hotspot/test/testlibrary/ctw/test/JarsTest.java +++ b/hotspot/test/testlibrary/ctw/test/JarsTest.java @@ -22,10 +22,10 @@ */ /* - * @test JarsTest + * @test * @bug 8012447 * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src - * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox JarsTest Foo Bar + * @build ClassFileInstaller com.oracle.java.testlibrary.* sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox Foo Bar * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar * @run main JarsTest prepare * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld foo.jar bar.jar From 870bec251ca6c600c4365c40553ea0dda6d9ded7 Mon Sep 17 00:00:00 2001 From: Ron Durbin Date: Mon, 2 Jun 2014 09:30:08 -0700 Subject: [PATCH 14/90] 8038132: jprt bundles have libjsig.dylib in different place on OSX The build of Hotspot should not remove the symlinks for libjsig. Reviewed-by: dcubed, dholmes --- hotspot/make/bsd/makefiles/universal.gmk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hotspot/make/bsd/makefiles/universal.gmk b/hotspot/make/bsd/makefiles/universal.gmk index d1136a86806..44d57d963aa 100644 --- a/hotspot/make/bsd/makefiles/universal.gmk +++ b/hotspot/make/bsd/makefiles/universal.gmk @@ -74,19 +74,21 @@ $(UNIVERSAL_COPY_LIST): # Replace arch specific binaries with universal binaries +# Do not touch jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) +# That symbolic link belongs to the 'jdk' build. export_universal: $(RM) -r $(EXPORT_PATH)/jre/lib/{i386,amd64} $(RM) -r $(JDK_IMAGE_DIR)/jre/lib/{i386,amd64} - $(RM) $(JDK_IMAGE_DIR)/jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) ($(CD) $(EXPORT_PATH) && \ $(TAR) -cf - *) | \ ($(CD) $(JDK_IMAGE_DIR) && $(TAR) -xpf -) # Overlay universal binaries +# Do not touch jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) +# That symbolic link belongs to the 'jdk' build. copy_universal: $(RM) -r $(JDK_IMAGE_DIR)$(COPY_SUBDIR)/jre/lib/{i386,amd64} - $(RM) $(JDK_IMAGE_DIR)$(COPY_SUBDIR)/jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) ($(CD) $(EXPORT_PATH)$(COPY_SUBDIR) && \ $(TAR) -cf - *) | \ ($(CD) $(JDK_IMAGE_DIR)$(COPY_SUBDIR) && $(TAR) -xpf -) From fd282f6e9ac62360eb783e59e19fa6dcc26e840b Mon Sep 17 00:00:00 2001 From: Christian Tornqvist Date: Mon, 2 Jun 2014 19:08:18 +0200 Subject: [PATCH 15/90] 8044364: runtime/RedefineFinalizer test fails on windows Rewrote the test in pure Java, added RedefineClassHelper utility class Reviewed-by: coleenp, allwin, gtriantafill, dsamersoff --- .../test/runtime/RedefineFinalizer/Agent.java | 94 ------------------- .../runtime/RedefineFinalizer/MartyrSon.java | 28 ------ .../{Main.java => RedefineFinalizer.java} | 48 ++++++++-- .../runtime/RedefineFinalizer/manifest.mf | 5 - .../test/runtime/RedefineFinalizer/testme.sh | 49 ---------- .../test/testlibrary/RedefineClassHelper.java | 79 ++++++++++++++++ .../RedefineClassTest.java} | 33 +++++-- 7 files changed, 145 insertions(+), 191 deletions(-) delete mode 100644 hotspot/test/runtime/RedefineFinalizer/Agent.java delete mode 100644 hotspot/test/runtime/RedefineFinalizer/MartyrSon.java rename hotspot/test/runtime/RedefineFinalizer/{Main.java => RedefineFinalizer.java} (52%) delete mode 100644 hotspot/test/runtime/RedefineFinalizer/manifest.mf delete mode 100644 hotspot/test/runtime/RedefineFinalizer/testme.sh create mode 100644 hotspot/test/testlibrary/RedefineClassHelper.java rename hotspot/test/{runtime/RedefineFinalizer/Martyr.java => testlibrary_tests/RedefineClassTest.java} (55%) diff --git a/hotspot/test/runtime/RedefineFinalizer/Agent.java b/hotspot/test/runtime/RedefineFinalizer/Agent.java deleted file mode 100644 index 92b274ab02c..00000000000 --- a/hotspot/test/runtime/RedefineFinalizer/Agent.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -import java.lang.instrument.Instrumentation; -import java.lang.instrument.ClassDefinition; - -import jdk.internal.org.objectweb.asm.ClassWriter; -import jdk.internal.org.objectweb.asm.Label; -import jdk.internal.org.objectweb.asm.MethodVisitor; -import jdk.internal.org.objectweb.asm.Opcodes; - -public class Agent implements Opcodes { - - private static byte[] makeNewMartyr() { - ClassWriter cw = new ClassWriter(0); - MethodVisitor mv; - - cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "Martyr", null, "java/lang/Object", null); - cw.visitSource(null, null); - - { - mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); - mv.visitCode(); - Label lab0 = new Label(); - mv.visitLabel(lab0); - mv.visitLineNumber(1, lab0); - mv.visitVarInsn(ALOAD, 0); - mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V"); - mv.visitInsn(RETURN); - mv.visitMaxs(1, 1); - mv.visitEnd(); - } - - { - mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null); - mv.visitCode(); - Label lab0 = new Label(); - mv.visitLabel(lab0); - mv.visitLineNumber(6, lab0); - mv.visitLdcInsn("Redefinition done"); - mv.visitInsn(ARETURN); - mv.visitMaxs(1, 1); - mv.visitEnd(); - } - - { - mv = cw.visitMethod(ACC_PROTECTED, "finalize", "()V", null, null); - mv.visitCode(); - Label lab0 = new Label(); - mv.visitLabel(lab0); - mv.visitLineNumber(8, lab0); - mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); - mv.visitLdcInsn("Finalizer called"); - mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); - mv.visitInsn(RETURN); - mv.visitMaxs(2, 1); - mv.visitEnd(); - } - - cw.visitEnd(); - return cw.toByteArray(); - } - - - public static void premain(String args, Instrumentation inst) throws Exception { - agentmain(args, inst); - } - - public static void agentmain(String args, Instrumentation inst) throws Exception { - ClassDefinition martyrDef = - new ClassDefinition(Class.forName("Martyr"), makeNewMartyr()); - inst.redefineClasses(martyrDef); - } -} diff --git a/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java b/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java deleted file mode 100644 index 22fd4e3e275..00000000000 --- a/hotspot/test/runtime/RedefineFinalizer/MartyrSon.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -class MartyrSon extends Martyr { - public String getName() { - return super.getName(); - } -} diff --git a/hotspot/test/runtime/RedefineFinalizer/Main.java b/hotspot/test/runtime/RedefineFinalizer/RedefineFinalizer.java similarity index 52% rename from hotspot/test/runtime/RedefineFinalizer/Main.java rename to hotspot/test/runtime/RedefineFinalizer/RedefineFinalizer.java index 77f9f926d75..227b9e8186e 100644 --- a/hotspot/test/runtime/RedefineFinalizer/Main.java +++ b/hotspot/test/runtime/RedefineFinalizer/RedefineFinalizer.java @@ -21,14 +21,44 @@ * questions. */ -public class Main { - public static void main(String[] args) { - try { - MartyrSon m = new MartyrSon(); - System.out.println(m.getName()); - System.runFinalization(); - } catch (Throwable e) { - e.printStackTrace(); - } +/* + * @test + * @bug 6904403 + * @summary Don't assert if we redefine finalize method + * @library /testlibrary + * @build RedefineClassHelper + * @run main RedefineClassHelper + * @run main/othervm -javaagent:redefineagent.jar RedefineFinalizer + */ + +/* + * Regression test for hitting: + * + * assert(f == k->has_finalizer()) failed: inconsistent has_finalizer + * + * when redefining finalizer method + */ +public class RedefineFinalizer { + + public static String newB = + "class RedefineFinalizer$B {" + + " protected void finalize() { " + + " System.out.println(\"Finalizer called\");" + + " }" + + "}"; + + public static void main(String[] args) throws Exception { + RedefineClassHelper.redefineClass(B.class, newB); + + A a = new A(); + } + + static class A extends B { + } + + static class B { + protected void finalize() { + // should be empty + } } } diff --git a/hotspot/test/runtime/RedefineFinalizer/manifest.mf b/hotspot/test/runtime/RedefineFinalizer/manifest.mf deleted file mode 100644 index e337a65c01a..00000000000 --- a/hotspot/test/runtime/RedefineFinalizer/manifest.mf +++ /dev/null @@ -1,5 +0,0 @@ -Main-Class: Main -Agent-Class: Agent -Can-Redefine-Classes: true -Can-Retransform-Classes: true -Premain-Class: Agent diff --git a/hotspot/test/runtime/RedefineFinalizer/testme.sh b/hotspot/test/runtime/RedefineFinalizer/testme.sh deleted file mode 100644 index 3b50f5050db..00000000000 --- a/hotspot/test/runtime/RedefineFinalizer/testme.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -# 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 6904403 -# @summary Don't assert if we redefine finalize method -# @run shell testme.sh - -# This test shouldn't provoke and assert(f == k->has_finalizer()) failed: inconsistent has_finalizer - -. ${TESTSRC}/../../test_env.sh - -JAVAC=${COMPILEJAVA}${FS}bin${FS}javac -JAR=${COMPILEJAVA}${FS}bin${FS}jar -JAVA=${TESTJAVA}${FS}bin${FS}java - -TOOLS_JAR=${TESTJAVA}${FS}lib${FS}tools.jar - -cp ${TESTSRC}${FS}*.java . -${JAVAC} -XDignore.symbol.file -classpath ${TOOLS_JAR} -sourcepath ${TESTSRC} *.java -if [ $? -eq 1 ] - then - echo "Compilation failed" - exit -fi - -${JAR} cvfm testcase.jar ${TESTSRC}/manifest.mf . -${JAVA} -Xbootclasspath/a:${TOOLS_JAR} -javaagent:${PWD}/testcase.jar Main diff --git a/hotspot/test/testlibrary/RedefineClassHelper.java b/hotspot/test/testlibrary/RedefineClassHelper.java new file mode 100644 index 00000000000..accc5447a67 --- /dev/null +++ b/hotspot/test/testlibrary/RedefineClassHelper.java @@ -0,0 +1,79 @@ +/* + * 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. + */ + +import java.io.PrintWriter; +import java.lang.instrument.*; +import com.oracle.java.testlibrary.*; + +/* + * Helper class to write tests that redefine classes. + * When main method is run, it will create a redefineagent.jar that can be used + * with the -javaagent option to support redefining classes in jtreg tests. + * + * See sample test in test/testlibrary_tests/RedefineClassTest.java + */ +public class RedefineClassHelper { + + public static Instrumentation instrumentation; + public static void premain(String agentArgs, Instrumentation inst) { + instrumentation = inst; + } + + /** + * Redefine a class + * + * @param clazz Class to redefine + * @param javacode String with the new java code for the class to be redefined + */ + public static void redefineClass(Class clazz, String javacode) throws Exception { + byte[] bytecode = InMemoryJavaCompiler.compile(clazz.getName(), javacode); + redefineClass(clazz, bytecode); + } + + /** + * Redefine a class + * + * @param clazz Class to redefine + * @param bytecode byte[] with the new class + */ + public static void redefineClass(Class clazz, byte[] bytecode) throws Exception { + instrumentation.redefineClasses(new ClassDefinition(clazz, bytecode)); + } + + /** + * Main method to be invoked before test to create the redefineagent.jar + */ + public static void main(String[] args) throws Exception { + ClassFileInstaller.main("RedefineClassHelper"); + + PrintWriter pw = new PrintWriter("MANIFEST.MF"); + pw.println("Premain-Class: RedefineClassHelper"); + pw.println("Can-Redefine-Classes: true"); + pw.close(); + + sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar"); + if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineClassHelper.class" })) { + throw new Exception("jar operation failed"); + } + } +} diff --git a/hotspot/test/runtime/RedefineFinalizer/Martyr.java b/hotspot/test/testlibrary_tests/RedefineClassTest.java similarity index 55% rename from hotspot/test/runtime/RedefineFinalizer/Martyr.java rename to hotspot/test/testlibrary_tests/RedefineClassTest.java index 95f8ff2e056..e812e43cded 100644 --- a/hotspot/test/runtime/RedefineFinalizer/Martyr.java +++ b/hotspot/test/testlibrary_tests/RedefineClassTest.java @@ -21,13 +21,34 @@ * questions. */ -public class Martyr { - public String getName() { - return "Redefinition NOT done"; +/* + * @test + * @library /testlibrary + * @summary Proof of concept test for RedefineClassHelper + * @build RedefineClassHelper + * @run main RedefineClassHelper + * @run main/othervm -javaagent:redefineagent.jar RedefineClassTest + */ + +import static com.oracle.java.testlibrary.Asserts.*; +import com.oracle.java.testlibrary.*; + +/* + * Proof of concept test for the test utility class RedefineClassHelper + */ +public class RedefineClassTest { + + public static String newClass = "class RedefineClassTest$A { public int Method() { return 2; } }"; + public static void main(String[] args) throws Exception { + A a = new A(); + assertTrue(a.Method() == 1); + RedefineClassHelper.redefineClass(A.class, newClass); + assertTrue(a.Method() == 2); } - protected void finalize() { - // should be empty + static class A { + public int Method() { + return 1; + } } - } From 489a26ec8e8fc0c5afd0a871b6df0749176767ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gr=C3=B6nlund?= Date: Tue, 3 Jun 2014 09:44:54 +0200 Subject: [PATCH 16/90] 8044531: Event based tracing locks to rank as leafs where possible Reviewed-by: dcubed, dholmes --- hotspot/src/share/vm/runtime/mutexLocker.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hotspot/src/share/vm/runtime/mutexLocker.cpp b/hotspot/src/share/vm/runtime/mutexLocker.cpp index 136bc4d28fe..439bb40c7d4 100644 --- a/hotspot/src/share/vm/runtime/mutexLocker.cpp +++ b/hotspot/src/share/vm/runtime/mutexLocker.cpp @@ -280,10 +280,10 @@ void mutex_init() { #ifdef INCLUDE_TRACE def(JfrMsg_lock , Monitor, leaf, true); - def(JfrBuffer_lock , Mutex, nonleaf+1, true); - def(JfrThreadGroups_lock , Mutex, nonleaf+1, true); - def(JfrStream_lock , Mutex, nonleaf+2, true); - def(JfrStacktrace_lock , Mutex, special, true ); + def(JfrBuffer_lock , Mutex, leaf, true); + def(JfrThreadGroups_lock , Mutex, leaf, true); + def(JfrStream_lock , Mutex, nonleaf, true); + def(JfrStacktrace_lock , Mutex, special, true); #endif } From 36d332413dc3b86743f46fe5872acbb877773633 Mon Sep 17 00:00:00 2001 From: Mikhailo Seledtsov Date: Mon, 2 Jun 2014 21:36:59 -0400 Subject: [PATCH 17/90] 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address Added new tests to cover missing CDS basic funtions Reviewed-by: coleenp, ctornqvi --- .../SharedArchiveFile/LimitSharedSizes.java | 93 ++++++++++++++++++ .../SharedArchiveFile/SharedBaseAddress.java | 77 +++++++++++++++ .../SpaceUtilizationCheck.java | 96 +++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java create mode 100644 hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java create mode 100644 hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java diff --git a/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java b/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java new file mode 100644 index 00000000000..dff619248ec --- /dev/null +++ b/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java @@ -0,0 +1,93 @@ +/* + * 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. + */ + +/* @ignore JDK-8043896 + * @test LimitSharedSizes + * @summary Test handling of limits on shared space size + * @library /testlibrary + * @run main LimitSharedSizes + */ + +import com.oracle.java.testlibrary.*; + +public class LimitSharedSizes { + private static class SharedSizeTestData { + public String optionName; + public String optionValue; + public String expectedErrorMsg; + + public SharedSizeTestData(String name, String value, String msg) { + optionName = name; + optionValue = value; + expectedErrorMsg = msg; + } + } + + private static final SharedSizeTestData[] testTable = { + // values in this part of the test table should cause failure + // (shared space sizes are deliberately too small) + new SharedSizeTestData("-XX:SharedReadOnlySize", "4M", "read only"), + new SharedSizeTestData("-XX:SharedReadWriteSize","4M", "read write"), + + // Known issue, JDK-8038422 (assert() on Windows) + // new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"), + + // This will cause a VM crash; commenting out for now; see bug JDK-8038268 + // @ignore JDK-8038268 + // new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), + + // these values are larger than default ones, but should + // be acceptable and not cause failure + new SharedSizeTestData("-XX:SharedReadOnlySize", "20M", null), + new SharedSizeTestData("-XX:SharedReadWriteSize", "20M", null), + new SharedSizeTestData("-XX:SharedMiscDataSize", "20M", null), + new SharedSizeTestData("-XX:SharedMiscCodeSize", "20M", null) + }; + + public static void main(String[] args) throws Exception { + String fileName = "test.jsa"; + + for (SharedSizeTestData td : testTable) { + String option = td.optionName + "=" + td.optionValue; + System.out.println("testing option <" + option + ">"); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=./" + fileName, + option, + "-Xshare:dump"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + if (td.expectedErrorMsg != null) { + output.shouldContain("The shared " + td.expectedErrorMsg + + " space is not large enough"); + + output.shouldHaveExitValue(2); + } else { + output.shouldNotContain("space is not large enough"); + output.shouldHaveExitValue(0); + } + } + } +} diff --git a/hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java b/hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java new file mode 100644 index 00000000000..388fe7d0659 --- /dev/null +++ b/hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java @@ -0,0 +1,77 @@ +/* + * 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 SharedBaseAddress + * @summary Test variety of values for SharedBaseAddress, making sure + * VM handles normal values as well as edge values w/o a crash. + * @library /testlibrary + * @run main SharedBaseAddress + */ + +import com.oracle.java.testlibrary.*; + +public class SharedBaseAddress { + + // shared base address test table + private static final String[] testTable = { + "1g", "8g", "64g","512g", "4t", + "32t", "128t", "0", + "1", "64k", "64M" + }; + + public static void main(String[] args) throws Exception { + // Known issue on Solaris-Sparc + // @ignore JDK-8044600 + if (Platform.isSolaris() && Platform.isSparc()) + return; + + for (String testEntry : testTable) { + System.out.println("sharedBaseAddress = " + testEntry); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=test.jsa", + "-XX:SharedBaseAddress=" + testEntry, + "-Xshare:dump"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + output.shouldContain("Loading classes to share"); + + try { + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=test.jsa", + "-Xshare:on", + "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("sharing"); + output.shouldHaveExitValue(0); + } catch (RuntimeException e) { + output.shouldContain("Unable to use shared archive"); + output.shouldHaveExitValue(1); + } + } + } +} diff --git a/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java b/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java new file mode 100644 index 00000000000..a95979f355c --- /dev/null +++ b/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java @@ -0,0 +1,96 @@ +/* + * 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 SpaceUtilizationCheck + * @summary Check if the space utilization for shared spaces is adequate + * @library /testlibrary + * @run main SpaceUtilizationCheck + */ + +import com.oracle.java.testlibrary.*; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.ArrayList; +import java.lang.Integer; + +public class SpaceUtilizationCheck { + // Minimum allowed utilization value (percent) + // The goal is to have this number to be 50% for RO and RW regions + // Once that feature is implemented, increase the MIN_UTILIZATION to 50 + private static final int MIN_UTILIZATION = 30; + + // Only RO and RW regions are considered for this check, since they + // currently account for the bulk of the shared space + private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2; + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=./test.jsa", + "-Xshare:dump"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + String stdout = output.getStdout(); + ArrayList utilization = findUtilization(stdout); + + if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS ) + throw new RuntimeException("The output format of sharing summary has changed"); + + for(String str : utilization) { + int value = Integer.parseInt(str); + if (value < MIN_UTILIZATION) { + System.out.println(stdout); + throw new RuntimeException("Utilization for one of the regions" + + "is below a threshold of " + MIN_UTILIZATION + "%"); + } + } + } + + public static ArrayList findUtilization(String input) { + ArrayList regions = filterRegionsOfInterest(input.split("\n")); + return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+"); + } + + private static ArrayList filterByPattern(Iterable input, String pattern) { + ArrayList result = new ArrayList(); + for (String str : input) { + Matcher matcher = Pattern.compile(pattern).matcher(str); + if (matcher.find()) { + result.add(matcher.group()); + } + } + return result; + } + + private static ArrayList filterRegionsOfInterest(String[] inputLines) { + ArrayList result = new ArrayList(); + for (String str : inputLines) { + if (str.contains("ro space:") || str.contains("rw space:")) { + result.add(str); + } + } + return result; + } +} From 9c1843a7c34fb09a125307bc7b613309f154b6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Wed, 4 Jun 2014 14:16:20 +0200 Subject: [PATCH 18/90] 8044768: Backout fix for JDK-8040807 Reviewed-by: brutisso, ehelin --- .../vm/gc_implementation/g1/concurrentMark.cpp | 4 ++-- .../vm/gc_implementation/g1/concurrentMark.hpp | 4 +--- .../vm/gc_implementation/g1/g1CollectedHeap.cpp | 16 +++++++++++----- hotspot/src/share/vm/runtime/java.cpp | 9 +++++++-- hotspot/src/share/vm/runtime/thread.cpp | 10 ++++++++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index 7478a1e163c..24c62d775bd 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -901,7 +901,7 @@ void ConcurrentMark::checkpointRootsInitialPre() { G1CollectedHeap* g1h = G1CollectedHeap::heap(); G1CollectorPolicy* g1p = g1h->g1_policy(); - clear_has_aborted(); + _has_aborted = false; #ifndef PRODUCT if (G1PrintReachableAtInitialMark) { @@ -3261,7 +3261,7 @@ void ConcurrentMark::abort() { } _first_overflow_barrier_sync.abort(); _second_overflow_barrier_sync.abort(); - set_has_aborted(); + _has_aborted = true; SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); satb_mq_set.abandon_partial_marking(); diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp index c4dbcda557f..9d049a2a255 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp @@ -822,9 +822,7 @@ public: // Called to abort the marking cycle after a Full GC takes place. void abort(); - bool has_aborted() { return _has_aborted; } - void set_has_aborted() { _has_aborted = true; } - void clear_has_aborted() { _has_aborted = false; } + bool has_aborted() { return _has_aborted; } // This prints the global/local fingers. It is used for debugging. NOT_PRODUCT(void print_finger();) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 6e565c11d99..83f819b3919 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2174,14 +2174,20 @@ jint G1CollectedHeap::initialize() { } void G1CollectedHeap::stop() { - // Abort any ongoing concurrent mark and stop all concurrent threads. - // We do this to make sure these threads do not continue to execute - // and access resources (e.g. gclog_or_tty) that are destroyed during - // shutdown. - _cm->set_has_aborted(); +#if 0 + // Stopping concurrent worker threads is currently disabled until + // some bugs in concurrent mark has been resolve. Without fixing + // those bugs first we risk haning during VM exit when trying to + // stop these threads. + + // Abort any ongoing concurrent root region scanning and stop all + // concurrent threads. We do this to make sure these threads do + // not continue to execute and access resources (e.g. gclog_or_tty) + // that are destroyed during shutdown. _cm->root_regions()->abort(); _cm->root_regions()->wait_until_scan_finished(); stop_conc_gc_threads(); +#endif } size_t G1CollectedHeap::conservative_max_heap_alignment() { diff --git a/hotspot/src/share/vm/runtime/java.cpp b/hotspot/src/share/vm/runtime/java.cpp index 3a075117afe..e852b56ef54 100644 --- a/hotspot/src/share/vm/runtime/java.cpp +++ b/hotspot/src/share/vm/runtime/java.cpp @@ -501,6 +501,9 @@ void before_exit(JavaThread * thread) { os::infinite_sleep(); } + // Stop any ongoing concurrent GC work + Universe::heap()->stop(); + // Terminate watcher thread - must before disenrolling any periodic task if (PeriodicTask::num_tasks() > 0) WatcherThread::stop(); @@ -515,8 +518,10 @@ void before_exit(JavaThread * thread) { StatSampler::disengage(); StatSampler::destroy(); - // Stop concurrent GC threads - Universe::heap()->stop(); + // We do not need to explicitly stop concurrent GC threads because the + // JVM will be taken down at a safepoint when such threads are inactive -- + // except for some concurrent G1 threads, see (comment in) + // Threads::destroy_vm(). // Print GC/heap related information. if (PrintGCDetails) { diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index 1716ed5e572..1a0849a29d1 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3968,8 +3968,14 @@ bool Threads::destroy_vm() { // GC vm_operations can get caught at the safepoint, and the // heap is unparseable if they are caught. Grab the Heap_lock // to prevent this. The GC vm_operations will not be able to - // queue until after the vm thread is dead. After this point, - // we'll never emerge out of the safepoint before the VM exits. + // queue until after the vm thread is dead. + // After this point, we'll never emerge out of the safepoint before + // the VM exits, so concurrent GC threads do not need to be explicitly + // stopped; they remain inactive until the process exits. + // Note: some concurrent G1 threads may be running during a safepoint, + // but these will not be accessing the heap, just some G1-specific side + // data structures that are not accessed by any other threads but them + // after this point in a terminal safepoint. MutexLocker ml(Heap_lock); From eab7ad0813904829176b201f5c1cc2623eb720c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Fri, 6 Jun 2014 16:51:53 +0200 Subject: [PATCH 19/90] 8046215: Running uncompilable scripts throws NullPointerException Reviewed-by: sundar, jlaskey --- .../jdk/nashorn/internal/runtime/Context.java | 3 +++ .../nashorn/internal/runtime/ContextTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/nashorn/src/jdk/nashorn/internal/runtime/Context.java b/nashorn/src/jdk/nashorn/internal/runtime/Context.java index a33b0d2a148..369c4e6ebf2 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java @@ -1014,6 +1014,9 @@ public final class Context { } private static ScriptFunction getProgramFunction(final Class script, final ScriptObject scope) { + if (script == null) { + return null; + } return invokeCreateProgramFunctionHandle(getCreateProgramFunctionHandle(script), scope); } diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java index 4c4a8c65704..8e17e34ad23 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java @@ -28,6 +28,7 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.runtime.Source.sourceFor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.util.Map; import jdk.nashorn.internal.objects.Global; @@ -60,6 +61,27 @@ public class ContextTest { } } + // Make sure trying to compile an invalid script returns null - see JDK-8046215. + @Test + public void compileErrorTest() { + final Options options = new Options(""); + final ErrorManager errors = new ErrorManager(); + final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader()); + final Global oldGlobal = Context.getGlobal(); + Context.setGlobal(cx.createGlobal()); + try { + final ScriptFunction script = cx.compileScript(sourceFor("", "*/"), Context.getGlobal()); + if (script != null) { + fail("Invalid script compiled without errors"); + } + if (errors.getNumberOfErrors() != 1) { + fail("Wrong number of errors: " + errors.getNumberOfErrors()); + } + } finally { + Context.setGlobal(oldGlobal); + } + } + // basic check for JS reflection access - java.util.Map-like access on ScriptObject @Test public void reflectionTest() { From 8ff3cbd414dedacea428731a61501e335208026d Mon Sep 17 00:00:00 2001 From: Eric McCorkle Date: Fri, 6 Jun 2014 16:00:59 -0400 Subject: [PATCH 20/90] 8027262: Determine location for type annotations earlier in compiler pipeline 8027261: Single codepath for attaching annotations to symbols 8027258: Permit a single source annotation to generate multiple bytecode annotations 8027182: Incorrect annotation attributes for type annotations on constructor type parameters 8044010: TypeAnnotation attribute is not generated for repeatable annotation in type argument 8044009: TypeAnnotation attribute is not generated for repeatable annotation in nested types 8043974: TypeAnnotation attribute is not generated for repeatable annotation in lambda 8043669: Few of the ANNOT tests in JCK9 test suite fail with an AssertionError for exception_index 8042060: Type parameter annotations don't work with multiple type parameters 8037348: RuntimeInvisibleAnnotations should not be generated for type annotation on anonymous innerclass creation Initial rearchitecting of type annotations frontend pipeline Reviewed-by: jjg, jfranck, mcimadamore, jlahoda, wmdietl --- .../com/sun/tools/javac/code/Attribute.java | 52 +- .../com/sun/tools/javac/code/TargetType.java | 16 +- .../javac/code/TypeAnnotationPosition.java | 24 +- .../sun/tools/javac/code/TypeAnnotations.java | 1397 ------------ .../com/sun/tools/javac/comp/Annotate.java | 2009 +++++++++++++++-- .../com/sun/tools/javac/comp/Attr.java | 527 ++--- .../com/sun/tools/javac/comp/AttrContext.java | 6 + .../sun/tools/javac/comp/DeferredAttr.java | 41 +- .../classes/com/sun/tools/javac/comp/Env.java | 7 + .../com/sun/tools/javac/comp/MemberEnter.java | 258 ++- .../com/sun/tools/javac/jvm/ClassReader.java | 2 - .../com/sun/tools/javac/jvm/ClassWriter.java | 22 +- .../classes/com/sun/tools/javac/jvm/Gen.java | 18 +- .../typeAnnotations/TargetTypes.java | 90 +- .../classfile/ClassfileTestHelper.java | 4 +- .../failures/AnnotatedClassExpr.java | 17 + .../failures/AnnotatedClassExpr.out | 2 + .../failures/AnnotatedImport.java | 3 +- .../failures/AnnotatedImport.out | 12 +- .../failures/AnnotatedPackage1.java | 3 +- .../failures/AnnotatedPackage1.out | 2 +- .../failures/CantAnnotatePackages.out | 10 +- .../failures/CantAnnotateScoping.out | 20 +- .../failures/CantAnnotateStaticClass.java | 121 +- .../failures/CantAnnotateStaticClass2.out | 125 +- .../failures/CantAnnotateStaticClass3.java | 3 +- .../failures/CantAnnotateStaticClass3.out | 157 +- .../common/arrays/DeclarationAnnotation.java | 2 +- .../common/arrays/DeclarationAnnotation.out | 2 +- .../common/arrays/MissingAnnotationValue.java | 3 + .../common/arrays/MissingAnnotationValue.out | 2 +- .../MissingAnnotationValue.java | 3 + .../MissingAnnotationValue.out | 2 +- .../newarray/MissingAnnotationValue.java | 3 + .../newarray/MissingAnnotationValue.out | 2 +- .../receiver/MissingAnnotationValue.java | 5 + .../receiver/MissingAnnotationValue.out | 2 +- .../typeArgs/MissingAnnotationValue.java | 3 + .../typeArgs/MissingAnnotationValue.out | 2 +- .../typeparams/MissingAnnotationValue.java | 3 + .../typeparams/MissingAnnotationValue.out | 2 +- .../wildcards/MissingAnnotationValue.java | 3 + .../wildcards/MissingAnnotationValue.out | 2 +- .../newlocations/AllLocations.java | 196 ++ .../newlocations/Expressions.java | 44 +- .../newlocations/NestedTypes.java | 1 + .../newlocations/RepeatingTypeAnnotations.out | 6 +- .../referenceinfos/Fields.java | 2 - .../model/element/TestAnonClassNames.java | 13 +- .../test/tools/javac/tree/TreePosTest.java | 4 + .../tools/javac/warnings/6747671/T6747671.out | 2 +- .../javac/warnings/suppress/T6480588.out | 6 +- .../warnings/suppress/TypeAnnotations.out | 11 +- .../output/RepeatingTypeAnnotations.java | 147 +- 54 files changed, 3042 insertions(+), 2379 deletions(-) delete mode 100644 langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.java create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.out create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/newlocations/AllLocations.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java index f2cff56cf65..e78931474d7 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java @@ -142,7 +142,7 @@ public abstract class Attribute implements AnnotationValue { * access this attribute. */ public final List> values; - public TypeAnnotationPosition position; + public final TypeAnnotationPosition position; private boolean synthesized = false; @@ -170,53 +170,9 @@ public abstract class Attribute implements AnnotationValue { @Override public TypeAnnotationPosition getPosition() { - if (hasUnknownPosition()) { - if (values.size() != 0) { - Name valueName = values.head.fst.name.table.names.value; - Pair res = getElemPair(valueName); - position = res == null ? null : res.snd.getPosition(); - } - } return position; } - public boolean isContainerTypeCompound() { - if (isSynthesized() && values.size() == 1) - return getFirstEmbeddedTC() != null; - return false; - } - - private Compound getFirstEmbeddedTC() { - if (values.size() == 1) { - Pair val = values.get(0); - if (val.fst.getSimpleName().contentEquals("value") - && val.snd instanceof Array) { - Array arr = (Array) val.snd; - if (arr.values.length != 0 - && arr.values[0] instanceof Attribute.TypeCompound) - return (Attribute.TypeCompound) arr.values[0]; - } - } - return null; - } - - public boolean tryFixPosition() { - if (!isContainerTypeCompound()) - return false; - - Compound from = getFirstEmbeddedTC(); - if (from != null && from.position != null && - from.position.type != TargetType.UNKNOWN) { - position = from.position; - return true; - } - return false; - } - - public boolean hasUnknownPosition() { - return position.type == TargetType.UNKNOWN; - } - public void accept(Visitor v) { v.visitCompound(this); } /** @@ -280,6 +236,12 @@ public abstract class Attribute implements AnnotationValue { valmap.put(value.fst, value.snd); return valmap; } + + public TypeCompound toTypeCompound() { + // It is safe to alias the position. + return new TypeCompound(this, this.position); + } + } public static class TypeCompound extends Compound { diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java b/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java index 08767493354..2ac4ca88670 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java @@ -107,10 +107,7 @@ public enum TargetType { CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true), /** For annotations on a type argument of a method reference. */ - METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true), - - /** For annotations with an unknown target. */ - UNKNOWN(0xFF); + METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true); private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B; @@ -150,26 +147,15 @@ public enum TargetType { targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1]; TargetType[] alltargets = values(); for (TargetType target : alltargets) { - if (target.targetTypeValue != UNKNOWN.targetTypeValue) targets[target.targetTypeValue] = target; } - for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) { - if (targets[i] == null) - targets[i] = UNKNOWN; - } } public static boolean isValidTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return true; - return (tag >= 0 && tag < targets.length); } public static TargetType fromTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return UNKNOWN; - if (tag < 0 || tag >= targets.length) Assert.error("Unknown TargetType: " + tag); return targets[tag]; diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java index 55412a2853a..76a9fa9cda7 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java @@ -259,9 +259,6 @@ public class TypeAnnotationPosition { case METHOD_RETURN: case FIELD: break; - case UNKNOWN: - sb.append(", position UNKNOWN!"); - break; default: Assert.error("Unknown target type: " + type); } @@ -428,7 +425,7 @@ public class TypeAnnotationPosition { } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. @@ -445,7 +442,7 @@ public class TypeAnnotationPosition { } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param location The type path. */ @@ -455,7 +452,7 @@ public class TypeAnnotationPosition { } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param pos The position from the associated tree node. */ @@ -664,10 +661,11 @@ public class TypeAnnotationPosition { public static TypeAnnotationPosition exceptionParameter(final List location, final JCLambda onLambda, + final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.EXCEPTION_PARAMETER, pos, Integer.MIN_VALUE, onLambda, - Integer.MIN_VALUE, Integer.MIN_VALUE, + type_index, Integer.MIN_VALUE, location); } @@ -680,7 +678,7 @@ public class TypeAnnotationPosition { public static TypeAnnotationPosition exceptionParameter(final JCLambda onLambda, final int pos) { - return exceptionParameter(emptyPath, onLambda, pos); + return exceptionParameter(emptyPath, onLambda, Integer.MIN_VALUE, pos); } /** @@ -690,7 +688,7 @@ public class TypeAnnotationPosition { */ public static TypeAnnotationPosition exceptionParameter(final List location) { - return exceptionParameter(location, null, -1); + return exceptionParameter(location, null, Integer.MIN_VALUE, -1); } @@ -1204,12 +1202,4 @@ public class TypeAnnotationPosition { return methodTypeParameterBound(location, null, parameter_index, bound_index, -1); } - - // Consider this deprecated on arrival. We eventually want to get - // rid of this value altogether. Do not use it for anything new. - public static final TypeAnnotationPosition unknown = - new TypeAnnotationPosition(TargetType.UNKNOWN, -1, - Integer.MIN_VALUE, null, - Integer.MIN_VALUE, Integer.MIN_VALUE, - emptyPath); } diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java deleted file mode 100644 index 1fa63c1ae5e..00000000000 --- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java +++ /dev/null @@ -1,1397 +0,0 @@ -/* - * Copyright (c) 2009, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javac.code; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.type.TypeKind; - -import javax.tools.JavaFileObject; - -import com.sun.tools.javac.code.Attribute.TypeCompound; -import com.sun.tools.javac.code.Type.ArrayType; -import com.sun.tools.javac.code.Type.CapturedType; -import com.sun.tools.javac.code.Type.ClassType; -import com.sun.tools.javac.code.Type.ErrorType; -import com.sun.tools.javac.code.Type.ForAll; -import com.sun.tools.javac.code.Type.MethodType; -import com.sun.tools.javac.code.Type.PackageType; -import com.sun.tools.javac.code.Type.TypeVar; -import com.sun.tools.javac.code.Type.UndetVar; -import com.sun.tools.javac.code.Type.Visitor; -import com.sun.tools.javac.code.Type.WildcardType; -import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry; -import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind; -import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.Symbol.MethodSymbol; -import com.sun.tools.javac.comp.Annotate; -import com.sun.tools.javac.comp.Annotate.Worker; -import com.sun.tools.javac.comp.Attr; -import com.sun.tools.javac.comp.AttrContext; -import com.sun.tools.javac.comp.Env; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeInfo; -import com.sun.tools.javac.tree.JCTree.JCBlock; -import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCLambda; -import com.sun.tools.javac.tree.JCTree.JCMethodDecl; -import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; -import com.sun.tools.javac.tree.JCTree.JCNewClass; -import com.sun.tools.javac.tree.JCTree.JCTypeApply; -import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.tree.TreeScanner; -import com.sun.tools.javac.tree.JCTree.*; -import com.sun.tools.javac.util.Assert; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.ListBuffer; -import com.sun.tools.javac.util.Log; -import com.sun.tools.javac.util.Names; -import com.sun.tools.javac.util.Options; - -/** - * Contains operations specific to processing type annotations. - * This class has two functions: - * separate declaration from type annotations and insert the type - * annotations to their types; - * and determine the TypeAnnotationPositions for all type annotations. - */ -public class TypeAnnotations { - protected static final Context.Key typeAnnosKey = new Context.Key<>(); - - public static TypeAnnotations instance(Context context) { - TypeAnnotations instance = context.get(typeAnnosKey); - if (instance == null) - instance = new TypeAnnotations(context); - return instance; - } - - final Log log; - final Names names; - final Symtab syms; - final Annotate annotate; - final Attr attr; - - protected TypeAnnotations(Context context) { - context.put(typeAnnosKey, this); - names = Names.instance(context); - log = Log.instance(context); - syms = Symtab.instance(context); - annotate = Annotate.instance(context); - attr = Attr.instance(context); - Options options = Options.instance(context); - } - - /** - * Separate type annotations from declaration annotations and - * determine the correct positions for type annotations. - * This version only visits types in signatures and should be - * called from MemberEnter. - * The method takes the Annotate object as parameter and - * adds an Annotate.Worker to the correct Annotate queue for - * later processing. - */ - public void organizeTypeAnnotationsSignatures(final Env env, final JCClassDecl tree) { - annotate.afterRepeated( new Worker() { - @Override - public void run() { - JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); - - try { - new TypeAnnotationPositions(true).scan(tree); - } finally { - log.useSource(oldSource); - } - } - } ); - } - - public void validateTypeAnnotationsSignatures(final Env env, final JCClassDecl tree) { - annotate.validate(new Worker() { //validate annotations - @Override - public void run() { - JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); - - try { - attr.validateTypeAnnotations(tree, true); - } finally { - log.useSource(oldSource); - } - } - } ); - } - - /** - * This version only visits types in bodies, that is, field initializers, - * top-level blocks, and method bodies, and should be called from Attr. - */ - public void organizeTypeAnnotationsBodies(JCClassDecl tree) { - new TypeAnnotationPositions(false).scan(tree); - } - - public enum AnnotationType { DECLARATION, TYPE, BOTH } - - /** - * Determine whether an annotation is a declaration annotation, - * a type annotation, or both. - */ - public AnnotationType annotationType(Attribute.Compound a, Symbol s) { - Attribute.Compound atTarget = - a.type.tsym.attribute(syms.annotationTargetType.tsym); - if (atTarget == null) { - return inferTargetMetaInfo(a, s); - } - Attribute atValue = atTarget.member(names.value); - if (!(atValue instanceof Attribute.Array)) { - Assert.error("annotationType(): bad @Target argument " + atValue + - " (" + atValue.getClass() + ")"); - return AnnotationType.DECLARATION; // error recovery - } - Attribute.Array arr = (Attribute.Array) atValue; - boolean isDecl = false, isType = false; - for (Attribute app : arr.values) { - if (!(app instanceof Attribute.Enum)) { - Assert.error("annotationType(): unrecognized Attribute kind " + app + - " (" + app.getClass() + ")"); - isDecl = true; - continue; - } - Attribute.Enum e = (Attribute.Enum) app; - if (e.value.name == names.TYPE) { - if (s.kind == Kinds.TYP) - isDecl = true; - } else if (e.value.name == names.FIELD) { - if (s.kind == Kinds.VAR && - s.owner.kind != Kinds.MTH) - isDecl = true; - } else if (e.value.name == names.METHOD) { - if (s.kind == Kinds.MTH && - !s.isConstructor()) - isDecl = true; - } else if (e.value.name == names.PARAMETER) { - if (s.kind == Kinds.VAR && - s.owner.kind == Kinds.MTH && - (s.flags() & Flags.PARAMETER) != 0) - isDecl = true; - } else if (e.value.name == names.CONSTRUCTOR) { - if (s.kind == Kinds.MTH && - s.isConstructor()) - isDecl = true; - } else if (e.value.name == names.LOCAL_VARIABLE) { - if (s.kind == Kinds.VAR && - s.owner.kind == Kinds.MTH && - (s.flags() & Flags.PARAMETER) == 0) - isDecl = true; - } else if (e.value.name == names.ANNOTATION_TYPE) { - if (s.kind == Kinds.TYP && - (s.flags() & Flags.ANNOTATION) != 0) - isDecl = true; - } else if (e.value.name == names.PACKAGE) { - if (s.kind == Kinds.PCK) - isDecl = true; - } else if (e.value.name == names.TYPE_USE) { - if (s.kind == Kinds.TYP || - s.kind == Kinds.VAR || - (s.kind == Kinds.MTH && !s.isConstructor() && - !s.type.getReturnType().hasTag(TypeTag.VOID)) || - (s.kind == Kinds.MTH && s.isConstructor())) - isType = true; - } else if (e.value.name == names.TYPE_PARAMETER) { - /* Irrelevant in this case */ - // TYPE_PARAMETER doesn't aid in distinguishing between - // Type annotations and declaration annotations on an - // Element - } else { - Assert.error("annotationType(): unrecognized Attribute name " + e.value.name + - " (" + e.value.name.getClass() + ")"); - isDecl = true; - } - } - if (isDecl && isType) { - return AnnotationType.BOTH; - } else if (isType) { - return AnnotationType.TYPE; - } else { - return AnnotationType.DECLARATION; - } - } - - /** Infer the target annotation kind, if none is give. - * We only infer declaration annotations. - */ - private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) { - return AnnotationType.DECLARATION; - } - - - private class TypeAnnotationPositions extends TreeScanner { - - private final boolean sigOnly; - - TypeAnnotationPositions(boolean sigOnly) { - this.sigOnly = sigOnly; - } - - /* - * When traversing the AST we keep the "frames" of visited - * trees in order to determine the position of annotations. - */ - private ListBuffer frames = new ListBuffer<>(); - - protected void push(JCTree t) { frames = frames.prepend(t); } - protected JCTree pop() { return frames.next(); } - // could this be frames.elems.tail.head? - private JCTree peek2() { return frames.toList().tail.head; } - - @Override - public void scan(JCTree tree) { - push(tree); - super.scan(tree); - pop(); - } - - /** - * Separates type annotations from declaration annotations. - * This step is needed because in certain locations (where declaration - * and type annotations can be mixed, e.g. the type of a field) - * we never build an JCAnnotatedType. This step finds these - * annotations and marks them as if they were part of the type. - */ - private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym, - TypeAnnotationPosition pos) { - List annotations = sym.getRawAttributes(); - ListBuffer declAnnos = new ListBuffer<>(); - ListBuffer typeAnnos = new ListBuffer<>(); - ListBuffer onlyTypeAnnos = new ListBuffer<>(); - - for (Attribute.Compound a : annotations) { - switch (annotationType(a, sym)) { - case DECLARATION: - declAnnos.append(a); - break; - case BOTH: { - declAnnos.append(a); - Attribute.TypeCompound ta = toTypeCompound(a, pos); - typeAnnos.append(ta); - break; - } - case TYPE: { - Attribute.TypeCompound ta = toTypeCompound(a, pos); - typeAnnos.append(ta); - // Also keep track which annotations are only type annotations - onlyTypeAnnos.append(ta); - break; - } - } - } - - sym.resetAnnotations(); - sym.setDeclarationAttributes(declAnnos.toList()); - - if (typeAnnos.isEmpty()) { - return; - } - - List typeAnnotations = typeAnnos.toList(); - - if (type == null) { - // When type is null, put the type annotations to the symbol. - // This is used for constructor return annotations, for which - // we use the type of the enclosing class. - type = sym.getEnclosingElement().asType(); - - // Declaration annotations are always allowed on constructor returns. - // Therefore, use typeAnnotations instead of onlyTypeAnnos. - type = typeWithAnnotations(typetree, type, typeAnnotations, typeAnnotations); - // Note that we don't use the result, the call to - // typeWithAnnotations side-effects the type annotation positions. - // This is important for constructors of nested classes. - sym.appendUniqueTypeAttributes(typeAnnotations); - return; - } - - // type is non-null and annotations are added to that type - type = typeWithAnnotations(typetree, type, typeAnnotations, onlyTypeAnnos.toList()); - - if (sym.getKind() == ElementKind.METHOD) { - sym.type.asMethodType().restype = type; - } else if (sym.getKind() == ElementKind.PARAMETER) { - sym.type = type; - if (sym.getQualifiedName().equals(names._this)) { - sym.owner.type.asMethodType().recvtype = type; - // note that the typeAnnotations will also be added to the owner below. - } else { - MethodType methType = sym.owner.type.asMethodType(); - List params = ((MethodSymbol)sym.owner).params; - List oldArgs = methType.argtypes; - ListBuffer newArgs = new ListBuffer<>(); - while (params.nonEmpty()) { - if (params.head == sym) { - newArgs.add(type); - } else { - newArgs.add(oldArgs.head); - } - oldArgs = oldArgs.tail; - params = params.tail; - } - methType.argtypes = newArgs.toList(); - } - } else { - sym.type = type; - } - - sym.appendUniqueTypeAttributes(typeAnnotations); - - if (sym.getKind() == ElementKind.PARAMETER || - sym.getKind() == ElementKind.LOCAL_VARIABLE || - sym.getKind() == ElementKind.RESOURCE_VARIABLE || - sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { - // Make sure all type annotations from the symbol are also - // on the owner. - sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes()); - } - } - - // This method has a similar purpose as - // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List, boolean)} - // We found a type annotation in a declaration annotation position, - // for example, on the return type. - // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore - // need to set its position explicitly. - // The method returns a copy of type that contains these annotations. - // - // As a side effect the method sets the type annotation position of "annotations". - // Note that it is assumed that all annotations share the same position. - private Type typeWithAnnotations(final JCTree typetree, final Type type, - final List annotations, - final List onlyTypeAnnotations) { - //System.err.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s, onlyTypeAnnotations: %s)%n", - // typetree, type, annotations, onlyTypeAnnotations); - if (annotations.isEmpty()) { - return type; - } - if (type.hasTag(TypeTag.ARRAY)) { - Type.ArrayType arType = (Type.ArrayType) type; - Type.ArrayType tomodify = new Type.ArrayType(null, arType.tsym, - Type.noAnnotations); - Type toreturn; - if (type.isAnnotated()) { - toreturn = tomodify.annotatedType(type.getAnnotationMirrors()); - } else { - toreturn = tomodify; - } - - JCArrayTypeTree arTree = arrayTypeTree(typetree); - - ListBuffer depth = new ListBuffer<>(); - depth = depth.append(TypePathEntry.ARRAY); - while (arType.elemtype.hasTag(TypeTag.ARRAY)) { - if (arType.elemtype.isAnnotated()) { - Type aelemtype = arType.elemtype; - arType = (Type.ArrayType) aelemtype; - ArrayType prevToMod = tomodify; - tomodify = new Type.ArrayType(null, arType.tsym, - Type.noAnnotations); - prevToMod.elemtype = tomodify.annotatedType(arType.elemtype.getAnnotationMirrors()); - } else { - arType = (Type.ArrayType) arType.elemtype; - tomodify.elemtype = new Type.ArrayType(null, arType.tsym, - Type.noAnnotations); - tomodify = (Type.ArrayType) tomodify.elemtype; - } - arTree = arrayTypeTree(arTree.elemtype); - depth = depth.append(TypePathEntry.ARRAY); - } - Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, onlyTypeAnnotations); - tomodify.elemtype = arelemType; - { - // All annotations share the same position; modify the first one. - Attribute.TypeCompound a = annotations.get(0); - TypeAnnotationPosition p = a.position; - p.location = p.location.prependList(depth.toList()); - } - typetree.type = toreturn; - return toreturn; - } else if (type.hasTag(TypeTag.TYPEVAR)) { - // Nothing to do for type variables. - return type; - } else if (type.getKind() == TypeKind.UNION) { - // There is a TypeKind, but no TypeTag. - JCTypeUnion tutree = (JCTypeUnion) typetree; - JCExpression fst = tutree.alternatives.get(0); - Type res = typeWithAnnotations(fst, fst.type, annotations, onlyTypeAnnotations); - fst.type = res; - // TODO: do we want to set res as first element in uct.alternatives? - // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type; - // Return the un-annotated union-type. - return type; - } else { - Type enclTy = type; - Element enclEl = type.asElement(); - JCTree enclTr = typetree; - - while (enclEl != null && - enclEl.getKind() != ElementKind.PACKAGE && - enclTy != null && - enclTy.getKind() != TypeKind.NONE && - enclTy.getKind() != TypeKind.ERROR && - (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT || - enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE || - enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) { - // Iterate also over the type tree, not just the type: the type is already - // completely resolved and we cannot distinguish where the annotation - // belongs for a nested type. - if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) { - // only change encl in this case. - enclTy = enclTy.getEnclosingType(); - enclEl = enclEl.getEnclosingElement(); - enclTr = ((JCFieldAccess)enclTr).getExpression(); - } else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) { - enclTr = ((JCTypeApply)enclTr).getType(); - } else { - // only other option because of while condition - enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType(); - } - } - - /** We are trying to annotate some enclosing type, - * but nothing more exists. - */ - if (enclTy != null && - enclTy.hasTag(TypeTag.NONE)) { - switch (onlyTypeAnnotations.size()) { - case 0: - // Don't issue an error if all type annotations are - // also declaration annotations. - // If the annotations are also declaration annotations, they are - // illegal as type annotations but might be legal as declaration annotations. - // The normal declaration annotation checks make sure that the use is valid. - break; - case 1: - log.error(typetree.pos(), "cant.type.annotate.scoping.1", - onlyTypeAnnotations); - break; - default: - log.error(typetree.pos(), "cant.type.annotate.scoping", - onlyTypeAnnotations); - } - return type; - } - - // At this point we have visited the part of the nested - // type that is written in the source code. - // Now count from here to the actual top-level class to determine - // the correct nesting. - - // The genericLocation for the annotation. - ListBuffer depth = new ListBuffer<>(); - - Type topTy = enclTy; - while (enclEl != null && - enclEl.getKind() != ElementKind.PACKAGE && - topTy != null && - topTy.getKind() != TypeKind.NONE && - topTy.getKind() != TypeKind.ERROR) { - topTy = topTy.getEnclosingType(); - enclEl = enclEl.getEnclosingElement(); - - if (topTy != null && topTy.getKind() != TypeKind.NONE) { - // Only count enclosing types. - depth = depth.append(TypePathEntry.INNER_TYPE); - } - } - - if (depth.nonEmpty()) { - // Only need to change the annotation positions - // if they are on an enclosed type. - // All annotations share the same position; modify the first one. - Attribute.TypeCompound a = annotations.get(0); - TypeAnnotationPosition p = a.position; - p.location = p.location.appendList(depth.toList()); - } - - Type ret = typeWithAnnotations(type, enclTy, annotations); - typetree.type = ret; - return ret; - } - } - - private JCArrayTypeTree arrayTypeTree(JCTree typetree) { - if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) { - return (JCArrayTypeTree) typetree; - } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) { - return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType; - } else { - Assert.error("Could not determine array type from type tree: " + typetree); - return null; - } - } - - /** Return a copy of the first type that only differs by - * inserting the annotations to the left-most/inner-most type - * or the type given by stopAt. - * - * We need the stopAt parameter to know where on a type to - * put the annotations. - * If we have nested classes Outer > Middle > Inner, and we - * have the source type "@A Middle.Inner", we will invoke - * this method with type = Outer.Middle.Inner, - * stopAt = Middle.Inner, and annotations = @A. - * - * @param type The type to copy. - * @param stopAt The type to stop at. - * @param annotations The annotations to insert. - * @return A copy of type that contains the annotations. - */ - private Type typeWithAnnotations(final Type type, - final Type stopAt, - final List annotations) { - //System.err.println("typeWithAnnotations " + type + " " + annotations + " stopAt " + stopAt); - Visitor> visitor = - new Type.Visitor>() { - @Override - public Type visitClassType(ClassType t, List s) { - // assert that t.constValue() == null? - if (t == stopAt || - t.getEnclosingType() == Type.noType) { - return t.annotatedType(s); - } else { - ClassType ret = new ClassType(t.getEnclosingType().accept(this, s), - t.typarams_field, t.tsym, - t.getAnnotationMirrors()); - ret.all_interfaces_field = t.all_interfaces_field; - ret.allparams_field = t.allparams_field; - ret.interfaces_field = t.interfaces_field; - ret.rank_field = t.rank_field; - ret.supertype_field = t.supertype_field; - return ret; - } - } - - @Override - public Type visitWildcardType(WildcardType t, List s) { - return t.annotatedType(s); - } - - @Override - public Type visitArrayType(ArrayType t, List s) { - ArrayType ret = new ArrayType(t.elemtype.accept(this, s), t.tsym, - t.getAnnotationMirrors()); - return ret; - } - - @Override - public Type visitMethodType(MethodType t, List s) { - // Impossible? - return t; - } - - @Override - public Type visitPackageType(PackageType t, List s) { - // Impossible? - return t; - } - - @Override - public Type visitTypeVar(TypeVar t, List s) { - return t.annotatedType(s); - } - - @Override - public Type visitCapturedType(CapturedType t, List s) { - return t.annotatedType(s); - } - - @Override - public Type visitForAll(ForAll t, List s) { - // Impossible? - return t; - } - - @Override - public Type visitUndetVar(UndetVar t, List s) { - // Impossible? - return t; - } - - @Override - public Type visitErrorType(ErrorType t, List s) { - return t.annotatedType(s); - } - - @Override - public Type visitType(Type t, List s) { - return t.annotatedType(s); - } - }; - - return type.accept(visitor, annotations); - } - - private Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) { - // It is safe to alias the position. - return new Attribute.TypeCompound(a, p); - } - - - /* This is the beginning of the second part of organizing - * type annotations: determine the type annotation positions. - */ - - // This method is considered deprecated, and will be removed - // in the near future. Don't use it for anything new. - private TypeAnnotationPosition - resolveFrame(JCTree tree, - JCTree frame, - List path, - JCLambda currentLambda, - int outer_type_index, - ListBuffer location) { - /* - System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind()); - System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind()); - */ - - // Note that p.offset is set in - // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int) - - switch (frame.getKind()) { - case TYPE_CAST: - return TypeAnnotationPosition.typeCast(location.toList(), - currentLambda, - outer_type_index, - frame.pos); - - case INSTANCE_OF: - return TypeAnnotationPosition.instanceOf(location.toList(), - currentLambda, - frame.pos); - - case NEW_CLASS: - final JCNewClass frameNewClass = (JCNewClass) frame; - if (frameNewClass.def != null) { - // Special handling for anonymous class instantiations - final JCClassDecl frameClassDecl = frameNewClass.def; - if (frameClassDecl.extending == tree) { - return TypeAnnotationPosition - .classExtends(location.toList(), currentLambda, - frame.pos); - } else if (frameClassDecl.implementing.contains(tree)) { - final int type_index = - frameClassDecl.implementing.indexOf(tree); - return TypeAnnotationPosition - .classExtends(location.toList(), currentLambda, - type_index, frame.pos); - } else { - // In contrast to CLASS below, typarams cannot occur here. - throw new AssertionError("Could not determine position of tree " + tree + - " within frame " + frame); - } - } else if (frameNewClass.typeargs.contains(tree)) { - final int type_index = - frameNewClass.typeargs.indexOf(tree); - return TypeAnnotationPosition - .constructorInvocationTypeArg(location.toList(), - currentLambda, - type_index, - frame.pos); - } else { - return TypeAnnotationPosition - .newObj(location.toList(), currentLambda, - frame.pos); - } - - case NEW_ARRAY: - return TypeAnnotationPosition - .newObj(location.toList(), currentLambda, frame.pos); - - case ANNOTATION_TYPE: - case CLASS: - case ENUM: - case INTERFACE: - if (((JCClassDecl)frame).extending == tree) { - return TypeAnnotationPosition - .classExtends(location.toList(), currentLambda, - frame.pos); - } else if (((JCClassDecl)frame).implementing.contains(tree)) { - final int type_index = - ((JCClassDecl)frame).implementing.indexOf(tree); - return TypeAnnotationPosition - .classExtends(location.toList(), currentLambda, - type_index, frame.pos); - } else if (((JCClassDecl)frame).typarams.contains(tree)) { - final int parameter_index = - ((JCClassDecl)frame).typarams.indexOf(tree); - return TypeAnnotationPosition - .typeParameter(location.toList(), currentLambda, - parameter_index, frame.pos); - } else { - throw new AssertionError("Could not determine position of tree " + - tree + " within frame " + frame); - } - - case METHOD: { - final JCMethodDecl frameMethod = (JCMethodDecl) frame; - if (frameMethod.thrown.contains(tree)) { - final int type_index = frameMethod.thrown.indexOf(tree); - return TypeAnnotationPosition - .methodThrows(location.toList(), currentLambda, - type_index, frame.pos); - } else if (frameMethod.restype == tree) { - return TypeAnnotationPosition - .methodReturn(location.toList(), currentLambda, - frame.pos); - } else if (frameMethod.typarams.contains(tree)) { - final int parameter_index = - frameMethod.typarams.indexOf(tree); - return TypeAnnotationPosition - .methodTypeParameter(location.toList(), - currentLambda, - parameter_index, frame.pos); - } else { - throw new AssertionError("Could not determine position of tree " + tree + - " within frame " + frame); - } - } - - case PARAMETERIZED_TYPE: { - List newPath = path.tail; - - if (((JCTypeApply)frame).clazz == tree) { - // generic: RAW; noop - } else if (((JCTypeApply)frame).arguments.contains(tree)) { - JCTypeApply taframe = (JCTypeApply) frame; - int arg = taframe.arguments.indexOf(tree); - location = location.prepend( - new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, - arg)); - - Type typeToUse; - if (newPath.tail != null && - newPath.tail.head.hasTag(Tag.NEWCLASS)) { - // If we are within an anonymous class - // instantiation, use its type, because it - // contains a correctly nested type. - typeToUse = newPath.tail.head.type; - } else { - typeToUse = taframe.type; - } - - location = locateNestedTypes(typeToUse, location); - } else { - throw new AssertionError("Could not determine type argument position of tree " + tree + - " within frame " + frame); - } - - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, location); - } - - case MEMBER_REFERENCE: { - JCMemberReference mrframe = (JCMemberReference) frame; - - if (mrframe.expr == tree) { - switch (mrframe.mode) { - case INVOKE: - return TypeAnnotationPosition - .methodRef(location.toList(), currentLambda, - frame.pos); - case NEW: - return TypeAnnotationPosition - .constructorRef(location.toList(), - currentLambda, - frame.pos); - default: - throw new AssertionError("Unknown method reference mode " + mrframe.mode + - " for tree " + tree + " within frame " + frame); - } - } else if (mrframe.typeargs != null && - mrframe.typeargs.contains(tree)) { - final int type_index = mrframe.typeargs.indexOf(tree); - switch (mrframe.mode) { - case INVOKE: - return TypeAnnotationPosition - .methodRefTypeArg(location.toList(), - currentLambda, - type_index, frame.pos); - case NEW: - return TypeAnnotationPosition - .constructorRefTypeArg(location.toList(), - currentLambda, - type_index, frame.pos); - default: - throw new AssertionError("Unknown method reference mode " + mrframe.mode + - " for tree " + tree + " within frame " + frame); - } - } else { - throw new AssertionError("Could not determine type argument position of tree " + tree + - " within frame " + frame); - } - } - - case ARRAY_TYPE: { - location = location.prepend(TypePathEntry.ARRAY); - List newPath = path.tail; - while (true) { - JCTree npHead = newPath.tail.head; - if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) { - newPath = newPath.tail; - location = location.prepend(TypePathEntry.ARRAY); - } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) { - newPath = newPath.tail; - } else { - break; - } - } - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, location); - } - - case TYPE_PARAMETER: - if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) { - final JCClassDecl clazz = - (JCClassDecl)path.tail.tail.head; - final int parameter_index = - clazz.typarams.indexOf(path.tail.head); - final int bound_index = - ((JCTypeParameter)frame).bounds.get(0) - .type.isInterface() ? - ((JCTypeParameter)frame).bounds.indexOf(tree) + 1: - ((JCTypeParameter)frame).bounds.indexOf(tree); - return TypeAnnotationPosition - .typeParameterBound(location.toList(), - currentLambda, - parameter_index, bound_index, - frame.pos); - } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) { - final JCMethodDecl method = - (JCMethodDecl)path.tail.tail.head; - final int parameter_index = - method.typarams.indexOf(path.tail.head); - final int bound_index = - ((JCTypeParameter)frame).bounds.get(0) - .type.isInterface() ? - ((JCTypeParameter)frame).bounds.indexOf(tree) + 1: - ((JCTypeParameter)frame).bounds.indexOf(tree); - return TypeAnnotationPosition - .methodTypeParameterBound(location.toList(), - currentLambda, - parameter_index, - bound_index, - frame.pos); - } else { - throw new AssertionError("Could not determine position of tree " + tree + - " within frame " + frame); - } - - case VARIABLE: - VarSymbol v = ((JCVariableDecl)frame).sym; - if (v.getKind() != ElementKind.FIELD) { - v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes()); - } - switch (v.getKind()) { - case LOCAL_VARIABLE: - return TypeAnnotationPosition - .localVariable(location.toList(), currentLambda, - frame.pos); - case FIELD: - return TypeAnnotationPosition.field(location.toList(), - currentLambda, - frame.pos); - case PARAMETER: - if (v.getQualifiedName().equals(names._this)) { - return TypeAnnotationPosition - .methodReceiver(location.toList(), - currentLambda, - frame.pos); - } else { - final int parameter_index = - methodParamIndex(path, frame); - return TypeAnnotationPosition - .methodParameter(location.toList(), - currentLambda, - parameter_index, - frame.pos); - } - case EXCEPTION_PARAMETER: - return TypeAnnotationPosition - .exceptionParameter(location.toList(), - currentLambda, - frame.pos); - case RESOURCE_VARIABLE: - return TypeAnnotationPosition - .resourceVariable(location.toList(), - currentLambda, - frame.pos); - default: - throw new AssertionError("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind()); - } - - case ANNOTATED_TYPE: { - if (frame == tree) { - // This is only true for the first annotated type we see. - // For any other annotated types along the path, we do - // not care about inner types. - JCAnnotatedType atypetree = (JCAnnotatedType) frame; - final Type utype = atypetree.underlyingType.type; - Assert.checkNonNull(utype); - Symbol tsym = utype.tsym; - if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) || - utype.getKind().equals(TypeKind.WILDCARD) || - utype.getKind().equals(TypeKind.ARRAY)) { - // Type parameters, wildcards, and arrays have the declaring - // class/method as enclosing elements. - // There is actually nothing to do for them. - } else { - location = locateNestedTypes(utype, location); - } - } - List newPath = path.tail; - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, location); - } - - case UNION_TYPE: { - List newPath = path.tail; - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, location); - } - - case INTERSECTION_TYPE: { - JCTypeIntersection isect = (JCTypeIntersection)frame; - final List newPath = path.tail; - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - isect.bounds.indexOf(tree), location); - } - - case METHOD_INVOCATION: { - JCMethodInvocation invocation = (JCMethodInvocation)frame; - if (!invocation.typeargs.contains(tree)) { - throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation); - } - MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect()); - final int type_index = invocation.typeargs.indexOf(tree); - if (exsym == null) { - throw new AssertionError("could not determine symbol for {" + invocation + "}"); - } else if (exsym.isConstructor()) { - return TypeAnnotationPosition - .constructorInvocationTypeArg(location.toList(), - currentLambda, - type_index, - invocation.pos); - } else { - return TypeAnnotationPosition - .methodInvocationTypeArg(location.toList(), - currentLambda, - type_index, - invocation.pos); - } - } - - case EXTENDS_WILDCARD: - case SUPER_WILDCARD: { - // Annotations in wildcard bounds - final List newPath = path.tail; - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, - location.prepend(TypePathEntry.WILDCARD)); - } - - case MEMBER_SELECT: { - final List newPath = path.tail; - return resolveFrame(newPath.head, newPath.tail.head, - newPath, currentLambda, - outer_type_index, location); - } - - default: - throw new AssertionError("Unresolved frame: " + frame + - " of kind: " + frame.getKind() + - "\n Looking for tree: " + tree); - } - } - - private ListBuffer - locateNestedTypes(Type type, - ListBuffer depth) { - Type encl = type.getEnclosingType(); - while (encl != null && - encl.getKind() != TypeKind.NONE && - encl.getKind() != TypeKind.ERROR) { - depth = depth.prepend(TypePathEntry.INNER_TYPE); - encl = encl.getEnclosingType(); - } - return depth; - } - - private int methodParamIndex(List path, JCTree param) { - List curr = path; - while (curr.head.getTag() != Tag.METHODDEF && - curr.head.getTag() != Tag.LAMBDA) { - curr = curr.tail; - } - if (curr.head.getTag() == Tag.METHODDEF) { - JCMethodDecl method = (JCMethodDecl)curr.head; - return method.params.indexOf(param); - } else if (curr.head.getTag() == Tag.LAMBDA) { - JCLambda lambda = (JCLambda)curr.head; - return lambda.params.indexOf(param); - } else { - Assert.error("methodParamIndex expected to find method or lambda for param: " + param); - return -1; - } - } - - // Each class (including enclosed inner classes) is visited separately. - // This flag is used to prevent from visiting inner classes. - private boolean isInClass = false; - - @Override - public void visitClassDef(JCClassDecl tree) { - if (isInClass) - return; - isInClass = true; - - if (sigOnly) { - scan(tree.mods); - scan(tree.typarams); - scan(tree.extending); - scan(tree.implementing); - } - scan(tree.defs); - } - - /** - * Resolve declaration vs. type annotations in methods and - * then determine the positions. - */ - @Override - public void visitMethodDef(final JCMethodDecl tree) { - if (tree.sym == null) { - Assert.error("Visiting tree node before memberEnter"); - } - if (sigOnly) { - if (!tree.mods.annotations.isEmpty()) { - if (tree.sym.isConstructor()) { - final TypeAnnotationPosition pos = - TypeAnnotationPosition.methodReturn(tree.pos); - // Use null to mark that the annotations go - // with the symbol. - separateAnnotationsKinds(tree, null, tree.sym, pos); - } else { - final TypeAnnotationPosition pos = - TypeAnnotationPosition.methodReturn(tree.restype.pos); - separateAnnotationsKinds(tree.restype, - tree.sym.type.getReturnType(), - tree.sym, pos); - } - } - if (tree.recvparam != null && tree.recvparam.sym != null && - !tree.recvparam.mods.annotations.isEmpty()) { - // Nothing to do for separateAnnotationsKinds if - // there are no annotations of either kind. - // TODO: make sure there are no declaration annotations. - final TypeAnnotationPosition pos = - TypeAnnotationPosition.methodReceiver(tree.recvparam.vartype.pos); - separateAnnotationsKinds(tree.recvparam.vartype, - tree.recvparam.sym.type, - tree.recvparam.sym, pos); - } - int i = 0; - for (JCVariableDecl param : tree.params) { - if (!param.mods.annotations.isEmpty()) { - // Nothing to do for separateAnnotationsKinds if - // there are no annotations of either kind. - final TypeAnnotationPosition pos = - TypeAnnotationPosition.methodParameter(i, param.vartype.pos); - separateAnnotationsKinds(param.vartype, - param.sym.type, - param.sym, pos); - } - ++i; - } - } - - push(tree); - // super.visitMethodDef(tree); - if (sigOnly) { - scan(tree.mods); - scan(tree.restype); - scan(tree.typarams); - scan(tree.recvparam); - scan(tree.params); - scan(tree.thrown); - } else { - scan(tree.defaultValue); - scan(tree.body); - } - pop(); - } - - /* Store a reference to the current lambda expression, to - * be used by all type annotations within this expression. - */ - private JCLambda currentLambda = null; - - public void visitLambda(JCLambda tree) { - JCLambda prevLambda = currentLambda; - try { - currentLambda = tree; - - int i = 0; - for (JCVariableDecl param : tree.params) { - if (!param.mods.annotations.isEmpty()) { - // Nothing to do for separateAnnotationsKinds if - // there are no annotations of either kind. - final TypeAnnotationPosition pos = - TypeAnnotationPosition.methodParameter(tree, i, - param.vartype.pos); - separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); - } - ++i; - } - - push(tree); - scan(tree.body); - scan(tree.params); - pop(); - } finally { - currentLambda = prevLambda; - } - } - - /** - * Resolve declaration vs. type annotations in variable declarations and - * then determine the positions. - */ - @Override - public void visitVarDef(final JCVariableDecl tree) { - if (tree.mods.annotations.isEmpty()) { - // Nothing to do for separateAnnotationsKinds if - // there are no annotations of either kind. - } else if (tree.sym == null) { - Assert.error("Visiting tree node before memberEnter"); - } else if (tree.sym.getKind() == ElementKind.PARAMETER) { - // Parameters are handled in visitMethodDef or visitLambda. - } else if (tree.sym.getKind() == ElementKind.FIELD) { - if (sigOnly) { - TypeAnnotationPosition pos = - TypeAnnotationPosition.field(tree.pos); - separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); - } - } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) { - final TypeAnnotationPosition pos = - TypeAnnotationPosition.localVariable(currentLambda, - tree.pos); - separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); - } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { - final TypeAnnotationPosition pos = - TypeAnnotationPosition.exceptionParameter(currentLambda, - tree.pos); - separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); - } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) { - final TypeAnnotationPosition pos = - TypeAnnotationPosition.resourceVariable(currentLambda, - tree.pos); - separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); - } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) { - // No type annotations can occur here. - } else { - // There is nothing else in a variable declaration that needs separation. - Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind()); - } - - push(tree); - // super.visitVarDef(tree); - scan(tree.mods); - scan(tree.vartype); - if (!sigOnly) { - scan(tree.init); - } - pop(); - } - - @Override - public void visitBlock(JCBlock tree) { - // Do not descend into top-level blocks when only interested - // in the signature. - if (!sigOnly) { - scan(tree.stats); - } - } - - @Override - public void visitAnnotatedType(JCAnnotatedType tree) { - push(tree); - findPosition(tree, tree, tree.annotations); - pop(); - super.visitAnnotatedType(tree); - } - - @Override - public void visitTypeParameter(JCTypeParameter tree) { - findPosition(tree, peek2(), tree.annotations); - super.visitTypeParameter(tree); - } - - private void copyNewClassAnnotationsToOwner(JCNewClass tree) { - Symbol sym = tree.def.sym; - final TypeAnnotationPosition pos = - TypeAnnotationPosition.newObj(tree.pos); - ListBuffer newattrs = new ListBuffer<>(); - - for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) { - newattrs.append(new Attribute.TypeCompound(old.type, old.values, - pos)); - } - - sym.owner.appendUniqueTypeAttributes(newattrs.toList()); - } - - @Override - public void visitNewClass(JCNewClass tree) { - if (tree.def != null && - !tree.def.mods.annotations.isEmpty()) { - JCClassDecl classdecl = tree.def; - TypeAnnotationPosition pos; - - if (classdecl.extending == tree.clazz) { - pos = TypeAnnotationPosition.classExtends(tree.pos); - } else if (classdecl.implementing.contains(tree.clazz)) { - final int index = classdecl.implementing.indexOf(tree.clazz); - pos = TypeAnnotationPosition.classExtends(index, tree.pos); - } else { - // In contrast to CLASS elsewhere, typarams cannot occur here. - throw new AssertionError("Could not determine position of tree " + tree); - } - Type before = classdecl.sym.type; - separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos); - copyNewClassAnnotationsToOwner(tree); - // classdecl.sym.type now contains an annotated type, which - // is not what we want there. - // TODO: should we put this type somewhere in the superclass/interface? - classdecl.sym.type = before; - } - - scan(tree.encl); - scan(tree.typeargs); - scan(tree.clazz); - scan(tree.args); - - // The class body will already be scanned. - // scan(tree.def); - } - - @Override - public void visitNewArray(JCNewArray tree) { - findPosition(tree, tree, tree.annotations); - int dimAnnosCount = tree.dimAnnotations.size(); - ListBuffer depth = new ListBuffer<>(); - - // handle annotations associated with dimensions - for (int i = 0; i < dimAnnosCount; ++i) { - ListBuffer location = - new ListBuffer(); - if (i != 0) { - depth = depth.append(TypePathEntry.ARRAY); - location = location.appendList(depth.toList()); - } - final TypeAnnotationPosition p = - TypeAnnotationPosition.newObj(location.toList(), - currentLambda, - tree.pos); - - setTypeAnnotationPos(tree.dimAnnotations.get(i), p); - } - - // handle "free" annotations - // int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1; - // TODO: is depth.size == i here? - JCExpression elemType = tree.elemtype; - depth = depth.append(TypePathEntry.ARRAY); - while (elemType != null) { - if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) { - JCAnnotatedType at = (JCAnnotatedType)elemType; - final ListBuffer locationbuf = - locateNestedTypes(elemType.type, - new ListBuffer()); - final List location = - locationbuf.toList().prependList(depth.toList()); - final TypeAnnotationPosition p = - TypeAnnotationPosition.newObj(location, currentLambda, - tree.pos); - setTypeAnnotationPos(at.annotations, p); - elemType = at.underlyingType; - } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) { - depth = depth.append(TypePathEntry.ARRAY); - elemType = ((JCArrayTypeTree)elemType).elemtype; - } else if (elemType.hasTag(JCTree.Tag.SELECT)) { - elemType = ((JCFieldAccess)elemType).selected; - } else { - break; - } - } - scan(tree.elems); - } - - private void findPosition(JCTree tree, JCTree frame, List annotations) { - if (!annotations.isEmpty()) { - /* - System.err.println("Finding pos for: " + annotations); - System.err.println(" tree: " + tree + " kind: " + tree.getKind()); - System.err.println(" frame: " + frame + " kind: " + frame.getKind()); - */ - final TypeAnnotationPosition p = - resolveFrame(tree, frame, frames.toList(), currentLambda, 0, - new ListBuffer()); - setTypeAnnotationPos(annotations, p); - } - } - - private void setTypeAnnotationPos(List annotations, - TypeAnnotationPosition position) { - for (JCAnnotation anno : annotations) { - // attribute might be null during DeferredAttr; - // we will be back later. - if (anno.attribute != null) { - ((Attribute.TypeCompound) anno.attribute).position = position; - } - } - } - - @Override - public String toString() { - return super.toString() + ": sigOnly: " + sigOnly; - } - } -} diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java index 04e475e7b3c..296c98a913f 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java @@ -29,12 +29,15 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import javax.lang.model.element.ElementKind; +import javax.lang.model.type.TypeKind; import javax.tools.JavaFileObject; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.code.TypeAnnotationPosition.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -259,36 +262,78 @@ public class Annotate { * Compute an attribute from its annotation. *********************************************************************/ - /** Process a single compound annotation, returning its - * Attribute. Used from MemberEnter for attaching the attributes - * to the annotated symbol. + /** + * Enter (and attribute) a single regular annotation, returning + * its Attribute. We give these annotations a position in case we + * end up creating a type annotation from using toTypeCompound. + * + * In some cases, namely on annotations that can never be type + * annotations (like package annotations), the position can be + * null; however, if this annotation is in a place where it might + * possibly denote a type annotation, it will have a non-null + * position. + * + * @param a Annotation to attribute. + * @param expected Expected annotation type. + * @param env The environment. + * @param position The type annotation position this will have if + * it's converted to a type annotation. + * @return The Attribute.Compound representing this annotation. */ Attribute.Compound enterAnnotation(JCAnnotation a, Type expected, - Env env) { - List> elems = - enterAttributeValues(a, expected, env); - Attribute.Compound ac = new Attribute.Compound(a.type, elems); + Env env, + TypeAnnotationPosition position) { + List> buf = + enterAttributeValues(a, expected, env, position); + Attribute.Compound ac = + new Attribute.Compound(a.type, buf, position); a.attribute = ac; return ac; } + /** + * Enter (and attribute) a single type annotation, returning its + * Attribute. + * + * Things are a bit complicated, though, because a single source + * annotation (JCAnnotation) might give rise to several bytecode + * annotations (Attribute.TypeCompound), but we can only associate + * a source annotation with one bytecode annotation. Thus, we + * have to distinguish between the "primary" (which will be stored + * to the JCAnnotation) and "secondary" (which won't) annotations. + * The primary place this gets used is for anonymous classes. + * + * The annotations we generate for the new instruction are the + * primary, and the ones we generate for the class are the + * secondaries. (Note: this choice is arbitrary, and it does not + * appear to cause any problems if these roles are reversed) + * + * @param a The annotation to attribute. + * @param expected The expected annotation type. + * @param env The environment. + * @param position The type annotation position to give the type + * annotation. + * @param secondaryAttr Whether or not this is a secondary (ie + * will ignore the .attribute field on a). + * @return The Attribute.TypeCompound representing the annotation. + */ Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a, Type expected, - Env env) { - List> elems = - enterAttributeValues(a, expected, env); + Env env, + TypeAnnotationPosition position, + boolean secondaryAttr) { + List> buf = + enterAttributeValues(a, expected, env, position); - if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) { + // Secondary attr means we do not set the .attribute field of + // the JCAnnotation, nor do we pay attention to it. + if (!secondaryAttr || a.attribute == null || + !(a.attribute instanceof Attribute.TypeCompound)) { // Create a new TypeCompound - Attribute.TypeCompound tc = - new Attribute.TypeCompound(a.type, elems, - // TODO: Eventually, we will get rid of this use of - // unknown, because we'll get a position from - // MemberEnter (task 8027262). - TypeAnnotationPosition.unknown); + new Attribute.TypeCompound(a.type, buf, position); a.attribute = tc; return tc; } else { @@ -297,10 +342,12 @@ public class Annotate { } } + // Attribute all the annotation's values. private List> enterAttributeValues(JCAnnotation a, Type expected, - Env env) { + Env env, + TypeAnnotationPosition position) { // The annotation might have had its type attributed (but not // checked) by attr.attribAnnotationTypes during MemberEnter, // in which case we do not need to do it again. @@ -325,13 +372,13 @@ public class Annotate { JCExpression t = tl.head; if (!t.hasTag(ASSIGN)) { log.error(t.pos(), "annotation.value.must.be.name.value"); - enterAttributeValue(t.type = syms.errType, t, env); + enterAttributeValue(t.type = syms.errType, t, env, position); continue; } JCAssign assign = (JCAssign)t; if (!assign.lhs.hasTag(IDENT)) { log.error(t.pos(), "annotation.value.must.be.name.value"); - enterAttributeValue(t.type = syms.errType, t, env); + enterAttributeValue(t.type = syms.errType, t, env, position); continue; } JCIdent left = (JCIdent)assign.lhs; @@ -346,7 +393,7 @@ public class Annotate { if (method.owner != a.type.tsym && !isError) log.error(left.pos(), "no.annotation.member", left.name, a.type); Type result = method.type.getReturnType(); - Attribute value = enterAttributeValue(result, assign.rhs, env); + Attribute value = enterAttributeValue(result, assign.rhs, env, position); if (!method.type.isErroneous()) buf.append(new Pair<>((MethodSymbol)method, value)); t.type = result; @@ -357,6 +404,13 @@ public class Annotate { Attribute enterAttributeValue(Type expected, JCExpression tree, Env env) { + return enterAttributeValue(expected, tree, env, null); + } + + Attribute enterAttributeValue(Type expected, + JCExpression tree, + Env env, + TypeAnnotationPosition position) { //first, try completing the attribution value sym - if a completion //error is thrown, we should recover gracefully, and display an //ordinary resolution diagnostic. @@ -378,8 +432,7 @@ public class Annotate { ListBuffer buf = new ListBuffer<>(); for (List l = na.elems; l.nonEmpty(); l=l.tail) { buf.append(enterAttributeValue(types.elemtype(expected), - l.head, - env)); + l.head, env, position)); } na.type = expected; return new Attribute. @@ -393,15 +446,13 @@ public class Annotate { log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); } for (List l = na.elems; l.nonEmpty(); l=l.tail) { - enterAttributeValue(syms.errType, - l.head, - env); + enterAttributeValue(syms.errType, l.head, env, position); } return new Attribute.Error(syms.errType); } if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { if (tree.hasTag(ANNOTATION)) { - return enterAnnotation((JCAnnotation)tree, expected, env); + return enterAnnotation((JCAnnotation)tree, expected, env, position); } else { log.error(tree.pos(), "annotation.value.must.be.annotation"); expected = syms.errType; @@ -410,7 +461,7 @@ public class Annotate { if (tree.hasTag(ANNOTATION)) { //error recovery if (!expected.isErroneous()) log.error(tree.pos(), "annotation.not.valid.for.type", expected); - enterAnnotation((JCAnnotation)tree, syms.errType, env); + enterAnnotation((JCAnnotation)tree, syms.errType, env, position); return new Attribute.Error(((JCAnnotation)tree).annotationType.type); } if (expected.isPrimitive() || @@ -477,9 +528,11 @@ public class Annotate { * synthesized container annotation or null IFF all repeating * annotation are invalid. This method reports errors/warnings. */ - private T processRepeatedAnnotations(List annotations, + private T processRepeatedAnnotations( + List annotations, AnnotationContext ctx, - Symbol on) { + Symbol on, + TypeAnnotationPosition position) { T firstOccurrence = annotations.head; List repeated = List.nil(); Type origAnnoType = null; @@ -491,12 +544,8 @@ public class Annotate { !annotations.tail.isEmpty()); // i.e. size() > 1 int count = 0; - for (List al = annotations; - !al.isEmpty(); - al = al.tail) - { + for (List al = annotations; !al.isEmpty(); al = al.tail) { count++; - // There must be more than a single anno in the annotation list Assert.check(count > 1 || !al.tail.isEmpty()); @@ -536,26 +585,16 @@ public class Annotate { new Pair(containerValueSymbol, new Attribute.Array(arrayOfOrigAnnoType, repeated)); if (ctx.isTypeCompound) { - /* TODO: the following code would be cleaner: - Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), - ((Attribute.TypeCompound)annotations.head).position); - JCTypeAnnotation annoTree = m.TypeAnnotation(at); - at = enterTypeAnnotation(annoTree, targetContainerType, ctx.env); - */ - // However, we directly construct the TypeCompound to keep the - // direct relation to the contained TypeCompounds. - Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), - ((Attribute.TypeCompound)annotations.head).position); - - // TODO: annotation applicability checks from below? - + Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), position); at.setSynthesized(true); @SuppressWarnings("unchecked") T x = (T) at; return x; } else { - Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p)); + Attribute.Compound c = new Attribute.Compound(targetContainerType, + List.of(p), + position); JCAnnotation annoTree = m.Annotation(c); if (!chk.annotationApplicable(annoTree, on)) @@ -564,7 +603,7 @@ public class Annotate { if (!chk.validateAnnotationDeferErrors(annoTree)) log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType); - c = enterAnnotation(annoTree, targetContainerType, ctx.env); + c = enterAnnotation(annoTree, targetContainerType, ctx.env, position); c.setSynthesized(true); @SuppressWarnings("unchecked") @@ -576,6 +615,7 @@ public class Annotate { } } + /** Fetches the actual Type that should be the containing annotation. */ private Type getContainingType(Attribute.Compound currentAnno, DiagnosticPosition pos, @@ -705,31 +745,53 @@ public class Annotate { return fatalError ? null : containerValueSymbol; } + /** + * First step of repeating annotations handling: go through a list + * of annotations, and gather up all the repeated ones into a map, + * which we use to build an AnnotationContext. + * + * Because we do this, we need to get all the annotations for a + * given AST node at once (ie. if we have "@A @B @A int foo;", we + * have to get "@A @B @A" at the same time). + * + * @param annotations The annotations being attached. + * @param env The environment. + * @param sym The symbol to which the annotations will be attached. + * @param creator The attribute creator used to enter the annotations. + * @param position The position for any type annotations. + * @return The AnnotaionContext for use in the next phase. + */ private AnnotationContext prepareEnterAnnotations(List annotations, Env env, Symbol sym, AttributeCreator creator, - boolean isTypeCompound) { + TypeAnnotationPosition position) { Map> annotated = new LinkedHashMap<>(); Map pos = new HashMap<>(); + // Go through the annotation list, build up a map from + // annotation types to lists of annotations. for (List al = annotations; !al.isEmpty(); al = al.tail) { JCAnnotation a = al.head; - T c = creator.create(a, syms.annotationType, env); + T c = creator.create(a, syms.annotationType, env, position); Assert.checkNonNull(c, "Failed to create annotation"); if (annotated.containsKey(a.type.tsym)) { + // Make sure we even allow repeating annotations. if (!allowRepeatedAnnos) { log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); allowRepeatedAnnos = true; } + // Append the annotation to the list for this kind of + // annotation. ListBuffer l = annotated.get(a.type.tsym); l = l.append(c); annotated.put(a.type.tsym, l); pos.put(c, a.pos()); } else { + // We are seeing the first annotation of this kind. annotated.put(a.type.tsym, ListBuffer.of(c)); pos.put(c, a.pos()); } @@ -743,25 +805,54 @@ public class Annotate { } return new AnnotationContext<>(env, annotated, pos, - isTypeCompound); + creator.createsTypeCompound()); } - // Gather up annotations into a map from type symbols to lists of - // Compound attributes, then continue on with repeating - // annotations processing + /** + * Entry-point for repeating annotations handling. At this point, + * we should know the type annotation position, and we should have + * all the annotations for a given source location. + * + * We first gather up all the repeated annotations and build an + * AnnotationContext. Then create Placeholder's for any repeated + * annotations and send them further down the pipeline. + * + * Something to keep in mind here is that even if we are handling + * "declaration" annotations, it is still possible that those + * might turn into type annotations (consider "@A @B int foo;", + * for example). + * + * The pipeline uses a sort of continuation-passing like style, + * with creator and attacher. This allows two things. First, it + * allows for a single pipeline for repeating annotations, + * regardless of what eventually happens to the annotations. + * Second, it allows us to avoid some unsafe casts we would + * otherwise have to make. + * + * @param annotations The annotations to handle. + * @param env The environment. + * @param sym The symbol to which to attach annotations. + * @param position The position for type annotations. + * @param creator The creator to use to enter annotations. + * @param attacher The attacher to use to attach annotations. + */ private void attachAttributesLater(final List annotations, final Env env, final Symbol sym, - final boolean isTypeCompound, + final TypeAnnotationPosition position, final AttributeCreator creator, final AttributeAttacher attacher) { + // First, gather up all the repeated annotations. final AnnotationContext ctx = - prepareEnterAnnotations(annotations, env, sym, creator, isTypeCompound); + prepareEnterAnnotations(annotations, env, sym, creator, position); final Map> annotated = ctx.annotated; boolean hasRepeated = false; + // Now run through all the annotation types in the + // AnnotationContext. If there are any that have more than + // one entry, then we set up a Placeholder for them. List buf = List.nil(); for (ListBuffer lb : annotated.values()) { if (lb.size() == 1) { @@ -776,14 +867,62 @@ public class Annotate { final List attrs = buf.reverse(); - if (!isTypeCompound) { + if (!creator.createsTypeCompound()) { // Attach declaration attributes early, so // that @Repeatable and other annotations get attached. // Since the attacher uses setDeclarationAttributes, this // will be overwritten later. - attacher.attach(sym, attrs); + // + // The root cause of this is that annotations are + // themselves defined using annotations. However, it is + // never the case that a type annotation affects the + // definition of an annotation, so we don't have to do + // this. + // + // We really should find a better way to do this. + @SuppressWarnings("unchecked") + List tempattrs = (List) attrs; + sym.setDeclarationAttributes(tempattrs); } + if (hasRepeated) { + // If we have repeated annotations, then we go to the next + // pipeline step, which replaces all the placeholders. + replacePlaceholdersAndAttach(attrs, ctx, env, sym, attacher); + } else { + // If we don't have repeated annotations, then we still + // have to run the annotations through the rest of the + // pipeline. + // + // For type annotations, we might have error-reporting to + // do, and the attacher might end up attaching the + // annotation to the symbol's owner as well. + // + // For regular annotations, we might have a + // classifyingAttacher, in which case we have to pull the + // annotations off the symbol, classify them, and then put + // them in the right place. + attachAttributesAfterRepeated(attrs, env, attacher); + } + } + + /** + * Next pipeline step for repeated annotations: replate all the + * placeholders, and then send the result further down the pipe. + * + * @param attrs The Attributes representing the annotations. + * @param ctx The AnnotationContext being used. + * @param env The environment. + * @param sym The symbol to which to attach annotations. + * @param attacher The attacher to use to attach annotations. + */ + private + void replacePlaceholdersAndAttach(final List attrs, + final AnnotationContext ctx, + final Env env, + final Symbol sym, + final AttributeAttacher attacher) { + // Set up a Worker. repeated(new Annotate.Worker() { @Override public String toString() { @@ -795,38 +934,493 @@ public class Annotate { JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); try { - attacher.attach(sym, replacePlaceholders(attrs, ctx, sym)); + // Replace placeholders + final List replaced = + replacePlaceholders(attrs, ctx, sym); + // Then send the result to the final pipeline stage. + attachAttributesAfterRepeated(replaced, env, attacher); } finally { log.useSource(oldSource); } } }); + } + + /** + * Final pipeline stage. Simply use the attacher to deal with the + * annotations however we want to deal with them. Note that + * attachers may do a number of things, like attach annotations to + * other symbols (as is the case with some type annotations, which + * get attached to their symbol's owner as well), report errors, + * or even create copies (as is the case with classifyingAttacher) + * + * At this point, we have to be able to guarantee that we don't + * see any Placeholders. + * + * @param attrs The Attributes representing the annotations. + * @param env The environment. + * @param attacher The attacher we use to finish handling the + * annotations. + */ + private + void attachAttributesAfterRepeated(final List attrs, + final Env env, + final AttributeAttacher attacher) { + // Set up a Worker that just calls the attacher. + afterRepeated(new Worker() { + @Override + public String toString() { + return "attach pass for: " + attrs; + } + + @Override + public void run() { + JavaFileObject oldSource = + log.useSource(env.toplevel.sourcefile); + try { + attacher.attach(attrs); + } finally { + log.useSource(oldSource); + } + } + }); + } + + /** + * AttributeAttachers are similar to continuations. That contains + * the behavior of the final stage of the annotation pipeline, + * when we've creted Attributes (which have a type annotation + * position), and we've dealt with repeating annotations. Once we + * have done all that, we simply hand off the list of attributes + * to the attacher and let it do its work. + * + * If we didn't have the multiple deferred steps, we could + * implement this by returning a list of Attributes from a + * top-level method representing the entire repeating annotations + * pipeline. Since we have to handle annotations in multiple + * steps, we can't do that. Therefore, in this light, we can + * think of an attacher as being essentially a return + * continuation. + * + * We also have ways to "build" more complex attachers out of + * simple ones, such as classifyingAttacher. This allows us + * considerable flexibility in how we deal with annotations at the + * end of the pipeline (which is necessary, because there are a + * lot of cases). + */ + public interface AttributeAttacher { + public void attach(List attrs); + } + + /** + * An interface for describing error reporting behaviors for + * type-only annotations. Sometimes, we need to report errors if + * any annotations wind up being type-only annotations (the best + * example being for illegal scoping). But at the point where we + * know this, we don't always know if a given annotation will be a + * type-only annotation, a regular annotation, or both. So we + * have to defer the error-reporting until we do know. + */ + public interface Reporter { + public void report(List attrs); + } + + public enum AnnotationKind { DECLARATION, TYPE, BOTH } + + public Attribute[] getTargetTypes(Attribute.Compound a) { + Attribute.Compound atTarget = + a.type.tsym.attribute(syms.annotationTargetType.tsym); + if (atTarget == null) { + return null; + } + Attribute atValue = atTarget.member(names.value); + Assert.check(atValue instanceof Attribute.Array); + return ((Attribute.Array) atValue).values; + } + + public boolean hasTypeUseTarget(Attribute.Compound a, + boolean isTypeParameter) { + Attribute[] targets = getTargetTypes(a); + if (targets != null) { + for (Attribute app : targets) { + Assert.check(app instanceof Attribute.Enum); + Attribute.Enum e = (Attribute.Enum) app; + if (e.value.name == names.TYPE_USE || + (isTypeParameter && e.value.name == names.TYPE_PARAMETER)) { + return true; + } + } + } + return false; + } + + /** + * Determine whether an annotation is a declaration annotation, + * a type annotation, or both. + */ + public AnnotationKind annotationKind(Attribute.Compound a, Symbol s) { + Attribute[] targets = getTargetTypes(a); + if (targets == null) { + return AnnotationKind.DECLARATION; + } + boolean isDecl = false, isType = false; + for (Attribute app : targets) { + Assert.check(app instanceof Attribute.Enum); + Attribute.Enum e = (Attribute.Enum) app; + if (e.value.name == names.TYPE) { + if (s.kind == Kinds.TYP) { + ElementKind skind = s.getKind(); + // The only symbols we should see here correspond + // to definitions. + Assert.check(skind == ElementKind.ANNOTATION_TYPE || + skind == ElementKind.INTERFACE || + skind == ElementKind.ENUM || + skind == ElementKind.CLASS); + isDecl = true; + } + } else if (e.value.name == names.FIELD) { + if (s.kind == Kinds.VAR && + s.owner.kind != Kinds.MTH) + isDecl = true; + } else if (e.value.name == names.METHOD) { + if (s.kind == Kinds.MTH && + !s.isConstructor()) + isDecl = true; + } else if (e.value.name == names.PARAMETER) { + if (s.kind == Kinds.VAR && + s.owner.kind == Kinds.MTH && + (s.flags() & Flags.PARAMETER) != 0) + isDecl = true; + } else if (e.value.name == names.CONSTRUCTOR) { + if (s.kind == Kinds.MTH && + s.isConstructor()) + isDecl = true; + } else if (e.value.name == names.LOCAL_VARIABLE) { + if (s.kind == Kinds.VAR && + s.owner.kind == Kinds.MTH && + (s.flags() & Flags.PARAMETER) == 0) + isDecl = true; + } else if (e.value.name == names.ANNOTATION_TYPE) { + if (s.kind == Kinds.TYP && + (s.flags() & Flags.ANNOTATION) != 0) + isDecl = true; + } else if (e.value.name == names.PACKAGE) { + if (s.kind == Kinds.PCK) + isDecl = true; + } else if (e.value.name == names.TYPE_USE) { + if (s.kind == Kinds.TYP || + s.kind == Kinds.VAR || + (s.kind == Kinds.MTH && !s.isConstructor() && + !s.type.getReturnType().hasTag(TypeTag.VOID)) || + (s.kind == Kinds.MTH && s.isConstructor())) + isType = true; + } else if (e.value.name == names.TYPE_PARAMETER) { + /* Irrelevant in this case: we will never see symbols + * that are type parameters, as we never attach + * declaration annotations to them. */ + Assert.check(s.getKind() != ElementKind.TYPE_PARAMETER); + } else { + Assert.error("annotationKind(): unrecognized Attribute name " + e.value.name + + " (" + e.value.name.getClass() + ")"); + } + } + if (isDecl && isType) { + return AnnotationKind.BOTH; + } else if (isType) { + return AnnotationKind.TYPE; } else { - attacher.attach(sym, attrs); + return AnnotationKind.DECLARATION; } } - private interface AttributeAttacher { - public void attach(Symbol sym, List attrs); - } - - private final AttributeAttacher declAnnotationsAttacher = - new AttributeAttacher() { + /** + * An attacher that just attaches annotations as declaration + * annotations. This is used in places where we know for a fact + * that type annotations cannot occur. + */ + private AttributeAttacher + declAnnotationsAttacher(final Symbol sym) { + return new AttributeAttacher() { @Override - public void attach(Symbol sym, List attrs) { + public String toString() { + return "Attacher for strictly declaration annotations, for " + + sym; + } + + @Override + public void attach(List attrs) { sym.resetAnnotations(); sym.setDeclarationAttributes(attrs); } }; + } - private final AttributeAttacher typeAnnotationsAttacher = - new AttributeAttacher() { + /** + * An attacher that just attaches annotations as type annotations. + * We use this in places where only type annotations can occur. + * The most common use for this is any annotation where we have to + * "parse" a type (arrays, inner classes, type arguments, bounds, + * etc.). We also use this for base types for non-declarations + * (ie. casts, instanceofs, etc). A more subtle case is for + * anonymous classes and receiver parameters, both of which cannot + * have regular annotations. + */ + private AttributeAttacher + typeAnnotationsAttacher(final Symbol sym) { + return new AttributeAttacher() { @Override - public void attach(Symbol sym, List attrs) { - sym.appendUniqueTypeAttributes(attrs); + public String toString() { + return "Attacher for strictly type annotations, for " + sym; + } + + @Override + public void attach(List attrs) { + if (!attrs.isEmpty()) { + attachTypeAnnotations(sym, attrs); + } } }; + } + /** + * Attach type-only annotations using an attacher, and run a + * reporter. Either the reporter or the attacher may be null, in + * which case we skip that step. + */ + private AttributeAttacher + reportingTypeAnnotationsAttacher(final AttributeAttacher attacher, + final Reporter reporter) { + return new AttributeAttacher() { + @Override + public String toString() { + return "Error-reporting type annotation, attacher is: " + attacher + + "\n reporter is: " + reporter; + } + + @Override + public void attach(List attrs) { + if (attacher != null) + attacher.attach(attrs); + + if (reporter != null) + reporter.report(attrs); + } + }; + } + + /** + * Attach type-only annotations to a symbol and also update the + * .type field on a tree (unless it is a package type). This is + * used to put annotations on to a type as well as a symbol. + */ + private AttributeAttacher + typeUpdatingTypeAnnotationsAttacher(final AttributeAttacher attacher, + final JCTree tree) { + return new AttributeAttacher() { + @Override + public String toString() { + return "Type-updating type annotation attacher, attacher is: " + attacher + + "\n tree is: " + tree; + } + + @Override + public void attach(List attrs) { + if (null != attacher) + attacher.attach(attrs); + + if (!attrs.isEmpty() && !tree.type.hasTag(TypeTag.PACKAGE)) { + tree.type = tree.type.annotatedType(attrs); + } + } + }; + } + + /** + * A Reporter for illegal scoping. We set one of these up in + * TypeAnnotate whenever we are in a place that corresponds to a + * package or static class that cannot be annotated. + */ + private void reportIllegalScoping(List attrs, + int pos) { + switch (attrs.size()) { + case 0: + // Don't issue an error if all type annotations are + // also declaration annotations. + // If the annotations are also declaration annotations, they are + // illegal as type annotations but might be legal as declaration annotations. + // The normal declaration annotation checks make sure that the use is valid. + break; + case 1: + log.error(pos, "cant.type.annotate.scoping.1", attrs); + break; + default: + log.error(pos, "cant.type.annotate.scoping", attrs); + } + } + + private Reporter + illegalScopingReporter(final int pos) { + return new Reporter() { + @Override + public String toString() { + return "Illegal scoping reporter at position " + pos; + } + + @Override + public void report(List attrs) { + reportIllegalScoping(attrs, pos); + } + }; + } + + // Create the "simple case": just attach type and regular + // annotations, no reporting. + private AttributeAttacher + classifyingAttacher(final Symbol sym) { + return classifyingAttacher(sym, declAnnotationsAttacher(sym), + typeAnnotationsAttacher(sym), + null); + } + + + /** + * Build an attacher for handling the case where we have + * annotations, but we don't know for sure whether they are + * declaration annotations, type annotations, or both. + * + * We do this by taking an attacher for declaration annotations, + * another one for type annotations, and (possibly) a reporter for + * type-only annotations. We then use the logic from + * annotationKind to figure out what kind each annotation is and + * deal with it accordingly. + * + * Any of the declAttacher, the typeAttacher, or the Reporter can + * be null, in which case we skip it. + * + * We have to have the reporter *separate* from the type + * annotation attacher, because we might be attaching type + * annotations that are also declaration annotations. But the + * semantics of reporters are that they get called for type-only + * annotations. For an example of where this matters, consider + * "@A java.lang.Object foo;", where @A can annotate packages and + * type uses. We would create the classifyingAttacher with null + * for the type attacher and an illegal scoping reporter. Both + * attachers would end up getting called on @A (which, we'd skip + * the type attacher, because it's null), the result being that @A + * goes on foo as a declaration annotation. The reporter would + * not get called, because there are no type-only annotations. + * However, if @A can only annotate type uses, then it's a + * type-only annotation, and we report an illegal scoping error. + * + * Note: there is a case where we want both attachers to be null: + * speculative attribution. + * + * @param sym The symbol to which to attach annotations. + * @param declAttacher The attacher to use for declaration (and + * both) annotations, or null. + * @param typeAttacher The attacher to use for type (and both) + * annotations, or null. + * @param reporter The reporter to use for type-only annotations, or null. + * @return The created attacher. + */ + private AttributeAttacher + classifyingAttacher(final Symbol sym, + final AttributeAttacher declAttacher, + final AttributeAttacher typeAttacher, + final Reporter reporter) { + return new AttributeAttacher() { + @Override + public String toString() { + return "Classifying attacher, attaching to " + sym + + "\n declaration annotation attacher is: " + declAttacher + + "\n type annotation attacher is: " + typeAttacher + + "\n reporter for strictly type annotations is: " + reporter; + } + + @Override + public void attach(List attrs) { + // We sort annotations into "buckets" based on what + // kind they are. + ListBuffer declAnnos = new ListBuffer<>(); + ListBuffer typeAnnos = new ListBuffer<>(); + // We also need to keep track of the type-only + // annotations, in case we have a reporting action. + ListBuffer onlyTypeAnnos = new ListBuffer<>(); + + for (Attribute.Compound a : attrs) { + Assert.check(!(a instanceof Placeholder), + "Placeholders found in annotations being attached!"); + switch (annotationKind(a, sym)) { + case DECLARATION: + declAnnos.append(a); + break; + case BOTH: { + declAnnos.append(a); + Attribute.TypeCompound ta = a.toTypeCompound(); + Assert.checkNonNull(ta.position); + typeAnnos.append(ta); + break; + } + case TYPE: { + Attribute.TypeCompound ta = a.toTypeCompound(); + Assert.checkNonNull(ta.position); + typeAnnos.append(ta); + // Also keep track which annotations are only type annotations + onlyTypeAnnos.append(ta); + break; + } + default: + throw new AssertionError("Unknown annotation type"); + } + } + + if (declAttacher != null) + declAttacher.attach(declAnnos.toList()); + + if (typeAttacher != null) + typeAttacher.attach(typeAnnos.toList()); + + if (reporter != null) + reporter.report(onlyTypeAnnos.toList()); + } + }; + } + + /** + * Actually attach a list of type annotations to a symbol. For + * variables defined in methods, we need to attach to both the + * variable symbol, as well as the method symbol. This takes care + * of that. + * + * @param sym The symbol to which to attach. + * @param attrs The annotations to attach. + */ + public void attachTypeAnnotations(Symbol sym, List attrs) { + sym.appendUniqueTypeAttributes(attrs); + + // For type annotations on variables in methods, make + // sure they are attached to the owner too. + switch(sym.getKind()) { + case PARAMETER: + case LOCAL_VARIABLE: + case RESOURCE_VARIABLE: + case EXCEPTION_PARAMETER: + // Make sure all type annotations from the symbol are also + // on the owner. + sym.owner.appendUniqueTypeAttributes(attrs); + break; + } + } + + /** + * Final task for repeating annotations: go through a list of + * Attributes and replace all the placeholders with containers. + * + * @param buf The list of Attributes. + * @param ctx The AnnotationContext. + * @param sym The symbol to which we are attaching. + * @return The list of attributes with all placeholders replaced. + */ private List replacePlaceholders(List buf, Annotate.AnnotationContext ctx, @@ -848,13 +1442,16 @@ public class Annotate { return result.reverse(); } + /** + * Replace one placeholder with a container. + */ private T replaceOne(Placeholder placeholder, Annotate.AnnotationContext ctx, Symbol sym) { // Process repeated annotations T validRepeated = processRepeatedAnnotations(placeholder.getPlaceholderFor(), - ctx, sym); + ctx, sym, placeholder.position); if (validRepeated != null) { // Check that the container isn't manually @@ -875,16 +1472,65 @@ public class Annotate { * Annotation processing *********************************************************************/ - /** Queue annotations for later processing. */ + /** + * Run a list of annotations through the repeating annotations + * pipeline, and attach them. We don't have any diagnostic + * position. + */ + void annotateLater(final List annotations, + final Env localEnv, + final Symbol s) { + annotateLater(annotations, localEnv, s, null); + } + + /** + * Run a list of annotations through the repeating annotations + * pipeline and attach them. This is for when we have annotations + * that cannot possibly be type annotations (thus, we have no type + * annotation position). + */ void annotateLater(final List annotations, final Env localEnv, final Symbol s, final DiagnosticPosition deferPos) { + // Only attach declaration annotations. + doAnnotateLater(annotations, localEnv, s, deferPos, null, + declAnnotationsAttacher(s)); + } + + /** + * Run a list of annotations through the repeating annotation + * pipeline, and then classify and attach them. This is used + * whenever we have annotations that might be regular annotations, + * type annotations, or both. + */ + void annotateWithClassifyLater(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition tapos) { + // Set up just the basic classifying attacher. + doAnnotateLater(annotations, localEnv, s, deferPos, tapos, + classifyingAttacher(s)); + } + + /** + * Set up a worker for handling annotations without parsing a type tree. + */ + private void doAnnotateLater(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition tapos, + final AttributeAttacher attacher) { if (annotations.isEmpty()) { return; } + // Mark annotations as incomplete for now. + // + // This should probably get redesigned at some point. if (s.kind != PCK) { - s.resetAnnotations(); // mark Annotations as incomplete for now + s.resetAnnotations(); } normal(new Annotate.Worker() { @Override @@ -894,12 +1540,44 @@ public class Annotate { @Override public void run() { + annotateNow(annotations, localEnv, s, deferPos, + tapos, attacher); + } + }); + + validate(annotationValidator(annotations, localEnv, s)); + } + + /** + * Run a list of declaration (meaning they are in a declaration + * position) annotations through the repeating annotations + * pipeline. + * + * Note that in some cases, these annotations might end up being + * type annotations, or both declaration and type annotations. + * + * @param annotations The annotations to handle. + * @param localEnv the environment. + * @param s The symbol to which to attach. + * @param deferPos The diagnostic position to use. + * @param position The type annotation position to use if some of + * the annotations end up being type annotations. + * @param attacher The attacher to use. + */ + private void annotateNow(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition position, + final AttributeAttacher attacher) { + if (annotations.isEmpty()) { + return; + } Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); - DiagnosticPosition prevLintPos = - deferPos != null - ? deferredLintHandler.setPos(deferPos) - : deferredLintHandler.immediate(); + DiagnosticPosition prevLintPos = deferPos != null ? + deferredLintHandler.setPos(deferPos) : + deferredLintHandler.immediate(); Lint prevLint = deferPos != null ? null : chk.setLint(lint); try { if (s.hasAnnotations() && @@ -907,7 +1585,7 @@ public class Annotate { log.error(annotations.head.pos, "already.annotated", kindName(s), s); - actualEnterAnnotations(annotations, localEnv, s); + actualEnterAnnotations(annotations, localEnv, s, position, attacher); } finally { if (prevLint != null) chk.setLint(prevLint); @@ -915,9 +1593,12 @@ public class Annotate { log.useSource(prev); } } - }); - validate(new Annotate.Worker() { //validate annotations + // Set up a validator to enforce some rules on regular annotations. + private Annotate.Worker annotationValidator(final List annotations, + final Env localEnv, + final Symbol s) { + return new Annotate.Worker() { //validate annotations @Override public void run() { JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); @@ -927,52 +1608,140 @@ public class Annotate { log.useSource(prev); } } - }); + }; } + private void checkForDeclarationAnnotations(List annotations, + boolean isTypeParameter) { + // Ensure that no declaration annotations are present. + // Note that a tree type might be an AnnotatedType with + // empty annotations, if only declaration annotations were given. + // This method will raise an error for such a type. + for (JCAnnotation ai : annotations) { + Assert.checkNonNull(ai.type); + Assert.checkNonNull(ai.attribute); + + if (!ai.type.isErroneous() && + !hasTypeUseTarget(ai.attribute, isTypeParameter)) { + log.error(ai.pos(), "annotation.type.not.applicable"); + } + } + } + + // Set up a validator to enforce some rules on type annotations. + // In addition to those enforced by Check.validateTypeAnnotations, + // this enforces that declaration annotations cannot occur on type + // parameters. + private Annotate.Worker typeAnnotationValidator(final List annotations, + final Env localEnv, + final boolean isTypeParameter) { + return new Annotate.Worker() { //validate annotations + @Override + public void run() { + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + try { + checkForDeclarationAnnotations(annotations, isTypeParameter); + chk.validateTypeAnnotations(annotations, isTypeParameter); + } finally { + log.useSource(prev); + } + } + }; + } + + /** + * This is an interface that wraps up the functionality of + * enterAnnotations and enterTypeAnnotations. This allows some + * code duplication to be removed from the original repeating + * annotations pipeline. It also allows for some unsafe casts to + * be eliminated. + * + * Note: when Lambdas can be used in the compiler, we can just use + * method refs for enterAnnotations and enterTypeAnnotations. + */ private interface AttributeCreator { - public T create(JCAnnotation a, Type expected, Env env); + public T create(JCAnnotation a, + Type expected, + Env env, + TypeAnnotationPosition position); + public abstract boolean createsTypeCompound(); } - // TODO: When SE8 features can be used, these can go away and be - // replaced by method refs. + // Note: try to avoid doing anything that makes these any more + // than just the equivalent of method refs in a pre-lambda + // setting. That way, they can go away when we are allowed to use + // lambda. private final AttributeCreator enterAnnotationsCreator = new AttributeCreator() { @Override + public String toString() { + return "Attribute creator for regular declaration annotations"; + } + + @Override public Attribute.Compound create(JCAnnotation a, Type expected, - Env env) { - return enterAnnotation(a, syms.annotationType, env); + Env env, + TypeAnnotationPosition position) { + return enterAnnotation(a, syms.annotationType, env, position); } + + @Override + public boolean createsTypeCompound() { return false; } }; - private final AttributeCreator enterTypeAnnotationsCreator = - new AttributeCreator() { + + private AttributeCreator + enterTypeAnnotationsCreator(final boolean secondaryAttr) { + return new AttributeCreator() { + @Override + public String toString() { + if (!secondaryAttr) { + return "Attribute creator for regular type annotations"; + } else { + return "Attribute creator for regular type annotations, ignores cached attributes"; + } + } + @Override public Attribute.TypeCompound create(JCAnnotation a, Type expected, - Env env) { - return enterTypeAnnotation(a, syms.annotationType, env); + Env env, + TypeAnnotationPosition position) { + return enterTypeAnnotation(a, syms.annotationType, + env, position, secondaryAttr); } - }; - /** Enter a set of annotations. */ - private void actualEnterAnnotations(List annotations, - Env env, - Symbol s) { - Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); - attachAttributesLater(annotations, env, s, false, - enterAnnotationsCreator, - declAnnotationsAttacher); + @Override + public boolean createsTypeCompound() { return true; } + }; } - /* - * If the symbol is non-null, attach the type annotation to it. + /** + * Send a list of annotations (which occurred in a declaration + * position) into the repeating annotations pipeline. + */ + private void actualEnterAnnotations(List annotations, + Env env, + Symbol s, + TypeAnnotationPosition position, + AttributeAttacher attacher) { + Assert.checkNonNull(s); + attachAttributesLater(annotations, env, s, position, + enterAnnotationsCreator, attacher); + } + + /** + * Send a list of annotations (which occurred in a type-use + * position) into the repeating annotations pipeline. */ private void actualEnterTypeAnnotations(final List annotations, final Env env, final Symbol s, - final DiagnosticPosition deferPos) { - Assert.checkNonNull(s, "Symbol argument to actualEnterTypeAnnotations is nul/"); + final DiagnosticPosition deferPos, + final boolean secondaryAttr, + final TypeAnnotationPosition position, + final AttributeAttacher attacher) { + Assert.checkNonNull(s); JavaFileObject prev = log.useSource(env.toplevel.sourcefile); DiagnosticPosition prevLintPos = null; @@ -980,9 +1749,9 @@ public class Annotate { prevLintPos = deferredLintHandler.setPos(deferPos); } try { - attachAttributesLater(annotations, env, s, true, - enterTypeAnnotationsCreator, - typeAnnotationsAttacher); + attachAttributesLater(annotations, env, s, position, + enterTypeAnnotationsCreator(secondaryAttr), + attacher); } finally { if (prevLintPos != null) deferredLintHandler.setPos(prevLintPos); @@ -990,11 +1759,114 @@ public class Annotate { } } + /** + * Given a type tree, walk down it and handle any annotations we + * find. + * + * @param tree The type tree to scan. + * @param env The environment. + * @param sym The symbol to which to attach any annotations we + * might find. + * @param deferPos The diagnostic position to use. + * @param creator The creator to use for making positions. + */ public void annotateTypeLater(final JCTree tree, final Env env, final Symbol sym, - final DiagnosticPosition deferPos) { + final DiagnosticPosition deferPos, + final PositionCreator creator) { + doAnnotateTypeLater(tree, List.nil(), env, + sym, deferPos, creator, false, false); + } + + /** + * Given a type tree, walk down it and handle any annotations we + * find. We also have a set of base-type annotations (which + * occurred in a declaration position in source), which may either + * be declaration annotations or annotations on the base type. + * For an example, in "@A int @B []", we would have the type tree + * "int @B []" with base-type annotations "@A". + * + * @param tree The type tree to scan. + * @param baseTypeAnnos The base-type annotations. + * @param env The environment. + * @param sym The symbol to which to attach any annotations we + * might find. + * @param deferPos The diagnostic position to use. + * @param creator The creator to use for making positions. + */ + public void annotateTypeLater(final JCTree tree, + final List baseTypeAnnos, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final PositionCreator creator) { + doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos, + creator, false, false); + } + + /** + * Given a type tree, walk down it and handle any annotations we + * find. We also have a set of base-type annotations (which + * occurred in a declaration position in source), which must be + * type annotations on the base type. + * + * @param tree The type tree to scan. + * @param baseTypeAnnos The base-type annotations. + * @param env The environment. + * @param sym The symbol to which to attach any annotations we + * might find. + * @param deferPos The diagnostic position to use. + * @param creator The creator to use for making positions. + */ + public void annotateStrictTypeLater(final JCTree tree, + final List baseTypeAnnos, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final PositionCreator creator) { + doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos, + creator, true, false); + } + + /** + * Given a type tree representing an anonymous class' supertype, + * walk down it and handle any annotations we find. We also have + * a set of base-type annotations (which occurred in a declaration + * position in source), which must be type annotations on the base + * type. + * + * @param tree The type tree to scan. + * @param baseTypeAnnos The base-type annotations. + * @param env The environment. + * @param sym The symbol to which to attach any annotations we + * might find. + * @param deferPos The diagnostic position to use. + * @param creator The creator to use for making positions. + */ + public void annotateAnonClassDefLater(final JCTree tree, + final List baseTypeAnnos, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final PositionCreator creator) { + doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos, + creator, true, true); + } + + // The combined worker function for the annotateTypeLater family. + public void doAnnotateTypeLater(final JCTree tree, + final List baseTypeAnnos, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final PositionCreator creator, + final boolean onlyTypeAnnos, + final boolean secondaryAttr) { Assert.checkNonNull(sym); + Assert.checkNonNull(baseTypeAnnos); + Assert.checkNonNull(creator); + normal(new Annotate.Worker() { @Override public String toString() { @@ -1002,93 +1874,912 @@ public class Annotate { } @Override public void run() { - tree.accept(new TypeAnnotate(env, sym, deferPos)); + if (!baseTypeAnnos.isEmpty()) { + sym.resetAnnotations(); // mark Annotations as incomplete for now + } + + tree.accept(typeAnnotator(baseTypeAnnos, sym, env, deferPos, + creator, onlyTypeAnnos, + secondaryAttr)); } }); } /** - * We need to use a TreeScanner, because it is not enough to visit the top-level - * annotations. We also need to visit type arguments, etc. + * A client passed into various visitors that takes a type path as + * an argument and performs an action (typically creating a + * TypeAnnotationPosition and then creating a {@code Worker} and + * adding it to a queue. + */ + public abstract class PositionCreator { + public abstract TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex); + } + + // For when we don't have a creator. Throws an exception. + public final PositionCreator noCreator = + new PositionCreator() { + @Override + public String toString() { + return "Sentinel null position creator"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + throw new AssertionError("No annotation position creator registered"); + } + }; + + // For when we are creating annotations that will inevitably + // trigger errors. Creates null. + public final PositionCreator errorCreator = + new PositionCreator() { + @Override + public String toString() { + return "Position creator for annotations that represent errors"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return null; + } + }; + + // Create class extension positions + public final PositionCreator extendsCreator = + new PositionCreator() { + @Override + public String toString() { + return "Position creator for extends"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.classExtends(path, lambda, -1); + } + }; + + // Create interface implementation positions + public PositionCreator implementsCreator(final int idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for implements, index " + idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.classExtends(path, lambda, idx, -1); + } + }; + } + + // Create method parameter positions + public final PositionCreator paramCreator(final int idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for parameter " + idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodParameter(path, lambda, idx, -1); + } + }; + } + + // Create class type parameter positions + public PositionCreator typeParamCreator(final int idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for class type parameter " + idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.typeParameter(path, lambda, idx, -1); + } + }; + } + + public PositionCreator typeParamBoundCreator(final JCTypeParameter typaram, + final int param_idx, + final int bound_idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for class type parameter " + param_idx + + ", bound " + bound_idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + final int real_bound_idx = + typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx; + return TypeAnnotationPosition + .typeParameterBound(path, lambda, param_idx, real_bound_idx, -1); + } + }; + } + + // Create field positions + public final PositionCreator fieldCreator = + new PositionCreator() { + @Override + public String toString() { + return "Position creator for field declaration"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.field(path, lambda, -1); + } + }; + + // Create local variable positions + public PositionCreator localVarCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for local variable declaration at " + + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.localVariable(path, lambda, pos); + } + }; + } + + // Create resource variable positions. + public PositionCreator resourceVarCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for resource variable declaration at " + + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.resourceVariable(path, lambda, pos); + } + }; + } + + // Create exception parameter positions. + public PositionCreator exceptionParamCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for exception param declaration at " + + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.exceptionParameter(path, lambda, + typeIndex, pos); + } + }; + } + + // Create constructor reference type argument positions. + public PositionCreator constructorRefTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for constructor reference type argument " + idx + + " at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition + .constructorRefTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator methodInvokeTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for method invoke type argument " + idx + + " at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodInvocationTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator methodTypeParamCreator(final int idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for method type parameter " + idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodTypeParameter(path, lambda, idx, -1); + } + }; + } + + public PositionCreator methodTypeParamBoundCreator(final JCTypeParameter typaram, + final int param_idx, + final int bound_idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for method type parameter " + param_idx + + " bound " + bound_idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + final int real_bound_idx = + typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx; + return TypeAnnotationPosition + .methodTypeParameterBound(path, lambda, param_idx, real_bound_idx, -1); + } + }; + } + + public PositionCreator throwCreator(final int idx) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for throw, type index " + idx; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodThrows(path, lambda, idx, -1); + } + }; + } + + public final PositionCreator returnCreator = + new PositionCreator() { + @Override + public String toString() { + return "Position creator for method return type"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodReturn(path, lambda, -1); + } + }; + + public PositionCreator receiverCreator = + new PositionCreator() { + @Override + public String toString() { + return "Position creator for method receiver parameter type"; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodReceiver(path, lambda, -1); + } + }; + + public PositionCreator methodRefCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for method reference at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodRef(path, lambda, pos); + } + }; + } + + public PositionCreator methodRefTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for method reference type argument " + idx + + " at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodRefTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator constructorRefCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for constructor reference at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.constructorRef(path, lambda, pos); + } + }; + } + + public PositionCreator constructorInvokeTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for constructor invoke type argument " + idx + + " at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.constructorInvocationTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator instanceOfCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for instanceof at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.instanceOf(path, lambda, pos); + } + }; + } + + public PositionCreator newObjCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for new at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.newObj(path, lambda, pos); + } + }; + } + + public PositionCreator castCreator(final int pos) { + return new PositionCreator() { + @Override + public String toString() { + return "Position creator for cast at " + pos; + } + + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.typeCast(path, lambda, typeIndex, pos); + } + }; + } + + public static List makeInners(Type type) { + return addInners(type, List.nil()); + } + + private static List addInners(Type type, + List typepath) { + Type encl = type.getEnclosingType(); + while (encl != null && encl.getKind() != TypeKind.NONE && + encl.getKind() != TypeKind.ERROR) { + typepath = typepath.append(TypePathEntry.INNER_TYPE); + encl = encl.getEnclosingType(); + } + return typepath; + } + + /** + * Set up the visitor to scan the type tree and handle any + * annotations we find. If we are in speculative attribution, we + * will not actually attach anything, we will just enter the + * annotations and run them through the pipeline to pick up any + * errors that might occur. + * + * @param baseTypeAnnos Annotations on the base type, which need + * to be classified if onlyTypeAnnos is false. + * @param sym The symbol to which to attach. + * @param env The environment. + * @param creator The position creator to use. + * @param onlyTypeAnnos Whether or not baseTypeAnnos can represent + * declaration annotations. + * @param secondaryAttr Whether or not we are creating secondary + * attributes (see enterTypeAnnotations). + */ + public TypeAnnotate typeAnnotator(final List baseTypeAnnos, + final Symbol sym, + final Env env, + final DiagnosticPosition deferPos, + final PositionCreator creator, + final boolean onlyTypeAnnos, + final boolean secondaryAttr) { + if (!env.info.isSpeculative) { + return new TypeAnnotate(baseTypeAnnos, sym, env, deferPos, creator, + declAnnotationsAttacher(sym), + typeAnnotationsAttacher(sym), + onlyTypeAnnos, secondaryAttr); + } else { + return new TypeAnnotate(baseTypeAnnos, sym, env, deferPos, creator, + null, null, onlyTypeAnnos, secondaryAttr); + } + } + + /** + * A visitor that scans a type tree and handles an annotations it finds. + * */ private class TypeAnnotate extends TreeScanner { - private final Env env; + // The creator we use to create positions. + protected PositionCreator creator; + // The current type path + private List typepath = List.nil(); + // The current innermost lambda + private JCLambda currentLambda; + // The current type index, if we are looking at an + // intersection type. + private int type_index = 0; + // Whether or not we are looking at the innermost type. This + // gets used to figure out where to attach base type + // annotations. + private boolean innermost; + // The attachers and reporter we use. + private AttributeAttacher declAttacher; + private AttributeAttacher typeAttacher; + private Reporter reporter; + // The symbol to which we are attaching. private final Symbol sym; - private DiagnosticPosition deferPos; + // The diagnostic position we use. + private final DiagnosticPosition deferPos; + // The environment + private final Env env; + private final List baseTypeAnnos; + // Whether or not baseTypeAnnos can be declaration + // annotations, or just strictly type annotations. + private final boolean onlyTypeAnnos; + // Whether or not we are creating secondary attributes (see + // enterTypeAnnotations). + private final boolean secondaryAttr; - public TypeAnnotate(final Env env, + public TypeAnnotate(final List baseTypeAnnos, final Symbol sym, - final DiagnosticPosition deferPos) { - - this.env = env; + final Env env, + final DiagnosticPosition deferPos, + final PositionCreator creator, + final AttributeAttacher declAttacher, + final AttributeAttacher typeAttacher, + final boolean onlyTypeAnnos, + final boolean secondaryAttr) { + this.baseTypeAnnos = baseTypeAnnos; this.sym = sym; + this.env = env; this.deferPos = deferPos; + this.currentLambda = env.getLambda(); + this.creator = creator; + this.innermost = true; + this.declAttacher = declAttacher; + this.typeAttacher = typeAttacher; + this.reporter = null; + this.onlyTypeAnnos = onlyTypeAnnos; + this.secondaryAttr = secondaryAttr; + } + + // Deal with the base-type annotations. This should only get + // called when we are at the inner-most type. + private void doBaseTypeAnnos() { + if (onlyTypeAnnos) { + // If the base type annotations can only be type + // annotations, then handle them as such. + doTypeAnnos(baseTypeAnnos, false); + } else if (!baseTypeAnnos.isEmpty()) { + // Otherwise, send them into the repeating annotations + // pipeline with a classifying attacher we build based + // on the current state. + final TypeAnnotationPosition tapos = + creator.create(typepath, currentLambda, type_index); + annotateNow(baseTypeAnnos, env, sym, deferPos, tapos, + classifyingAttacher(sym, declAttacher, + typeAttacher, reporter)); + // Also set up a validator. + validate(annotationValidator(baseTypeAnnos, env, sym)); + } + } + + // Deal with type annotations we found while scanning the tree. + private void doTypeAnnos(List annos, + boolean isTypeParameter) { + if (!annos.isEmpty()) { + // Grab the reporter and the type attacher (which, + // it's ok for either to be null), and combine them + // into a reporting attacher. + final AttributeAttacher attacher = + reportingTypeAnnotationsAttacher(typeAttacher, reporter); + // Create the position using the current type path and + // type index. + final TypeAnnotationPosition tapos = + creator.create(typepath, currentLambda, type_index); + // Send the annotations into the repeating annotations + // pipeline, and set up a validator. + actualEnterTypeAnnotations(annos, env, sym, deferPos, secondaryAttr, + tapos, attacher); + validate(typeAnnotationValidator(annos, env, isTypeParameter)); + } } @Override - public void visitAnnotatedType(final JCAnnotatedType tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - super.visitAnnotatedType(tree); + public void visitTypeIdent(final JCPrimitiveTypeTree tree) { + // This is one place that can represent the base type. + // But we need to make sure we're actually in the + // innermost type (ie not a type argument or something). + if (innermost) { + final AttributeAttacher oldTypeAttacher = typeAttacher; + // We want to update the Type to have annotations. + typeAttacher = typeUpdatingTypeAnnotationsAttacher(oldTypeAttacher, + tree); + // We can't possibly have any INNER_TYPE type path + // elements, because these are all primitives. + doBaseTypeAnnos(); + typeAttacher = oldTypeAttacher; + } } @Override - public void visitTypeParameter(final JCTypeParameter tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - super.visitTypeParameter(tree); + public void visitIdent(final JCIdent tree) { + // This is one place that can represent the base type. + // But we need to make sure we're actually in the + // innermost type (ie not a type argument or something). + if (innermost) { + final AttributeAttacher oldTypeAttacher = typeAttacher; + // Set up an attacher that updates the Type, so we get + // the annotations. + typeAttacher = typeUpdatingTypeAnnotationsAttacher(oldTypeAttacher, + tree); + // Add any INNER_TYPE type path elements we might need. + if (tree.type != null) { + final List oldpath = typepath; + typepath = addInners(tree.type, typepath); + doBaseTypeAnnos(); + typepath = oldpath; + } else { + doBaseTypeAnnos(); + } + typeAttacher = oldTypeAttacher; + } } @Override - public void visitNewArray(final JCNewArray tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - for (List dimAnnos : tree.dimAnnotations) - actualEnterTypeAnnotations(dimAnnos, env, sym, deferPos); - super.visitNewArray(tree); + public void visitAnnotatedType(JCAnnotatedType tree) { + // This is one place where we run into pure type + // annotations. + Assert.checkNonNull(tree.getUnderlyingType().type); + final boolean oldinnermost = innermost; + // Make sure we don't consider ourselves "innermost" when + // scanning the annotations. + innermost = false; + scan(tree.annotations); + innermost = oldinnermost; + scan(tree.underlyingType); + final List oldpath = typepath; + typepath = addInners(tree.getUnderlyingType().type, typepath); + doTypeAnnos(tree.annotations, false); + typepath = oldpath; } @Override - public void visitMethodDef(final JCMethodDecl tree) { - scan(tree.mods); - scan(tree.restype); - scan(tree.typarams); - scan(tree.recvparam); + public void visitTypeArray(JCArrayTypeTree tree) { + // This case is simple: just add an ARRAY to the type path. + final List oldpath = typepath; + typepath = typepath.append(TypePathEntry.ARRAY); + super.visitTypeArray(tree); + typepath = oldpath; + } + + @Override + public void visitTypeApply(JCTypeApply tree) { + // Handle type arguments + Assert.checkNonNull(tree.getType().type); + final List oldpath = typepath; + // First, look at the base type. + scan(tree.clazz); + + // Add any INNER_TYPE path elements we need first + if (tree.getType() != null && tree.getType().type != null) { + typepath = addInners(tree.getType().type, typepath); + } + // Make sure we're not considering ourselves innermost + // when looking at type arguments. + final boolean oldinnermost = innermost; + innermost = false; + // For each type argument, add a TYPE_ARGUMENT path + // element for the right index. + int i = 0; + for (List l = tree.arguments; l.nonEmpty(); + l = l.tail, i++) { + final JCExpression arg = l.head; + final List noargpath = typepath; + typepath = typepath.append(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, i)); + scan(arg); + typepath = noargpath; + } + typepath = oldpath; + innermost = oldinnermost; + } + + @Override + public void visitNewArray(JCNewArray tree) { + // We can also run into type annotations here, on dimAnnos. + final List oldpath = typepath; + final PositionCreator oldcreator = creator; + creator = newObjCreator(tree.pos); + doTypeAnnos(tree.annotations, false); + + // Go through the dimensions, set up the type path, and + // handle any annetations we find. + for (int i = 0; i < tree.dimAnnotations.size(); i++) { + final List dimAnnos = tree.dimAnnotations.get(i); + doTypeAnnos(dimAnnos, false); + // This is right. As per the type annotations spec, + // the first array dimension has no arrays in the type + // path, the second has one, and so on, and the + // element type has n for n dimensions. + typepath = typepath.append(TypePathEntry.ARRAY); + } + + // The element type is sometimes null, in the case of + // array literals. + scan(tree.elemtype); + typepath = oldpath; + creator = oldcreator; + } + + @Override + public void visitWildcard(JCWildcard tree) { + // Simple: add a WILDCARD type path element and continue. + final List oldpath = typepath; + typepath = typepath.append(TypePathEntry.WILDCARD); + super.visitWildcard(tree); + typepath = oldpath; + } + + @Override + public void visitTypeParameter(JCTypeParameter tree) { + // This is another place where we can run into pure type + // annotations. + scan(tree.annotations); + Assert.checkNonNull(tree.type); + doTypeAnnos(tree.annotations, true); + } + + @Override + public void visitLambda(JCLambda tree) { + // If we run into a lambda, set the current lambda to it. + final JCLambda oldLambda = currentLambda; + currentLambda = tree; + scan(tree.body); scan(tree.params); - scan(tree.thrown); - scan(tree.defaultValue); - // Do not annotate the body, just the signature. - // scan(tree.body); + currentLambda = oldLambda; } + @Override + public void visitTypeIntersection(JCTypeIntersection tree) { + final boolean oldinnermost = innermost; + // Run through the options, and update the type_index + // accordingly. + for (List l = tree.bounds; l.nonEmpty(); + l = l.tail, type_index++) { + scan(l.head); + // Set innermost to false after the first element + innermost = false; + } + innermost = oldinnermost; + } + + @Override + public void visitTypeUnion(JCTypeUnion tree) { + final boolean oldinnermost = innermost; + // Run through the options, and update the type_index + // accordingly. + for (List l = tree.alternatives; l.nonEmpty(); + l = l.tail, type_index++) { + scan(l.head); + // Set innermost to false after the first element + innermost = false; + } + innermost = oldinnermost; + } + + @Override + public void visitSelect(JCFieldAccess tree) { + // In this case, we need to possibly set up an + // illegalScopingReporter, if the selected type cannot be + // annotated. + Symbol sym = tree.sym; + final AttributeAttacher oldTypeAttacher = typeAttacher; + final Reporter oldReporter = reporter; + // If we're selecting from an interface or a static class, + // set up attachers that will only attach declaration + // annotations and will report type annotations as errors. + Type selectedTy = tree.selected.type; + if ((sym != null && (sym.isStatic() || sym.isInterface() || + selectedTy.hasTag(TypeTag.PACKAGE))) || + tree.name == names._class) { + typeAttacher = null; + reporter = illegalScopingReporter(tree.pos); + } + super.visitSelect(tree); + typeAttacher = oldTypeAttacher; + reporter = oldReporter; + } + + // These methods stop the visitor from continuing on when it + // sees a definition. @Override public void visitVarDef(final JCVariableDecl tree) { - DiagnosticPosition prevPos = deferPos; - deferPos = tree.pos(); - try { - if (sym != null && sym.kind == Kinds.VAR) { - // Don't visit a parameter once when the sym is the method - // and once when the sym is the parameter. - scan(tree.mods); - scan(tree.vartype); - } - scan(tree.init); - } finally { - deferPos = prevPos; - } } @Override public void visitClassDef(JCClassDecl tree) { - // We can only hit a classdef if it is declared within - // a method. Ignore it - the class will be visited - // separately later. } @Override public void visitNewClass(JCNewClass tree) { - if (tree.def == null) { - // For an anonymous class instantiation the class - // will be visited separately. - super.visitNewClass(tree); + } } + + // A derived TypeAnnotate visitor that also scans expressions + // within Deferred attribution. + private class TypeAnnotateExpr extends TypeAnnotate { + // This constructor creates an instance suitable for deferred + // attribution. + public TypeAnnotateExpr(final Symbol sym, + final Env env, + final DiagnosticPosition deferPos, + final PositionCreator creator) { + super(List.nil(), sym, env, deferPos, + creator, null, null, false, false); + } + + @Override + public void visitTypeCast(final JCTypeCast tree) { + final PositionCreator oldcreator = creator; + creator = castCreator(tree.pos); + super.visitTypeCast(tree); + creator = oldcreator; + } + + @Override + public void visitTypeTest(JCInstanceOf tree) { + final PositionCreator oldcreator = creator; + creator = instanceOfCreator(tree.pos); + super.visitTypeTest(tree); + creator = oldcreator; + } + + @Override + public void visitReference(JCMemberReference that) { + final boolean isConstructor = that.getName() == names.init; + final PositionCreator oldcreator = creator; + creator = isConstructor ? constructorRefCreator(that.pos) : + methodRefCreator(that.pos); + scan(that.expr); + + if (null != that.typeargs) { + int i = 0; + for (List l = that.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final Annotate.PositionCreator typeArgCreator = + isConstructor ? constructorRefTypeArgCreator(i, that.pos) : + methodRefTypeArgCreator(i, that.pos); + final JCExpression arg = l.head; + scan(that.expr); + } + } + + creator = oldcreator; + } + + @Override + public void visitNewClass(JCNewClass tree) { + // This will be visited by Attr later, so don't do + // anything. + } + } + + /** + * Set up a visitor to scan an expression and handle any type + * annotations it finds, within a deferred attribution context. + */ + public void typeAnnotateExprLater(final JCTree tree, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final PositionCreator creator) { + Assert.checkNonNull(sym); + Assert.checkNonNull(creator); + + normal(new Annotate.Worker() { + @Override + public String toString() { + return "type annotate " + tree + " onto " + sym + " in " + sym.owner; + } + @Override + public void run() { + tree.accept(new TypeAnnotateExpr(sym, env, deferPos, creator)); + } + }); } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index ba72525a70f..ae7b493a6d6 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -91,7 +91,6 @@ public class Attr extends JCTree.Visitor { final Types types; final JCDiagnostic.Factory diags; final Annotate annotate; - final TypeAnnotations typeAnnotations; final DeferredLintHandler deferredLintHandler; public static Attr instance(Context context) { @@ -120,7 +119,6 @@ public class Attr extends JCTree.Visitor { types = Types.instance(context); diags = JCDiagnostic.Factory.instance(context); annotate = Annotate.instance(context); - typeAnnotations = TypeAnnotations.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); Options options = Options.instance(context); @@ -434,8 +432,7 @@ public class Attr extends JCTree.Visitor { public Type attribImportQualifier(JCImport tree, Env env) { // Attribute qualifying package or class. JCFieldAccess s = (JCFieldAccess)tree.qualid; - return attribTree(s.selected, - env, + return attribTree(s.selected, env, new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), Type.noType)); } @@ -638,7 +635,8 @@ public class Attr extends JCTree.Visitor { /** Derived visitor method: attribute an expression tree. */ public Type attribExpr(JCTree tree, Env env, Type pt) { - return attribTree(tree, env, new ResultInfo(VAL, !pt.hasTag(ERROR) ? pt : Type.noType)); + return attribTree(tree, env, + new ResultInfo(VAL, !pt.hasTag(ERROR) ? pt : Type.noType)); } /** Derived visitor method: attribute an expression tree with @@ -650,6 +648,7 @@ public class Attr extends JCTree.Visitor { /** Derived visitor method: attribute a type tree. */ + public Type attribType(JCTree tree, Env env) { Type result = attribType(tree, env, Type.noType); return result; @@ -664,6 +663,7 @@ public class Attr extends JCTree.Visitor { /** Derived visitor method: attribute a statement or definition tree. */ + public Type attribStat(JCTree tree, Env env) { return attribTree(tree, env, statInfo); } @@ -731,7 +731,8 @@ public class Attr extends JCTree.Visitor { a.tsym.flags_field |= UNATTRIBUTED; a.bound = Type.noType; if (!tvar.bounds.isEmpty()) { - List bounds = List.of(attribType(tvar.bounds.head, env)); + List bounds = + List.of(attribType(tvar.bounds.head, env)); for (JCExpression bound : tvar.bounds.tail) bounds = bounds.prepend(attribType(bound, env)); types.setBounds(a, bounds.reverse()); @@ -765,7 +766,7 @@ public class Attr extends JCTree.Visitor { * @param type The expected type, or null * @see VarSymbol#setLazyConstValue */ - public Object attribLazyConstantValue(Env env, + public Object attribLazyConstantValue(final Env env, JCVariableDecl variable, Type type) { @@ -884,6 +885,7 @@ public class Attr extends JCTree.Visitor { c.flags_field |= NOOUTERTHIS; } attribClass(tree.pos(), c); + result = tree.type = c.type; } } @@ -1021,10 +1023,6 @@ public class Attr extends JCTree.Visitor { } } - // Attribute all type annotations in the body - annotate.annotateTypeLater(tree.body, localEnv, m, null); - annotate.flush(); - // Attribute method body. attribStat(tree.body, localEnv); } @@ -1038,21 +1036,67 @@ public class Attr extends JCTree.Visitor { } } - public void visitVarDef(JCVariableDecl tree) { + public Annotate.PositionCreator getVarCreator(final JCVariableDecl tree) { + // Form the enclosing tree node, figure out what kind + // of definition we are looking at. + switch(env.tree.getTag()) { + case TRY: + // If it's a try, then we have a resource variable + return annotate.resourceVarCreator(tree.pos); + case CATCH: + // If it's a catch, then we have an exception parameter + return annotate.exceptionParamCreator(tree.pos); + case LAMBDA: { + // If it's a lambda, then we could have a local + // variable or a parameter. + final JCLambda lambda = (JCLambda) env.tree; + // We have to figure out what the index of the + // parameter is, and unfortunately, the visitor + // and tree APIs don't help us much here. If we + // don't find the declaration in the parameter + // list, then it must be a local variable. + // + // This could easily be replaced by an index + // parameter, which is -1 for non-indexed + // definitions. + int index = -1; + int i = 0; + for (List l = lambda.params; + l.nonEmpty(); l = l.tail, i++) { + if (l.head == tree) { + index = i; + break; + } + } + if (index == -1) { + return annotate.localVarCreator(tree.pos); + } else { + return annotate.paramCreator(index); + } + } + case CASE: + case BLOCK: + case FORLOOP: + case FOREACHLOOP: + case LABELLED: + // These are all cases where we can end up with a + // local variable. + return annotate.localVarCreator(tree.pos); + default: + // Be strict and throw an error if we see + // something we don't expect. + throw new AssertionError("Unexpected enclosing tree for variable definition: " + env.tree.getTag()); + } + } + + public void visitVarDef(final JCVariableDecl tree) { // Local variables have not been entered yet, so we need to do it now: if (env.info.scope.owner.kind == MTH) { if (tree.sym != null) { // parameters have already been entered env.info.scope.enter(tree.sym); } else { - memberEnter.memberEnter(tree, env); - annotate.flush(); - } - } else { - if (tree.init != null) { - // Field initializer expression need to be entered. - annotate.annotateTypeLater(tree.init, env, tree.sym, tree.pos()); - annotate.flush(); + memberEnter.memberEnter(tree, env, getVarCreator(tree)); } } @@ -1103,17 +1147,15 @@ public class Attr extends JCTree.Visitor { // Block is a static or instance initializer; // let the owner of the environment be a freshly // created BLOCK-method. - Env localEnv = + final Env localEnv = env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); localEnv.info.scope.owner = new MethodSymbol(tree.flags | BLOCK | env.info.scope.owner.flags() & STRICTFP, names.empty, null, env.info.scope.owner); - if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; - // Attribute all type annotations in the block - annotate.annotateTypeLater(tree, localEnv, localEnv.info.scope.owner, null); - annotate.flush(); + if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; + attribStats(tree.stats, localEnv); { // Store init and clinit type annotations with the ClassSymbol @@ -1126,8 +1168,6 @@ public class Attr extends JCTree.Visitor { cs.appendInitTypeAttributes(tas); } } - - attribStats(tree.stats, localEnv); } else { // Create a new local environment with a local scope. Env localEnv = @@ -1481,17 +1521,21 @@ public class Attr extends JCTree.Visitor { isBooleanOrNumeric(env, condTree.falsepart); case APPLY: JCMethodInvocation speculativeMethodTree = - (JCMethodInvocation)deferredAttr.attribSpeculative(tree, env, unknownExprInfo); + (JCMethodInvocation)deferredAttr.attribSpeculative(tree, env, unknownExprInfo, + annotate.noCreator); Type owntype = TreeInfo.symbol(speculativeMethodTree.meth).type.getReturnType(); return types.unboxedTypeOrType(owntype).isPrimitive(); case NEWCLASS: JCExpression className = removeClassParams.translate(((JCNewClass)tree).clazz); JCExpression speculativeNewClassTree = - (JCExpression)deferredAttr.attribSpeculative(className, env, unknownTypeInfo); + (JCExpression)deferredAttr.attribSpeculative(className, + env, + unknownTypeInfo, + annotate.newObjCreator(tree.pos)); return types.unboxedTypeOrType(speculativeNewClassTree.type).isPrimitive(); default: - Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type; + Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo, annotate.noCreator).type; speculativeType = types.unboxedTypeOrType(speculativeType); return speculativeType.isPrimitive(); } @@ -1754,7 +1798,28 @@ public class Attr extends JCTree.Visitor { // Attribute arguments, yielding list of argument types. attribArgs(tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); - typeargtypes = attribTypes(tree.typeargs, localEnv); + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + try { + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), + annotate.constructorInvokeTypeArgCreator(i, tree.pos)); + } finally { + annotate.enterDone(); + } + } + + typeargtypes = + chk.checkRefTypes(tree.typeargs, typeargtypesbuf.toList()); // Variable `site' points to the class in which the called // constructor is defined. @@ -1827,7 +1892,27 @@ public class Attr extends JCTree.Visitor { // Attribute the arguments, yielding list of argument types, ... int kind = attribArgs(tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); - typeargtypes = attribAnyTypes(tree.typeargs, localEnv); + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + try { + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), + annotate.methodInvokeTypeArgCreator(i, tree.pos)); + } finally { + annotate.enterDone(); + } + } + + typeargtypes = typeargtypesbuf.toList(); // ... and attribute the method using as a prototype a methodtype // whose formal argument types is exactly the list of actual @@ -1852,6 +1937,7 @@ public class Attr extends JCTree.Visitor { // current context. Also, capture the return type result = check(tree, capture(restype), VAL, resultInfo); } + chk.validate(tree.typeargs, localEnv); } //where @@ -1927,14 +2013,12 @@ public class Attr extends JCTree.Visitor { annoclazzid = (JCAnnotatedType) clazzid; clazzid = annoclazzid.underlyingType; } - } else { - if (clazz.hasTag(ANNOTATED_TYPE)) { + } else if (clazz.hasTag(ANNOTATED_TYPE)) { annoclazzid = (JCAnnotatedType) clazz; clazzid = annoclazzid.underlyingType; } else { clazzid = clazz; } - } JCExpression clazzid1 = clazzid; // The same in fully qualified form @@ -1956,11 +2040,12 @@ public class Attr extends JCTree.Visitor { EndPosTable endPosTable = this.env.toplevel.endPositions; endPosTable.storeEnd(clazzid1, tree.getEndPosition(endPosTable)); - if (clazz.hasTag(ANNOTATED_TYPE)) { - JCAnnotatedType annoType = (JCAnnotatedType) clazz; - List annos = annoType.annotations; + if (annoclazzid != null) { + JCAnnotatedType annoType = annoclazzid; + List annos = annoclazzid.annotations; + + if (clazz.hasTag(TYPEAPPLY)) { - if (annoType.underlyingType.hasTag(TYPEAPPLY)) { clazzid1 = make.at(tree.pos). TypeApply(clazzid1, ((JCTypeApply) clazz).arguments); @@ -1977,12 +2062,32 @@ public class Attr extends JCTree.Visitor { clazz = clazzid1; } + Type clazztype; + + try { + annotate.enterStart(); // Attribute clazz expression and store // symbol + type back into the attributed tree. - Type clazztype = TreeInfo.isEnumInit(env.tree) ? + clazztype = TreeInfo.isEnumInit(env.tree) ? attribIdentAsEnumType(env, (JCIdent)clazz) : attribType(clazz, env); + if (cdef != null) { + // If we are looking at an anonymous class creation, then + // we are not allowed to have declaration annotations on + // the base type. + annotate.annotateStrictTypeLater(clazz, cdef.mods.annotations, localEnv, + env.info.scope.owner, tree.pos(), + annotate.newObjCreator(tree.pos)); + } else { + // Otherwise, we are. + annotate.annotateTypeLater(clazz, localEnv, env.info.scope.owner, + tree.pos(), annotate.newObjCreator(tree.pos)); + } + } finally { + annotate.enterDone(); + } + clazztype = chk.checkDiamond(tree, clazztype); chk.validate(clazz, localEnv); if (tree.encl != null) { @@ -2011,7 +2116,29 @@ public class Attr extends JCTree.Visitor { ListBuffer argtypesBuf = new ListBuffer<>(); int pkind = attribArgs(tree.args, localEnv, argtypesBuf); List argtypes = argtypesBuf.toList(); - List typeargtypes = attribTypes(tree.typeargs, localEnv); + List typeargtypes; + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + try { + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), + annotate.constructorInvokeTypeArgCreator(i, tree.pos)); + } finally { + annotate.enterDone(); + } + } + + typeargtypes = + chk.checkRefTypes(tree.typeargs, typeargtypesbuf.toList()); // If we have made no mistakes in the class type... if (clazztype.hasTag(CLASS)) { @@ -2194,7 +2321,9 @@ public class Attr extends JCTree.Visitor { ta.arguments = List.nil(); ResultInfo findDiamondResult = new ResultInfo(VAL, resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); - Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; + Type inferred = deferredAttr.attribSpeculative(tree, env, + findDiamondResult, + annotate.newObjCreator(tree.pos)).type; Type polyPt = allowPoly ? syms.objectType : clazztype; @@ -2256,8 +2385,20 @@ public class Attr extends JCTree.Visitor { Type owntype = types.createErrorType(tree.type); Env localEnv = env.dup(tree); Type elemtype; + + for(List dim : tree.dimAnnotations) { + this.attribAnnotationTypes(dim, localEnv); + } + if (tree.elemtype != null) { + try { + annotate.enterStart(); elemtype = attribType(tree.elemtype, localEnv); + annotate.annotateTypeLater(tree, env, env.info.scope.owner, tree.pos(), + annotate.newObjCreator(tree.pos)); + } finally { + annotate.enterDone(); + } chk.validate(tree.elemtype, localEnv); owntype = elemtype; for (List l = tree.dims; l.nonEmpty(); l = l.tail) { @@ -2278,6 +2419,7 @@ public class Attr extends JCTree.Visitor { elemtype = types.createErrorType(pt()); } } + if (tree.elems != null) { attribExprs(tree.elems, localEnv, elemtype); owntype = new ArrayType(elemtype, syms.arrayClass, @@ -2672,6 +2814,8 @@ public class Attr extends JCTree.Visitor { @Override public void visitReference(final JCMemberReference that) { + final boolean isConstructor = that.getName() == names.init; + if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { if (pt().hasTag(NONE)) { //method reference only allowed in assignment or method invocation/cast context @@ -2682,9 +2826,20 @@ public class Attr extends JCTree.Visitor { } final Env localEnv = env.dup(that); try { + Type exprType; + try { + annotate.enterStart(); //attribute member reference qualifier - if this is a constructor //reference, the expected kind must be a type - Type exprType = attribTree(that.expr, env, memberReferenceQualifierResult(that)); + exprType = attribTree(that.expr, env, memberReferenceQualifierResult(that)); + final Annotate.PositionCreator creator = + isConstructor ? annotate.constructorRefCreator(that.pos) : + annotate.methodRefCreator(that.pos); + annotate.annotateTypeLater(that.expr, localEnv, env.info.scope.owner, + that.pos(), creator); + } finally { + annotate.enterDone(); + } if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { exprType = chk.checkConstructorRefType(that.expr, exprType); @@ -2714,7 +2869,24 @@ public class Attr extends JCTree.Visitor { //attrib type-arguments List typeargtypes = List.nil(); if (that.typeargs != null) { + try { + annotate.enterStart(); typeargtypes = attribTypes(that.typeargs, localEnv); + + // Annotate type arguments + int i = 0; + for (List l = that.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final Annotate.PositionCreator typeArgCreator = + isConstructor ? annotate.constructorRefTypeArgCreator(i, that.pos) : + annotate.methodRefTypeArgCreator(i, that.pos); + final JCExpression arg = l.head; + annotate.annotateTypeLater(arg, env, env.info.scope.owner, + that.pos(), typeArgCreator); + } + } finally { + annotate.enterDone(); + } } Type desc; @@ -3088,7 +3260,15 @@ public class Attr extends JCTree.Visitor { } public void visitTypeCast(final JCTypeCast tree) { - Type clazztype = attribType(tree.clazz, env); + Type clazztype; + try { + annotate.enterStart(); + clazztype = attribType(tree.clazz, env); + annotate.annotateTypeLater(tree.clazz, env, env.info.scope.owner, + tree.pos(), annotate.castCreator(tree.pos)); + } finally { + annotate.enterDone(); + } chk.validate(tree.clazz, env, false); //a fresh environment is required for 292 inference to work properly --- //see Infer.instantiatePolymorphicSignatureInstance() @@ -3121,7 +3301,16 @@ public class Attr extends JCTree.Visitor { public void visitTypeTest(JCInstanceOf tree) { Type exprtype = chk.checkNullOrRefType( tree.expr.pos(), attribExpr(tree.expr, env)); - Type clazztype = attribType(tree.clazz, env); + Type clazztype; + try { + annotate.enterStart(); + clazztype = attribType(tree.clazz, env); + annotate.annotateTypeLater(tree.clazz, env, env.info.scope.owner, tree.pos(), + annotate.instanceOfCreator(tree.pos)); + } finally { + annotate.enterDone(); + } + if (!clazztype.hasTag(TYPEVAR)) { clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype); } @@ -3250,9 +3439,12 @@ public class Attr extends JCTree.Visitor { if ((pkind() & (PCK | TYP)) == 0) site = capture(site); // Capture field access - // don't allow T.class T[].class, etc if (skind == TYP) { + // If the qualifier is a type, annotate it + annotate.annotateTypeLater(tree, env, env.info.scope.owner, + tree.pos(), annotate.errorCreator); Type elt = site; + // don't allow T.class T[].class, etc while (elt.hasTag(ARRAY)) elt = ((ArrayType)elt).elemtype; if (elt.hasTag(TYPEVAR)) { @@ -4081,8 +4273,13 @@ public class Attr extends JCTree.Visitor { Assert.error("should be handled in Annotate"); } + /* This needs to be removed or otherwise changed, as it implicitly + * relies on the annotated types having previously been visited by + * Annotate.TypeAnnotate. + */ public void visitAnnotatedType(JCAnnotatedType tree) { - Type underlyingType = attribType(tree.getUnderlyingType(), env); + Type underlyingType = attribTree(tree.getUnderlyingType(), env, + resultInfo); this.attribAnnotationTypes(tree.annotations, env); annotateType(tree, tree.annotations); result = tree.type = underlyingType; @@ -4101,8 +4298,10 @@ public class Attr extends JCTree.Visitor { public void run() { List compounds = fromAnnotations(annotations); Assert.check(annotations.size() == compounds.size()); + if (!tree.type.hasTag(TypeTag.PACKAGE)) { tree.type = tree.type.annotatedType(compounds); } + } }); } @@ -4353,13 +4552,6 @@ public class Attr extends JCTree.Visitor { checkForSerial(c)) { checkSerialVersionUID(tree, c); } - if (allowTypeAnnos) { - // Correctly organize the postions of the type annotations - typeAnnotations.organizeTypeAnnotationsBodies(tree); - - // Check type annotations applicability rules - validateTypeAnnotations(tree, false); - } } // where boolean checkForSerial(ClassSymbol c) { @@ -4433,233 +4625,6 @@ public class Attr extends JCTree.Visitor { return types.capture(type); } - public void validateTypeAnnotations(JCTree tree, boolean sigOnly) { - tree.accept(new TypeAnnotationsValidator(sigOnly)); - } - //where - private final class TypeAnnotationsValidator extends TreeScanner { - - private final boolean sigOnly; - public TypeAnnotationsValidator(boolean sigOnly) { - this.sigOnly = sigOnly; - } - - public void visitAnnotation(JCAnnotation tree) { - chk.validateTypeAnnotation(tree, false); - super.visitAnnotation(tree); - } - public void visitAnnotatedType(JCAnnotatedType tree) { - if (!tree.underlyingType.type.isErroneous()) { - super.visitAnnotatedType(tree); - } - } - public void visitTypeParameter(JCTypeParameter tree) { - chk.validateTypeAnnotations(tree.annotations, true); - scan(tree.bounds); - // Don't call super. - // This is needed because above we call validateTypeAnnotation with - // false, which would forbid annotations on type parameters. - // super.visitTypeParameter(tree); - } - public void visitMethodDef(JCMethodDecl tree) { - if (tree.recvparam != null && - !tree.recvparam.vartype.type.isErroneous()) { - checkForDeclarationAnnotations(tree.recvparam.mods.annotations, - tree.recvparam.vartype.type.tsym); - } - if (tree.restype != null && tree.restype.type != null) { - validateAnnotatedType(tree.restype, tree.restype.type); - } - if (sigOnly) { - scan(tree.mods); - scan(tree.restype); - scan(tree.typarams); - scan(tree.recvparam); - scan(tree.params); - scan(tree.thrown); - } else { - scan(tree.defaultValue); - scan(tree.body); - } - } - public void visitVarDef(final JCVariableDecl tree) { - //System.err.println("validateTypeAnnotations.visitVarDef " + tree); - if (tree.sym != null && tree.sym.type != null) - validateAnnotatedType(tree.vartype, tree.sym.type); - scan(tree.mods); - scan(tree.vartype); - if (!sigOnly) { - scan(tree.init); - } - } - public void visitTypeCast(JCTypeCast tree) { - if (tree.clazz != null && tree.clazz.type != null) - validateAnnotatedType(tree.clazz, tree.clazz.type); - super.visitTypeCast(tree); - } - public void visitTypeTest(JCInstanceOf tree) { - if (tree.clazz != null && tree.clazz.type != null) - validateAnnotatedType(tree.clazz, tree.clazz.type); - super.visitTypeTest(tree); - } - public void visitNewClass(JCNewClass tree) { - if (tree.clazz.hasTag(ANNOTATED_TYPE)) { - checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, - tree.clazz.type.tsym); - } - if (tree.def != null) { - checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); - } - if (tree.clazz.type != null) { - validateAnnotatedType(tree.clazz, tree.clazz.type); - } - super.visitNewClass(tree); - } - public void visitNewArray(JCNewArray tree) { - if (tree.elemtype != null && tree.elemtype.type != null) { - if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { - checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, - tree.elemtype.type.tsym); - } - validateAnnotatedType(tree.elemtype, tree.elemtype.type); - } - super.visitNewArray(tree); - } - public void visitClassDef(JCClassDecl tree) { - //System.err.println("validateTypeAnnotations.visitClassDef " + tree); - if (sigOnly) { - scan(tree.mods); - scan(tree.typarams); - scan(tree.extending); - scan(tree.implementing); - } - for (JCTree member : tree.defs) { - if (member.hasTag(Tag.CLASSDEF)) { - continue; - } - scan(member); - } - } - public void visitBlock(JCBlock tree) { - if (!sigOnly) { - scan(tree.stats); - } - } - - /* I would want to model this after - * com.sun.tools.javac.comp.Check.Validator.visitSelectInternal(JCFieldAccess) - * and override visitSelect and visitTypeApply. - * However, we only set the annotated type in the top-level type - * of the symbol. - * Therefore, we need to override each individual location where a type - * can occur. - */ - private void validateAnnotatedType(final JCTree errtree, final Type type) { - //System.err.println("Attr.validateAnnotatedType: " + errtree + " type: " + type); - - if (type.isPrimitiveOrVoid()) { - return; - } - - JCTree enclTr = errtree; - Type enclTy = type; - - boolean repeat = true; - while (repeat) { - if (enclTr.hasTag(TYPEAPPLY)) { - List tyargs = enclTy.getTypeArguments(); - List trargs = ((JCTypeApply)enclTr).getTypeArguments(); - if (trargs.length() > 0) { - // Nothing to do for diamonds - if (tyargs.length() == trargs.length()) { - for (int i = 0; i < tyargs.length(); ++i) { - validateAnnotatedType(trargs.get(i), tyargs.get(i)); - } - } - // If the lengths don't match, it's either a diamond - // or some nested type that redundantly provides - // type arguments in the tree. - } - - // Look at the clazz part of a generic type - enclTr = ((JCTree.JCTypeApply)enclTr).clazz; - } - - if (enclTr.hasTag(SELECT)) { - enclTr = ((JCTree.JCFieldAccess)enclTr).getExpression(); - if (enclTy != null && - !enclTy.hasTag(NONE)) { - enclTy = enclTy.getEnclosingType(); - } - } else if (enclTr.hasTag(ANNOTATED_TYPE)) { - JCAnnotatedType at = (JCTree.JCAnnotatedType) enclTr; - if (enclTy == null || enclTy.hasTag(NONE)) { - if (at.getAnnotations().size() == 1) { - log.error(at.underlyingType.pos(), "cant.type.annotate.scoping.1", at.getAnnotations().head.attribute); - } else { - ListBuffer comps = new ListBuffer<>(); - for (JCAnnotation an : at.getAnnotations()) { - comps.add(an.attribute); - } - log.error(at.underlyingType.pos(), "cant.type.annotate.scoping", comps.toList()); - } - repeat = false; - } - enclTr = at.underlyingType; - // enclTy doesn't need to be changed - } else if (enclTr.hasTag(IDENT)) { - repeat = false; - } else if (enclTr.hasTag(JCTree.Tag.WILDCARD)) { - JCWildcard wc = (JCWildcard) enclTr; - if (wc.getKind() == JCTree.Kind.EXTENDS_WILDCARD) { - validateAnnotatedType(wc.getBound(), ((WildcardType)enclTy).getExtendsBound()); - } else if (wc.getKind() == JCTree.Kind.SUPER_WILDCARD) { - validateAnnotatedType(wc.getBound(), ((WildcardType)enclTy).getSuperBound()); - } else { - // Nothing to do for UNBOUND - } - repeat = false; - } else if (enclTr.hasTag(TYPEARRAY)) { - JCArrayTypeTree art = (JCArrayTypeTree) enclTr; - validateAnnotatedType(art.getType(), ((ArrayType)enclTy).getComponentType()); - repeat = false; - } else if (enclTr.hasTag(TYPEUNION)) { - JCTypeUnion ut = (JCTypeUnion) enclTr; - for (JCTree t : ut.getTypeAlternatives()) { - validateAnnotatedType(t, t.type); - } - repeat = false; - } else if (enclTr.hasTag(TYPEINTERSECTION)) { - JCTypeIntersection it = (JCTypeIntersection) enclTr; - for (JCTree t : it.getBounds()) { - validateAnnotatedType(t, t.type); - } - repeat = false; - } else if (enclTr.getKind() == JCTree.Kind.PRIMITIVE_TYPE || - enclTr.getKind() == JCTree.Kind.ERRONEOUS) { - repeat = false; - } else { - Assert.error("Unexpected tree: " + enclTr + " with kind: " + enclTr.getKind() + - " within: "+ errtree + " with kind: " + errtree.getKind()); - } - } - } - - private void checkForDeclarationAnnotations(List annotations, - Symbol sym) { - // Ensure that no declaration annotations are present. - // Note that a tree type might be an AnnotatedType with - // empty annotations, if only declaration annotations were given. - // This method will raise an error for such a type. - for (JCAnnotation ai : annotations) { - if (!ai.type.isErroneous() && - typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) { - log.error(ai.pos(), "annotation.type.not.applicable"); - } - } - } - } - // /** diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java b/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java index e9e6224d298..3ffda2453d8 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java @@ -58,6 +58,11 @@ public class AttrContext { */ boolean isSerializable = false; + /** + * Are we doing speculative attribution? + */ + boolean isSpeculative = false; + /** Are arguments to current function applications boxed into an array for varargs? */ Resolve.MethodResolutionPhase pendingResolutionPhase = null; @@ -94,6 +99,7 @@ public class AttrContext { info.returnResult = returnResult; info.defaultSuperCallSite = defaultSuperCallSite; info.isSerializable = isSerializable; + info.isSpeculative = isSpeculative; return info; } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java index 151794853f6..3f2157cdc35 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.source.tree.*; import com.sun.source.tree.LambdaExpressionTree.BodyKind; import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; @@ -76,6 +77,7 @@ public class DeferredAttr extends JCTree.Visitor { final Types types; final Flow flow; final Names names; + final Annotate annotate; public static DeferredAttr instance(Context context) { DeferredAttr instance = context.get(deferredAttrKey); @@ -99,6 +101,7 @@ public class DeferredAttr extends JCTree.Visitor { flow = Flow.instance(context); names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); + annotate = Annotate.instance(context); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override @@ -133,7 +136,8 @@ public class DeferredAttr extends JCTree.Visitor { AttrMode mode; SpeculativeCache speculativeCache; - DeferredType(JCExpression tree, Env env) { + DeferredType(JCExpression tree, + Env env) { super(null, noAnnotations); this.tree = tree; this.env = attr.copyEnv(env); @@ -277,12 +281,18 @@ public class DeferredAttr extends JCTree.Visitor { //Note: if a symbol is imported twice we might do two identical //speculative rounds... Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE); - JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo); + JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, + resultInfo, + annotate.noCreator); dt.speculativeCache.put(speculativeTree, resultInfo); return speculativeTree.type; case CHECK: Assert.check(dt.mode != null); - return attr.attribTree(dt.tree, dt.env, resultInfo); + final boolean oldSpeculative = dt.env.info.isSpeculative; + dt.env.info.isSpeculative = false; + Type out = attr.attribTree(dt.tree, dt.env, resultInfo); + dt.env.info.isSpeculative = oldSpeculative; + return out; } Assert.error(); return null; @@ -359,9 +369,13 @@ public class DeferredAttr extends JCTree.Visitor { * restored after type-checking. All diagnostics (but critical ones) are * disabled during speculative type-checking. */ - JCTree attribSpeculative(JCTree tree, Env env, ResultInfo resultInfo) { + JCTree attribSpeculative(JCTree tree, + Env env, + ResultInfo resultInfo, + Annotate.PositionCreator creator) { final JCTree newTree = new TreeCopier<>(make).copy(tree); Env speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); + speculativeEnv.info.isSpeculative = true; speculativeEnv.info.scope.owner = env.info.scope.owner; Log.DeferredDiagnosticHandler deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log, new Filter() { @@ -385,6 +399,9 @@ public class DeferredAttr extends JCTree.Visitor { }); try { attr.attribTree(newTree, speculativeEnv, resultInfo); + annotate.typeAnnotateExprLater(newTree, speculativeEnv, + speculativeEnv.info.scope.owner, + newTree.pos(), creator); unenterScanner.scan(newTree); return newTree; } finally { @@ -741,8 +758,11 @@ public class DeferredAttr extends JCTree.Visitor { checkContext.report(null, ex.getDiagnostic()); } Env localEnv = env.dup(tree); - JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, - attr.memberReferenceQualifierResult(tree)); + JCExpression exprTree = + (JCExpression)attribSpeculative(tree.getQualifierExpression(), + localEnv, + attr.memberReferenceQualifierResult(tree), + annotate.methodRefCreator(tree.pos)); ListBuffer argtypes = new ListBuffer<>(); for (Type t : types.findDescriptorType(pt).getParameterTypes()) { argtypes.append(Type.noType); @@ -1164,8 +1184,11 @@ public class DeferredAttr extends JCTree.Visitor { public void visitReference(JCMemberReference tree) { //perform arity-based check Env localEnv = env.dup(tree); - JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, - attr.memberReferenceQualifierResult(tree)); + JCExpression exprTree = + (JCExpression)attribSpeculative(tree.getQualifierExpression(), + localEnv, + attr.memberReferenceQualifierResult(tree), + annotate.methodRefCreator(tree.pos)); JCMemberReference mref2 = new TreeCopier(make).copy(tree); mref2.expr = exprTree; Symbol res = @@ -1309,7 +1332,7 @@ public class DeferredAttr extends JCTree.Visitor { return null; site = resolvedReturnType.type; } else { - site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo, annotate.noCreator).type; } } else { site = env.enclClass.sym.type; diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java index e189d999fe3..e3549915143 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java @@ -26,6 +26,7 @@ package com.sun.tools.javac.comp; import com.sun.tools.javac.tree.*; +import com.sun.tools.javac.tree.JCTree.JCLambda; import java.util.Iterator; import java.util.NoSuchElementException; @@ -156,4 +157,10 @@ public class Env implements Iterable> { } }; } + + public JCLambda getLambda() { + Env out = enclosing(JCTree.Tag.LAMBDA); + + return out != null ? (JCLambda) out.tree : null; + } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java index 4fddfb10f85..5c7c90052ac 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java @@ -35,8 +35,9 @@ import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; -import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.code.Type.*; +import com.sun.tools.javac.code.TypeAnnotationPosition.*; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; @@ -75,7 +76,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer { private final TreeMaker make; private final Todo todo; private final Annotate annotate; - private final TypeAnnotations typeAnnotations; private final Types types; private final JCDiagnostic.Factory diags; private final Source source; @@ -101,7 +101,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer { make = TreeMaker.instance(context); todo = Todo.instance(context); annotate = Annotate.instance(context); - typeAnnotations = TypeAnnotations.instance(context); types = Types.instance(context); diags = JCDiagnostic.Factory.instance(context); source = Source.instance(context); @@ -131,6 +130,13 @@ public class MemberEnter extends JCTree.Visitor implements Completer { */ boolean completionEnabled = true; + /** The creator that will be used for any varDef's we visit. This + * is used to create the position for any type annotations (or + * annotations that potentially are type annotations) that we + * encounter. + */ + Annotate.PositionCreator creator; + /* ---------- Processing import clauses ---------------- */ @@ -348,6 +354,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } /** Construct method type from method signature. + * @param msym The MethodSymbol for the method. * @param typarams The method's type parameters. * @param params The method's value parameters. * @param res The method's result type, @@ -356,33 +363,89 @@ public class MemberEnter extends JCTree.Visitor implements Completer { * null if none given; TODO: or already set here? * @param thrown The method's thrown exceptions. * @param env The method's (local) environment. + * @param declAnnos The annotations on the method declaration, + * some of which may be type annotations on + * the return type. + * @param deferPos The deferred diagnostic position for error + * reporting. */ - Type signature(MethodSymbol msym, - List typarams, - List params, - JCTree res, - JCVariableDecl recvparam, - List thrown, - Env env) { + Type signature(final MethodSymbol msym, + final List typarams, + final List params, + final JCTree res, + final JCVariableDecl recvparam, + final List thrown, + final Env env, + final List declAnnos, + final DiagnosticPosition deferPos) { + int i; // Enter and attribute type parameters. List tvars = enter.classEnter(typarams, env); attr.attribTypeVariables(typarams, env); - // Enter and attribute value parameters. + // Handle type annotations on type parameters. + i = 0; + for (List l = typarams; l.nonEmpty(); + l = l.tail, i++) { + final JCTypeParameter param = l.head; + annotate.annotateTypeLater(param, env, msym, deferPos, + annotate.methodTypeParamCreator(i)); + // ...and bounds on type parameters. + int j = 0; + for (List bounds = param.bounds; + bounds.nonEmpty(); bounds = bounds.tail, j++) { + annotate.annotateTypeLater(bounds.head, env, msym, deferPos, + annotate.methodTypeParamBoundCreator(param, i, j)); + } + } + + // Enter and attribute value parameters. Type annotations get + // METHOD_FORMAL_PARAMETER positions. ListBuffer argbuf = new ListBuffer<>(); - for (List l = params; l.nonEmpty(); l = l.tail) { - memberEnter(l.head, env); + i = 0; + for (List l = params; l.nonEmpty(); l = l.tail, i++) { + // The types will get annotated by visitVarDef + memberEnter(l.head, env, annotate.paramCreator(i)); argbuf.append(l.head.vartype.type); } // Attribute result type, if one is given. - Type restype = res == null ? syms.voidType : attr.attribType(res, env); + Type restype; + + if (res != null) { + // If we have any declaration annotations, they might + // be/also be type annotations on the return type. We + // pass them in, so they get classified and then attached + // to the method, or the return type, or both. + restype = attr.attribType(res, env); + annotate.annotateTypeLater(res, declAnnos, env, msym, deferPos, + annotate.returnCreator); + } else { + // For constructors, we don't actually have a type, so we + // can't have a type path (except for INNER_TYPE), and we + // don't have annotations on arrays, type arguments, and + // the like. + + // The only type path we have is if we are in an inner type. + List typepath = Annotate.makeInners(msym.owner.type); + TypeAnnotationPosition tapos = + TypeAnnotationPosition.methodReturn(typepath, env.getLambda(), -1); + + // We don't have to walk down a type. We just have to do + // repeating annotation handling, then classify and attach + // the annotations. + annotate.annotateWithClassifyLater(declAnnos, env, msym, + deferPos, tapos); + restype = syms.voidType; + } + // Attribute receiver type, if one is given. Type recvtype; if (recvparam!=null) { - memberEnter(recvparam, env); + // The type will get annotated by visitVarDef + memberEnter(recvparam, env, annotate.receiverCreator); recvtype = recvparam.vartype.type; } else { recvtype = null; @@ -390,8 +453,12 @@ public class MemberEnter extends JCTree.Visitor implements Completer { // Attribute thrown exceptions. ListBuffer thrownbuf = new ListBuffer<>(); - for (List l = thrown; l.nonEmpty(); l = l.tail) { + i = 0; + for (List l = thrown; l.nonEmpty(); l = l.tail, i++) { Type exc = attr.attribType(l.head, env); + // Annotate each exception type. + annotate.annotateTypeLater(l.head, env, msym, deferPos, + annotate.throwCreator(i)); if (!exc.hasTag(TYPEVAR)) { exc = chk.checkClassType(l.head.pos(), exc); } else if (exc.tsym.owner == msym) { @@ -420,33 +487,49 @@ public class MemberEnter extends JCTree.Visitor implements Completer { /** Enter field and method definitions and process import * clauses, catching any completion failure exceptions. */ - protected void memberEnter(JCTree tree, Env env) { + protected void memberEnter(JCTree tree, Env env, + Annotate.PositionCreator creator) { Env prevEnv = this.env; + Annotate.PositionCreator prevCreator = this.creator; try { this.env = env; + this.creator = creator; tree.accept(this); } catch (CompletionFailure ex) { chk.completionError(tree.pos(), ex); } finally { + this.creator = prevCreator; this.env = prevEnv; } } + + protected void memberEnter(JCTree tree, Env env) { + memberEnter(tree, env, annotate.noCreator); + } + /** Enter members from a list of trees. */ - void memberEnter(List trees, Env env) { + void memberEnter(List trees, + Env env, + Annotate.PositionCreator creator) { for (List l = trees; l.nonEmpty(); l = l.tail) - memberEnter(l.head, env); + memberEnter(l.head, env, creator); + } + + void memberEnter(List trees, + Env env) { + memberEnter(trees, env, annotate.noCreator); } /** Enter members for a class. */ - void finishClass(JCClassDecl tree, Env env) { + void finishClass(final JCClassDecl tree, final Env env) { if ((tree.mods.flags & Flags.ENUM) != 0 && (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { addEnumMembers(tree, env); } - memberEnter(tree.defs, env); + memberEnter(tree.defs, env, annotate.fieldCreator); } /** Add the implicit members for an enum type @@ -521,7 +604,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } } // process package annotations - annotate.annotateLater(tree.annotations, env, env.toplevel.packge, null); + annotate.annotateLater(tree.annotations, env, env.toplevel.packge); } // process the non-static imports and the static imports of types. @@ -567,15 +650,13 @@ public class MemberEnter extends JCTree.Visitor implements Completer { Env localEnv = methodEnv(tree, env); - annotate.enterStart(); - try { DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); try { // Compute the method type m.type = signature(m, tree.typarams, tree.params, tree.restype, tree.recvparam, - tree.thrown, - localEnv); + tree.thrown, localEnv, + tree.mods.annotations, tree.pos()); } finally { deferredLintHandler.setPos(prevLintPos); } @@ -602,16 +683,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer { enclScope.enter(m); } - annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); - // Visit the signature of the method. Note that - // TypeAnnotate doesn't descend into the body. - annotate.annotateTypeLater(tree, localEnv, m, tree.pos()); - if (tree.defaultValue != null) - annotateDefaultValueLater(tree.defaultValue, localEnv, m); - } finally { - annotate.enterDone(); - } + annotateDefaultValueLater(tree.defaultValue, localEnv, + m, annotate.noCreator); } /** Create a fresh environment for method bodies. @@ -695,8 +769,18 @@ public class MemberEnter extends JCTree.Visitor implements Completer { chk.checkTransparentVar(tree.pos(), v, enclScope); enclScope.enter(v); } - annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); - annotate.annotateTypeLater(tree.vartype, env, v, tree.pos()); + if (tree.name.equals(names._this)) { + // If we are dealing with a receiver parameter, then + // we only allow base type annotations to be type + // annotations. Receivers are not allowed to have + // declaration annotations. + annotate.annotateStrictTypeLater(tree.vartype, tree.mods.annotations, + localEnv, v, tree.pos(), creator); + } else { + // Otherwise, we annotate the type. + annotate.annotateTypeLater(tree.vartype, tree.mods.annotations, + localEnv, v, tree.pos(), creator); + } v.pos = tree.pos; } finally { annotate.enterDone(); @@ -849,7 +933,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer { /** Queue processing of an attribute default value. */ void annotateDefaultValueLater(final JCExpression defaultValue, final Env localEnv, - final MethodSymbol m) { + final MethodSymbol m, + final Annotate.PositionCreator creator) { annotate.normal(new Annotate.Worker() { @Override public String toString() { @@ -936,22 +1021,44 @@ public class MemberEnter extends JCTree.Visitor implements Completer { // create an environment for evaluating the base clauses Env baseEnv = baseEnv(tree, env); - if (tree.extending != null) - annotate.annotateTypeLater(tree.extending, baseEnv, sym, tree.pos()); - for (JCExpression impl : tree.implementing) - annotate.annotateTypeLater(impl, baseEnv, sym, tree.pos()); - annotate.flush(); + // Annotations. + // In general, we cannot fully process annotations yet, but we + // can attribute the annotation types and then check to see if the + // @Deprecated annotation is present. + attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); + if (hasDeprecatedAnnotation(tree.mods.annotations)) + c.flags_field |= DEPRECATED; + + // Don't attach declaration annotations to anonymous + // classes, they get handled specially below. + if (!sym.isAnonymous()) { + annotate.annotateLater(tree.mods.annotations, baseEnv, + c, tree.pos()); + } // Determine supertype. - Type supertype = - (tree.extending != null) - ? attr.attribBase(tree.extending, baseEnv, true, false, true) - : ((tree.mods.flags & Flags.ENUM) != 0) + Type supertype; + + if (tree.extending != null) { + supertype = attr.attribBase(tree.extending, baseEnv, + true, false, true); + if (sym.isAnonymous()) { + annotate.annotateAnonClassDefLater(tree.extending, + tree.mods.annotations, + baseEnv, sym, tree.pos(), + annotate.extendsCreator); + } else { + annotate.annotateTypeLater(tree.extending, baseEnv, sym, + tree.pos(), annotate.extendsCreator); + } + } else { + supertype = ((tree.mods.flags & Flags.ENUM) != 0) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, true, false, false) : (c.fullname == names.java_lang_Object) ? Type.noType : syms.objectType; + } ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); // Determine interfaces. @@ -959,18 +1066,33 @@ public class MemberEnter extends JCTree.Visitor implements Completer { ListBuffer all_interfaces = null; // lazy init Set interfaceSet = new HashSet<>(); List interfaceTrees = tree.implementing; + int i = 0; for (JCExpression iface : interfaceTrees) { - Type i = attr.attribBase(iface, baseEnv, false, true, true); - if (i.hasTag(CLASS)) { - interfaces.append(i); - if (all_interfaces != null) all_interfaces.append(i); - chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); + Type it = attr.attribBase(iface, baseEnv, false, true, true); + if (it.hasTag(CLASS)) { + interfaces.append(it); + if (all_interfaces != null) all_interfaces.append(it); + chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet); } else { if (all_interfaces == null) all_interfaces = new ListBuffer().appendList(interfaces); - all_interfaces.append(modelMissingTypes(i, iface, true)); + all_interfaces.append(modelMissingTypes(it, iface, true)); + } + if (sym.isAnonymous()) { + // Note: if an anonymous class ever has more than + // one supertype for some reason, this will + // incorrectly attach tree.mods.annotations to ALL + // supertypes, not just the first. + annotate.annotateAnonClassDefLater(iface, tree.mods.annotations, + baseEnv, sym, tree.pos(), + annotate.implementsCreator(i++)); + } else { + annotate.annotateTypeLater(iface, baseEnv, sym, tree.pos(), + annotate.implementsCreator(i++)); } + } + if ((c.flags_field & ANNOTATION) != 0) { ct.interfaces_field = List.of(syms.annotationType); ct.all_interfaces_field = ct.interfaces_field; @@ -993,22 +1115,28 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } } - // Annotations. - // In general, we cannot fully process annotations yet, but we - // can attribute the annotation types and then check to see if the - // @Deprecated annotation is present. - attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); - if (hasDeprecatedAnnotation(tree.mods.annotations)) - c.flags_field |= DEPRECATED; - annotate.annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); // class type parameters use baseEnv but everything uses env chk.checkNonCyclicDecl(tree); attr.attribTypeVariables(tree.typarams, baseEnv); // Do this here, where we have the symbol. - for (JCTypeParameter tp : tree.typarams) - annotate.annotateTypeLater(tp, baseEnv, sym, tree.pos()); + int j = 0; + for (List l = tree.typarams; l.nonEmpty(); + l = l.tail, j++) { + final JCTypeParameter typaram = l.head; + annotate.annotateTypeLater(typaram, baseEnv, sym, tree.pos(), + annotate.typeParamCreator(j)); + + int k = 0; + for(List b = typaram.bounds; b.nonEmpty(); + b = b.tail, k++) { + final JCExpression bound = b.head; + annotate.annotateTypeLater(bound, baseEnv, sym, tree.pos(), + annotate.typeParamBoundCreator(typaram, j, k)); + } + + } // Add default constructor if needed. if ((c.flags() & INTERFACE) == 0 && @@ -1088,10 +1216,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer { while (halfcompleted.nonEmpty()) { Env toFinish = halfcompleted.next(); finish(toFinish); - if (allowTypeAnnos) { - typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); - typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); - } } } finally { isFirst = true; diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 0a585735ba7..bc610a2b6ee 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -1611,8 +1611,6 @@ public class ClassReader { return TypeAnnotationPosition.methodReturn(readTypePath()); case FIELD: return TypeAnnotationPosition.field(readTypePath()); - case UNKNOWN: - throw new AssertionError("jvm.ClassReader: UNKNOWN target type should never occur!"); default: throw new AssertionError("jvm.ClassReader: Unknown target type for position: " + type); } diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java index d86644d864b..5eebcc21cc9 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java @@ -768,25 +768,13 @@ public class ClassWriter extends ClassFile { ListBuffer invisibles = new ListBuffer<>(); for (Attribute.TypeCompound tc : typeAnnos) { - if (tc.hasUnknownPosition()) { - boolean fixed = tc.tryFixPosition(); - - // Could we fix it? - if (!fixed) { - // This happens for nested types like @A Outer. @B Inner. - // For method parameters we get the annotation twice! Once with - // a valid position, once unknown. - // TODO: find a cleaner solution. - PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); - pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc); + Assert.checkNonNull(tc.position); + if (tc.position.type.isLocal() != inCode) { continue; } + if (!tc.position.emitToClassfile()) { + continue; } - - if (tc.position.type.isLocal() != inCode) - continue; - if (!tc.position.emitToClassfile()) - continue; switch (types.getRetention(tc)) { case SOURCE: break; case CLASS: invisibles.append(tc); break; @@ -967,8 +955,6 @@ public class ClassWriter extends ClassFile { case METHOD_RETURN: case FIELD: break; - case UNKNOWN: - throw new AssertionError("jvm.ClassWriter: UNKNOWN target type should never occur!"); default: throw new AssertionError("jvm.ClassWriter: Unknown target type for position: " + p); } diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java index 37050775fb8..2ee148947b6 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -557,7 +557,6 @@ public class Gen extends JCTree.Visitor { ListBuffer fieldTAs = new ListBuffer<>(); ListBuffer nonfieldTAs = new ListBuffer<>(); for (TypeCompound ta : tas) { - Assert.check(ta.getPosition().type != TargetType.UNKNOWN); if (ta.getPosition().type == TargetType.FIELD) { fieldTAs.add(ta); } else { @@ -1931,10 +1930,7 @@ public class Gen extends JCTree.Visitor { || code.meth.getKind() == javax.lang.model.element.ElementKind.STATIC_INIT; for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } @@ -1942,10 +1938,7 @@ public class Gen extends JCTree.Visitor { return; for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } @@ -1955,10 +1948,7 @@ public class Gen extends JCTree.Visitor { continue; for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } } @@ -2330,8 +2320,8 @@ public class Gen extends JCTree.Visitor { } public void visitTypeTest(JCInstanceOf tree) { - setTypeAnnotationPositions(tree.pos); genExpr(tree.expr, tree.expr.type).load(); + setTypeAnnotationPositions(tree.pos); code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); result = items.makeStackItem(syms.booleanType); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/TargetTypes.java b/langtools/test/tools/javac/annotations/typeAnnotations/TargetTypes.java index 053f4e4b574..2d42a640ae5 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/TargetTypes.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/TargetTypes.java @@ -35,9 +35,41 @@ import java.io.*; * @compile TargetTypes.java */ -@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@interface A {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface A {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface B {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface C {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface D {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface E {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface F {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface G {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface H {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface I {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface J {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface K {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface L {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface M {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface N {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface O {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface P {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Q {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface R {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface S {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface U {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface V {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface W {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface X {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Y {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Z {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AA {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AB {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AC {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AD {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AE {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AF {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AG {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AH {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AI {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AJ {} /** wildcard bound */ class T0x1C { @@ -46,75 +78,75 @@ class T0x1C { /** wildcard bound generic/array */ class T0x1D { - void m0x1D(List> lst) {} + void m0x1D(List> lst) {} } /** typecast */ class T0x00 { void m0x00(Long l1) { - Object l2 = (@A Long) l1; + Object l2 = (@C Long) l1; } } /** typecast generic/array */ class T0x01 { void m0x01(List list) { - List l = (List<@A T>) list; + List l = (List<@D T>) list; } } /** instanceof */ class T0x02 { boolean m0x02(String s) { - return (s instanceof @A String); + return (s instanceof @E String); } } /** object creation (new) */ class T0x04 { void m0x04() { - new @A ArrayList(); + new @F ArrayList(); } } /** local variable */ class T0x08 { void m0x08() { - @A String s = null; + @G String s = null; } } /** method parameter generic/array */ class T0x0D { - void m0x0D(HashMap<@A Object, List<@A List<@A Class>>> s1) {} + void m0x0D(HashMap<@H Object, List<@I List<@J Class>>> s1) {} } /** method receiver */ class T0x06 { - void m0x06(@A T0x06 this) {} + void m0x06(@K T0x06 this) {} } /** method return type generic/array */ class T0x0B { - Class<@A Object> m0x0B() { return null; } + Class<@L Object> m0x0B() { return null; } } /** field generic/array */ class T0x0F { - HashMap<@A Object, @A Object> c1; + HashMap<@M Object, @N Object> c1; } /** method type parameter */ class T0x20 { - <@A T, @A U> void m0x20() {} + <@O T, @P U> void m0x20() {} } /** class type parameter */ -class T0x22<@A T, @A U> { +class T0x22<@Q T, @R U> { } /** class type parameter bound */ -class T0x10 { +class T0x10 { } /** method type parameter bound */ @@ -123,43 +155,43 @@ class T0x12 { } /** class type parameter bound generic/array */ -class T0x11> { +class T0x11> { } /** method type parameter bound generic/array */ class T0x13 { - static > T m0x13() { + static > T m0x13() { return null; } } /** class extends/implements generic/array */ -class T0x15 extends ArrayList<@A T> { +class T0x15 extends ArrayList<@W T> { } /** type test (instanceof) generic/array */ class T0x03 { void m0x03(T typeObj, Object obj) { - boolean ok = obj instanceof String @A []; + boolean ok = obj instanceof String @X []; } } /** object creation (new) generic/array */ class T0x05 { void m0x05() { - new ArrayList<@A T>(); + new ArrayList<@Y T>(); } } /** local variable generic/array */ class T0x09 { void g() { - List<@A String> l = null; + List<@Z String> l = null; } void a() { - String @A [] as = null; + String @AA [] as = null; } } @@ -168,14 +200,14 @@ class T0x19 { T0x19() {} void g() { - new > T0x19(); + new > T0x19(); } } /** type argument in method call generic/array */ class T0x1B { void m0x1B() { - Collections.emptyList(); + Collections.emptyList(); } } @@ -184,7 +216,7 @@ class T0x18 { T0x18() {} void m() { - new <@A Integer> T0x18(); + new <@AD Integer> T0x18(); } } @@ -192,15 +224,15 @@ class T0x18 { class T0x1A { public static T m() { return null; } static void m0x1A() { - T0x1A.<@A Integer, @A Short>m(); + T0x1A.<@AE Integer, @AF Short>m(); } } /** class extends/implements */ -class T0x14 extends @A Object implements @A Serializable, @A Cloneable { +class T0x14 extends @AG Object implements @AH Serializable, @AI Cloneable { } /** exception type in throws */ class T0x16 { - void m0x16() throws @A Exception {} + void m0x16() throws @AJ Exception {} } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java b/langtools/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java index 6beae3afd8f..d6fa8e73724 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java @@ -36,8 +36,8 @@ public class ClassfileTestHelper { //Makes debugging much easier. Set to 'false' for less output. public Boolean verbose = true; - void println(String msg) { if (verbose) System.out.println(msg); } - void print(String msg) { if (verbose) System.out.print(msg); } + void println(String msg) { if (verbose) System.err.println(msg); } + void print(String msg) { if (verbose) System.err.print(msg); } File writeTestFile(String fname, String source) throws IOException { File f = new File(fname); diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.java new file mode 100644 index 00000000000..d1006592b5c --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.java @@ -0,0 +1,17 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8027262 + * @summary A class expression cannot be annotated. + * @compile/fail/ref=AnnotatedClassExpr.out -XDrawDiagnostics AnnotatedClassExpr.java + */ +import java.lang.annotation.*; +import java.util.List; + +class AnnotatedClassExpr { + static void main() { + Object o1 = @A int.class; + } +} + +@Target(ElementType.TYPE_USE) +@interface A { } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.out new file mode 100644 index 00000000000..d2d354cbda6 --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedClassExpr.out @@ -0,0 +1,2 @@ +AnnotatedClassExpr.java:12:29: compiler.err.no.annotations.on.dot.class +1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java index c7b38cc5974..b5953d0b62b 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java @@ -1,9 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8006775 + * @bug 8006775 8027262 * @summary Import clauses cannot use annotations. * @author Werner Dietl - * @ignore * @compile/fail/ref=AnnotatedImport.out -XDrawDiagnostics AnnotatedImport.java */ diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out index dbd0d42c1e3..91589d9252e 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out @@ -1,7 +1,7 @@ -AnnotatedImport.java:9:13: compiler.err.expected: token.identifier -AnnotatedImport.java:9:14: compiler.err.expected3: class, interface, enum -AnnotatedImport.java:10:7: compiler.err.expected: token.identifier -AnnotatedImport.java:10:10: compiler.err.expected: ';' -AnnotatedImport.java:11:18: compiler.err.expected: token.identifier -AnnotatedImport.java:11:19: compiler.err.expected3: class, interface, enum +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 6 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java index 4122fa11e5c..aed3e2cc5fd 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java @@ -1,9 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8006775 + * @bug 8006775 8027262 * @summary Package declarations cannot use annotations. * @author Werner Dietl - * @ignore * @compile/fail/ref=AnnotatedPackage1.out -XDrawDiagnostics AnnotatedPackage1.java */ diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out index 648af198629..b2c1770b3b5 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.out @@ -1,3 +1,3 @@ AnnotatedPackage1.java:9:14: compiler.err.expected: token.identifier -AnnotatedPackage1.java:9:16: compiler.err.expected3: class, interface, enum +AnnotatedPackage1.java:9:17: compiler.err.expected3: class, interface, enum 2 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out index 574ceb64cfb..600d699ebd4 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out @@ -1,5 +1,5 @@ -CantAnnotatePackages.java:19:14: compiler.err.cant.resolve.location: kindname.class, java, , , (compiler.misc.location: kindname.class, CantAnnotatePackages, null) -CantAnnotatePackages.java:20:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotatePackages.java:21:14: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotatePackages.java:14:18: compiler.err.cant.type.annotate.scoping.1: @TA -4 errors \ No newline at end of file +CantAnnotatePackages.java:14:13: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:19:18: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:20:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:21:24: compiler.err.cant.type.annotate.scoping.1: @TA +4 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out index 638b91d14ee..85118d3f64a 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out @@ -1,12 +1,14 @@ -CantAnnotateScoping.java:61:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotateScoping.java:66:9: compiler.err.cant.resolve.location: kindname.class, XXX, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotateScoping.java:70:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) +CantAnnotateScoping.java:66:18: compiler.err.doesnt.exist: java.XXX CantAnnotateScoping.java:38:14: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:47:18: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:56:37: compiler.err.cant.type.annotate.scoping: @TA,@TA2 -CantAnnotateScoping.java:40:14: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:42:34: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 +CantAnnotateScoping.java:40:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:47:13: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:56:32: compiler.err.cant.type.annotate.scoping: @TA,@TA2 +CantAnnotateScoping.java:61:19: compiler.err.cant.type.annotate.scoping.1: @DA +CantAnnotateScoping.java:70:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:61:11: compiler.err.annotation.type.not.applicable +CantAnnotateScoping.java:66:11: compiler.err.annotation.type.not.applicable +CantAnnotateScoping.java:42:39: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 CantAnnotateScoping.java:42:25: compiler.err.annotation.type.not.applicable -CantAnnotateScoping.java:44:38: compiler.err.cant.type.annotate.scoping: @TA,@DA +CantAnnotateScoping.java:44:43: compiler.err.cant.type.annotate.scoping: @TA,@DA CantAnnotateScoping.java:44:34: compiler.err.annotation.type.not.applicable -11 errors +13 errors \ No newline at end of file diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java index cf019b117f5..442c9d55b35 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java @@ -12,14 +12,49 @@ import java.util.HashMap; import java.lang.annotation.*; class Top { - @Target(ElementType.TYPE_USE) - @interface TA {} - - @Target(ElementType.TYPE_USE) - @interface TB {} - - @Target(ElementType.TYPE_USE) - @interface TC {} + @Target(ElementType.TYPE_USE) @interface TA {} + @Target(ElementType.TYPE_USE) @interface TB1 {} + @Target(ElementType.TYPE_USE) @interface TB2 {} + @Target(ElementType.TYPE_USE) @interface TB3 {} + @Target(ElementType.TYPE_USE) @interface TB4 {} + @Target(ElementType.TYPE_USE) @interface TB5 {} + @Target(ElementType.TYPE_USE) @interface TB6 {} + @Target(ElementType.TYPE_USE) @interface TB7 {} + @Target(ElementType.TYPE_USE) @interface TB8 {} + @Target(ElementType.TYPE_USE) @interface TB9 {} + @Target(ElementType.TYPE_USE) @interface TB10 {} + @Target(ElementType.TYPE_USE) @interface TB11 {} + @Target(ElementType.TYPE_USE) @interface TB12 {} + @Target(ElementType.TYPE_USE) @interface TB13 {} + @Target(ElementType.TYPE_USE) @interface TB14 {} + @Target(ElementType.TYPE_USE) @interface TB15 {} + @Target(ElementType.TYPE_USE) @interface TB16 {} + @Target(ElementType.TYPE_USE) @interface TB17 {} + @Target(ElementType.TYPE_USE) @interface TB18 {} + @Target(ElementType.TYPE_USE) @interface TB19 {} + @Target(ElementType.TYPE_USE) @interface TB20 {} + @Target(ElementType.TYPE_USE) @interface TB21 {} + @Target(ElementType.TYPE_USE) @interface TB22 {} + @Target(ElementType.TYPE_USE) @interface TB23 {} + @Target(ElementType.TYPE_USE) @interface TB24 {} + @Target(ElementType.TYPE_USE) @interface TB25 {} + @Target(ElementType.TYPE_USE) @interface TB26 {} + @Target(ElementType.TYPE_USE) @interface TB27 {} + @Target(ElementType.TYPE_USE) @interface TB28 {} + @Target(ElementType.TYPE_USE) @interface TB29 {} + @Target(ElementType.TYPE_USE) @interface TB30 {} + @Target(ElementType.TYPE_USE) @interface TB31 {} + @Target(ElementType.TYPE_USE) @interface TB32 {} + @Target(ElementType.TYPE_USE) @interface TB33 {} + @Target(ElementType.TYPE_USE) @interface TB34 {} + @Target(ElementType.TYPE_USE) @interface TB35 {} + @Target(ElementType.TYPE_USE) @interface TB36 {} + @Target(ElementType.TYPE_USE) @interface TB37 {} + @Target(ElementType.TYPE_USE) @interface TB38 {} + @Target(ElementType.TYPE_USE) @interface TB39 {} + @Target(ElementType.TYPE_USE) @interface TB40 {} + @Target(ElementType.TYPE_USE) @interface TB41 {} + @Target(ElementType.TYPE_USE) @interface TC {} class Outer { class Inner { @@ -34,63 +69,63 @@ class Top { // All combinations are OK - Top.@TB Outer f1; - @TB Outer.Inner f1a; + Top.@TB1 Outer f1; + @TB2 Outer.Inner f1a; Outer. @TC Inner f1b; - @TB Outer. @TC Inner f1c; + @TB3 Outer. @TC Inner f1c; - @TA Top. @TB Outer f2; - @TA Top. @TB Outer.Inner f2a; + @TA Top. @TB4 Outer f2; + @TA Top. @TB5 Outer.Inner f2a; @TA Top. Outer. @TC Inner f2b; - @TA Top. @TB Outer. @TC Inner f2c; + @TA Top. @TB6 Outer. @TC Inner f2c; - @TB Outer f1r() { return null; } - @TB Outer.Inner f1ra() { return null; } + @TB7 Outer f1r() { return null; } + @TB8 Outer.Inner f1ra() { return null; } Outer. @TC Inner f1rb() { return null; } - @TB Outer. @TC Inner f1rc() { return null; } + @TB9 Outer. @TC Inner f1rc() { return null; } - void f1param(@TB Outer p, - @TB Outer.Inner p1, + void f1param(@TB41 Outer p, + @TB10 Outer.Inner p1, Outer. @TC Inner p2, - @TB Outer. @TC Inner p3) { } + @TB11 Outer. @TC Inner p3) { } void f1cast(Object o) { Object l; - l = (@TB Outer) o; - l = (@TB Outer.Inner) o; + l = (@TB12 Outer) o; + l = (@TB13 Outer.Inner) o; l = (Outer. @TC Inner) o; - l = (@TB Outer. @TC Inner) o; + l = (@TB14 Outer. @TC Inner) o; } - List<@TB Outer> g1; - List<@TB Outer.Inner> g1a; + List<@TB15 Outer> g1; + List<@TB16 Outer.Inner> g1a; List g1b; - List<@TB Outer. @TC Inner> g1c; + List<@TB17 Outer. @TC Inner> g1c; - List<@TA Top. @TB Outer> g2; - List<@TA Top. @TB Outer.Inner> g2a; + List<@TA Top. @TB18 Outer> g2; + List<@TA Top. @TB19 Outer.Inner> g2a; List<@TA Top. Outer. @TC Inner> g2b; - List<@TA Top. @TB Outer. @TC Inner> g2c; + List<@TA Top. @TB20 Outer. @TC Inner> g2c; - List<@TB Outer> g1r() { return null; } - List<@TB Outer.Inner> g1ra() { return null; } + List<@TB21 Outer> g1r() { return null; } + List<@TB22 Outer.Inner> g1ra() { return null; } List g1rb() { return null; } - List<@TB Outer. @TC Inner> g1rc() { return null; } + List<@TB23 Outer. @TC Inner> g1rc() { return null; } - void g1param(List<@TB Outer> p, - List<@TB Outer.Inner> p1, + void g1param(List<@TB24 Outer> p, + List<@TB25 Outer.Inner> p1, List p2, - List<@TB Outer. @TC Inner> p3) { } + List<@TB26 Outer. @TC Inner> p3) { } void g1new(Object o) { Object l; - l = new @TB ArrayList<@TB Outer>(); - l = new @TB ArrayList<@TB Outer.Inner>(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); + l = new @TB27 ArrayList<@TB28 Outer>(); + l = new @TB29 ArrayList<@TB30 Outer.Inner>(); + l = new @TB31 HashMap(); + l = new @TB32 HashMap(); + l = new @TB34 HashMap(); + l = new @TB36 HashMap(); + l = new @TB37 HashMap(); + l = new @TB39 HashMap(); } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out index 869059ce7f0..b6e5d188ed4 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out @@ -1,65 +1,72 @@ CantAnnotateStaticClass2.java:44:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:45:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:52:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:53:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:55:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:56:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:60:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:61:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:62:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:64:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:65:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:66:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:52:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:53:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:55:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:56:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:60:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:61:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:62:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:64:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:65:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:66:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:71:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:72:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:79:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:80:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:79:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:80:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:87:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:89:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:89:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:91:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:93:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:129:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:131:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:133:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:137:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:138:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:139:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:141:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:149:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:150:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:157:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:158:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:165:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:167:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:169:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:171:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:184:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:186:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:192:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:194:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:195:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:199:35: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:201:41: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:204:49: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC -64 errors +CantAnnotateStaticClass2.java:93:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:120:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:121:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:128:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:129:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:131:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:133:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:134:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:135:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:137:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:138:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:139:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:141:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:142:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:143:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:149:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:150:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:157:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:158:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:165:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:167:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:169:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:171:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:105:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:107:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:112:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:114:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:184:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:186:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:187:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:192:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:194:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:195:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:199:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:200:49: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:201:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:202:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:203:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:204:52: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC +71 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java index f9d123e91b5..4d94b6f12ee 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java @@ -1,9 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8006733 8006775 + * @bug 8006733 8006775 8027262 * @summary Ensure behavior for nested types is correct. * @author Werner Dietl - * @ignore * @compile/fail/ref=CantAnnotateStaticClass3.out -XDrawDiagnostics CantAnnotateStaticClass3.java */ diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out index 1d3cba06694..4f2f989ebf3 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out @@ -1,83 +1,92 @@ CantAnnotateStaticClass3.java:44:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:45:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:46:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:52:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:53:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:54:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:56:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:59:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:61:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:62:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:63:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:65:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:66:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:67:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:52:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:53:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:54:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:56:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:59:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:59:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:61:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:62:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:63:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:65:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:66:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:67:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:67:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:71:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:72:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:73:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:79:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:80:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:81:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:79:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:80:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:81:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:84:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:86:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:86:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:88:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:90:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:90:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass3.java:92:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:94:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:59:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:67:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:99:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:101:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:106:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:108:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:113:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:115:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:122:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:129:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:130:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:132:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:136:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:138:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:139:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:140:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:144:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:149:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:150:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:151:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:157:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:158:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:159:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:162:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:164:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:166:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:168:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:170:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:172:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:177:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:179:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:180:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:185:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:188:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:193:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:195:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:196:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:200:35: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:201:38: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:202:41: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:204:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -82 errors \ No newline at end of file +CantAnnotateStaticClass3.java:94:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:120:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:121:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:122:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:128:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:129:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:130:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:132:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:134:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:135:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:136:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:136:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:138:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:139:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:140:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:142:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:143:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:144:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:144:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:149:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:150:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:151:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:157:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:158:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:159:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:162:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:164:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:166:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:168:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:170:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:172:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:99:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:101:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:106:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:108:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:113:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:115:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:177:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:179:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:180:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:185:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:187:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:188:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:193:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:195:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:196:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:201:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:201:49: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:203:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass3.java:204:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass3.java:204:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +91 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java index d33fd24e16c..65029ceb9f1 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java @@ -10,7 +10,7 @@ class DeclarationAnnotation { Object e1 = new @DA int[5]; Object e2 = new @DA String[42]; Object e3 = new @DA Object(); - Object ok = new @DA Object() { }; + Object e4 = new @DA Object() { }; } @interface DA { } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out index efb655727e1..325094a615a 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out @@ -1,5 +1,5 @@ -DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable +DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable 4 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.java index 4f099e03156..0ae45afdb70 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.java @@ -5,10 +5,13 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue { void test() { String @A [] s; } } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.out index 74a7ef7340b..c6deb988baa 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:10:12: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:12:12: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.java index 5a5c8b69587..1acb2eca4db 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.java @@ -5,10 +5,13 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue { void innermethod() { class Inner<@A K> { } } } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.out index 637ff4acc0a..9c513dc6c0b 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/innertypeparams/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:10:17: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:12:17: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.java index 15cf6e91496..784474bd97c 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.java @@ -5,10 +5,13 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue { void test() { String[] a = new String @A [5]; } } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.out index 6865348250b..a8f60fb199a 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/newarray/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:10:29: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:12:29: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java index 4043ed6bc50..7851d214c42 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java @@ -5,8 +5,13 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; + class MissingAnnotationValue { void test(@A MissingAnnotationValue this) { } } +@Target({TYPE_USE}) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out index c83391029bf..3d0ae6b280a 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:9:13: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:13:13: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.java index a6e00304fa1..8daca363e7f 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.java @@ -5,8 +5,11 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue { MissingAnnotationValue<@A String> l; } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.out index 749442f45b6..ec12c3d7d0e 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeArgs/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:9:26: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:11:26: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.java index 39f8bee930f..0b2b8999538 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.java @@ -5,7 +5,10 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue<@A K> { } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.out index acac021869b..563bf878c53 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/typeparams/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:8:30: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:10:30: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.java b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.java index c111c895c7d..4e9a1131678 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.java @@ -5,8 +5,11 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; + class MissingAnnotationValue { MissingAnnotationValue<@A ?> l; } +@Target(ElementType.TYPE_USE) @interface A { int field(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.out b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.out index 749442f45b6..ec12c3d7d0e 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/MissingAnnotationValue.out @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:9:26: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:11:26: compiler.err.annotation.missing.default.value: A, field 1 error diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/AllLocations.java b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/AllLocations.java new file mode 100644 index 00000000000..ed667504ef9 --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/AllLocations.java @@ -0,0 +1,196 @@ +/* + * 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 8027262 + * @summary Stress test for type annotatons + * @compile AllLocations.java + */ + +import java.util.function.Function; +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; +import java.io.*; +import java.lang.ref.WeakReference; + +public class AllLocations { + + public class ParamStream extends FileOutputStream { + public ParamStream(File f) throws FileNotFoundException { super(f); } + } + + public class Inner { + public Inner() {} + public <@A T> Inner(@B Object o) {} + public <@C T> Object g(Inner<@D S> this, Object @E [] o) { + return new @F int @G [5]; + } + } + + public <@H T extends @I Inner<@J ? extends @K String>> AllLocations(Object o) {} + + public @L Object @M [] @N [] arr = new @O Object @P [5] @Q [5]; + + public Inner<@R ? extends @S Inner<@T ? extends @U Integer>> inner; + + public Function func(@V AllLocations this) { + try (final ParamStream<@W Integer @X []> fs = new ParamStream<@Y Integer @Z []>(new File("testfile"))) { + return @AA AllLocations.Inner<@AB String>::<@AC Integer>new; + } catch(@AD Exception ex) { + return null; + } + } + + public <@AE T extends @AF Inner<@AG Integer @AH []>> Function func2() { + arr[0][0] = new @AI Inner((@AJ Object) arr[0]); + return Ext.f((@AK Object) arr[0]) instanceof @AL Inner @AM [] @AN [] ? + @AO @AP Ext::<@AQ @AR Integer> f : + @AS @AT Ext::<@AU @AV Integer> f; + } + + public Object func3(Object @AW [] arr) { + Inner<@AX ? extends @AY Inner<@AZ ? extends @BA Integer>> loc; + if (arr[0] instanceof @BB Inner @BC [] @BD []) + return this.> func4(); + else + return new <@BG Inner<@BH Integer>> @BI Inner<@BJ Inner<@BK Integer>>(null); + } + + public <@BL T extends @BO Inner<@BP Integer @BQ []>> + @BR Inner<@BS Inner<@BT String>> func4() { + return (@BU Inner<@BV Inner<@BW String>>) + new <@BX Inner<@BY Integer>> @BZ Inner<@CA Inner<@CB String>>(null) {}; + } + + { Inner<@CC ? extends @CD Inner<@CE ? extends @CF Integer>> loc = + new @CG Inner<@CH Inner<@CI Integer>>() {}; + Ext.func(Ext.func(@CJ WeakReference::new)); + Ext.func(Ext.func(@CK Ext::<@CL Integer>f)); + Ext.func((@CM Object a) -> { @CN Object b = a; return b; }); + } + +} + +class Ext { + public static <@CO T> Object f(Object o) { + return null; + } + public static Function func(Function f) { return f; } +} + + +@Retention(RUNTIME) @Target({TYPE_USE}) @interface A { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface B { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface C { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface D { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface E { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface F { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface G { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface H { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface I { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface J { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface K { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface L { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface M { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface N { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface O { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface P { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Q { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface R { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface S { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface T { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface U { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface V { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface W { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface X { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Y { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Z { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AJ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AK { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AL { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AM { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AN { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AO { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AP { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AQ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AR { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AS { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AT { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AU { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AV { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AW { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AX { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AY { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AZ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BJ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BK { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BL { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BM { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BN { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BO { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BP { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BQ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BR { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BS { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BT { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BU { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BV { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BW { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BX { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BY { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BZ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CJ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CK { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CL { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CM { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CN { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CO { } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java index bd4acc9c895..77ab7549eae 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java @@ -52,28 +52,40 @@ class Expressions { } void objectCreationArray() { - Object a1 = new @A String [] [] { }; - Object a2 = new @A String [1] []; - Object a3 = new @A String [1] [2]; + Object a1 = new @C String [] [] { }; + Object a2 = new @D String [1] []; + Object a3 = new @E String [1] [2]; - Object b1 = new @A String @B(0) [] [] { }; - Object b2 = new @A String @B(0) [1] []; - Object b3 = new @A String @B(0) [1] [2]; + Object b1 = new @F String @B(1) [] [] { }; + Object b2 = new @G String @B(2) [1] []; + Object b3 = new @H String @B(3) [1] [2]; - Object c1 = new @A String [] @B(0) [] { }; - Object c2 = new @A String [1] @B(0) []; - Object c3 = new @A String [1] @B(0) [2]; + Object c1 = new @I String [] @B(4) [] { }; + Object c2 = new @J String [1] @B(5) []; + Object c3 = new @K String [1] @B(6) [2]; - Object d1 = new @A String @B(0) [] @B(0) [] { }; - Object d2 = new @A String @B(0) [1] @B(0) []; - Object d3 = new @A String @B(0) [1] @B(0) [2]; + Object d1 = new @L String @B(7) [] @B(8) [] { }; + Object d2 = new @M String @B(9) [1] @B(10) []; + Object d3 = new @N String @B(11) [1] @B(12) [2]; - Object rand = new @A String @B(value = 0) [1] @B(value = 0) [2]; + Object rand = new @O String @B(value = 13) [1] @B(value = 14) [2]; } } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface A { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface C { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface D { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface E { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface F { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface G { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface H { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface I { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface J { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface K { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface L { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface M { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface N { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface O { } @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface A { } -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface B { int value(); } + @interface B { int value(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java index 7572b4fefb2..76c98fc67ec 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java @@ -128,6 +128,7 @@ class Test1 { MyList f9; // Illegal: // MyList<@A Outer . @Cv("Data") Static> f9; + } class Test2 { diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out index 2e892772433..d914d564aff 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out +++ b/langtools/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out @@ -17,12 +17,12 @@ RepeatingTypeAnnotations.java:89:18: compiler.err.duplicate.annotation.missing.c RepeatingTypeAnnotations.java:89:33: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:93:19: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:93:35: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:97:34: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:97:19: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:101:26: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:97:34: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:101:37: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:101:72: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:101:26: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:101:56: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:101:72: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable - compiler.note.unchecked.filename: RepeatingTypeAnnotations.java - compiler.note.unchecked.recompile 25 errors diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java index 6502846c4e8..7667e243807 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java @@ -30,7 +30,6 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; * @run main Driver Fields */ public class Fields { - // field types @TADescription(annotation = "TA", type = FIELD) public String fieldAsPrimitive() { @@ -124,5 +123,4 @@ public class Fields { public String staticFieldAsParametrized() { return "static @TA Map<@TB String, @TC List<@TD String>> test;"; } - } diff --git a/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java b/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java index 13fe97c18af..cf1124590fe 100644 --- a/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java +++ b/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java @@ -96,9 +96,10 @@ public class TestAnonClassNames { List names = new ArrayList(); for(Class clazz : classes) { String name = clazz.getName(); - System.out.format("%s is %s%n", - clazz.getName(), - clazz.getAnnotation(Nesting.class).value()); + Nesting annotation = clazz.getAnnotation(Nesting.class); + NestingKind expected = annotation == null ? + NestingKind.ANONYMOUS : annotation.value(); + System.out.format("%s is %s%n", name, expected); testClassName(name); names.add(name); } @@ -186,7 +187,11 @@ class ClassNameProber extends JavacTestingAbstractProcessor { typeElt.getKind().toString(), nestingKind.toString()); - if (typeElt.getAnnotation(Nesting.class).value() != nestingKind) { + Nesting annotation = typeElt.getAnnotation(Nesting.class); + NestingKind expected = annotation == null ? + NestingKind.ANONYMOUS : annotation.value(); + + if (expected != nestingKind) { throw new RuntimeException("Mismatch of expected and reported nesting kind."); } } diff --git a/langtools/test/tools/javac/tree/TreePosTest.java b/langtools/test/tools/javac/tree/TreePosTest.java index 8fed3e5c07f..f1723211b9c 100644 --- a/langtools/test/tools/javac/tree/TreePosTest.java +++ b/langtools/test/tools/javac/tree/TreePosTest.java @@ -367,7 +367,9 @@ public class TreePosTest { // and because of inconsistent nesting of left and right of // array declarations: // e.g. int[][] a = new int[2][]; + if (!(encl.tag == REFERENCE && self.tag == ANNOTATED_TYPE)) { check("encl.start <= start", encl, self, encl.start <= self.start); + } check("start <= pos", encl, self, self.start <= self.pos); if (!( (self.tag == TYPEARRAY || isAnnotatedArray(self.tree)) @@ -377,6 +379,8 @@ public class TreePosTest { isAnnotatedArray(encl.tree)) || encl.tag == ANNOTATED_TYPE && self.tag == SELECT + || + encl.tag == REFERENCE && self.tag == ANNOTATED_TYPE )) { check("encl.pos <= start || end <= encl.pos", encl, self, encl.pos <= self.start || self.end <= encl.pos); diff --git a/langtools/test/tools/javac/warnings/6747671/T6747671.out b/langtools/test/tools/javac/warnings/6747671/T6747671.out index 518804d68b5..d3628d22579 100644 --- a/langtools/test/tools/javac/warnings/6747671/T6747671.out +++ b/langtools/test/tools/javac/warnings/6747671/T6747671.out @@ -8,5 +8,5 @@ T6747671.java:32:9: compiler.warn.raw.class.use: T6747671.A, T6747671.A T6747671.java:32:20: compiler.warn.raw.class.use: T6747671.A, T6747671.A T6747671.java:33:16: compiler.warn.raw.class.use: T6747671.A.Z, T6747671.A.Z T6747671.java:36:9: compiler.warn.raw.class.use: @T6747671.TA T6747671.B, T6747671.B -T6747671.java:36:27: compiler.warn.raw.class.use: T6747671.B, T6747671.B +T6747671.java:36:27: compiler.warn.raw.class.use: @T6747671.TA T6747671.B, T6747671.B 11 warnings diff --git a/langtools/test/tools/javac/warnings/suppress/T6480588.out b/langtools/test/tools/javac/warnings/suppress/T6480588.out index 6e6f36739f3..6470e0c7248 100644 --- a/langtools/test/tools/javac/warnings/suppress/T6480588.out +++ b/langtools/test/tools/javac/warnings/suppress/T6480588.out @@ -1,6 +1,6 @@ +T6480588.java:11:2: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package T6480588.java:12:24: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6480588.java:12:51: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package -T6480588.java:11:2: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package T6480588.java:14:12: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6480588.java:14:65: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6480588.java:13:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package @@ -12,7 +12,7 @@ T6480588.java:17:35: compiler.warn.has.been.deprecated: DeprecatedClass, compile T6480588.java:26:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6480588.java:25:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package T6480588.java:26:33: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:28:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package T6480588.java:29:25: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6480588.java:29:52: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package -T6480588.java:28:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package -17 warnings \ No newline at end of file +17 warnings diff --git a/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out index 52a5484ea5e..6d45713e276 100644 --- a/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out +++ b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out @@ -5,28 +5,20 @@ TypeAnnotations.java:14:61: compiler.warn.has.been.deprecated: TA, compiler.misc TypeAnnotations.java:14:13: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:14:44: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:14:33: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:16:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:17:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:20:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:21:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:28:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:29:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:32:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:33:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:21: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package @@ -35,7 +27,6 @@ TypeAnnotations.java:38:17: compiler.warn.has.been.deprecated: TA, compiler.misc TypeAnnotations.java:38:6: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:38:43: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:42:40: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:42:62: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -40 warnings \ No newline at end of file +31 warnings diff --git a/langtools/test/tools/javap/output/RepeatingTypeAnnotations.java b/langtools/test/tools/javap/output/RepeatingTypeAnnotations.java index f78bf128927..a0bc56949b5 100644 --- a/langtools/test/tools/javap/output/RepeatingTypeAnnotations.java +++ b/langtools/test/tools/javap/output/RepeatingTypeAnnotations.java @@ -245,11 +245,11 @@ public class RepeatingTypeAnnotations extends Tester { " @A @A @A String ls = (@B @B @B String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #34(#35=[@#36(),@#36(),@#36()]): CAST, offset=4, type_index=0", - "1: #37(#35=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(#35=[@#36(),@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(#35=[@#38(),@#38(),@#38()]): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #37(#35=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #34(#35=[@#36(),@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -261,15 +261,15 @@ public class RepeatingTypeAnnotations extends Tester { " @A @A @B String ls = (@B @A @B String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #34(#35=[@#36(),@#36()]): CAST, offset=4, type_index=0", - "1: #37(): CAST, offset=4, type_index=0", - "2: #38(#35=[@#37(),@#37()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "3: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "2: #38(#35=[@#37(),@#37()]): CAST, offset=4, type_index=0", + "3: #36(): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #38(#35=[@#37(),@#37()]): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #37(): METHOD_FORMAL_PARAMETER, param_index=1", - "3: #36(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #37(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #37(): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -282,14 +282,14 @@ public class RepeatingTypeAnnotations extends Tester { " }"); verify("RuntimeVisibleTypeAnnotations", "RuntimeInvisibleTypeAnnotations", - "0: #34(): CAST, offset=4, type_index=0", - "1: #35(#36=[@#34(),@#34()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "0: #38(#36=[@#39(),@#39()]): CAST, offset=4, type_index=0", - "1: #39(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "0: #35(#36=[@#34(),@#34()]): METHOD_FORMAL_PARAMETER, param_index=0", - "0: #39(): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1", - "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #36(): CAST, offset=4, type_index=0", + "0: #38(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #39(#35=[@#38(),@#38()]): CAST, offset=4, type_index=0", + "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #40(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -301,13 +301,13 @@ public class RepeatingTypeAnnotations extends Tester { " @A @B @C String ls = (@C @A @B String) o;", " }"); verify("RuntimeVisibleTypeAnnotations", - "0: #34(): CAST, offset=4, type_index=0", - "1: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #34(): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #36(): CAST, offset=4, type_index=0", - "1: #37(): CAST, offset=4, type_index=0", - "2: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "3: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "2: #36(): CAST, offset=4, type_index=0", + "3: #37(): CAST, offset=4, type_index=0", "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0", "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1", "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", @@ -325,13 +325,14 @@ public class RepeatingTypeAnnotations extends Tester { " return (@A @A @A String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=0, type_index=0", - "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=6, type_index=0", - "2: #39(#37=[@#40(),@#40(),@#40()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #36(#37=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=0, type_index=0", + "2: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=6, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #39(#37=[@#40(),@#40(),@#40()]): METHOD_RETURN", - "1: #39(#37=[@#40(),@#40(),@#40()]): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #36(#37=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "2: #36(#37=[@#38(),@#38(),@#38()]): METHOD_RETURN" + ); } } @@ -345,19 +346,19 @@ public class RepeatingTypeAnnotations extends Tester { " }"); verify( "RuntimeInvisibleTypeAnnotations:", - "0: #36(#37=[@#38(),@#38()]): CAST, offset=0, type_index=0", - "1: #39(): CAST, offset=0, type_index=0", - "2: #39(): CAST, offset=6, type_index=0", - "3: #36(#37=[@#38(),@#38()]): CAST, offset=6, type_index=0", - "4: #40(#37=[@#39(),@#39()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "5: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #36(#37=[@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "2: #40(#37=[@#39(),@#39()]): CAST, offset=0, type_index=0", + "3: #38(): CAST, offset=0, type_index=0", + "4: #38(): CAST, offset=6, type_index=0", + "5: #40(#37=[@#39(),@#39()]): CAST, offset=6, type_index=0", "RuntimeInvisibleTypeAnnotations:", - "0: #39(): METHOD_RETURN", - "1: #36(#37=[@#38(),@#38()]): METHOD_RETURN", - "2: #40(#37=[@#39(),@#39()]): METHOD_FORMAL_PARAMETER, param_index=0", - "3: #38(): METHOD_FORMAL_PARAMETER, param_index=0", - "4: #39(): METHOD_FORMAL_PARAMETER, param_index=1", - "5: #38(): METHOD_FORMAL_PARAMETER, param_index=1" + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #36(#37=[@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", + "4: #38(): METHOD_RETURN", + "5: #40(#37=[@#39(),@#39()]): METHOD_RETURN" ); } } @@ -372,21 +373,21 @@ public class RepeatingTypeAnnotations extends Tester { " }"); verify( "RuntimeVisibleTypeAnnotations:", - "0: #36(): CAST, offset=0, type_index=0", - "1: #36(): CAST, offset=6, type_index=0", - "2: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #36(#37=[@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #38(): CAST, offset=0, type_index=0", + "2: #38(): CAST, offset=6, type_index=0", "RuntimeInvisibleTypeAnnotations:", - "0: #40(#38=[@#41(),@#41()]): CAST, offset=0, type_index=0", - "1: #42(#38=[@#43(),@#43()]): CAST, offset=6, type_index=0", - "2: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #40(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #41(#37=[@#40(),@#40()]): CAST, offset=0, type_index=0", + "2: #42(#37=[@#43(),@#43()]): CAST, offset=6, type_index=0", "RuntimeVisibleTypeAnnotations:", - "0: #36(): METHOD_RETURN", - "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", + "0: #36(#37=[@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #38(): METHOD_RETURN", "RuntimeInvisibleTypeAnnotations:", - "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN", - "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1", - "3: #43(): METHOD_FORMAL_PARAMETER, param_index=1" + "0: #40(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #43(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #40(): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #41(#37=[@#40(),@#40()]): METHOD_RETURN" ); } } @@ -401,26 +402,26 @@ public class RepeatingTypeAnnotations extends Tester { " }"); verify( "RuntimeVisibleTypeAnnotations:", - "0: #36(): CAST, offset=0, type_index=0", - "1: #36(): CAST, offset=6, type_index=0", - "2: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #36(): CAST, offset=0, type_index=0", + "2: #36(): CAST, offset=6, type_index=0", "RuntimeInvisibleTypeAnnotations:", - "0: #38(): CAST, offset=0, type_index=0", - "1: #39(): CAST, offset=0, type_index=0", - "2: #39(): CAST, offset=6, type_index=0", - "3: #38(): CAST, offset=6, type_index=0", - "4: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "5: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "2: #38(): CAST, offset=0, type_index=0", + "3: #39(): CAST, offset=0, type_index=0", + "4: #39(): CAST, offset=6, type_index=0", + "5: #38(): CAST, offset=6, type_index=0", "RuntimeVisibleTypeAnnotations:", - "0: #36(): METHOD_RETURN", - "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #36(): METHOD_RETURN", "RuntimeInvisibleTypeAnnotations:", - "0: #38(): METHOD_RETURN", - "1: #39(): METHOD_RETURN", - "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0", - "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", - "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1" + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #39(): METHOD_FORMAL_PARAMETER, param_index=0", + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "3: #38(): METHOD_RETURN", + "4: #39(): METHOD_RETURN" ); } } From 8aa391d4c9f0417d31f9fe8344215935e818a796 Mon Sep 17 00:00:00 2001 From: Andrei Eremeev Date: Fri, 6 Jun 2014 16:08:46 -0400 Subject: [PATCH 21/90] 8042451: Write tests for all possible kinds of type annotation Add new tests for type annotations to improve case coverage Reviewed-by: jjg, emc, abuckley --- .../referenceinfos/ClassExtends.java | 94 +- .../referenceinfos/ClassTypeParam.java | 260 ++- .../ConstructorInvocationTypeArgument.java | 67 + .../referenceinfos/Constructors.java | 117 +- .../referenceinfos/Driver.java | 240 ++- .../referenceinfos/ExceptionParameters.java | 70 +- .../referenceinfos/Fields.java | 158 +- .../referenceinfos/FromSpecification.java | 115 +- .../referenceinfos/Initializers.java | 121 +- .../referenceinfos/Lambda.java | 327 +++- .../MethodInvocationTypeArgument.java | 96 + .../referenceinfos/MethodParameters.java | 230 ++- .../referenceinfos/MethodReceivers.java | 79 +- .../referenceinfos/MethodReturns.java | 268 ++- .../referenceinfos/MethodThrows.java | 53 +- .../referenceinfos/MethodTypeParam.java | 417 +++-- .../referenceinfos/MultiCatch.java | 58 +- .../referenceinfos/NestedTypes.java | 1641 ++++++++++++----- .../referenceinfos/NewObjects.java | 231 ++- .../referenceinfos/ReferenceInfoUtil.java | 152 +- .../referenceinfos/ResourceVariable.java | 79 + .../referenceinfos/TypeCasts.java | 297 ++- .../referenceinfos/TypeTests.java | 141 +- 23 files changed, 3670 insertions(+), 1641 deletions(-) create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ConstructorInvocationTypeArgument.java create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodInvocationTypeArgument.java create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ResourceVariable.java diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java index a38839e527a..8d39967d0ff 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java @@ -25,72 +25,110 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for class extends clauses * @compile -g Driver.java ReferenceInfoUtil.java ClassExtends.java * @run main Driver ClassExtends */ public class ClassExtends { - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1), - @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) - }) + @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1) + @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) public String regularClass() { - return "class Test extends @TA Object implements Cloneable, @TB Runnable {" + return "class %TEST_CLASS_NAME% extends @TA Object implements Cloneable, @TB Runnable {" + " public void run() { } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1, - genericLocation = { 3, 1 }) - }) + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1) + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1) + public String regularClassRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% extends @RTA @RTA Object implements Cloneable, @RTB @RTB Runnable {" + + " public void run() { } }"; + } + + @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1, + genericLocation = { 3, 1 }) public String regularClassExtendsParametrized() { - return "class Test extends HashMap<@TA String, String> implements Cloneable, Map{ } "; + return "class %TEST_CLASS_NAME% extends HashMap<@TA String, String> implements Cloneable, Map{ } "; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1), - @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) - }) + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1, + genericLocation = { 3, 1 }) + public String regularClassExtendsParametrizedRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% extends HashMap<@RTA @RTA String, String> implements Cloneable, Map{ } "; + } + + @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1) + @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) public String abstractClass() { - return "abstract class Test extends @TA Date implements Cloneable, @TB Runnable {" + return "abstract class %TEST_CLASS_NAME% extends @TA Date implements Cloneable, @TB Runnable {" + " public void run() { } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1, - genericLocation = { 3, 1 }) - }) + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1) + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1) + public String abstractClassRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% extends @RTA @RTA Date implements Cloneable, @RTB @RTB Runnable {" + + " public void run() { } }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1, + genericLocation = { 3, 1 }) public String abstractClassExtendsParametrized() { - return "abstract class Test extends HashMap<@TA String, String> implements Cloneable, Map{ } "; + return "abstract class %TEST_CLASS_NAME% extends HashMap<@RTA @RTA String, String> implements Cloneable, Map{ } "; } @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) public String regularInterface() { - return "interface Test extends Cloneable, @TB Runnable { }"; + return "interface %TEST_CLASS_NAME% extends Cloneable, @TB Runnable { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 1) + public String regularInterfaceRepetableAnnotation() { + return "interface %TEST_CLASS_NAME% extends Cloneable, @RTA @RTA Runnable { }"; } @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1, genericLocation = { 3, 1 }) public String regularInterfaceExtendsParametrized() { - return "interface Test extends Cloneable, Map{ } "; + return "interface %TEST_CLASS_NAME% extends Cloneable, Map{ } "; + } + + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1, + genericLocation = { 3, 1 }) + public String regularInterfaceExtendsParametrizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% extends Cloneable, Map{ } "; } @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1) public String regularEnum() { - return "enum Test implements Cloneable, @TB Runnable { TEST; public void run() { } }"; + return "enum %TEST_CLASS_NAME% implements Cloneable, @TB Runnable { TEST; public void run() { } }"; + } + + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1) + public String regularEnumRepeatableAnnotation() { + return "enum %TEST_CLASS_NAME% implements Cloneable, @RTB @RTB Runnable { TEST; public void run() { } }"; } @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1, genericLocation = { 3, 0 }) public String regularEnumExtendsParametrized() { return - "enum Test implements Cloneable, Comparator<@TB String> { TEST; " + "enum %TEST_CLASS_NAME% implements Cloneable, Comparator<@TB String> { TEST; " + "public int compare(String a, String b) { return 0; }}"; } + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1, + genericLocation = { 3, 0 }) + public String regularEnumExtendsParametrizedRepeatableAnnotation() { + return + "enum %TEST_CLASS_NAME% implements Cloneable, Comparator<@RTB @RTB String> { TEST; " + + "public int compare(String a, String b) { return 0; }}"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassTypeParam.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassTypeParam.java index 123cb05c5d9..20885dbffda 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassTypeParam.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassTypeParam.java @@ -25,134 +25,232 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for class type parameters * @compile -g Driver.java ReferenceInfoUtil.java ClassTypeParam.java * @run main Driver ClassTypeParam */ public class ClassTypeParam { - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) - public String regularClass() { - return "class Test<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularClass1() { + return "class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String regularClass2() { - return "class Test<@TA K extends @TB Date, @TC V extends @TE Cloneable> { }"; + return "class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TE Cloneable> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) public String regularClassParameterized() { - return "class Test, V extends @TC List<@TD List<@TE Object>>> { }"; + return "class %TEST_CLASS_NAME%, V extends @TC List<@TD List<@TE Object>>> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) public String regularClassParameterized2() { - return "class Test, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; + return "class %TEST_CLASS_NAME%, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String abstractClass() { - return "abstract class Test<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; + return "abstract class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) public String abstractClassParameterized() { - return "abstract class Test, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; + return "abstract class %TEST_CLASS_NAME%, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String regularInterface() { - return "interface Test<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; + return "interface %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) public String regularInterfaceParameterized() { - return "interface Test, V extends @TC List<@TD List<@TE Object>>> { }"; + return "interface %TEST_CLASS_NAME%, V extends @TC List<@TD List<@TE Object>>> { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) - }) + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) public String regularInterfaceParameterized2() { - return "interface Test, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; + return "interface %TEST_CLASS_NAME%, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }"; } @TADescription(annotation = "TA", type = METHOD_RETURN) public String useInReturn1() { - return "class Test { @TA T m() { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { @TA T m() { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {3, 0}) public String useInReturn2() { - return "class Test { Class<@TA T> m() { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { Class<@TA T> m() { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0, genericLocation = {3, 0}) public String useInParam1() { - return "class Test { void m(Class<@TA T> p) { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { void m(Class<@TA T> p) { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0, genericLocation = {3, 0}) public String useInParam2() { - return "class Test { void m(Class<@TA Object> p) { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { void m(Class<@TA Object> p) { throw new RuntimeException(); } }"; } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularClassRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularClassRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTE @RTE Cloneable> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + public String regularClassParameterizedRepeatableAnnotation() { + return "class %TEST_CLASS_NAME%," + + " V extends @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTGs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + public String regularClassParameterizedRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME%," + + " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String abstractClassRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date," + + " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + public String abstractClassParameterizedRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME%," + + " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularInterfaceRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date," + + " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + public String regularInterfaceParameterizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME%," + + " V extends @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTGs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + public String regularInterfaceParameterizedRepeatableAnnotation2() { + return "interface %TEST_CLASS_NAME%," + + " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String useInReturnRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { @RTA @RTA T m() { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, genericLocation = {3, 0}) + public String useInReturnRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { Class<@RTA @RTA T> m() { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0, genericLocation = {3, 0}) + public String useInParamRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { void m(Class<@RTA @RTA T> p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0, genericLocation = {3, 0}) + public String useInParamRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { void m(Class<@RTA @RTA Object> p) { throw new RuntimeException(); } }"; + } + } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ConstructorInvocationTypeArgument.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ConstructorInvocationTypeArgument.java new file mode 100644 index 00000000000..d69a1652c5f --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ConstructorInvocationTypeArgument.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, 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 8042451 + * @summary Test population of reference info for constructor invocation type argument + * @compile -g Driver.java ReferenceInfoUtil.java ConstructorInvocationTypeArgument.java + * @run main Driver ConstructorInvocationTypeArgument + */ + +import static com.sun.tools.classfile.TypeAnnotation.TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT; + +public class ConstructorInvocationTypeArgument { + + @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 4) + @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + public String generic1() { + return "class %TEST_CLASS_NAME% { %TEST_CLASS_NAME%(int i) { new <@TA T>%TEST_CLASS_NAME%(); }" + + " %TEST_CLASS_NAME%() { <@TB String>this(0); } }"; + } + + @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + public String generic2() { + return "class Super { Super(int i) { } } " + + "class %TEST_CLASS_NAME% extends Super { %TEST_CLASS_NAME%() { <@TA String>super(0); } }"; + } + + @TADescription(annotation = "RTAs", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 4) + @TADescription(annotation = "RTBs", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + public String genericRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { %TEST_CLASS_NAME%(int i) { new <@RTA @RTA T>%TEST_CLASS_NAME%(); }" + + " %TEST_CLASS_NAME%() { <@RTB @RTB String>this(0); } }"; + } + + @TADescription(annotation = "RTAs", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + public String genericRepeatableAnnotation2() { + return "class Super { Super(int i) { } } " + + "class %TEST_CLASS_NAME% extends Super { %TEST_CLASS_NAME%() { <@RTA @RTA String>super(0); } }"; + } +} diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java index 3106341ddc5..78e9acab2ab 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8026791 + * @bug 8026791 8042451 * @summary Test population of reference info for constructor results * @compile -g Driver.java ReferenceInfoUtil.java Constructors.java * @run main Driver Constructors @@ -33,52 +33,44 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; public class Constructors { - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN), - @TADescription(annotation = "TB", type = METHOD_RETURN), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN) + @TADescription(annotation = "TB", type = METHOD_RETURN) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) public String regularClass() { - return "class Test { @TA Test() {}" + - " @TB Test(@TC int b) {} }"; + return "class %TEST_CLASS_NAME% { @TA %TEST_CLASS_NAME%() {}" + + " @TB %TEST_CLASS_NAME%(@TC int b) {} }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}), - @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) - @TestClass("Test$Inner") + @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TestClass("%TEST_CLASS_NAME%$Inner") public String innerClass() { - return "class Test { class Inner {" + + return "class %TEST_CLASS_NAME% { class Inner {" + " @TA Inner() {}" + " @TB Inner(@TC int b) {}" + " } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RECEIVER), - @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), - @TADescription(annotation = "TC", type = METHOD_RECEIVER), - @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) - @TestClass("Test$Inner") + @TADescription(annotation = "TA", type = METHOD_RECEIVER) + @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "TC", type = METHOD_RECEIVER) + @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TestClass("%TEST_CLASS_NAME%$Inner") public String innerClass2() { - return "class Test { class Inner {" + - " @TB Inner(@TA Test Test.this) {}" + - " @TD Inner(@TC Test Test.this, @TE int b) {}" + + return "class %TEST_CLASS_NAME% { class Inner {" + + " @TB Inner(@TA %TEST_CLASS_NAME% %TEST_CLASS_NAME%.this) {}" + + " @TD Inner(@TC %TEST_CLASS_NAME% %TEST_CLASS_NAME%.this, @TE int b) {}" + " } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RECEIVER), - @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}), - @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), - @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}), - @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_RECEIVER) + @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}) + @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}) + @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}) + @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) @TestClass("Outer$Middle$Inner") public String innerClass3() { return "class Outer { class Middle { class Inner {" + @@ -87,24 +79,49 @@ public class Constructors { " } } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, - typeIndex = 0, offset = 4), - @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, - typeIndex = 0, offset = 0) - }) - public String generic1() { - return "class Test { Test(int i) { new <@TA T>Test(); }" + - " Test() { <@TB String>this(0); } }"; + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + @TADescription(annotation = "RTBs", type = METHOD_RETURN) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + public String regularClassRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% { @RTA @RTA %TEST_CLASS_NAME%() {}" + + " @RTB @RTB %TEST_CLASS_NAME%(@RTC @RTC int b) {} }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, - typeIndex = 0, offset = 0) - }) - public String generic2() { - return "class Super { Super(int i) { } } " + - "class Test extends Super { Test() { <@TA String>super(0); } }"; + @TADescription(annotation = "RTAs", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String innerClassRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% { class Inner {" + + " @RTA @RTA Inner() {}" + + " @RTB @RTB Inner(@RTC @RTC int b) {}" + + " } }"; } + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_RECEIVER) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, genericLocation = {1, 0}) + @TADescription(annotation = "RTEs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String innerClassRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { class Inner {" + + " @RTB @RTB Inner(@RTA @RTA %TEST_CLASS_NAME% %TEST_CLASS_NAME%.this) {}" + + " @RTD @RTD Inner(@RTC @RTC %TEST_CLASS_NAME% %TEST_CLASS_NAME%.this, @RTE @RTE int b) {}" + + " } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + @TADescription(annotation = "RTBs", type = METHOD_RECEIVER, genericLocation = {1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}) + @TADescription(annotation = "RTDs", type = METHOD_RECEIVER, genericLocation = {1, 0}) + @TADescription(annotation = "RTEs", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}) + @TADescription(annotation = "RTFs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TestClass("Outer$Middle$Inner") + public String innerClassRepatableAnnotation3() { + return "class Outer { class Middle { class Inner {" + + " @RTC @RTC Inner(@RTA @RTA Outer. @RTB @RTB Middle Middle.this) {}" + + " @RTE @RTE Inner(@RTD @RTD Middle Outer.Middle.this, @RTF @RTF int b) {}" + + " } } }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java index 2493edfbf9e..b6c6aa4fd8f 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java @@ -40,51 +40,75 @@ import com.sun.tools.classfile.ClassFile; import com.sun.tools.classfile.TypeAnnotation; import com.sun.tools.classfile.TypeAnnotation.TargetType; +import static java.lang.String.format; + public class Driver { private static final PrintStream out = System.err; + private final Object testObject; + + public Driver(Class clazz) throws IllegalAccessException, InstantiationException { + testObject = clazz.newInstance(); + } + public static void main(String[] args) throws Exception { if (args.length == 0 || args.length > 1) throw new IllegalArgumentException("Usage: java Driver "); String name = args[0]; - Class clazz = Class.forName(name); - new Driver().runDriver(clazz.newInstance()); + new Driver(Class.forName(name)).runDriver(); } - String[][] extraParamsCombinations = new String[][] { + private final String[][] extraParamsCombinations = new String[][] { new String[] { }, new String[] { "-g" }, }; - protected void runDriver(Object object) throws Exception { + private final String[] retentionPolicies = {RetentionPolicy.CLASS.toString(), RetentionPolicy.RUNTIME.toString()}; + + protected void runDriver() { int passed = 0, failed = 0; - Class clazz = object.getClass(); + Class clazz = testObject.getClass(); out.println("Tests for " + clazz.getName()); // Find methods for (Method method : clazz.getMethods()) { - Map expected = expectedOf(method); - if (expected == null) - continue; - if (method.getReturnType() != String.class) - throw new IllegalArgumentException("Test method needs to return a string: " + method); - String testClass = testClassOf(method); + try { + Map expected = expectedOf(method); + if (expected == null) + continue; + if (method.getReturnType() != String.class) + throw new IllegalArgumentException("Test method needs to return a string: " + method); - for (String[] extraParams : extraParamsCombinations) { - try { - String compact = (String)method.invoke(object); - String fullFile = wrap(compact); - ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); - List actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); - ReferenceInfoUtil.compare(expected, actual, cf); - out.println("PASSED: " + method.getName()); - ++passed; - } catch (Throwable e) { - out.println("FAILED: " + method.getName()); - out.println(" " + e.toString()); - ++failed; + String compact = (String) method.invoke(testObject); + for (String retentionPolicy : retentionPolicies) { + String testClassName = getTestClassName(method, retentionPolicy); + String testClass = testClassOf(method, testClassName); + String fullFile = wrap(compact, new HashMap() {{ + put("%RETENTION_POLICY%", retentionPolicy); + put("%TEST_CLASS_NAME%", testClassName); + }}); + for (String[] extraParams : extraParamsCombinations) { + try { + ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); + List actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); + ReferenceInfoUtil.compare(expected, actual, cf); + out.format("PASSED: %s %s%n", testClassName, Arrays.toString(extraParams)); + ++passed; + } catch (Throwable e) { + out.format("FAILED: %s %s%n", testClassName, Arrays.toString(extraParams)); + out.println(fullFile); + out.println(" " + e.toString()); + e.printStackTrace(out); + ++failed; + } + } } + } catch (IllegalAccessException | InvocationTargetException e) { + out.println("FAILED: " + method.getName()); + out.println(" " + e.toString()); + e.printStackTrace(out); + ++failed; } } @@ -106,7 +130,7 @@ public class Driver { return null; Map result = - new HashMap(); + new HashMap<>(); if (ta != null) result.putAll(expectedOf(ta)); @@ -149,33 +173,42 @@ public class Driver { } private List wrapIntArray(int[] ints) { - List list = new ArrayList(ints.length); + List list = new ArrayList<>(ints.length); for (int i : ints) list.add(i); return list; } - private String testClassOf(Method m) { + private String getTestClassName(Method m, String retentionPolicy) { + return format("%s_%s_%s", testObject.getClass().getSimpleName(), + m.getName(), retentionPolicy); + } + + private String testClassOf(Method m, String testClassName) { TestClass tc = m.getAnnotation(TestClass.class); if (tc != null) { - return tc.value(); + return tc.value().replace("%TEST_CLASS_NAME%", testClassName); } else { - return "Test"; + return testClassName; } } private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception { - File source = writeTestFile(fullFile); - File clazzFile = compileTestFile(source, testClass); + File source = writeTestFile(fullFile, testClass); + File clazzFile = compileTestFile(source, testClass, extraParams); return ClassFile.read(clazzFile); } - protected File writeTestFile(String fullFile) throws IOException { - File f = new File("Test.java"); - PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); - out.println(fullFile); - out.close(); - return f; + protected File writeTestFile(String fullFile, String testClass) throws IOException { + File f = new File(getClassDir(), format("%s.java", testClass)); + try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)))) { + out.println(fullFile); + return f; + } + } + + private String getClassDir() { + return System.getProperty("test.classes", Driver.class.getResource(".").getPath()); } protected File compileTestFile(File f, String testClass, String... extraParams) { @@ -185,20 +218,15 @@ public class Driver { int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()])); if (rc != 0) throw new Error("compilation failed. rc=" + rc); - String path; - if (f.getParent() != null) { - path = f.getParent(); - } else { - path = ""; - } - - return new File(path + testClass + ".class"); + String path = f.getParent() != null ? f.getParent() : ""; + return new File(path, format("%s.class", testClass)); } - private String wrap(String compact) { + private String wrap(String compact, Map replacements) { StringBuilder sb = new StringBuilder(); // Automatically import java.util + sb.append("\nimport java.io.*;"); sb.append("\nimport java.util.*;"); sb.append("\nimport java.lang.annotation.*;"); @@ -208,7 +236,7 @@ public class Driver { && !compact.contains("interface") && !compact.contains("enum"); if (isSnippet) - sb.append("class Test {\n"); + sb.append("class %TEST_CLASS_NAME% {\n"); sb.append(compact); sb.append("\n"); @@ -224,41 +252,102 @@ public class Driver { } // create A ... F annotation declarations - sb.append("\n@interface A {}"); - sb.append("\n@interface B {}"); - sb.append("\n@interface C {}"); - sb.append("\n@interface D {}"); - sb.append("\n@interface E {}"); - sb.append("\n@interface F {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface A {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface B {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface C {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface D {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface E {}"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface F {}"); // create TA ... TF proper type annotations sb.append("\n"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TB {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TC {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TD {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TE {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TF {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TG {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TH {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TI {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TJ {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TK {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TL {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TM {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + " @Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TA {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TB {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TC {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TD {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TE {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TF {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TG {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TH {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TI {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TJ {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TK {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TL {}"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TM {}"); - // create RTA, RTAs, RTB, RTBs for repeating type annotations + // create RT?, RT?s for repeating type annotations sb.append("\n"); - sb.append("\n@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTA {}"); - sb.append("\n@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTB {}"); + sb.append("\n@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTA {}"); + sb.append("\n@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTB {}"); + sb.append("\n@Repeatable(RTCs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTC {}"); + sb.append("\n@Repeatable(RTDs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTD {}"); + sb.append("\n@Repeatable(RTEs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTE {}"); + sb.append("\n@Repeatable(RTFs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTF {}"); + sb.append("\n@Repeatable(RTGs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTG {}"); + sb.append("\n@Repeatable(RTHs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTH {}"); + sb.append("\n@Repeatable(RTIs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTI {}"); + sb.append("\n@Repeatable(RTJs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJ {}"); + sb.append("\n@Repeatable(RTKs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTK {}"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTAs { RTA[] value(); }"); - sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTBs { RTB[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTAs { RTA[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTBs { RTB[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTCs { RTC[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTDs { RTD[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTEs { RTE[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTFs { RTF[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTGs { RTG[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTHs { RTH[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTIs { RTI[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJs { RTJ[] value(); }"); + sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + + "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTKs { RTK[] value(); }"); - sb.append("\n@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})"); - sb.append("\n@interface Decl {}"); + sb.append("\n@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD," + + "ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})"); + sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface Decl {}"); - return sb.toString(); + return replaceAll(sb.toString(), replacements); + } + + private String replaceAll(String src, Map replacements) { + for (Map.Entry entry : replacements.entrySet()) { + src = src.replace(entry.getKey(), entry.getValue()); + } + return src; } public static final int NOT_SET = -888; @@ -267,6 +356,7 @@ public class Driver { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) +@Repeatable(TADescriptions.class) @interface TADescription { String annotation(); @@ -296,5 +386,5 @@ public class Driver { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface TestClass { - String value() default "Test"; + String value(); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java index f41cff9ab11..d91e92d9138 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java @@ -25,7 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test - * @bug 8028576 + * @bug 8028576 8042451 * @summary Test population of reference info for exception parameters * @author Werner Dietl * @compile -g Driver.java ReferenceInfoUtil.java ExceptionParameters.java @@ -43,11 +43,9 @@ public class ExceptionParameters { return "void finalException() { try { new Object(); } catch(final @TA Exception e) { } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) public String multipleExceptions1() { return "void multipleExceptions() { " + "try { new Object(); } catch(@TA Exception e) { }" + @@ -56,11 +54,9 @@ public class ExceptionParameters { " }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) public String multipleExceptions2() { return "void multipleExceptions() { " + " try { new Object(); " + @@ -71,11 +67,9 @@ public class ExceptionParameters { "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) public String multipleExceptions3() { return "void multipleExceptions() { " + " try { new Object(); " + @@ -87,4 +81,48 @@ public class ExceptionParameters { " }" + "}"; } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + public String exceptionRepeatableAnnoation() { + return "void exception() { try { new Object(); } catch(@RTA @RTA Exception e) { } }"; + } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTCs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + public String multipleExceptionsRepeatableAnnotation1() { + return "void multipleExceptions() { " + + "try { new Object(); } catch(@RTA @RTA Exception e) { }" + + "try { new Object(); } catch(@RTB @RTB Exception e) { }" + + "try { new Object(); } catch(@RTC @RTC Exception e) { }" + + " }"; + } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTCs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + public String multipleExceptionsRepeatableAnnotation2() { + return "void multipleExceptions() { " + + " try { new Object(); " + + " try { new Object(); " + + " try { new Object(); } catch(@RTA @RTA Exception e) { }" + + " } catch(@RTB @RTB Exception e) { }" + + " } catch(@RTC @RTC Exception e) { }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTCs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + public String multipleExceptionsRepeatableAnnotation3() { + return "void multipleExceptions() { " + + " try { new Object(); " + + " } catch(@RTA @RTA Exception e1) { "+ + " try { new Object(); " + + " } catch(@RTB @RTB Exception e2) {" + + " try { new Object(); } catch(@RTC @RTC Exception e3) { }" + + " }" + + " }" + + "}"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java index 7667e243807..1a531c30ffe 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for field * @compile -g Driver.java ReferenceInfoUtil.java Fields.java * @run main Driver Fields @@ -41,37 +42,31 @@ public class Fields { return "@TA Object test;"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TD", type = FIELD, - genericLocation = { 3, 1, 3, 0 }) - }) + @TADescription(annotation = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) public String fieldAsParametrized() { return "@TA Map<@TB String, @TC List<@TD String>> test;"; } - @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 = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0 }) public String fieldAsArray() { return "@TC String @TA [] @TB [] test;"; } - @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 = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 0, 0, 0, 0 }) public String fieldAsArrayOld() { return "@TC String test @TA [] @TB [];"; } @@ -88,39 +83,108 @@ public class Fields { // Smoke tests @TADescription(annotation = "TA", type = FIELD) - public String interfacefieldAsObject() { - return "interface Test { @TA String test = null; }"; + public String interfaceFieldAsObject() { + return "interface %TEST_CLASS_NAME% { @TA String test = null; }"; } @TADescription(annotation = "TA", type = FIELD) - public String abstractfieldAsObject() { - return "abstract class Test { @TA String test; }"; + public String abstractFieldAsObject() { + return "abstract class %TEST_CLASS_NAME% { @TA String test; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TD", type = FIELD, - genericLocation = { 3, 1, 3, 0 }) - }) - public String interfacefieldAsParametrized() { - return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test = null; }"; + @TADescription(annotation = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) + public String interfaceFieldAsParametrized() { + return "interface %TEST_CLASS_NAME% { @TA Map<@TB String, @TC List<@TD String>> test = null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TD", type = FIELD, - genericLocation = { 3, 1, 3, 0 }) - }) + @TADescription(annotation = "TA", type = FIELD) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) public String staticFieldAsParametrized() { return "static @TA Map<@TB String, @TC List<@TD String>> test;"; } + + @TADescription(annotation = "RTAs", type = FIELD) + public String fieldAsPrimitiveRepeatableAnnotation() { + return "@RTA @RTA int test;"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + public String fieldAsObjectRepeatableAnnotation() { + return "@RTA @RTA Object test;"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) + public String fieldAsParametrizedRepeatableAnnotation() { + return "@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test;"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = { 0, 0, 0, 0 }) + public String fieldAsArrayRepeatableAnnotation() { + return "@RTC @RTC String @RTA @RTA [] @RTB @RTB [] test;"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = { 0, 0 }) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = { 0, 0, 0, 0 }) + public String fieldAsArrayOldRepeatableAnnotation() { + return "@RTC @RTC String test @RTA @RTA [] @RTB @RTB [];"; + } + + // Smoke tests + @TADescription(annotation = "RTAs", type = FIELD) + public String interfaceFieldAsObjectRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { @RTA @RTA String test = null; }"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + public String abstractFieldAsObjectRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% { @RTA @RTA String test; }"; + } + + @TADescription(annotation = "RTAs", type = FIELD) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) + public String interfaceFieldAsParametrizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test = null; }"; + } + + + @TADescription(annotation = "RTAs", type = FIELD) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = { 3, 1, 3, 0 }) + public String staticFieldAsParametrizedRepeatableAnnotation() { + return "static @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test;"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/FromSpecification.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/FromSpecification.java index 7f4c6fdbfd6..6d5bfd4a3e0 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/FromSpecification.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/FromSpecification.java @@ -25,98 +25,89 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test that the examples from the manual are stored as expected * @compile -g Driver.java ReferenceInfoUtil.java FromSpecification.java * @run main Driver FromSpecification */ public class FromSpecification { - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 2, 0}, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 1}, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 2, 0}, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 1}, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, genericLocation = {3, 1, 3, 0}, paramIndex = 0) - }) public String testSpec1() { return "void test(@TA Map<@TB ? extends @TC String, @TD List<@TE Object>> a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0}, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0}, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, genericLocation = {0, 0, 0, 0, 0, 0}, paramIndex = 0) - }) public String testSpec2() { return "void test(@TI String @TF [] @TG [] @TH [] a) { }"; } // Note first "1, 0" for top-level class Test. - @TADescriptions({ - @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TL", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TM", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TL", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TM", type = METHOD_FORMAL_PARAMETER, genericLocation = {1, 0}, paramIndex = 0) - }) public String testSpec3() { - return "class Test { class O1 { class O2 { class O3 { class NestedStatic {} } } }" + + return "class %TEST_CLASS_NAME% { class O1 { class O2 { class O3 { class NestedStatic {} } } }" + "void test(@TM O1.@TL O2.@TK O3.@TJ NestedStatic a) { } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 3, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 3, 0, 0, 0, 0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 1}, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 3, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 3, 0, 0, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 1}, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, genericLocation = {3, 1, 3, 0}, paramIndex = 0) - }) public String testSpec4() { return "void test(@TA Map<@TB Comparable<@TF Object @TC [] @TD [] @TE []>, @TG List<@TH String>> a) { }"; } // Note first "1, 0" for top-level class Test. - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0, 1, 0, 3, 1}, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, genericLocation = {1, 0}, paramIndex = 0) - }) public String testSpec5() { - return "class Test { class O1 { class O2 { class O3 { class Nested {} } } }" + + return "class %TEST_CLASS_NAME% { class O1 { class O2 { class O3 { class Nested {} } } }" + "void test(@TH O1.@TE O2<@TF String, @TG String>.@TD O3.@TA Nested<@TB String, @TC String> a) { } }"; } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java index d42c4f74fc9..bab51f10ad3 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java @@ -25,7 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test - * @bug 8013852 + * @bug 8013852 8042451 * @summary Test population of reference info for instance and class initializers * @author Werner Dietl * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java @@ -33,63 +33,98 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; */ public class Initializers { - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) - public String instanceInit1() { - return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }"; + public String instanceInit1() { + return "class %TEST_CLASS_NAME% { { Object o = new @TA ArrayList<@TB String>(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TD", type = NEW, + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) - public String instanceInit2() { - return "class Test { Object f = new @TA ArrayList<@TB String>(); " + + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TD", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String instanceInit2() { + return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + " { Object o = new @TC ArrayList<@TD String>(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) - public String staticInit1() { - return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }"; + public String staticInit1() { + return "class %TEST_CLASS_NAME% { static { Object o = new @TA ArrayList<@TB String>(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TD", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TF", type = NEW, + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) - public String staticInit2() { - return "class Test { Object f = new @TA ArrayList<@TB String>(); " + + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TD", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TF", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String staticInit2() { + return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + " static Object g = new @TC ArrayList<@TD String>(); " + " static { Object o = new @TE ArrayList<@TF String>(); } }"; } - // TODO: test interaction with several constructors, especially non-initial constuctors. - // I don't think this kind of test is possible here. - - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, - typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE), - }) - public String lazyConstantCast1() { - return "class Test { public static final Object o = (@TA Object) null; }"; + @TADescription(annotation = "TA", type = CAST, + typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String lazyConstantCast1() { + return "class %TEST_CLASS_NAME% { public static final Object o = (@TA Object) null; }"; } + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String instanceInitRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTDs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String instanceInitRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + + " { Object o = new @RTC @RTC ArrayList<@RTD @RTD String>(); } }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String staticInitRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { static { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTDs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTFs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String staticInitRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + + " static Object g = new @RTC @RTC ArrayList<@RTD @RTD String>(); " + + " static { Object o = new @RTE @RTE ArrayList<@RTF @RTF String>(); } }"; + } + + // TODO: test interaction with several constructors, especially non-initial constructors. + // I don't think this kind of test is possible here. + + @TADescription(annotation = "RTAs", type = CAST, + typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String lazyConstantCastRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { public static final Object o = (@RTA @RTA Object) null; }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java index ccf8f463c95..139f08b595b 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8008077 8029721 + * @bug 8008077 8029721 8042451 8043974 * @summary Test population of reference info for lambda expressions * javac crash for annotated parameter type of lambda in a field * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java @@ -35,64 +35,58 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; public class Lambda { - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = METHOD_REFERENCE, + @TADescription(annotation = "TA", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) public String returnMethodRef1() { return "class Lambda {" + " public String getName() { return \"Lambda!\"; }" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " java.util.function.Function lambda() {" + " return @TA @TB Lambda::getName;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = METHOD_REFERENCE, + @TADescription(annotation = "TA", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = METHOD_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TD", type = METHOD_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TE", type = METHOD_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TD", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, genericLocation = { 3, 1 }) - }) + @TADescription(annotation = "TE", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 1}) public String returnMethodRef2() { return "class Lambda {" + " public String getName() { return \"Lambda!\"; }" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " java.util.function.Function, String> lambda() {" + " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "CTA", type = METHOD_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "CTB", type = METHOD_REFERENCE, + @TADescription(annotation = "CTA", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "CTB", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "CTC", type = METHOD_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "CTC", type = METHOD_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 1 }) - }) + genericLocation = { 3, 1 }) public String returnMethodRef3() { return "class Lambda {" + @@ -114,7 +108,7 @@ public class Lambda { " String name();" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " java.util.function.Function, String> lambda() {" + " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" + " }" + @@ -122,64 +116,58 @@ public class Lambda { } - @TADescriptions({ - @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) public String returnConstructorRef1() { return "class Lambda {" + " Lambda() { }" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " Runnable lambda() {" + " return @TA @TB Lambda::new;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, genericLocation = { 3, 1 }) - }) + @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 1 }) public String returnConstructorRef2() { return "class Lambda {" + " Lambda() { }" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " Runnable lambda() {" + " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE, - offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE, + @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 0 }), - @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = { 3, 1 }) - }) + genericLocation = { 3, 1 }) public String returnConstructorRef3() { return "class Lambda {" + @@ -201,7 +189,7 @@ public class Lambda { " String name();" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " Runnable lambda() {" + " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" + " }" + @@ -209,14 +197,12 @@ public class Lambda { } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT, + @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT, + typeIndex = 0) + @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT, offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) - }) public String returnMethodRefTA1() { return "interface Lambda {" + @@ -227,21 +213,19 @@ public class Lambda { " public void generic(S p1, T p2) {}" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " Lambda lambda(LambdaImpl r) {" + " return r::<@TA Object, @TB Object>generic;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, + @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, + typeIndex = 0) + @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) - }) public String returnConstructorRefTA2() { return "interface Lambda {" + @@ -253,57 +237,222 @@ public class Lambda { " public void generic(S p1, T p2) {}" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " Lambda lambda() {" + " return LambdaImpl::<@TA Object, @TB Object>new;" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - paramIndex = 1), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - paramIndex = 1, genericLocation = { 3, 0 }), - @TADescription(annotation = "TD", type = LOCAL_VARIABLE, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + paramIndex = 1) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + paramIndex = 1, genericLocation = { 3, 0 }) + @TADescription(annotation = "TD", type = LOCAL_VARIABLE, lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, lvarLength = ReferenceInfoUtil.IGNORE_VALUE, - lvarIndex = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TE", type = CAST, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TE", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0) - }) public String returnLambdaExpr1() { return "interface LambdaInt {" + " void lambda(Object p1, List p2);" + "}" + - "class Test {" + + "class %TEST_CLASS_NAME% {" + " LambdaInt getLambda() {" + " return (@TA Object x, @TB List<@TC Object> y) -> { @TD Object l = null; System.out.println((@TE Object) l); };" + " }" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - paramIndex = 0)}) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) public String lambdaField1() { return - "class Test {" + + "class %TEST_CLASS_NAME% {" + " java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - paramIndex = 0)}) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) public String lambdaField2() { return - "class Test {" + + "class %TEST_CLASS_NAME% {" + " static java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" + "}"; } + + @TADescription(annotation = "RTAs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnMethodRefRepeatableAnnotation1() { + return + "class Lambda {" + + " public String getName() { return \"Lambda!\"; }" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " java.util.function.Function lambda() {" + + " return @RTA @RTA Lambda::getName;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTDs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTEs", type = METHOD_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 1}) + public String returnMethodRefRepeatableAnnotation2() { + return + "class Lambda {" + + " public String getName() { return \"Lambda!\"; }" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " java.util.function.Function, String> lambda() {" + + " return @RTA @RTA Lambda<@RTB @RTB @RTC @RTC Integer, @RTD @RTD @RTE @RTE Float>::getName;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnConstructorRefRepeatable1() { + return + "class Lambda {" + + " Lambda() { }" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " Runnable lambda() {" + + " return @RTA @RTA Lambda::new;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = CONSTRUCTOR_REFERENCE, + offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = { 3, 1 }) + public String returnConstructorRefRepeatable2() { + return + "class Lambda {" + + " Lambda() { }" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " Runnable lambda() {" + + " return @RTA @RTA Lambda<@RTB @RTB Integer, @RTC @RTC Float>::new;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_REFERENCE_TYPE_ARGUMENT, + offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_REFERENCE_TYPE_ARGUMENT, + offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 1) + public String returnMethodRefTARepeatableAnnotation1() { + return + "interface Lambda {" + + " void generic(S p1, T p2);" + + "}" + + + "class LambdaImpl implements Lambda {" + + " public void generic(S p1, T p2) {}" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " Lambda lambda(LambdaImpl r) {" + + " return r::<@RTA @RTA Object, @RTB @RTB Object>generic;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, + offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, + offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 1) + public String returnConstructorRefTARepeatableAnnotation2() { + return + "interface Lambda {" + + " void generic(S p1, T p2);" + + "}" + + + "class LambdaImpl implements Lambda {" + + " LambdaImpl(S p1, T p2) {}" + + " public void generic(S p1, T p2) {}" + + "}" + + + "class %TEST_CLASS_NAME% {" + + " Lambda lambda() {" + + " return LambdaImpl::<@RTA @RTA Object, @RTB @RTB Object>new;" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 1, genericLocation = { 3, 0 }) + @TADescription(annotation = "RTDs", type = LOCAL_VARIABLE, + lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, + lvarLength = ReferenceInfoUtil.IGNORE_VALUE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTEs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnLambdaExprRepeatableAnnotation1() { + return + "interface LambdaInt {" + + " void lambda(Object p1, List p2);" + + "}" + + "class %TEST_CLASS_NAME% {" + + " LambdaInt getLambda() {" + + " return (@RTA @RTA Object x, @RTB @RTB List<@RTC @RTC Object> y) ->" + + " { @RTD @RTD Object l = null; System.out.println((@RTE @RTE Object) l); };" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) + public String lambdaFieldRepeatableAnnotation1() { + return + "class %TEST_CLASS_NAME% {" + + " java.util.function.IntUnaryOperator field = (@RTA @RTA int y) -> 1;" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) + public String lambdaFieldRepeatableAnnotation2() { + return + "class %TEST_CLASS_NAME% {" + + " static java.util.function.IntUnaryOperator field = (@RTA @RTA int y) -> 1;" + + "}"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodInvocationTypeArgument.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodInvocationTypeArgument.java new file mode 100644 index 00000000000..30dd2843188 --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodInvocationTypeArgument.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2009, 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 8042451 + * @summary Test population of reference info for method invocation type arguments + * @compile -g Driver.java ReferenceInfoUtil.java MethodInvocationTypeArgument.java + * @run main Driver MethodInvocationTypeArgument + */ + +import static com.sun.tools.classfile.TypeAnnotation.TargetType.METHOD_INVOCATION_TYPE_ARGUMENT; +import static java.lang.System.lineSeparator; + +public class MethodInvocationTypeArgument { + + @TADescription(annotation = "TA", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 4) + @TADescription(annotation = "TB", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 4) + @TADescription(annotation = "TC", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 2, offset = 4) + @TADescription(annotation = "TD", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 24) + @TADescription(annotation = "TE", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 24) + @TADescription(annotation = "TF", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 2, offset = 24) + public String genericMethod() { + return + "public void function(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() + + "{ new %TEST_CLASS_NAME%().<@TA Integer, @TB String, @TC Double>function(0, \"\", 0.0); " + lineSeparator() + + " this.<@TD Integer, @TE String, @TF Double>function(0, \"\", 0.0); }"; + } + + @TADescription(annotation = "TA", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + @TADescription(annotation = "TB", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 0) + @TADescription(annotation = "TC", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 2, offset = 0) + public String genericStaticMethod() { + return + "public static void staticFunction(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() + + "static { %TEST_CLASS_NAME%.<@TA Integer, @TB String, @TC Double>staticFunction(0, \"\", 0.0); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 4) + @TADescription(annotation = "RTBs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 4) + @TADescription(annotation = "RTCs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 20) + @TADescription(annotation = "RTDs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 20) + public String genericMethodRepeatableAnnotation() { + return + "public void function(T1 t1, T2 t2) {}" + lineSeparator() + + "{ new %TEST_CLASS_NAME%().<@RTA @RTA Integer, @RTB @RTB String>" + + "function(0, \"\"); " + lineSeparator() + + " this.<@RTC @RTC Integer, @RTD @RTD String>function(0, \"\"); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 0, offset = 0) + @TADescription(annotation = "RTBs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 1, offset = 0) + @TADescription(annotation = "RTCs", type = METHOD_INVOCATION_TYPE_ARGUMENT, + typeIndex = 2, offset = 0) + public String genericStaticMethodRepeatableAnnotation() { + return + "public static void staticFunction(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() + + "static { %TEST_CLASS_NAME%.<@RTA @RTA Integer, @RTB @RTB String, @RTC @RTC Double>staticFunction(0, \"\", 0.0); }"; + } + +} diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java index d4cc4186a71..b72e9cee7a5 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for method parameters * @compile -g Driver.java ReferenceInfoUtil.java MethodParameters.java * @run main Driver MethodParameters @@ -41,97 +42,83 @@ public class MethodParameters { return "void test(Object b, @TA Object a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 0 }, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1 }, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) - }) public String methodParamAsParametrized() { return "void test(@TA Map<@TB String, @TC List<@TD String>> a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 0 }, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 0, 2, 0 }, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1 }, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1, 3, 0 }, paramIndex = 0), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0 }, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0, 2, 0 }, paramIndex = 0), - @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1 }, paramIndex = 0), - @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0, 2, 0 }, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0 }, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0, 2, 0 }, paramIndex = 0) + @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1 }, paramIndex = 0) + @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1, 2, 0 }, paramIndex = 0) - }) public String methodParamAsWildcard() { return "void test(@TA Map<@TB ? extends @TC String," + " @TD List<@TE ? extends @TF Map<@TG ? super @TH String," + " @TI ? extends @TJ Object>>> a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) - }) public String methodParamAsArray() { return "void test(Object b, @TC String @TA [] @TB [] a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, genericLocation = { 0, 0 }, paramIndex = 1) - }) public String methodParamAsArray2() { return "void test(Object b, @TA @TB String [] a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, genericLocation = { 0, 0 }, paramIndex = 1) - }) public String methodParamAsArray3() { return "void test(Object b, @TA @TB @TC String [] a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) - }) public String methodParamAsVararg() { return "void test(Object b, @TC String @TA [] @TB ... a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 0, 0 }, paramIndex = 1), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) - }) public String methodParamAsFQVararg() { return "void test(Object b, java.lang.@TC String @TA [] @TB ... a) { }"; } @@ -148,26 +135,125 @@ public class MethodParameters { // Smoke tests @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - public String interfacemethodParamAsObject() { - return "interface Test { void test(@TA Object a); }"; + public String interfaceMethodParamAsObject() { + return "interface %TEST_CLASS_NAME% { void test(@TA Object a); }"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 2) - public String abstractmethodParamAsObject() { - return "abstract class Test { abstract void test(Object b, Object c, @TA Object a); }"; + public String abstractMethodParamAsObject() { + return "abstract class %TEST_CLASS_NAME% { abstract void test(Object b, Object c, @TA Object a); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 0 }, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = { 3, 1 }, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) - }) - public String interfacemethodParamAsParametrized() { - return "interface Test { void test(@TA Map<@TB String, @TC List<@TD String>> a); }"; + public String interfaceMethodParamAsParametrized() { + return "interface %TEST_CLASS_NAME% { void test(@TA Map<@TB String, @TC List<@TD String>> a); }"; } + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + public String methodParamAsPrimitiveRepeatableAnnotation() { + return "void test(@RTA @RTA int a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + public String methodParamAsObjectRepeatableAnnotation() { + return "void test(Object b, @RTA @RTA Object a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) + public String methodParamAsParametrizedRepeatableAnnotation() { + return "void test(@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0, 2, 0 }, paramIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) + @TADescription(annotation = "RTFs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0) + public String methodParamAsWildcardRepeatableAnnotation() { + return "void test(@RTA @RTA Map<@RTB @RTB ? extends @RTC @RTC String," + + " @RTD @RTD List<@RTE @RTE ? super @RTF @RTF String>> a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) + public String methodParamAsArrayRepeatableAnnotation() { + return "void test(Object b, @RTC @RTC String @RTA @RTA [] @RTB @RTB [] a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + public String methodParamAsArrayRepeatableAnnotation2() { + return "void test(Object b, @RTA @RTA @RTB @RTB String [] a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + public String methodParamAsArrayRepeatableAnnotation3() { + return "void test(Object b, @RTA @RTA @RTB @RTB String [] a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) + public String methodParamAsVarargRepeatableAnnoattion() { + return "void test(Object b, @RTC @RTC String @RTA @RTA [] @RTB @RTB ... a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0 }, paramIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) + public String methodParamAsFQVarargRepeatableAnnotation() { + return "void test(Object b, java.lang.@RTC @RTC String @RTA @RTA [] @RTB @RTB ... a) { }"; + } + + // Smoke tests + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + public String interfaceMethodParamAsObjectRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { void test(@RTA @RTA Object a); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 2) + public String abstractMethodParamAsObjectRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% { abstract void test(Object b, Object c, @RTA @RTA Object a); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 0 }, paramIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1 }, paramIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER, + genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) + public String interfaceMethodParamAsParametrizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { void test(@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> a); }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReceivers.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReceivers.java index 8aefdd333cd..cab0de4e279 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReceivers.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReceivers.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for method receivers * @compile -g Driver.java ReferenceInfoUtil.java MethodReceivers.java * @run main Driver MethodReceivers @@ -33,47 +34,87 @@ public class MethodReceivers { @TADescription(annotation = "TA", type = METHOD_RECEIVER) public String regularMethod() { - return "class Test { void test(@TA Test this) { } }"; + return "class %TEST_CLASS_NAME% { void test(@TA %TEST_CLASS_NAME% this) { } }"; } @TADescription(annotation = "TA", type = METHOD_RECEIVER) public String abstractMethod() { - return "abstract class Test { abstract void test(@TA Test this); }"; + return "abstract class %TEST_CLASS_NAME% { abstract void test(@TA %TEST_CLASS_NAME% this); }"; } @TADescription(annotation = "TA", type = METHOD_RECEIVER) public String interfaceMethod() { - return "interface Test { void test(@TA Test this); }"; + return "interface %TEST_CLASS_NAME% { void test(@TA %TEST_CLASS_NAME% this); }"; } @TADescription(annotation = "TA", type = METHOD_RECEIVER) public String regularWithThrows() { - return "class Test { void test(@TA Test this) throws Exception { } }"; - } - - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RECEIVER, - genericLocation = {}), - @TADescription(annotation = "TB", type = METHOD_RECEIVER, - genericLocation = {1, 0}) - }) - @TestClass("TestOuter$TestInner") - public String nestedtypes1() { - return "class TestOuter { class TestInner { void test(@TA TestOuter. @TB TestInner this) { } } }"; + return "class %TEST_CLASS_NAME% { void test(@TA %TEST_CLASS_NAME% this) throws Exception { } }"; } @TADescription(annotation = "TA", type = METHOD_RECEIVER, genericLocation = {}) - @TestClass("TestOuter$TestInner") + @TADescription(annotation = "TB", type = METHOD_RECEIVER, + genericLocation = {1, 0}) + @TestClass("%TEST_CLASS_NAME%$TestInner") + public String nestedtypes1() { + return "class %TEST_CLASS_NAME% { class TestInner { void test(@TA %TEST_CLASS_NAME%. @TB TestInner this) { } } }"; + } + + @TADescription(annotation = "TA", type = METHOD_RECEIVER, + genericLocation = {}) + @TestClass("%TEST_CLASS_NAME%$TestInner") public String nestedtypes2() { - return "class TestOuter { class TestInner { void test(@TA TestOuter.TestInner this) { } } }"; + return "class %TEST_CLASS_NAME% { class TestInner { void test(@TA %TEST_CLASS_NAME%.TestInner this) { } } }"; } @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}) - @TestClass("TestOuter$TestInner") + @TestClass("%TEST_CLASS_NAME%$TestInner") public String nestedtypes3() { - return "class TestOuter { class TestInner { void test(TestOuter. @TB TestInner this) { } } }"; + return "class %TEST_CLASS_NAME% { class TestInner { void test(%TEST_CLASS_NAME%. @TB TestInner this) { } } }"; } + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + public String regularMethodRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% { void test(@RTA @RTA %TEST_CLASS_NAME% this) { } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + public String abstractMethodRepeatablaAnnotation() { + return "abstract class %TEST_CLASS_NAME% { abstract void test(@RTA @RTA %TEST_CLASS_NAME% this); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + public String interfaceMethodRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { void test(@RTA @RTA %TEST_CLASS_NAME% this); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER) + public String regularWithThrowsRepeatableAnnotation() { + return "class %TEST_CLASS_NAME% { void test(@RTA @RTA %TEST_CLASS_NAME% this) throws Exception { } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = METHOD_RECEIVER, + genericLocation = {1, 0}) + @TestClass("%TEST_CLASS_NAME%$TestInner") + public String nestedtypesRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { class TestInner { void test(@RTA @RTA %TEST_CLASS_NAME%. @RTB @RTB TestInner this) { } } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RECEIVER, + genericLocation = {}) + @TestClass("%TEST_CLASS_NAME%$TestInner") + public String nestedtypesRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { class TestInner { void test(@RTA @RTA %TEST_CLASS_NAME%.TestInner this) { } } }"; + } + + @TADescription(annotation = "RTBs", type = METHOD_RECEIVER, + genericLocation = {1, 0}) + @TestClass("%TEST_CLASS_NAME%$TestInner") + public String nestedtypesRepeatableAnnotation3() { + return "class %TEST_CLASS_NAME% { class TestInner { void test(%TEST_CLASS_NAME%. @RTB @RTB TestInner this) { } } }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java index e31c6327430..c3fcd771453 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodReturns.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for method return * @compile -g Driver.java ReferenceInfoUtil.java MethodReturns.java * @run main Driver MethodReturns @@ -42,37 +43,31 @@ public class MethodReturns { return "@TA Object test() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = { 3, 1, 3, 0 }) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 1 }) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 3, 1, 3, 0 }) public String methodReturnAsParametrized() { return "@TA Map<@TB String, @TC List<@TD String>> test() { 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 = "TA", type = METHOD_RETURN) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }) public String methodReturnAsArray() { return "@TC String @TA [] @TB [] test() { 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 = "TA", type = METHOD_RETURN) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 0, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }) public String methodReturnAsArrayOld() { return "@TC String test() @TA [] @TB [] { return null; }"; } @@ -90,97 +85,206 @@ public class MethodReturns { // Smoke tests @TADescription(annotation = "TA", type = METHOD_RETURN) public String interfaceMethodReturnAsObject() { - return "interface Test { @TA Object test(); }"; + return "interface %TEST_CLASS_NAME% { @TA Object test(); }"; } @TADescription(annotation = "TA", type = METHOD_RETURN) public String abstractMethodReturnAsObject() { - return "abstract class Test { abstract @TA Object test(); }"; + return "abstract class %TEST_CLASS_NAME% { abstract @TA Object test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 1 }), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = { 3, 1, 3, 0 }) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 1 }) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 3, 1, 3, 0 }) public String interfaceMethodReturnAsParametrized() { - return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test(); }"; + return "interface %TEST_CLASS_NAME% { @TA Map<@TB String, @TC List<@TD String>> test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = { 3, 0 }), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0 }), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }), - @TADescription(annotation = "TE", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }), - @TADescription(annotation = "TF", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "TE", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "TF", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) public String methodReturnAsNestedWildcard() { return "Set<@TA ? extends @TB GOuter. @TC GInner<@TD String, @TE ? super @TF Object>> entrySet() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = { 3, 0, 1, 0, 3, 0 }), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0, 1, 0, 3, 1 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) public String methodReturnAsNestedWildcard2() { return "class GOuter { class GInner {} } " + - "class Test { Set.GInner<@TA K, @TB ? extends @TC Object>> entrySet() { return null; } }"; + "class %TEST_CLASS_NAME% { Set.GInner<@TA K, @TB ? extends @TC Object>> entrySet() { return null; } }"; } - @TADescriptions({ - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0 }), - }) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) public String methodReturnAsNestedWildcard3() { return "Set. @TC GInner> entrySet() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0 }), - }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) public String methodReturnAsNestedWildcard4() { return "Set. @TC GInner> entrySet() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0 }), - }) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) public String methodReturnAsNestedWildcard5() { return "Set entrySet() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = { 3, 0, 2, 0, 1, 0 }), - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) public String methodReturnAsNestedWildcard6() { return "Set. @TC GInner<@TA String, @TB Object>> entrySet() { return null; }"; } + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String methodReturnAsPrimitiveRepeatableAnnotation() { + return "@RTA @RTA int test() { return 0; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String methodReturnAsObjectRepeatableAnnotation() { + return "@RTA @RTA Object test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = { 3, 1, 3, 0 }) + public String methodReturnAsParametrizedRepeatableAnnotation() { + return "@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 0, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }) + public String methodReturnAsArrayRepeatableAnnotation() { + return "@RTC @RTC String @RTA @RTA [] @RTB @RTB [] test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 0, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 0, 0, 0, 0 }) + public String methodReturnAsArrayOldRepeatableAnnotation() { + return "@RTC @RTC String test() @RTA @RTA [] @RTB @RTB [] { return null; }"; + } + + // Smoke tests + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String interfaceMethodReturnAsObjectRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { @RTA @RTA Object test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String abstractMethodReturnAsObjectRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% { abstract @RTA @RTA Object test(); }"; + } + + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 1 }) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = { 3, 1, 3, 0 }) + public String interfaceMethodReturnAsParametrizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = { 3, 0 }) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "RTEs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "RTFs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation() { + return "Set<@RTA @RTA ? extends @RTB @RTB GOuter. @RTC @RTC GInner<@RTD @RTD String," + + " @RTE @RTE ? super @RTF @RTF Object>> entrySet() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation2() { + return "class GOuter { class GInner {} } " + + "class %TEST_CLASS_NAME% { Set.GInner<@RTA @RTA K," + + " @RTB @RTB ? extends @RTC @RTC Object>> entrySet() { return null; } }"; + } + + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation3() { + return "Set. @RTC @RTC GInner> entrySet() { return null; }"; + } + + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation4() { + return "Set. @RTC @RTC GInner> entrySet() { return null; }"; + } + + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation5() { + return "Set entrySet() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = { 3, 0, 2, 0, 1, 0 }) + public String methodReturnAsNestedWildcardRepeatableAnnotation6() { + return "Set. @RTC @RTC GInner<@RTA @RTA String," + + " @RTB @RTB Object>> entrySet() { return null; }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java index 2b73c6ebf4a..db0f6104188 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java @@ -25,53 +25,46 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for method exception clauses * @compile -g Driver.java ReferenceInfoUtil.java MethodThrows.java * @run main Driver MethodThrows */ public class MethodThrows { - @TADescriptions({ - @TADescription(annotation = "TA", type = THROWS, typeIndex = 0), - @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) - }) + @TADescription(annotation = "TA", type = THROWS, typeIndex = 0) + @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) public String regularMethod() { - return "class Test { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception { } }"; + return "class %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception { } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = THROWS, typeIndex = 0), - @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) - }) + @TADescription(annotation = "TA", type = THROWS, typeIndex = 0) + @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) public String abstractMethod() { - return "abstract class Test { abstract void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }"; + return "abstract class %TEST_CLASS_NAME% { abstract void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = THROWS, typeIndex = 0), - @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) - }) + @TADescription(annotation = "TA", type = THROWS, typeIndex = 0) + @TADescription(annotation = "TB", type = THROWS, typeIndex = 2) public String interfaceMethod() { - return "interface Test { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }"; + return "interface %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = THROWS, typeIndex = 0, - genericLocation = {}), - @TADescription(annotation = "TB", type = THROWS, typeIndex = 0, - genericLocation = {1, 0}), - @TADescription(annotation = "TC", type = THROWS, typeIndex = 0, - genericLocation = {1, 0, 1, 0}), - @TADescription(annotation = "TD", type = THROWS, typeIndex = 1, - genericLocation = {}), - @TADescription(annotation = "TE", type = THROWS, typeIndex = 1, - genericLocation = {1, 0}), - @TADescription(annotation = "TF", type = THROWS, typeIndex = 1, - genericLocation = {1, 0, 1, 0}) - }) + @TADescription(annotation = "TA", type = THROWS, typeIndex = 0, + genericLocation = {}) + @TADescription(annotation = "TB", type = THROWS, typeIndex = 0, + genericLocation = {1, 0}) + @TADescription(annotation = "TC", type = THROWS, typeIndex = 0, + genericLocation = {1, 0, 1, 0}) + @TADescription(annotation = "TD", type = THROWS, typeIndex = 1, + genericLocation = {}) + @TADescription(annotation = "TE", type = THROWS, typeIndex = 1, + genericLocation = {1, 0}) + @TADescription(annotation = "TF", type = THROWS, typeIndex = 1, + genericLocation = {1, 0, 1, 0}) public String NestedTypes() { return "class Outer { class Middle { class Inner1 extends Exception {}" + " class Inner2 extends Exception{} } }" + - "class Test { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }"; + "class %TEST_CLASS_NAME% { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }"; } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodTypeParam.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodTypeParam.java index a48198c73ec..c34f80eacfb 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodTypeParam.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodTypeParam.java @@ -22,230 +22,387 @@ */ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; +import static java.lang.System.lineSeparator; /* * @test + * @bug 8042451 * @summary Test population of reference info for method type parameters * @compile -g Driver.java ReferenceInfoUtil.java MethodTypeParam.java * @run main Driver MethodTypeParam */ public class MethodTypeParam { - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String regularClass() { return "<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> void test() { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String regularClass2() { return "<@TA K extends @TB Date, @TC V extends @TE Cloneable> void test() { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) public String regularClassParameterized() { return ", V extends @TF Object & @TC List<@TD List<@TE Object>>> void test() { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String abstractClass() { - return "abstract class Test { abstract <@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> void test(); }"; + return "abstract class %TEST_CLASS_NAME% { abstract <@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) public String abstractClassParameterized() { - return "abstract class Test { abstract , V extends @TF Object & @TC List<@TD List<@TE Object>>> void test(); }"; + return "abstract class %TEST_CLASS_NAME% { abstract , V extends @TF Object & @TC List<@TD List<@TE Object>>> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) public String abstractClassParameterized2() { - return "abstract class Test { abstract , V extends @TC List<@TD List<@TE Object>>> void test(); }"; + return "abstract class %TEST_CLASS_NAME% { abstract , V extends @TC List<@TD List<@TE Object>>> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String abstractClassParameterized3() { - return "abstract class Test { abstract , V extends @TB List> void test(); }"; + return "abstract class %TEST_CLASS_NAME% { abstract , V extends @TB List> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) public String regularInterface() { - return "interface Test { <@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> void test(); }"; + return "interface %TEST_CLASS_NAME% { <@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER, paramIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER, paramIndex = 1) public String regularInterfaceParameterized() { - return "interface Test { <@TH K extends @TG Object & @TA Map, @TI V extends @TF Object & @TC List<@TD List<@TE Object>>> void test(); }"; + return "interface %TEST_CLASS_NAME% { <@TH K extends @TG Object & @TA Map, @TI V extends @TF Object & @TC List<@TD List<@TE Object>>> void test(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER, paramIndex = 1) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER, paramIndex = 1) public String regularInterfaceParameterized2() { - return "interface Test { <@TF K extends @TA Map, @TG V extends @TC List<@TD List<@TE Object>>> void test(); }"; + return "interface %TEST_CLASS_NAME% { <@TF K extends @TA Map, @TG V extends @TC List<@TD List<@TE Object>>> void test(); }"; } @TADescription(annotation = "TA", type = METHOD_RETURN) public String useInReturn1() { - return "class Test { @TA T m() { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { @TA T m() { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {3, 0}) public String useInReturn2() { - return "class Test { Class<@TA T> m() { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { Class<@TA T> m() { throw new RuntimeException(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TB", type = METHOD_RETURN) - }) - public String useInReturn3() { - return "class Test { @TB T m() { throw new RuntimeException(); } }"; + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TB", type = METHOD_RETURN) + public String useInReturn3() { + return "class %TEST_CLASS_NAME% { @TB T m() { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0, genericLocation = {3, 0}) public String useInParam1() { - return "class Test { void m(Class<@TA T> p) { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { void m(Class<@TA T> p) { throw new RuntimeException(); } }"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0, genericLocation = {3, 0}) public String useInParam2() { - return "class Test { void m(Class<@TA Object> p) { throw new RuntimeException(); } }"; + return "class %TEST_CLASS_NAME% { void m(Class<@TA Object> p) { throw new RuntimeException(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 2), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 2) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) public String useInParam3() { return "interface IA {} " + "interface IB {} " + "interface IC {} " + - "class Test { & @TB IC> void m(@TC T p) { throw new RuntimeException(); } }"; + "class %TEST_CLASS_NAME% { & @TB IC> void m(@TC T p) { throw new RuntimeException(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, - genericLocation = {}), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 2, - genericLocation = {}), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) - }) public String useInParam4() { - return "class Test {" + + return "class %TEST_CLASS_NAME% {" + " interface IA {} " + " interface IB {} " + " interface IC {} " + " & @TB IC> void m(@TC T p) { throw new RuntimeException(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0, - genericLocation = {}), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0, - genericLocation = {1, 0}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0, - genericLocation = {1, 0, 3, 0}), - }) - public String useInParam5() { - return "class Test {" + + genericLocation = {1, 0, 3, 0}) + public String useInParam5() { + return "class %TEST_CLASS_NAME% {" + " interface IA {} " + " class CB {} " + - " > void m(T p) { throw new RuntimeException(); } }"; + " > void m(T p) { throw new RuntimeException(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, - paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER, + paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0, - genericLocation = {}), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0, - genericLocation = {1, 0, 3, 0}), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 3, 0}) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, - genericLocation = {}), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 0}) - }) public String useInParam6() { - return "class Test {" + + return "class %TEST_CLASS_NAME% {" + " interface IA {} " + " interface IB {} " + " class CC {} " + " interface ID {} " + - " <@TA T extends @TB Test.CC<@TC IA> & Test. @TD ID<@TE IA>> void m(T p) { throw new RuntimeException(); } }"; + " <@TA T extends @TB %TEST_CLASS_NAME%.CC<@TC IA> & %TEST_CLASS_NAME%. @TD ID<@TE IA>> void m(T p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularClassRepeatableAnnotation() { + return "<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> void test() { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularClassRepeatableAnnotation2() { + return "<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTE @RTE Cloneable> void test() { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + public String regularClassParameterizedRepeatableAnnotation() { + return ", V extends @RTF @RTF Object" + + " & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> void test() { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String abstractClassRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% { abstract <@RTA @RTA K extends @RTB @RTB Date," + + " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + public String abstractClassParameterizedRepeatableAnnotation() { + return "abstract class %TEST_CLASS_NAME% { abstract , V extends @RTF @RTF Object &" + + " @RTC @RTC List<@RTD @RTD Object>> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0}) + public String abstractClassParameterizedRepeatableAnnotation2() { + return "abstract class %TEST_CLASS_NAME% { abstract ," + + " V extends @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String abstractClassParameterizedRepeatableAnnotation3() { + return "abstract class %TEST_CLASS_NAME% { abstract ," + + " V extends @RTB @RTB List> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + public String regularInterfaceRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { <@RTA @RTA K extends @RTB @RTB Date," + + " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0}) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER, paramIndex = 1) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER, paramIndex = 0) + public String regularInterfaceParameterizedRepeatableAnnotation() { + return "interface %TEST_CLASS_NAME% { <@RTF @RTF K extends @RTA @RTA Map," + + " @RTE @RTE V extends @RTC @RTC List<@RTD @RTD Object>> void test(); }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN) + public String useInReturnRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { @RTA @RTA T m() { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, genericLocation = {3, 0}) + public String useInReturnRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { Class<@RTA @RTA T> m() { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_RETURN) + public String useInReturnRepeatableAnnotation3() { + return "class %TEST_CLASS_NAME% { @RTB @RTB T m() { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0, genericLocation = {3, 0}) + public String useInParamRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% { void m(Class<@RTA @RTA T> p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0, genericLocation = {3, 0}) + public String useInParamRepeatableAnnotation2() { + return "class %TEST_CLASS_NAME% { void m(Class<@RTA @RTA Object> p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 2) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + public String useInParamRepeatableAnnotation3() { + return "interface IA {} " + + "interface IB {} " + + "interface IC {} " + + "class %TEST_CLASS_NAME% { & @RTB @RTB IC>" + + " void m(@RTC @RTC T p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 2, + genericLocation = {}) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + paramIndex = 0) + public String useInParamRepeatableAnnotation4() { + return "class %TEST_CLASS_NAME% {" + + " interface IA {} " + + " interface IB {} " + + " interface IC {} " + + " & @RTB @RTB IC>" + + " void m(@RTC @RTC T p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0, + genericLocation = {1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0, + genericLocation = {1, 0, 3, 0}) + public String useInParamRepeatableAnnotation5() { + return "class %TEST_CLASS_NAME% {" + + " interface IA {} " + + " class CB {} " + + " > void m(T p) { throw new RuntimeException(); } }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER, + paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0, + genericLocation = {}) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0, + genericLocation = {1, 0, 3, 0}) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1, + genericLocation = {}) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1, + genericLocation = {3, 0}) + public String useInParamRepeatableAnnotation6() { + return "class %TEST_CLASS_NAME% {" + + " interface IA {} " + + " interface IB {} " + + " class CC {} " + + " interface ID {} " + + " <@RTA @RTA T extends @RTB @RTB %TEST_CLASS_NAME%.CC<@RTC @RTC IA> &" + + " %TEST_CLASS_NAME%. @RTD @RTD ID<@RTE @RTE IA>> void m(T p) { throw new RuntimeException(); } }"; } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java index 7c16a0d7b66..f791521d455 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java @@ -25,7 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test - * @bug 8006732 8006775 + * @bug 8006732 8006775 8042451 * @summary Test population of reference info for multicatch exception parameters * @author Werner Dietl * @compile -g Driver.java ReferenceInfoUtil.java MultiCatch.java @@ -33,35 +33,59 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; */ public class MultiCatch { - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) public String multiCatch1() { return "void multiCatch1() { " + "try { new Object(); } catch (@TA NullPointerException | @TB IndexOutOfBoundsException e) { e.toString(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2), - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) public String multiCatch2() { return "void multiCatch2() { " + "try { new Object(); } catch (@TA NullPointerException | @TB IndexOutOfBoundsException | @TC IllegalArgumentException e) { e.toString(); } }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1), - @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2), - @TADescription(annotation = "TD", type = EXCEPTION_PARAMETER, exceptionIndex = 2), - @TADescription(annotation = "TE", type = EXCEPTION_PARAMETER, exceptionIndex = 3), - }) + @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + @TADescription(annotation = "TD", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + @TADescription(annotation = "TE", type = EXCEPTION_PARAMETER, exceptionIndex = 3) public String multiCatch3() { return "void multiCatch3() { " + "try { new Object(); } catch (NullPointerException e1) {}" + "try { new Object(); } catch (@TA @TB NullPointerException | @TC @TD IndexOutOfBoundsException | @TE IllegalArgumentException e2) { e2.toString(); } }"; } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + public String multiCatchRepeatableAnnotation1() { + return "void multiCatch1() { " + + "try { new Object(); } catch (@RTA @RTA NullPointerException |" + + " @RTB @RTB IndexOutOfBoundsException e) { e.toString(); } }"; + } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 0) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTCs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + public String multiCatchRepeatableAnnotation2() { + return "void multiCatch2() { " + + "try { new Object(); } catch (@RTA @RTA NullPointerException |" + + " @RTB @RTB IndexOutOfBoundsException | @RTC @RTC IllegalArgumentException e) { e.toString(); } }"; + } + + @TADescription(annotation = "RTAs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTBs", type = EXCEPTION_PARAMETER, exceptionIndex = 1) + @TADescription(annotation = "RTCs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + @TADescription(annotation = "RTDs", type = EXCEPTION_PARAMETER, exceptionIndex = 2) + @TADescription(annotation = "RTEs", type = EXCEPTION_PARAMETER, exceptionIndex = 3) + public String multiCatchRepeatableAnnotation3() { + return "void multiCatch3() { " + + "try { new Object(); } catch (NullPointerException e1) {}" + + "try { new Object(); } catch (@RTA @RTA @RTB @RTB NullPointerException |" + + " @RTC @RTC @RTD @RTD IndexOutOfBoundsException |" + + " @RTE @RTE IllegalArgumentException e2) { e2.toString(); } }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java index 3bd39e508c6..78d5853f175 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 8044009 8044010 * @summary Test population of reference info for nested types * @compile -g Driver.java ReferenceInfoUtil.java NestedTypes.java * @run main Driver NestedTypes @@ -33,22 +34,18 @@ public class NestedTypes { // method parameters - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0}, paramIndex = 0) public String testParam1() { return "void test(@TA Outer.@TB Inner a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 1, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 1, 0}, paramIndex = 0) public String testParam1b() { return "void test(List<@TA Outer.@TB Inner> a) { }"; } @@ -63,10 +60,9 @@ public class NestedTypes { return "void test(java.util.@TA Map.Entry a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, genericLocation = {1, 0}, paramIndex = 0) }) public String testParam1d() { @@ -79,10 +75,9 @@ public class NestedTypes { return "void test(List a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, genericLocation = {3, 0, 1, 0}, paramIndex = 0) }) public String testParam1f() { @@ -96,89 +91,81 @@ public class NestedTypes { return "void test(List a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {1, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0}, paramIndex = 0) public String testParam2() { return "void test(@TA GOuter.@TB GInner a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 1, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 1, 0}, paramIndex = 0) public String testParam2b() { return "void test(List<@TA GOuter.@TB GInner> a) { }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0), - @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), - @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, - genericLocation = {0, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0}, paramIndex = 0) public String testParam3() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " void test(@TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[] a) { }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0), - @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0), - @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0), - @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0), - @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0}, paramIndex = 0), - @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, - genericLocation = {3, 0, 0, 0}, paramIndex = 0) - }) + @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0}, paramIndex = 0) public String testParam4() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " void test(List<@TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[]> a) { }\n" + "}"; } @@ -186,14 +173,12 @@ public class NestedTypes { // Local variables - @TADescriptions({ - @TADescription(annotation = "TA", type = LOCAL_VARIABLE, - genericLocation = {}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TB", type = LOCAL_VARIABLE, - genericLocation = {1, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) - }) + @TADescription(annotation = "TA", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) public String testLocal1a() { return "void test() { @TA Outer.@TB Inner a = null; }"; } @@ -212,104 +197,99 @@ public class NestedTypes { return "void test() { Outer.@TB Inner a = null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = LOCAL_VARIABLE, - genericLocation = {}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TB", type = LOCAL_VARIABLE, - genericLocation = {1, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) - }) + @TADescription(annotation = "TA", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) public String testLocal2() { return "void test() { @TA GOuter.@TB GInner a = null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TB", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TC", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TD", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TE", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TF", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TG", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TH", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TI", type = LOCAL_VARIABLE, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TJ", type = LOCAL_VARIABLE, - genericLocation = {}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TK", type = LOCAL_VARIABLE, - genericLocation = {0, 0}, - lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) - }) + @TADescription(annotation = "TA", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TC", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TD", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TE", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TF", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TG", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TH", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TI", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TJ", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TK", type = LOCAL_VARIABLE, + genericLocation = {0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) public String testLocal3() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " void test() { @TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[] a = null; }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TB", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TC", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TD", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TE", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TF", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TG", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TH", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TI", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TJ", type = LOCAL_VARIABLE, - genericLocation = {3, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}), - @TADescription(annotation = "TK", type = LOCAL_VARIABLE, - genericLocation = {3, 0, 0, 0}, - lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) - }) + + @TADescription(annotation = "TA", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TC", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TD", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TE", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TF", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TG", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TH", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TI", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TJ", type = LOCAL_VARIABLE, + genericLocation = {3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "TK", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) public String testLocal4() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " void test() { List<@TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[]> a = null; }\n" + "}"; } @@ -317,12 +297,10 @@ public class NestedTypes { // fields - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, - genericLocation = {}), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = {1, 0}) - }) + @TADescription(annotation = "TA", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = {1, 0}) public String testField1a() { return "@TA Outer.@TB Inner a;"; } @@ -339,79 +317,73 @@ public class NestedTypes { return "Outer.@TB Inner a;"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, - genericLocation = {}), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = {1, 0}) - }) + @TADescription(annotation = "TA", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = {1, 0}) public String testField2() { return "@TA GOuter.@TB GInner a;"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TD", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TE", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}), - @TADescription(annotation = "TF", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}), - @TADescription(annotation = "TG", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TH", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TI", type = FIELD, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}), - @TADescription(annotation = "TJ", type = FIELD), - @TADescription(annotation = "TK", type = FIELD, - genericLocation = {0, 0}) - }) + @TADescription(annotation = "TA", type = FIELD, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TE", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "TF", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "TG", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TH", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TI", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "TJ", type = FIELD) + @TADescription(annotation = "TK", type = FIELD, + genericLocation = {0, 0}) public String testField3() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " @TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[] a;\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TB", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TD", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TE", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}), - @TADescription(annotation = "TF", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}), - @TADescription(annotation = "TG", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TH", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TI", type = FIELD, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}), - @TADescription(annotation = "TJ", type = FIELD, - genericLocation = {3, 0}), - @TADescription(annotation = "TK", type = FIELD, - genericLocation = {3, 0, 0, 0}) - }) + @TADescription(annotation = "TA", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TB", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TD", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TE", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "TF", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "TG", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TH", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TI", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "TJ", type = FIELD, + genericLocation = {3, 0}) + @TADescription(annotation = "TK", type = FIELD, + genericLocation = {3, 0, 0, 0}) public String testField4() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " List<@TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[]> a;\n" + "}"; } @@ -419,121 +391,111 @@ public class NestedTypes { // return types - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = {}), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = {1, 0}) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = {}) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = {1, 0}) public String testReturn1() { return "@TA Outer.@TB Inner test() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = {}), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = {1, 0}) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = {}) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = {1, 0}) public String testReturn2() { return "@TA GOuter.@TB GInner test() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TE", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}), - @TADescription(annotation = "TG", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TH", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TI", type = METHOD_RETURN, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}), - @TADescription(annotation = "TJ", type = METHOD_RETURN), - @TADescription(annotation = "TK", type = METHOD_RETURN, - genericLocation = {0, 0}) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TE", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "TG", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TH", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TI", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "TJ", type = METHOD_RETURN) + @TADescription(annotation = "TK", type = METHOD_RETURN, + genericLocation = {0, 0}) public String testReturn3() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " @TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[] test() { return null; }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TE", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}), - @TADescription(annotation = "TF", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}), - @TADescription(annotation = "TG", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TH", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TI", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}), - @TADescription(annotation = "TJ", type = METHOD_RETURN, - genericLocation = {3, 0}), - @TADescription(annotation = "TK", type = METHOD_RETURN, - genericLocation = {3, 0, 0, 0}) - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TE", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "TF", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "TG", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TH", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TI", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "TJ", type = METHOD_RETURN, + genericLocation = {3, 0}) + @TADescription(annotation = "TK", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0}) public String testReturn4() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " List<@TA Outer . @TB GInner<@TC List<@TD Object @TE[] @TF[]>>. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[]> test() { return null; }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_RETURN, - genericLocation = {3, 0}), - @TADescription(annotation = "TB", type = METHOD_RETURN, - genericLocation = {3, 0, 3, 0}), - @TADescription(annotation = "TC", type = METHOD_RETURN, - genericLocation = {3, 0, 3, 1}), - @TADescription(annotation = "TD", type = METHOD_RETURN, - genericLocation = {3, 0, 3, 1, 3, 0}), - @TADescription(annotation = "TE", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0}), - @TADescription(annotation = "TF", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0, 3, 0}), - @TADescription(annotation = "TG", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TH", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}), - @TADescription(annotation = "TI", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}), - @TADescription(annotation = "TJ", type = METHOD_RETURN, - genericLocation = {3, 0, 1, 0, 1, 0}), - }) + @TADescription(annotation = "TA", type = METHOD_RETURN, + genericLocation = {3, 0}) + @TADescription(annotation = "TB", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "TC", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 1}) + @TADescription(annotation = "TD", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 1, 3, 0}) + @TADescription(annotation = "TE", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0}) + @TADescription(annotation = "TF", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0}) + @TADescription(annotation = "TG", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TH", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "TI", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "TJ", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 1, 0}) public String testReturn5() { return "class GOuter {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " List<@TA GOuter<@TB String, @TC List<@TD Object>> . @TE GInner<@TF List<@TG Object @TH[] @TI[]>>. @TJ GInner2> test() { return null; }\n" + "}"; } @@ -541,138 +503,128 @@ public class NestedTypes { // type parameters - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {}, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0}, paramIndex = 0, boundIndex = 0) - }) public String testTypeparam1() { return " X test() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {}, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0}, paramIndex = 0, boundIndex = 0) - }) public String testTypeparam2() { return ".@TB GInner> X test() { return null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 3, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 3, 0, 3, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 3, 0, 3, 0, 0, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 1, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 1, 0, 3, 0}, - paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {1, 0, 1, 0, 3, 1}, - paramIndex = 0, boundIndex = 0), - }) + paramIndex = 0, boundIndex = 0) public String testTypeparam3() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " >. @TG GInner2<@TH Integer, @TI Object>> X test() { return null; }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TJ", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TJ", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0}, - paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TK", type = METHOD_TYPE_PARAMETER_BOUND, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TK", type = METHOD_TYPE_PARAMETER_BOUND, genericLocation = {3, 0, 0, 0}, paramIndex = 0, boundIndex = 1) - }) public String testTypeparam4() { return "class Outer {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " >. @TG GInner2<@TH Integer, @TI Object> @TJ[] @TK[]>> X test() { return null; }\n" + "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 3, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 3, 1}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 3, 1, 3, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0, 3, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0, boundIndex = 1), - @TADescription(annotation = "TJ", type = METHOD_TYPE_PARAMETER_BOUND, - genericLocation = {3, 0, 1, 0, 1, 0}, paramIndex = 0, boundIndex = 1), - }) + @TADescription(annotation = "TA", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TB", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TC", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 1}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TD", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 1, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TE", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TF", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TG", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TH", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TI", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "TJ", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 1, 0}, paramIndex = 0, boundIndex = 1) public String testTypeparam5() { return "class GOuter {\n" + " class GInner {\n" + " class GInner2 {}\n" + "}}\n\n" + - "class Test {\n" + + "class %TEST_CLASS_NAME% {\n" + " > . @TE GInner<@TF List<@TG Object @TH[] @TI[]>>. @TJ GInner2>> X test() { return null; }\n" + "}"; } @@ -680,91 +632,89 @@ public class NestedTypes { @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0}) public String testUses1a() { - return "class Test { class Inner {} List<@TA Inner> f; }"; + return "class %TEST_CLASS_NAME% { class Inner {} List<@TA Inner> f; }"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0}) public String testUses1b() { - return "class Test { class Inner {} List<@TA Test.Inner> f; }"; + return "class %TEST_CLASS_NAME% { class Inner {} List<@TA %TEST_CLASS_NAME%.Inner> f; }"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2a() { - return "class Test { class Inner { class Inner2{} List<@TA Inner2> f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<@TA Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2b() { - return "class Test { class Inner { class Inner2{} List<@TA Inner.Inner2> f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<@TA Inner.Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2c() { - return "class Test { class Inner { class Inner2{} List f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2d() { - return "class Test{ class Inner { class Inner2{} List<@TA Test.Inner.Inner2> f; }}"; + return "class %TEST_CLASS_NAME%{ class Inner { class Inner2{} List<@TA %TEST_CLASS_NAME%.Inner.Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2e() { - return "class Test { class Inner { class Inner2{} List f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<%TEST_CLASS_NAME%.@TA Inner.Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses2f() { - return "class Test { class Inner { class Inner2{} List f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<%TEST_CLASS_NAME%.Inner.@TA Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses3a() { - return "class Test { class Inner { class Inner2{}\n" + - " List f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.Inner.@TA Inner2> f; }}"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses3b() { - return "class Test { class Inner { class Inner2{}\n" + - " List f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.@TA Inner.Inner2> f; }}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, - genericLocation = {}), - @TADescription(annotation = "TB", type = FIELD, + @TADescription(annotation = "TA", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "TB", type = FIELD, genericLocation = {3, 0}) - }) public String testUses4() { - return "class Test { static class TInner {}\n" + + return "class %TEST_CLASS_NAME% { static class TInner {}\n" + " @TA TInner f; \n" + " List<@TB TInner> g; }"; } @TADescription(annotation = "TA", type = FIELD, genericLocation = {3, 0, 1, 0, 3, 1}) - @TestClass("Test$Inner") + @TestClass("%TEST_CLASS_NAME%$Inner") public String testUses3c() { - return "class Test { class Inner { class Inner2{}\n" + - " List.Inner2> f; }}"; + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.Inner.Inner2<%TEST_CLASS_NAME%, %TEST_CLASS_NAME%>> f; }}"; } @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex=0) @@ -778,24 +728,22 @@ public class NestedTypes { return "void testme(List protectionDomain) {}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = LOCAL_VARIABLE, + @TADescription(annotation = "TA", type = LOCAL_VARIABLE, genericLocation = {}, lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, lvarLength = ReferenceInfoUtil.IGNORE_VALUE, - lvarIndex = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = LOCAL_VARIABLE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = LOCAL_VARIABLE, genericLocation = {1, 0}, lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, lvarLength = ReferenceInfoUtil.IGNORE_VALUE, - lvarIndex = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = LOCAL_VARIABLE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = LOCAL_VARIABLE, // Only classes count, not methods. genericLocation = {1, 0, 1, 0}, lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, lvarLength = ReferenceInfoUtil.IGNORE_VALUE, - lvarIndex = ReferenceInfoUtil.IGNORE_VALUE), - }) + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) @TestClass("Outer$Inner") public String testMethodNesting1() { return "class Outer {\n" + @@ -808,18 +756,16 @@ public class NestedTypes { "}}\n"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, + @TADescription(annotation = "TA", type = NEW, genericLocation = {}, - offset = 0), - @TADescription(annotation = "TB", type = NEW, + offset = 0) + @TADescription(annotation = "TB", type = NEW, genericLocation = {1, 0}, - offset = 0), - @TADescription(annotation = "TC", type = NEW, + offset = 0) + @TADescription(annotation = "TC", type = NEW, // Only classes count, not methods. genericLocation = {1, 0, 1, 0}, - offset = 12), - }) + offset = 12) @TestClass("Outer$Inner") public String testMethodNesting2() { return "class Outer {\n" + @@ -832,20 +778,18 @@ public class NestedTypes { "}}\n"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_EXTENDS, - genericLocation = {}, typeIndex = -1), - @TADescription(annotation = "TB", type = CLASS_EXTENDS, - genericLocation = {3, 0}, typeIndex = -1), - @TADescription(annotation = "TC", type = CLASS_EXTENDS, - genericLocation = {3, 1}, typeIndex = -1), - @TADescription(annotation = "TD", type = CLASS_EXTENDS, - genericLocation = {1, 0}, typeIndex = -1), - @TADescription(annotation = "TE", type = CLASS_EXTENDS, - genericLocation = {1, 0, 3, 0}, typeIndex = -1), - @TADescription(annotation = "TF", type = CLASS_EXTENDS, + @TADescription(annotation = "TA", type = CLASS_EXTENDS, + genericLocation = {}, typeIndex = -1) + @TADescription(annotation = "TB", type = CLASS_EXTENDS, + genericLocation = {3, 0}, typeIndex = -1) + @TADescription(annotation = "TC", type = CLASS_EXTENDS, + genericLocation = {3, 1}, typeIndex = -1) + @TADescription(annotation = "TD", type = CLASS_EXTENDS, + genericLocation = {1, 0}, typeIndex = -1) + @TADescription(annotation = "TE", type = CLASS_EXTENDS, + genericLocation = {1, 0, 3, 0}, typeIndex = -1) + @TADescription(annotation = "TF", type = CLASS_EXTENDS, genericLocation = {1, 0, 3, 1}, typeIndex = -1) - }) @TestClass("GOuter$GInner$Test") public String testExtends1() { return "class GOuter {\n" + @@ -855,19 +799,17 @@ public class NestedTypes { "}"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, - genericLocation = {}, paramIndex = 0), - @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, - genericLocation = {}, paramIndex = 0, boundIndex = 0), - @TADescription(annotation = "TC", type = FIELD, - genericLocation = {}), - @TADescription(annotation = "TD", type = FIELD, + @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "TC", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "TD", type = FIELD, genericLocation = {3, 0}) - }) - @TestClass("Test$1Nested") + @TestClass("%TEST_CLASS_NAME%$1Nested") public String testNestedInMethod1() { - return "class Test {\n" + + return "class %TEST_CLASS_NAME% {\n" + " void foobar() {\n" + " class Nested<@TA X extends @TB Object> {\n" + " @TC List<@TD Object> f;\n" + @@ -875,4 +817,781 @@ public class NestedTypes { " }" + "}"; } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation1() { + return "void test(@RTA @RTA Outer.@RTB @RTB Inner a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 1, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation1b() { + return "void test(List<@RTA @RTA Outer.@RTB @RTB Inner> a) { }"; + } + + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation1g() { + return "void test(List a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {1, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation2() { + return "void test(@RTA @RTA GOuter.@RTB @RTB GInner a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 1, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation2b() { + return "void test(List<@RTA @RTA GOuter.@RTB @RTB GInner> a) { }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTFs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTGs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "RTHs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTIs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "RTJs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) + @TADescription(annotation = "RTKs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {0, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation3() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " void test(@RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object" + + " @RTE @RTE[] @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer, @RTI @RTI Object>" + + " @RTJ @RTJ[] @RTK @RTK[] a) { }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTFs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0) + @TADescription(annotation = "RTGs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, paramIndex = 0) + @TADescription(annotation = "RTHs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0) + @TADescription(annotation = "RTIs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0) + @TADescription(annotation = "RTJs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0}, paramIndex = 0) + @TADescription(annotation = "RTKs", type = METHOD_FORMAL_PARAMETER, + genericLocation = {3, 0, 0, 0}, paramIndex = 0) + public String testParamRepeatableAnnotation4() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " void test(List<@RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object" + + " @RTE @RTE[] @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[]> a) { }\n" + + "}"; + } + + // Local variables + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation1a() { + return "void test() { @RTA @RTA Outer.@RTB @RTB Inner a = null; }"; + } + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation1b() { + return "void test() { @RTA @RTA Outer.Inner a = null; }"; + } + + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation1c() { + return "void test() { Outer.@RTB @RTB Inner a = null; }"; + } + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation2() { + return "void test() { @RTA @RTA GOuter.@RTB @RTB GInner a = null; }"; + } + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTCs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTDs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTEs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTFs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTGs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTHs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTIs", type = LOCAL_VARIABLE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTJs", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTKs", type = LOCAL_VARIABLE, + genericLocation = {0, 0}, + lvarOffset = {5}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation3() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " void test() { @RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object" + + " @RTE @RTE[] @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer, @RTI @RTI Object>" + + " @RTJ @RTJ[] @RTK @RTK[] a = null; }\n" + + "}"; + } + + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTCs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTDs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTEs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTFs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTGs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTHs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTIs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTJs", type = LOCAL_VARIABLE, + genericLocation = {3, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + @TADescription(annotation = "RTKs", type = LOCAL_VARIABLE, + genericLocation = {3, 0, 0, 0}, + lvarOffset = {2}, lvarLength = {1}, lvarIndex = {1}) + public String testLocalRepeatableAnnotation4() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " void test() { List<@RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD" + + " Object @RTE @RTE [] @RTF @RTF []>>. @RTG @RTG GInner2<@RTH @RTH" + + " Integer, @RTI @RTI Object> @RTJ @RTJ [] @RTK @RTK []> a = null; }\n" + + "}"; + } + + + // fields + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {1, 0}) + public String testFieldRepeatableAnnotation1a() { + return "@RTA @RTA Outer.@RTB @RTB Inner a;"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {}) + public String testFieldRepeatableAnnotation1b() { + return "@RTA @RTA Outer.Inner a;"; + } + + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {1, 0}) + public String testFieldRepeatableAnnotation1c() { + return "Outer.@RTB @RTB Inner a;"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {1, 0}) + public String testFieldRepeatableAnnotation2() { + return "@RTA @RTA GOuter.@RTB @RTB GInner a;"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTEs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "RTGs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTHs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTIs", type = FIELD, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "RTJs", type = FIELD) + @TADescription(annotation = "RTKs", type = FIELD, + genericLocation = {0, 0}) + public String testFieldRepeatableAnnotation3() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " @RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object @RTE @RTE[] @RTF @RTF[]>>." + + " @RTG @RTG GInner2<@RTH @RTH Integer, @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[] a;\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTEs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "RTGs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTHs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTIs", type = FIELD, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "RTJs", type = FIELD, + genericLocation = {3, 0}) + @TADescription(annotation = "RTKs", type = FIELD, + genericLocation = {3, 0, 0, 0}) + public String testFieldRepeatableAnnotation4() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " List<@RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object" + + " @RTE @RTE[] @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[]> a;\n" + + "}"; + } + + + // return types + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = {1, 0}) + public String testReturnRepeatableAnnotation1() { + return "@RTA @RTA Outer.@RTB @RTB Inner test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = {1, 0}) + public String testReturnRepeatableAnnotation2() { + return "@RTA @RTA GOuter." + + "@RTB @RTB GInner test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTEs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "RTGs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTHs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTIs", type = METHOD_RETURN, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "RTJs", type = METHOD_RETURN) + @TADescription(annotation = "RTKs", type = METHOD_RETURN, + genericLocation = {0, 0}) + public String testReturnRepeatableAnnotation3() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " @RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object @RTE @RTE[]" + + " @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[] test() { return null; }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTEs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "RTFs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "RTGs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTHs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTIs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}) + @TADescription(annotation = "RTJs", type = METHOD_RETURN, + genericLocation = {3, 0}) + @TADescription(annotation = "RTKs", type = METHOD_RETURN, + genericLocation = {3, 0, 0, 0}) + public String testReturnRepeatableAnnotation4() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " List<@RTA @RTA Outer . @RTB @RTB GInner<@RTC @RTC List<@RTD @RTD Object" + + " @RTE @RTE[] @RTF @RTF[]>>. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[]> test() { return null; }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_RETURN, + genericLocation = {3, 0}) + @TADescription(annotation = "RTBs", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 0}) + @TADescription(annotation = "RTCs", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 1}) + @TADescription(annotation = "RTDs", type = METHOD_RETURN, + genericLocation = {3, 0, 3, 1, 3, 0}) + @TADescription(annotation = "RTEs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0}) + @TADescription(annotation = "RTFs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0}) + @TADescription(annotation = "RTGs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTHs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}) + @TADescription(annotation = "RTIs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}) + @TADescription(annotation = "RTJs", type = METHOD_RETURN, + genericLocation = {3, 0, 1, 0, 1, 0}) + public String testReturnRepeatableAnnotation5() { + return "class GOuter {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " List<@RTA @RTA GOuter<@RTB @RTB String, @RTC @RTC List<@RTD @RTD Object>> ." + + " @RTE @RTE GInner<@RTF @RTF List<@RTG @RTG Object @RTH @RTH[] @RTI @RTI[]>>." + + " @RTJ @RTJ GInner2> test() { return null; }\n" + + "}"; + } + + + // type parameters + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0}, paramIndex = 0, boundIndex = 0) + public String testTypeparamRepeatableAnnotation1() { + return " X test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0}, paramIndex = 0, boundIndex = 0) + public String testTypeparamRepeatableAnnotation2() { + return ".@RTB @RTB GInner> X test() { return null; }"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 3, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 3, 0, 3, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 3, 0, 3, 0, 0, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTGs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 1, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTHs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 1, 0, 3, 0}, + paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTIs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {1, 0, 1, 0, 3, 1}, + paramIndex = 0, boundIndex = 0) + public String testTypeparamRepeatableAnnotation3() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " >. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object>> X test() { return null; }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 0, 0, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTGs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTHs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTIs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTJs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0}, + paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTKs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 0, 0}, + paramIndex = 0, boundIndex = 1) + public String testTypeparamRepeatableAnnotation4() { + return "class Outer {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " >. @RTG @RTG GInner2<@RTH @RTH Integer," + + " @RTI @RTI Object> @RTJ @RTJ[] @RTK @RTK[]>> X test() { return null; }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTBs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTCs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 1}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTDs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 3, 1, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTEs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTFs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTGs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTHs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTIs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 3, 0, 3, 0, 0, 0}, paramIndex = 0, boundIndex = 1) + @TADescription(annotation = "RTJs", type = METHOD_TYPE_PARAMETER_BOUND, + genericLocation = {3, 0, 1, 0, 1, 0}, paramIndex = 0, boundIndex = 1) + public String testTypeparamRepeatableAnnotation5() { + return "class GOuter {\n" + + " class GInner {\n" + + " class GInner2 {}\n" + + "}}\n\n" + + "class %TEST_CLASS_NAME% {\n" + + " > ." + + " @RTE @RTE GInner<@RTF @RTF List<@RTG @RTG Object @RTH @RTH[] @RTI @RTI[]>>." + + " @RTJ @RTJ GInner2>> X test() { return null; }\n" + + "}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0}) + public String testUsesRepeatableAnnotation1a() { + return "class %TEST_CLASS_NAME% { class Inner {} List<@RTA @RTA Inner> f; }"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0}) + public String testUsesRepeatableAnnotation1b() { + return "class %TEST_CLASS_NAME% { class Inner {} List<@RTA @RTA %TEST_CLASS_NAME%.Inner> f; }"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2a() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<@RTA @RTA Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2b() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List<@RTA @RTA Inner.Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2c() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{} List f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2d() { + return "class %TEST_CLASS_NAME%{ class Inner { class Inner2{}" + + " List<@RTA @RTA %TEST_CLASS_NAME%.Inner.Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2e() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}" + + " List<%TEST_CLASS_NAME%.@RTA @RTA Inner.Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation2f() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}" + + " List<%TEST_CLASS_NAME%.Inner.@RTA @RTA Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation3a() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.Inner.@RTA @RTA Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation3b() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.@RTA @RTA Inner.Inner2> f; }}"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "RTBs", type = FIELD, + genericLocation = {3, 0}) + public String testUsesRepeatableAnnotation4() { + return "class %TEST_CLASS_NAME% { static class TInner {}\n" + + " @RTA @RTA TInner f; \n" + + " List<@RTB @RTB TInner> g; }"; + } + + @TADescription(annotation = "RTAs", type = FIELD, + genericLocation = {3, 0, 1, 0, 3, 1}) + @TestClass("%TEST_CLASS_NAME%$Inner") + public String testUsesRepeatableAnnotation3c() { + return "class %TEST_CLASS_NAME% { class Inner { class Inner2{}\n" + + " List<%TEST_CLASS_NAME%.Inner.Inner2<%TEST_CLASS_NAME%, %TEST_CLASS_NAME%>> f; }}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex=0) + public String testFullyQualifiedRepeatableAnnotation1() { + return "void testme(java.security.@RTA @RTA ProtectionDomain protectionDomain) {}"; + } + + @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex=0, + genericLocation = {3, 0}) + public String testFullyQualifiedRepeatableAnnotation2() { + return "void testme(List protectionDomain) {}"; + } + + @TADescription(annotation = "RTAs", type = LOCAL_VARIABLE, + genericLocation = {}, + lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, + lvarLength = ReferenceInfoUtil.IGNORE_VALUE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = LOCAL_VARIABLE, + genericLocation = {1, 0}, + lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, + lvarLength = ReferenceInfoUtil.IGNORE_VALUE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = LOCAL_VARIABLE, + // Only classes count, not methods. + genericLocation = {1, 0, 1, 0}, + lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, + lvarLength = ReferenceInfoUtil.IGNORE_VALUE, + lvarIndex = ReferenceInfoUtil.IGNORE_VALUE) + @TestClass("Outer$Inner") + public String testMethodNestingRepeatableAnnotation1() { + return "class Outer {\n" + + " class Inner {\n" + + " void foo() {\n" + + " class MInner {}\n" + + " @RTA @RTA Outer . @RTB @RTB Inner l1 = null;\n" + + " @RTC @RTC MInner l2 = null;\n" + + " }\n" + + "}}\n"; + } + + @TADescription(annotation = "RTAs", type = NEW, + genericLocation = {}, + offset = 0) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = {1, 0}, + offset = 0) + @TADescription(annotation = "RTCs", type = NEW, + // Only classes count, not methods. + genericLocation = {1, 0, 1, 0}, + offset = 12) + @TestClass("Outer$Inner") + public String testMethodNestingRepeatableAnnotation2() { + return "class Outer {\n" + + " class Inner {\n" + + " void foo() {\n" + + " class MInner {}\n" + + " Object o1 = new @RTA @RTA Outer . @RTB @RTB Inner();" + + " Object o2 = new @RTC @RTC MInner();\n" + + " }\n" + + "}}\n"; + } + + @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, + genericLocation = {}, typeIndex = -1) + @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, + genericLocation = {3, 0}, typeIndex = -1) + @TADescription(annotation = "RTCs", type = CLASS_EXTENDS, + genericLocation = {3, 1}, typeIndex = -1) + @TADescription(annotation = "RTDs", type = CLASS_EXTENDS, + genericLocation = {1, 0}, typeIndex = -1) + @TADescription(annotation = "RTEs", type = CLASS_EXTENDS, + genericLocation = {1, 0, 3, 0}, typeIndex = -1) + @TADescription(annotation = "RTFs", type = CLASS_EXTENDS, + genericLocation = {1, 0, 3, 1}, typeIndex = -1) + @TestClass("GOuter$GInner$Test") + public String testExtendsRepeatableAnnotation1() { + return "class GOuter {\n" + + " class GInner {\n" + + " class Test extends @RTA @RTA GOuter<@RTB @RTB String," + + " @RTC @RTC String>.@RTD @RTD GInner<@RTE @RTE String, @RTF @RTF String> {}" + + " }" + + "}"; + } + + @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, + genericLocation = {}, paramIndex = 0) + @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, + genericLocation = {}, paramIndex = 0, boundIndex = 0) + @TADescription(annotation = "RTCs", type = FIELD, + genericLocation = {}) + @TADescription(annotation = "RTDs", type = FIELD, + genericLocation = {3, 0}) + @TestClass("%TEST_CLASS_NAME%$1Nested") + public String testNestedInMethodRepeatableAnnotation1() { + return "class %TEST_CLASS_NAME% {\n" + + " void foobar() {\n" + + " class Nested<@RTA @RTA X extends @RTB @RTB Object> {\n" + + " @RTC @RTC List<@RTD @RTD Object> f;\n" + + " }\n" + + " }" + + "}"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java index 30913b1cece..8bcddc45ec3 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for new object creations * @compile -g Driver.java ReferenceInfoUtil.java NewObjects.java * @run main Driver NewObjects @@ -36,11 +37,9 @@ public class NewObjects { return "Object returnObject() { return new @TA String(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String returnObjectGeneric() { return "Object returnObjectGeneric() { return new @TA ArrayList<@TB String>(); }"; } @@ -50,13 +49,11 @@ public class NewObjects { return "void initObject() { Object a = new @TA String(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = NEW, - genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = NEW, + genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String initObjectGeneric() { return "void initObjectGeneric() { Object a = new @TA HashMap<@TB String, @TC String>(); }"; } @@ -66,90 +63,182 @@ public class NewObjects { return "void eqtestObject() { if (null == new @TA String()); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String eqtestObjectGeneric() { return "void eqtestObjectGeneric() { if (null == new @TA ArrayList<@TB String >()); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0}), - @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) public String returnNewArray1() { return "Object returnNewArray1() { return new @TA String @TB[1]; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0}), - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) public String returnNewArray2() { return "Object returnNewArray2() { return new @TA String @TB [1] @TC [2]; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0}), - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) public String returnNewArray3() { return "Object returnNewArray3() { return new @TA Outer. @TB Inner @TC [1] @TD [2]; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0}), - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) public String returnNewArray4() { return "Object returnNewArray4() { return new @TA Outer. @TB Middle. @TC MInner @TD [1] @TE [2]; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {3, 0, 0, 0, 0, 0}), - @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}), - @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {3, 0}), - @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {3, 0, 0, 0}), - }) + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0}) + @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0}) public String returnNewArray5() { return "Object returnNewArray5() { return new @TA ArrayList<@TB Outer. @TC Middle. @TD MInner @TE [] @TF []>(); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0}), - @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0, 0, 0, 1, 0}), - @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, - genericLocation = {0, 0}), - }) + @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) public String arrayField() { return "@TA Outer. @TB Inner @TC [] @TD [] f;"; } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnObjectRepeatableAnnotation() { + return "Object returnObject() { return new @RTA @RTA String(); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnObjectGenericRepeatableAnnotation() { + return "Object returnObjectGeneric() { return new @RTA @RTA ArrayList<@RTB @RTB String>(); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String initObjectRepeatableAnnotation() { + return "void initObject() { Object a = new @RTA @RTA String(); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = NEW, + genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String initObjectGenericRepeatableAnnotation() { + return "void initObjectGeneric() { Object a = new @RTA @RTA HashMap<@RTB @RTB String, @RTC @RTC String>(); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String eqtestObjectRepeatableAnnotation() { + return "void eqtestObject() { if (null == new @RTA @RTA String()); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String eqtestObjectGenericRepeatableAnnotation() { + return "void eqtestObjectGeneric() { if (null == new @RTA @RTA ArrayList<@RTB @RTB String >()); }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnNewArrayRepeatableAnnotation1() { + return "Object returnNewArray1() { return new @RTA @RTA String @RTB @RTB[1]; }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + public String returnNewArrayRepeatableAnnotation2() { + return "Object returnNewArray2() { return new @RTA @RTA String @RTB @RTB [1] @RTC @RTC [2]; }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + public String returnNewArrayRepeatableAnnotation3() { + return "Object returnNewArray3() { return new @RTA @RTA Outer. @RTB @RTB Inner @RTC @RTC [1] @RTD @RTD [2]; }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + public String returnNewArrayRepeatableAnnotation4() { + return "Object returnNewArray4() { return new @RTA @RTA Outer." + + " @RTB @RTB Middle. @RTC @RTC MInner @RTD @RTD [1] @RTE @RTE [2]; }"; + } + + @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0}) + @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) + @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0}) + @TADescription(annotation = "RTFs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {3, 0, 0, 0}) + public String returnNewArrayRepeatableAnnotation5() { + return "Object returnNewArray5() { return new @RTA @RTA ArrayList<@RTB @RTB Outer." + + " @RTC @RTC Middle. @RTD @RTD MInner @RTE @RTE [] @RTF @RTF []>(); }"; + } + + @TADescription(annotation = "RTAs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0}) + @TADescription(annotation = "RTBs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0, 0, 0, 1, 0}) + @TADescription(annotation = "RTCs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTDs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, + genericLocation = {0, 0}) + public String arrayFieldRepeatableAnnotation() { + return "@RTA @RTA Outer. @RTB @RTB Inner @RTC @RTC [] @RTD @RTD [] f;"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java index 0577c8b4246..8ed09252894 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java @@ -41,7 +41,7 @@ public class ReferenceInfoUtil { public static final int IGNORE_VALUE = -321; public static List extendedAnnotationsOf(ClassFile cf) { - List annos = new ArrayList(); + List annos = new ArrayList<>(); findAnnotations(cf, annos); return annos; } @@ -119,128 +119,6 @@ public class ReferenceInfoUtil { } } - /////////////////// TA Position Builder /////////////////////// - /* TODO: comment out this dead code. Was this unfinished code that was - * supposed to be used somewhere? The tests pass without this. - private static class TAPositionBuilder { - private TypeAnnotation.Position pos = new TypeAnnotation.Position(); - - private TAPositionBuilder() { } - - public TypeAnnotation.Position build() { return pos; } - - public static TAPositionBuilder ofType(TypeAnnotation.TargetType type) { - TAPositionBuilder builder = new TAPositionBuilder(); - builder.pos.type = type; - return builder; - } - - public TAPositionBuilder atOffset(int offset) { - switch (pos.type) { - // type cast - case TYPECAST: - // instanceof - case INSTANCEOF: - // new expression - case NEW: - pos.offset = offset; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atLocalPosition(int offset, int length, int index) { - switch (pos.type) { - // local variable - case LOCAL_VARIABLE: - pos.lvarOffset = new int[] { offset }; - pos.lvarLength = new int[] { length }; - pos.lvarIndex = new int[] { index }; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atParameterIndex(int index) { - switch (pos.type) { - // type parameters - case CLASS_TYPE_PARAMETER: - case METHOD_TYPE_PARAMETER: - // method parameter - case METHOD_FORMAL_PARAMETER: - pos.parameter_index = index; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atParamBound(int param, int bound) { - switch (pos.type) { - // type parameters bounds - case CLASS_TYPE_PARAMETER_BOUND: - case METHOD_TYPE_PARAMETER_BOUND: - pos.parameter_index = param; - pos.bound_index = bound; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atWildcardPosition(TypeAnnotation.Position pos) { - switch (pos.type) { - // wildcards - case WILDCARD_BOUND: - pos.wildcard_position = pos; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atTypeIndex(int index) { - switch (pos.type) { - // class extends or implements clauses - case CLASS_EXTENDS: - // throws - case THROWS: - pos.type_index = index; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atOffsetWithIndex(int offset, int index) { - switch (pos.type) { - // method type argument: wasn't specified - case NEW_TYPE_ARGUMENT: - case METHOD_TYPE_ARGUMENT: - pos.offset = offset; - pos.type_index = index; - break; - default: - throw new IllegalArgumentException("invalid field for given type: " + pos.type); - } - return this; - } - - public TAPositionBuilder atGenericLocation(Integer ...loc) { - pos.location = Arrays.asList(loc); - pos.type = pos.type.getGenericComplement(); - return this; - } - }*/ - /////////////////////// Equality testing ///////////////////// private static boolean areEquals(int a, int b) { return a == b || a == IGNORE_VALUE || b == IGNORE_VALUE; @@ -264,21 +142,18 @@ public class ReferenceInfoUtil { } public static boolean areEquals(TypeAnnotation.Position p1, TypeAnnotation.Position p2) { - if (p1 == p2) - return true; - if (p1 == null || p2 == null) - return false; + return p1 == p2 || !(p1 == null || p2 == null) && + p1.type == p2.type && + (p1.location.equals(p2.location)) && + areEquals(p1.offset, p2.offset) && + areEquals(p1.lvarOffset, p2.lvarOffset) && + areEquals(p1.lvarLength, p2.lvarLength) && + areEquals(p1.lvarIndex, p2.lvarIndex) && + areEquals(p1.bound_index, p2.bound_index) && + areEquals(p1.parameter_index, p2.parameter_index) && + areEquals(p1.type_index, p2.type_index) && + areEquals(p1.exception_index, p2.exception_index); - return ((p1.type == p2.type) - && (p1.location.equals(p2.location)) - && areEquals(p1.offset, p2.offset) - && areEquals(p1.lvarOffset, p2.lvarOffset) - && areEquals(p1.lvarLength, p2.lvarLength) - && areEquals(p1.lvarIndex, p2.lvarIndex) - && areEquals(p1.bound_index, p2.bound_index) - && areEquals(p1.parameter_index, p2.parameter_index) - && areEquals(p1.type_index, p2.type_index) - && areEquals(p1.exception_index, p2.exception_index)); } private static TypeAnnotation findAnnotation(String name, List annotations, ClassFile cf) throws InvalidIndex, UnexpectedEntry { @@ -306,9 +181,6 @@ public class ReferenceInfoUtil { if (actual == null) throw new ComparisionException("Expected annotation not found: " + aName); - // TODO: you currently get an exception if the test case does not use all necessary - // annotation attributes, e.g. forgetting the offset for a local variable. - // It would be nicer to give an understandable warning instead. if (!areEquals(expected, actual.position)) { throw new ComparisionException("Unexpected position for annotation : " + aName + "\n Expected: " + expected.toString() + diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ResourceVariable.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ResourceVariable.java new file mode 100644 index 00000000000..b4eae546dfc --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ResourceVariable.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012, 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 8042451 + * @summary Test population of reference info for resource variable + * @compile -g Driver.java ReferenceInfoUtil.java ResourceVariable.java + * @run main Driver ResourceVariable + */ + +import static com.sun.tools.classfile.TypeAnnotation.TargetType.RESOURCE_VARIABLE; +import static java.lang.System.lineSeparator; + +public class ResourceVariable { + + @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, + lvarOffset = {10}, lvarLength = {118}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, + lvarOffset = {22}, lvarLength = {35}, lvarIndex = {3}) + public String testResourceVariable() { + return + "public void f() throws IOException {" + lineSeparator() + + " try (@TA InputStream is1 = new FileInputStream(\"\")) {" + lineSeparator() + + " try (@TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + + " }" + lineSeparator() + + "}"; + } + + @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, + lvarOffset = {10}, lvarLength = {30}, lvarIndex = {1}) + public String testRepeatedAnnotation1() { + return + "public void f() throws IOException {" + lineSeparator() + + " try (@RTA @RTA InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + + "}"; + } + + @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, + lvarOffset = {10}, lvarLength = {30}, lvarIndex = {1}) + public String testRepeatedAnnotation2() { + return + "public void f() throws IOException {" + lineSeparator() + + " try (@RTAs({@RTA, @RTA}) InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + + "}"; + } + + @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, + lvarOffset = {10}, lvarLength = {118}, lvarIndex = {1}) + @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, + lvarOffset = {22}, lvarLength = {35}, lvarIndex = {3}) + public String testSeveralVariablesInTryWithResources() { + return + "public void f() throws IOException {" + lineSeparator() + + " try (@TA InputStream is1 = new FileInputStream(\"\");" + lineSeparator() + + " @TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + + "}"; + } +} diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java index e8c5798b248..dd7b567e752 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for type casts * @compile -g Driver.java ReferenceInfoUtil.java TypeCasts.java * @run main Driver TypeCasts @@ -37,27 +38,23 @@ public class TypeCasts { return "Object returnObject() { return (@TA String)null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TC", type = CAST, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TC", type = CAST, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String returnObjectArray() { return "Object returnObjectArray() { return (@TC String @TA [] @TB [])null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String returnObjectGeneric() { return "Object returnObjectGeneric() { return (@TA List<@TB String>)null; }"; } @@ -68,13 +65,11 @@ public class TypeCasts { return "Object returnPrim() { return (@TA int)0; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String returnPrimArray() { return "Object returnPrimArray() { return (@TB int @TA [])null; }"; } @@ -85,24 +80,20 @@ public class TypeCasts { return "void initObject() { Object a = (@TA String)null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String initObjectArray() { return "void initObjectArray() { Object a = (@TB String @TA [])null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String initObjectGeneric() { return "void initObjectGeneric() { Object a = (@TA List<@TB String>)null; }"; } @@ -113,13 +104,11 @@ public class TypeCasts { return "void initPrim() { Object a = (@TA int)0; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String initPrimArray() { return "void initPrimArray() { Object a = (@TB int @TA [])null; }"; } @@ -130,24 +119,20 @@ public class TypeCasts { return "void eqtestObject() { if (null == (@TA String)null); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String eqtestObjectArray() { return "void eqtestObjectArray() { if (null == (@TB String @TA [])null); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String eqtestObjectGeneric() { return "void eqtestObjectGeneric() { if (null == (@TA List<@TB String >)null); }"; } @@ -159,42 +144,182 @@ public class TypeCasts { return "void eqtestPrim(int a) { if (0 == (@TA int)a); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, - typeIndex = 0) - }) + @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) public String eqtestPrimArray() { return "void eqtestPrimArray() { if (null == (@TB int @TA [])null); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1), - @TADescription(annotation = "TC", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, - genericLocation = {3, 0}) - }) + @TADescription(annotation = "TA", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) + @TADescription(annotation = "TC", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, + genericLocation = {3, 0}) public String intersection1() { return "void intersection() { Object o = (@TA String & @TB Comparable<@TC String>) null; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0), - @TADescription(annotation = "TB", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1), - @TADescription(annotation = "TC", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, - genericLocation = {3, 0}), - @TADescription(annotation = "TD", type = CAST, - offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 2), - }) + @TADescription(annotation = "TA", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0) + @TADescription(annotation = "TB", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) + @TADescription(annotation = "TC", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, + genericLocation = {3, 0}) + @TADescription(annotation = "TD", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 2) public String intersection2() { return "void intersection() { Object o = (@TA String & @TB Comparable<@TC String> & @TD CharSequence) null; }"; } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnObjectRepeatableAnnotation() { + return "Object returnObject() { return (@RTA @RTA String)null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTCs", type = CAST, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnObjectArrayRepeatableAnnotation() { + return "Object returnObjectArray() { return (@RTC @RTC String @RTA @RTA [] @RTB @RTB [])null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnObjectGenericRepeatableAnnotation() { + return "Object returnObjectGeneric() { return (@RTA @RTA List<@RTB @RTB String>)null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnPrimRepeatableAnnotation() { + return "Object returnPrim() { return (@RTA @RTA int)0; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String returnPrimArrayRepeatableAnnotation() { + return "Object returnPrimArray() { return (@RTB @RTB int @RTA @RTA [])null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String initObjectRepeatableAnnotation() { + return "void initObject() { Object a = (@RTA @RTA String)null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String initObjectArrayRepeatableAnnotation() { + return "void initObjectArray() { Object a = (@RTB @RTB String @RTA @RTA [])null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String initObjectGenericRepeatableAnnotation() { + return "void initObjectGeneric() { Object a = (@RTA @RTA List<@RTB @RTB String>)null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String initPrimRepeatableAnnotation() { + return "void initPrim() { Object a = (@RTA @RTA int)0; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String initPrimArrayRepeatableAnnotation() { + return "void initPrimArray() { Object a = (@RTB @RTB int @RTA @RTA [])null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String eqtestObjectRepeatableAnnotation() { + return "void eqtestObject() { if (null == (@RTA @RTA String)null); }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String eqtestObjectArrayRepeatableAnnotation() { + return "void eqtestObjectArray() { if (null == (@RTB @RTB String @RTA @RTA [])null); }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String eqtestObjectGenericRepeatableAnnotation() { + return "void eqtestObjectGeneric() { if (null == (@RTA @RTA List<@RTB @RTB String >)null); }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + // compiler optimizes away compile time constants casts + public String eqtestPrimRepeatableAnnotation() { + return "void eqtestPrim(int a) { if (0 == (@RTA @RTA int)a); }"; + } + + @TADescription(annotation = "RTAs", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE, + typeIndex = 0) + public String eqtestPrimArrayRepeatableAnnotation() { + return "void eqtestPrimArray() { if (null == (@RTB @RTB int @RTA @RTA [])null); }"; + } + + @TADescription(annotation = "RTAs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) + @TADescription(annotation = "RTCs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, + genericLocation = {3, 0}) + public String intersectionRepeatableAnnotation1() { + return "void intersection() { Object o = (@RTA @RTA String & @RTB @RTB Comparable<@RTC @RTC String>) null; }"; + } + + @TADescription(annotation = "RTAs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 0) + @TADescription(annotation = "RTBs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1) + @TADescription(annotation = "RTCs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 1, + genericLocation = {3, 0}) + @TADescription(annotation = "RTDs", type = CAST, + offset = ReferenceInfoUtil.IGNORE_VALUE, typeIndex = 2) + public String intersectionRepeatableAnnotation2() { + return "void intersection() { Object o = (@RTA @RTA String & @RTB @RTB Comparable<@RTC @RTC String> &" + + " @RTD @RTD CharSequence) null; }"; + } } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeTests.java b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeTests.java index 8d26acf8cf4..6af89f3d3f9 100644 --- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeTests.java +++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeTests.java @@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; /* * @test + * @bug 8042451 * @summary Test population of reference info for class literals * @compile -g Driver.java ReferenceInfoUtil.java TypeTests.java * @run main Driver TypeTests @@ -36,26 +37,22 @@ public class TypeTests { return "Object returnObject() { return null instanceof @TA String; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String returnObjectArray() { return "Object returnObjectArray() { return null instanceof @TC String @TA [] @TB []; }"; } // no type test for primitives - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String returnPrimArray() { return "Object returnPrimArray() { return null instanceof @TC int @TA [] @TB []; }"; } @@ -68,26 +65,22 @@ public class TypeTests { return "void initObject() { Object a = null instanceof @TA String; }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String initObjectArray() { return "void initObjectArray() { Object a = null instanceof @TC String @TA [] @TB []; }"; } // no primitive instanceof - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String initPrimArray() { return "void initPrimArray() { Object a = null instanceof @TC int @TA [] @TB []; }"; } @@ -100,26 +93,22 @@ public class TypeTests { return "void eqtestObject() { if (true == (null instanceof @TA String)); }"; } - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String eqtestObjectArray() { return "void eqtestObjectArray() { if (true == (null instanceof @TC String @TA [] @TB [])); }"; } // no primitives - @TADescriptions({ - @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TB", type = INSTANCEOF, - genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), - @TADescription(annotation = "TC", type = INSTANCEOF, - genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) - }) + @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TB", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "TC", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) public String eqtestPrimArray() { return "void eqtestPrimArray() { if (true == (null instanceof @TC int @TA [] @TB [])); }"; } @@ -127,4 +116,72 @@ public class TypeTests { // no void // no void array + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnObjectRepeatableAnnotation() { + return "Object returnObject() { return null instanceof @RTA @RTA String; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnObjectArrayRepeatableAnnotation() { + return "Object returnObjectArray() { return null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB []; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String returnPrimArrayRepeatableAnnotation() { + return "Object returnPrimArrayRepeatableAnnotation() { return null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB []; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String initObjectRepeatableAnnotation() { + return "void initObject() { Object a = null instanceof @RTA @RTA String; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String initObjectArrayRepeatableAnnotation() { + return "void initObjectArray() { Object a = null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB []; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String initPrimArrayRepeatableAnnotation() { + return "void initPrimArray() { Object a = null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB []; }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String eqtestObjectRepeatableAnnotation() { + return "void eqtestObject() { if (true == (null instanceof @RTA @RTA String)); }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String eqtestObjectArrayRepeatableAnnotation() { + return "void eqtestObjectArray() { if (true == (null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB [])); }"; + } + + @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTBs", type = INSTANCEOF, + genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + @TADescription(annotation = "RTCs", type = INSTANCEOF, + genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) + public String eqtestPrimArrayRepeatableAnnotation() { + return "void eqtestPrimArray() { if (true == (null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB [])); }"; + } } From 15853aca130d9811cb496215cb30b0654ab1a2ee Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Sun, 8 Jun 2014 15:02:34 -0700 Subject: [PATCH 22/90] 7026941: 199: path options ignored when reusing filemanager across tasks Reviewed-by: jlahoda, jfranck --- .../tools/javac/api/ClientCodeWrapper.java | 5 +- .../sun/tools/javac/api/JavacTaskImpl.java | 9 + .../tools/javac/file/JavacFileManager.java | 16 +- .../com/sun/tools/javac/file/Locations.java | 359 +++++----- .../sun/tools/javac/main/JavaCompiler.java | 3 + .../com/sun/tools/javac/main/Main.java | 25 +- .../com/sun/tools/javac/main/Option.java | 3 + .../sun/tools/javac/main/OptionHelper.java | 10 +- .../tools/javac/nio/JavacPathFileManager.java | 7 +- .../sun/tools/javac/util/BaseFileManager.java | 56 +- .../classes/com/sun/tools/javadoc/Start.java | 18 +- .../com/sun/tools/javadoc/ToolOption.java | 33 +- langtools/test/tools/javac/T6358166.java | 21 +- langtools/test/tools/javac/T6358168.java | 36 +- .../test/tools/javac/api/TestSearchPaths.java | 632 ++++++++++++++++++ .../javac/diags/ArgTypeCompilerFactory.java | 47 +- .../javac/processing/6430209/T6430209.java | 6 +- 17 files changed, 1008 insertions(+), 278 deletions(-) create mode 100644 langtools/test/tools/javac/api/TestSearchPaths.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java b/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java index 0467c2cb371..6fd5b524f23 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java +++ b/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -202,9 +202,6 @@ public class ClientCodeWrapper { // - // FIXME: all these classes should be converted to use multi-catch when - // that is available in the bootstrap compiler. - protected class WrappedJavaFileManager implements JavaFileManager { protected JavaFileManager clientJavaFileManager; WrappedJavaFileManager(JavaFileManager clientJavaFileManager) { diff --git a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java index 9dba0badced..9d9ad45c5a4 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java @@ -161,6 +161,15 @@ public class JavacTaskImpl extends BasicJavacTask { compilerMain.log = Log.instance(context); compilerMain.setOptions(Options.instance(context)); compilerMain.filenames = new LinkedHashSet<>(); + compilerMain.deferredFileManagerOptions = new LinkedHashMap<>(); + // The following line is conceptually wrong. It should not refer to args + // which may include inappropriate file manager options. + // (Ideally, args should not even be passed into JavacTaskImpl at all.) + // The "no filenames in args" check should have been handled by the use of + // the GrumpyHelper in JavacTool.getTask, but processArgs also has some + // additional checking, which should be factored out and called separately. + // If we fix this, then filenames and deferredFileManagerOptions in Main + // can revert to being protected or private, not public. Collection filenames = compilerMain.processArgs(CommandLine.parse(args), classNames); if (filenames != null && !filenames.isEmpty()) throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java index f57ce741931..25f062ba28d 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java +++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -158,11 +158,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil symbolFileEnabled = b; } - @Override - public boolean isDefaultBootClassPath() { - return locations.isDefaultBootClassPath(); - } - public JavaFileObject getFileForInput(String name) { return getRegularFile(new File(name)); } @@ -579,15 +574,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil } } - private String defaultEncodingName; - private String getDefaultEncodingName() { - if (defaultEncodingName == null) { - defaultEncodingName = - new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); - } - return defaultEncodingName; - } - public ClassLoader getClassLoader(Location location) { nullCheck(location); Iterable path = getLocation(location); diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java b/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java index 3ba1d11ecbd..41068493961 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java +++ b/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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,12 +22,10 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.sun.tools.javac.file; -import java.io.FileNotFoundException; -import java.util.Iterator; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -38,64 +36,72 @@ import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.zip.ZipFile; + +import javax.tools.JavaFileManager; import javax.tools.JavaFileManager.Location; +import javax.tools.StandardJavaFileManager; import javax.tools.StandardLocation; import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; -import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.StringUtils; -import javax.tools.JavaFileManager; -import javax.tools.StandardJavaFileManager; -import static javax.tools.StandardLocation.*; -import static com.sun.tools.javac.main.Option.*; +import static javax.tools.StandardLocation.CLASS_PATH; +import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; +import static javax.tools.StandardLocation.SOURCE_PATH; -/** This class converts command line arguments, environment variables - * and system properties (in File.pathSeparator-separated String form) - * into a boot class path, user class path, and source path (in - * {@code Collection} form). +import static com.sun.tools.javac.main.Option.BOOTCLASSPATH; +import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; +import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; +import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; +import static com.sun.tools.javac.main.Option.EXTDIRS; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND; + +/** + * This class converts command line arguments, environment variables and system properties (in + * File.pathSeparator-separated String form) into a boot class path, user class path, and source + * path (in {@code Collection} form). * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. + *

+ * This is NOT part of any supported API. If you write code that depends on this, you do so at + * your own risk. This code and its internal interfaces are subject to change or deletion without + * notice. */ public class Locations { - /** The log to use for warning output */ + /** + * The log to use for warning output + */ private Log log; - /** Collection of command-line options */ - private Options options; - - /** Handler for -Xlint options */ - private Lint lint; - - /** Access to (possibly cached) file info */ + /** + * Access to (possibly cached) file info + */ private FSInfo fsInfo; - /** Whether to warn about non-existent path elements */ + /** + * Whether to warn about non-existent path elements + */ private boolean warn; - // TODO: remove need for this - private boolean inited = false; // TODO? caching bad? - public Locations() { initHandlers(); } - public void update(Log log, Options options, Lint lint, FSInfo fsInfo) { + // could replace Lint by "boolean warn" + public void update(Log log, Lint lint, FSInfo fsInfo) { this.log = log; - this.options = options; - this.lint = lint; + warn = lint.isEnabled(Lint.LintCategory.PATH); this.fsInfo = fsInfo; } @@ -104,14 +110,14 @@ public class Locations { } public boolean isDefaultBootClassPath() { - BootClassPathLocationHandler h = - (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); + BootClassPathLocationHandler h + = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); return h.isDefault(); } boolean isDefaultBootClassPathRtJar(File file) { - BootClassPathLocationHandler h = - (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); + BootClassPathLocationHandler h + = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); return h.isDefaultRtJar(file); } @@ -127,6 +133,7 @@ public class Locations { /** * Split a path into its elements. Empty path elements will be ignored. + * * @param path The path to be split * @return The elements of the path */ @@ -135,12 +142,13 @@ public class Locations { } /** - * Split a path into its elements. If emptyPathDefault is not null, all - * empty elements in the path, including empty elements at either end of - * the path, will be replaced with the value of emptyPathDefault. + * Split a path into its elements. If emptyPathDefault is not null, all empty elements in the + * path, including empty elements at either end of the path, will be replaced with the value of + * emptyPathDefault. + * * @param path The path to be split - * @param emptyPathDefault The value to substitute for empty path elements, - * or null, to ignore empty path elements + * @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore + * empty path elements * @return The elements of the path */ private static Iterable getPathEntries(String path, File emptyPathDefault) { @@ -148,33 +156,38 @@ public class Locations { int start = 0; while (start <= path.length()) { int sep = path.indexOf(File.pathSeparatorChar, start); - if (sep == -1) + if (sep == -1) { sep = path.length(); - if (start < sep) + } + if (start < sep) { entries.add(new File(path.substring(start, sep))); - else if (emptyPathDefault != null) + } else if (emptyPathDefault != null) { entries.add(emptyPathDefault); + } start = sep + 1; } return entries; } /** - * Utility class to help evaluate a path option. - * Duplicate entries are ignored, jar class paths can be expanded. + * Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths + * can be expanded. */ private class Path extends LinkedHashSet { + private static final long serialVersionUID = 0; private boolean expandJarClassPaths = false; - private Set canonicalValues = new HashSet<>(); + private final Set canonicalValues = new HashSet<>(); public Path expandJarClassPaths(boolean x) { expandJarClassPaths = x; return this; } - /** What to use when path element is the empty string */ + /** + * What to use when path element is the empty string + */ private File emptyPathDefault = null; public Path emptyPathDefault(File x) { @@ -182,15 +195,15 @@ public class Locations { return this; } - public Path() { super(); } - public Path addDirectories(String dirs, boolean warn) { boolean prev = expandJarClassPaths; expandJarClassPaths = true; try { - if (dirs != null) - for (File dir : getPathEntries(dirs)) + if (dirs != null) { + for (File dir : getPathEntries(dirs)) { addDirectory(dir, warn); + } + } return this; } finally { expandJarClassPaths = prev; @@ -203,19 +216,22 @@ public class Locations { private void addDirectory(File dir, boolean warn) { if (!dir.isDirectory()) { - if (warn) + if (warn) { log.warning(Lint.LintCategory.PATH, "dir.path.element.not.found", dir); + } return; } File[] files = dir.listFiles(); - if (files == null) + if (files == null) { return; + } for (File direntry : files) { - if (isArchive(direntry)) + if (isArchive(direntry)) { addFile(direntry, warn); + } } } @@ -232,8 +248,9 @@ public class Locations { public Path addFiles(Iterable files, boolean warn) { if (files != null) { - for (File file: files) + for (File file : files) { addFile(file, warn); + } } return this; } @@ -248,7 +265,7 @@ public class Locations { return; } - if (! fsInfo.exists(file)) { + if (!fsInfo.exists(file)) { /* No such file or directory exists */ if (warn) { log.warning(Lint.LintCategory.PATH, @@ -288,12 +305,13 @@ public class Locations { } /* Now what we have left is either a directory or a file name - conforming to archive naming convention */ + conforming to archive naming convention */ super.add(file); canonicalValues.add(canonFile); - if (expandJarClassPaths && fsInfo.isFile(file)) + if (expandJarClassPaths && fsInfo.isFile(file)) { addJarClassPath(file, warn); + } } // Adds referenced classpath elements from a jar's Class-Path @@ -302,7 +320,7 @@ public class Locations { // filenames, but if we do, we should redo all path-related code. private void addJarClassPath(File jarFile, boolean warn) { try { - for (File f: fsInfo.getJarClassPath(jarFile)) { + for (File f : fsInfo.getJarClassPath(jarFile)) { addFile(f, warn); } } catch (IOException e) { @@ -312,53 +330,56 @@ public class Locations { } /** - * Base class for handling support for the representation of Locations. - * Implementations are responsible for handling the interactions between - * the command line options for a location, and API access via setLocation. + * Base class for handling support for the representation of Locations. Implementations are + * responsible for handling the interactions between the command line options for a location, + * and API access via setLocation. + * * @see #initHandlers * @see #getHandler */ protected abstract class LocationHandler { + final Location location; final Set

A SerialClob is not safe for use by multiple concurrent threads. If a * SerialClob is to be used by more than one thread then access to the SerialClob * should be controlled by appropriate synchronization. + * * @author Jonathan Bruce + * @since 1.5 */ public class SerialClob implements Clob, Serializable, Cloneable { diff --git a/jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java b/jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java index 221502a868c..422fd25cba8 100644 --- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java +++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java @@ -48,6 +48,8 @@ import java.net.URL; * A SerialDatalink is not safe for use by multiple concurrent threads. If a * SerialDatalink is to be used by more than one thread then access to the * SerialDatalink should be controlled by appropriate synchronization. + * + * @since 1.5 */ public class SerialDatalink implements Serializable, Cloneable { diff --git a/jdk/src/share/classes/javax/sql/rowset/serial/SerialException.java b/jdk/src/share/classes/javax/sql/rowset/serial/SerialException.java index e2d0c11b84c..2429b176bb8 100644 --- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialException.java +++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialException.java @@ -32,6 +32,7 @@ import java.sql.SQLException; * SQL types such as BLOB, CLOB, STRUCT or ARRAY in * addition to SQL types such as DATALINK and JAVAOBJECT * + * @since 1.5 */ public class SerialException extends java.sql.SQLException { diff --git a/jdk/src/share/classes/javax/sql/rowset/serial/SerialJavaObject.java b/jdk/src/share/classes/javax/sql/rowset/serial/SerialJavaObject.java index 71f8c340cf4..7578c41d963 100644 --- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialJavaObject.java +++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialJavaObject.java @@ -54,6 +54,7 @@ import sun.reflect.misc.ReflectUtil; * SerialJavaObject should be controlled by appropriate synchronization. * * @author Jonathan Bruce + * @since 1.5 */ public class SerialJavaObject implements Serializable, Cloneable { diff --git a/jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java b/jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java index 834fafe32b6..91d3dcd57a2 100644 --- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java +++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java @@ -43,6 +43,7 @@ import java.util.*; * SerialRef is to be used by more than one thread then access to the SerialRef * should be controlled by appropriate synchronization. * + * @since 1.5 */ public class SerialRef implements Ref, Serializable, Cloneable { diff --git a/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java b/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java index 6eef84f3ef9..8937e3c48fc 100644 --- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java +++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java @@ -57,6 +57,7 @@ import javax.sql.rowset.*; * SerialStruct is to be used by more than one thread then access to the * SerialStruct should be controlled by appropriate synchronization. * + * @since 1.5 */ public class SerialStruct implements Struct, Serializable, Cloneable { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java b/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java index a4b757941da..586e19fb8c3 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java @@ -200,6 +200,7 @@ import sun.reflect.misc.ReflectUtil; * @author Jonathan Bruce * @see javax.sql.rowset.spi.SyncProvider * @see javax.sql.rowset.spi.SyncFactoryException + * @since 1.5 */ public class SyncFactory { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactoryException.java b/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactoryException.java index c904c9eb5fc..31daba55880 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactoryException.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactoryException.java @@ -35,6 +35,7 @@ import java.sql.SQLException; * @author Jonathan Bruce * @see javax.sql.rowset.spi.SyncFactory * @see javax.sql.rowset.spi.SyncFactoryException + * @since 1.5 */ public class SyncFactoryException extends java.sql.SQLException { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/SyncProvider.java b/jdk/src/share/classes/javax/sql/rowset/spi/SyncProvider.java index 6f1cc1620cb..14c605634bf 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/SyncProvider.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/SyncProvider.java @@ -209,6 +209,7 @@ import javax.sql.*; * @author Jonathan Bruce * @see javax.sql.rowset.spi.SyncFactory * @see javax.sql.rowset.spi.SyncFactoryException + * @since 1.5 */ public abstract class SyncProvider { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/SyncProviderException.java b/jdk/src/share/classes/javax/sql/rowset/spi/SyncProviderException.java index 57f9930a678..795667ab8b7 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/SyncProviderException.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/SyncProviderException.java @@ -61,6 +61,7 @@ import javax.sql.rowset.*; * @see javax.sql.rowset.spi.SyncFactory * @see javax.sql.rowset.spi.SyncResolver * @see javax.sql.rowset.spi.SyncFactoryException + * @since 1.5 */ public class SyncProviderException extends java.sql.SQLException { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/SyncResolver.java b/jdk/src/share/classes/javax/sql/rowset/spi/SyncResolver.java index 45fdfe02a53..4fee7df2f69 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/SyncResolver.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/SyncResolver.java @@ -231,7 +231,9 @@ import java.sql.SQLException; * } * } * } + * * @author Jonathan Bruce + * @since 1.5 */ public interface SyncResolver extends RowSet { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/TransactionalWriter.java b/jdk/src/share/classes/javax/sql/rowset/spi/TransactionalWriter.java index fce96e85821..ae69b1e4ca6 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/TransactionalWriter.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/TransactionalWriter.java @@ -44,6 +44,8 @@ import java.sql.Savepoint; * the CachedRowSet constant COMMIT_ON_ACCEPT_CHANGES * to false and use the commit and rollback * methods defined in this interface to manage transaction boundaries. + * + * @since 1.5 */ public interface TransactionalWriter extends RowSetWriter { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/XmlReader.java b/jdk/src/share/classes/javax/sql/rowset/spi/XmlReader.java index 9aad9cc3ac3..ba0ee8c9dce 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/XmlReader.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/XmlReader.java @@ -46,6 +46,8 @@ import javax.sql.rowset.*; * rowset's xmlReader field. When the WebRowSet * object's readXml method is invoked, it in turn invokes * its XML reader's readXML method. + * + * @since 1.5 */ public interface XmlReader extends RowSetReader { diff --git a/jdk/src/share/classes/javax/sql/rowset/spi/XmlWriter.java b/jdk/src/share/classes/javax/sql/rowset/spi/XmlWriter.java index 80ab78f6b77..79811d86d83 100644 --- a/jdk/src/share/classes/javax/sql/rowset/spi/XmlWriter.java +++ b/jdk/src/share/classes/javax/sql/rowset/spi/XmlWriter.java @@ -44,6 +44,8 @@ import javax.sql.rowset.*; * Writing a WebRowSet object includes printing the * rowset's data, metadata, and properties, all with the * appropriate XML tags. + * + * @since 1.5 */ public interface XmlWriter extends RowSetWriter { From ed271b0d5a72dc67601d07181512144f14894474 Mon Sep 17 00:00:00 2001 From: Otavio Goncalves de Santana Date: Mon, 16 Jun 2014 17:45:26 +0100 Subject: [PATCH 32/90] 8041679: Replace uses of StringBuffer with StringBuilder within core library classes Reviewed-by: psandoz, alanb, xuelei, dfuchs, jfranck, prr, serb, chegar --- .../imageio/plugins/gif/GIFImageReader.java | 2 +- .../sun/imageio/plugins/png/PNGMetadata.java | 2 +- .../java/swing/plaf/gtk/GTKFileChooserUI.java | 12 +- .../com/sun/java/swing/plaf/gtk/Metacity.java | 6 +- .../swing/plaf/motif/MotifFileChooserUI.java | 12 +- .../plaf/windows/WindowsFileChooserUI.java | 2 +- .../sun/java/util/jar/pack/BandStructure.java | 4 +- .../sun/java/util/jar/pack/ConstantPool.java | 2 +- .../com/sun/jmx/snmp/IPAcl/NetMaskImpl.java | 6 +- .../sun/jmx/snmp/IPAcl/ParseException.java | 2 +- .../com/sun/jmx/snmp/IPAcl/SnmpAcl.java | 4 +- .../com/sun/jmx/snmp/IPAcl/TokenMgrError.java | 2 +- .../classes/com/sun/jmx/snmp/SnmpMessage.java | 2 +- .../classes/com/sun/jmx/snmp/SnmpMsg.java | 14 +- .../classes/com/sun/jmx/snmp/SnmpOpaque.java | 2 +- .../com/sun/jmx/snmp/SnmpV3Message.java | 2 +- .../com/sun/jndi/cosnaming/CNNameParser.java | 4 +- .../com/sun/jndi/dns/DnsContextFactory.java | 8 +- .../classes/com/sun/jndi/dns/DnsName.java | 8 +- .../com/sun/jndi/dns/ResourceRecord.java | 12 +- .../classes/com/sun/jndi/ldap/ClientId.java | 2 +- .../com/sun/jndi/ldap/DigestClientId.java | 8 +- .../com/sun/jndi/ldap/LdapSchemaParser.java | 12 +- .../com/sun/jndi/ldap/ServiceLocator.java | 2 +- .../ldap/sasl/DefaultCallbackHandler.java | 2 +- .../sun/jndi/toolkit/dir/SearchFilter.java | 18 +-- .../com/sun/media/sound/SoftPerformer.java | 2 +- .../media/sound/WaveExtensibleFileReader.java | 2 +- .../xml/internal/security/utils/Base64.java | 2 +- .../com/sun/security/sasl/CramMD5Base.java | 2 +- .../com/sun/security/sasl/CramMD5Server.java | 18 +-- .../security/sasl/digest/DigestMD5Base.java | 4 +- .../security/sasl/digest/DigestMD5Server.java | 10 +- .../security/sasl/util/AbstractSaslImpl.java | 16 +- .../example/debug/bdi/ExceptionSpec.java | 6 +- .../example/debug/bdi/LineBreakpointSpec.java | 16 +- .../debug/bdi/MethodBreakpointSpec.java | 28 ++-- .../example/debug/expr/ExpressionParser.java | 2 +- .../example/debug/expr/ParseException.java | 4 +- .../example/debug/expr/TokenMgrError.java | 2 +- .../example/debug/gui/CommandInterpreter.java | 10 +- .../example/debug/gui/ContextManager.java | 2 +- .../tools/example/debug/gui/SourceModel.java | 2 +- .../example/debug/tty/BreakpointSpec.java | 24 +-- .../sun/tools/example/debug/tty/Commands.java | 48 +++--- .../com/sun/tools/example/debug/tty/Env.java | 8 +- .../com/sun/tools/example/debug/tty/TTY.java | 12 +- .../com/sun/tools/example/trace/Trace.java | 2 +- .../com/sun/tools/hat/internal/util/Misc.java | 20 +-- .../classes/com/sun/tools/jdi/FieldImpl.java | 10 +- .../com/sun/tools/jdi/JNITypeParser.java | 28 ++-- .../classes/com/sun/tools/jdi/MethodImpl.java | 2 +- .../com/sun/tools/jdi/ReferenceTypeImpl.java | 2 +- .../share/classes/com/sun/tools/jdi/SDE.java | 10 +- .../classes/com/sun/tools/jdi/TargetVM.java | 2 +- .../com/sun/tools/jdi/VirtualMachineImpl.java | 4 +- .../classes/java/beans/Introspector.java | 2 +- .../share/classes/java/beans/Statement.java | 2 +- .../classes/java/io/RandomAccessFile.java | 2 +- jdk/src/share/classes/java/net/IDN.java | 4 +- .../classes/java/net/SocketPermission.java | 2 +- jdk/src/share/classes/java/net/URI.java | 6 +- .../classes/java/net/URISyntaxException.java | 2 +- .../share/classes/java/net/URLDecoder.java | 2 +- .../share/classes/java/net/URLEncoder.java | 2 +- .../classes/java/net/URLStreamHandler.java | 2 +- .../java/nio/file/InvalidPathException.java | 2 +- jdk/src/share/classes/java/rmi/dgc/VMID.java | 12 +- .../classes/java/security/CodeSigner.java | 2 +- .../classes/java/security/Timestamp.java | 2 +- .../classes/java/security/cert/CertPath.java | 2 +- .../cert/CollectionCertStoreParameters.java | 2 +- .../cert/LDAPCertStoreParameters.java | 2 +- .../security/cert/PKIXBuilderParameters.java | 2 +- .../cert/PKIXCertPathBuilderResult.java | 2 +- .../cert/PKIXCertPathValidatorResult.java | 2 +- .../java/security/cert/PKIXParameters.java | 2 +- .../security/cert/PolicyQualifierInfo.java | 2 +- .../java/security/cert/TrustAnchor.java | 2 +- .../java/security/cert/X509CRLSelector.java | 2 +- .../java/security/cert/X509CertSelector.java | 2 +- .../classes/java/text/AttributedString.java | 6 +- .../share/classes/java/text/ChoiceFormat.java | 2 +- .../share/classes/java/util/Properties.java | 2 +- .../share/classes/java/util/prefs/Base64.java | 2 +- .../util/regex/PatternSyntaxException.java | 2 +- .../imageio/stream/ImageInputStreamImpl.java | 2 +- .../classes/javax/naming/BinaryRefAddr.java | 2 +- .../share/classes/javax/naming/NameImpl.java | 2 +- .../share/classes/javax/naming/RefAddr.java | 2 +- .../share/classes/javax/naming/Reference.java | 8 +- .../naming/directory/BasicAttribute.java | 2 +- .../share/classes/javax/print/MimeType.java | 4 +- .../print/attribute/ResolutionSyntax.java | 4 +- .../print/attribute/SetOfIntegerSyntax.java | 2 +- .../javax/print/attribute/Size2DSyntax.java | 4 +- .../auth/kerberos/KerberosTicket.java | 8 +- .../javax/sound/sampled/CompoundControl.java | 10 +- .../classes/javax/sound/sampled/DataLine.java | 14 +- .../classes/javax/swing/JColorChooser.java | 2 +- .../classes/javax/swing/MultiUIDefaults.java | 14 +- .../classes/javax/swing/RepaintManager.java | 2 +- .../javax/swing/event/TreeModelEvent.java | 22 +-- .../swing/plaf/basic/BasicFileChooserUI.java | 4 +- .../javax/swing/plaf/basic/BasicListUI.java | 16 +- .../javax/swing/plaf/basic/BasicTableUI.java | 22 +-- .../javax/swing/plaf/basic/BasicTreeUI.java | 16 +- .../swing/plaf/metal/MetalFileChooserUI.java | 12 +- .../javax/swing/plaf/nimbus/State.java | 30 ++-- .../swing/plaf/synth/ParsedSynthStyle.java | 4 +- .../swing/tree/DefaultTreeSelectionModel.java | 14 +- .../classes/javax/swing/tree/TreePath.java | 2 +- .../dsig/internal/dom/DOMExcC14NMethod.java | 2 +- .../classes/sun/applet/AppletViewer.java | 12 +- .../share/classes/sun/font/Decoration.java | 22 +-- .../sun/font/ExtendedTextSourceLabel.java | 38 ++--- .../classes/sun/font/StandardTextSource.java | 50 +++--- jdk/src/share/classes/sun/font/Type1Font.java | 2 +- .../classes/sun/java2d/opengl/OGLContext.java | 18 +-- .../share/classes/sun/java2d/pipe/Region.java | 2 +- .../java2d/pipe/hw/ContextCapabilities.java | 24 +-- .../sun/jvmstat/monitor/HostIdentifier.java | 2 +- .../sun/jvmstat/monitor/MonitoredHost.java | 2 +- .../sun/jvmstat/monitor/VmIdentifier.java | 2 +- .../share/classes/sun/management/Agent.java | 4 +- .../jvminstr/JvmThreadInstanceEntryImpl.java | 8 +- .../share/classes/sun/misc/MessageUtils.java | 2 +- jdk/src/share/classes/sun/misc/UUDecoder.java | 4 +- .../sun/net/TransferProtocolClient.java | 2 +- .../classes/sun/net/ftp/impl/FtpClient.java | 12 +- .../share/classes/sun/net/www/MimeEntry.java | 22 +-- .../classes/sun/net/www/http/HttpClient.java | 2 +- .../www/protocol/file/FileURLConnection.java | 8 +- .../protocol/http/DigestAuthentication.java | 2 +- .../sun/nio/ch/ServerSocketChannelImpl.java | 2 +- .../classes/sun/nio/ch/SocketChannelImpl.java | 2 +- .../share/classes/sun/print/PSPrinterJob.java | 2 +- .../sun/reflect/MethodAccessorGenerator.java | 12 +- .../classes/sun/rmi/server/Activation.java | 2 +- .../classes/sun/rmi/server/LoaderHandler.java | 2 +- .../share/classes/sun/rmi/server/Util.java | 2 +- .../classes/sun/security/acl/AclImpl.java | 2 +- .../sun/security/jgss/GSSCredentialImpl.java | 28 ++-- .../classes/sun/security/jgss/GSSHeader.java | 2 +- .../classes/sun/security/jgss/GSSToken.java | 2 +- .../sun/security/jgss/ProviderList.java | 12 +- .../sun/security/jgss/TokenTracker.java | 20 +-- .../sun/security/jgss/krb5/InitialToken.java | 10 +- .../sun/security/jgss/krb5/Krb5Context.java | 2 +- .../sun/security/jgss/wrapper/Krb5Util.java | 6 +- .../jgss/wrapper/NativeGSSContext.java | 8 +- .../sun/security/krb5/Credentials.java | 22 +-- .../sun/security/krb5/KrbException.java | 4 +- .../sun/security/krb5/PrincipalName.java | 8 +- .../security/krb5/internal/EncTicketPart.java | 2 +- .../security/krb5/internal/TicketFlags.java | 2 +- .../security/krb5/internal/crypto/EType.java | 2 +- .../krb5/internal/crypto/dk/DkCrypto.java | 2 +- .../krb5/internal/ktab/KeyTabEntry.java | 2 +- .../sun/security/pkcs/PKCS9Attribute.java | 26 ++-- .../sun/security/pkcs/PKCS9Attributes.java | 12 +- .../security/pkcs/SigningCertificateInfo.java | 24 +-- .../pkcs11/wrapper/CK_AES_CTR_PARAMS.java | 18 +-- .../sun/security/pkcs11/wrapper/CK_DATE.java | 16 +- .../wrapper/CK_ECDH1_DERIVE_PARAMS.java | 42 ++--- .../wrapper/CK_ECDH2_DERIVE_PARAMS.java | 74 ++++----- .../sun/security/pkcs11/wrapper/CK_INFO.java | 42 ++--- .../security/pkcs11/wrapper/CK_MECHANISM.java | 24 +-- .../pkcs11/wrapper/CK_MECHANISM_INFO.java | 30 ++-- .../pkcs11/wrapper/CK_PBE_PARAMS.java | 50 +++--- .../pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS.java | 58 +++---- .../wrapper/CK_RSA_PKCS_OAEP_PARAMS.java | 42 ++--- .../wrapper/CK_RSA_PKCS_PSS_PARAMS.java | 26 ++-- .../pkcs11/wrapper/CK_SESSION_INFO.java | 34 ++-- .../security/pkcs11/wrapper/CK_SLOT_INFO.java | 42 ++--- .../pkcs11/wrapper/CK_TOKEN_INFO.java | 146 +++++++++--------- .../wrapper/CK_X9_42_DH1_DERIVE_PARAMS.java | 42 ++--- .../wrapper/CK_X9_42_DH2_DERIVE_PARAMS.java | 74 ++++----- .../security/pkcs11/wrapper/Functions.java | 20 +-- .../sun/security/provider/AuthPolicyFile.java | 4 +- .../sun/security/provider/X509Factory.java | 4 +- .../sun/security/smartcardio/PCSC.java | 2 +- .../sun/security/ssl/HandshakeMessage.java | 8 +- .../sun/security/ssl/SSLSocketImpl.java | 2 +- .../sun/security/ssl/ServerNameExtension.java | 6 +- .../classes/sun/security/ssl/SessionId.java | 12 +- .../ssl/SignatureAlgorithmsExtension.java | 8 +- .../sun/security/tools/jarsigner/Main.java | 18 +-- .../sun/security/tools/keytool/Main.java | 4 +- .../security/tools/policytool/PolicyTool.java | 8 +- .../classes/sun/security/util/Debug.java | 16 +- .../security/util/ManifestEntryVerifier.java | 2 +- .../sun/security/util/ObjectIdentifier.java | 2 +- .../sun/security/util/PropertyExpander.java | 2 +- .../security/util/SignatureFileVerifier.java | 2 +- .../sun/security/x509/X509CRLImpl.java | 2 +- .../classes/sun/swing/SwingUtilities2.java | 2 +- .../swing/plaf/synth/DefaultSynthStyle.java | 36 ++--- .../plaf/synth/SynthFileChooserUIImpl.java | 12 +- .../classes/sun/text/normalizer/UTF16.java | 2 +- .../sun/tools/java/MemberDefinition.java | 14 +- .../classes/sun/tools/java/MethodSet.java | 12 +- .../classes/sun/tools/java/MethodType.java | 14 +- .../share/classes/sun/tools/java/Parser.java | 10 +- .../share/classes/sun/tools/java/Type.java | 12 +- .../classes/sun/tools/jconsole/Formatter.java | 12 +- .../sun/tools/jstatd/RemoteHostImpl.java | 2 +- .../sun/tools/native2ascii/N2AFilter.java | 2 +- .../sun/tools/serialver/SerialVer.java | 2 +- .../sun/tools/tree/FieldExpression.java | 10 +- .../share/classes/sun/tools/tree/Vset.java | 2 +- .../tracing/PrintStreamProviderFactory.java | 2 +- 212 files changed, 1124 insertions(+), 1124 deletions(-) diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java b/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java index 650fd313051..961f7a0682e 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java @@ -509,7 +509,7 @@ public class GIFImageReader extends ImageReader { byte[] signature = new byte[6]; stream.readFully(signature); - StringBuffer version = new StringBuffer(3); + StringBuilder version = new StringBuilder(3); version.append((char)signature[3]); version.append((char)signature[4]); version.append((char)signature[5]); diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java b/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java index 3ad3a8b6420..11018ec4015 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java @@ -900,7 +900,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { if (times == 1) { return s; } - StringBuffer sb = new StringBuffer((s.length() + 1)*times - 1); + StringBuilder sb = new StringBuilder((s.length() + 1)*times - 1); sb.append(s); for (int i = 1; i < times; i++) { sb.append(" "); diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java index ddbdcded4b6..0a6bd6ae57f 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java @@ -169,23 +169,23 @@ class GTKFileChooserUI extends SynthFileChooserUI { result.add(typedInName); } - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); len = result.size(); // construct the resulting string for (int i=0; i 0) { - buf.append(" "); + sb.append(" "); } if (len > 1) { - buf.append("\""); + sb.append("\""); } - buf.append(result.get(i)); + sb.append(result.get(i)); if (len > 1) { - buf.append("\""); + sb.append("\""); } } - return buf.toString(); + return sb.toString(); } public void setFileName(String fileName) { diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java index 72167580a92..b0a811c3bbf 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java @@ -533,13 +533,13 @@ class Metacity implements SynthConstants { // Pending: verify character encoding spec for gconf Reader reader = new InputStreamReader(url.openStream(), "ISO-8859-1"); char[] buf = new char[1024]; - StringBuffer strBuf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int n; while ((n = reader.read(buf)) >= 0) { - strBuf.append(buf, 0, n); + sb.append(buf, 0, n); } reader.close(); - String str = strBuf.toString(); + String str = sb.toString(); if (str != null) { String strLowerCase = str.toLowerCase(); int i = strLowerCase.indexOf(" 0) { - buf.append(" "); + sb.append(" "); } if (files.length > 1) { - buf.append("\""); + sb.append("\""); } - buf.append(fileNameString(files[i])); + sb.append(fileNameString(files[i])); if (files.length > 1) { - buf.append("\""); + sb.append("\""); } } - return buf.toString(); + return sb.toString(); } public MotifFileChooserUI(JFileChooser filechooser) { diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index 0def92eba15..76a30a13c5a 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -690,7 +690,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { } private String fileNameString(File[] files) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int i = 0; files != null && i < files.length; i++) { if (i > 0) { buf.append(" "); diff --git a/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java b/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java index 1152aa73f0c..a7db9784946 100644 --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java @@ -628,7 +628,7 @@ class BandStructure { } if (metaCoding.length > 0 && (verbose > 2 || verbose > 1 && metaCoding.length > 1)) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < metaCoding.length; i++) { if (i == 1) sb.append(" /"); sb.append(" ").append(metaCoding[i] & 0xFF); @@ -756,7 +756,7 @@ class BandStructure { " size="+outputSize()+ irr+" coding="+bandCoding); if (metaCoding != noMetaCoding) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < metaCoding.length; i++) { if (i == 1) sb.append(" /"); sb.append(" ").append(metaCoding[i] & 0xFF); diff --git a/jdk/src/share/classes/com/sun/java/util/jar/pack/ConstantPool.java b/jdk/src/share/classes/com/sun/java/util/jar/pack/ConstantPool.java index fd17dea7fdd..e4c7d7d931d 100644 --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/ConstantPool.java +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/ConstantPool.java @@ -1026,7 +1026,7 @@ class ConstantPool { } static String stringValueOf(MethodHandleEntry bsmRef, Entry[] argRefs) { - StringBuffer sb = new StringBuffer(bsmRef.stringValue()); + StringBuilder sb = new StringBuilder(bsmRef.stringValue()); // Arguments are formatted as "" instead of "[foo,bar,baz]". // This ensures there will be no confusion if "[,]" appear inside of names. char nextSep = '<'; diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/NetMaskImpl.java b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/NetMaskImpl.java index ac0fcc8b68c..9606c020266 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/NetMaskImpl.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/NetMaskImpl.java @@ -63,12 +63,12 @@ class NetMaskImpl extends PrincipalImpl implements Group, Serializable { if (SNMP_LOGGER.isLoggable(Level.FINEST)) { SNMP_LOGGER.logp(Level.FINEST, NetMaskImpl.class.getName(), "extractSubNet", "BINARY ARRAY :"); - StringBuffer buff = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for(int i =0; i < addrLength; i++) { - buff.append((b[i] &0xFF) +":"); + sb.append((b[i] & 0xFF) + ":"); } SNMP_LOGGER.logp(Level.FINEST, NetMaskImpl.class.getName(), - "extractSubNet", buff.toString()); + "extractSubNet", sb.toString()); } // 8 is a byte size. Common to any InetAddress (V4 or V6). diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/ParseException.java b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/ParseException.java index 7d7f3f7abba..78be1da103b 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/ParseException.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/ParseException.java @@ -170,7 +170,7 @@ class ParseException extends Exception { * string literal. */ protected String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java index a8e43c5337e..1a3fb7cc0cf 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java @@ -186,8 +186,8 @@ public class SnmpAcl implements InetAddressAcl, Serializable { public static String getDefaultAclFileName() { final String fileSeparator = System.getProperty("file.separator"); - final StringBuffer defaultAclName = - new StringBuffer(System.getProperty("java.home")). + final StringBuilder defaultAclName = + new StringBuilder(System.getProperty("java.home")). append(fileSeparator).append("lib").append(fileSeparator). append("snmp.acl"); return defaultAclName.toString(); diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/TokenMgrError.java b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/TokenMgrError.java index 1a0eba110ab..b09c4530d83 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/TokenMgrError.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/TokenMgrError.java @@ -65,7 +65,7 @@ class TokenMgrError extends Error * equivalents in the given string */ protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMessage.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMessage.java index 32685602ff0..ec4c87466c0 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMessage.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMessage.java @@ -347,7 +347,7 @@ public class SnmpMessage extends SnmpMsg implements SnmpDefinitions { * @return The string containing the dump. */ public String printMessage() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (community == null) { sb.append("Community: null") ; } diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMsg.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMsg.java index d72dc822c2e..cea4c744ad0 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMsg.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpMsg.java @@ -181,22 +181,22 @@ public abstract class SnmpMsg implements SnmpDefinitions { * @return The string containing the dump. */ public static String dumpHexBuffer(byte [] b, int offset, int len) { - StringBuffer buf = new StringBuffer(len << 1) ; + StringBuilder sb = new StringBuilder(len << 1) ; int k = 1 ; int flen = offset + len ; for (int i = offset; i < flen ; i++) { int j = b[i] & 0xFF ; - buf.append(Character.forDigit((j >>> 4) , 16)) ; - buf.append(Character.forDigit((j & 0x0F), 16)) ; + sb.append(Character.forDigit((j >>> 4), 16)) ; + sb.append(Character.forDigit((j & 0x0F), 16)) ; k++ ; if (k%16 == 0) { - buf.append('\n') ; + sb.append('\n') ; k = 1 ; } else - buf.append(' ') ; + sb.append(' ') ; } - return buf.toString() ; + return sb.toString() ; } /** @@ -205,7 +205,7 @@ public abstract class SnmpMsg implements SnmpDefinitions { * @return The string containing the dump. */ public String printMessage() { - StringBuffer sb = new StringBuffer() ; + StringBuilder sb = new StringBuilder() ; sb.append("Version: ") ; sb.append(version) ; sb.append("\n") ; diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpOpaque.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpOpaque.java index afe948e1519..50bb8b8c9aa 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpOpaque.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpOpaque.java @@ -73,7 +73,7 @@ public class SnmpOpaque extends SnmpString { * @return The String representation of the value. */ public String toString() { - StringBuffer result = new StringBuffer() ; + StringBuilder result = new StringBuilder() ; for (int i = 0 ; i < value.length ; i++) { byte b = value[i] ; int n = (b >= 0) ? b : b + 256 ; diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpV3Message.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpV3Message.java index bcdcc3ed0a0..64288f14c61 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpV3Message.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpV3Message.java @@ -478,7 +478,7 @@ public class SnmpV3Message extends SnmpMsg { * @return The string containing the dump. */ public String printMessage() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("msgId : " + msgId + "\n"); sb.append("msgMaxSize : " + msgMaxSize + "\n"); sb.append("msgFlags : " + msgFlags + "\n"); diff --git a/jdk/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java b/jdk/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java index 3b746528c3b..ebd0f05e65a 100644 --- a/jdk/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java +++ b/jdk/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java @@ -96,7 +96,7 @@ final public class CNNameParser implements NameParser { * Used by CNCtx.getNameInNamespace(), CNCompoundName.toString(). */ static String cosNameToInsString(NameComponent[] cname) { - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); for ( int i = 0; i < cname.length; i++) { if ( i > 0) { str.append(compSeparator); @@ -254,7 +254,7 @@ final public class CNNameParser implements NameParser { } private static String stringifyComponent(NameComponent comp) { - StringBuffer one = new StringBuffer(escape(comp.id)); + StringBuilder one = new StringBuilder(escape(comp.id)); if (comp.kind != null && !comp.kind.equals("")) { one.append(kindSeparator + escape(comp.kind)); } diff --git a/jdk/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java b/jdk/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java index 587d9b236d5..b6ad2c15bfc 100644 --- a/jdk/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java +++ b/jdk/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java @@ -198,14 +198,14 @@ public class DnsContextFactory implements InitialContextFactory { } } - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < servers.length; i++) { if (i > 0) { - buf.append(' '); + sb.append(' '); } - buf.append("dns://").append(servers[i]).append(path); + sb.append("dns://").append(servers[i]).append(path); } - return buf.toString(); + return sb.toString(); } /* diff --git a/jdk/src/share/classes/com/sun/jndi/dns/DnsName.java b/jdk/src/share/classes/com/sun/jndi/dns/DnsName.java index d2f76added9..eb4a7fb96f4 100644 --- a/jdk/src/share/classes/com/sun/jndi/dns/DnsName.java +++ b/jdk/src/share/classes/com/sun/jndi/dns/DnsName.java @@ -415,7 +415,7 @@ public final class DnsName implements Name { */ private void parse(String name) throws InvalidNameException { - StringBuffer label = new StringBuffer(); // label being parsed + StringBuilder label = new StringBuilder(); // label being parsed for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); @@ -564,15 +564,15 @@ public final class DnsName implements Name { * into account. See compareLabels(). */ private static String keyForLabel(String label) { - StringBuffer buf = new StringBuffer(label.length()); + StringBuilder sb = new StringBuilder(label.length()); for (int i = 0; i < label.length(); i++) { char c = label.charAt(i); if (c >= 'A' && c <= 'Z') { c += 'a' - 'A'; // to lower case } - buf.append(c); + sb.append(c); } - return buf.toString(); + return sb.toString(); } diff --git a/jdk/src/share/classes/com/sun/jndi/dns/ResourceRecord.java b/jdk/src/share/classes/com/sun/jndi/dns/ResourceRecord.java index 846135c45aa..c34bd680983 100644 --- a/jdk/src/share/classes/com/sun/jndi/dns/ResourceRecord.java +++ b/jdk/src/share/classes/com/sun/jndi/dns/ResourceRecord.java @@ -596,21 +596,21 @@ public class ResourceRecord { // If bestBase != -1, compress zeros in [bestBase, bestBase+bestLen) boolean compress = (bestBase != -1); - StringBuffer buf = new StringBuffer(40); + StringBuilder sb = new StringBuilder(40); if (bestBase == 0) { - buf.append(':'); + sb.append(':'); } for (int i = 0; i < 8; i++) { if (!compress || (i < bestBase) || (i >= bestBase + bestLen)) { - buf.append(Integer.toHexString(addr6[i])); + sb.append(Integer.toHexString(addr6[i])); if (i < 7) { - buf.append(':'); + sb.append(':'); } } else if (compress && (i == bestBase)) { // first compressed zero - buf.append(':'); + sb.append(':'); } } - return buf.toString(); + return sb.toString(); } } diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java b/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java index 9f75e8373e3..7a30c1c7beb 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java @@ -210,7 +210,7 @@ class ClientId { if (ctls == null) { return ""; } - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); for (int i = 0; i < ctls.length; i++) { str.append(ctls[i].getID()); str.append(' '); diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/DigestClientId.java b/jdk/src/share/classes/com/sun/jndi/ldap/DigestClientId.java index b4f19d02b3b..e7078098cbd 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/DigestClientId.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/DigestClientId.java @@ -103,14 +103,14 @@ class DigestClientId extends SimpleClientId { public String toString() { if (propvals != null) { - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < propvals.length; i++) { - buf.append(':'); + sb.append(':'); if (propvals[i] != null) { - buf.append(propvals[i]); + sb.append(propvals[i]); } } - return super.toString() + buf.toString(); + return super.toString() + sb.toString(); } else { return super.toString(); } diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java b/jdk/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java index 7804314fc15..7fddd7799f5 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java @@ -767,7 +767,7 @@ final class LdapSchemaParser { final private String classDef2ObjectDesc(Attributes attrs) throws NamingException { - StringBuffer objectDesc = new StringBuffer("( "); + StringBuilder objectDesc = new StringBuilder("( "); Attribute attr = null; int count = 0; @@ -879,7 +879,7 @@ final class LdapSchemaParser { final private String attrDef2AttrDesc(Attributes attrs) throws NamingException { - StringBuffer attrDesc = new StringBuffer("( "); // opening parens + StringBuilder attrDesc = new StringBuilder("( "); // opening parens Attribute attr = null; int count = 0; @@ -1012,7 +1012,7 @@ final class LdapSchemaParser { final private String syntaxDef2SyntaxDesc(Attributes attrs) throws NamingException { - StringBuffer syntaxDesc = new StringBuffer("( "); // opening parens + StringBuilder syntaxDesc = new StringBuilder("( "); // opening parens Attribute attr = null; int count = 0; @@ -1068,7 +1068,7 @@ final class LdapSchemaParser { final private String matchRuleDef2MatchRuleDesc(Attributes attrs) throws NamingException { - StringBuffer matchRuleDesc = new StringBuffer("( "); // opening parens + StringBuilder matchRuleDesc = new StringBuilder("( "); // opening parens Attribute attr = null; int count = 0; @@ -1196,7 +1196,7 @@ final class LdapSchemaParser { // write QDList - StringBuffer qdList = new StringBuffer(attr.getID()); + StringBuilder qdList = new StringBuilder(attr.getID()); qdList.append(WHSP); qdList.append(OID_LIST_BEGIN); @@ -1233,7 +1233,7 @@ final class LdapSchemaParser { // write OID List - StringBuffer oidList = new StringBuffer(oidsAttr.getID()); + StringBuilder oidList = new StringBuilder(oidsAttr.getID()); oidList.append(WHSP); oidList.append(OID_LIST_BEGIN); diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java b/jdk/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java index 5bbd58da462..05df1bbd6b7 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java @@ -68,7 +68,7 @@ class ServiceLocator { if (dn == null) { return null; } - StringBuffer domain = new StringBuffer(); + StringBuilder domain = new StringBuilder(); LdapName ldapName = new LdapName(dn); // process RDNs left-to-right diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java b/jdk/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java index 3bea1cc403d..3e0098eaaa4 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java @@ -88,7 +88,7 @@ final class DefaultCallbackHandler implements CallbackHandler { } } if (selected == -1) { - StringBuffer allChoices = new StringBuffer(); + StringBuilder allChoices = new StringBuilder(); for (int j = 0; j < choices.length; j++) { allChoices.append(choices[j] + ","); } diff --git a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java index ffdc9b8279f..bdbf578cc24 100644 --- a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java @@ -520,30 +520,30 @@ public class SearchFilter implements AttrFilter { str = (String)obj; } int len = str.length(); - StringBuffer buf = new StringBuffer(len); + StringBuilder sb = new StringBuilder(len); char ch; for (int i = 0; i < len; i++) { switch (ch=str.charAt(i)) { case '*': - buf.append("\\2a"); + sb.append("\\2a"); break; case '(': - buf.append("\\28"); + sb.append("\\28"); break; case ')': - buf.append("\\29"); + sb.append("\\29"); break; case '\\': - buf.append("\\5c"); + sb.append("\\5c"); break; case 0: - buf.append("\\00"); + sb.append("\\00"); break; default: - buf.append(ch); + sb.append(ch); } } - return buf.toString(); + return sb.toString(); } @@ -585,7 +585,7 @@ public class SearchFilter implements AttrFilter { int param; int where = 0, start = 0; - StringBuffer answer = new StringBuffer(expr.length()); + StringBuilder answer = new StringBuilder(expr.length()); while ((where = findUnescaped('{', expr, start)) >= 0) { int pstart = where + 1; // skip '{' diff --git a/jdk/src/share/classes/com/sun/media/sound/SoftPerformer.java b/jdk/src/share/classes/com/sun/media/sound/SoftPerformer.java index 905bdb3128e..5cd7c6eb92e 100644 --- a/jdk/src/share/classes/com/sun/media/sound/SoftPerformer.java +++ b/jdk/src/share/classes/com/sun/media/sound/SoftPerformer.java @@ -326,7 +326,7 @@ public final class SoftPerformer { private static KeySortComparator keySortComparator = new KeySortComparator(); private String extractKeys(ModelConnectionBlock conn) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (conn.getSources() != null) { sb.append("["); ModelSource[] srcs = conn.getSources(); diff --git a/jdk/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java b/jdk/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java index 827cef6a23a..ba46be6cf5a 100644 --- a/jdk/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java +++ b/jdk/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java @@ -162,7 +162,7 @@ public final class WaveExtensibleFileReader extends AudioFileReader { 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); private String decodeChannelMask(long channelmask) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); long m = 1; for (int i = 0; i < allchannelnames.length; i++) { if ((channelmask & m) != 0L) { diff --git a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/Base64.java b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/Base64.java index db1f49eaee4..de822922b36 100644 --- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/Base64.java +++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/Base64.java @@ -257,7 +257,7 @@ public class Base64 { public static final byte[] decode(Element element) throws Base64DecodingException { Node sibling = element.getFirstChild(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); while (sibling != null) { if (sibling.getNodeType() == Node.TEXT_NODE) { diff --git a/jdk/src/share/classes/com/sun/security/sasl/CramMD5Base.java b/jdk/src/share/classes/com/sun/security/sasl/CramMD5Base.java index 5d0309c60d0..4e51266f97b 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/CramMD5Base.java +++ b/jdk/src/share/classes/com/sun/security/sasl/CramMD5Base.java @@ -195,7 +195,7 @@ abstract class CramMD5Base { digest = md5.digest(); // Get character representation of digest - StringBuffer digestString = new StringBuffer(); + StringBuilder digestString = new StringBuilder(); for (i = 0; i < digest.length; i++) { if ((digest[i] & 0x000000ff) < 0x10) { diff --git a/jdk/src/share/classes/com/sun/security/sasl/CramMD5Server.java b/jdk/src/share/classes/com/sun/security/sasl/CramMD5Server.java index b87867b3ae7..94512f806dd 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/CramMD5Server.java +++ b/jdk/src/share/classes/com/sun/security/sasl/CramMD5Server.java @@ -117,15 +117,15 @@ final class CramMD5Server extends CramMD5Base implements SaslServer { long rand = random.nextLong(); long timestamp = System.currentTimeMillis(); - StringBuffer buf = new StringBuffer(); - buf.append('<'); - buf.append(rand); - buf.append('.'); - buf.append(timestamp); - buf.append('@'); - buf.append(fqdn); - buf.append('>'); - String challengeStr = buf.toString(); + StringBuilder sb = new StringBuilder(); + sb.append('<'); + sb.append(rand); + sb.append('.'); + sb.append(timestamp); + sb.append('@'); + sb.append(fqdn); + sb.append('>'); + String challengeStr = sb.toString(); logger.log(Level.FINE, "CRAMSRV01:Generated challenge: {0}", challengeStr); diff --git a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java index 548bac7273b..37a261a6a2f 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java +++ b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java @@ -387,7 +387,7 @@ abstract class DigestMD5Base extends AbstractSaslImpl { protected byte[] binaryToHex(byte[] digest) throws UnsupportedEncodingException { - StringBuffer digestString = new StringBuffer(); + StringBuilder digestString = new StringBuilder(); for (int i = 0; i < digest.length; i ++) { if ((digest[i] & 0x000000ff) < 0x10) { @@ -598,7 +598,7 @@ abstract class DigestMD5Base extends AbstractSaslImpl { protected static String nonceCountToHex(int count) { String str = Integer.toHexString(count); - StringBuffer pad = new StringBuffer(); + StringBuilder pad = new StringBuilder(); if (str.length() < 8) { for (int i = 0; i < 8-str.length(); i ++) { diff --git a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java index b722f0b36ba..449284258c3 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java +++ b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java @@ -203,19 +203,19 @@ final class DigestMD5Server extends DigestMD5Base implements SaslServer { String supportedCiphers = null; if ((allQop&PRIVACY_PROTECTION) != 0) { myCiphers = getPlatformCiphers(); - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); // myCipher[i] is a byte that indicates whether CIPHER_TOKENS[i] // is supported for (int i = 0; i < CIPHER_TOKENS.length; i++) { if (myCiphers[i] != 0) { - if (buf.length() > 0) { - buf.append(','); + if (sb.length() > 0) { + sb.append(','); } - buf.append(CIPHER_TOKENS[i]); + sb.append(CIPHER_TOKENS[i]); } } - supportedCiphers = buf.toString(); + supportedCiphers = sb.toString(); } try { diff --git a/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java b/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java index c0df4bf960d..eb122e3bbb4 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java +++ b/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java @@ -80,13 +80,13 @@ public abstract class AbstractSaslImpl { "SASLIMPL02:Preferred qop mask: {0}", new Byte(allQop)); if (qop.length > 0) { - StringBuffer qopbuf = new StringBuffer(); + StringBuilder str = new StringBuilder(); for (int i = 0; i < qop.length; i++) { - qopbuf.append(Byte.toString(qop[i])); - qopbuf.append(' '); + str.append(Byte.toString(qop[i])); + str.append(' '); } logger.logp(Level.FINE, myClassName, "constructor", - "SASLIMPL03:Preferred qops : {0}", qopbuf.toString()); + "SASLIMPL03:Preferred qops : {0}", str.toString()); } } @@ -95,13 +95,13 @@ public abstract class AbstractSaslImpl { logger.logp(Level.FINE, myClassName, "constructor", "SASLIMPL04:Preferred strength property: {0}", prop); if (logger.isLoggable(Level.FINE) && strength.length > 0) { - StringBuffer strbuf = new StringBuffer(); + StringBuilder str = new StringBuilder(); for (int i = 0; i < strength.length; i++) { - strbuf.append(Byte.toString(strength[i])); - strbuf.append(' '); + str.append(Byte.toString(strength[i])); + str.append(' '); } logger.logp(Level.FINE, myClassName, "constructor", - "SASLIMPL05:Cipher strengths: {0}", strbuf.toString()); + "SASLIMPL05:Cipher strengths: {0}", str.toString()); } // Max receive buffer size diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExceptionSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExceptionSpec.java index 489da6afc90..df87688152c 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExceptionSpec.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExceptionSpec.java @@ -102,8 +102,8 @@ public class ExceptionSpec extends EventRequestSpec { @Override public String toString() { - StringBuffer buffer = new StringBuffer("exception catch "); - buffer.append(refSpec.toString()); - return buffer.toString(); + StringBuilder sb = new StringBuilder("exception catch "); + sb.append(refSpec.toString()); + return sb.toString(); } } diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java index 0cfe97a75e2..f7d66ce2d52 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java @@ -118,13 +118,13 @@ public class LineBreakpointSpec extends BreakpointSpec { @Override public String toString() { - StringBuffer buffer = new StringBuffer("breakpoint "); - buffer.append(refSpec.toString()); - buffer.append(':'); - buffer.append(lineNumber); - buffer.append(" ("); - buffer.append(getStatusString()); - buffer.append(')'); - return buffer.toString(); + StringBuilder sb = new StringBuilder("breakpoint "); + sb.append(refSpec.toString()); + sb.append(':'); + sb.append(lineNumber); + sb.append(" ("); + sb.append(getStatusString()); + sb.append(')'); + return sb.toString(); } } diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java index 112d3a87f68..b414443faf7 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java @@ -126,26 +126,26 @@ public class MethodBreakpointSpec extends BreakpointSpec { @Override public String toString() { - StringBuffer buffer = new StringBuffer("breakpoint "); - buffer.append(refSpec.toString()); - buffer.append('.'); - buffer.append(methodId); + StringBuilder sb = new StringBuilder("breakpoint "); + sb.append(refSpec.toString()); + sb.append('.'); + sb.append(methodId); if (methodArgs != null) { boolean first = true; - buffer.append('('); + sb.append('('); for (String name : methodArgs) { if (!first) { - buffer.append(','); + sb.append(','); } - buffer.append(name); + sb.append(name); first = false; } - buffer.append(")"); + sb.append(")"); } - buffer.append(" ("); - buffer.append(getStatusString()); - buffer.append(')'); - return buffer.toString(); + sb.append(" ("); + sb.append(getStatusString()); + sb.append(')'); + return sb.toString(); } private boolean isValidMethodName(String s) { @@ -225,8 +225,8 @@ public class MethodBreakpointSpec extends BreakpointSpec { * stripping whitespace after the name ends. */ int i = 0; - StringBuffer typePart = new StringBuffer(); - StringBuffer arrayPart = new StringBuffer(); + StringBuilder typePart = new StringBuilder(); + StringBuilder arrayPart = new StringBuilder(); name = name.trim(); int nameLength = name.length(); /* diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java b/jdk/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java index 69deb789a94..5f0c12086d6 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java @@ -185,7 +185,7 @@ public class ExpressionParser implements ExpressionParserConstants { } final public String Name() throws ParseException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); jj_consume_token(IDENTIFIER); sb.append(token); label_2: diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/expr/ParseException.java b/jdk/src/share/classes/com/sun/tools/example/debug/expr/ParseException.java index 6df5e4bafc6..77b0980c282 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/expr/ParseException.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/expr/ParseException.java @@ -114,7 +114,7 @@ public class ParseException extends Exception { int[][] expectedTokenSequences, String[] tokenImage) { String eol = System.getProperty("line.separator", "\n"); - StringBuffer expected = new StringBuffer(); + StringBuilder expected = new StringBuilder(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { @@ -164,7 +164,7 @@ public class ParseException extends Exception { * string literal. */ static String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/expr/TokenMgrError.java b/jdk/src/share/classes/com/sun/tools/example/debug/expr/TokenMgrError.java index 5bc49c343a6..f6408697b48 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/expr/TokenMgrError.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/expr/TokenMgrError.java @@ -73,7 +73,7 @@ public class TokenMgrError extends Error * equivalents in the given string */ protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java index 8b7e88facac..fbff95b2703 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java @@ -267,7 +267,7 @@ public class CommandInterpreter { buf[j] = ' '; } buf[79] = '\0'; - StringBuffer sbOut = new StringBuffer(); + StringBuilder sbOut = new StringBuilder(); sbOut.append(buf); // Right-justify the thread number at start of output string @@ -381,16 +381,16 @@ public class CommandInterpreter { } } else { clname = t.nextToken(); - StringBuffer sbuf = new StringBuffer(); + StringBuilder str = new StringBuilder(); // Allow VM arguments to be specified here? while (t.hasMoreTokens()) { String tok = t.nextToken(); - sbuf.append(tok); + str.append(tok); if (t.hasMoreTokens()) { - sbuf.append(' '); + str.append(' '); } } - String args = sbuf.toString(); + String args = str.toString(); try { String vmArgs = context.getVmArguments(); runtime.run(suspended, vmArgs, clname, args); diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java index 52ceca4c19b..74c61b55969 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java @@ -333,7 +333,7 @@ public class ContextManager { private String processClasspathDefaults(String javaArgs) { if (javaArgs.indexOf("-classpath ") == -1) { - StringBuffer munged = new StringBuffer(javaArgs); + StringBuilder munged = new StringBuilder(javaArgs); SearchPath classpath = classManager.getClassPath(); if (classpath.isEmpty()) { String envcp = System.getProperty("env.class.path"); diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java index dc93d21ff4c..9b26646a70a 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java @@ -236,7 +236,7 @@ public class SourceModel extends AbstractListModel { private String expandTabs(String s) { int col = 0; int len = s.length(); - StringBuffer sb = new StringBuffer(132); + StringBuilder sb = new StringBuilder(132); for (int i = 0; i < len; i++) { char c = s.charAt(i); sb.append(c); diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java index f39a7f8059e..db0f25c1cb8 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java @@ -154,27 +154,27 @@ class BreakpointSpec extends EventRequestSpec { @Override public String toString() { - StringBuffer buffer = new StringBuffer(refSpec.toString()); + StringBuilder sb = new StringBuilder(refSpec.toString()); if (isMethodBreakpoint()) { - buffer.append('.'); - buffer.append(methodId); + sb.append('.'); + sb.append(methodId); if (methodArgs != null) { boolean first = true; - buffer.append('('); + sb.append('('); for (String arg : methodArgs) { if (!first) { - buffer.append(','); + sb.append(','); } - buffer.append(arg); + sb.append(arg); first = false; } - buffer.append(")"); + sb.append(")"); } } else { - buffer.append(':'); - buffer.append(lineNumber); + sb.append(':'); + sb.append(lineNumber); } - return MessageOutput.format("breakpoint", buffer.toString()); + return MessageOutput.format("breakpoint", sb.toString()); } private Location location(ReferenceType refType) throws @@ -275,8 +275,8 @@ class BreakpointSpec extends EventRequestSpec { * stripping whitespace after the name ends */ int i = 0; - StringBuffer typePart = new StringBuffer(); - StringBuffer arrayPart = new StringBuffer(); + StringBuilder typePart = new StringBuilder(); + StringBuilder arrayPart = new StringBuilder(); name = name.trim(); int nameLength = name.length(); /* diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java index 33f6e3ddf7f..65a0a800e09 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java @@ -164,30 +164,30 @@ class Commands { } String typedName(Method method) { - StringBuffer buf = new StringBuffer(); - buf.append(method.name()); - buf.append("("); + StringBuilder sb = new StringBuilder(); + sb.append(method.name()); + sb.append("("); List args = method.argumentTypeNames(); int lastParam = args.size() - 1; // output param types except for the last for (int ii = 0; ii < lastParam; ii++) { - buf.append(args.get(ii)); - buf.append(", "); + sb.append(args.get(ii)); + sb.append(", "); } if (lastParam >= 0) { // output the last param String lastStr = args.get(lastParam); if (method.isVarArgs()) { // lastParam is an array. Replace the [] with ... - buf.append(lastStr.substring(0, lastStr.length() - 2)); - buf.append("..."); + sb.append(lastStr.substring(0, lastStr.length() - 2)); + sb.append("..."); } else { - buf.append(lastStr); + sb.append(lastStr); } } - buf.append(")"); - return buf.toString(); + sb.append(")"); + return sb.toString(); } void commandConnectors(VirtualMachineManager vmm) { @@ -226,7 +226,7 @@ class Commands { } void commandClasses() { - StringBuffer classList = new StringBuffer(); + StringBuilder classList = new StringBuilder(); for (ReferenceType refType : Env.vm().allClasses()) { classList.append(refType.name()); classList.append("\n"); @@ -309,7 +309,7 @@ class Commands { String idClass = t.nextToken(); ReferenceType cls = Env.getReferenceTypeFromToken(idClass); if (cls != null) { - StringBuffer methodsList = new StringBuffer(); + StringBuilder methodsList = new StringBuilder(); for (Method method : cls.allMethods()) { methodsList.append(method.declaringType().name()); methodsList.append(" "); @@ -333,7 +333,7 @@ class Commands { if (cls != null) { List fields = cls.allFields(); List visible = cls.visibleFields(); - StringBuffer fieldsList = new StringBuffer(); + StringBuilder fieldsList = new StringBuilder(); for (Field field : fields) { String s; if (!visible.contains(field)) { @@ -391,11 +391,11 @@ class Commands { * very long thread names, at the possible cost of lines * being wrapped by the display device. */ - StringBuffer idBuffer = new StringBuffer(Env.description(thr)); + StringBuilder idBuffer = new StringBuilder(Env.description(thr)); for (int i = idBuffer.length(); i < maxIdLength; i++) { idBuffer.append(" "); } - StringBuffer nameBuffer = new StringBuffer(thr.name()); + StringBuilder nameBuffer = new StringBuilder(thr.name()); for (int i = nameBuffer.length(); i < maxNameLength; i++) { nameBuffer.append(" "); } @@ -1606,16 +1606,16 @@ class Commands { private void dump(ObjectReference obj, ReferenceType refType, ReferenceType refTypeBase) { for (Field field : refType.fields()) { - StringBuffer o = new StringBuffer(); - o.append(" "); + StringBuilder sb = new StringBuilder(); + sb.append(" "); if (!refType.equals(refTypeBase)) { - o.append(refType.name()); - o.append("."); + sb.append(refType.name()); + sb.append("."); } - o.append(field.name()); - o.append(MessageOutput.format("colon space")); - o.append(obj.getValue(field)); - MessageOutput.printDirectln(o.toString()); // Special case: use printDirectln() + sb.append(field.name()); + sb.append(MessageOutput.format("colon space")); + sb.append(obj.getValue(field)); + MessageOutput.printDirectln(sb.toString()); // Special case: use printDirectln() } if (refType instanceof ClassType) { ClassType sup = ((ClassType)refType).superclass(); @@ -1954,7 +1954,7 @@ class Commands { } } - StringBuffer line = new StringBuffer(80); + StringBuilder line = new StringBuilder(80); line.append("0000: "); for (int i = 0; i < bytecodes.length; i++) { if ((i > 0) && (i % 16 == 0)) { diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java index 63e1fe10e0e..b67295e840e 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java @@ -114,12 +114,12 @@ class Env { } static String excludesString() { - StringBuffer buffer = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String pattern : excludes()) { - buffer.append(pattern); - buffer.append(","); + sb.append(pattern); + sb.append(","); } - return buffer.toString(); + return sb.toString(); } static void addExcludes(StepRequest request) { diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java index 1958b9a8eca..8de89b26689 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java @@ -827,17 +827,17 @@ public class TTY implements EventNotifier { private static String addArgument(String string, String argument) { if (hasWhitespace(argument) || argument.indexOf(',') != -1) { // Quotes were stripped out for this argument, add 'em back. - StringBuffer buffer = new StringBuffer(string); - buffer.append('"'); + StringBuilder sb = new StringBuilder(string); + sb.append('"'); for (int i = 0; i < argument.length(); i++) { char c = argument.charAt(i); if (c == '"') { - buffer.append('\\'); + sb.append('\\'); } - buffer.append(c); + sb.append(c); } - buffer.append("\" "); - return buffer.toString(); + sb.append("\" "); + return sb.toString(); } else { return string + argument + ' '; } diff --git a/jdk/src/share/classes/com/sun/tools/example/trace/Trace.java b/jdk/src/share/classes/com/sun/tools/example/trace/Trace.java index fa66b3bd3d5..2ce99f97a01 100644 --- a/jdk/src/share/classes/com/sun/tools/example/trace/Trace.java +++ b/jdk/src/share/classes/com/sun/tools/example/trace/Trace.java @@ -121,7 +121,7 @@ public class Trace { usage(); System.exit(1); } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(args[inx]); for (++inx; inx < args.length; ++inx) { sb.append(' '); diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/util/Misc.java b/jdk/src/share/classes/com/sun/tools/hat/internal/util/Misc.java index 0fdf405967c..84a9291003c 100644 --- a/jdk/src/share/classes/com/sun/tools/hat/internal/util/Misc.java +++ b/jdk/src/share/classes/com/sun/tools/hat/internal/util/Misc.java @@ -83,30 +83,30 @@ public class Misc { public static String encodeHtml(String str) { final int len = str.length(); - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char ch = str.charAt(i); if (ch == '<') { - buf.append("<"); + sb.append("<"); } else if (ch == '>') { - buf.append(">"); + sb.append(">"); } else if (ch == '"') { - buf.append("""); + sb.append("""); } else if (ch == '\'') { - buf.append("'"); + sb.append("'"); } else if (ch == '&') { - buf.append("&"); + sb.append("&"); } else if (ch < ' ') { - buf.append("&#" + Integer.toString(ch) + ";"); + sb.append("&#" + Integer.toString(ch) + ";"); } else { int c = (ch & 0xFFFF); if (c > 127) { - buf.append("&#" + Integer.toString(c) + ";"); + sb.append("&#" + Integer.toString(c) + ";"); } else { - buf.append(ch); + sb.append(ch); } } } - return buf.toString(); + return sb.toString(); } } diff --git a/jdk/src/share/classes/com/sun/tools/jdi/FieldImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/FieldImpl.java index ecf6fdcb625..a7d46501d1c 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/FieldImpl.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/FieldImpl.java @@ -95,12 +95,12 @@ public class FieldImpl extends TypeComponentImpl } public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); - buf.append(declaringType().name()); - buf.append('.'); - buf.append(name()); + sb.append(declaringType().name()); + sb.append('.'); + sb.append(name()); - return buf.toString(); + return sb.toString(); } } diff --git a/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java b/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java index 2ed7265eb7a..4905fc69065 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java @@ -44,11 +44,11 @@ public class JNITypeParser { } static String typeNameToSignature(String signature) { - StringBuffer buffer = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int firstIndex = signature.indexOf('['); int index = firstIndex; while (index != -1) { - buffer.append('['); + sb.append('['); index = signature.indexOf('[', index + 1); } @@ -57,28 +57,28 @@ public class JNITypeParser { } if (signature.equals("boolean")) { - buffer.append('Z'); + sb.append('Z'); } else if (signature.equals("byte")) { - buffer.append('B'); + sb.append('B'); } else if (signature.equals("char")) { - buffer.append('C'); + sb.append('C'); } else if (signature.equals("short")) { - buffer.append('S'); + sb.append('S'); } else if (signature.equals("int")) { - buffer.append('I'); + sb.append('I'); } else if (signature.equals("long")) { - buffer.append('J'); + sb.append('J'); } else if (signature.equals("float")) { - buffer.append('F'); + sb.append('F'); } else if (signature.equals("double")) { - buffer.append('D'); + sb.append('D'); } else { - buffer.append('L'); - buffer.append(signature.replace('.', '/')); - buffer.append(';'); + sb.append('L'); + sb.append(signature.replace('.', '/')); + sb.append(';'); } - return buffer.toString(); + return sb.toString(); } String typeName() { diff --git a/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java index 1d93f4c76ba..b5cd9c67abd 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java @@ -387,7 +387,7 @@ public abstract class MethodImpl extends TypeComponentImpl } public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(declaringType().name()); sb.append("."); sb.append(name()); diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java index be98d5e0f3e..ab76a876e6d 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java @@ -751,7 +751,7 @@ implements ReferenceType { String baseSourceDir() { if (baseSourceDir == null) { String typeName = name(); - StringBuffer sb = new StringBuffer(typeName.length() + 10); + StringBuilder sb = new StringBuilder(typeName.length() + 10); int index = 0; int nextIndex; diff --git a/jdk/src/share/classes/com/sun/tools/jdi/SDE.java b/jdk/src/share/classes/com/sun/tools/jdi/SDE.java index 2ccaf25eb66..25fed40042d 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/SDE.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/SDE.java @@ -56,16 +56,16 @@ class SDE { if (sourcePath == null) { sourcePath = refType.baseSourceDir() + sourceName; } else { - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < sourcePath.length(); ++i) { char ch = sourcePath.charAt(i); if (ch == '/') { - buf.append(File.separatorChar); + sb.append(File.separatorChar); } else { - buf.append(ch); + sb.append(ch); } } - sourcePath = buf.toString(); + sourcePath = sb.toString(); } isConverted = true; } @@ -327,7 +327,7 @@ class SDE { } String readLine() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); char ch; ignoreWhite(); diff --git a/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java b/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java index a94eb43eafd..941ab405130 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java @@ -78,7 +78,7 @@ public class TargetVM implements Runnable { ", errorCode=" + packet.errorCode + ", flags=" + packet.flags); } - StringBuffer line = new StringBuffer(80); + StringBuilder line = new StringBuilder(80); line.append("0000: "); for (int i = 0; i < packet.data.length; i++) { if ((i > 0) && (i % 16 == 0)) { diff --git a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java index 3397e0f3ad1..ca1c6e21408 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java @@ -742,7 +742,7 @@ class VirtualMachineImpl extends MirrorImpl } void printReceiveTrace(int depth, String string) { - StringBuffer sb = new StringBuffer("Receiving:"); + StringBuilder sb = new StringBuilder("Receiving:"); for (int i = depth; i > 0; --i) { sb.append(" "); } @@ -872,7 +872,7 @@ class VirtualMachineImpl extends MirrorImpl ReferenceTypeImpl referenceType(long id, int tag, String signature) { if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("Looking up "); if (tag == JDWP.TypeTag.CLASS) { sb.append("Class"); diff --git a/jdk/src/share/classes/java/beans/Introspector.java b/jdk/src/share/classes/java/beans/Introspector.java index 10efa7ae5a8..3f1e564e8f5 100644 --- a/jdk/src/share/classes/java/beans/Introspector.java +++ b/jdk/src/share/classes/java/beans/Introspector.java @@ -1282,7 +1282,7 @@ public class Introspector { * Creates a key for a method in a method cache. */ private static String makeQualifiedMethodName(String name, String[] params) { - StringBuffer sb = new StringBuffer(name); + StringBuilder sb = new StringBuilder(name); sb.append('='); for (int i = 0; i < params.length; i++) { sb.append(':'); diff --git a/jdk/src/share/classes/java/beans/Statement.java b/jdk/src/share/classes/java/beans/Statement.java index 8eb88242a72..d1e6717817f 100644 --- a/jdk/src/share/classes/java/beans/Statement.java +++ b/jdk/src/share/classes/java/beans/Statement.java @@ -340,7 +340,7 @@ public class Statement { if (arguments == null) { arguments = emptyArray; } - StringBuffer result = new StringBuffer(instanceName(target) + "." + methodName + "("); + StringBuilder result = new StringBuilder(instanceName(target) + "." + methodName + "("); int n = arguments.length; for(int i = 0; i < n; i++) { result.append(instanceName(arguments[i])); diff --git a/jdk/src/share/classes/java/io/RandomAccessFile.java b/jdk/src/share/classes/java/io/RandomAccessFile.java index d5703937e54..ae1e530f168 100644 --- a/jdk/src/share/classes/java/io/RandomAccessFile.java +++ b/jdk/src/share/classes/java/io/RandomAccessFile.java @@ -890,7 +890,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { */ public final String readLine() throws IOException { - StringBuffer input = new StringBuffer(); + StringBuilder input = new StringBuilder(); int c = -1; boolean eol = false; diff --git a/jdk/src/share/classes/java/net/IDN.java b/jdk/src/share/classes/java/net/IDN.java index 34642b9824c..d4c8f5e426d 100644 --- a/jdk/src/share/classes/java/net/IDN.java +++ b/jdk/src/share/classes/java/net/IDN.java @@ -111,7 +111,7 @@ public final class IDN { public static String toASCII(String input, int flag) { int p = 0, q = 0; - StringBuffer out = new StringBuffer(); + StringBuilder out = new StringBuilder(); if (isRootLabel(input)) { return "."; @@ -172,7 +172,7 @@ public final class IDN { */ public static String toUnicode(String input, int flag) { int p = 0, q = 0; - StringBuffer out = new StringBuffer(); + StringBuilder out = new StringBuilder(); if (isRootLabel(input)) { return "."; diff --git a/jdk/src/share/classes/java/net/SocketPermission.java b/jdk/src/share/classes/java/net/SocketPermission.java index d44c8471613..1f3248077be 100644 --- a/jdk/src/share/classes/java/net/SocketPermission.java +++ b/jdk/src/share/classes/java/net/SocketPermission.java @@ -733,7 +733,7 @@ public final class SocketPermission extends Permission InetAddress auth; try { - StringBuffer sb = new StringBuffer(39); + StringBuilder sb = new StringBuilder(39); for (int i = 15; i >= 0; i--) { sb.append(Integer.toHexString(((addr[i]) & 0x0f))); diff --git a/jdk/src/share/classes/java/net/URI.java b/jdk/src/share/classes/java/net/URI.java index 0035d00ead7..62dea657c04 100644 --- a/jdk/src/share/classes/java/net/URI.java +++ b/jdk/src/share/classes/java/net/URI.java @@ -1957,7 +1957,7 @@ public final class URI private void defineString() { if (string != null) return; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (scheme != null) { sb.append(scheme); sb.append(':'); @@ -2015,7 +2015,7 @@ public final class URI if (i >= 0) path = base.substring(0, i + 1); } else { - StringBuffer sb = new StringBuffer(base.length() + cn); + StringBuilder sb = new StringBuilder(base.length() + cn); // 5.2 (6a) if (i >= 0) sb.append(base.substring(0, i + 1)); @@ -2778,7 +2778,7 @@ public final class URI if (s.indexOf('%') < 0) return s; - StringBuffer sb = new StringBuffer(n); + StringBuilder sb = new StringBuilder(n); ByteBuffer bb = ByteBuffer.allocate(n); CharBuffer cb = CharBuffer.allocate(n); CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8") diff --git a/jdk/src/share/classes/java/net/URISyntaxException.java b/jdk/src/share/classes/java/net/URISyntaxException.java index 8072c37244e..17d12bd9637 100644 --- a/jdk/src/share/classes/java/net/URISyntaxException.java +++ b/jdk/src/share/classes/java/net/URISyntaxException.java @@ -121,7 +121,7 @@ public class URISyntaxException * @return A string describing the parse error */ public String getMessage() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(getReason()); if (index > -1) { sb.append(" at index "); diff --git a/jdk/src/share/classes/java/net/URLDecoder.java b/jdk/src/share/classes/java/net/URLDecoder.java index 1e1138ad7ec..2c65c95fefc 100644 --- a/jdk/src/share/classes/java/net/URLDecoder.java +++ b/jdk/src/share/classes/java/net/URLDecoder.java @@ -134,7 +134,7 @@ public class URLDecoder { boolean needToChange = false; int numChars = s.length(); - StringBuffer sb = new StringBuffer(numChars > 500 ? numChars / 2 : numChars); + StringBuilder sb = new StringBuilder(numChars > 500 ? numChars / 2 : numChars); int i = 0; if (enc.length() == 0) { diff --git a/jdk/src/share/classes/java/net/URLEncoder.java b/jdk/src/share/classes/java/net/URLEncoder.java index 657572c6176..5ad817bc72c 100644 --- a/jdk/src/share/classes/java/net/URLEncoder.java +++ b/jdk/src/share/classes/java/net/URLEncoder.java @@ -201,7 +201,7 @@ public class URLEncoder { throws UnsupportedEncodingException { boolean needToChange = false; - StringBuffer out = new StringBuffer(s.length()); + StringBuilder out = new StringBuilder(s.length()); Charset charset; CharArrayWriter charArrayWriter = new CharArrayWriter(); diff --git a/jdk/src/share/classes/java/net/URLStreamHandler.java b/jdk/src/share/classes/java/net/URLStreamHandler.java index 0a8f1f1d5fe..9ea65260f3d 100644 --- a/jdk/src/share/classes/java/net/URLStreamHandler.java +++ b/jdk/src/share/classes/java/net/URLStreamHandler.java @@ -486,7 +486,7 @@ public abstract class URLStreamHandler { if (u.getRef() != null) len += 1 + u.getRef().length(); - StringBuffer result = new StringBuffer(len); + StringBuilder result = new StringBuilder(len); result.append(u.getProtocol()); result.append(":"); if (u.getAuthority() != null && u.getAuthority().length() > 0) { diff --git a/jdk/src/share/classes/java/nio/file/InvalidPathException.java b/jdk/src/share/classes/java/nio/file/InvalidPathException.java index 2c628652c24..c3d617b2896 100644 --- a/jdk/src/share/classes/java/nio/file/InvalidPathException.java +++ b/jdk/src/share/classes/java/nio/file/InvalidPathException.java @@ -117,7 +117,7 @@ public class InvalidPathException * @return a string describing the error */ public String getMessage() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(getReason()); if (index > -1) { sb.append(" at index "); diff --git a/jdk/src/share/classes/java/rmi/dgc/VMID.java b/jdk/src/share/classes/java/rmi/dgc/VMID.java index 913c598be2e..840bae4eeaa 100644 --- a/jdk/src/share/classes/java/rmi/dgc/VMID.java +++ b/jdk/src/share/classes/java/rmi/dgc/VMID.java @@ -120,15 +120,15 @@ public final class VMID implements java.io.Serializable { * Return string representation of this VMID. */ public String toString() { - StringBuffer result = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (addr != null) for (int i = 0; i < addr.length; ++ i) { int x = addr[i] & 0xFF; - result.append((x < 0x10 ? "0" : "") + - Integer.toString(x, 16)); + sb.append((x < 0x10 ? "0" : "") + + Integer.toString(x, 16)); } - result.append(':'); - result.append(uid.toString()); - return result.toString(); + sb.append(':'); + sb.append(uid.toString()); + return sb.toString(); } } diff --git a/jdk/src/share/classes/java/security/CodeSigner.java b/jdk/src/share/classes/java/security/CodeSigner.java index 37c12b153b3..a1d37ee208a 100644 --- a/jdk/src/share/classes/java/security/CodeSigner.java +++ b/jdk/src/share/classes/java/security/CodeSigner.java @@ -154,7 +154,7 @@ public final class CodeSigner implements Serializable { * if present. */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("("); sb.append("Signer: " + signerCertPath.getCertificates().get(0)); if (timestamp != null) { diff --git a/jdk/src/share/classes/java/security/Timestamp.java b/jdk/src/share/classes/java/security/Timestamp.java index f66d2883e62..668a6114510 100644 --- a/jdk/src/share/classes/java/security/Timestamp.java +++ b/jdk/src/share/classes/java/security/Timestamp.java @@ -141,7 +141,7 @@ public final class Timestamp implements Serializable { * its signer's certificate. */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("("); sb.append("timestamp: " + timestamp); List certs = signerCertPath.getCertificates(); diff --git a/jdk/src/share/classes/java/security/cert/CertPath.java b/jdk/src/share/classes/java/security/cert/CertPath.java index 8717f948203..88df135f6c0 100644 --- a/jdk/src/share/classes/java/security/cert/CertPath.java +++ b/jdk/src/share/classes/java/security/cert/CertPath.java @@ -220,7 +220,7 @@ public abstract class CertPath implements Serializable { * @return a string representation of this certification path */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); Iterator stringIterator = getCertificates().iterator(); diff --git a/jdk/src/share/classes/java/security/cert/CollectionCertStoreParameters.java b/jdk/src/share/classes/java/security/cert/CollectionCertStoreParameters.java index 12bd358cfff..e6ca94383fb 100644 --- a/jdk/src/share/classes/java/security/cert/CollectionCertStoreParameters.java +++ b/jdk/src/share/classes/java/security/cert/CollectionCertStoreParameters.java @@ -132,7 +132,7 @@ public class CollectionCertStoreParameters * @return a formatted string describing the parameters */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("CollectionCertStoreParameters: [\n"); sb.append(" collection: " + coll + "\n"); sb.append("]"); diff --git a/jdk/src/share/classes/java/security/cert/LDAPCertStoreParameters.java b/jdk/src/share/classes/java/security/cert/LDAPCertStoreParameters.java index 96fe9cd0939..2daef343d50 100644 --- a/jdk/src/share/classes/java/security/cert/LDAPCertStoreParameters.java +++ b/jdk/src/share/classes/java/security/cert/LDAPCertStoreParameters.java @@ -138,7 +138,7 @@ public class LDAPCertStoreParameters implements CertStoreParameters { * @return a formatted string describing the parameters */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("LDAPCertStoreParameters: [\n"); sb.append(" serverName: " + serverName + "\n"); diff --git a/jdk/src/share/classes/java/security/cert/PKIXBuilderParameters.java b/jdk/src/share/classes/java/security/cert/PKIXBuilderParameters.java index b33e1f8c1e2..51cf21e5e99 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXBuilderParameters.java +++ b/jdk/src/share/classes/java/security/cert/PKIXBuilderParameters.java @@ -189,7 +189,7 @@ public class PKIXBuilderParameters extends PKIXParameters { * @return a formatted string describing the parameters */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("[\n"); sb.append(super.toString()); sb.append(" Maximum Path Length: " + maxPathLength + "\n"); diff --git a/jdk/src/share/classes/java/security/cert/PKIXCertPathBuilderResult.java b/jdk/src/share/classes/java/security/cert/PKIXCertPathBuilderResult.java index 3255a3bbda6..01cedffe9c8 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXCertPathBuilderResult.java +++ b/jdk/src/share/classes/java/security/cert/PKIXCertPathBuilderResult.java @@ -107,7 +107,7 @@ public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult * {@code PKIXCertPathBuilderResult} */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("PKIXCertPathBuilderResult: [\n"); sb.append(" Certification Path: " + certPath + "\n"); sb.append(" Trust Anchor: " + getTrustAnchor().toString() + "\n"); diff --git a/jdk/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java b/jdk/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java index b40cd393c7d..3ba1e335a54 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java +++ b/jdk/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java @@ -148,7 +148,7 @@ public class PKIXCertPathValidatorResult implements CertPathValidatorResult { * {@code PKIXCertPathValidatorResult} */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("PKIXCertPathValidatorResult: [\n"); sb.append(" Trust Anchor: " + trustAnchor.toString() + "\n"); sb.append(" Policy Tree: " + String.valueOf(policyTree) + "\n"); diff --git a/jdk/src/share/classes/java/security/cert/PKIXParameters.java b/jdk/src/share/classes/java/security/cert/PKIXParameters.java index 4d8a344532e..a411f6e2aec 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXParameters.java +++ b/jdk/src/share/classes/java/security/cert/PKIXParameters.java @@ -693,7 +693,7 @@ public class PKIXParameters implements CertPathParameters { * @return a formatted string describing the parameters. */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("[\n"); /* start with trusted anchor info */ diff --git a/jdk/src/share/classes/java/security/cert/PolicyQualifierInfo.java b/jdk/src/share/classes/java/security/cert/PolicyQualifierInfo.java index ec06a88ae58..c09ccd6c3cd 100644 --- a/jdk/src/share/classes/java/security/cert/PolicyQualifierInfo.java +++ b/jdk/src/share/classes/java/security/cert/PolicyQualifierInfo.java @@ -161,7 +161,7 @@ public class PolicyQualifierInfo { if (pqiString != null) return pqiString; HexDumpEncoder enc = new HexDumpEncoder(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("PolicyQualifierInfo: [\n"); sb.append(" qualifierID: " + mId + "\n"); sb.append(" qualifier: " + diff --git a/jdk/src/share/classes/java/security/cert/TrustAnchor.java b/jdk/src/share/classes/java/security/cert/TrustAnchor.java index c98bf814caf..f7fb2c89497 100644 --- a/jdk/src/share/classes/java/security/cert/TrustAnchor.java +++ b/jdk/src/share/classes/java/security/cert/TrustAnchor.java @@ -317,7 +317,7 @@ public class TrustAnchor { * @return a formatted string describing the {@code TrustAnchor} */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("[\n"); if (pubKey != null) { sb.append(" Trusted CA Public Key: " + pubKey.toString() + "\n"); diff --git a/jdk/src/share/classes/java/security/cert/X509CRLSelector.java b/jdk/src/share/classes/java/security/cert/X509CRLSelector.java index 0580ee36bf2..a0e6b5b600a 100644 --- a/jdk/src/share/classes/java/security/cert/X509CRLSelector.java +++ b/jdk/src/share/classes/java/security/cert/X509CRLSelector.java @@ -566,7 +566,7 @@ public class X509CRLSelector implements CRLSelector { * {@code X509CRLSelector}. */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("X509CRLSelector: [\n"); if (issuerNames != null) { sb.append(" IssuerNames:\n"); diff --git a/jdk/src/share/classes/java/security/cert/X509CertSelector.java b/jdk/src/share/classes/java/security/cert/X509CertSelector.java index aae32c93f44..feb85d28b58 100644 --- a/jdk/src/share/classes/java/security/cert/X509CertSelector.java +++ b/jdk/src/share/classes/java/security/cert/X509CertSelector.java @@ -1811,7 +1811,7 @@ public class X509CertSelector implements CertSelector { * {@code CertSelector} */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("X509CertSelector: [\n"); if (x509Cert != null) { sb.append(" Certificate: " + x509Cert.toString() + "\n"); diff --git a/jdk/src/share/classes/java/text/AttributedString.java b/jdk/src/share/classes/java/text/AttributedString.java index fa398e943aa..2e82924510a 100644 --- a/jdk/src/share/classes/java/text/AttributedString.java +++ b/jdk/src/share/classes/java/text/AttributedString.java @@ -243,11 +243,11 @@ public class AttributedString { throw new IllegalArgumentException("Invalid substring range"); // Copy the given string - StringBuffer textBuffer = new StringBuffer(); + StringBuilder textBuilder = new StringBuilder(); text.setIndex(beginIndex); for (char c = text.current(); text.getIndex() < endIndex; c = text.next()) - textBuffer.append(c); - this.text = textBuffer.toString(); + textBuilder.append(c); + this.text = textBuilder.toString(); if (beginIndex == endIndex) return; diff --git a/jdk/src/share/classes/java/text/ChoiceFormat.java b/jdk/src/share/classes/java/text/ChoiceFormat.java index f55837f8a4c..f8bd9a90b59 100644 --- a/jdk/src/share/classes/java/text/ChoiceFormat.java +++ b/jdk/src/share/classes/java/text/ChoiceFormat.java @@ -259,7 +259,7 @@ public class ChoiceFormat extends NumberFormat { * @return the pattern string */ public String toPattern() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); for (int i = 0; i < choiceLimits.length; ++i) { if (i != 0) { result.append('|'); diff --git a/jdk/src/share/classes/java/util/Properties.java b/jdk/src/share/classes/java/util/Properties.java index 1df838e6394..e313c9716d0 100644 --- a/jdk/src/share/classes/java/util/Properties.java +++ b/jdk/src/share/classes/java/util/Properties.java @@ -602,7 +602,7 @@ class Properties extends Hashtable { if (bufLen < 0) { bufLen = Integer.MAX_VALUE; } - StringBuffer outBuffer = new StringBuffer(bufLen); + StringBuilder outBuffer = new StringBuilder(bufLen); for(int x=0; x= 0) { sb.append(" near index "); diff --git a/jdk/src/share/classes/javax/imageio/stream/ImageInputStreamImpl.java b/jdk/src/share/classes/javax/imageio/stream/ImageInputStreamImpl.java index 46d7748732c..5d2484017cb 100644 --- a/jdk/src/share/classes/javax/imageio/stream/ImageInputStreamImpl.java +++ b/jdk/src/share/classes/javax/imageio/stream/ImageInputStreamImpl.java @@ -289,7 +289,7 @@ public abstract class ImageInputStreamImpl implements ImageInputStream { } public String readLine() throws IOException { - StringBuffer input = new StringBuffer(); + StringBuilder input = new StringBuilder(); int c = -1; boolean eol = false; diff --git a/jdk/src/share/classes/javax/naming/BinaryRefAddr.java b/jdk/src/share/classes/javax/naming/BinaryRefAddr.java index 214e2aaa7f9..9061e2198de 100644 --- a/jdk/src/share/classes/javax/naming/BinaryRefAddr.java +++ b/jdk/src/share/classes/javax/naming/BinaryRefAddr.java @@ -165,7 +165,7 @@ public class BinaryRefAddr extends RefAddr { * @return The non-null string representation of this address. */ public String toString(){ - StringBuffer str = new StringBuffer("Address Type: " + addrType + "\n"); + StringBuilder str = new StringBuilder("Address Type: " + addrType + "\n"); str.append("AddressContents: "); for (int i = 0; i"i-j" otherwise. */ public String toString() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); int n = members.length; for (int i = 0; i < n; i++) { if (i > 0) { diff --git a/jdk/src/share/classes/javax/print/attribute/Size2DSyntax.java b/jdk/src/share/classes/javax/print/attribute/Size2DSyntax.java index aac527fed26..0f6a5dfe6c4 100644 --- a/jdk/src/share/classes/javax/print/attribute/Size2DSyntax.java +++ b/jdk/src/share/classes/javax/print/attribute/Size2DSyntax.java @@ -257,7 +257,7 @@ public abstract class Size2DSyntax implements Serializable, Cloneable { * (unchecked exception) Thrown if {@code units < 1}. */ public String toString(int units, String unitsName) { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); result.append(getX (units)); result.append('x'); result.append(getY (units)); @@ -312,7 +312,7 @@ public abstract class Size2DSyntax implements Serializable, Cloneable { * The values are reported in the internal units of micrometers. */ public String toString() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); result.append(x); result.append('x'); result.append(y); diff --git a/jdk/src/share/classes/javax/security/auth/kerberos/KerberosTicket.java b/jdk/src/share/classes/javax/security/auth/kerberos/KerberosTicket.java index c9e2b283e98..da38df976e7 100644 --- a/jdk/src/share/classes/javax/security/auth/kerberos/KerberosTicket.java +++ b/jdk/src/share/classes/javax/security/auth/kerberos/KerberosTicket.java @@ -636,11 +636,11 @@ public class KerberosTicket implements Destroyable, Refreshable, public String toString() { if (destroyed) throw new IllegalStateException("This ticket is no longer valid"); - StringBuffer caddrBuf = new StringBuffer(); + StringBuilder caddrString = new StringBuilder(); if (clientAddresses != null) { for (int i = 0; i < clientAddresses.length; i++) { - caddrBuf.append("clientAddresses[" + i + "] = " + - clientAddresses[i].toString()); + caddrString.append("clientAddresses[" + i + "] = " + + clientAddresses[i].toString()); } } return ("Ticket (hex) = " + "\n" + @@ -660,7 +660,7 @@ public class KerberosTicket implements Destroyable, Refreshable, "End Time = " + endTime.toString() + "\n" + "Renew Till = " + String.valueOf(renewTill) + "\n" + "Client Addresses " + - (clientAddresses == null ? " Null " : caddrBuf.toString() + + (clientAddresses == null ? " Null " : caddrString.toString() + "\n")); } diff --git a/jdk/src/share/classes/javax/sound/sampled/CompoundControl.java b/jdk/src/share/classes/javax/sound/sampled/CompoundControl.java index 1c7ba46ede9..bb01fbe9f43 100644 --- a/jdk/src/share/classes/javax/sound/sampled/CompoundControl.java +++ b/jdk/src/share/classes/javax/sound/sampled/CompoundControl.java @@ -94,18 +94,18 @@ public abstract class CompoundControl extends Control { */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < controls.length; i++) { if (i != 0) { - buf.append(", "); + sb.append(", "); if ((i + 1) == controls.length) { - buf.append("and "); + sb.append("and "); } } - buf.append(controls[i].getType()); + sb.append(controls[i].getType()); } - return new String(getType() + " Control containing " + buf + " Controls."); + return new String(getType() + " Control containing " + sb + " Controls."); } diff --git a/jdk/src/share/classes/javax/sound/sampled/DataLine.java b/jdk/src/share/classes/javax/sound/sampled/DataLine.java index d0030c9baae..d9013560381 100644 --- a/jdk/src/share/classes/javax/sound/sampled/DataLine.java +++ b/jdk/src/share/classes/javax/sound/sampled/DataLine.java @@ -471,23 +471,23 @@ public interface DataLine extends Line { */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if ( (formats.length == 1) && (formats[0] != null) ) { - buf.append(" supporting format " + formats[0]); + sb.append(" supporting format " + formats[0]); } else if (getFormats().length > 1) { - buf.append(" supporting " + getFormats().length + " audio formats"); + sb.append(" supporting " + getFormats().length + " audio formats"); } if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (maxBufferSize != AudioSystem.NOT_SPECIFIED) ) { - buf.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes"); + sb.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes"); } else if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (minBufferSize > 0) ) { - buf.append(", and buffers of at least " + minBufferSize + " bytes"); + sb.append(", and buffers of at least " + minBufferSize + " bytes"); } else if (maxBufferSize != AudioSystem.NOT_SPECIFIED) { - buf.append(", and buffers of up to " + minBufferSize + " bytes"); + sb.append(", and buffers of up to " + minBufferSize + " bytes"); } - return new String(super.toString() + buf); + return new String(super.toString() + sb); } } // class Info diff --git a/jdk/src/share/classes/javax/swing/JColorChooser.java b/jdk/src/share/classes/javax/swing/JColorChooser.java index 09cbf6c5d80..9420f499c41 100644 --- a/jdk/src/share/classes/javax/swing/JColorChooser.java +++ b/jdk/src/share/classes/javax/swing/JColorChooser.java @@ -542,7 +542,7 @@ public class JColorChooser extends JComponent implements Accessible { * @return a string representation of this JColorChooser */ protected String paramString() { - StringBuffer chooserPanelsString = new StringBuffer(""); + StringBuilder chooserPanelsString = new StringBuilder(""); for (int i=0; i 1) { - buf.delete(length-2, length); + sb.delete(length-2, length); } - buf.append("}"); - return buf.toString(); + sb.append("}"); + return sb.toString(); } } diff --git a/jdk/src/share/classes/javax/swing/RepaintManager.java b/jdk/src/share/classes/javax/swing/RepaintManager.java index c65c826eb45..5d397ad1af0 100644 --- a/jdk/src/share/classes/javax/swing/RepaintManager.java +++ b/jdk/src/share/classes/javax/swing/RepaintManager.java @@ -975,7 +975,7 @@ public class RepaintManager * @return a String representation of this object */ public synchronized String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if(dirtyComponents != null) sb.append("" + dirtyComponents); return sb.toString(); diff --git a/jdk/src/share/classes/javax/swing/event/TreeModelEvent.java b/jdk/src/share/classes/javax/swing/event/TreeModelEvent.java index 8dbdfcb8d3c..7bd565d9314 100644 --- a/jdk/src/share/classes/javax/swing/event/TreeModelEvent.java +++ b/jdk/src/share/classes/javax/swing/event/TreeModelEvent.java @@ -292,24 +292,24 @@ public class TreeModelEvent extends EventObject { * @return a String representation of this object */ public String toString() { - StringBuffer retBuffer = new StringBuffer(); + StringBuilder sb = new StringBuilder(); - retBuffer.append(getClass().getName() + " " + - Integer.toString(hashCode())); + sb.append(getClass().getName() + " " + + Integer.toString(hashCode())); if(path != null) - retBuffer.append(" path " + path); + sb.append(" path " + path); if(childIndices != null) { - retBuffer.append(" indices [ "); + sb.append(" indices [ "); for(int counter = 0; counter < childIndices.length; counter++) - retBuffer.append(Integer.toString(childIndices[counter])+ " "); - retBuffer.append("]"); + sb.append(Integer.toString(childIndices[counter])+ " "); + sb.append("]"); } if(children != null) { - retBuffer.append(" children [ "); + sb.append(" children [ "); for(int counter = 0; counter < children.length; counter++) - retBuffer.append(children[counter] + " "); - retBuffer.append("]"); + sb.append(children[counter] + " "); + sb.append("]"); } - return retBuffer.toString(); + return sb.toString(); } } diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java index b609dd2f2f0..e04b1c28e94 100644 --- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -1322,8 +1322,8 @@ public class BasicFileChooserUI extends FileChooserUI { return null; } - StringBuffer plainBuf = new StringBuffer(); - StringBuffer htmlBuf = new StringBuffer(); + StringBuilder plainBuf = new StringBuilder(); + StringBuilder htmlBuf = new StringBuilder(); htmlBuf.append("\n\n