1/* 2 * Copyright (c) 2012, 2016, 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 8042451 27 * @summary Test population of reference info for resource variable 28 * @modules jdk.jdeps/com.sun.tools.classfile 29 * @compile -g Driver.java ReferenceInfoUtil.java ResourceVariable.java 30 * @run main Driver ResourceVariable 31 */ 32 33import static com.sun.tools.classfile.TypeAnnotation.TargetType.RESOURCE_VARIABLE; 34import static java.lang.System.lineSeparator; 35 36public class ResourceVariable { 37 38 @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, 39 lvarOffset = {10}, lvarLength = {106}, lvarIndex = {1}) 40 @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, 41 lvarOffset = {22}, lvarLength = {31}, lvarIndex = {3}) 42 public String testResourceVariable() { 43 return 44 "public void f() throws IOException {" + lineSeparator() + 45 " try (@TA InputStream is1 = new FileInputStream(\"\")) {" + lineSeparator() + 46 " try (@TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + 47 " }" + lineSeparator() + 48 "}"; 49 } 50 51 @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, 52 lvarOffset = {10}, lvarLength = {26}, lvarIndex = {1}) 53 public String testRepeatedAnnotation1() { 54 return 55 "public void f() throws IOException {" + lineSeparator() + 56 " try (@RTA @RTA InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + 57 "}"; 58 } 59 60 @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, 61 lvarOffset = {10}, lvarLength = {26}, lvarIndex = {1}) 62 public String testRepeatedAnnotation2() { 63 return 64 "public void f() throws IOException {" + lineSeparator() + 65 " try (@RTAs({@RTA, @RTA}) InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + 66 "}"; 67 } 68 69 @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, 70 lvarOffset = {10}, lvarLength = {106}, lvarIndex = {1}) 71 @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, 72 lvarOffset = {22}, lvarLength = {31}, lvarIndex = {3}) 73 public String testSeveralVariablesInTryWithResources() { 74 return 75 "public void f() throws IOException {" + lineSeparator() + 76 " try (@TA InputStream is1 = new FileInputStream(\"\");" + lineSeparator() + 77 " @TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + 78 "}"; 79 } 80} 81