From 74a70fea97ddddb430346bd4b9b7e83a29616abc Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 19 May 2017 04:04:30 -0700 Subject: [PATCH] Add some helper methods to JStackTraceElement Reviewed By: mhorowitz Differential Revision: D5069764 fbshipit-source-id: e2073ab824c357b28e00838abc768d402905207d --- .../fb/include/fb/fbjni/CoreClasses.h | 7 ++++++- .../jni/first-party/fb/jni/Exceptions.cpp | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/CoreClasses.h b/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/CoreClasses.h index 1ee5bb005..76eecb87b 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/CoreClasses.h +++ b/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/CoreClasses.h @@ -557,10 +557,15 @@ class PinnedPrimitiveArray { friend class JPrimitiveArray::array_type>; }; -struct JStackTraceElement : JavaClass { +struct FBEXPORT JStackTraceElement : JavaClass { static auto constexpr kJavaDescriptor = "Ljava/lang/StackTraceElement;"; static local_ref create(const std::string& declaringClass, const std::string& methodName, const std::string& file, int line); + + std::string getClassName() const; + std::string getMethodName() const; + std::string getFileName() const; + int getLineNumber() const; }; /// Wrapper to provide functionality to jthrowable references diff --git a/ReactAndroid/src/main/jni/first-party/fb/jni/Exceptions.cpp b/ReactAndroid/src/main/jni/first-party/fb/jni/Exceptions.cpp index f8273e222..3dca10b76 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/jni/Exceptions.cpp +++ b/ReactAndroid/src/main/jni/first-party/fb/jni/Exceptions.cpp @@ -184,6 +184,26 @@ auto JStackTraceElement::create( return newInstance(declaringClass, methodName, file, line); } +std::string JStackTraceElement::getClassName() const { + static auto meth = javaClassStatic()->getMethod()>("getClassName"); + return meth(self())->toStdString(); +} + +std::string JStackTraceElement::getMethodName() const { + static auto meth = javaClassStatic()->getMethod()>("getMethodName"); + return meth(self())->toStdString(); +} + +std::string JStackTraceElement::getFileName() const { + static auto meth = javaClassStatic()->getMethod()>("getFileName"); + return meth(self())->toStdString(); +} + +int JStackTraceElement::getLineNumber() const { + static auto meth = javaClassStatic()->getMethod("getLineNumber"); + return meth(self()); +} + // Translate C++ to Java Exception namespace {