1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo) 2 3 #include "ExpectedType.h" 4 5 namespace expo { 6 getFirstParameterType()7jni::local_ref<ExpectedType::javaobject> SingleType::getFirstParameterType() { 8 static const auto method = getClass()->getMethod<jni::local_ref<ExpectedType::javaobject>()>( 9 "getFirstParameterType"); 10 return method(self()); 11 } 12 getSecondParameterType()13jni::local_ref<ExpectedType::javaobject> SingleType::getSecondParameterType() { 14 static const auto method = getClass()->getMethod<jni::local_ref<ExpectedType::javaobject>()>( 15 "getSecondParameterType"); 16 return method(self()); 17 } 18 getCppType()19CppType SingleType::getCppType() { 20 static const auto method = getClass()->getMethod<int()>("getCppType"); 21 return static_cast<CppType>(method(self())); 22 } 23 getCombinedTypes()24CppType ExpectedType::getCombinedTypes() { 25 static const auto method = getClass()->getMethod<int()>("getCombinedTypes"); 26 return static_cast<CppType>(method(self())); 27 } 28 getFirstType()29jni::local_ref<SingleType::javaobject> ExpectedType::getFirstType() { 30 static const auto method = getClass()->getMethod<jni::local_ref<SingleType::javaobject>()>( 31 "getFirstType"); 32 return method(self()); 33 } 34 getJClassString(bool allowsPrimitives)35std::string ExpectedType::getJClassString(bool allowsPrimitives) { 36 CppType type = this->getCombinedTypes(); 37 if (type == CppType::DOUBLE) { 38 if (allowsPrimitives) { 39 return "D"; 40 } 41 return "java/lang/Double"; 42 } 43 if (type == CppType::BOOLEAN) { 44 if (allowsPrimitives) { 45 return "Z"; 46 } 47 return "java/lang/Boolean"; 48 } 49 if (type == CppType::INT) { 50 if (allowsPrimitives) { 51 return "I"; 52 } 53 return "java/lang/Integer"; 54 } 55 if (type == CppType::FLOAT) { 56 return "java/lang/Float"; 57 } 58 if (type == CppType::STRING) { 59 return "java/lang/String"; 60 } 61 if (type == CppType::JS_OBJECT) { 62 return "expo/modules/kotlin/jni/JavaScriptObject"; 63 } 64 if (type == CppType::JS_VALUE) { 65 return "expo/modules/kotlin/jni/JavaScriptValue"; 66 } 67 if (type == CppType::READABLE_ARRAY) { 68 return "com/facebook/react/bridge/ReadableNativeArray"; 69 } 70 if (type == CppType::READABLE_MAP) { 71 return "com/facebook/react/bridge/ReadableNativeMap"; 72 } 73 if (type == CppType::TYPED_ARRAY) { 74 return "expo/modules/kotlin/jni/JavaScriptTypedArray"; 75 } 76 if (type == CppType::PRIMITIVE_ARRAY) { 77 auto innerType = this->getFirstType()->getFirstParameterType()->getJClassString(true); 78 if (innerType.size() == 1) { 79 // is a primitive type 80 return "[" + innerType; 81 } 82 83 return "[L" + innerType + ";"; 84 } 85 if (type == CppType::LIST) { 86 return "java/util/ArrayList"; 87 } 88 return "java/lang/Object"; 89 } 90 getPossibleTypes()91jni::local_ref<jni::JArrayClass<SingleType>::javaobject> ExpectedType::getPossibleTypes() { 92 static const auto method = getClass()->getMethod<jni::local_ref<jni::JArrayClass<SingleType>::javaobject>()>( 93 "getPossibleTypes"); 94 return method(self()); 95 } 96 } // namespace expo 97