ResourceVariable.java revision 3351:d30f35629f0e
1141296Sdas/* 2141296Sdas * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42116Sjkh * 52116Sjkh * This code is free software; you can redistribute it and/or modify it 62116Sjkh * under the terms of the GNU General Public License version 2 only, as 7141296Sdas * published by the Free Software Foundation. 82116Sjkh * 9141296Sdas * This code is distributed in the hope that it will be useful, but WITHOUT 102116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112116Sjkh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 122116Sjkh * version 2 for more details (a copy is included in the LICENSE file that 132116Sjkh * accompanied this code). 142116Sjkh * 1550476Speter * You should have received a copy of the GNU General Public License version 162116Sjkh * 2 along with this work; if not, write to the Free Software Foundation, 172116Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 182116Sjkh * 192116Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 202116Sjkh * or visit www.oracle.com if you need additional information or have any 21141296Sdas * questions. 22141296Sdas */ 232116Sjkh 242116Sjkh/* 252116Sjkh * @test 26141296Sdas * @bug 8042451 272116Sjkh * @summary Test population of reference info for resource variable 282116Sjkh * @modules jdk.jdeps/com.sun.tools.classfile 292116Sjkh * @compile -g Driver.java ReferenceInfoUtil.java ResourceVariable.java 302116Sjkh * @run main Driver ResourceVariable 312116Sjkh */ 322116Sjkh 332116Sjkhimport static com.sun.tools.classfile.TypeAnnotation.TargetType.RESOURCE_VARIABLE; 342116Sjkhimport static java.lang.System.lineSeparator; 35141296Sdas 362116Sjkhpublic class ResourceVariable { 37141296Sdas 38141296Sdas @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, 392116Sjkh lvarOffset = {10}, lvarLength = {106}, lvarIndex = {1}) 402116Sjkh @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, 412116Sjkh lvarOffset = {22}, lvarLength = {31}, lvarIndex = {3}) 422116Sjkh public String testResourceVariable() { 432116Sjkh return 442116Sjkh "public void f() throws IOException {" + lineSeparator() + 452116Sjkh " try (@TA InputStream is1 = new FileInputStream(\"\")) {" + lineSeparator() + 462116Sjkh " try (@TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + 472116Sjkh " }" + lineSeparator() + 482116Sjkh "}"; 492116Sjkh } 502116Sjkh 512116Sjkh @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, 522116Sjkh lvarOffset = {10}, lvarLength = {26}, lvarIndex = {1}) 532116Sjkh public String testRepeatedAnnotation1() { 542116Sjkh return 552116Sjkh "public void f() throws IOException {" + lineSeparator() + 562116Sjkh " try (@RTA @RTA InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + 572116Sjkh "}"; 582116Sjkh } 592116Sjkh 602116Sjkh @TADescription(annotation = "RTAs", type = RESOURCE_VARIABLE, 612116Sjkh lvarOffset = {10}, lvarLength = {26}, lvarIndex = {1}) 622116Sjkh public String testRepeatedAnnotation2() { 632116Sjkh return 642116Sjkh "public void f() throws IOException {" + lineSeparator() + 652116Sjkh " try (@RTAs({@RTA, @RTA}) InputStream is1 = new FileInputStream(\"\")) {}" + lineSeparator() + 662116Sjkh "}"; 672116Sjkh } 682116Sjkh 692116Sjkh @TADescription(annotation = "TA", type = RESOURCE_VARIABLE, 702116Sjkh lvarOffset = {10}, lvarLength = {106}, lvarIndex = {1}) 712116Sjkh @TADescription(annotation = "TB", type = RESOURCE_VARIABLE, 722116Sjkh lvarOffset = {22}, lvarLength = {31}, lvarIndex = {3}) 732116Sjkh public String testSeveralVariablesInTryWithResources() { 742116Sjkh return 75141296Sdas "public void f() throws IOException {" + lineSeparator() + 76141296Sdas " try (@TA InputStream is1 = new FileInputStream(\"\");" + lineSeparator() + 772116Sjkh " @TB InputStream is2 = new FileInputStream(\"\")) {}" + lineSeparator() + 782116Sjkh "}"; 792116Sjkh } 802116Sjkh} 812116Sjkh