1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8026791 27 * @summary Test population of reference info for constructor results 28 * @compile -g Driver.java ReferenceInfoUtil.java Constructors.java 29 * @run main Driver Constructors 30 */ 31 32 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 33 34 public class Constructors { 35 36 @TADescriptions({ 37 @TADescription(annotation = "TA", type = METHOD_RETURN), 38 @TADescription(annotation = "TB", type = METHOD_RETURN), 39 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 40 }) 41 public String regularClass() { 42 return "class Test { @TA Test() {}" + 43 " @TB Test(@TC int b) {} }"; 44 } 45 46 @TADescriptions({ 47 @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}), 48 @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 49 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 50 }) 51 @TestClass("Test$Inner") 52 public String innerClass() { 53 return "class Test { class Inner {" + 54 " @TA Inner() {}" + 55 " @TB Inner(@TC int b) {}" + 56 " } }"; 57 } 58 59 @TADescriptions({ 60 @TADescription(annotation = "TA", type = METHOD_RECEIVER), 61 @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 62 @TADescription(annotation = "TC", type = METHOD_RECEIVER), 63 @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}), 64 @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 65 }) 66 @TestClass("Test$Inner") 67 public String innerClass2() { 68 return "class Test { class Inner {" + 69 " @TB Inner(@TA Test Test.this) {}" + 70 " @TD Inner(@TC Test Test.this, @TE int b) {}" + 71 " } }"; 72 } 73 74 @TADescriptions({ 75 @TADescription(annotation = "TA", type = METHOD_RECEIVER), 76 @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}), 77 @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 78 @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}), 79 @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 80 @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 81 }) 82 @TestClass("Outer$Middle$Inner") 83 public String innerClass3() { 84 return "class Outer { class Middle { class Inner {" + 85 " @TC Inner(@TA Outer. @TB Middle Middle.this) {}" + 86 " @TE Inner(@TD Middle Outer.Middle.this, @TF int b) {}" + 87 " } } }"; 88 } 89 90 @TADescriptions({ 91 @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 92 typeIndex = 0, offset = 4), 93 @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 94 typeIndex = 0, offset = 0) 95 }) 96 public String generic1() { 97 return "class Test { <T> Test(int i) { new <@TA T>Test(); }" + 98 " <T> Test() { <@TB String>this(0); } }"; 99 } 100 101 @TADescriptions({ 102 @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 103 typeIndex = 0, offset = 0) 104 }) 105 public String generic2() { 106 return "class Super { <T> Super(int i) { } } " + 107 "class Test extends Super { <T> Test() { <@TA String>super(0); } }"; 108 } 109 110 }