summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qjniobject.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-04-30 14:22:39 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-05-17 00:34:06 +0200
commitf6e89e901ba718d64b50f79f3b1b327a7f6a0211 (patch)
tree5a4c7752642f28dd1102fbb74cd83b0856b9115b /src/corelib/kernel/qjniobject.cpp
parent18a16533b9c8782c5ff642a37dd58f82c1eb881d (diff)
Fold methods for object return type into generic methods
Since we know at compile time whether the return type is an object type, we can use 'if constexpr' and auto return type in the call(Static)Method and get(Static)Field functions to call the object-type methods. This makes the object-methods conceptually obsolete, but don't declare them as deprecated as long as they are still used in submodules to avoid warning floods and build failures in -Werror configurations. Change-Id: Ic3019ed990a9252eefcb02cdb355f8a6ed6bc2ff Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/corelib/kernel/qjniobject.cpp')
-rw-r--r--src/corelib/kernel/qjniobject.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/corelib/kernel/qjniobject.cpp b/src/corelib/kernel/qjniobject.cpp
index 045b9316cbd..8f21835a1fd 100644
--- a/src/corelib/kernel/qjniobject.cpp
+++ b/src/corelib/kernel/qjniobject.cpp
@@ -903,24 +903,26 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
}
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callMethod(const char *methodName, const char *signature, Args &&...args) const
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callMethod(const char *methodName, const char *signature, Args &&...args) const
\since 6.4
Calls the object's method \a methodName with \a signature specifying the types of any
- subsequent arguments \a args.
+ subsequent arguments \a args, and returns the value (unless \c Ret is \c void). If \c Ret
+ is a jobject type, then the returned value will be a QJniObject.
\code
QJniObject myJavaStrin("org/qtproject/qt/TestClass");
jint index = myJavaString.callMethod<jint>("indexOf", "(I)I", 0x0051);
\endcode
-
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callMethod(const char *methodName, Args &&...args) const
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callMethod(const char *methodName, Args &&...args) const
\since 6.4
- Calls the method \a methodName with arguments \a args and returns the value.
+ Calls the method \a methodName with arguments \a args and returns the value
+ (unless \c Ret is \c void). If \c Ret is a jobject type, then the returned value
+ will be a QJniObject.
\code
QJniObject myJavaStrin("org/qtproject/qt/TestClass");
@@ -931,11 +933,13 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callStaticMethod(const char *className, const char *methodName, const char *signature, Args &&...args)
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callStaticMethod(const char *className, const char *methodName, const char *signature, Args &&...args)
\since 6.4
Calls the static method \a methodName from class \a className with \a signature
- specifying the types of any subsequent arguments \a args.
+ specifying the types of any subsequent arguments \a args. Returns the result of
+ the method (unless \c Ret is \c void). If \c Ret is a jobject type, then the
+ returned value will be a QJniObject.
\code
jint a = 2;
@@ -945,11 +949,12 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callStaticMethod(const char *className, const char *methodName, Args &&...args)
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callStaticMethod(const char *className, const char *methodName, Args &&...args)
\since 6.4
Calls the static method \a methodName on class \a className with arguments \a args,
- and returns the value of type \c Ret.
+ and returns the value of type \c Ret (unless \c Ret is \c void). If \c Ret
+ is a jobject type, then the returned value will be a QJniObject.
\code
jint value = QJniObject::callStaticMethod<jint>("MyClass", "staticMethod");
@@ -959,10 +964,12 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callStaticMethod(jclass clazz, const char *methodName, const char *signature, Args &&...args)
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callStaticMethod(jclass clazz, const char *methodName, const char *signature, Args &&...args)
Calls the static method \a methodName from \a clazz with \a signature
- specifying the types of any subsequent arguments.
+ specifying the types of any subsequent arguments. Returns the result of
+ the method (unless \c Ret is \c void). If \c Ret is a jobject type, then the
+ returned value will be a QJniObject.
\code
QJniEnvironment env;
@@ -974,12 +981,15 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callStaticMethod(jclass clazz, jmethodID methodId, Args &&...args)
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callStaticMethod(jclass clazz, jmethodID methodId, Args &&...args)
\since 6.4
Calls the static method identified by \a methodId from the class \a clazz
- with any subsequent arguments. Useful when \a clazz and \a methodId are
- already cached from previous operations.
+ with any subsequent arguments, and returns the value of type \c Ret (unless
+ \c Ret is \c void). If \c Ret is a jobject type, then the returned value will
+ be a QJniObject.
+
+ Useful when \a clazz and \a methodId are already cached from previous operations.
\code
QJniEnvironment env;
@@ -994,10 +1004,12 @@ QJniObject QJniObject::callStaticObjectMethodV(jclass clazz,
*/
/*!
- \fn template <typename Ret, typename ...Args> Ret QJniObject::callStaticMethod(jclass clazz, const char *methodName, Args &&...args)
+ \fn template <typename Ret, typename ...Args> auto QJniObject::callStaticMethod(jclass clazz, const char *methodName, Args &&...args)
\since 6.4
- Calls the static method \a methodName on \a clazz and returns the value.
+ Calls the static method \a methodName on \a clazz and returns the value of type \c Ret
+ (unless c Ret is \c void). If \c Ret if a jobject type, then the returned value will
+ be a QJniObject.
\code
QJniEnvironment env;