提交 85fe1ce9 编写于 作者: J jjg

8003412: javac needs to understand java.lang.annotation.Native

Reviewed-by: mcimadamore
上级 47883245
......@@ -130,6 +130,7 @@ public class Symtab {
public final Type methodHandleLookupType;
public final Type methodTypeType;
public final Type nativeHeaderType;
public final Type nativeHeaderType_old;
public final Type throwableType;
public final Type errorType;
public final Type interruptedExceptionType;
......@@ -505,7 +506,8 @@ public class Symtab {
List.of(exceptionType), methodClass),
autoCloseableType.tsym);
trustMeType = enterClass("java.lang.SafeVarargs");
nativeHeaderType = enterClass("javax.tools.annotation.GenerateNativeHeader");
nativeHeaderType = enterClass("java.lang.annotation.Native");
nativeHeaderType_old = enterClass("javax.tools.annotation.GenerateNativeHeader");
lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
synthesizeEmptyInterfaceIfMissing(autoCloseableType);
......
......@@ -157,13 +157,20 @@ public class JNIWriter {
if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
return false;
/* temporary code for backwards compatibility */
for (Attribute.Compound a: c.annotations.getAttributes()) {
if (a.type.tsym == syms.nativeHeaderType.tsym)
if (a.type.tsym == syms.nativeHeaderType_old.tsym)
return true;
}
/* end of temporary code for backwards compatibility */
for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
return true;
for (Attribute.Compound a: i.sym.annotations.getAttributes()) {
if (a.type.tsym == syms.nativeHeaderType.tsym)
return true;
}
}
if (checkNestedClasses) {
for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
......
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 7150368
* @bug 7150368 8003412
* @summary javac should include basic ability to generate native headers
*/
......@@ -125,7 +125,7 @@ public class NativeHeaderTest {
}
@Test
void annoTest(RunKind rk, GenKind gk) throws Exception {
void oldAnnoTest(RunKind rk, GenKind gk) throws Exception {
List<File> files = new ArrayList<File>();
files.add(createFile("p/C.java",
"@javax.tools.annotation.GenerateNativeHeader class C { }"));
......@@ -136,7 +136,18 @@ public class NativeHeaderTest {
}
@Test
void annoNestedClassTest(RunKind rk, GenKind gk) throws Exception {
void annoTest(RunKind rk, GenKind gk) throws Exception {
List<File> files = new ArrayList<File>();
files.add(createFile("p/C.java",
"class C { @java.lang.annotation.Native public static final int i = 1907; }"));
Set<String> expect = createSet("C.h");
test(rk, gk, files, expect);
}
@Test
void oldAnnoNestedClassTest(RunKind rk, GenKind gk) throws Exception {
List<File> files = new ArrayList<File>();
files.add(createFile("p/C.java",
"class C { @javax.tools.annotation.GenerateNativeHeader class Inner { } }"));
......@@ -147,6 +158,18 @@ public class NativeHeaderTest {
test(rk, gk, files, expect);
}
@Test
void annoNestedClassTest(RunKind rk, GenKind gk) throws Exception {
List<File> files = new ArrayList<File>();
files.add(createFile("p/C.java",
"class C { class Inner { @java.lang.annotation.Native public static final int i = 1907; } }"));
Set<String> expect = createSet("C_Inner.h");
if (gk == GenKind.FULL) expect.add("C.h");
test(rk, gk, files, expect);
}
/**
* The worker method for each test case.
* Compile the files and verify that exactly the expected set of header files
......
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 7150368
* @bug 7150368 8003412
* @summary javac should include basic ability to generate native headers
*/
......
/*
* Copyright (c) 2007, 2012, 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.annotation.Native;
public class TestClass4 {
@Native
public static final byte b = 1;
@Native
public static final short s = 2;
@Native
public static final int i = 3;
@Native
public static final long l = 4;
@Native
public static final float f = 5.0f;
@Native
public static final double d = 6.0;
@Native
public static final Object o = null;
@Native
public static final String t = "8";
}
/*
* Copyright (c) 2007, 2012, 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.annotation.Native;
public class TestClass5 {
@Native
public static final int tc5 = 1;
public class Inner1 {
@Native
public static final int tc5i1 = 2;
public class Inner1A {
@Native
public static final int tc5i1i1a = 3;
}
public class Inner1B {
@Native
public static final int tc5i1i1b = 4;
}
}
public class Inner2 {
@Native
public static final int tc521 = 5;
public class Inner2A {
@Native
public static final int tc5i2i2a = 6;
}
public class Inner2B {
@Native
public static final int tc5i2i2b = 7;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册