2015-07-10 09:42:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 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
|
2015-11-06 09:15:44 +00:00
|
|
|
* @bug 8044411 8079060 8138612
|
2015-07-10 09:42:00 +00:00
|
|
|
* @summary Tests the RuntimeParameterVisibleAnnotations/RuntimeParameterInvisibleAnnotations attribute.
|
2016-01-25 19:01:32 +00:00
|
|
|
* @modules jdk.jdeps/com.sun.tools.classfile
|
|
|
|
* jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.main
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* jdk.jdeps/com.sun.tools.javap
|
2015-07-10 09:42:00 +00:00
|
|
|
* @library /tools/lib /tools/javac/lib ../lib
|
|
|
|
* @build WorkAnnotations TestBase TestResult InMemoryFileManager ToolBox
|
|
|
|
* @build TestCase ClassType TestAnnotationInfo
|
|
|
|
* @build RuntimeParameterAnnotationsForLambdaTest AnnotationsTestBase RuntimeParameterAnnotationsTestBase
|
|
|
|
* @run main RuntimeParameterAnnotationsForLambdaTest
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2015-11-06 09:15:44 +00:00
|
|
|
import com.sun.tools.classfile.*;
|
2015-07-10 09:42:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* RuntimeParameterAnnotationsForLambdaTest is a test which checks that RuntimeVisibleParameterAnnotationsAttribute
|
2015-11-06 09:15:44 +00:00
|
|
|
* and RuntimeInvisibleParameterAnnotationsAttribute are not generated at all for lambda expressions.
|
2015-07-10 09:42:00 +00:00
|
|
|
* The test checks both single and repeatable annotations.
|
|
|
|
* All possible combinations of retention policies are tested.
|
|
|
|
*
|
|
|
|
* The test generates source code, compiles it and checks the byte code.
|
|
|
|
*
|
|
|
|
* See README.txt for more information.
|
|
|
|
*/
|
|
|
|
public class RuntimeParameterAnnotationsForLambdaTest extends RuntimeParameterAnnotationsTestBase {
|
|
|
|
|
|
|
|
private static final String CLASS_NAME = "Test";
|
|
|
|
private static final String SOURCE_TEMPLATE =
|
|
|
|
"public class " + CLASS_NAME + " {\n" +
|
|
|
|
" interface I { void method(int a, double b, String c); }\n" +
|
|
|
|
" %SOURCE%\n" +
|
|
|
|
"}";
|
|
|
|
|
|
|
|
public static void main(String[] args) throws TestFailedException {
|
|
|
|
new RuntimeParameterAnnotationsForLambdaTest().test();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void test() throws TestFailedException {
|
|
|
|
try {
|
|
|
|
for (TestAnnotationInfos annotations : getAllCombinationsOfAnnotations()) {
|
|
|
|
try {
|
|
|
|
TestCase.TestMethodInfo testMethodInfo = new TestCase.TestMethodInfo(0, null, "lambda", false, false);
|
|
|
|
TestCase.TestParameterInfo p1 = testMethodInfo.addParameter("int", "a");
|
|
|
|
annotations.annotate(p1);
|
|
|
|
testMethodInfo.addParameter("double", "b");
|
|
|
|
TestCase.TestParameterInfo p3 = testMethodInfo.addParameter("String", "c");
|
|
|
|
annotations.annotate(p3);
|
|
|
|
String source = SOURCE_TEMPLATE.replace("%SOURCE%", generateLambdaSource(testMethodInfo));
|
|
|
|
addTestCase(source);
|
2015-11-06 09:15:44 +00:00
|
|
|
echo("Testing:\n" + source);
|
2015-07-10 09:42:00 +00:00
|
|
|
ClassFile classFile = readClassFile(compile(source).getClasses().get(CLASS_NAME));
|
|
|
|
boolean isFoundLambda = false;
|
|
|
|
for (Method method : classFile.methods) {
|
|
|
|
if (method.getName(classFile.constant_pool).startsWith("lambda$")) {
|
|
|
|
isFoundLambda = true;
|
|
|
|
testAttributes(testMethodInfo, classFile, method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkTrue(isFoundLambda, "The tested lambda method was not found.");
|
|
|
|
} catch (Exception e) {
|
|
|
|
addFailure(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
checkStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 09:15:44 +00:00
|
|
|
protected void testAttributes(
|
|
|
|
TestCase.TestMethodInfo testMethod,
|
|
|
|
ClassFile classFile,
|
|
|
|
Method method) throws ConstantPoolException {
|
|
|
|
Attributes attributes = method.attributes;
|
|
|
|
RuntimeParameterAnnotations_attribute attr = (RuntimeParameterAnnotations_attribute) attributes.get(Attribute.RuntimeInvisibleParameterAnnotations);
|
|
|
|
checkNull(attr, String.format("%s should be null", Attribute.RuntimeInvisibleParameterAnnotations));
|
|
|
|
attr = (RuntimeParameterAnnotations_attribute) attributes.get(Attribute.RuntimeVisibleParameterAnnotations);
|
|
|
|
checkNull(attr, String.format("%s should be null", Attribute.RuntimeVisibleParameterAnnotations));
|
|
|
|
}
|
|
|
|
|
2015-07-10 09:42:00 +00:00
|
|
|
public String generateLambdaSource(TestCase.TestMethodInfo method) {
|
|
|
|
return method.parameters.stream()
|
|
|
|
.map(TestCase.TestParameterInfo::generateSource)
|
|
|
|
.collect(Collectors.joining(", ", "I i = (", ") -> {};"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<TestCase> generateTestCases() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
}
|