From e87cf0e4e1119637f568804201ab6457ac992c06 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 11:37:51 -0300 Subject: [PATCH 1/7] java interface support --- .gitignore | 2 + .../com/dropbox/textsort/TextboxListener.java | 2 +- .../djinni/benchmark/ObjectPlatform.java | 2 +- src/source/JavaGenerator.scala | 11 +++- test-suite/djinni/common.djinni | 1 + .../interface_and_abstract_class.djinni | 7 +++ .../cpp/test_java_abstract_class_only.hpp | 15 +++++ .../cpp/test_java_interface_only.hpp | 15 +++++ test-suite/generated-src/inFileList.txt | 1 + .../dropbox/djinni/test/AsyncInterface.java | 2 +- .../dropbox/djinni/test/ClientInterface.java | 2 +- .../dropbox/djinni/test/ExternInterface2.java | 2 +- .../dropbox/djinni/test/FirstListener.java | 2 +- .../dropbox/djinni/test/JavaOnlyListener.java | 2 +- .../dropbox/djinni/test/ObjcOnlyListener.java | 2 +- .../dropbox/djinni/test/SecondListener.java | 2 +- .../test/TestJavaAbstractClassOnly.java | 27 +++++++++ .../djinni/test/TestJavaInterfaceOnly.java | 11 ++++ .../djinni/test/ThrowingInterface.java | 2 +- .../jni/NativeTestJavaAbstractClassOnly.cpp | 29 +++++++++ .../jni/NativeTestJavaAbstractClassOnly.hpp | 32 ++++++++++ .../jni/NativeTestJavaInterfaceOnly.cpp | 26 ++++++++ .../jni/NativeTestJavaInterfaceOnly.hpp | 46 ++++++++++++++ .../DBTestJavaAbstractClassOnly+Private.h | 31 ++++++++++ .../DBTestJavaAbstractClassOnly+Private.mm | 60 +++++++++++++++++++ .../objc/DBTestJavaAbstractClassOnly.h | 11 ++++ .../objc/DBTestJavaInterfaceOnly+Private.h | 31 ++++++++++ .../objc/DBTestJavaInterfaceOnly+Private.mm | 30 ++++++++++ .../objc/DBTestJavaInterfaceOnly.h | 11 ++++ test-suite/generated-src/outFileList.txt | 18 ++++++ test-suite/generated-src/ts/test.ts | 12 ++++ .../wasm/NativeTestJavaAbstractClassOnly.cpp | 32 ++++++++++ .../wasm/NativeTestJavaAbstractClassOnly.hpp | 30 ++++++++++ .../wasm/NativeTestJavaInterfaceOnly.cpp | 16 +++++ .../wasm/NativeTestJavaInterfaceOnly.hpp | 27 +++++++++ .../test_java_abstract_class_only_impl.cpp | 10 ++++ .../test_java_abstract_class_only_impl.hpp | 14 +++++ .../com/dropbox/djinni/test/AllTests.java | 1 + .../com/dropbox/djinni/test/AsyncTest.java | 2 +- .../djinni/test/ClientInterfaceImpl.java | 2 +- .../test/InterfaceAndAbstractClass.java | 22 +++++++ 41 files changed, 590 insertions(+), 13 deletions(-) create mode 100644 test-suite/djinni/interface_and_abstract_class.djinni create mode 100644 test-suite/generated-src/cpp/test_java_abstract_class_only.hpp create mode 100644 test-suite/generated-src/cpp/test_java_interface_only.hpp create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaAbstractClassOnly.java create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java create mode 100644 test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.cpp create mode 100644 test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.hpp create mode 100644 test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.cpp create mode 100644 test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.hpp create mode 100644 test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.h create mode 100644 test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.mm create mode 100644 test-suite/generated-src/objc/DBTestJavaAbstractClassOnly.h create mode 100644 test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.h create mode 100644 test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.mm create mode 100644 test-suite/generated-src/objc/DBTestJavaInterfaceOnly.h create mode 100644 test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp create mode 100644 test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp create mode 100644 test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp create mode 100644 test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp create mode 100644 test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp create mode 100644 test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp create mode 100644 test-suite/handwritten-src/java/com/dropbox/djinni/test/InterfaceAndAbstractClass.java diff --git a/.gitignore b/.gitignore index ada091c4..92285051 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .idea/ +.vscode # bazel /bazel-* .ijwb/ @@ -22,3 +23,4 @@ test-suite/djinni/vendor/third-party/proto/ts/*.js .bsp /project /target +/.metals diff --git a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java index 664c21a3..12f69fa7 100644 --- a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java +++ b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java @@ -6,6 +6,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -/*package*/ abstract class TextboxListener { +/*package*/ interface TextboxListener { public abstract void update(@Nonnull ItemList items); } diff --git a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java index b660d903..1964c25f 100644 --- a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java +++ b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** interfaces for platform Java or Objective-C objects, to be passed to C++ */ -/*package*/ abstract class ObjectPlatform { +/*package*/ interface ObjectPlatform { public abstract void onDone(); } diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index 7da5231f..1214a176 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -174,8 +174,17 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { val typeParamList = javaTypeParams(typeParams) writeDoc(w, doc) + val statics = i.methods.filter(m => m.static && m.lang.java) + javaAnnotationHeader.foreach(w.wl) - w.w(s"${javaClassAccessModifierString}abstract class $javaClass$typeParamList").braced { + + // if no static and no cpp will use interface instead of abstract class + var classOrInterfaceDesc = "abstract class"; + if (!statics.nonEmpty && !i.ext.cpp) { + classOrInterfaceDesc = "interface" + } + + w.w(s"${javaClassAccessModifierString}${classOrInterfaceDesc} $javaClass$typeParamList").braced { val skipFirst = SkipFirst() generateJavaConstants(w, i.consts) diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index 1a078536..ed504d22 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -18,3 +18,4 @@ @import "array.djinni" @import "nscopying.djinni" @import "static_method_language.djinni" +@import "interface_and_abstract_class.djinni" diff --git a/test-suite/djinni/interface_and_abstract_class.djinni b/test-suite/djinni/interface_and_abstract_class.djinni new file mode 100644 index 00000000..723d80bc --- /dev/null +++ b/test-suite/djinni/interface_and_abstract_class.djinni @@ -0,0 +1,7 @@ +test_java_interface_only = interface +j { + test_method(): bool; +} + +test_java_abstract_class_only = interface +c { + static test_method(): bool; +} diff --git a/test-suite/generated-src/cpp/test_java_abstract_class_only.hpp b/test-suite/generated-src/cpp/test_java_abstract_class_only.hpp new file mode 100644 index 00000000..88d10b89 --- /dev/null +++ b/test-suite/generated-src/cpp/test_java_abstract_class_only.hpp @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +namespace testsuite { + +class TestJavaAbstractClassOnly { +public: + virtual ~TestJavaAbstractClassOnly() = default; + + static bool test_method(); +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/test_java_interface_only.hpp b/test-suite/generated-src/cpp/test_java_interface_only.hpp new file mode 100644 index 00000000..077dd128 --- /dev/null +++ b/test-suite/generated-src/cpp/test_java_interface_only.hpp @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +namespace testsuite { + +class TestJavaInterfaceOnly { +public: + virtual ~TestJavaInterfaceOnly() = default; + + virtual bool test_method() = 0; +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/inFileList.txt b/test-suite/generated-src/inFileList.txt index d3614d89..399faad9 100644 --- a/test-suite/generated-src/inFileList.txt +++ b/test-suite/generated-src/inFileList.txt @@ -21,6 +21,7 @@ djinni/relative_paths.djinni djinni/array.djinni djinni/nscopying.djinni djinni/static_method_language.djinni +djinni/interface_and_abstract_class.djinni djinni/enum_flags.djinni djinni/constant_enum.djinni djinni/data_ref_view.djinni diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java index 357be805..5810aa99 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java @@ -6,7 +6,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class AsyncInterface { +public interface AsyncInterface { @Nonnull public abstract com.snapchat.djinni.Future futureRoundtrip(@Nonnull com.snapchat.djinni.Future f); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java index f6024d9e..92a857cf 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; /** Client interface */ -public abstract class ClientInterface { +public interface ClientInterface { /** Returns record of given string */ @Nonnull public abstract ClientReturnedRecord getRecord(long recordId, @Nonnull String utf8string, @CheckForNull String misc); diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java index 48f8c8af..e5fc038f 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java @@ -3,6 +3,6 @@ package com.dropbox.djinni.test; -public abstract class ExternInterface2 { +public interface ExternInterface2 { public abstract ExternRecordWithDerivings foo(com.dropbox.djinni.test.TestHelpers i); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java index 32fa60da..f3ebb620 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** Used for ObjC multiple inheritance tests */ -public abstract class FirstListener { +public interface FirstListener { public abstract void first(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java index 7b552972..43d7fdf6 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java @@ -6,5 +6,5 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class JavaOnlyListener { +public interface JavaOnlyListener { } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java index f228f076..8dc9f189 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java @@ -6,5 +6,5 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class ObjcOnlyListener { +public interface ObjcOnlyListener { } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java index d841d32e..6f50945b 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** Used for ObjC multiple inheritance tests */ -public abstract class SecondListener { +public interface SecondListener { public abstract void second(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaAbstractClassOnly.java b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaAbstractClassOnly.java new file mode 100644 index 00000000..3e49bbaf --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaAbstractClassOnly.java @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +package com.dropbox.djinni.test; + +import com.snapchat.djinni.NativeObjectManager; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class TestJavaAbstractClassOnly { + public static native boolean testMethod(); + + public static final class CppProxy extends TestJavaAbstractClassOnly + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + NativeObjectManager.register(this, nativeRef); + } + public static native void nativeDestroy(long nativeRef); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java new file mode 100644 index 00000000..b36be532 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public interface TestJavaInterfaceOnly { + public abstract boolean testMethod(); +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java index 79dc232b..48ef2fa5 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java @@ -6,6 +6,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class ThrowingInterface { +public interface ThrowingInterface { public abstract void throwException(); } diff --git a/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.cpp b/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.cpp new file mode 100644 index 00000000..d2730903 --- /dev/null +++ b/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.cpp @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "NativeTestJavaAbstractClassOnly.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeTestJavaAbstractClassOnly::NativeTestJavaAbstractClassOnly() : ::djinni::JniInterface<::testsuite::TestJavaAbstractClassOnly, NativeTestJavaAbstractClassOnly>("com/dropbox/djinni/test/TestJavaAbstractClassOnly$CppProxy") {} + +NativeTestJavaAbstractClassOnly::~NativeTestJavaAbstractClassOnly() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_TestJavaAbstractClassOnly_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::TestJavaAbstractClassOnly>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jboolean JNICALL Java_com_dropbox_djinni_test_TestJavaAbstractClassOnly_testMethod(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + auto r = ::testsuite::TestJavaAbstractClassOnly::test_method(); + return ::djinni::release(::djinni::Bool::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.hpp b/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.hpp new file mode 100644 index 00000000..6472c8c9 --- /dev/null +++ b/test-suite/generated-src/jni/NativeTestJavaAbstractClassOnly.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_java_abstract_class_only.hpp" + +namespace djinni_generated { + +class NativeTestJavaAbstractClassOnly final : ::djinni::JniInterface<::testsuite::TestJavaAbstractClassOnly, NativeTestJavaAbstractClassOnly> { +public: + using CppType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using JniType = jobject; + + using Boxed = NativeTestJavaAbstractClassOnly; + + ~NativeTestJavaAbstractClassOnly(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeTestJavaAbstractClassOnly(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::TestJavaAbstractClassOnly, NativeTestJavaAbstractClassOnly>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.cpp b/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.cpp new file mode 100644 index 00000000..ef0f48a9 --- /dev/null +++ b/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.cpp @@ -0,0 +1,26 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "NativeTestJavaInterfaceOnly.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeTestJavaInterfaceOnly::NativeTestJavaInterfaceOnly() : ::djinni::JniInterface<::testsuite::TestJavaInterfaceOnly, NativeTestJavaInterfaceOnly>() {} + +NativeTestJavaInterfaceOnly::~NativeTestJavaInterfaceOnly() = default; + +NativeTestJavaInterfaceOnly::JavaProxy::JavaProxy(JniType j) : Handle(::djinni::jniGetThreadEnv(), j) { } + +NativeTestJavaInterfaceOnly::JavaProxy::~JavaProxy() = default; + +bool NativeTestJavaInterfaceOnly::JavaProxy::test_method() { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeTestJavaInterfaceOnly>::get(); + auto jret = jniEnv->CallBooleanMethod(Handle::get().get(), data.method_testMethod); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni::Bool::toCpp(jniEnv, jret); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.hpp b/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.hpp new file mode 100644 index 00000000..e008325a --- /dev/null +++ b/test-suite/generated-src/jni/NativeTestJavaInterfaceOnly.hpp @@ -0,0 +1,46 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_java_interface_only.hpp" + +namespace djinni_generated { + +class NativeTestJavaInterfaceOnly final : ::djinni::JniInterface<::testsuite::TestJavaInterfaceOnly, NativeTestJavaInterfaceOnly> { +public: + using CppType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using JniType = jobject; + + using Boxed = NativeTestJavaInterfaceOnly; + + ~NativeTestJavaInterfaceOnly(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeTestJavaInterfaceOnly(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::TestJavaInterfaceOnly, NativeTestJavaInterfaceOnly>; + + class JavaProxy final : ::djinni::JavaProxyHandle, public ::testsuite::TestJavaInterfaceOnly + { + public: + JavaProxy(JniType j); + ~JavaProxy(); + + bool test_method() override; + + private: + friend ::djinni::JniInterface<::testsuite::TestJavaInterfaceOnly, ::djinni_generated::NativeTestJavaInterfaceOnly>; + }; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/TestJavaInterfaceOnly") }; + const jmethodID method_testMethod { ::djinni::jniGetMethodID(clazz.get(), "testMethod", "()Z") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.h b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.h new file mode 100644 index 00000000..4c859c4f --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "test_java_abstract_class_only.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBTestJavaAbstractClassOnly; + +namespace djinni_generated { + +class TestJavaAbstractClassOnly +{ +public: + using CppType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using ObjcType = DBTestJavaAbstractClassOnly*; + + using Boxed = TestJavaAbstractClassOnly; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.mm b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.mm new file mode 100644 index 00000000..bf4d519c --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly+Private.mm @@ -0,0 +1,60 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#import "DBTestJavaAbstractClassOnly+Private.h" +#import "DBTestJavaAbstractClassOnly.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBTestJavaAbstractClassOnly () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>&)cppRef; + +@end + +@implementation DBTestJavaAbstractClassOnly { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + ++ (BOOL)testMethod { + try { + auto objcpp_result_ = ::testsuite::TestJavaAbstractClassOnly::test_method(); + return ::djinni::Bool::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto TestJavaAbstractClassOnly::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto TestJavaAbstractClassOnly::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly.h b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly.h new file mode 100644 index 00000000..92547d88 --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaAbstractClassOnly.h @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#import + + +@interface DBTestJavaAbstractClassOnly : NSObject + ++ (BOOL)testMethod; + +@end diff --git a/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.h b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.h new file mode 100644 index 00000000..28285b3d --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "test_java_interface_only.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBTestJavaInterfaceOnly; + +namespace djinni_generated { + +class TestJavaInterfaceOnly +{ +public: + using CppType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using ObjcType = DBTestJavaInterfaceOnly*; + + using Boxed = TestJavaInterfaceOnly; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.mm b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.mm new file mode 100644 index 00000000..6d75c4ab --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly+Private.mm @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#import "DBTestJavaInterfaceOnly+Private.h" +#import "DBTestJavaInterfaceOnly.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +namespace djinni_generated { + +auto TestJavaInterfaceOnly::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + DJINNI_UNIMPLEMENTED(@"Interface not implementable in any language."); +} + +auto TestJavaInterfaceOnly::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + DJINNI_UNIMPLEMENTED(@"Interface not implementable in any language."); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBTestJavaInterfaceOnly.h b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly.h new file mode 100644 index 00000000..88fec57f --- /dev/null +++ b/test-suite/generated-src/objc/DBTestJavaInterfaceOnly.h @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#import + + +@interface DBTestJavaInterfaceOnly : NSObject + +- (BOOL)testMethod; + +@end diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index 555f56f8..c1235fdf 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -20,6 +20,8 @@ djinni-output-temp/cpp/access_flags.hpp djinni-output-temp/cpp/empty_flags.hpp djinni-output-temp/cpp/flag_roundtrip.hpp djinni-output-temp/cpp/record_with_flags.hpp +djinni-output-temp/cpp/test_java_interface_only.hpp +djinni-output-temp/cpp/test_java_abstract_class_only.hpp djinni-output-temp/cpp/test_static_method_language.hpp djinni-output-temp/cpp/support_copying.hpp djinni-output-temp/cpp/vec2.hpp @@ -89,6 +91,8 @@ djinni-output-temp/java/AccessFlags.java djinni-output-temp/java/EmptyFlags.java djinni-output-temp/java/FlagRoundtrip.java djinni-output-temp/java/RecordWithFlags.java +djinni-output-temp/java/TestJavaInterfaceOnly.java +djinni-output-temp/java/TestJavaAbstractClassOnly.java djinni-output-temp/java/TestStaticMethodLanguage.java djinni-output-temp/java/SupportCopying.java djinni-output-temp/java/Vec2.java @@ -163,6 +167,10 @@ djinni-output-temp/jni/NativeFlagRoundtrip.hpp djinni-output-temp/jni/NativeFlagRoundtrip.cpp djinni-output-temp/jni/NativeRecordWithFlags.hpp djinni-output-temp/jni/NativeRecordWithFlags.cpp +djinni-output-temp/jni/NativeTestJavaInterfaceOnly.hpp +djinni-output-temp/jni/NativeTestJavaInterfaceOnly.cpp +djinni-output-temp/jni/NativeTestJavaAbstractClassOnly.hpp +djinni-output-temp/jni/NativeTestJavaAbstractClassOnly.cpp djinni-output-temp/jni/NativeTestStaticMethodLanguage.hpp djinni-output-temp/jni/NativeTestStaticMethodLanguage.cpp djinni-output-temp/jni/NativeSupportCopying.hpp @@ -274,6 +282,8 @@ djinni-output-temp/objc/DBEmptyFlags.h djinni-output-temp/objc/DBFlagRoundtrip.h djinni-output-temp/objc/DBRecordWithFlags.h djinni-output-temp/objc/DBRecordWithFlags.mm +djinni-output-temp/objc/DBTestJavaInterfaceOnly.h +djinni-output-temp/objc/DBTestJavaAbstractClassOnly.h djinni-output-temp/objc/DBTestStaticMethodLanguage.h djinni-output-temp/objc/DBSupportCopying.h djinni-output-temp/objc/DBSupportCopying.mm @@ -368,6 +378,10 @@ djinni-output-temp/objc/DBFlagRoundtrip+Private.h djinni-output-temp/objc/DBFlagRoundtrip+Private.mm djinni-output-temp/objc/DBRecordWithFlags+Private.h djinni-output-temp/objc/DBRecordWithFlags+Private.mm +djinni-output-temp/objc/DBTestJavaInterfaceOnly+Private.h +djinni-output-temp/objc/DBTestJavaInterfaceOnly+Private.mm +djinni-output-temp/objc/DBTestJavaAbstractClassOnly+Private.h +djinni-output-temp/objc/DBTestJavaAbstractClassOnly+Private.mm djinni-output-temp/objc/DBTestStaticMethodLanguage+Private.h djinni-output-temp/objc/DBTestStaticMethodLanguage+Private.mm djinni-output-temp/objc/DBSupportCopying+Private.h @@ -487,6 +501,10 @@ djinni-output-temp/wasm/NativeFlagRoundtrip.hpp djinni-output-temp/wasm/NativeFlagRoundtrip.cpp djinni-output-temp/wasm/NativeRecordWithFlags.hpp djinni-output-temp/wasm/NativeRecordWithFlags.cpp +djinni-output-temp/wasm/NativeTestJavaInterfaceOnly.hpp +djinni-output-temp/wasm/NativeTestJavaInterfaceOnly.cpp +djinni-output-temp/wasm/NativeTestJavaAbstractClassOnly.hpp +djinni-output-temp/wasm/NativeTestJavaAbstractClassOnly.cpp djinni-output-temp/wasm/NativeTestStaticMethodLanguage.hpp djinni-output-temp/wasm/NativeTestStaticMethodLanguage.cpp djinni-output-temp/wasm/NativeSupportCopying.hpp diff --git a/test-suite/generated-src/ts/test.ts b/test-suite/generated-src/ts/test.ts index afedf466..7be56dd6 100644 --- a/test-suite/generated-src/ts/test.ts +++ b/test-suite/generated-src/ts/test.ts @@ -151,6 +151,16 @@ export interface /*record*/ RecordWithFlags { access: AccessFlags; } +export interface TestJavaInterfaceOnly { + testMethod(): boolean; +} + +export interface TestJavaAbstractClassOnly { +} +export interface TestJavaAbstractClassOnly_statics { + testMethod(): boolean; +} + export interface TestStaticMethodLanguage { } @@ -605,6 +615,7 @@ export interface ns_testsuite { TestDuration: TestDuration_statics; DataRefTest: DataRefTest_statics; FlagRoundtrip: FlagRoundtrip_statics; + TestJavaAbstractClassOnly: TestJavaAbstractClassOnly_statics; TestArray: TestArray_statics; ListenerCaller: ListenerCaller_statics; ReturnOne: ReturnOne_statics; @@ -619,6 +630,7 @@ export interface Test_statics { testsuite_TestDuration: TestDuration_statics; testsuite_DataRefTest: DataRefTest_statics; testsuite_FlagRoundtrip: FlagRoundtrip_statics; + testsuite_TestJavaAbstractClassOnly: TestJavaAbstractClassOnly_statics; testsuite_TestArray: TestArray_statics; testsuite_ListenerCaller: ListenerCaller_statics; testsuite_ReturnOne: ReturnOne_statics; diff --git a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp new file mode 100644 index 00000000..58d7901e --- /dev/null +++ b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "NativeTestJavaAbstractClassOnly.hpp" // my header + +namespace djinni_generated { + +em::val NativeTestJavaAbstractClassOnly::cppProxyMethods() { + static const em::val methods = em::val::array(std::vector { + }); + return methods; +} + +bool NativeTestJavaAbstractClassOnly::test_method() { + try { + auto r = ::testsuite::TestJavaAbstractClassOnly::test_method(); + return ::djinni::Bool::fromCpp(r); + } + catch(const std::exception& e) { + return djinni::ExceptionHandlingTraits<::djinni::Bool>::handleNativeException(e); + } +} + +EMSCRIPTEN_BINDINGS(testsuite_test_java_abstract_class_only) { + ::djinni::DjinniClass_<::testsuite::TestJavaAbstractClassOnly>("testsuite_TestJavaAbstractClassOnly", "testsuite.TestJavaAbstractClassOnly") + .smart_ptr>("testsuite_TestJavaAbstractClassOnly") + .function("nativeDestroy", &NativeTestJavaAbstractClassOnly::nativeDestroy) + .class_function("testMethod", NativeTestJavaAbstractClassOnly::test_method) + ; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp new file mode 100644 index 00000000..57a90b1b --- /dev/null +++ b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "test_java_abstract_class_only.hpp" + +namespace djinni_generated { + +struct NativeTestJavaAbstractClassOnly : ::djinni::JsInterface<::testsuite::TestJavaAbstractClassOnly, NativeTestJavaAbstractClassOnly> { + using CppType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; + using JsType = em::val; + using Boxed = NativeTestJavaAbstractClassOnly; + + static CppType toCpp(JsType j) { return _fromJs(j); } + static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } + static JsType fromCpp(const CppType& c) { + djinni::checkForNull(c.get(), "NativeTestJavaAbstractClassOnly::fromCpp"); + return fromCppOpt(c); + } + + static em::val cppProxyMethods(); + + static bool test_method(); + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp new file mode 100644 index 00000000..77e8c058 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#include "NativeTestJavaInterfaceOnly.hpp" // my header + +namespace djinni_generated { + + +EMSCRIPTEN_BINDINGS(testsuite_test_java_interface_only) { + ::djinni::DjinniClass_<::testsuite::TestJavaInterfaceOnly>("testsuite_TestJavaInterfaceOnly", "testsuite.TestJavaInterfaceOnly") + .smart_ptr>("testsuite_TestJavaInterfaceOnly") + .function("nativeDestroy", &NativeTestJavaInterfaceOnly::nativeDestroy) + ; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp new file mode 100644 index 00000000..bb73c7cf --- /dev/null +++ b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from interface_and_abstract_class.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "test_java_interface_only.hpp" + +namespace djinni_generated { + +struct NativeTestJavaInterfaceOnly : ::djinni::JsInterface<::testsuite::TestJavaInterfaceOnly, NativeTestJavaInterfaceOnly> { + using CppType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using CppOptType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; + using JsType = em::val; + using Boxed = NativeTestJavaInterfaceOnly; + + static CppType toCpp(JsType j) { return _fromJs(j); } + static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } + static JsType fromCpp(const CppType& c) { + djinni::checkForNull(c.get(), "NativeTestJavaInterfaceOnly::fromCpp"); + return fromCppOpt(c); + } + + +}; + +} // namespace djinni_generated diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp new file mode 100644 index 00000000..af325c6b --- /dev/null +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp @@ -0,0 +1,10 @@ +#include "test_java_abstract_class_only_impl.hpp" + +namespace testsuite { + +bool TestJavaAbstractClassOnlyImpl::test_method() +{ + return true; +} + +} // namespace testsuite \ No newline at end of file diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp new file mode 100644 index 00000000..9cb76e8c --- /dev/null +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp @@ -0,0 +1,14 @@ +#include "test_java_abstract_class_only.hpp" + +namespace testsuite { + +class TestJavaAbstractClassOnlyImpl: public TestJavaAbstractClassOnly { +public: +public: + TestJavaAbstractClassOnlyImpl() {} + virtual ~TestJavaAbstractClassOnlyImpl() {} + + static bool test_method(); +}; + +} // namespace testsuite \ No newline at end of file diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java index f3053211..6515a311 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java @@ -30,6 +30,7 @@ public static Test suite() { mySuite.addTestSuite(ArrayTest.class); mySuite.addTestSuite(DataTest.class); mySuite.addTestSuite(AsyncTest.class); + mySuite.addTestSuite(InterfaceAndAbstractClass.class); return mySuite; } diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java index 5ad1ac65..742230af 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java @@ -9,7 +9,7 @@ public class AsyncTest extends TestCase { - static class AsyncInterfaceImpl extends AsyncInterface { + static class AsyncInterfaceImpl implements AsyncInterface { public com.snapchat.djinni.Future futureRoundtrip(com.snapchat.djinni.Future f) { return f.then((i) -> {return i.get().toString();}); } diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java index 0049334e..822125f4 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java @@ -2,7 +2,7 @@ import javax.annotation.CheckForNull; -public class ClientInterfaceImpl extends ClientInterface { +public class ClientInterfaceImpl implements ClientInterface { @Override public ClientReturnedRecord getRecord(long id, String utf8string, String misc) { if (!utf8string.equals("Non-ASCII /\0 非 ASCII 字符") && !utf8string.equals("Hello World!")) { diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/InterfaceAndAbstractClass.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/InterfaceAndAbstractClass.java new file mode 100644 index 00000000..a1b50920 --- /dev/null +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/InterfaceAndAbstractClass.java @@ -0,0 +1,22 @@ +package com.dropbox.djinni.test; + +import junit.framework.TestCase; + +public class InterfaceAndAbstractClass extends TestCase { + + static class TestJavaInterfaceOnlyImpl implements TestJavaInterfaceOnly { + @Override + public boolean testMethod() { + return true; + } + } + + public void test() { + // interface + TestJavaInterfaceOnlyImpl impl1 = new TestJavaInterfaceOnlyImpl(); + assertEquals(impl1.testMethod(), true); + + // abstract class + assertEquals(TestJavaAbstractClassOnly.testMethod(), true); + } +} From d6597d321c1dd15accaf16506f5b590713a6bd37 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 12:13:56 -0300 Subject: [PATCH 2/7] java interface support --- .../handwritten-src/cpp/test_java_abstract_class_only_impl.cpp | 2 +- .../handwritten-src/cpp/test_java_abstract_class_only_impl.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp index af325c6b..53ef5795 100644 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp @@ -7,4 +7,4 @@ bool TestJavaAbstractClassOnlyImpl::test_method() return true; } -} // namespace testsuite \ No newline at end of file +} // namespace testsuite diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp index 9cb76e8c..a1e435f0 100644 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp @@ -11,4 +11,4 @@ class TestJavaAbstractClassOnlyImpl: public TestJavaAbstractClassOnly { static bool test_method(); }; -} // namespace testsuite \ No newline at end of file +} // namespace testsuite From c9c5d62c5eb7b85d81382197bff12a23919ba7f2 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 12:42:24 -0300 Subject: [PATCH 3/7] java interface support --- .../handwritten-src/cpp/test_java_abstract_class_only_impl.cpp | 2 +- .../handwritten-src/cpp/test_java_abstract_class_only_impl.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp index 53ef5795..aa4e3814 100644 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp @@ -2,7 +2,7 @@ namespace testsuite { -bool TestJavaAbstractClassOnlyImpl::test_method() +bool TestJavaAbstractClassOnly::test_method() { return true; } diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp index a1e435f0..7f352c1b 100644 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp @@ -7,8 +7,6 @@ class TestJavaAbstractClassOnlyImpl: public TestJavaAbstractClassOnly { public: TestJavaAbstractClassOnlyImpl() {} virtual ~TestJavaAbstractClassOnlyImpl() {} - - static bool test_method(); }; } // namespace testsuite From 2e33bffdf05371f004d3a5a7062abc0fd63d216e Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 12:43:32 -0300 Subject: [PATCH 4/7] java interface support --- ...ly_impl.cpp => test_java_abstract_class_only.cpp} | 2 +- .../cpp/test_java_abstract_class_only_impl.hpp | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) rename test-suite/handwritten-src/cpp/{test_java_abstract_class_only_impl.cpp => test_java_abstract_class_only.cpp} (70%) delete mode 100644 test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only.cpp similarity index 70% rename from test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp rename to test-suite/handwritten-src/cpp/test_java_abstract_class_only.cpp index aa4e3814..99c6ee9b 100644 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.cpp +++ b/test-suite/handwritten-src/cpp/test_java_abstract_class_only.cpp @@ -1,4 +1,4 @@ -#include "test_java_abstract_class_only_impl.hpp" +#include "test_java_abstract_class_only.hpp" namespace testsuite { diff --git a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp b/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp deleted file mode 100644 index 7f352c1b..00000000 --- a/test-suite/handwritten-src/cpp/test_java_abstract_class_only_impl.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "test_java_abstract_class_only.hpp" - -namespace testsuite { - -class TestJavaAbstractClassOnlyImpl: public TestJavaAbstractClassOnly { -public: -public: - TestJavaAbstractClassOnlyImpl() {} - virtual ~TestJavaAbstractClassOnlyImpl() {} -}; - -} // namespace testsuite From 4d9a3a84e0a11ccbe5c28d40c5ee8bfb46c287e5 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 13:59:52 -0300 Subject: [PATCH 5/7] java interface support --- src/source/JavaGenerator.scala | 5 ++++- .../java/com/dropbox/djinni/test/AsyncInterface.java | 2 +- .../java/com/dropbox/djinni/test/ClientInterface.java | 10 +++++----- .../java/com/dropbox/djinni/test/ExternInterface2.java | 2 +- .../java/com/dropbox/djinni/test/FirstListener.java | 2 +- .../java/com/dropbox/djinni/test/SecondListener.java | 2 +- .../com/dropbox/djinni/test/TestJavaInterfaceOnly.java | 2 +- .../com/dropbox/djinni/test/ThrowingInterface.java | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index 1214a176..6bc5822b 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -180,8 +180,11 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { // if no static and no cpp will use interface instead of abstract class var classOrInterfaceDesc = "abstract class"; + var methodPrefixDesc = "public abstract "; + if (!statics.nonEmpty && !i.ext.cpp) { classOrInterfaceDesc = "interface" + methodPrefixDesc = "" } w.w(s"${javaClassAccessModifierString}${classOrInterfaceDesc} $javaClass$typeParamList").braced { @@ -198,7 +201,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { nullityAnnotation + marshal.paramType(p.ty) + " " + idJava.local(p.ident) }) marshal.nullityAnnotation(m.ret).foreach(w.wl) - w.wl("public abstract " + ret + " " + idJava.method(m.ident) + params.mkString("(", ", ", ")") + throwException + ";") + w.wl(methodPrefixDesc + ret + " " + idJava.method(m.ident) + params.mkString("(", ", ", ")") + throwException + ";") } val statics = i.methods.filter(m => m.static && m.lang.java) diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java index 5810aa99..461f22b0 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java @@ -8,5 +8,5 @@ public interface AsyncInterface { @Nonnull - public abstract com.snapchat.djinni.Future futureRoundtrip(@Nonnull com.snapchat.djinni.Future f); + com.snapchat.djinni.Future futureRoundtrip(@Nonnull com.snapchat.djinni.Future f); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java index 92a857cf..059efc18 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java @@ -10,16 +10,16 @@ public interface ClientInterface { /** Returns record of given string */ @Nonnull - public abstract ClientReturnedRecord getRecord(long recordId, @Nonnull String utf8string, @CheckForNull String misc); + ClientReturnedRecord getRecord(long recordId, @Nonnull String utf8string, @CheckForNull String misc); - public abstract double identifierCheck(@Nonnull byte[] data, int r, long jret); + double identifierCheck(@Nonnull byte[] data, int r, long jret); @Nonnull - public abstract String returnStr(); + String returnStr(); @Nonnull - public abstract String methTakingInterface(@CheckForNull ClientInterface i); + String methTakingInterface(@CheckForNull ClientInterface i); @Nonnull - public abstract String methTakingOptionalInterface(@CheckForNull ClientInterface i); + String methTakingOptionalInterface(@CheckForNull ClientInterface i); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java index e5fc038f..af72b45f 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java @@ -4,5 +4,5 @@ package com.dropbox.djinni.test; public interface ExternInterface2 { - public abstract ExternRecordWithDerivings foo(com.dropbox.djinni.test.TestHelpers i); + ExternRecordWithDerivings foo(com.dropbox.djinni.test.TestHelpers i); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java index f3ebb620..1443eb9e 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java @@ -8,5 +8,5 @@ /** Used for ObjC multiple inheritance tests */ public interface FirstListener { - public abstract void first(); + void first(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java index 6f50945b..e24477e3 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java @@ -8,5 +8,5 @@ /** Used for ObjC multiple inheritance tests */ public interface SecondListener { - public abstract void second(); + void second(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java index b36be532..22306af6 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/TestJavaInterfaceOnly.java @@ -7,5 +7,5 @@ import javax.annotation.Nonnull; public interface TestJavaInterfaceOnly { - public abstract boolean testMethod(); + boolean testMethod(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java index 48ef2fa5..f3a28672 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java @@ -7,5 +7,5 @@ import javax.annotation.Nonnull; public interface ThrowingInterface { - public abstract void throwException(); + void throwException(); } From 0e6685f10be7454706e92a66455247d8bc41fc6a Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 30 Aug 2022 14:17:17 -0300 Subject: [PATCH 6/7] java interface support --- .../java/com/dropbox/textsort/TextboxListener.java | 2 +- .../java/com/snapchat/djinni/benchmark/ObjectPlatform.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java index 12f69fa7..05bed257 100644 --- a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java +++ b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java @@ -7,5 +7,5 @@ import javax.annotation.Nonnull; /*package*/ interface TextboxListener { - public abstract void update(@Nonnull ItemList items); + void update(@Nonnull ItemList items); } diff --git a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java index 1964c25f..1b6d2687 100644 --- a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java +++ b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java @@ -8,5 +8,5 @@ /** interfaces for platform Java or Objective-C objects, to be passed to C++ */ /*package*/ interface ObjectPlatform { - public abstract void onDone(); + void onDone(); } From 085b670d3aecb12bba1f02702b456fcadfef0b73 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Thu, 1 Sep 2022 14:11:22 -0300 Subject: [PATCH 7/7] java interface support --- .../com/dropbox/textsort/TextboxListener.java | 4 +-- .../djinni/benchmark/ObjectPlatform.java | 4 +-- src/source/JavaGenerator.scala | 12 +++---- src/source/Main.scala | 4 +++ src/source/generator.scala | 1 + test-suite/djinni/common.djinni | 1 - test-suite/generated-src/inFileList.txt | 1 - .../dropbox/djinni/test/AsyncInterface.java | 4 +-- .../dropbox/djinni/test/ClientInterface.java | 12 +++---- .../dropbox/djinni/test/ExternInterface2.java | 4 +-- .../dropbox/djinni/test/FirstListener.java | 4 +-- .../dropbox/djinni/test/JavaOnlyListener.java | 2 +- .../dropbox/djinni/test/ObjcOnlyListener.java | 2 +- .../dropbox/djinni/test/SecondListener.java | 4 +-- .../djinni/test/ThrowingInterface.java | 4 +-- test-suite/generated-src/outFileList.txt | 18 ---------- test-suite/generated-src/ts/test.ts | 12 ------- .../wasm/NativeTestJavaAbstractClassOnly.cpp | 32 ----------------- .../wasm/NativeTestJavaAbstractClassOnly.hpp | 30 ---------------- .../wasm/NativeTestJavaInterfaceOnly.cpp | 16 --------- .../wasm/NativeTestJavaInterfaceOnly.hpp | 27 -------------- .../com/dropbox/djinni/test/AsyncTest.java | 2 +- .../djinni/test/ClientInterfaceImpl.java | 2 +- test-suite/run_djinni.sh | 35 ++++++++++++++++++- 24 files changed, 67 insertions(+), 170 deletions(-) delete mode 100644 test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp delete mode 100644 test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp delete mode 100644 test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp delete mode 100644 test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp diff --git a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java index 05bed257..664c21a3 100644 --- a/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java +++ b/examples/generated-src/java/com/dropbox/textsort/TextboxListener.java @@ -6,6 +6,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -/*package*/ interface TextboxListener { - void update(@Nonnull ItemList items); +/*package*/ abstract class TextboxListener { + public abstract void update(@Nonnull ItemList items); } diff --git a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java index 1b6d2687..b660d903 100644 --- a/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java +++ b/perftest/generated-src/java/com/snapchat/djinni/benchmark/ObjectPlatform.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** interfaces for platform Java or Objective-C objects, to be passed to C++ */ -/*package*/ interface ObjectPlatform { - void onDone(); +/*package*/ abstract class ObjectPlatform { + public abstract void onDone(); } diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index 6bc5822b..6481a841 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * This file has been modified by Snap, Inc. */ @@ -179,13 +179,9 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { javaAnnotationHeader.foreach(w.wl) // if no static and no cpp will use interface instead of abstract class - var classOrInterfaceDesc = "abstract class"; - var methodPrefixDesc = "public abstract "; - - if (!statics.nonEmpty && !i.ext.cpp) { - classOrInterfaceDesc = "interface" - methodPrefixDesc = "" - } + val genJavaInterface = spec.javaGenInterface && !statics.nonEmpty && !i.ext.cpp + val classOrInterfaceDesc = if (genJavaInterface) "interface" else "abstract class"; + val methodPrefixDesc = if (genJavaInterface) "" else "public abstract "; w.w(s"${javaClassAccessModifierString}${classOrInterfaceDesc} $javaClass$typeParamList").braced { val skipFirst = SkipFirst() diff --git a/src/source/Main.scala b/src/source/Main.scala index a59b46cf..eb40c8c4 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -49,6 +49,7 @@ object Main { var javaNonnullAnnotation: Option[String] = None var javaImplementAndroidOsParcelable : Boolean = false var javaUseFinalForRecord: Boolean = true + var javaGenInterface: Boolean = false var jniOutFolder: Option[File] = None var jniHeaderOutFolderOptional: Option[File] = None var jniNamespace: String = "djinni_generated" @@ -140,6 +141,8 @@ object Main { .text("all generated java classes will implement the interface android.os.Parcelable") opt[Boolean]("java-use-final-for-record").valueName("").foreach(x => javaUseFinalForRecord = x) .text("Whether generated Java classes for records should be marked 'final' (default: true). ") + opt[Boolean]("java-gen-interface").valueName("").foreach(x => javaGenInterface = x) + .text("Generate Java interface instead of abstract class.") note("") opt[File]("cpp-out").valueName("").foreach(x => cppOutFolder = Some(x)) .text("The output folder for C++ files (Generator disabled if unspecified).") @@ -373,6 +376,7 @@ object Main { javaNonnullAnnotation, javaImplementAndroidOsParcelable, javaUseFinalForRecord, + javaGenInterface, cppOutFolder, cppHeaderOutFolder, cppIncludePrefix, diff --git a/src/source/generator.scala b/src/source/generator.scala index 5bd55f5a..3e87a826 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -41,6 +41,7 @@ package object generatorTools { javaNonnullAnnotation: Option[String], javaImplementAndroidOsParcelable: Boolean, javaUseFinalForRecord: Boolean, + javaGenInterface: Boolean, cppOutFolder: Option[File], cppHeaderOutFolder: Option[File], cppIncludePrefix: String, diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index ed504d22..1a078536 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -18,4 +18,3 @@ @import "array.djinni" @import "nscopying.djinni" @import "static_method_language.djinni" -@import "interface_and_abstract_class.djinni" diff --git a/test-suite/generated-src/inFileList.txt b/test-suite/generated-src/inFileList.txt index 399faad9..d3614d89 100644 --- a/test-suite/generated-src/inFileList.txt +++ b/test-suite/generated-src/inFileList.txt @@ -21,7 +21,6 @@ djinni/relative_paths.djinni djinni/array.djinni djinni/nscopying.djinni djinni/static_method_language.djinni -djinni/interface_and_abstract_class.djinni djinni/enum_flags.djinni djinni/constant_enum.djinni djinni/data_ref_view.djinni diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java index 461f22b0..357be805 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/AsyncInterface.java @@ -6,7 +6,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public interface AsyncInterface { +public abstract class AsyncInterface { @Nonnull - com.snapchat.djinni.Future futureRoundtrip(@Nonnull com.snapchat.djinni.Future f); + public abstract com.snapchat.djinni.Future futureRoundtrip(@Nonnull com.snapchat.djinni.Future f); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java index 059efc18..f6024d9e 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientInterface.java @@ -7,19 +7,19 @@ import javax.annotation.Nonnull; /** Client interface */ -public interface ClientInterface { +public abstract class ClientInterface { /** Returns record of given string */ @Nonnull - ClientReturnedRecord getRecord(long recordId, @Nonnull String utf8string, @CheckForNull String misc); + public abstract ClientReturnedRecord getRecord(long recordId, @Nonnull String utf8string, @CheckForNull String misc); - double identifierCheck(@Nonnull byte[] data, int r, long jret); + public abstract double identifierCheck(@Nonnull byte[] data, int r, long jret); @Nonnull - String returnStr(); + public abstract String returnStr(); @Nonnull - String methTakingInterface(@CheckForNull ClientInterface i); + public abstract String methTakingInterface(@CheckForNull ClientInterface i); @Nonnull - String methTakingOptionalInterface(@CheckForNull ClientInterface i); + public abstract String methTakingOptionalInterface(@CheckForNull ClientInterface i); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java index af72b45f..48f8c8af 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternInterface2.java @@ -3,6 +3,6 @@ package com.dropbox.djinni.test; -public interface ExternInterface2 { - ExternRecordWithDerivings foo(com.dropbox.djinni.test.TestHelpers i); +public abstract class ExternInterface2 { + public abstract ExternRecordWithDerivings foo(com.dropbox.djinni.test.TestHelpers i); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java index 1443eb9e..32fa60da 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/FirstListener.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** Used for ObjC multiple inheritance tests */ -public interface FirstListener { - void first(); +public abstract class FirstListener { + public abstract void first(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java index 43d7fdf6..7b552972 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/JavaOnlyListener.java @@ -6,5 +6,5 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public interface JavaOnlyListener { +public abstract class JavaOnlyListener { } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java index 8dc9f189..f228f076 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ObjcOnlyListener.java @@ -6,5 +6,5 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public interface ObjcOnlyListener { +public abstract class ObjcOnlyListener { } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java index e24477e3..d841d32e 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/SecondListener.java @@ -7,6 +7,6 @@ import javax.annotation.Nonnull; /** Used for ObjC multiple inheritance tests */ -public interface SecondListener { - void second(); +public abstract class SecondListener { + public abstract void second(); } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java index f3a28672..79dc232b 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ThrowingInterface.java @@ -6,6 +6,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public interface ThrowingInterface { - void throwException(); +public abstract class ThrowingInterface { + public abstract void throwException(); } diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index c1235fdf..555f56f8 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -20,8 +20,6 @@ djinni-output-temp/cpp/access_flags.hpp djinni-output-temp/cpp/empty_flags.hpp djinni-output-temp/cpp/flag_roundtrip.hpp djinni-output-temp/cpp/record_with_flags.hpp -djinni-output-temp/cpp/test_java_interface_only.hpp -djinni-output-temp/cpp/test_java_abstract_class_only.hpp djinni-output-temp/cpp/test_static_method_language.hpp djinni-output-temp/cpp/support_copying.hpp djinni-output-temp/cpp/vec2.hpp @@ -91,8 +89,6 @@ djinni-output-temp/java/AccessFlags.java djinni-output-temp/java/EmptyFlags.java djinni-output-temp/java/FlagRoundtrip.java djinni-output-temp/java/RecordWithFlags.java -djinni-output-temp/java/TestJavaInterfaceOnly.java -djinni-output-temp/java/TestJavaAbstractClassOnly.java djinni-output-temp/java/TestStaticMethodLanguage.java djinni-output-temp/java/SupportCopying.java djinni-output-temp/java/Vec2.java @@ -167,10 +163,6 @@ djinni-output-temp/jni/NativeFlagRoundtrip.hpp djinni-output-temp/jni/NativeFlagRoundtrip.cpp djinni-output-temp/jni/NativeRecordWithFlags.hpp djinni-output-temp/jni/NativeRecordWithFlags.cpp -djinni-output-temp/jni/NativeTestJavaInterfaceOnly.hpp -djinni-output-temp/jni/NativeTestJavaInterfaceOnly.cpp -djinni-output-temp/jni/NativeTestJavaAbstractClassOnly.hpp -djinni-output-temp/jni/NativeTestJavaAbstractClassOnly.cpp djinni-output-temp/jni/NativeTestStaticMethodLanguage.hpp djinni-output-temp/jni/NativeTestStaticMethodLanguage.cpp djinni-output-temp/jni/NativeSupportCopying.hpp @@ -282,8 +274,6 @@ djinni-output-temp/objc/DBEmptyFlags.h djinni-output-temp/objc/DBFlagRoundtrip.h djinni-output-temp/objc/DBRecordWithFlags.h djinni-output-temp/objc/DBRecordWithFlags.mm -djinni-output-temp/objc/DBTestJavaInterfaceOnly.h -djinni-output-temp/objc/DBTestJavaAbstractClassOnly.h djinni-output-temp/objc/DBTestStaticMethodLanguage.h djinni-output-temp/objc/DBSupportCopying.h djinni-output-temp/objc/DBSupportCopying.mm @@ -378,10 +368,6 @@ djinni-output-temp/objc/DBFlagRoundtrip+Private.h djinni-output-temp/objc/DBFlagRoundtrip+Private.mm djinni-output-temp/objc/DBRecordWithFlags+Private.h djinni-output-temp/objc/DBRecordWithFlags+Private.mm -djinni-output-temp/objc/DBTestJavaInterfaceOnly+Private.h -djinni-output-temp/objc/DBTestJavaInterfaceOnly+Private.mm -djinni-output-temp/objc/DBTestJavaAbstractClassOnly+Private.h -djinni-output-temp/objc/DBTestJavaAbstractClassOnly+Private.mm djinni-output-temp/objc/DBTestStaticMethodLanguage+Private.h djinni-output-temp/objc/DBTestStaticMethodLanguage+Private.mm djinni-output-temp/objc/DBSupportCopying+Private.h @@ -501,10 +487,6 @@ djinni-output-temp/wasm/NativeFlagRoundtrip.hpp djinni-output-temp/wasm/NativeFlagRoundtrip.cpp djinni-output-temp/wasm/NativeRecordWithFlags.hpp djinni-output-temp/wasm/NativeRecordWithFlags.cpp -djinni-output-temp/wasm/NativeTestJavaInterfaceOnly.hpp -djinni-output-temp/wasm/NativeTestJavaInterfaceOnly.cpp -djinni-output-temp/wasm/NativeTestJavaAbstractClassOnly.hpp -djinni-output-temp/wasm/NativeTestJavaAbstractClassOnly.cpp djinni-output-temp/wasm/NativeTestStaticMethodLanguage.hpp djinni-output-temp/wasm/NativeTestStaticMethodLanguage.cpp djinni-output-temp/wasm/NativeSupportCopying.hpp diff --git a/test-suite/generated-src/ts/test.ts b/test-suite/generated-src/ts/test.ts index 7be56dd6..afedf466 100644 --- a/test-suite/generated-src/ts/test.ts +++ b/test-suite/generated-src/ts/test.ts @@ -151,16 +151,6 @@ export interface /*record*/ RecordWithFlags { access: AccessFlags; } -export interface TestJavaInterfaceOnly { - testMethod(): boolean; -} - -export interface TestJavaAbstractClassOnly { -} -export interface TestJavaAbstractClassOnly_statics { - testMethod(): boolean; -} - export interface TestStaticMethodLanguage { } @@ -615,7 +605,6 @@ export interface ns_testsuite { TestDuration: TestDuration_statics; DataRefTest: DataRefTest_statics; FlagRoundtrip: FlagRoundtrip_statics; - TestJavaAbstractClassOnly: TestJavaAbstractClassOnly_statics; TestArray: TestArray_statics; ListenerCaller: ListenerCaller_statics; ReturnOne: ReturnOne_statics; @@ -630,7 +619,6 @@ export interface Test_statics { testsuite_TestDuration: TestDuration_statics; testsuite_DataRefTest: DataRefTest_statics; testsuite_FlagRoundtrip: FlagRoundtrip_statics; - testsuite_TestJavaAbstractClassOnly: TestJavaAbstractClassOnly_statics; testsuite_TestArray: TestArray_statics; testsuite_ListenerCaller: ListenerCaller_statics; testsuite_ReturnOne: ReturnOne_statics; diff --git a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp deleted file mode 100644 index 58d7901e..00000000 --- a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file was generated by Djinni from interface_and_abstract_class.djinni - -#include "NativeTestJavaAbstractClassOnly.hpp" // my header - -namespace djinni_generated { - -em::val NativeTestJavaAbstractClassOnly::cppProxyMethods() { - static const em::val methods = em::val::array(std::vector { - }); - return methods; -} - -bool NativeTestJavaAbstractClassOnly::test_method() { - try { - auto r = ::testsuite::TestJavaAbstractClassOnly::test_method(); - return ::djinni::Bool::fromCpp(r); - } - catch(const std::exception& e) { - return djinni::ExceptionHandlingTraits<::djinni::Bool>::handleNativeException(e); - } -} - -EMSCRIPTEN_BINDINGS(testsuite_test_java_abstract_class_only) { - ::djinni::DjinniClass_<::testsuite::TestJavaAbstractClassOnly>("testsuite_TestJavaAbstractClassOnly", "testsuite.TestJavaAbstractClassOnly") - .smart_ptr>("testsuite_TestJavaAbstractClassOnly") - .function("nativeDestroy", &NativeTestJavaAbstractClassOnly::nativeDestroy) - .class_function("testMethod", NativeTestJavaAbstractClassOnly::test_method) - ; -} - -} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp b/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp deleted file mode 100644 index 57a90b1b..00000000 --- a/test-suite/generated-src/wasm/NativeTestJavaAbstractClassOnly.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file was generated by Djinni from interface_and_abstract_class.djinni - -#pragma once - -#include "djinni_wasm.hpp" -#include "test_java_abstract_class_only.hpp" - -namespace djinni_generated { - -struct NativeTestJavaAbstractClassOnly : ::djinni::JsInterface<::testsuite::TestJavaAbstractClassOnly, NativeTestJavaAbstractClassOnly> { - using CppType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; - using CppOptType = std::shared_ptr<::testsuite::TestJavaAbstractClassOnly>; - using JsType = em::val; - using Boxed = NativeTestJavaAbstractClassOnly; - - static CppType toCpp(JsType j) { return _fromJs(j); } - static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } - static JsType fromCpp(const CppType& c) { - djinni::checkForNull(c.get(), "NativeTestJavaAbstractClassOnly::fromCpp"); - return fromCppOpt(c); - } - - static em::val cppProxyMethods(); - - static bool test_method(); - -}; - -} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp deleted file mode 100644 index 77e8c058..00000000 --- a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file was generated by Djinni from interface_and_abstract_class.djinni - -#include "NativeTestJavaInterfaceOnly.hpp" // my header - -namespace djinni_generated { - - -EMSCRIPTEN_BINDINGS(testsuite_test_java_interface_only) { - ::djinni::DjinniClass_<::testsuite::TestJavaInterfaceOnly>("testsuite_TestJavaInterfaceOnly", "testsuite.TestJavaInterfaceOnly") - .smart_ptr>("testsuite_TestJavaInterfaceOnly") - .function("nativeDestroy", &NativeTestJavaInterfaceOnly::nativeDestroy) - ; -} - -} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp b/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp deleted file mode 100644 index bb73c7cf..00000000 --- a/test-suite/generated-src/wasm/NativeTestJavaInterfaceOnly.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file was generated by Djinni from interface_and_abstract_class.djinni - -#pragma once - -#include "djinni_wasm.hpp" -#include "test_java_interface_only.hpp" - -namespace djinni_generated { - -struct NativeTestJavaInterfaceOnly : ::djinni::JsInterface<::testsuite::TestJavaInterfaceOnly, NativeTestJavaInterfaceOnly> { - using CppType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; - using CppOptType = std::shared_ptr<::testsuite::TestJavaInterfaceOnly>; - using JsType = em::val; - using Boxed = NativeTestJavaInterfaceOnly; - - static CppType toCpp(JsType j) { return _fromJs(j); } - static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } - static JsType fromCpp(const CppType& c) { - djinni::checkForNull(c.get(), "NativeTestJavaInterfaceOnly::fromCpp"); - return fromCppOpt(c); - } - - -}; - -} // namespace djinni_generated diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java index 742230af..5ad1ac65 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AsyncTest.java @@ -9,7 +9,7 @@ public class AsyncTest extends TestCase { - static class AsyncInterfaceImpl implements AsyncInterface { + static class AsyncInterfaceImpl extends AsyncInterface { public com.snapchat.djinni.Future futureRoundtrip(com.snapchat.djinni.Future f) { return f.then((i) -> {return i.get().toString();}); } diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java index 822125f4..0049334e 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java @@ -2,7 +2,7 @@ import javax.annotation.CheckForNull; -public class ClientInterfaceImpl implements ClientInterface { +public class ClientInterfaceImpl extends ClientInterface { @Override public ClientReturnedRecord getRecord(long id, String utf8string, String misc) { if (!utf8string.equals("Non-ASCII /\0 非 ASCII 字符") && !utf8string.equals("Hello World!")) { diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 53bb5da7..61328b40 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -27,6 +27,7 @@ in_relative="djinni/all.djinni" wchar_in_relative="djinni/wchar_test.djinni" prologue_in_relative="djinni/function_prologue.djinni" ident_explicit_in_relative="djinni/ident_explicit.djinni" +interface_and_abstract_class_in_relative="djinni/interface_and_abstract_class.djinni" temp_out_relative="djinni-output-temp" cpp_out="$base_dir/generated-src/cpp" @@ -196,7 +197,39 @@ fi --ident-objc-enum NativeFooBar! \ --ident-objc-const NativeFooBar! \ \ - --idl "$ident_explicit_in_relative" \ + --idl "$ident_explicit_in_relative" && \ +"$base_dir/../src/run-assume-built" \ + --java-out "$temp_out_relative/java" \ + --java-package $java_package \ + --java-nullable-annotation "javax.annotation.CheckForNull" \ + --java-nonnull-annotation "javax.annotation.Nonnull" \ + --java-use-final-for-record false \ + --java-implement-android-os-parcelable true \ + --java-gen-interface true \ + --ident-java-field mFooBar \ + \ + --cpp-out "$temp_out_relative/cpp" \ + --cpp-namespace testsuite \ + --ident-cpp-enum-type foo_bar \ + --cpp-optional-template "std::experimental::optional" \ + --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ + \ + --jni-out "$temp_out_relative/jni" \ + --jni-use-on-load-initializer false \ + --ident-jni-class NativeFooBar \ + --ident-jni-file NativeFooBar \ + \ + --objc-out "$temp_out_relative/objc" \ + --objcpp-out "$temp_out_relative/objc" \ + --objc-type-prefix DB \ + \ + --yaml-out "$temp_out_relative/yaml" \ + --yaml-out-file "yaml-interface-test.yaml" \ + --yaml-prefix "test_" \ + \ + --idl "$interface_and_abstract_class_in_relative" \ + --idl-include-path "djinni/vendor" \ ) # Make sure we can parse back our own generated YAML file