From d2bff49120a2e366a7acecfe5cfeabe2c4500a0b Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 9 Feb 2016 17:27:28 -0500 Subject: [PATCH] Bug 1244875 - Update binding generator; r=snorp Update the automatic binding generator to match the JNI template changes. --- build/annotationProcessors/CodeGenerator.java | 40 +++++++++---------- build/annotationProcessors/utils/Utils.java | 4 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/build/annotationProcessors/CodeGenerator.java b/build/annotationProcessors/CodeGenerator.java index f96026e50257..9faa460cf51f 100644 --- a/build/annotationProcessors/CodeGenerator.java +++ b/build/annotationProcessors/CodeGenerator.java @@ -27,6 +27,7 @@ public class CodeGenerator { private final Class cls; private final String clsName; + private boolean isMultithreaded; private final HashSet takenMethodNames = new HashSet(); @@ -36,30 +37,26 @@ public class CodeGenerator { final String unqualifiedName = Utils.getUnqualifiedName(clsName); header.append( - "class " + clsName + " : public mozilla::jni::Class<" + unqualifiedName + ">\n" + + "class " + clsName + " : public mozilla::jni::ObjectBase<" + + unqualifiedName + ", jobject>\n" + "{\n" + "public:\n" + - " typedef mozilla::jni::Ref<" + unqualifiedName + "> Ref;\n" + - " typedef mozilla::jni::LocalRef<" + unqualifiedName + "> LocalRef;\n" + - " typedef mozilla::jni::GlobalRef<" + unqualifiedName + "> GlobalRef;\n" + - " typedef const mozilla::jni::Param<" + unqualifiedName + ">& Param;\n" + - "\n" + - " static constexpr char name[] =\n" + - " \"" + cls.getName().replace('.', '/') + "\";\n" + - "\n" + - "protected:\n" + - " " + unqualifiedName + "(jobject instance) : Class(instance) {}\n" + + " explicit " + unqualifiedName + "(const Context& ctx) : ObjectBase<" + + unqualifiedName + ", jobject>(ctx) {}\n" + "\n"); cpp.append( - "constexpr char " + clsName + "::name[];\n" + + "template<> const char mozilla::jni::Context<" + + clsName + ", jobject>::name[] =\n" + + " \"" + cls.getName().replace('.', '/') + "\";\n" + "\n"); natives.append( "template\n" + "class " + clsName + "::Natives : " + "public mozilla::jni::NativeImpl<" + unqualifiedName + ", Impl>\n" + - "{\n"); + "{\n" + + "public:\n"); } private String getTraitsName(String uniqueName, boolean includeScope) { @@ -113,7 +110,6 @@ public class CodeGenerator { } header.append( - "public:\n" + " struct " + getTraitsName(uniqueName, /* includeScope */ false) + " {\n" + " typedef " + Utils.getUnqualifiedName(clsName) + " Owner;\n" + " typedef " + getNativeReturnType(type, info) + " ReturnType;\n" + @@ -124,7 +120,6 @@ public class CodeGenerator { " static constexpr char signature[] =\n" + " \"" + Utils.getSignature(member) + "\";\n" + " static const bool isStatic = " + Utils.isStatic(member) + ";\n" + - " static const bool isMultithreaded = " + info.isMultithreaded + ";\n" + " static const mozilla::jni::ExceptionMode exceptionMode =\n" + " " + ( info.catchException ? "mozilla::jni::ExceptionMode::NSRESULT" : @@ -139,6 +134,8 @@ public class CodeGenerator { "constexpr char " + getTraitsName(uniqueName, /* includeScope */ true) + "::signature[];\n" + "\n"); + + this.isMultithreaded |= info.isMultithreaded; } private String getUniqueMethodName(String basename) { @@ -261,7 +258,8 @@ public class CodeGenerator { // Generate a call, e.g., Method::Call(a0, a1, a2); def.append(accessorName).append("(") - .append(isStatic ? "nullptr" : "this"); + .append(Utils.getUnqualifiedName(clsName) + + (isStatic ? "::Context()" : "::mCtx")); if (info.catchException) { def.append(", &rv"); @@ -400,7 +398,6 @@ public class CodeGenerator { if (val != null && type.isPrimitive()) { // For static final primitive fields, we can use a "static const" declaration. header.append( - "public:\n" + " static const " + Utils.getNativeReturnType(type, info) + ' ' + info.wrapperName + " = " + getLiteral(val, info) + ";\n" + "\n"); @@ -410,7 +407,6 @@ public class CodeGenerator { final String nativeType = info.narrowChars ? "char" : "char16_t"; header.append( - "public:\n" + " static const " + nativeType + ' ' + info.wrapperName + "[];\n" + "\n"); @@ -519,8 +515,6 @@ public class CodeGenerator { return; } - header.append( - "public:\n"); for (final ClassWithOptions cls : classes) { // Extract "Inner" from "Outer::Inner". header.append( @@ -544,9 +538,12 @@ public class CodeGenerator { * @return The bytes to be written to the header file. */ public String getHeaderFileContents() { + header.append( + " static const bool isMultithreaded = " + this.isMultithreaded + ";\n" + + "\n"); + if (nativesInits.length() > 0) { header.append( - "public:\n" + " template class Natives;\n"); } header.append( @@ -565,7 +562,6 @@ public class CodeGenerator { return ""; } natives.append( - "public:\n" + " static constexpr JNINativeMethod methods[] = {" + nativesInits + '\n' + " };\n" + "};\n" + diff --git a/build/annotationProcessors/utils/Utils.java b/build/annotationProcessors/utils/Utils.java index 0e96f7232e65..136f43f9b635 100644 --- a/build/annotationProcessors/utils/Utils.java +++ b/build/annotationProcessors/utils/Utils.java @@ -88,7 +88,7 @@ public class Utils { if (type.equals(Class.class)) { // You're doing reflection on Java objects from inside C, returning Class objects // to C, generating the corresponding code using this Java program. Really?! - return "mozilla::jni::ClassObject::Param"; + return "mozilla::jni::Class::Param"; } if (type.equals(Throwable.class)) { @@ -120,7 +120,7 @@ public class Utils { if (type.equals(Class.class)) { // You're doing reflection on Java objects from inside C, returning Class objects // to C, generating the corresponding code using this Java program. Really?! - return "mozilla::jni::ClassObject::LocalRef"; + return "mozilla::jni::Class::LocalRef"; } if (type.equals(Throwable.class)) {