├── .github └── workflows │ └── CI.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── compiler ├── .gitignore ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── readdle │ │ └── codegen │ │ ├── JavaSwiftProcessor.java │ │ ├── SwiftBlockDescriptor.java │ │ ├── SwiftCallbackFuncDescriptor.java │ │ ├── SwiftDelegateDescriptor.java │ │ ├── SwiftEnvironment.java │ │ ├── SwiftFuncDescriptor.java │ │ ├── SwiftGetterDescriptor.java │ │ ├── SwiftMappingException.java │ │ ├── SwiftModuleDescriptor.java │ │ ├── SwiftParamDescriptor.java │ │ ├── SwiftReferenceDescriptor.java │ │ ├── SwiftSetterDescriptor.java │ │ ├── SwiftValueDescriptor.java │ │ ├── SwiftWriter.java │ │ └── Utils.java │ └── resources │ └── META-INF │ ├── gradle │ └── incremental.annotation.processors │ └── services │ └── javax.annotation.processing.Processor ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── readdle │ └── codegen │ └── anotation │ ├── JavaSwift.java │ ├── SwiftBlock.java │ ├── SwiftCallbackFunc.java │ ├── SwiftDelegate.java │ ├── SwiftError.java │ ├── SwiftFunc.java │ ├── SwiftGetter.java │ ├── SwiftModule.java │ ├── SwiftReference.java │ ├── SwiftRuntimeError.java │ ├── SwiftSetter.java │ ├── SwiftValue.java │ ├── TypeMapping.java │ └── Unsigned.java ├── publish-module.gradle ├── publish-root.gradle ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── readdle │ │ └── swiftjava │ │ └── sample │ │ ├── BoolTests.java │ │ ├── DoubleTests.java │ │ ├── FloatTests.java │ │ ├── Int16Tests.java │ │ ├── Int32Tests.java │ │ ├── Int64Tests.java │ │ ├── Int8Tests.java │ │ ├── IntTests.java │ │ ├── Issue31Tests.kt │ │ ├── MemoryLeakVerifier.java │ │ ├── SampleEnumWithValueTests.kt │ │ ├── SampleReferenceTest.java │ │ ├── SampleValueTest.kt │ │ ├── StringTests.java │ │ ├── UInt16Tests.java │ │ ├── UInt32Tests.java │ │ ├── UInt64Tests.java │ │ ├── UInt8Tests.java │ │ └── UIntTests.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── readdle │ │ └── swiftjava │ │ └── sample │ │ ├── BoolTest.kt │ │ ├── CustomSampleValue.kt │ │ ├── DoubleTest.kt │ │ ├── FloatTest.kt │ │ ├── Int16Test.kt │ │ ├── Int32Test.kt │ │ ├── Int64Test.kt │ │ ├── Int8Test.kt │ │ ├── IntTest.kt │ │ ├── Issue31Test.kt │ │ ├── MainActivity.java │ │ ├── SampleDelegateAndroid.kt │ │ ├── SampleEnumWithValue.kt │ │ ├── SampleReference.kt │ │ ├── SampleValue.kt │ │ ├── StringTests.kt │ │ ├── SwiftEnvironment.kt │ │ ├── UInt16Test.kt │ │ ├── UInt32Test.kt │ │ ├── UInt64Test.kt │ │ ├── UInt8Test.kt │ │ ├── UIntTest.kt │ │ └── asbtracthierarhy │ │ ├── AbstractType.kt │ │ ├── FirstChild.kt │ │ ├── FourthChild.kt │ │ ├── SecondChild.kt │ │ └── ThirdChild.kt │ ├── res │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ ├── drawable │ │ └── ic_launcher_background.xml │ ├── layout │ │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── swift │ ├── .swiftlint.yml │ ├── Package.resolved │ ├── Package.swift │ └── Sources │ └── SampleAppCore │ ├── AbstractHierarchy.swift │ ├── Array+JavaBridgeable.swift │ ├── BoolTest.swift │ ├── DoubleTest.swift │ ├── FloatTest.swift │ ├── Int16Test.swift │ ├── Int32Test.swift │ ├── Int64Test.swift │ ├── Int8Test.swift │ ├── IntTest.swift │ ├── IssueTests │ └── Issue31Test.swift │ ├── SampleEnumWithValue.swift │ ├── SampleReference.swift │ ├── SampleValue.swift │ ├── StringTest.swift │ ├── SwiftEnvironment.swift │ ├── UInt16Test.swift │ ├── UInt32Test.swift │ ├── UInt64Test.swift │ ├── UInt8Test.swift │ └── UIntTest.swift └── settings.gradle /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI Test 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | 7 | android-x86_64: 8 | runs-on: macos-13 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Select XCode 14.2 13 | run: sudo xcode-select --switch /Applications/Xcode_14.2.app 14 | - name: Install NDK 15 | run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "ndk;25.2.9519653" 16 | - name: Install Swift Android Toolchain 17 | run: wget https://github.com/readdle/swift-android-toolchain/releases/latest/download/swift-android.zip; 18 | unzip swift-android.zip; 19 | swift-android/bin/swift-android tools --update; 20 | - name: Install Android Emulator 21 | run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-29;google_apis;x86_64" 22 | - name: Create Android Emulator 23 | run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n ci-test -k "system-images;android-29;google_apis;x86_64" -d "pixel" --force 24 | - name: Start Android Emulator 25 | run: $ANDROID_HOME/emulator/emulator -no-window -avd ci-test -noaudio > /dev/null & 26 | - name: Run connected android tests 27 | run: export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/25.2.9519653; 28 | export SWIFT_ANDROID_HOME=$(pwd)/swift-android; 29 | export PATH=$ANDROID_NDK_HOME:$PATH; 30 | export PATH=$SWIFT_ANDROID_HOME/bin:$SWIFT_ANDROID_HOME/build-tools/current:$PATH; 31 | adb wait-for-device; 32 | ./gradlew sample:cAT 33 | 34 | # It looks like macos-13-arm64 is quite busy on Gtihub CI, skip for now 35 | 36 | # android-arm64-v8a: 37 | # runs-on: macos-13-arm64 38 | 39 | # steps: 40 | # - uses: actions/checkout@v1 41 | # - name: Select XCode 14.2 42 | # run: sudo xcode-select --switch /Applications/Xcode_14.2.app 43 | # - name: Install NDK 44 | # run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "ndk;25.2.9519653" 45 | # - name: Install Swift Android Toolchain 46 | # run: wget https://github.com/readdle/swift-android-toolchain/releases/latest/download/swift-android.zip; 47 | # unzip swift-android.zip; 48 | # swift-android/bin/swift-android tools --update; 49 | # - name: Accept Android SDK licenses 50 | # run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses 51 | # - name: Install Android Emulator 52 | # run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-29;google_apis;arm64-v8a" 53 | # - name: Create Android Emulator 54 | # run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n ci-test -k "system-images;android-29;google_apis;arm64-v8a" -d "pixel" --force 55 | # - name: Start Android Emulator 56 | # run: $ANDROID_HOME/emulator/emulator -no-window -avd ci-test -noaudio > /dev/null & 57 | # - name: Run connected android tests 58 | # run: export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/25.2.9519653; 59 | # export SWIFT_ANDROID_HOME=$(pwd)/swift-android; 60 | # export PATH=$ANDROID_NDK_HOME:$PATH; 61 | # export PATH=$SWIFT_ANDROID_HOME/bin:$SWIFT_ANDROID_HOME/build-tools/current:$PATH; 62 | # adb wait-for-device; 63 | # ./gradlew sample:cAT 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | *.hprof 5 | 6 | # files for the dex VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # generated files 13 | bin/ 14 | gen/ 15 | build/ 16 | .build/ 17 | jniLibs/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Eclipse project files 23 | .classpath 24 | .project 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Intellij project files 30 | *.iml 31 | *.ipr 32 | *.iws 33 | 34 | # Gradle files 35 | .gradle/ 36 | crashlytics-build.properties 37 | 38 | # XCode 39 | *.xcodeproj 40 | app/src/main/swift/.idea 41 | captures 42 | .idea 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Readdle Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Swift Java Codegeneration annotation processor ![Maven Central](https://img.shields.io/maven-central/v/com.readdle.swift.java.codegen/compiler) 3 | 4 | Annotation processor that generate Swift JNI code for Kotlin headers 5 | 6 | ## Pre-requirements 7 | 8 | This annotation process only generate Swift JNI code. For compiling swift code for Android please use [Swift Android Gradle plugin](https://github.com/readdle/swift-android-gradle) 9 | 10 | ## Setup 11 | 12 | 1. Add the following to your root build.gradle 13 | 14 | ```gradle 15 | allprojects { 16 | repositories { 17 | mavenCentral() 18 | } 19 | } 20 | ``` 21 | 22 | 2. Add the following to your project build.gradle 23 | 24 | ```gradle 25 | dependencies { 26 | kapt "com.readdle.swift.java.codegen:compiler:$swift-java-codegen-version" 27 | implementation "com.readdle.swift.java.codegen:annotations:$swift-java-codegen-version" 28 | } 29 | ``` 30 | 31 | 32 | ## Usage 33 | 34 | Documentation in progress... 35 | 36 | 37 | ## Samples 38 | 39 | There are few samples that use Swift Java Codegen: 40 | 41 | 1. [Sample in this repo](https://github.com/readdle/swift-java-codegen/tree/master/sample) 42 | 2. [Kotlin sample for Desktop](https://github.com/andriydruk/swift-kotlin-sample) 43 | 3. [Cross-platform swift weather app](https://github.com/andriydruk/swift-weather-app) 44 | 45 | ## FAQ 46 | 47 | ### Why this project has Java in it name but doesn't support Java? 48 | 49 | When this project was started Kotlin was in beta development. That's why we decide to move on with Java as primary language. After 4 year of development we moved to Kotlin and break Java support. If for some reason you would like to use this project with Java, latest Java support version us stil available on Maven Central. 50 | 51 | ### Could I generate Swift JNI without writing Kotlin headers manually? 52 | 53 | Very good question. Probably it's possible but it's quite complicated. We invest time to research code generation based on Swift and have a small prototype. But the development of this new tool is still at a very early stage. 54 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '2.0.21' 3 | 4 | repositories { 5 | google() 6 | mavenCentral() 7 | maven { 8 | url "https://plugins.gradle.org/m2/" 9 | } 10 | } 11 | 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:8.3.2' 14 | classpath "com.readdle.android.swift:gradle:6.0.3" 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 16 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" 17 | classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' 18 | } 19 | } 20 | 21 | subprojects { project -> 22 | repositories { 23 | google() 24 | mavenCentral() 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | 32 | apply plugin: 'io.github.gradle-nexus.publish-plugin' 33 | apply from: "${rootDir}/publish-root.gradle" 34 | 35 | ext { 36 | PUBLISH_GROUP_ID = 'com.readdle.swift.java.codegen' 37 | PUBLISH_VERSION = "0.9.6" 38 | } -------------------------------------------------------------------------------- /compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'maven-publish' 3 | 4 | archivesBaseName = "compiler" 5 | 6 | dependencies { 7 | api project(':library') 8 | api 'com.google.code.gson:gson:2.10' 9 | } 10 | 11 | java { 12 | sourceCompatibility = JavaVersion.VERSION_1_8 13 | targetCompatibility = JavaVersion.VERSION_1_8 14 | 15 | withSourcesJar() 16 | withJavadocJar() 17 | } 18 | 19 | ext { 20 | PUBLISH_ARTIFACT_ID = 'compiler' 21 | } 22 | 23 | apply from: "${rootProject.projectDir}/publish-module.gradle" -------------------------------------------------------------------------------- /compiler/src/main/java/com/readdle/codegen/SwiftMappingException.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen; 2 | 3 | import javax.lang.model.element.Element; 4 | 5 | public class SwiftMappingException extends RuntimeException { 6 | private final Element element; 7 | 8 | public SwiftMappingException(String message, Element element) { 9 | super(message); 10 | this.element = element; 11 | } 12 | 13 | public SwiftMappingException(String message, Element element, Throwable parent) { 14 | super(message, parent); 15 | this.element = element; 16 | } 17 | 18 | public Element getElement() { 19 | return element; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/readdle/codegen/SwiftModuleDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen; 2 | 3 | import java.util.HashMap; 4 | 5 | class SwiftModuleDescriptor { 6 | 7 | String moduleName; 8 | String[] importPackages; 9 | HashMap customTypeMappings; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/readdle/codegen/SwiftParamDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen; 2 | 3 | import com.readdle.codegen.anotation.SwiftBlock; 4 | import javax.lang.model.element.VariableElement; 5 | 6 | import static java.util.Objects.requireNonNull; 7 | 8 | public class SwiftParamDescriptor { 9 | 10 | final String name; 11 | final SwiftEnvironment.Type swiftType; 12 | final boolean isOptional; 13 | 14 | SwiftParamDescriptor(VariableElement variableElement, JavaSwiftProcessor processor) { 15 | this.name = variableElement.getSimpleName().toString(); 16 | boolean isUnsigned = processor.isUnsigned(variableElement); 17 | if (isUnsigned) { 18 | this.swiftType = requireNonNull(processor.parseJavaType(Utils.typeToString(variableElement.asType()))).makeUnsigned(); 19 | } 20 | else { 21 | this.swiftType = requireNonNull(processor.parseJavaType(Utils.typeToString(variableElement.asType()))); 22 | } 23 | 24 | SwiftBlock swiftParam = variableElement.getAnnotation(SwiftBlock.class); 25 | if (swiftParam != null) { 26 | this.swiftType.swiftConstructorType = "SwiftBlock" + this.swiftType.swiftConstructorType; 27 | } 28 | this.isOptional = processor.isNullable(variableElement); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "SwiftParamDescriptor{" + 34 | "name='" + name + '\'' + 35 | ", swiftType='" + swiftType + '\'' + 36 | ", isOptional=" + isOptional + 37 | '}'; 38 | } 39 | 40 | public boolean isPrimitive() { 41 | if (isOptional) { 42 | return false; 43 | } 44 | else { 45 | return swiftType.isPrimitiveType(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/readdle/codegen/SwiftSetterDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen; 2 | 3 | import com.readdle.codegen.anotation.SwiftSetter; 4 | 5 | import java.io.IOException; 6 | import java.util.Collections; 7 | 8 | import javax.lang.model.element.ExecutableElement; 9 | import javax.lang.model.element.Modifier; 10 | 11 | class SwiftSetterDescriptor implements JavaSwiftProcessor.WritableElement { 12 | 13 | private String javaName; 14 | private String swiftName; 15 | 16 | private boolean isStatic; 17 | 18 | private SwiftParamDescriptor param; 19 | 20 | SwiftSetterDescriptor(ExecutableElement executableElement, SwiftSetter setterAnnotation, JavaSwiftProcessor processor) { 21 | this.javaName = executableElement.getSimpleName().toString(); 22 | this.isStatic = executableElement.getModifiers().contains(Modifier.STATIC); 23 | 24 | if (executableElement.getThrownTypes().size() != 0) { 25 | throw new SwiftMappingException("Setter can't throw", executableElement); 26 | } 27 | 28 | if (executableElement.getParameters().size() != 1) { 29 | throw new SwiftMappingException("Setter should have exactly 1 parameter", executableElement); 30 | } 31 | 32 | param = new SwiftParamDescriptor(executableElement.getParameters().get(0), processor); 33 | 34 | if (setterAnnotation != null && !setterAnnotation.value().isEmpty()) { 35 | this.swiftName = setterAnnotation.value(); 36 | } 37 | else { 38 | this.swiftName = javaName; 39 | if (swiftName.startsWith("set")) { 40 | swiftName = swiftName.substring(3); 41 | } 42 | char first = Character.toLowerCase(swiftName.charAt(0)); 43 | swiftName = first + swiftName.substring(1); 44 | } 45 | } 46 | 47 | @Override 48 | public void generateCode(SwiftWriter swiftWriter, String javaFullName, String swiftType) throws IOException { 49 | String swiftFuncName = Utils.mangleFunctionName(javaFullName, javaName, Collections.singletonList(param)); 50 | 51 | swiftWriter.emitEmptyLine(); 52 | swiftWriter.emitStatement(String.format("@_cdecl(\"%s\")", swiftFuncName)); 53 | swiftWriter.emit(String.format("public func %s(env: UnsafeMutablePointer, %s", swiftFuncName, isStatic ? "clazz: jclass" : "this: jobject")); 54 | swiftWriter.emit(String.format(", j%s: %s%s) {\n", param.name, param.swiftType.javaSigType(param.isOptional), param.isOptional ? "?" : "")); 55 | swiftWriter.emitEmptyLine(); 56 | 57 | if (!isStatic) { 58 | swiftWriter.emitStatement(String.format("let swiftSelf: %s", swiftType)); 59 | } 60 | 61 | swiftWriter.emitStatement(String.format("let %s: %s%s", param.name, param.swiftType.swiftType, param.isOptional ? "?" : "")); 62 | 63 | swiftWriter.emitStatement("do {"); 64 | 65 | if (!isStatic) { 66 | swiftWriter.emitStatement(String.format("swiftSelf = try %s.from(javaObject: this)", swiftType)); 67 | } 68 | 69 | if (param.isPrimitive()) { 70 | swiftWriter.emitStatement(String.format("%1$s = " + param.swiftType.swiftType + "(fromJavaPrimitive: j%1$s)", param.name)); 71 | } 72 | else if (param.isOptional) { 73 | swiftWriter.emitStatement(String.format("if let j%1$s = j%1$s {", param.name)); 74 | swiftWriter.emitStatement(String.format("%1$s = try %2$s.from(javaObject: j%1$s)", param.name, param.swiftType.swiftConstructorType)); 75 | swiftWriter.emitStatement("}"); 76 | swiftWriter.emitStatement("else {"); 77 | swiftWriter.emitStatement(String.format("%s = nil", param.name)); 78 | swiftWriter.emitStatement("}"); 79 | } 80 | else { 81 | swiftWriter.emitStatement(String.format("%1$s = try %2$s.from(javaObject: j%1$s)", param.name, param.swiftType.swiftConstructorType)); 82 | } 83 | 84 | swiftWriter.emitStatement("}"); 85 | swiftWriter.emitStatement("catch {"); 86 | Utils.handleRuntimeError(swiftWriter); 87 | swiftWriter.emitStatement("return"); 88 | swiftWriter.emitStatement("}"); 89 | 90 | swiftWriter.emitStatement(String.format("%s.%s = %s", isStatic ? swiftType : "swiftSelf", swiftName, param.name)); 91 | swiftWriter.emitStatement("}"); 92 | } 93 | 94 | @Override 95 | public String toString(String javaClassname) { 96 | return Utils.mangleFunctionName(javaClassname, javaName, Collections.singletonList(param)); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "SwiftSetterDescriptor{" + 102 | "javaName='" + javaName + '\'' + 103 | ", swiftName='" + swiftName + '\'' + 104 | ", isStatic=" + isStatic + 105 | ", param=" + param + 106 | '}'; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/readdle/codegen/SwiftWriter.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen; 2 | 3 | import java.io.File; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.text.Collator; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.Locale; 13 | 14 | public class SwiftWriter { 15 | 16 | private static class AlignedFileWriter extends FileWriter { 17 | private static final char MARGIN = '\t'; 18 | private int currentLevel = 0; 19 | private boolean printMargin = false; 20 | 21 | private AlignedFileWriter(File file) throws IOException { 22 | super(file); 23 | } 24 | 25 | private void appendCharacter(Character character) throws IOException { 26 | if (printMargin) { 27 | for (int i = 0; i < currentLevel; i++) { 28 | super.append(MARGIN); 29 | } 30 | 31 | printMargin = false; 32 | } 33 | 34 | super.append(character); 35 | } 36 | 37 | public Writer append(CharSequence charSequence) throws IOException { 38 | for (int i = 0; i < charSequence.length(); i++) { 39 | char c = charSequence.charAt(i); 40 | 41 | 42 | if (c == '}') { 43 | printMargin = true; 44 | currentLevel--; 45 | } 46 | 47 | appendCharacter(c); 48 | 49 | if (c == '\n') { 50 | printMargin = true; 51 | } 52 | 53 | if (c == '{') { 54 | currentLevel++; 55 | } 56 | } 57 | return this; 58 | } 59 | } 60 | 61 | private final Writer writer; 62 | 63 | public SwiftWriter(File file) throws IOException { 64 | this.writer = new AlignedFileWriter(file); 65 | } 66 | 67 | public void close() throws IOException { 68 | this.writer.flush(); 69 | this.writer.close(); 70 | } 71 | 72 | private static final String[] defaultImports = {"Foundation", "Java", "java_swift", "JavaCoder", "AnyCodable"}; 73 | 74 | public void emitImports(String[] importPackages) throws IOException { 75 | this.writer.append("/* This file was generated with Readdle SwiftJava Codegen */\n"); 76 | this.writer.append("/* Don't change it manually! */\n"); 77 | 78 | List allPackages = new ArrayList<>(); 79 | allPackages.addAll(Arrays.asList(defaultImports)); 80 | allPackages.addAll(Arrays.asList(importPackages)); 81 | Collections.sort(allPackages, Collator.getInstance(Locale.US)); 82 | 83 | for (String importPackage : allPackages) { 84 | this.writer.append(String.format("import %s\n", importPackage)); 85 | } 86 | } 87 | 88 | public void emitEmptyLine() throws IOException { 89 | this.writer.append("\n"); 90 | } 91 | 92 | public void emit(String statement) throws IOException { 93 | this.writer.append(statement); 94 | } 95 | 96 | public void emitStatement(String statement) throws IOException { 97 | this.writer.append(statement); 98 | this.writer.append("\n"); 99 | } 100 | 101 | public void beginExtension(String swiftType) throws IOException { 102 | this.writer.append(String.format("public extension %s {", swiftType)); 103 | this.writer.append("\n"); 104 | } 105 | 106 | public void endExtension() throws IOException { 107 | this.writer.append("}"); 108 | this.writer.append("\n"); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /compiler/src/main/resources/META-INF/gradle/incremental.annotation.processors: -------------------------------------------------------------------------------- 1 | com.readdle.codegen.JavaSwiftProcessor,isolating -------------------------------------------------------------------------------- /compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | com.readdle.codegen.JavaSwiftProcessor -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536m 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'maven-publish' 3 | 4 | archivesBaseName = "annotations" 5 | 6 | java { 7 | sourceCompatibility = JavaVersion.VERSION_1_8 8 | targetCompatibility = JavaVersion.VERSION_1_8 9 | 10 | withSourcesJar() 11 | withJavadocJar() 12 | } 13 | 14 | ext { 15 | PUBLISH_ARTIFACT_ID = 'annotations' 16 | } 17 | 18 | apply from: "${rootProject.projectDir}/publish-module.gradle" -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/JavaSwift.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | public class JavaSwift { 4 | 5 | private JavaSwift() {} 6 | 7 | public static native void init(); 8 | 9 | public static native void dumpReferenceTables(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftBlock.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftBlock { 10 | 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftCallbackFunc.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftCallbackFunc { 10 | 11 | String value() default ""; 12 | 13 | } -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftDelegate.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) 10 | public @interface SwiftDelegate { 11 | 12 | String[] protocols() default {}; 13 | 14 | } -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftError.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | public class SwiftError extends Exception { 4 | 5 | public SwiftError() { 6 | 7 | } 8 | 9 | public SwiftError(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftFunc.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftFunc { 10 | 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftGetter.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftGetter { 10 | 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftModule.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * @deprecated Using SwiftModule for package makes incremental annotation processing unavailable. 11 | * Please use annotationProcessorOptions "com.readdle.codegen.package" instead 12 | */ 13 | @Deprecated 14 | @Retention(RetentionPolicy.CLASS) 15 | @Target(ElementType.PACKAGE) 16 | public @interface SwiftModule { 17 | 18 | String moduleName() default ""; 19 | 20 | String[] importPackages() default {}; 21 | 22 | TypeMapping[] customTypeMappings() default {}; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftReference.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftReference { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftRuntimeError.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | 4 | public class SwiftRuntimeError extends RuntimeException { 5 | 6 | public SwiftRuntimeError() { 7 | 8 | } 9 | 10 | public SwiftRuntimeError(String message) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftSetter.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftSetter { 10 | 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/SwiftValue.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) 9 | public @interface SwiftValue { 10 | 11 | boolean hasSubclasses() default false; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/TypeMapping.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @deprecated Using SwiftModule for package makes incremental annotation processing unavailable. 10 | * Please use annotationProcessorOptions "com.readdle.codegen.package" instead 11 | */ 12 | @Deprecated 13 | @Retention(RetentionPolicy.CLASS) 14 | @Target(ElementType.PACKAGE) 15 | public @interface TypeMapping { 16 | 17 | String swiftType(); 18 | 19 | Class javaClass(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /library/src/main/java/com/readdle/codegen/anotation/Unsigned.java: -------------------------------------------------------------------------------- 1 | package com.readdle.codegen.anotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.CLASS) 9 | public @interface Unsigned { 10 | 11 | String value() default ""; 12 | } 13 | -------------------------------------------------------------------------------- /publish-module.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | group = PUBLISH_GROUP_ID 5 | version = PUBLISH_VERSION 6 | 7 | afterEvaluate { 8 | publishing { 9 | publications { 10 | release(MavenPublication) { 11 | from components.java 12 | 13 | groupId PUBLISH_GROUP_ID 14 | artifactId PUBLISH_ARTIFACT_ID 15 | version PUBLISH_VERSION 16 | 17 | pom { 18 | name = PUBLISH_ARTIFACT_ID 19 | description = 'Swift Java codegen' 20 | url = 'https://github.com/readdle/swift-java-codegen' 21 | licenses { 22 | license { 23 | name = 'MIT License' 24 | url = 'https://github.com/readdle/swift-java-codegen/blob/master/LICENSE' 25 | } 26 | } 27 | developers { 28 | developer { 29 | id = 'andriydruk' 30 | name = 'Andrew Druk' 31 | email = 'adruk@readdle.com' 32 | } 33 | } 34 | scm { 35 | connection = 'scm:git:github.com/readdle/swift-java-codegen.git' 36 | developerConnection = 'scm:git:ssh://github.com/readdle/swift-java-codegen.git' 37 | url = 'https://github.com/readdle/swift-java-codegen' 38 | } 39 | } 40 | } 41 | } 42 | } 43 | } 44 | 45 | ext["signing.keyId"] = rootProject.ext["signing.keyId"] 46 | ext["signing.password"] = rootProject.ext["signing.password"] 47 | ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"] 48 | 49 | signing { 50 | sign publishing.publications 51 | } -------------------------------------------------------------------------------- /publish-root.gradle: -------------------------------------------------------------------------------- 1 | // Create variables with empty default values 2 | ext["signing.keyId"] = '' 3 | ext["signing.password"] = '' 4 | ext["signing.secretKeyRingFile"] = '' 5 | ext["ossrhUsername"] = '' 6 | ext["ossrhPassword"] = '' 7 | ext["sonatypeStagingProfileId"] = '' 8 | 9 | File secretPropsFile = project.rootProject.file('local.properties') 10 | if (secretPropsFile.exists()) { 11 | // Read local.properties file first if it exists 12 | Properties p = new Properties() 13 | new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } 14 | p.each { name, value -> ext[name] = value } 15 | } else { 16 | // Use system environment variables 17 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') 18 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') 19 | ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') 20 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') 21 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD') 22 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') 23 | } 24 | 25 | // Set up Sonatype repository 26 | nexusPublishing { 27 | repositories { 28 | sonatype { 29 | stagingProfileId = sonatypeStagingProfileId 30 | username = ossrhUsername 31 | password = ossrhPassword 32 | nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) 33 | snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.readdle.android.swift' 3 | 4 | apply plugin: 'kotlin-android' 5 | apply plugin: 'kotlin-kapt' 6 | 7 | swift { 8 | useKapt true 9 | cleanEnabled true 10 | debug { 11 | extraBuildFlags("-Xswiftc", "-DDEBUG") 12 | } 13 | } 14 | 15 | android { 16 | namespace = "com.readdle.swiftjava.sample" 17 | compileSdkVersion 34 18 | defaultConfig { 19 | applicationId "com.readdle.swiftjava.sample" 20 | minSdkVersion 24 21 | targetSdkVersion 34 22 | versionCode 1 23 | versionName "1.0" 24 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 25 | javaCompileOptions { 26 | annotationProcessorOptions { 27 | arguments = ["com.readdle.codegen.package": """{ 28 | "moduleName": "SampleProject", 29 | "importPackages": ["SampleAppCore"], 30 | "customTypeMappings": { 31 | "com.readdle.swiftjava.sample.CustomSampleValue": "SampleValue" 32 | } 33 | } 34 | """ 35 | ] 36 | } 37 | } 38 | } 39 | 40 | compileOptions { 41 | sourceCompatibility = JavaVersion.VERSION_11 42 | targetCompatibility = JavaVersion.VERSION_11 43 | } 44 | 45 | kotlinOptions { 46 | jvmTarget = "11" 47 | } 48 | 49 | buildTypes { 50 | release { 51 | debuggable false 52 | jniDebuggable false 53 | minifyEnabled false 54 | shrinkResources false 55 | } 56 | debug { 57 | debuggable true 58 | jniDebuggable true 59 | minifyEnabled false 60 | shrinkResources false 61 | } 62 | } 63 | } 64 | 65 | dependencies { 66 | kapt project(':compiler') 67 | implementation project(':library') 68 | 69 | implementation "androidx.appcompat:appcompat:1.7.0" 70 | implementation 'androidx.constraintlayout:constraintlayout:2.2.1' 71 | testImplementation 'junit:junit:4.13.2' 72 | androidTestImplementation 'androidx.test.ext:junit:1.2.1' 73 | androidTestImplementation 'androidx.test:rules:1.6.1' 74 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' 75 | } 76 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | @RunWith(AndroidJUnit4.class) 13 | public class BoolTests { 14 | 15 | @Before 16 | public void setUp() { 17 | System.loadLibrary("SampleAppCore"); 18 | JavaSwift.init(); 19 | SwiftEnvironment.initEnvironment(); 20 | } 21 | 22 | @Test 23 | public void testZero() { 24 | Assert.assertTrue(BoolTest.testYes()); 25 | } 26 | 27 | @Test 28 | public void testMin() { 29 | Assert.assertFalse(BoolTest.testNo()); 30 | } 31 | 32 | @Test 33 | public void testParam() { 34 | Assert.assertTrue(BoolTest.testParam(true)); 35 | Assert.assertFalse(BoolTest.testParam(false)); 36 | } 37 | 38 | @Test 39 | public void testReturnType() { 40 | Assert.assertTrue(BoolTest.testReturnType()); 41 | } 42 | 43 | @Test 44 | public void testOptionalParam() { 45 | Assert.assertTrue(BoolTest.testOptionalParam(true)); 46 | Assert.assertFalse(BoolTest.testOptionalParam(false)); 47 | } 48 | 49 | public void testOptionalReturnType() { 50 | Boolean result = BoolTest.testOptionalReturnType(); 51 | Assert.assertNotNull(result); 52 | Assert.assertEquals(result, true); 53 | } 54 | 55 | @Test 56 | public void testProtocolParam() { 57 | boolean result = BoolTest.testProtocolParam(param -> param); 58 | Assert.assertTrue(result); 59 | } 60 | 61 | @Test 62 | public void testProtocolReturnType() { 63 | boolean result = BoolTest.testProtocolReturnType(() -> true); 64 | Assert.assertTrue(result); 65 | } 66 | 67 | @Test 68 | public void testProtocolOptionalParam() { 69 | boolean result = BoolTest.testProtocolOptionalParam(param -> param != null && param); 70 | Assert.assertTrue(result); 71 | } 72 | 73 | @Test 74 | public void testProtocolOptionalReturnType() { 75 | Boolean result = BoolTest.testProtocolOptionalReturnType(() -> true); 76 | Assert.assertNotNull(result); 77 | Assert.assertEquals(result, true); 78 | } 79 | 80 | @Test 81 | public void testEncode() { 82 | BoolTestStruct result = BoolTest.testEncode(); 83 | Assert.assertEquals(result, new BoolTestStruct()); 84 | } 85 | 86 | @Test 87 | public void testDecode() { 88 | BoolTestStruct goodParam = new BoolTestStruct(); 89 | BoolTestStruct badParam = new BoolTestStruct(true, true, true, true); 90 | Assert.assertTrue(BoolTest.testDecode(goodParam)); 91 | Assert.assertFalse(BoolTest.testDecode(badParam)); 92 | } 93 | 94 | @Test 95 | public void testBlock() { 96 | Assert.assertTrue(BoolTest.testBlock(value -> value)); 97 | } 98 | 99 | @Test 100 | public void testOptionalBlock() { 101 | Assert.assertTrue(BoolTest.testOptionalBlock(value -> value)); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | @RunWith(AndroidJUnit4.class) 13 | public class DoubleTests { 14 | 15 | private static final double DELTA = 0.000001; 16 | 17 | @Before 18 | public void setUp() { 19 | System.loadLibrary("SampleAppCore"); 20 | JavaSwift.init(); 21 | SwiftEnvironment.initEnvironment(); 22 | } 23 | 24 | @Test 25 | public void testZero() { 26 | Assert.assertEquals(DoubleTest.testZero(), 0f, DELTA); 27 | } 28 | 29 | @Test 30 | public void testMin() { 31 | Assert.assertEquals(DoubleTest.testNan(), Double.NaN, DELTA); 32 | } 33 | 34 | @Test 35 | public void testMax() { 36 | Assert.assertEquals(DoubleTest.testInfinite(), Double.POSITIVE_INFINITY, DELTA); 37 | } 38 | 39 | @Test 40 | public void testParam() { 41 | Assert.assertTrue(DoubleTest.testParam(Double.POSITIVE_INFINITY)); 42 | Assert.assertFalse(DoubleTest.testParam(Double.NaN)); 43 | } 44 | 45 | @Test 46 | public void testReturnType() { 47 | Assert.assertEquals(DoubleTest.testReturnType(), Double.POSITIVE_INFINITY, DELTA); 48 | } 49 | 50 | @Test 51 | public void testOptionalParam() { 52 | Assert.assertTrue(DoubleTest.testOptionalParam(Double.POSITIVE_INFINITY)); 53 | Assert.assertFalse(DoubleTest.testOptionalParam(Double.NaN)); 54 | } 55 | 56 | public void testOptionalReturnType() { 57 | Double result = DoubleTest.testOptionalReturnType(); 58 | Assert.assertNotNull(result); 59 | Assert.assertEquals(result.floatValue(), Double.POSITIVE_INFINITY, DELTA); 60 | } 61 | 62 | @Test 63 | public void testProtocolParam() { 64 | boolean result = DoubleTest.testProtocolParam(param -> param == Double.POSITIVE_INFINITY); 65 | Assert.assertTrue(result); 66 | } 67 | 68 | @Test 69 | public void testProtocolReturnType() { 70 | double result = DoubleTest.testProtocolReturnType(() -> 42.0); 71 | Assert.assertEquals(result, 42.0, DELTA); 72 | } 73 | 74 | @Test 75 | public void testProtocolOptionalParam() { 76 | boolean result = DoubleTest.testProtocolOptionalParam(param -> param != null && param == Double.POSITIVE_INFINITY); 77 | Assert.assertTrue(result); 78 | } 79 | 80 | @Test 81 | public void testProtocolOptionalReturnType() { 82 | Double result = DoubleTest.testProtocolOptionalReturnType(() -> 42.0); 83 | Assert.assertNotNull(result); 84 | Assert.assertEquals(result, 42.0, DELTA); 85 | } 86 | 87 | @Test 88 | public void testEncode() { 89 | DoubleTestStruct result = DoubleTest.testEncode(); 90 | Assert.assertEquals(result, new DoubleTestStruct()); 91 | } 92 | 93 | @Test 94 | public void testDecode() { 95 | DoubleTestStruct goodParam = new DoubleTestStruct(); 96 | DoubleTestStruct badParam = new DoubleTestStruct( 42.0, 42.0, 42.0, 42.0,42.0); 97 | Assert.assertTrue(DoubleTest.testDecode(goodParam)); 98 | Assert.assertFalse(DoubleTest.testDecode(badParam)); 99 | } 100 | 101 | @Test 102 | public void testBlock() { 103 | Assert.assertTrue(DoubleTest.testBlock(value -> value)); 104 | } 105 | 106 | @Test 107 | public void testOptionalBoolBlock() { 108 | Assert.assertTrue(DoubleTest.testOptionalBlock(value -> value)); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | @RunWith(AndroidJUnit4.class) 13 | public class FloatTests { 14 | 15 | private static final float DELTA = 0.000001f; 16 | 17 | @Before 18 | public void setUp() { 19 | System.loadLibrary("SampleAppCore"); 20 | JavaSwift.init(); 21 | SwiftEnvironment.initEnvironment(); 22 | } 23 | 24 | @Test 25 | public void testZero() { 26 | Assert.assertEquals(FloatTest.testZero(), 0f, DELTA); 27 | } 28 | 29 | @Test 30 | public void testMin() { 31 | Assert.assertEquals(FloatTest.testNan(), Float.NaN, DELTA); 32 | } 33 | 34 | @Test 35 | public void testMax() { 36 | Assert.assertEquals(FloatTest.testInfinite(), Float.POSITIVE_INFINITY, DELTA); 37 | } 38 | 39 | @Test 40 | public void testParam() { 41 | Assert.assertTrue(FloatTest.testParam(Float.POSITIVE_INFINITY)); 42 | Assert.assertFalse(FloatTest.testParam(Float.NaN)); 43 | } 44 | 45 | @Test 46 | public void testReturnType() { 47 | Assert.assertEquals(FloatTest.testReturnType(), Float.POSITIVE_INFINITY, DELTA); 48 | } 49 | 50 | @Test 51 | public void testOptionalParam() { 52 | Assert.assertTrue(FloatTest.testOptionalParam(Float.POSITIVE_INFINITY)); 53 | Assert.assertFalse(FloatTest.testOptionalParam(Float.NaN)); 54 | } 55 | 56 | public void testOptionalReturnType() { 57 | Float result = FloatTest.testOptionalReturnType(); 58 | Assert.assertNotNull(result); 59 | Assert.assertEquals(result.floatValue(), Float.POSITIVE_INFINITY, DELTA); 60 | } 61 | 62 | @Test 63 | public void testProtocolParam() { 64 | boolean result = FloatTest.testProtocolParam(param -> param == Float.POSITIVE_INFINITY); 65 | Assert.assertTrue(result); 66 | } 67 | 68 | @Test 69 | public void testProtocolReturnType() { 70 | float result = FloatTest.testProtocolReturnType(() -> 42f); 71 | Assert.assertEquals(result, 42f, DELTA); 72 | } 73 | 74 | @Test 75 | public void testProtocolOptionalParam() { 76 | boolean result = FloatTest.testProtocolOptionalParam(param -> param != null && param == Float.POSITIVE_INFINITY); 77 | Assert.assertTrue(result); 78 | } 79 | 80 | @Test 81 | public void testProtocolOptionalReturnType() { 82 | Float result = FloatTest.testProtocolOptionalReturnType(() -> 42f); 83 | Assert.assertNotNull(result); 84 | Assert.assertEquals(result.floatValue(), 42f, DELTA); 85 | } 86 | 87 | @Test 88 | public void testEncode() { 89 | FloatTestStruct result = FloatTest.testEncode(); 90 | Assert.assertEquals(result, new FloatTestStruct()); 91 | } 92 | 93 | @Test 94 | public void testDecode() { 95 | FloatTestStruct goodParam = new FloatTestStruct(); 96 | FloatTestStruct badParam = new FloatTestStruct( 42f, 42f, 42f, 42f,42f); 97 | Assert.assertTrue(FloatTest.testDecode(goodParam)); 98 | Assert.assertFalse(FloatTest.testDecode(badParam)); 99 | } 100 | 101 | @Test 102 | public void testBlock() { 103 | Assert.assertTrue(FloatTest.testBlock(value -> value)); 104 | } 105 | 106 | @Test 107 | public void testOptionalBlock() { 108 | Assert.assertTrue(FloatTest.testOptionalBlock(value -> value)); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/Int32Tests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | @RunWith(AndroidJUnit4.class) 13 | public class Int32Tests { 14 | 15 | @Before 16 | public void setUp() { 17 | System.loadLibrary("SampleAppCore"); 18 | JavaSwift.init(); 19 | SwiftEnvironment.initEnvironment(); 20 | } 21 | 22 | @Test 23 | public void testEncode() { 24 | Int32TestStruct result = Int32Test.testEncode(); 25 | Assert.assertEquals(result, new Int32TestStruct()); 26 | } 27 | 28 | @Test 29 | public void testDecode() { 30 | Int32TestStruct goodParam = new Int32TestStruct(); 31 | Int32TestStruct badParam = new Int32TestStruct(42, 42, 42, 42, 42); 32 | Assert.assertTrue(Int32Test.testDecode(goodParam)); 33 | Assert.assertFalse(Int32Test.testDecode(badParam)); 34 | } 35 | 36 | @Test 37 | public void testEnumEncode() { 38 | Assert.assertEquals(Int32Enum.ONE, Int32Test.testEnumEncode(Int32Enum.ONE.getRawValue())); 39 | Assert.assertEquals(Int32Enum.TWO, Int32Test.testEnumEncode(Int32Enum.TWO.getRawValue())); 40 | Assert.assertEquals(Int32Enum.THREE, Int32Test.testEnumEncode(Int32Enum.THREE.getRawValue())); 41 | } 42 | 43 | @Test 44 | public void testEnumDecode() { 45 | Assert.assertEquals(Int32Enum.ONE.getRawValue(), Int32Test.testEnumDecode(Int32Enum.ONE)); 46 | Assert.assertEquals(Int32Enum.TWO.getRawValue(), Int32Test.testEnumDecode(Int32Enum.TWO)); 47 | Assert.assertEquals(Int32Enum.THREE.getRawValue(), Int32Test.testEnumDecode(Int32Enum.THREE)); 48 | } 49 | 50 | @Test 51 | public void testOptionSetEncode() { 52 | Assert.assertEquals(Int32OptionsSet.getOne(), Int32Test.testOptionSetEncode(Int32OptionsSet.getOne().getRawValue())); 53 | Assert.assertEquals(Int32OptionsSet.getTwo(), Int32Test.testOptionSetEncode(Int32OptionsSet.getTwo().getRawValue())); 54 | Assert.assertEquals(Int32OptionsSet.getThree(), Int32Test.testOptionSetEncode(Int32OptionsSet.getThree().getRawValue())); 55 | } 56 | 57 | @Test 58 | public void testOptionSetDecode() { 59 | Assert.assertEquals(Int32OptionsSet.getOne().getRawValue(), Int32Test.testOptionSetDecode(Int32OptionsSet.getOne())); 60 | Assert.assertEquals(Int32OptionsSet.getTwo().getRawValue(), Int32Test.testOptionSetDecode(Int32OptionsSet.getTwo())); 61 | Assert.assertEquals(Int32OptionsSet.getThree().getRawValue(), Int32Test.testOptionSetDecode(Int32OptionsSet.getThree())); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/Issue31Tests.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4 4 | import com.readdle.codegen.anotation.JavaSwift 5 | import com.readdle.swiftjava.sample.SwiftEnvironment.Companion.initEnvironment 6 | import org.junit.Assert 7 | import org.junit.Before 8 | import org.junit.Test 9 | import org.junit.runner.RunWith 10 | 11 | @RunWith(AndroidJUnit4::class) 12 | class Issue31Tests { 13 | 14 | @Before 15 | fun setUp() { 16 | System.loadLibrary("SampleAppCore") 17 | JavaSwift.init() 18 | initEnvironment() 19 | } 20 | 21 | @Test 22 | fun testValueTypeNanBug() { 23 | val progress = Issue31TestProgress(elapsed = 8, total = 8) 24 | Assert.assertNotEquals(Double.NaN, progress.percentage) 25 | Assert.assertNotEquals(Double.NaN, progress.calculatePercentage()) 26 | } 27 | 28 | @Test 29 | fun testReferenceTypeNanBug() { 30 | val progress = Issue31ReferenceTestProgress.init(elapsed = 8, total = 8) 31 | Assert.assertNotEquals(Double.NaN, progress.percentage) 32 | Assert.assertNotEquals(Double.NaN, progress.calculatePercentage()) 33 | } 34 | } -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/MemoryLeakVerifier.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import org.junit.Assert; 4 | 5 | import java.lang.ref.WeakReference; 6 | 7 | public class MemoryLeakVerifier { 8 | 9 | private static final int MAX_GC_ITERATIONS = 50; 10 | private static final int GC_SLEEP_TIME = 100; 11 | 12 | private final WeakReference reference; 13 | 14 | public MemoryLeakVerifier(Object object) { 15 | this.reference = new WeakReference(object); 16 | } 17 | 18 | public Object getObject() { 19 | return reference.get(); 20 | } 21 | 22 | /** 23 | * Attempts to perform a full garbage collection so that all weak references will be removed. Usually only 24 | * a single GC is required, but there have been situations where some unused memory is not cleared up on the 25 | * first pass. This method performs a full garbage collection and then validates that the weak reference 26 | * now has been cleared. If it hasn't then the thread will sleep for 50 milliseconds and then retry up to 27 | * 10 more times. If after this the object still has not been collected then the assertion will fail. 28 | *

29 | * Based upon the method described in: http://www.javaworld.com/javaworld/javatips/jw-javatip130.html 30 | */ 31 | public void assertGarbageCollected(String name) { 32 | Runtime runtime = Runtime.getRuntime(); 33 | for (int i = 0; i < MAX_GC_ITERATIONS; i++) { 34 | runtime.runFinalization(); 35 | runtime.gc(); 36 | if (getObject() == null) 37 | break; 38 | 39 | // Pause for a while and then go back around the loop to try again... 40 | try { 41 | Thread.sleep(GC_SLEEP_TIME); 42 | } catch (InterruptedException e) { 43 | // Ignore any interrupts and just try again... 44 | } 45 | } 46 | Assert.assertNull(name + ": object should not exist after " + MAX_GC_ITERATIONS + " collections", getObject()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4 4 | import com.readdle.codegen.anotation.JavaSwift 5 | import com.readdle.codegen.anotation.SwiftError 6 | import com.readdle.swiftjava.sample.SampleValue.Companion.funcThrows 7 | import org.junit.Assert 8 | import org.junit.Before 9 | import org.junit.Test 10 | import org.junit.runner.RunWith 11 | import java.util.* 12 | 13 | @RunWith(AndroidJUnit4::class) 14 | class SampleValueTest { 15 | @Before 16 | fun setUp() { 17 | System.loadLibrary("SampleAppCore") 18 | JavaSwift.init() 19 | } 20 | 21 | @Test 22 | fun testGetRandomValue() { 23 | val sampleValue = SampleValue.getRandomValue().copy() 24 | Assert.assertNotNull(sampleValue) 25 | Assert.assertTrue(sampleValue.string.isNotEmpty()) 26 | Assert.assertTrue(sampleValue.integer == 32) 27 | Assert.assertTrue(sampleValue.int8.toInt() == 8) 28 | Assert.assertTrue(sampleValue.int16.toInt() == 16) 29 | Assert.assertTrue(sampleValue.int32 == 32) 30 | Assert.assertTrue(sampleValue.int64 == 64L) 31 | Assert.assertTrue(sampleValue.uint == 32U) 32 | Assert.assertTrue(sampleValue.uint8.toUInt() == 8U) 33 | Assert.assertTrue(sampleValue.uint16.toUInt() == 16U) 34 | Assert.assertTrue(sampleValue.uint32 == 32U) 35 | Assert.assertTrue(sampleValue.uint64.toUInt() == 64U) 36 | Assert.assertTrue(sampleValue.objectArray.isEmpty()) 37 | Assert.assertTrue(sampleValue.stringArray.size == 3) 38 | Assert.assertTrue(sampleValue.numberArray.size == 3) 39 | Assert.assertTrue(sampleValue.arrayInArray[0].size == 3) 40 | Assert.assertTrue(sampleValue.dictInArray[0].size == 3) 41 | Assert.assertTrue(sampleValue.dictSampleClass.isEmpty()) 42 | Assert.assertTrue(sampleValue.dictStrings.size == 1) 43 | Assert.assertTrue(sampleValue.dictNumbers.size == 1) 44 | Assert.assertTrue(sampleValue.dict64Numbers.size == 1) 45 | Assert.assertTrue(sampleValue.dictInDict.size == 1) 46 | Assert.assertTrue(sampleValue.arrayInDict.size == 1) 47 | Assert.assertTrue(sampleValue.set.size == 3) 48 | Assert.assertTrue(sampleValue.setValues.isEmpty()) 49 | } 50 | 51 | @Test 52 | fun testSaveValue() { 53 | val sampleValue = SampleValue.getRandomValue() 54 | sampleValue.string = UUID.randomUUID().toString() 55 | sampleValue.saveValue() 56 | } 57 | 58 | @Test 59 | fun testIsSame() { 60 | val otherValue = SampleValue.getRandomValue() 61 | val sampleValue = SampleValue.getRandomValue() 62 | sampleValue.string = otherValue.string 63 | Assert.assertTrue(sampleValue.isSame(otherValue)) 64 | } 65 | 66 | @Test 67 | fun testThrows() { 68 | try { 69 | funcThrows() 70 | Assert.fail() 71 | } catch (swiftError: SwiftError) { 72 | Assert.assertTrue(swiftError.message != null) 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/StringTests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | import com.readdle.codegen.anotation.SwiftRuntimeError; 7 | 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | 13 | @RunWith(AndroidJUnit4.class) 14 | public class StringTests { 15 | 16 | @Before 17 | public void setUp() { 18 | System.loadLibrary("SampleAppCore"); 19 | JavaSwift.init(); 20 | SwiftEnvironment.initEnvironment(); 21 | } 22 | 23 | @Test 24 | public void testZero() { 25 | Assert.assertEquals(StringTest.testZero(), ""); 26 | } 27 | 28 | @Test 29 | public void testParam() { 30 | Assert.assertTrue(StringTest.testParam("")); 31 | Assert.assertFalse(StringTest.testParam("42")); 32 | } 33 | 34 | @Test 35 | public void testReturnType() { 36 | Assert.assertEquals(StringTest.testReturnType(), ""); 37 | } 38 | 39 | @Test 40 | public void testOptionalParam() { 41 | Assert.assertTrue(StringTest.testOptionalParam("")); 42 | Assert.assertFalse(StringTest.testOptionalParam(null)); 43 | } 44 | 45 | @Test 46 | public void testOptionalReturnType() { 47 | try { 48 | StringTest.testOptionalReturnType(); 49 | } 50 | catch (Exception e) { 51 | Assert.assertTrue(e instanceof SwiftRuntimeError); 52 | Assert.assertEquals(e.getMessage(), "Invalid value \"" + Long.MAX_VALUE + "\": Not enough bits to represent Int []"); 53 | } 54 | } 55 | 56 | @Test 57 | public void testProtocolParam() { 58 | boolean result = StringTest.testProtocolParam(param -> param.equals("")); 59 | Assert.assertTrue(result); 60 | } 61 | 62 | @Test 63 | public void testProtocolReturnType() { 64 | String result = StringTest.testProtocolReturnType(() -> "42"); 65 | Assert.assertEquals(result, "42"); 66 | } 67 | 68 | @Test 69 | public void testProtocolOptionalParam() { 70 | boolean result = StringTest.testProtocolOptionalParam(param -> param != null && param.equals("")); 71 | Assert.assertTrue(result); 72 | } 73 | 74 | @Test 75 | public void testProtocolOptionalReturnType() { 76 | String result = StringTest.testProtocolOptionalReturnType(() -> "42"); 77 | Assert.assertNotNull(result); 78 | Assert.assertEquals(result, "42"); 79 | } 80 | 81 | @Test 82 | public void testEncode() { 83 | StringTestStruct result = StringTest.testEncode(); 84 | Assert.assertEquals(result, new StringTestStruct()); 85 | } 86 | 87 | @Test 88 | public void testDecode() { 89 | StringTestStruct goodParam = new StringTestStruct(); 90 | StringTestStruct badParam = new StringTestStruct("42", "42", "42"); 91 | Assert.assertTrue(StringTest.testDecode(goodParam)); 92 | Assert.assertFalse(StringTest.testDecode(badParam)); 93 | } 94 | 95 | @Test 96 | public void testEnumEncode() { 97 | Assert.assertEquals(StringEnum.ONE, StringTest.testEnumEncode(StringEnum.ONE.getRawValue())); 98 | Assert.assertEquals(StringEnum.TWO, StringTest.testEnumEncode(StringEnum.TWO.getRawValue())); 99 | Assert.assertEquals(StringEnum.THREE, StringTest.testEnumEncode(StringEnum.THREE.getRawValue())); 100 | } 101 | 102 | @Test 103 | public void testEnumDecode() { 104 | Assert.assertEquals(StringEnum.ONE.getRawValue(), StringTest.testEnumDecode(StringEnum.ONE)); 105 | Assert.assertEquals(StringEnum.TWO.getRawValue(), StringTest.testEnumDecode(StringEnum.TWO)); 106 | Assert.assertEquals(StringEnum.THREE.getRawValue(), StringTest.testEnumDecode(StringEnum.THREE)); 107 | } 108 | 109 | @Test 110 | public void testBlock() { 111 | Assert.assertTrue(StringTest.testBlock(value -> value)); 112 | } 113 | 114 | @Test 115 | public void testOptionalBlock() { 116 | Assert.assertTrue(StringTest.testOptionalBlock(value -> value)); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt32Tests.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | 5 | import com.readdle.codegen.anotation.JavaSwift; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | @RunWith(AndroidJUnit4.class) 13 | public class UInt32Tests { 14 | 15 | @Before 16 | public void setUp() { 17 | System.loadLibrary("SampleAppCore"); 18 | JavaSwift.init(); 19 | SwiftEnvironment.initEnvironment(); 20 | } 21 | 22 | @Test 23 | public void testEncode() { 24 | UInt32TestStruct result = UInt32Test.testEncode(); 25 | Assert.assertEquals(result, new UInt32TestStruct()); 26 | } 27 | 28 | @Test 29 | public void testDecode() { 30 | UInt32TestStruct goodParam = new UInt32TestStruct(); 31 | UInt32TestStruct badParam = new UInt32TestStruct(42, 42, 42, 42, 42); 32 | Assert.assertTrue(UInt32Test.testDecode(goodParam)); 33 | Assert.assertFalse(UInt32Test.testDecode(badParam)); 34 | } 35 | 36 | @Test 37 | public void testEnumEncode() { 38 | Assert.assertEquals(UInt32Enum.ONE,UInt32Test.testEnumEncode(UInt32Enum.ONE.getRawValue())); 39 | Assert.assertEquals(UInt32Enum.TWO,UInt32Test.testEnumEncode(UInt32Enum.TWO.getRawValue())); 40 | Assert.assertEquals(UInt32Enum.THREE,UInt32Test.testEnumEncode(UInt32Enum.THREE.getRawValue())); 41 | } 42 | 43 | @Test 44 | public void testEnumDecode() { 45 | Assert.assertEquals(UInt32Enum.ONE.getRawValue(),UInt32Test.testEnumDecode(UInt32Enum.ONE)); 46 | Assert.assertEquals(UInt32Enum.TWO.getRawValue(),UInt32Test.testEnumDecode(UInt32Enum.TWO)); 47 | Assert.assertEquals(UInt32Enum.THREE.getRawValue(),UInt32Test.testEnumDecode(UInt32Enum.THREE)); 48 | } 49 | 50 | @Test 51 | public void testOptionSetEncode() { 52 | Assert.assertEquals(UInt32OptionsSet.getOne(),UInt32Test.testOptionSetEncode(UInt32OptionsSet.getOne().getRawValue())); 53 | Assert.assertEquals(UInt32OptionsSet.getTwo(),UInt32Test.testOptionSetEncode(UInt32OptionsSet.getTwo().getRawValue())); 54 | Assert.assertEquals(UInt32OptionsSet.getThree(),UInt32Test.testOptionSetEncode(UInt32OptionsSet.getThree().getRawValue())); 55 | } 56 | 57 | @Test 58 | public void testOptionSetDecode() { 59 | Assert.assertEquals(UInt32OptionsSet.getOne().getRawValue(),UInt32Test.testOptionSetDecode(UInt32OptionsSet.getOne())); 60 | Assert.assertEquals(UInt32OptionsSet.getTwo().getRawValue(),UInt32Test.testOptionSetDecode(UInt32OptionsSet.getTwo())); 61 | Assert.assertEquals(UInt32OptionsSet.getThree().getRawValue(),UInt32Test.testOptionSetDecode(UInt32OptionsSet.getThree())); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/BoolTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | data class BoolTestStruct(var yes: Boolean = true, 8 | var no: Boolean = false, 9 | var optional: Boolean? = true, 10 | var optionalNil: Boolean? = null) 11 | 12 | @SwiftReference 13 | class BoolTest private constructor() { 14 | 15 | @SwiftDelegate(protocols = ["BoolTestParamProtocol"]) 16 | interface BoolParamProtocol { 17 | @SwiftCallbackFunc 18 | fun testParam(param: Boolean): Boolean 19 | } 20 | 21 | @SwiftDelegate(protocols = ["BoolTestReturnTypeProtocol"]) 22 | interface BoolReturnTypeProtocol { 23 | @SwiftCallbackFunc 24 | fun testReturnType(): Boolean 25 | } 26 | 27 | @SwiftDelegate(protocols = ["BoolTestOptionalParamProtocol"]) 28 | interface BoolOptionalParamProtocol { 29 | @SwiftCallbackFunc 30 | fun testOptionalParam(param: Boolean?): Boolean 31 | } 32 | 33 | @SwiftDelegate(protocols = ["BoolTestOptionalReturnTypeProtocol"]) 34 | interface BoolOptionalReturnTypeProtocol { 35 | @SwiftCallbackFunc 36 | fun testOptionalReturnType(): Boolean? 37 | } 38 | 39 | @SwiftBlock("(Bool) -> Bool") 40 | interface BoolBlock { 41 | fun call(value: Boolean): Boolean 42 | } 43 | 44 | @SwiftBlock("(Bool?) -> Bool?") 45 | interface OptionalBoolBlock { 46 | fun call(value: Boolean?): Boolean? 47 | } 48 | 49 | companion object { 50 | @JvmStatic 51 | external fun testYes(): Boolean 52 | 53 | @JvmStatic 54 | external fun testNo(): Boolean 55 | 56 | @JvmStatic 57 | external fun testParam(param: Boolean): Boolean 58 | 59 | @JvmStatic 60 | external fun testReturnType(): Boolean 61 | 62 | @JvmStatic 63 | external fun testOptionalParam(param: Boolean?): Boolean 64 | 65 | @JvmStatic 66 | external fun testOptionalReturnType(): Boolean? 67 | 68 | @JvmStatic 69 | external fun testProtocolParam(callback: BoolParamProtocol): Boolean 70 | 71 | @JvmStatic 72 | external fun testProtocolReturnType(callback: BoolReturnTypeProtocol): Boolean 73 | 74 | @JvmStatic 75 | external fun testProtocolOptionalParam(callback: BoolOptionalParamProtocol): Boolean 76 | 77 | @JvmStatic 78 | external fun testProtocolOptionalReturnType(callback: BoolOptionalReturnTypeProtocol): Boolean? 79 | 80 | @JvmStatic 81 | external fun testEncode(): BoolTestStruct 82 | 83 | @JvmStatic 84 | external fun testDecode(value: BoolTestStruct): Boolean 85 | 86 | @JvmStatic 87 | external fun testBlock(@SwiftBlock block: BoolBlock): Boolean 88 | 89 | @JvmStatic 90 | external fun testOptionalBlock(@SwiftBlock block: OptionalBoolBlock): Boolean 91 | } 92 | 93 | @Native 94 | var nativePointer: Long = 0 95 | 96 | external fun release() 97 | 98 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/CustomSampleValue.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | class CustomSampleValue private constructor() : SampleValue() 4 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/DoubleTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | data class DoubleTestStruct(var zero: Double = 0.0, 8 | var infinity: Double = Double.POSITIVE_INFINITY, 9 | var negativeInfinity: Double = Double.NEGATIVE_INFINITY, 10 | var optional: Double? = 0.0, 11 | var optionalNil: Double? = null) 12 | 13 | @SwiftReference 14 | class DoubleTest private constructor() { 15 | 16 | @SwiftDelegate(protocols = ["DoubleTestParamProtocol"]) 17 | interface DoubleParamProtocol { 18 | @SwiftCallbackFunc 19 | fun testParam(param: Double): Boolean 20 | } 21 | 22 | @SwiftDelegate(protocols = ["DoubleTestReturnTypeProtocol"]) 23 | interface DoubleReturnTypeProtocol { 24 | @SwiftCallbackFunc 25 | fun testReturnType(): Double 26 | } 27 | 28 | @SwiftDelegate(protocols = ["DoubleTestOptionalParamProtocol"]) 29 | interface DoubleOptionalParamProtocol { 30 | @SwiftCallbackFunc 31 | fun testOptionalParam(param: Double?): Boolean 32 | } 33 | 34 | @SwiftDelegate(protocols = ["DoubleTestOptionalReturnTypeProtocol"]) 35 | interface DoubleOptionalReturnTypeProtocol { 36 | @SwiftCallbackFunc 37 | fun testOptionalReturnType(): Double? 38 | } 39 | 40 | @SwiftBlock("(Double) -> Double") 41 | interface DoubleBlock { 42 | fun call(value: Double): Double 43 | } 44 | 45 | @SwiftBlock("(Double?) -> Double?") 46 | interface OptionalDoubleBlock { 47 | fun call(value: Double?): Double? 48 | } 49 | 50 | companion object { 51 | @JvmStatic 52 | external fun testZero(): Double 53 | 54 | @JvmStatic 55 | external fun testInfinite(): Double 56 | 57 | @JvmStatic 58 | external fun testNan(): Double 59 | 60 | @JvmStatic 61 | external fun testParam(param: Double): Boolean 62 | 63 | @JvmStatic 64 | external fun testReturnType(): Double 65 | 66 | @JvmStatic 67 | external fun testOptionalParam(param: Double?): Boolean 68 | 69 | @JvmStatic 70 | external fun testOptionalReturnType(): Double? 71 | 72 | @JvmStatic 73 | external fun testProtocolParam(callback: DoubleParamProtocol): Boolean 74 | 75 | @JvmStatic 76 | external fun testProtocolReturnType(callback: DoubleReturnTypeProtocol): Double 77 | 78 | @JvmStatic 79 | external fun testProtocolOptionalParam(callback: DoubleOptionalParamProtocol): Boolean 80 | 81 | @JvmStatic 82 | external fun testProtocolOptionalReturnType(callback: DoubleOptionalReturnTypeProtocol): Double? 83 | 84 | @JvmStatic 85 | external fun testEncode(): DoubleTestStruct 86 | 87 | @JvmStatic 88 | external fun testDecode(value: DoubleTestStruct): Boolean 89 | 90 | @JvmStatic 91 | external fun testBlock(@SwiftBlock block: DoubleBlock): Boolean 92 | 93 | @JvmStatic 94 | external fun testOptionalBlock(@SwiftBlock block: OptionalDoubleBlock): Boolean 95 | } 96 | 97 | @Native 98 | var nativePointer: Long = 0 99 | 100 | external fun release() 101 | 102 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/FloatTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | data class FloatTestStruct(var zero: Float = 0f, 8 | var infinity: Float = Float.POSITIVE_INFINITY, 9 | var negativeInfinity: Float = Float.NEGATIVE_INFINITY, 10 | var optional: Float? = 0f, 11 | var optionalNil: Float? = null) 12 | 13 | @SwiftReference 14 | class FloatTest private constructor() { 15 | 16 | @SwiftDelegate(protocols = ["FloatTestParamProtocol"]) 17 | interface FloatParamProtocol { 18 | @SwiftCallbackFunc 19 | fun testParam(param: Float): Boolean 20 | } 21 | 22 | @SwiftDelegate(protocols = ["FloatTestReturnTypeProtocol"]) 23 | interface FloatReturnTypeProtocol { 24 | @SwiftCallbackFunc 25 | fun testReturnType(): Float 26 | } 27 | 28 | @SwiftDelegate(protocols = ["FloatTestOptionalParamProtocol"]) 29 | interface FloatOptionalParamProtocol { 30 | @SwiftCallbackFunc 31 | fun testOptionalParam(param: Float?): Boolean 32 | } 33 | 34 | @SwiftDelegate(protocols = ["FloatTestOptionalReturnTypeProtocol"]) 35 | interface FloatOptionalReturnTypeProtocol { 36 | @SwiftCallbackFunc 37 | fun testOptionalReturnType(): Float? 38 | } 39 | 40 | @SwiftBlock("(Float) -> Float") 41 | interface FloatBlock { 42 | fun call(value: Float): Float 43 | } 44 | 45 | @SwiftBlock("(Float?) -> Float?") 46 | interface OptionalFloatBlock { 47 | fun call(value: Float?): Float? 48 | } 49 | 50 | companion object { 51 | @JvmStatic 52 | external fun testZero(): Float 53 | 54 | @JvmStatic 55 | external fun testInfinite(): Float 56 | 57 | @JvmStatic 58 | external fun testNan(): Float 59 | 60 | @JvmStatic 61 | external fun testParam(param: Float): Boolean 62 | 63 | @JvmStatic 64 | external fun testReturnType(): Float 65 | 66 | @JvmStatic 67 | external fun testOptionalParam(param: Float?): Boolean 68 | 69 | @JvmStatic 70 | external fun testOptionalReturnType(): Float? 71 | 72 | @JvmStatic 73 | external fun testProtocolParam(callback: FloatParamProtocol): Boolean 74 | 75 | @JvmStatic 76 | external fun testProtocolReturnType(callback: FloatReturnTypeProtocol): Float 77 | 78 | @JvmStatic 79 | external fun testProtocolOptionalParam(callback: FloatOptionalParamProtocol): Boolean 80 | 81 | @JvmStatic 82 | external fun testProtocolOptionalReturnType(callback: FloatOptionalReturnTypeProtocol): Float? 83 | 84 | @JvmStatic 85 | external fun testEncode(): FloatTestStruct 86 | 87 | @JvmStatic 88 | external fun testDecode(value: FloatTestStruct): Boolean 89 | 90 | @JvmStatic 91 | external fun testBlock(@SwiftBlock block: FloatBlock): Boolean 92 | 93 | @JvmStatic 94 | external fun testOptionalBlock(@SwiftBlock block: OptionalFloatBlock): Boolean 95 | } 96 | 97 | @Native 98 | var nativePointer: Long = 0 99 | 100 | external fun release() 101 | 102 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/Int16Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | enum class Int16Enum(val rawValue: Short) { 8 | 9 | ONE(0), TWO(1), THREE(2); 10 | 11 | companion object { 12 | 13 | private val values = HashMap() 14 | 15 | @JvmStatic 16 | fun valueOf(rawValue: Short): Int16Enum { 17 | return values[rawValue]!! 18 | } 19 | 20 | init { 21 | enumValues().forEach { 22 | values[it.rawValue] = it 23 | } 24 | } 25 | } 26 | 27 | } 28 | 29 | @SwiftValue 30 | data class Int16OptionsSet(val rawValue: Short = 0) { 31 | companion object { 32 | @JvmStatic 33 | val one = Int16OptionsSet(1) 34 | @JvmStatic 35 | val two = Int16OptionsSet(2) 36 | @JvmStatic 37 | val three = Int16OptionsSet(4) 38 | } 39 | } 40 | 41 | @SwiftValue 42 | data class Int16TestStruct(var zero: Short = 0, 43 | var max: Short = Short.MAX_VALUE, 44 | var min: Short = Short.MIN_VALUE, 45 | var optional: Short? = 0, 46 | var optionalNil: Short? = null) 47 | 48 | @SwiftReference 49 | class Int16Test private constructor() { 50 | 51 | @SwiftDelegate(protocols = ["Int16TestParamProtocol"]) 52 | interface Int16ParamProtocol { 53 | @SwiftCallbackFunc 54 | fun testParam(param: Short): Boolean 55 | } 56 | 57 | @SwiftDelegate(protocols = ["Int16TestReturnTypeProtocol"]) 58 | interface Int16ReturnTypeProtocol { 59 | @SwiftCallbackFunc 60 | fun testReturnType(): Short 61 | } 62 | 63 | @SwiftDelegate(protocols = ["Int16TestOptionalParamProtocol"]) 64 | interface Int16OptionalParamProtocol { 65 | @SwiftCallbackFunc 66 | fun testOptionalParam(param: Short?): Boolean 67 | } 68 | 69 | @SwiftDelegate(protocols = ["Int16TestOptionalReturnTypeProtocol"]) 70 | interface Int16OptionalReturnTypeProtocol { 71 | @SwiftCallbackFunc 72 | fun testOptionalReturnType(): Short? 73 | } 74 | 75 | @SwiftBlock("(Int16) -> Int16") 76 | interface Int16Block { 77 | fun call(value: Short): Short 78 | } 79 | 80 | @SwiftBlock("(Int16?) -> Int16?") 81 | interface OptionalInt16Block { 82 | fun call(value: Short?): Short? 83 | } 84 | 85 | companion object { 86 | @JvmStatic 87 | external fun testZero(): Short 88 | 89 | @JvmStatic 90 | external fun testMin(): Short 91 | 92 | @JvmStatic 93 | external fun testMax(): Short 94 | 95 | @JvmStatic 96 | external fun testParam(param: Short): Boolean 97 | 98 | @JvmStatic 99 | external fun testReturnType(): Short 100 | 101 | @JvmStatic 102 | external fun testOptionalParam(param: Short?): Boolean 103 | 104 | @JvmStatic 105 | external fun testOptionalReturnType(): Short? 106 | 107 | @JvmStatic 108 | external fun testProtocolParam(callback: Int16ParamProtocol): Boolean 109 | 110 | @JvmStatic 111 | external fun testProtocolReturnType(callback: Int16ReturnTypeProtocol): Short 112 | 113 | @JvmStatic 114 | external fun testProtocolOptionalParam(callback: Int16OptionalParamProtocol): Boolean 115 | 116 | @JvmStatic 117 | external fun testProtocolOptionalReturnType(callback: Int16OptionalReturnTypeProtocol): Short? 118 | 119 | @JvmStatic 120 | external fun testEncode(): Int16TestStruct 121 | 122 | @JvmStatic 123 | external fun testDecode(value: Int16TestStruct): Boolean 124 | 125 | @JvmStatic 126 | external fun testEnumEncode(rawValue: Short) : Int16Enum 127 | 128 | @JvmStatic 129 | external fun testEnumDecode(enum: Int16Enum) : Short 130 | 131 | @JvmStatic 132 | external fun testOptionSetEncode(rawValue: Short) : Int16OptionsSet 133 | 134 | @JvmStatic 135 | external fun testOptionSetDecode(enum: Int16OptionsSet) : Short 136 | 137 | @JvmStatic 138 | external fun testBlock(@SwiftBlock block: Int16Block): Boolean 139 | 140 | @JvmStatic 141 | external fun testOptionalBlock(@SwiftBlock block: OptionalInt16Block): Boolean 142 | } 143 | 144 | @Native 145 | var nativePointer: Long = 0 146 | 147 | external fun release() 148 | 149 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/Int32Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftReference 4 | import com.readdle.codegen.anotation.SwiftValue 5 | import java.lang.annotation.Native 6 | 7 | @SwiftValue 8 | enum class Int32Enum(val rawValue: Int) { 9 | 10 | ONE(0), TWO(1), THREE(2); 11 | 12 | companion object { 13 | 14 | private val values = HashMap() 15 | 16 | @JvmStatic 17 | fun valueOf(rawValue: Int): Int32Enum { 18 | return values[rawValue]!! 19 | } 20 | 21 | init { 22 | enumValues().forEach { 23 | values[it.rawValue] = it 24 | } 25 | } 26 | } 27 | 28 | } 29 | 30 | @SwiftValue 31 | data class Int32OptionsSet(val rawValue: Int = 0) { 32 | companion object { 33 | @JvmStatic 34 | val one = Int32OptionsSet(1) 35 | @JvmStatic 36 | val two = Int32OptionsSet(2) 37 | @JvmStatic 38 | val three = Int32OptionsSet(4) 39 | } 40 | } 41 | 42 | @SwiftValue 43 | data class Int32TestStruct(var zero: Int = 0, 44 | var max: Int = Int.MAX_VALUE, 45 | var min: Int = Int.MIN_VALUE, 46 | var optional: Int? = 0, 47 | var optionalNil: Int? = null) 48 | 49 | @SwiftReference 50 | class Int32Test private constructor() { 51 | 52 | companion object { 53 | 54 | @JvmStatic 55 | external fun testEncode(): Int32TestStruct 56 | 57 | @JvmStatic 58 | external fun testDecode(value: Int32TestStruct): Boolean 59 | 60 | @JvmStatic 61 | external fun testEnumEncode(rawValue: Int) : Int32Enum 62 | 63 | @JvmStatic 64 | external fun testEnumDecode(enum: Int32Enum) : Int 65 | 66 | @JvmStatic 67 | external fun testOptionSetEncode(rawValue: Int) : Int32OptionsSet 68 | 69 | @JvmStatic 70 | external fun testOptionSetDecode(enum: Int32OptionsSet) : Int 71 | } 72 | 73 | @Native 74 | var nativePointer: Long = 0 75 | 76 | external fun release() 77 | 78 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/Int64Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | enum class Int64Enum(val rawValue: Long) { 8 | 9 | ONE(0), TWO(1), THREE(2); 10 | 11 | companion object { 12 | 13 | private val values = HashMap() 14 | 15 | @JvmStatic 16 | fun valueOf(rawValue: Long): Int64Enum { 17 | return values[rawValue]!! 18 | } 19 | 20 | init { 21 | enumValues().forEach { 22 | values[it.rawValue] = it 23 | } 24 | } 25 | } 26 | 27 | } 28 | 29 | @SwiftValue 30 | data class Int64OptionsSet(val rawValue: Long = 0) { 31 | companion object { 32 | @JvmStatic 33 | val one = Int64OptionsSet(1) 34 | @JvmStatic 35 | val two = Int64OptionsSet(2) 36 | @JvmStatic 37 | val three = Int64OptionsSet(4) 38 | } 39 | } 40 | 41 | @SwiftValue 42 | data class Int64TestStruct(var zero: Long = 0, 43 | var max: Long = Long.MAX_VALUE, 44 | var min: Long = Long.MIN_VALUE, 45 | var optional: Long? = 0, 46 | var optionalNil: Long? = null) 47 | 48 | @SwiftReference 49 | class Int64Test private constructor() { 50 | 51 | @SwiftDelegate(protocols = ["Int64TestParamProtocol"]) 52 | interface Int64ParamProtocol { 53 | @SwiftCallbackFunc 54 | fun testParam(param: Long): Boolean 55 | } 56 | 57 | @SwiftDelegate(protocols = ["Int64TestReturnTypeProtocol"]) 58 | interface Int64ReturnTypeProtocol { 59 | @SwiftCallbackFunc 60 | fun testReturnType(): Long 61 | } 62 | 63 | @SwiftDelegate(protocols = ["Int64TestOptionalParamProtocol"]) 64 | interface Int64OptionalParamProtocol { 65 | @SwiftCallbackFunc 66 | fun testOptionalParam(param: Long?): Boolean 67 | } 68 | 69 | @SwiftDelegate(protocols = ["Int64TestOptionalReturnTypeProtocol"]) 70 | interface Int64OptionalReturnTypeProtocol { 71 | @SwiftCallbackFunc 72 | fun testOptionalReturnType(): Long? 73 | } 74 | 75 | @SwiftBlock("(Int64) -> Int64") 76 | interface Int64Block { 77 | fun call(value: Long): Long 78 | } 79 | 80 | @SwiftBlock("(Int64?) -> Int64?") 81 | interface OptionalInt64Block { 82 | fun call(value: Long?): Long? 83 | } 84 | 85 | companion object { 86 | @JvmStatic 87 | external fun testZero(): Long 88 | 89 | @JvmStatic 90 | external fun testMin(): Long 91 | 92 | @JvmStatic 93 | external fun testMax(): Long 94 | 95 | @JvmStatic 96 | external fun testParam(param: Long): Boolean 97 | 98 | @JvmStatic 99 | external fun testReturnType(): Long 100 | 101 | @JvmStatic 102 | external fun testOptionalParam(param: Long?): Boolean 103 | 104 | @JvmStatic 105 | external fun testOptionalReturnType(): Long? 106 | 107 | @JvmStatic 108 | external fun testProtocolParam(callback: Int64ParamProtocol): Boolean 109 | 110 | @JvmStatic 111 | external fun testProtocolReturnType(callback: Int64ReturnTypeProtocol): Long 112 | 113 | @JvmStatic 114 | external fun testProtocolOptionalParam(callback: Int64OptionalParamProtocol): Boolean 115 | 116 | @JvmStatic 117 | external fun testProtocolOptionalReturnType(callback: Int64OptionalReturnTypeProtocol): Long? 118 | 119 | @JvmStatic 120 | external fun testEncode(): Int64TestStruct 121 | 122 | @JvmStatic 123 | external fun testDecode(value: Int64TestStruct): Boolean 124 | 125 | @JvmStatic 126 | external fun testEnumEncode(rawValue: Long) : Int64Enum 127 | 128 | @JvmStatic 129 | external fun testEnumDecode(enum: Int64Enum) : Long 130 | 131 | @JvmStatic 132 | external fun testOptionSetEncode(rawValue: Long) : Int64OptionsSet 133 | 134 | @JvmStatic 135 | external fun testOptionSetDecode(enum: Int64OptionsSet) : Long 136 | 137 | @JvmStatic 138 | external fun testBlock(@SwiftBlock block: Int64Block): Boolean 139 | 140 | @JvmStatic 141 | external fun testOptionalBlock(@SwiftBlock block: OptionalInt64Block): Boolean 142 | } 143 | 144 | @Native 145 | var nativePointer: Long = 0 146 | 147 | external fun release() 148 | 149 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/Int8Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | enum class Int8Enum(val rawValue: Byte) { 8 | 9 | ONE(0), TWO(1), THREE(2); 10 | 11 | companion object { 12 | 13 | private val values = HashMap() 14 | 15 | @JvmStatic 16 | fun valueOf(rawValue: Byte): Int8Enum { 17 | return values[rawValue]!! 18 | } 19 | 20 | init { 21 | enumValues().forEach { 22 | values[it.rawValue] = it 23 | } 24 | } 25 | } 26 | 27 | } 28 | 29 | @SwiftValue 30 | data class Int8OptionsSet(val rawValue: Byte = 0) { 31 | companion object { 32 | @JvmStatic 33 | val one = Int8OptionsSet(1) 34 | @JvmStatic 35 | val two = Int8OptionsSet(2) 36 | @JvmStatic 37 | val three = Int8OptionsSet(4) 38 | } 39 | } 40 | 41 | @SwiftValue 42 | data class Int8TestStruct(var zero: Byte = 0, 43 | var max: Byte = Byte.MAX_VALUE, 44 | var min: Byte = Byte.MIN_VALUE, 45 | var optional: Byte? = 0, 46 | var optionalNil: Byte? = null) 47 | 48 | @SwiftReference 49 | class Int8Test private constructor() { 50 | 51 | @SwiftDelegate(protocols = ["Int8TestParamProtocol"]) 52 | interface Int8ParamProtocol { 53 | @SwiftCallbackFunc 54 | fun testParam(param: Byte): Boolean 55 | } 56 | 57 | @SwiftDelegate(protocols = ["Int8TestReturnTypeProtocol"]) 58 | interface Int8ReturnTypeProtocol { 59 | @SwiftCallbackFunc 60 | fun testReturnType(): Byte 61 | } 62 | 63 | @SwiftDelegate(protocols = ["Int8TestOptionalParamProtocol"]) 64 | interface Int8OptionalParamProtocol { 65 | @SwiftCallbackFunc 66 | fun testOptionalParam(param: Byte?): Boolean 67 | } 68 | 69 | @SwiftDelegate(protocols = ["Int8TestOptionalReturnTypeProtocol"]) 70 | interface Int8OptionalReturnTypeProtocol { 71 | @SwiftCallbackFunc 72 | fun testOptionalReturnType(): Byte? 73 | } 74 | 75 | @SwiftBlock("(Int8) -> Int8") 76 | interface Int8Block { 77 | fun call(value: Byte): Byte 78 | } 79 | 80 | @SwiftBlock("(Int8?) -> Int8?") 81 | interface OptionalInt8Block { 82 | fun call(value: Byte?): Byte? 83 | } 84 | 85 | companion object { 86 | @JvmStatic 87 | external fun testZero(): Byte 88 | 89 | @JvmStatic 90 | external fun testMin(): Byte 91 | 92 | @JvmStatic 93 | external fun testMax(): Byte 94 | 95 | @JvmStatic 96 | external fun testParam(param: Byte): Boolean 97 | 98 | @JvmStatic 99 | external fun testReturnType(): Byte 100 | 101 | @JvmStatic 102 | external fun testOptionalParam(param: Byte?): Boolean 103 | 104 | @JvmStatic 105 | external fun testOptionalReturnType(): Byte? 106 | 107 | @JvmStatic 108 | external fun testProtocolParam(callback: Int8ParamProtocol): Boolean 109 | 110 | @JvmStatic 111 | external fun testProtocolReturnType(callback: Int8ReturnTypeProtocol): Byte 112 | 113 | @JvmStatic 114 | external fun testProtocolOptionalParam(callback: Int8OptionalParamProtocol): Boolean 115 | 116 | @JvmStatic 117 | external fun testProtocolOptionalReturnType(callback: Int8OptionalReturnTypeProtocol): Byte? 118 | 119 | @JvmStatic 120 | external fun testEncode(): Int8TestStruct 121 | 122 | @JvmStatic 123 | external fun testDecode(value: Int8TestStruct): Boolean 124 | 125 | @JvmStatic 126 | external fun testEnumEncode(rawValue: Byte) : Int8Enum 127 | 128 | @JvmStatic 129 | external fun testEnumDecode(enum: Int8Enum) : Byte 130 | 131 | @JvmStatic 132 | external fun testOptionSetEncode(rawValue: Byte) : Int8OptionsSet 133 | 134 | @JvmStatic 135 | external fun testOptionSetDecode(enum: Int8OptionsSet) : Byte 136 | 137 | @JvmStatic 138 | external fun testBlock(@SwiftBlock block: Int8Block): Boolean 139 | 140 | @JvmStatic 141 | external fun testOptionalBlock(@SwiftBlock block: OptionalInt8Block): Boolean 142 | } 143 | 144 | @Native 145 | var nativePointer: Long = 0 146 | 147 | external fun release() 148 | 149 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/IntTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | enum class IntEnum(val rawValue: Int) { 8 | 9 | ONE(0), TWO(1), THREE(2); 10 | 11 | companion object { 12 | 13 | private val values = HashMap() 14 | 15 | @JvmStatic 16 | fun valueOf(rawValue: Int): IntEnum { 17 | return values[rawValue]!! 18 | } 19 | 20 | init { 21 | enumValues().forEach { 22 | values[it.rawValue] = it 23 | } 24 | } 25 | } 26 | 27 | } 28 | 29 | @SwiftValue 30 | data class IntOptionsSet(val rawValue: Int = 0) { 31 | companion object { 32 | @JvmStatic 33 | val one = IntOptionsSet(1) 34 | @JvmStatic 35 | val two = IntOptionsSet(2) 36 | @JvmStatic 37 | val three = IntOptionsSet(4) 38 | } 39 | } 40 | 41 | @SwiftValue 42 | data class IntTestStruct(var zero: Int = 0, 43 | var max: Int = Int.MAX_VALUE, 44 | var min: Int = Int.MIN_VALUE, 45 | var optional: Int? = 0, 46 | var optionalNil: Int? = null) 47 | 48 | @SwiftReference 49 | class IntTest private constructor() { 50 | 51 | @SwiftDelegate(protocols = ["IntTestParamProtocol"]) 52 | interface IntParamProtocol { 53 | @SwiftCallbackFunc 54 | fun testParam(param: Int): Boolean 55 | } 56 | 57 | @SwiftDelegate(protocols = ["IntTestReturnTypeProtocol"]) 58 | interface IntReturnTypeProtocol { 59 | @SwiftCallbackFunc 60 | fun testReturnType(): Int 61 | } 62 | 63 | @SwiftDelegate(protocols = ["IntTestOptionalParamProtocol"]) 64 | interface IntOptionalParamProtocol { 65 | @SwiftCallbackFunc 66 | fun testOptionalParam(param: Int?): Boolean 67 | } 68 | 69 | @SwiftDelegate(protocols = ["IntTestOptionalReturnTypeProtocol"]) 70 | interface IntOptionalReturnTypeProtocol { 71 | @SwiftCallbackFunc 72 | fun testOptionalReturnType(): Int? 73 | } 74 | 75 | @SwiftBlock("(Int) -> Int") 76 | interface IntBlock { 77 | fun call(value: Int): Int 78 | } 79 | 80 | @SwiftBlock("(Int?) -> Int?") 81 | interface OptionalIntBlock { 82 | fun call(value: Int?): Int? 83 | } 84 | 85 | companion object { 86 | @JvmStatic 87 | external fun testZero(): Int 88 | 89 | @JvmStatic 90 | external fun testMin(): Int 91 | 92 | @JvmStatic 93 | external fun testMax(): Int 94 | 95 | @JvmStatic 96 | external fun testParam(param: Int): Boolean 97 | 98 | @JvmStatic 99 | external fun testReturnType(): Int 100 | 101 | @JvmStatic 102 | external fun testOptionalParam(param: Int?): Boolean 103 | 104 | @JvmStatic 105 | external fun testOptionalReturnType(): Int? 106 | 107 | @JvmStatic 108 | external fun testProtocolParam(callback: IntParamProtocol): Boolean 109 | 110 | @JvmStatic 111 | external fun testProtocolReturnType(callback: IntReturnTypeProtocol): Int 112 | 113 | @JvmStatic 114 | external fun testProtocolOptionalParam(callback: IntOptionalParamProtocol): Boolean 115 | 116 | @JvmStatic 117 | external fun testProtocolOptionalReturnType(callback: IntOptionalReturnTypeProtocol): Int? 118 | 119 | @JvmStatic 120 | external fun testEncode(): IntTestStruct 121 | 122 | @JvmStatic 123 | external fun testDecode(value: IntTestStruct): Boolean 124 | 125 | @JvmStatic 126 | external fun testEnumEncode(rawValue: Int) : IntEnum 127 | 128 | @JvmStatic 129 | external fun testEnumDecode(enum: IntEnum) : Int 130 | 131 | @JvmStatic 132 | external fun testOptionSetEncode(rawValue: Int) : IntOptionsSet 133 | 134 | @JvmStatic 135 | external fun testOptionSetDecode(enum: IntOptionsSet) : Int 136 | 137 | @JvmStatic 138 | external fun testBlock(@SwiftBlock block: IntBlock): Boolean 139 | 140 | @JvmStatic 141 | external fun testOptionalBlock(@SwiftBlock block: OptionalIntBlock): Boolean 142 | } 143 | 144 | @Native 145 | var nativePointer: Long = 0 146 | 147 | external fun release() 148 | 149 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/Issue31Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftFunc 4 | import com.readdle.codegen.anotation.SwiftGetter 5 | import com.readdle.codegen.anotation.SwiftReference 6 | import com.readdle.codegen.anotation.SwiftValue 7 | 8 | @SwiftValue 9 | data class Issue31TestProgress( 10 | var elapsed: Int = 0, 11 | var total: Int = 1 12 | ) { 13 | @get:SwiftGetter 14 | val percentage: Double external get 15 | 16 | @SwiftFunc 17 | external fun calculatePercentage(): Double 18 | } 19 | 20 | @SwiftReference 21 | class Issue31ReferenceTestProgress private constructor() { 22 | // Swift JNI private native pointer 23 | private val nativePointer = 0L 24 | 25 | // Swift JNI release method 26 | external fun release() 27 | 28 | @get:SwiftGetter 29 | val percentage: Double external get 30 | 31 | @SwiftFunc 32 | external fun calculatePercentage(): Double 33 | 34 | companion object { 35 | @JvmStatic 36 | @SwiftFunc("init(elapsed:total:)") 37 | external fun init(elapsed: Int, total: Int): Issue31ReferenceTestProgress 38 | } 39 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/SampleDelegateAndroid.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftCallbackFunc 4 | import com.readdle.codegen.anotation.SwiftDelegate 5 | import android.util.Log 6 | 7 | import java.nio.ByteBuffer 8 | 9 | @SwiftDelegate(protocols = ["SampleDelegate"]) 10 | abstract class SampleDelegateAndroid { 11 | 12 | // Swift JNI private native pointer 13 | private val nativePointer = 0L 14 | 15 | internal var sampleValue: SampleValue? = null 16 | 17 | // Swift JNI init method 18 | external fun init() 19 | 20 | // Swift JNI release method 21 | external fun release() 22 | 23 | init { 24 | init() 25 | } 26 | 27 | @SwiftCallbackFunc("setSampleValue(value:)") 28 | fun setSampleValue(value: SampleValue?) { 29 | sampleValue = value 30 | onSetSampleValue(value) 31 | if (value != null) { 32 | } 33 | } 34 | 35 | @SwiftCallbackFunc 36 | fun getSampleValue(): SampleValue { 37 | return sampleValue!! 38 | } 39 | 40 | @SwiftCallbackFunc 41 | fun funcWithNil(): SampleValue? { 42 | return null 43 | } 44 | 45 | @SwiftCallbackFunc 46 | @Throws(Exception::class) 47 | fun throwableFunc(flag: Boolean) { 48 | require(!flag) { "Exception" } 49 | } 50 | 51 | @SwiftCallbackFunc 52 | @Throws(Exception::class) 53 | fun throwableFuncWithReturnType(flag: Boolean): String { 54 | return if (flag) { 55 | throw IllegalArgumentException("Exception") 56 | } else { 57 | "throwableFuncWithReturnType" 58 | } 59 | } 60 | 61 | @SwiftCallbackFunc 62 | fun funcWithData(): ByteBuffer { 63 | val tenBytes = ByteArray(10) 64 | return ByteBuffer.wrap(tenBytes) 65 | } 66 | 67 | abstract fun onSetSampleValue(value: SampleValue?) 68 | 69 | companion object { 70 | 71 | @JvmStatic 72 | var timestamp: Long 73 | @SwiftCallbackFunc 74 | get() = System.currentTimeMillis() 75 | @SwiftCallbackFunc 76 | set(value) { 77 | Log.i("TAG", value.toString()) 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/SampleEnumWithValue.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftFunc 4 | import com.readdle.codegen.anotation.SwiftValue 5 | 6 | @SwiftValue 7 | sealed class SampleEnumWithValue { 8 | 9 | object None : SampleEnumWithValue() 10 | data class StringValue(val value: String) : SampleEnumWithValue() 11 | data class IntegerValue(val value: Int) : SampleEnumWithValue() 12 | data class Int8Value(val value: Byte) : SampleEnumWithValue() 13 | data class Int16Value(val value: Short) : SampleEnumWithValue() 14 | data class Int32Value(val value: Int) : SampleEnumWithValue() 15 | data class Int64Value(val value: Long) : SampleEnumWithValue() 16 | data class UintValue(val value: UInt) : SampleEnumWithValue() 17 | data class Uint8Value(val value: UByte) : SampleEnumWithValue() 18 | data class Uint16Value(val value: UShort) : SampleEnumWithValue() 19 | data class Uint32Value(val value: UInt) : SampleEnumWithValue() 20 | data class Uint64Value(val value: ULong) : SampleEnumWithValue() 21 | data class ObjectArrayValue(val value: ArrayList) : SampleEnumWithValue() 22 | data class StringArrayValue(val value: ArrayList) : SampleEnumWithValue() 23 | data class NumberArrayValue(val value: ArrayList) : SampleEnumWithValue() 24 | data class ArrayInArrayValue(val value: ArrayList>) : SampleEnumWithValue() 25 | data class DictInArrayValue(val value: ArrayList>) : SampleEnumWithValue() 26 | data class DictSampleClassValue(val value: HashMap) : SampleEnumWithValue() 27 | data class DictStringsValue(val value: HashMap) : SampleEnumWithValue() 28 | data class DictNumbersValue(val value: HashMap) : SampleEnumWithValue() 29 | data class Dict64NumbersValue(val value: HashMap) : SampleEnumWithValue() 30 | data class DictInDictValue(val value: HashMap>) : SampleEnumWithValue() 31 | data class ArrayInDictValue(val value: HashMap>) : SampleEnumWithValue() 32 | data class SetValue(val value: HashSet) : SampleEnumWithValue() 33 | data class SetValuesValue(val value: HashSet) : SampleEnumWithValue() 34 | 35 | companion object { 36 | 37 | @JvmStatic 38 | @SwiftFunc("copy(value:)") 39 | external fun copy(value: SampleEnumWithValue): SampleEnumWithValue 40 | } 41 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/SampleReference.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import com.readdle.swiftjava.sample.asbtracthierarhy.* 5 | 6 | @SwiftReference 7 | class SampleReference private constructor() { 8 | 9 | @SwiftReference 10 | class SampleReferenceEnclose private constructor() { 11 | 12 | // Swift JNI private native pointer 13 | private val nativePointer = 0L 14 | 15 | // Swift JNI release method 16 | external fun release() 17 | 18 | companion object { 19 | @JvmStatic 20 | external fun init(): SampleReferenceEnclose 21 | } 22 | } 23 | 24 | @SwiftDelegate(protocols = ["SampleBlockDelegate"]) 25 | interface SampleInterfaceDelegateAndroid { 26 | @SwiftCallbackFunc 27 | fun onCall(pr1: Int, pr2: Int, pr3: Double, pr4: Double) 28 | } 29 | 30 | // Swift JNI private native pointer 31 | private val nativePointer = 0L 32 | 33 | // Swift JNI release method 34 | external fun release() 35 | 36 | val randomValue: SampleValue 37 | external get 38 | 39 | external fun saveValue(value: SampleValue) 40 | 41 | @Throws(SwiftError::class) 42 | external fun funcThrows() 43 | 44 | external fun funcWithNil(): SampleReference? 45 | 46 | // TODO: Impossible to generate for now. Add extra check for JavaSwift protocol before casting to .javaObject() 47 | //@Nullable @SwiftFunc 48 | //public native SampleDelegateAndroid getDelegate(); 49 | @SwiftSetter 50 | external fun setDelegate(delegate: SampleDelegateAndroid) 51 | 52 | external fun tick(): Long 53 | 54 | external fun tickWithBlock(delegate: SampleInterfaceDelegateAndroid) 55 | 56 | external fun floatCheck(var1: Float): Float 57 | 58 | external fun doubleCheck(var1: Double): Double 59 | 60 | external fun exceptionCheck(var1: Exception): Exception 61 | 62 | external fun enclose(var1: SampleReferenceEnclose): SampleReferenceEnclose 63 | 64 | @get:SwiftGetter 65 | @set:SwiftSetter 66 | var string: String 67 | external get 68 | external set 69 | 70 | @SwiftBlock("(Error?, String?) -> String?") 71 | interface CompletionBlock { 72 | fun call(error: Exception?, string: String?): String? 73 | } 74 | 75 | @SwiftFunc("funcWithBlock(completion:)") 76 | external fun funcWithBlock(@SwiftBlock block: CompletionBlock?): String? 77 | 78 | val abstractTypeList: List 79 | external get 80 | 81 | @get:SwiftFunc("getAbstractType()") 82 | val abstractType: AbstractType 83 | external get 84 | 85 | val firstChild: FirstChild 86 | external get 87 | 88 | val secondChild: SecondChild 89 | external get 90 | 91 | val thirdChild: ThirdChild 92 | external get 93 | 94 | val fourthChild: FourthChild 95 | external get 96 | 97 | @Throws(Exception::class) 98 | external fun throwableFunc(delegate: SampleDelegateAndroid, flag: Boolean) 99 | 100 | @Throws(Exception::class) 101 | external fun throwableFuncWithReturnType(delegate: SampleDelegateAndroid, flag: Boolean): String 102 | 103 | val randomCustomSampleValue: CustomSampleValue 104 | external get 105 | 106 | external fun saveCustomSampleValue(value: CustomSampleValue) 107 | 108 | external fun oneMoreReferenceTableOverflow(delegate: SampleDelegateAndroid) 109 | 110 | companion object { 111 | 112 | @JvmStatic 113 | external fun init(): SampleReference 114 | 115 | @JvmStatic @SwiftGetter("staticString") 116 | external fun getStaticString(): String 117 | 118 | @JvmStatic @SwiftSetter("staticString") 119 | external fun setStaticString(value: String) 120 | 121 | } 122 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/SampleValue.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftError 4 | import com.readdle.codegen.anotation.SwiftFunc 5 | import com.readdle.codegen.anotation.SwiftValue 6 | import java.math.BigInteger 7 | import java.util.* 8 | import kotlin.collections.ArrayList 9 | import kotlin.collections.HashMap 10 | import kotlin.collections.HashSet 11 | 12 | @SwiftValue 13 | open class SampleValue protected constructor() { 14 | 15 | @JvmField 16 | var string: String = "" 17 | 18 | var integer: Int = 0 19 | var int8: Byte = 0 20 | var int16: Short = 0 21 | var int32: Int = 0 22 | var int64: Long = 0 23 | 24 | var uint: UInt = 0U 25 | var uint8: UByte = 0U 26 | var uint16: UShort = 0U 27 | var uint32: UInt = 0U 28 | var uint64: ULong = 0U 29 | 30 | var optionalInteger: Int? = 0 31 | var optionalInt8: Byte? = 0 32 | var optionalInt16: Short? = 0 33 | var optionalInt32: Int? = 0 34 | var optionalInt64: Long? = 0 35 | 36 | var optionalUint: UInt? = 0U 37 | var optionalUint8: UByte? = 0U 38 | var optionalUint16: UShort? = 0U 39 | var optionalUint32: UInt? = 0U 40 | var optionalUint64: ULong? = 0U 41 | 42 | var objectArray: ArrayList = ArrayList() 43 | var stringArray: ArrayList = ArrayList() 44 | var numberArray: ArrayList = ArrayList() 45 | var arrayInArray: ArrayList> = ArrayList() 46 | var dictInArray: ArrayList> = ArrayList() 47 | var dictSampleClass: HashMap = HashMap() 48 | var dictStrings: HashMap = HashMap() 49 | var dictNumbers: HashMap = HashMap() 50 | var dict64Numbers: HashMap = HashMap() 51 | var dictInDict: HashMap> = HashMap() 52 | var arrayInDict: HashMap> = HashMap() 53 | var set: HashSet = HashSet() 54 | var setValues: HashSet = HashSet() 55 | 56 | external fun copy(): SampleValue 57 | 58 | external fun saveValue() 59 | 60 | @SwiftFunc("isSame(other:)") 61 | external fun isSame(other: SampleValue): Boolean 62 | 63 | override fun equals(o: Any?): Boolean { 64 | if (this === o) return true 65 | if (o !is SampleValue) return false 66 | return string == o.string 67 | } 68 | 69 | override fun hashCode(): Int { 70 | return Objects.hash(string) 71 | } 72 | 73 | override fun toString(): String { 74 | return "SampleValue(string='$string', " + 75 | "integer=$integer," + 76 | " int8=$int8, " + 77 | "int16=$int16, " + 78 | "int32=$int32, " + 79 | "int64=$int64, " + 80 | "uint=$uint, " + 81 | "uint8=$uint8, " + 82 | "uint16=$uint16, " + 83 | "uint32=$uint32, " + 84 | "uint64=$uint64, " + 85 | "optionalInteger=$optionalInteger, " + 86 | "optionalInt8=$optionalInt8, " + 87 | "optionalInt16=$optionalInt16, " + 88 | "optionalInt32=$optionalInt32, " + 89 | "optionalInt64=$optionalInt64, " + 90 | "optionalUint=$optionalUint, " + 91 | "optionalUint8=$optionalUint8, " + 92 | "optionalUint16=$optionalUint16, " + 93 | "optionalUint32=$optionalUint32, " + 94 | "optionalUint64=$optionalUint64, " + 95 | "objectArray=$objectArray, " + 96 | "stringArray=$stringArray, " + 97 | "numberArray=$numberArray, " + 98 | "arrayInArray=$arrayInArray, " + 99 | "dictInArray=$dictInArray, " + 100 | "dictSampleClass=$dictSampleClass, " + 101 | "dictStrings=$dictStrings, " + 102 | "dictNumbers=$dictNumbers, " + 103 | "dict64Numbers=$dict64Numbers, " + 104 | "dictInDict=$dictInDict, " + 105 | "arrayInDict=$arrayInDict, " + 106 | "set=$set, " + 107 | "setValues=$setValues)" 108 | } 109 | 110 | 111 | companion object { 112 | 113 | @JvmStatic 114 | external fun getRandomValue(): SampleValue 115 | 116 | @JvmStatic 117 | @Throws(SwiftError::class) 118 | external fun funcThrows() 119 | } 120 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/StringTests.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | @SwiftValue 7 | enum class StringEnum(val rawValue: String) { 8 | 9 | ONE("ONE"), TWO("TWO"), THREE("THREE"); 10 | 11 | } 12 | 13 | @SwiftValue 14 | data class StringTestStruct(var zero: String = "", 15 | var optional: String? = "42", 16 | var optionalNil: String? = null) 17 | 18 | @SwiftReference 19 | class StringTest private constructor() { 20 | 21 | @SwiftDelegate(protocols = ["StringTestParamProtocol"]) 22 | interface StringParamProtocol { 23 | @SwiftCallbackFunc 24 | fun testParam(param: String): Boolean 25 | } 26 | 27 | @SwiftDelegate(protocols = ["StringTestReturnTypeProtocol"]) 28 | interface StringReturnTypeProtocol { 29 | @SwiftCallbackFunc 30 | fun testReturnType(): String 31 | } 32 | 33 | @SwiftDelegate(protocols = ["StringTestOptionalParamProtocol"]) 34 | interface StringOptionalParamProtocol { 35 | @SwiftCallbackFunc 36 | fun testOptionalParam(param: String?): Boolean 37 | } 38 | 39 | @SwiftDelegate(protocols = ["StringTestOptionalReturnTypeProtocol"]) 40 | interface StringOptionalReturnTypeProtocol { 41 | @SwiftCallbackFunc 42 | fun testOptionalReturnType(): String? 43 | } 44 | 45 | @SwiftBlock("(String) -> String") 46 | interface StringBlock { 47 | fun call(value: String): String 48 | } 49 | 50 | @SwiftBlock("(String?) -> String?") 51 | interface OptionalStringBlock { 52 | fun call(value: String?): String? 53 | } 54 | 55 | companion object { 56 | @JvmStatic 57 | external fun testZero(): String 58 | 59 | @JvmStatic 60 | external fun testParam(param: String): Boolean 61 | 62 | @JvmStatic 63 | external fun testReturnType(): String 64 | 65 | @JvmStatic 66 | external fun testOptionalParam(param: String?): Boolean 67 | 68 | @JvmStatic 69 | external fun testOptionalReturnType(): String? 70 | 71 | @JvmStatic 72 | external fun testProtocolParam(callback: StringParamProtocol): Boolean 73 | 74 | @JvmStatic 75 | external fun testProtocolReturnType(callback: StringReturnTypeProtocol): String 76 | 77 | @JvmStatic 78 | external fun testProtocolOptionalParam(callback: StringOptionalParamProtocol): Boolean 79 | 80 | @JvmStatic 81 | external fun testProtocolOptionalReturnType(callback: StringOptionalReturnTypeProtocol): String? 82 | 83 | @JvmStatic 84 | external fun testEncode(): StringTestStruct 85 | 86 | @JvmStatic 87 | external fun testDecode(value: StringTestStruct): Boolean 88 | 89 | @JvmStatic 90 | external fun testEnumEncode(rawValue: String) : StringEnum 91 | 92 | @JvmStatic 93 | external fun testEnumDecode(enum: StringEnum) : String 94 | 95 | @JvmStatic 96 | external fun testBlock(@SwiftBlock block: StringBlock): Boolean 97 | 98 | @JvmStatic 99 | external fun testOptionalBlock(@SwiftBlock block: OptionalStringBlock): Boolean 100 | } 101 | 102 | @Native 103 | var nativePointer: Long = 0 104 | 105 | external fun release() 106 | 107 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/SwiftEnvironment.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.SwiftReference 4 | 5 | // Swift JNI private constructor 6 | // Should be private. Don't call this constructor from Java! 7 | @SwiftReference 8 | class SwiftEnvironment private constructor() { 9 | 10 | // Swift JNI private native pointer 11 | private val nativePointer = 0L 12 | 13 | // Swift JNI release method 14 | external fun release() 15 | 16 | companion object { 17 | 18 | @JvmStatic 19 | external fun initEnvironment() 20 | 21 | @JvmStatic 22 | external fun is64BitArch(): Boolean 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/UInt16Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | private const val MIN_VALUE: Short = 0 7 | private const val MAX_VALUE: Short = -1 8 | 9 | @SwiftValue 10 | enum class UInt16Enum(@Unsigned val rawValue: Short) { 11 | 12 | ONE(0), TWO(1), THREE(2); 13 | 14 | companion object { 15 | 16 | private val values = HashMap() 17 | 18 | @JvmStatic 19 | fun valueOf(rawValue: Short): UInt16Enum { 20 | return values[rawValue]!! 21 | } 22 | 23 | init { 24 | enumValues().forEach { 25 | values[it.rawValue] = it 26 | } 27 | } 28 | } 29 | 30 | } 31 | 32 | @SwiftValue 33 | data class UInt16OptionsSet(@Unsigned val rawValue: Short = 0) { 34 | companion object { 35 | @JvmStatic 36 | val one = UInt16OptionsSet(1) 37 | @JvmStatic 38 | val two = UInt16OptionsSet(2) 39 | @JvmStatic 40 | val three = UInt16OptionsSet(4) 41 | } 42 | } 43 | 44 | @SwiftValue 45 | data class UInt16TestStruct(@Unsigned var zero: Short = 0, 46 | @Unsigned var max: Short = MAX_VALUE, 47 | @Unsigned var min: Short = MIN_VALUE, 48 | @Unsigned var optional: Short? = 0, 49 | @Unsigned var optionalNil: Short? = null) 50 | 51 | @SwiftReference 52 | class UInt16Test private constructor() { 53 | 54 | @SwiftDelegate(protocols = ["UInt16TestParamProtocol"]) 55 | interface UInt16ParamProtocol { 56 | @SwiftCallbackFunc 57 | fun testParam(@Unsigned param: Short): Boolean 58 | } 59 | 60 | @SwiftDelegate(protocols = ["UInt16TestReturnTypeProtocol"]) 61 | interface UInt16ReturnTypeProtocol { 62 | @SwiftCallbackFunc @Unsigned 63 | fun testReturnType(): Short 64 | } 65 | 66 | @SwiftDelegate(protocols = ["UInt16TestOptionalParamProtocol"]) 67 | interface UInt16OptionalParamProtocol { 68 | @SwiftCallbackFunc 69 | fun testOptionalParam(@Unsigned param: Short?): Boolean 70 | } 71 | 72 | @SwiftDelegate(protocols = ["UInt16TestOptionalReturnTypeProtocol"]) 73 | interface UInt16OptionalReturnTypeProtocol { 74 | @SwiftCallbackFunc @Unsigned 75 | fun testOptionalReturnType(): Short? 76 | } 77 | 78 | @SwiftBlock("(UInt16) -> UInt16") 79 | interface UInt16Block { 80 | @Unsigned 81 | fun call(@Unsigned value: Short): Short 82 | } 83 | 84 | @SwiftBlock("(UInt16?) -> UInt16?") 85 | interface OptionalUInt16Block { 86 | @Unsigned 87 | fun call(@Unsigned value: Short?): Short? 88 | } 89 | 90 | companion object { 91 | @JvmStatic @Unsigned 92 | external fun testZero(): Short 93 | 94 | @JvmStatic @Unsigned 95 | external fun testMin(): Short 96 | 97 | @JvmStatic @Unsigned 98 | external fun testMax(): Short 99 | 100 | @JvmStatic 101 | external fun testParam(@Unsigned param: Short): Boolean 102 | 103 | @JvmStatic @Unsigned 104 | external fun testReturnType(): Short 105 | 106 | @JvmStatic 107 | external fun testOptionalParam(@Unsigned param: Short?): Boolean 108 | 109 | @JvmStatic @Unsigned 110 | external fun testOptionalReturnType(): Short? 111 | 112 | @JvmStatic 113 | external fun testProtocolParam(callback: UInt16ParamProtocol): Boolean 114 | 115 | @JvmStatic 116 | external fun testProtocolReturnType(callback: UInt16ReturnTypeProtocol): Short 117 | 118 | @JvmStatic 119 | external fun testProtocolOptionalParam(callback: UInt16OptionalParamProtocol): Boolean 120 | 121 | @JvmStatic 122 | external fun testProtocolOptionalReturnType(callback: UInt16OptionalReturnTypeProtocol): Short? 123 | 124 | @JvmStatic 125 | external fun testEncode(): UInt16TestStruct 126 | 127 | @JvmStatic 128 | external fun testDecode(value: UInt16TestStruct): Boolean 129 | 130 | @JvmStatic 131 | external fun testEnumEncode(@Unsigned rawValue: Short) : UInt16Enum 132 | 133 | @JvmStatic @Unsigned 134 | external fun testEnumDecode(enum: UInt16Enum) : Short 135 | 136 | @JvmStatic 137 | external fun testOptionSetEncode(@Unsigned rawValue: Short) : UInt16OptionsSet 138 | 139 | @JvmStatic @Unsigned 140 | external fun testOptionSetDecode(enum: UInt16OptionsSet) : Short 141 | 142 | @JvmStatic 143 | external fun testBlock(@SwiftBlock block: UInt16Block): Boolean 144 | 145 | @JvmStatic 146 | external fun testOptionalBlock(@SwiftBlock block: OptionalUInt16Block): Boolean 147 | } 148 | 149 | @Native 150 | var nativePointer: Long = 0 151 | 152 | external fun release() 153 | 154 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/UInt32Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | private const val MIN_VALUE: Int = 0 7 | private const val MAX_VALUE: Int = -1 8 | 9 | @SwiftValue 10 | enum class UInt32Enum(@Unsigned val rawValue: Int) { 11 | 12 | ONE(0), TWO(1), THREE(2); 13 | 14 | companion object { 15 | 16 | private val values = HashMap() 17 | 18 | @JvmStatic 19 | fun valueOf(rawValue: Int): UInt32Enum { 20 | return values[rawValue]!! 21 | } 22 | 23 | init { 24 | enumValues().forEach { 25 | values[it.rawValue] = it 26 | } 27 | } 28 | } 29 | 30 | } 31 | 32 | @SwiftValue 33 | data class UInt32OptionsSet(@Unsigned val rawValue: Int = 0) { 34 | companion object { 35 | @JvmStatic 36 | val one = UInt32OptionsSet(1) 37 | @JvmStatic 38 | val two = UInt32OptionsSet(2) 39 | @JvmStatic 40 | val three = UInt32OptionsSet(4) 41 | } 42 | } 43 | 44 | @SwiftValue 45 | data class UInt32TestStruct(@Unsigned var zero: Int = 0, 46 | @Unsigned var max: Int = MAX_VALUE, 47 | @Unsigned var min: Int = MIN_VALUE, 48 | @Unsigned var optional: Int? = 0, 49 | @Unsigned var optionalNil: Int? = null) 50 | 51 | @SwiftReference 52 | class UInt32Test private constructor() { 53 | 54 | companion object { 55 | 56 | @JvmStatic 57 | external fun testEncode(): UInt32TestStruct 58 | 59 | @JvmStatic 60 | external fun testDecode(value: UInt32TestStruct): Boolean 61 | 62 | @JvmStatic 63 | external fun testEnumEncode(@Unsigned rawValue: Int) : UInt32Enum 64 | 65 | @JvmStatic @Unsigned 66 | external fun testEnumDecode(enum: UInt32Enum) : Int 67 | 68 | @JvmStatic 69 | external fun testOptionSetEncode(@Unsigned rawValue: Int) : UInt32OptionsSet 70 | 71 | @JvmStatic @Unsigned 72 | external fun testOptionSetDecode(enum: UInt32OptionsSet) : Int 73 | } 74 | 75 | @Native 76 | var nativePointer: Long = 0 77 | 78 | external fun release() 79 | 80 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/UInt64Test.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | private const val MIN_VALUE: Long = 0 7 | private const val MAX_VALUE: Long = -1 8 | 9 | @SwiftValue 10 | enum class UInt64Enum(@Unsigned val rawValue: Long) { 11 | 12 | ONE(0), TWO(1), THREE(2); 13 | 14 | companion object { 15 | 16 | private val values = HashMap() 17 | 18 | @JvmStatic 19 | fun valueOf(rawValue: Long): UInt64Enum { 20 | return values[rawValue]!! 21 | } 22 | 23 | init { 24 | enumValues().forEach { 25 | values[it.rawValue] = it 26 | } 27 | } 28 | } 29 | 30 | } 31 | 32 | @SwiftValue 33 | data class UInt64OptionsSet(@Unsigned val rawValue: Long = 0) { 34 | companion object { 35 | @JvmStatic 36 | val one = UInt64OptionsSet(1) 37 | @JvmStatic 38 | val two = UInt64OptionsSet(2) 39 | @JvmStatic 40 | val three = UInt64OptionsSet(4) 41 | } 42 | } 43 | 44 | @SwiftValue 45 | data class UInt64TestStruct(@Unsigned var zero: Long = 0, 46 | @Unsigned var max: Long = MAX_VALUE, 47 | @Unsigned var min: Long = MIN_VALUE, 48 | @Unsigned var optional: Long? = 0, 49 | @Unsigned var optionalNil: Long? = null) 50 | 51 | @SwiftReference 52 | class UInt64Test private constructor() { 53 | 54 | @SwiftDelegate(protocols = ["UInt64TestParamProtocol"]) 55 | interface UInt64ParamProtocol { 56 | @SwiftCallbackFunc 57 | fun testParam(@Unsigned param: Long): Boolean 58 | } 59 | 60 | @SwiftDelegate(protocols = ["UInt64TestReturnTypeProtocol"]) 61 | interface UInt64ReturnTypeProtocol { 62 | @SwiftCallbackFunc @Unsigned 63 | fun testReturnType(): Long 64 | } 65 | 66 | @SwiftDelegate(protocols = ["UInt64TestOptionalParamProtocol"]) 67 | interface UInt64OptionalParamProtocol { 68 | @SwiftCallbackFunc 69 | fun testOptionalParam(@Unsigned param: Long?): Boolean 70 | } 71 | 72 | @SwiftDelegate(protocols = ["UInt64TestOptionalReturnTypeProtocol"]) 73 | interface UInt64OptionalReturnTypeProtocol { 74 | @SwiftCallbackFunc @Unsigned 75 | fun testOptionalReturnType(): Long? 76 | } 77 | 78 | @SwiftBlock("(UInt64) -> UInt64") 79 | interface UInt64Block { 80 | @Unsigned 81 | fun call(@Unsigned value: Long): Long 82 | } 83 | 84 | @SwiftBlock("(UInt64?) -> UInt64?") 85 | interface OptionalUInt64Block { 86 | @Unsigned 87 | fun call(@Unsigned value: Long?): Long? 88 | } 89 | 90 | companion object { 91 | @JvmStatic @Unsigned 92 | external fun testZero(): Long 93 | 94 | @JvmStatic @Unsigned 95 | external fun testMin(): Long 96 | 97 | @JvmStatic @Unsigned 98 | external fun testMax(): Long 99 | 100 | @JvmStatic 101 | external fun testParam(@Unsigned param: Long): Boolean 102 | 103 | @JvmStatic @Unsigned 104 | external fun testReturnType(): Long 105 | 106 | @JvmStatic 107 | external fun testOptionalParam(@Unsigned param: Long?): Boolean 108 | 109 | @JvmStatic @Unsigned 110 | external fun testOptionalReturnType(): Long? 111 | 112 | @JvmStatic 113 | external fun testProtocolParam(callback: UInt64ParamProtocol): Boolean 114 | 115 | @JvmStatic 116 | external fun testProtocolReturnType(callback: UInt64ReturnTypeProtocol): Long 117 | 118 | @JvmStatic 119 | external fun testProtocolOptionalParam(callback: UInt64OptionalParamProtocol): Boolean 120 | 121 | @JvmStatic 122 | external fun testProtocolOptionalReturnType(callback: UInt64OptionalReturnTypeProtocol): Long? 123 | 124 | @JvmStatic 125 | external fun testEncode(): UInt64TestStruct 126 | 127 | @JvmStatic 128 | external fun testDecode(value: UInt64TestStruct): Boolean 129 | 130 | @JvmStatic 131 | external fun testEnumEncode(@Unsigned rawValue: Long) : UInt64Enum 132 | 133 | @JvmStatic @Unsigned 134 | external fun testEnumDecode(enum: UInt64Enum) : Long 135 | 136 | @JvmStatic 137 | external fun testOptionSetEncode(@Unsigned rawValue: Long) : UInt64OptionsSet 138 | 139 | @JvmStatic @Unsigned 140 | external fun testOptionSetDecode(enum: UInt64OptionsSet) : Long 141 | 142 | @JvmStatic 143 | external fun testBlock(@SwiftBlock block: UInt64Block): Boolean 144 | 145 | @JvmStatic 146 | external fun testOptionalBlock(@SwiftBlock block: OptionalUInt64Block): Boolean 147 | } 148 | 149 | @Native 150 | var nativePointer: Long = 0 151 | 152 | external fun release() 153 | 154 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/UIntTest.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample 2 | 3 | import com.readdle.codegen.anotation.* 4 | import java.lang.annotation.Native 5 | 6 | private const val MIN_VALUE: Int = 0 7 | private const val MAX_VALUE: Int = -1 8 | 9 | @SwiftValue 10 | enum class UIntEnum(@Unsigned val rawValue: Int) { 11 | 12 | ONE(0), TWO(1), THREE(2); 13 | 14 | companion object { 15 | 16 | private val values = HashMap() 17 | 18 | @JvmStatic 19 | fun valueOf(rawValue: Int): UIntEnum { 20 | return values[rawValue]!! 21 | } 22 | 23 | init { 24 | enumValues().forEach { 25 | values[it.rawValue] = it 26 | } 27 | } 28 | } 29 | 30 | } 31 | 32 | @SwiftValue 33 | data class UIntOptionsSet(@Unsigned val rawValue: Int = 0) { 34 | companion object { 35 | @JvmStatic 36 | val one = UIntOptionsSet(1) 37 | @JvmStatic 38 | val two = UIntOptionsSet(2) 39 | @JvmStatic 40 | val three = UIntOptionsSet(4) 41 | } 42 | } 43 | 44 | 45 | @SwiftValue 46 | data class UIntTestStruct(@Unsigned var zero: Int = 0, 47 | @Unsigned var max: Int = MAX_VALUE, 48 | @Unsigned var min: Int = MIN_VALUE, 49 | @Unsigned var optional: Int? = 0, 50 | @Unsigned var optionalNil: Int? = null) 51 | 52 | @SwiftReference 53 | class UIntTest private constructor() { 54 | 55 | @SwiftDelegate(protocols = ["UIntTestParamProtocol"]) 56 | interface UIntParamProtocol { 57 | @SwiftCallbackFunc 58 | fun testParam(@Unsigned param: Int): Boolean 59 | } 60 | 61 | @SwiftDelegate(protocols = ["UIntTestReturnTypeProtocol"]) 62 | interface UIntReturnTypeProtocol { 63 | @SwiftCallbackFunc @Unsigned 64 | fun testReturnType(): Int 65 | } 66 | 67 | @SwiftDelegate(protocols = ["UIntTestOptionalParamProtocol"]) 68 | interface UIntOptionalParamProtocol { 69 | @SwiftCallbackFunc 70 | fun testOptionalParam(@Unsigned param: Int?): Boolean 71 | } 72 | 73 | @SwiftDelegate(protocols = ["UIntTestOptionalReturnTypeProtocol"]) 74 | interface UIntOptionalReturnTypeProtocol { 75 | @SwiftCallbackFunc @Unsigned 76 | fun testOptionalReturnType(): Int? 77 | } 78 | 79 | @SwiftBlock("(UInt) -> UInt") 80 | interface UIntBlock { 81 | @Unsigned 82 | fun call(@Unsigned value: Int): Int 83 | } 84 | 85 | @SwiftBlock("(UInt?) -> UInt?") 86 | interface OptionalUIntBlock { 87 | @Unsigned 88 | fun call(@Unsigned value: Int?): Int? 89 | } 90 | 91 | companion object { 92 | @JvmStatic @Unsigned 93 | external fun testZero(): Int 94 | 95 | @JvmStatic @Unsigned 96 | external fun testMin(): Int 97 | 98 | @JvmStatic @Unsigned 99 | external fun testMax(): Int 100 | 101 | @JvmStatic 102 | external fun testParam(@Unsigned param: Int): Boolean 103 | 104 | @JvmStatic @Unsigned 105 | external fun testReturnType(): Int 106 | 107 | @JvmStatic 108 | external fun testOptionalParam(@Unsigned param: Int?): Boolean 109 | 110 | @JvmStatic @Unsigned 111 | external fun testOptionalReturnType(): Int? 112 | 113 | @JvmStatic 114 | external fun testProtocolParam(callback: UIntParamProtocol): Boolean 115 | 116 | @JvmStatic @Unsigned 117 | external fun testProtocolReturnType(callback: UIntReturnTypeProtocol): Int 118 | 119 | @JvmStatic 120 | external fun testProtocolOptionalParam(callback: UIntOptionalParamProtocol): Boolean 121 | 122 | @JvmStatic @Unsigned 123 | external fun testProtocolOptionalReturnType(callback: UIntOptionalReturnTypeProtocol): Int? 124 | 125 | @JvmStatic 126 | external fun testEncode(): UIntTestStruct 127 | 128 | @JvmStatic 129 | external fun testDecode(value: UIntTestStruct): Boolean 130 | 131 | @JvmStatic 132 | external fun testEnumEncode(@Unsigned rawValue: Int) : UIntEnum 133 | 134 | @JvmStatic @Unsigned 135 | external fun testEnumDecode(enum: UIntEnum) : Int 136 | 137 | @JvmStatic 138 | external fun testOptionSetEncode(@Unsigned rawValue: Int) : UIntOptionsSet 139 | 140 | @JvmStatic @Unsigned 141 | external fun testOptionSetDecode(enum: UIntOptionsSet) : Int 142 | 143 | @JvmStatic 144 | external fun testBlock(@SwiftBlock block: UIntBlock): Boolean 145 | 146 | @JvmStatic 147 | external fun testOptionalBlock(@SwiftBlock block: OptionalUIntBlock): Boolean 148 | } 149 | 150 | @Native 151 | var nativePointer: Long = 0 152 | 153 | external fun release() 154 | 155 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/asbtracthierarhy/AbstractType.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample.asbtracthierarhy 2 | 3 | import com.readdle.codegen.anotation.SwiftValue 4 | 5 | @SwiftValue(hasSubclasses = true) 6 | open class AbstractType protected constructor() { 7 | 8 | external fun basicMethod(): String 9 | 10 | } 11 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/asbtracthierarhy/FirstChild.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample.asbtracthierarhy 2 | 3 | 4 | open class FirstChild : AbstractType() 5 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/asbtracthierarhy/FourthChild.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample.asbtracthierarhy 2 | 3 | 4 | class FourthChild : SecondChild() 5 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/asbtracthierarhy/SecondChild.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample.asbtracthierarhy 2 | 3 | 4 | open class SecondChild : AbstractType() 5 | -------------------------------------------------------------------------------- /sample/src/main/java/com/readdle/swiftjava/sample/asbtracthierarhy/ThirdChild.kt: -------------------------------------------------------------------------------- 1 | package com.readdle.swiftjava.sample.asbtracthierarhy 2 | 3 | 4 | class ThirdChild : FirstChild() 5 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/readdle/swift-java-codegen/6e670fb83eaacedc0dfaa87b9a3cbcc4d0cb4490/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | swift-java-codegen 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/swift/.swiftlint.yml: -------------------------------------------------------------------------------- 1 | disabled_rules: 2 | - identifier_name #short vars 3 | - force_cast #exclude tests, shoule be enabled #TODO 4 | - force_try #exclude tests 5 | - type_name 6 | - type_body_length 7 | - statement_position #}else{ 8 | - extension_access_modifier #not bad #TODO 9 | - file_header #check details 10 | - attributes #not bad #TODO 11 | - nesting #? 12 | - todo #todo 13 | - file_length 14 | - for_where #modern swift #TODO 15 | - syntactic_sugar #modern swift #TODO 16 | - function_body_length #short funcs not bad #TODO - 70 17 | - trailing_whitespace #xcode default 18 | # - vertical_parameter_alignment_on_call #strange in swift 19 | - cyclomatic_complexity #shoule be enabled #TODO2 20 | - pattern_matching_keywords #hz 21 | - override_in_extension #hz 22 | - unused_closure_parameter #i think it looks better with names 23 | - trailing_comma 24 | - large_tuple #looks good for me 25 | 26 | - compiler_protocol_init #TODO 27 | - weak_delegate #TODO 28 | - class_delegate_protocol #TODO 29 | - redundant_nil_coalescing #intruduces bugs 30 | 31 | - function_parameter_count #? 32 | # - closure_parameter_position 33 | - multiple_closures_with_trailing_closure 34 | - is_disjoint #? 35 | - contains_over_first_not_nil #maybe 36 | - no_fallthrough_only #? 37 | - notification_center_detachment 38 | - redundant_string_enum_value 39 | opt_in_rules: 40 | # - array_init 41 | - attributes 42 | - closure_end_indentation 43 | - closure_spacing 44 | - contains_over_first_not_nil 45 | # - empty_count #TODO2 46 | - explicit_init 47 | - extension_access_modifier 48 | - file_header 49 | # - file_name #not bad 50 | - first_where 51 | - joined_default_parameter 52 | - let_var_whitespace 53 | - literal_expression_end_indentation 54 | - nimble_operator 55 | - number_separator 56 | - object_literal 57 | - operator_usage_whitespace 58 | - overridden_super_call 59 | - override_in_extension 60 | - pattern_matching_keywords 61 | - private_action 62 | - private_outlet 63 | - prohibited_super_call 64 | - quick_discouraged_call 65 | - quick_discouraged_focused_test 66 | - quick_discouraged_pending_test 67 | - redundant_nil_coalescing 68 | - single_test_class 69 | - sorted_first_last 70 | - sorted_imports 71 | - unneeded_parentheses_in_closure_argument 72 | # - vertical_parameter_alignment_on_call 73 | # - yoda_condition 74 | - brackets_statment 75 | - closure_inner_space 76 | - brackets_space 77 | excluded: 78 | - Pods 79 | - .build 80 | 81 | type_name: 82 | min_length: 1 # only warning 83 | max_length: # warning and error 84 | warning: 40 85 | error: 50 86 | excluded: iPhone # excluded via string 87 | identifier_name: 88 | min_length: # only min_length 89 | error: 1 # only error 90 | excluded: # excluded via string array 91 | - id 92 | - URL 93 | - GlobalAPIKey 94 | line_length: 1000 #160 95 | number_separator: 96 | minimum_length: 5 97 | custom_rules: 98 | brackets_statment: 99 | name: Brackets Statment 100 | message: statments after } shoule be started from new line 101 | regex: \}[ ]*(if|else|catch) 102 | severity: error 103 | brackets_space: 104 | name: Block Opening 105 | message: shoule be whitespace after { 106 | regex: \{(?:\(|\w) 107 | severity: error 108 | match_kinds: # SyntaxKinds to match. optional. 109 | - parameter 110 | - identifier 111 | closure_inner_space: 112 | name: Closure Inner Space 113 | message: closures should have space after { 114 | regex: \{\w+(?:, \w+)* in\b 115 | severity: warning 116 | 117 | #TODO todo should have tickect refrence 118 | -------------------------------------------------------------------------------- /sample/src/main/swift/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "java_swift", 6 | "repositoryURL": "https://github.com/readdle/java_swift.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "8c6910dbc94657e5dfb2bc9d1d4d862ffd809d83", 10 | "version": "2.2.3" 11 | } 12 | }, 13 | { 14 | "package": "AndroidNDK", 15 | "repositoryURL": "https://github.com/readdle/swift-android-ndk.git", 16 | "state": { 17 | "branch": null, 18 | "revision": "0fbe0b28344b75079ff5d811551727bdd4ab8ec0", 19 | "version": "1.1.4" 20 | } 21 | }, 22 | { 23 | "package": "AnyCodable", 24 | "repositoryURL": "https://github.com/readdle/swift-anycodable.git", 25 | "state": { 26 | "branch": null, 27 | "revision": "9163d43ad317d938629592bbae798a95a3a0a4cf", 28 | "version": "1.0.3" 29 | } 30 | }, 31 | { 32 | "package": "Java", 33 | "repositoryURL": "https://github.com/readdle/swift-java.git", 34 | "state": { 35 | "branch": null, 36 | "revision": "e9449162891ce8e9687e9ff87d44c0752556df49", 37 | "version": "0.3.0" 38 | } 39 | }, 40 | { 41 | "package": "JavaCoder", 42 | "repositoryURL": "https://github.com/readdle/swift-java-coder.git", 43 | "state": { 44 | "branch": null, 45 | "revision": "d46cfd9f0efb61e45b08a01160a9e4aa35ae4817", 46 | "version": "1.1.2" 47 | } 48 | } 49 | ] 50 | }, 51 | "version": 1 52 | } 53 | -------------------------------------------------------------------------------- /sample/src/main/swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | import Foundation 3 | import PackageDescription 4 | 5 | let packageName = "SampleAppCore" 6 | 7 | let generatedName = "Generated" 8 | let generatedPath = ".build/\(generatedName.lowercased())" 9 | 10 | let package = Package( 11 | name: packageName, 12 | products: [ 13 | .library(name: packageName, type: .dynamic, targets: [generatedName]) 14 | ], 15 | dependencies: [ 16 | .package(url: "https://github.com/readdle/java_swift.git", .upToNextMinor(from: "2.2.3")), 17 | .package(url: "https://github.com/readdle/swift-java.git", .upToNextMinor(from: "0.3.0")), 18 | .package(url: "https://github.com/readdle/swift-java-coder.git", .upToNextMinor(from: "1.1.2")), 19 | .package(url: "https://github.com/readdle/swift-anycodable.git", .upToNextMinor(from: "1.0.3")), 20 | ], 21 | targets: [ 22 | .target(name: packageName, dependencies: ["AnyCodable", "java_swift", "JavaCoder"]), 23 | .target(name: generatedName, dependencies: [ 24 | .byName(name: packageName), 25 | "java_swift", 26 | "Java", 27 | "JavaCoder", 28 | ], 29 | path: generatedPath 30 | ) 31 | ] 32 | ) 33 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/AbstractHierarchy.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public class AbstractType: Codable { 8 | 9 | // Mandatory field: every SwiftValue should have at least 1 filed 10 | public let str: String = "" 11 | 12 | public func basicMethod() -> String { 13 | return "AbstractType" 14 | } 15 | 16 | } 17 | 18 | public class FirstChild: AbstractType { 19 | 20 | public override func basicMethod() -> String { 21 | return "FirstChild" 22 | } 23 | 24 | } 25 | 26 | public class SecondChild: AbstractType { 27 | 28 | public override func basicMethod() -> String { 29 | return "SecondChild" 30 | } 31 | 32 | } 33 | 34 | public class ThirdChild: FirstChild { 35 | 36 | public override func basicMethod() -> String { 37 | return "ThirdChild" 38 | } 39 | 40 | } 41 | 42 | public class FourthChild: SecondChild { 43 | 44 | public override func basicMethod() -> String { 45 | return super.basicMethod() 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/Array+JavaBridgeable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 1/11/18. 3 | // 4 | 5 | import Foundation 6 | import java_swift 7 | import JavaCoder 8 | 9 | // TODO: fix this hack 10 | private let AndroidPackage = "com/readdle/swiftjava/sample/asbtracthierarhy" 11 | 12 | public extension Array { 13 | 14 | // Decoding SwiftValue type with JavaCoder 15 | static func from(javaObject: jobject) throws -> Array where T: Decodable { 16 | // ignore forPackage for basic impl 17 | return try JavaDecoder(forPackage: AndroidPackage, missingFieldsStrategy: .ignore).decode(Array.self, from: javaObject) 18 | } 19 | 20 | } 21 | 22 | public extension Array where Element: Encodable { 23 | 24 | // Encoding SwiftValue type with JavaCoder 25 | func javaObject() throws -> jobject { 26 | // ignore forPackage for basic impl 27 | return try JavaEncoder(forPackage: AndroidPackage, missingFieldsStrategy: .ignore).encode(self) 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/BoolTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public struct BoolTestStruct: Codable, Hashable { 8 | public var yes: Bool = true 9 | public var no: Bool = false 10 | public var optional: Bool? = true 11 | public var optionalNil: Bool? = nil 12 | } 13 | 14 | public protocol BoolTestParamProtocol { 15 | func testParam(_ param: Bool) -> Bool 16 | } 17 | 18 | public protocol BoolTestReturnTypeProtocol { 19 | func testReturnType() -> Bool 20 | } 21 | 22 | public protocol BoolTestOptionalParamProtocol { 23 | func testOptionalParam(_ param: Bool?) -> Bool 24 | } 25 | 26 | public protocol BoolTestOptionalReturnTypeProtocol { 27 | func testOptionalReturnType() -> Bool? 28 | } 29 | 30 | public typealias BoolBlock = (_ boolValue: Bool) -> Bool 31 | public typealias OptionalBoolBlock = (_ boolValue: Bool?) -> Bool? 32 | 33 | public class BoolTest { 34 | 35 | public static func testYes() -> Bool { 36 | return true 37 | } 38 | 39 | public static func testNo() -> Bool { 40 | return false 41 | } 42 | 43 | public static func testParam(_ param: Bool) -> Bool { 44 | return param == true 45 | } 46 | 47 | public static func testReturnType() -> Bool { 48 | return true 49 | } 50 | 51 | public static func testOptionalParam(_ param: Bool?) -> Bool { 52 | return param == true 53 | } 54 | 55 | public static func testOptionalReturnType() -> Bool? { 56 | return true 57 | } 58 | 59 | public static func testProtocolParam(_ callback: BoolTestParamProtocol) -> Bool { 60 | return callback.testParam(true) 61 | } 62 | 63 | public static func testProtocolReturnType(_ callback: BoolTestReturnTypeProtocol) -> Bool { 64 | return callback.testReturnType() 65 | } 66 | 67 | public static func testProtocolOptionalParam(_ callback: BoolTestOptionalParamProtocol) -> Bool { 68 | return callback.testOptionalParam(true) 69 | } 70 | 71 | public static func testProtocolOptionalReturnType(_ callback: BoolTestOptionalReturnTypeProtocol) -> Bool? { 72 | return callback.testOptionalReturnType() 73 | } 74 | 75 | public static func testEncode() -> BoolTestStruct { 76 | return BoolTestStruct() 77 | } 78 | 79 | public static func testDecode(_ value: BoolTestStruct) -> Bool { 80 | return value == BoolTestStruct() 81 | } 82 | 83 | public static func testBlock(_ block: BoolBlock) -> Bool { 84 | let value = block(true) 85 | return value == true 86 | } 87 | 88 | public static func testOptionalBlock(_ block: OptionalBoolBlock) -> Bool { 89 | let value = block(nil) 90 | return value == nil 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/DoubleTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public struct DoubleTestStruct: Codable, Hashable { 8 | public var zero: Double = Double.zero 9 | public var infinity: Double = Double.infinity 10 | public var negativeInfinity: Double = -1 * Double.infinity 11 | public var optional: Double? = Double.zero 12 | public var optionalNil: Double? = nil 13 | } 14 | 15 | public protocol DoubleTestParamProtocol { 16 | func testParam(_ param: Double) -> Bool 17 | } 18 | 19 | public protocol DoubleTestReturnTypeProtocol { 20 | func testReturnType() -> Double 21 | } 22 | 23 | public protocol DoubleTestOptionalParamProtocol { 24 | func testOptionalParam(_ param: Double?) -> Bool 25 | } 26 | 27 | public protocol DoubleTestOptionalReturnTypeProtocol { 28 | func testOptionalReturnType() -> Double? 29 | } 30 | 31 | public typealias DoubleBlock = (_ value: Double) -> Double 32 | public typealias OptionalDoubleBlock = (_ value: Double?) -> Double? 33 | 34 | public class DoubleTest { 35 | 36 | public static func testZero() -> Double { 37 | return 0 38 | } 39 | 40 | public static func testInfinite() -> Double { 41 | return Double.infinity 42 | } 43 | 44 | public static func testNan() -> Double { 45 | return Double.nan 46 | } 47 | 48 | public static func testParam(_ param: Double) -> Bool { 49 | return param == Double.infinity 50 | } 51 | 52 | public static func testReturnType() -> Double { 53 | return Double.infinity 54 | } 55 | 56 | public static func testOptionalParam(_ param: Double?) -> Bool { 57 | return param == Double.infinity 58 | } 59 | 60 | public static func testOptionalReturnType() -> Double? { 61 | return Double.infinity 62 | } 63 | 64 | public static func testProtocolParam(_ callback: DoubleTestParamProtocol) -> Bool { 65 | return callback.testParam(Double.infinity) 66 | } 67 | 68 | public static func testProtocolReturnType(_ callback: DoubleTestReturnTypeProtocol) -> Double { 69 | return callback.testReturnType() 70 | } 71 | 72 | public static func testProtocolOptionalParam(_ callback: DoubleTestOptionalParamProtocol) -> Bool { 73 | return callback.testOptionalParam(Double.infinity) 74 | } 75 | 76 | public static func testProtocolOptionalReturnType(_ callback: DoubleTestOptionalReturnTypeProtocol) -> Double? { 77 | return callback.testOptionalReturnType() 78 | } 79 | 80 | public static func testEncode() -> DoubleTestStruct { 81 | return DoubleTestStruct() 82 | } 83 | 84 | public static func testDecode(_ value: DoubleTestStruct) -> Bool { 85 | return value == DoubleTestStruct() 86 | } 87 | 88 | public static func testBlock(_ block: DoubleBlock) -> Bool { 89 | let value = block(0) 90 | return value == 0 91 | } 92 | 93 | public static func testOptionalBlock(_ block: OptionalDoubleBlock) -> Bool { 94 | let value = block(nil) 95 | return value == nil 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/FloatTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public struct FloatTestStruct: Codable, Hashable { 8 | public var zero: Float = Float.zero 9 | public var infinity: Float = Float.infinity 10 | public var negativeInfinity: Float = -1 * Float.infinity 11 | public var optional: Float? = Float.zero 12 | public var optionalNil: Float? = nil 13 | } 14 | 15 | public protocol FloatTestParamProtocol { 16 | func testParam(_ param: Float) -> Bool 17 | } 18 | 19 | public protocol FloatTestReturnTypeProtocol { 20 | func testReturnType() -> Float 21 | } 22 | 23 | public protocol FloatTestOptionalParamProtocol { 24 | func testOptionalParam(_ param: Float?) -> Bool 25 | } 26 | 27 | public protocol FloatTestOptionalReturnTypeProtocol { 28 | func testOptionalReturnType() -> Float? 29 | } 30 | 31 | public typealias FloatBlock = (_ value: Float) -> Float 32 | public typealias OptionalFloatBlock = (_ value: Float?) -> Float? 33 | 34 | public class FloatTest { 35 | 36 | public static func testZero() -> Float { 37 | return 0 38 | } 39 | 40 | public static func testInfinite() -> Float { 41 | return Float.infinity 42 | } 43 | 44 | public static func testNan() -> Float { 45 | return Float.nan 46 | } 47 | 48 | public static func testParam(_ param: Float) -> Bool { 49 | return param == Float.infinity 50 | } 51 | 52 | public static func testReturnType() -> Float { 53 | return Float.infinity 54 | } 55 | 56 | public static func testOptionalParam(_ param: Float?) -> Bool { 57 | return param == Float.infinity 58 | } 59 | 60 | public static func testOptionalReturnType() -> Float? { 61 | return Float.infinity 62 | } 63 | 64 | public static func testProtocolParam(_ callback: FloatTestParamProtocol) -> Bool { 65 | return callback.testParam(Float.infinity) 66 | } 67 | 68 | public static func testProtocolReturnType(_ callback: FloatTestReturnTypeProtocol) -> Float { 69 | return callback.testReturnType() 70 | } 71 | 72 | public static func testProtocolOptionalParam(_ callback: FloatTestOptionalParamProtocol) -> Bool { 73 | return callback.testOptionalParam(Float.infinity) 74 | } 75 | 76 | public static func testProtocolOptionalReturnType(_ callback: FloatTestOptionalReturnTypeProtocol) -> Float? { 77 | return callback.testOptionalReturnType() 78 | } 79 | 80 | public static func testEncode() -> FloatTestStruct { 81 | return FloatTestStruct() 82 | } 83 | 84 | public static func testDecode(_ value: FloatTestStruct) -> Bool { 85 | return value == FloatTestStruct() 86 | } 87 | 88 | public static func testBlock(_ block: FloatBlock) -> Bool { 89 | let value = block(0) 90 | return value == 0 91 | } 92 | 93 | public static func testOptionalBlock(_ block: OptionalFloatBlock) -> Bool { 94 | let value = block(nil) 95 | return value == nil 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/Int16Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum Int16Enum: Int16, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct Int16OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: Int16 16 | 17 | public init(rawValue: Int16) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = Int16OptionsSet(rawValue: 1 << 0) 22 | static let two = Int16OptionsSet(rawValue: 1 << 1) 23 | static let three = Int16OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct Int16TestStruct: Codable, Hashable { 27 | public var zero: Int16 = Int16.zero 28 | public var max: Int16 = Int16.max 29 | public var min: Int16 = Int16.min 30 | public var optional: Int16? = Int16.zero 31 | public var optionalNil: Int16? = nil 32 | } 33 | 34 | public protocol Int16TestParamProtocol { 35 | func testParam(_ param: Int16) -> Bool 36 | } 37 | 38 | public protocol Int16TestReturnTypeProtocol { 39 | func testReturnType() -> Int16 40 | } 41 | 42 | public protocol Int16TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: Int16?) -> Bool 44 | } 45 | 46 | public protocol Int16TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> Int16? 48 | } 49 | 50 | public typealias Int16Block = (_ value: Int16) -> Int16 51 | public typealias OptionalInt16Block = (_ value: Int16?) -> Int16? 52 | 53 | public class Int16Test { 54 | 55 | public static func testZero() -> Int16 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> Int16 { 60 | return Int16.min 61 | } 62 | 63 | public static func testMax() -> Int16 { 64 | return Int16.max 65 | } 66 | 67 | public static func testParam(_ param: Int16) -> Bool { 68 | return param == Int16.max 69 | } 70 | 71 | public static func testReturnType() -> Int16 { 72 | return Int16.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: Int16?) -> Bool { 76 | return param == Int16.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> Int16? { 80 | return Int16.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: Int16TestParamProtocol) -> Bool { 84 | return callback.testParam(Int16.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: Int16TestReturnTypeProtocol) -> Int16 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: Int16TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(Int16.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: Int16TestOptionalReturnTypeProtocol) -> Int16? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> Int16TestStruct { 100 | return Int16TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: Int16TestStruct) -> Bool { 104 | return value == Int16TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: Int16) -> Int16Enum { 108 | switch rawValue { 109 | case Int16Enum.one.rawValue: return Int16Enum.one 110 | case Int16Enum.two.rawValue: return Int16Enum.two 111 | case Int16Enum.three.rawValue: return Int16Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: Int16Enum) -> Int16 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: Int16) -> Int16OptionsSet { 121 | return Int16OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: Int16OptionsSet) -> Int16 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: Int16Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalInt16Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/Int32Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum Int32Enum: Int32, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct Int32OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: Int32 16 | 17 | public init(rawValue: Int32) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = Int32OptionsSet(rawValue: 1 << 0) 22 | static let two = Int32OptionsSet(rawValue: 1 << 1) 23 | static let three = Int32OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct Int32TestStruct: Codable, Hashable { 27 | public var zero: Int32 = Int32.zero 28 | public var max: Int32 = Int32.max 29 | public var min: Int32 = Int32.min 30 | public var optional: Int32? = Int32.zero 31 | public var optionalNil: Int32? = nil 32 | } 33 | 34 | public protocol Int32TestParamProtocol { 35 | func testParam(_ param: Int32) -> Bool 36 | } 37 | 38 | public protocol Int32TestReturnTypeProtocol { 39 | func testReturnType() -> Int32 40 | } 41 | 42 | public protocol Int32TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: Int32?) -> Bool 44 | } 45 | 46 | public protocol Int32TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> Int32? 48 | } 49 | 50 | public typealias Int32Block = (_ value: Int32) -> Int32 51 | public typealias OptionalInt32Block = (_ value: Int32?) -> Int32? 52 | 53 | public class Int32Test { 54 | 55 | public static func testZero() -> Int32 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> Int32 { 60 | return Int32.min 61 | } 62 | 63 | public static func testMax() -> Int32 { 64 | return Int32.max 65 | } 66 | 67 | public static func testParam(_ param: Int32) -> Bool { 68 | return param == Int32.max 69 | } 70 | 71 | public static func testReturnType() -> Int32 { 72 | return Int32.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: Int32?) -> Bool { 76 | return param == Int32.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> Int32? { 80 | return Int32.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: Int32TestParamProtocol) -> Bool { 84 | return callback.testParam(Int32.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: Int32TestReturnTypeProtocol) -> Int32 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: Int32TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(Int32.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: Int32TestOptionalReturnTypeProtocol) -> Int32? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> Int32TestStruct { 100 | return Int32TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: Int32TestStruct) -> Bool { 104 | return value == Int32TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: Int) -> Int32Enum { 108 | switch Int32(rawValue) { 109 | case Int32Enum.one.rawValue: return Int32Enum.one 110 | case Int32Enum.two.rawValue: return Int32Enum.two 111 | case Int32Enum.three.rawValue: return Int32Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: Int32Enum) -> Int { 117 | return Int(enumValue.rawValue) 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: Int) -> Int32OptionsSet { 121 | return Int32OptionsSet(rawValue: Int32(rawValue)) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: Int32OptionsSet) -> Int { 125 | return Int(optionSet.rawValue) 126 | } 127 | 128 | public static func testBlock(_ block: Int32Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalInt32Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/Int64Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum Int64Enum: Int64, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct Int64OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: Int64 16 | 17 | public init(rawValue: Int64) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = Int64OptionsSet(rawValue: 1 << 0) 22 | static let two = Int64OptionsSet(rawValue: 1 << 1) 23 | static let three = Int64OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct Int64TestStruct: Codable, Hashable { 27 | public var zero: Int64 = Int64.zero 28 | public var max: Int64 = Int64.max 29 | public var min: Int64 = Int64.min 30 | public var optional: Int64? = Int64.zero 31 | public var optionalNil: Int64? = nil 32 | } 33 | 34 | public protocol Int64TestParamProtocol { 35 | func testParam(_ param: Int64) -> Bool 36 | } 37 | 38 | public protocol Int64TestReturnTypeProtocol { 39 | func testReturnType() -> Int64 40 | } 41 | 42 | public protocol Int64TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: Int64?) -> Bool 44 | } 45 | 46 | public protocol Int64TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> Int64? 48 | } 49 | 50 | public typealias Int64Block = (_ value: Int64) -> Int64 51 | public typealias OptionalInt64Block = (_ value: Int64?) -> Int64? 52 | 53 | public class Int64Test { 54 | 55 | public static func testZero() -> Int64 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> Int64 { 60 | return Int64.min 61 | } 62 | 63 | public static func testMax() -> Int64 { 64 | return Int64.max 65 | } 66 | 67 | public static func testParam(_ param: Int64) -> Bool { 68 | return param == Int64.max 69 | } 70 | 71 | public static func testReturnType() -> Int64 { 72 | return Int64.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: Int64?) -> Bool { 76 | return param == Int64.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> Int64? { 80 | return Int64.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: Int64TestParamProtocol) -> Bool { 84 | return callback.testParam(Int64.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: Int64TestReturnTypeProtocol) -> Int64 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: Int64TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(Int64.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: Int64TestOptionalReturnTypeProtocol) -> Int64? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> Int64TestStruct { 100 | return Int64TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: Int64TestStruct) -> Bool { 104 | return value == Int64TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: Int64) -> Int64Enum { 108 | switch rawValue { 109 | case Int64Enum.one.rawValue: return Int64Enum.one 110 | case Int64Enum.two.rawValue: return Int64Enum.two 111 | case Int64Enum.three.rawValue: return Int64Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: Int64Enum) -> Int64 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: Int64) -> Int64OptionsSet { 121 | return Int64OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: Int64OptionsSet) -> Int64 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: Int64Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalInt64Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/Int8Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum Int8Enum: Int8, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct Int8OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: Int8 16 | 17 | public init(rawValue: Int8) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = Int8OptionsSet(rawValue: 1 << 0) 22 | static let two = Int8OptionsSet(rawValue: 1 << 1) 23 | static let three = Int8OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct Int8TestStruct: Codable, Hashable { 27 | public var zero: Int8 = Int8.zero 28 | public var max: Int8 = Int8.max 29 | public var min: Int8 = Int8.min 30 | public var optional: Int8? = Int8.zero 31 | public var optionalNil: Int8? = nil 32 | } 33 | 34 | public protocol Int8TestParamProtocol { 35 | func testParam(_ param: Int8) -> Bool 36 | } 37 | 38 | public protocol Int8TestReturnTypeProtocol { 39 | func testReturnType() -> Int8 40 | } 41 | 42 | public protocol Int8TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: Int8?) -> Bool 44 | } 45 | 46 | public protocol Int8TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> Int8? 48 | } 49 | 50 | public typealias Int8Block = (_ value: Int8) -> Int8 51 | public typealias OptionalInt8Block = (_ value: Int8?) -> Int8? 52 | 53 | public class Int8Test { 54 | 55 | public static func testZero() -> Int8 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> Int8 { 60 | return Int8.min 61 | } 62 | 63 | public static func testMax() -> Int8 { 64 | return Int8.max 65 | } 66 | 67 | public static func testParam(_ param: Int8) -> Bool { 68 | return param == Int8.max 69 | } 70 | 71 | public static func testReturnType() -> Int8 { 72 | return Int8.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: Int8?) -> Bool { 76 | return param == Int8.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> Int8? { 80 | return Int8.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: Int8TestParamProtocol) -> Bool { 84 | return callback.testParam(Int8.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: Int8TestReturnTypeProtocol) -> Int8 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: Int8TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(Int8.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: Int8TestOptionalReturnTypeProtocol) -> Int8? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> Int8TestStruct { 100 | return Int8TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: Int8TestStruct) -> Bool { 104 | return value == Int8TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: Int8) -> Int8Enum { 108 | switch rawValue { 109 | case Int8Enum.one.rawValue: return Int8Enum.one 110 | case Int8Enum.two.rawValue: return Int8Enum.two 111 | case Int8Enum.three.rawValue: return Int8Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: Int8Enum) -> Int8 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: Int8) -> Int8OptionsSet { 121 | return Int8OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: Int8OptionsSet) -> Int8 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: Int8Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalInt8Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/IntTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum IntEnum: Int, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct IntOptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: Int 16 | 17 | public init(rawValue: Int) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = Int32OptionsSet(rawValue: 1 << 0) 22 | static let two = Int32OptionsSet(rawValue: 1 << 1) 23 | static let three = Int32OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct IntTestStruct: Codable, Hashable { 27 | public var zero: Int = Int.zero 28 | public var max: Int = Int(Int32.max) 29 | public var min: Int = Int(Int32.min) 30 | public var optional: Int? = Int.zero 31 | public var optionalNil: Int? = nil 32 | } 33 | 34 | public protocol IntTestParamProtocol { 35 | func testParam(_ param: Int) -> Bool 36 | } 37 | 38 | public protocol IntTestReturnTypeProtocol { 39 | func testReturnType() -> Int 40 | } 41 | 42 | public protocol IntTestOptionalParamProtocol { 43 | func testOptionalParam(_ param: Int?) -> Bool 44 | } 45 | 46 | public protocol IntTestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> Int? 48 | } 49 | 50 | public typealias IntBlock = (_ value: Int) -> Int 51 | public typealias OptionalIntBlock = (_ value: Int?) -> Int? 52 | 53 | public class IntTest { 54 | 55 | public static func testZero() -> Int { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> Int { 60 | return Int.min 61 | } 62 | 63 | public static func testMax() -> Int { 64 | return Int.max 65 | } 66 | 67 | public static func testMin32() -> Int { 68 | return Int(Int32.min) 69 | } 70 | 71 | public static func testMax32() -> Int { 72 | return Int(Int32.max) 73 | } 74 | 75 | public static func testParam(_ param: Int) -> Bool { 76 | return param == Int(Int32.max) 77 | } 78 | 79 | public static func testReturnType() -> Int { 80 | return Int(Int32.max) 81 | } 82 | 83 | public static func testOptionalParam(_ param: Int?) -> Bool { 84 | return param == Int(Int32.max) 85 | } 86 | 87 | public static func testOptionalReturnType() -> Int? { 88 | return Int.max 89 | } 90 | 91 | public static func testOptional32ReturnType() -> Int? { 92 | return Int(Int32.max) 93 | } 94 | 95 | public static func testProtocolParam(_ callback: IntTestParamProtocol) -> Bool { 96 | return callback.testParam(Int(Int32.max)) 97 | } 98 | 99 | public static func testProtocolReturnType(_ callback: IntTestReturnTypeProtocol) -> Int { 100 | return callback.testReturnType() 101 | } 102 | 103 | public static func testProtocolOptionalParam(_ callback: IntTestOptionalParamProtocol) -> Bool { 104 | return callback.testOptionalParam(Int(Int32.max)) 105 | } 106 | 107 | public static func testProtocolOptionalReturnType(_ callback: IntTestOptionalReturnTypeProtocol) -> Int? { 108 | return callback.testOptionalReturnType() 109 | } 110 | 111 | public static func testEncode() -> IntTestStruct { 112 | return IntTestStruct() 113 | } 114 | 115 | public static func testDecode(_ value: IntTestStruct) -> Bool { 116 | return value == IntTestStruct() 117 | } 118 | 119 | public static func testEnumEncode(_ rawValue: Int) -> IntEnum { 120 | switch rawValue { 121 | case IntEnum.one.rawValue: return IntEnum.one 122 | case IntEnum.two.rawValue: return IntEnum.two 123 | case IntEnum.three.rawValue: return IntEnum.three 124 | default: fatalError("Can't find enum with rawValue \(rawValue)") 125 | } 126 | } 127 | 128 | public static func testEnumDecode(_ enumValue: IntEnum) -> Int { 129 | return enumValue.rawValue 130 | } 131 | 132 | public static func testOptionSetEncode(_ rawValue: Int) -> IntOptionsSet { 133 | return IntOptionsSet(rawValue: rawValue) 134 | } 135 | 136 | public static func testOptionSetDecode(_ optionSet: IntOptionsSet) -> Int { 137 | return optionSet.rawValue 138 | } 139 | 140 | public static func testBlock(_ block: IntBlock) -> Bool { 141 | let value = block(0) 142 | return value == 0 143 | } 144 | 145 | public static func testOptionalBlock(_ block: OptionalIntBlock) -> Bool { 146 | let value = block(nil) 147 | return value == nil 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/IssueTests/Issue31Test.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct Issue31TestProgress: Codable { 4 | public let elapsed: Int 5 | public let total: Int 6 | 7 | public var percentage: Double { 8 | return 1.0 9 | } 10 | 11 | public init(elapsed: Int, total: Int) { 12 | self.elapsed = elapsed 13 | self.total = total 14 | } 15 | 16 | public func calculatePercentage() -> Double { 17 | return percentage 18 | } 19 | } 20 | 21 | public class Issue31ReferenceTestProgress: Codable { 22 | public let elapsed: Int 23 | public let total: Int 24 | 25 | public var percentage: Double { 26 | return 1.0 27 | } 28 | 29 | public init(elapsed: Int, total: Int) { 30 | self.elapsed = elapsed 31 | self.total = total 32 | } 33 | 34 | public func calculatePercentage() -> Double { 35 | return percentage 36 | } 37 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/SampleEnumWithValue.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew Druk on 06.05.2024. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum SampleEnumWithValue: Codable { 8 | case none 9 | case stringValue(value: String) 10 | case integerValue(value: Int) 11 | case int8Value(value: Int8) 12 | case int16Value(value: Int16) 13 | case int32Value(value: Int32) 14 | case int64Value(value: Int64) 15 | case uintValue(value: UInt) 16 | case uint8Value(value: UInt8) 17 | case uint16Value(value: UInt16) 18 | case uint32Value(value: UInt32) 19 | case uint64Value(value: UInt64) 20 | case optionalIntegerValue(value: Int?) 21 | case optionalInt8Value(value: Int8?) 22 | case optionalInt16Value(value: Int16?) 23 | case optionalInt32Value(value: Int32?) 24 | case optionalInt64Value(value: Int64?) 25 | case optionalUintValue(value: UInt?) 26 | case optionalUint8Value(value: UInt8?) 27 | case optionalUint16Value(value: UInt16?) 28 | case optionalUint32Value(value: UInt32?) 29 | case optionalUint64Value(value: UInt64?) 30 | case objectArrayValue(value: [SampleValue]) 31 | case stringArrayValue(value: [String]) 32 | case numberArrayValue(value: [Int]) 33 | case arrayInArrayValue(value: [[Int]]) 34 | case dictInArrayValue(value: [[Int: Int]]) 35 | case dictSampleClassValue(value: [String: SampleValue]) 36 | case dictStringsValue(value: [String: String]) 37 | case dictNumbersValue(value: [Int: Int]) 38 | case dict64NumbersValue(value: [Int: Int]) 39 | case dictInDictValue(value: [Int: [Int: Int]]) 40 | case arrayInDictValue(value: [Int: [Int]]) 41 | case setValue(value: Set) 42 | case setValuesValue(value: Set) 43 | 44 | public static func copy(value: SampleEnumWithValue) -> SampleEnumWithValue { 45 | return value 46 | } 47 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/SampleReference.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public protocol SampleDelegate: class { 4 | 5 | func setSampleValue(value: SampleValue?) 6 | 7 | func getSampleValue() -> SampleValue 8 | 9 | func funcWithNil() -> SampleValue? 10 | 11 | static func getTimestamp() -> Int64 12 | 13 | static func setTimestamp(_ value: Int64) 14 | 15 | func throwableFunc(_ flag: Bool) throws 16 | 17 | func throwableFuncWithReturnType(_ flag: Bool) throws -> String 18 | 19 | func funcWithData() -> Data 20 | } 21 | 22 | public protocol SampleBlockDelegate { 23 | 24 | func onCall(_ pr1: Int, _ pr2: Int, _ pr3: Double, _ pr4: Double) 25 | 26 | } 27 | 28 | private extension SampleDelegate { 29 | 30 | func timeStampTest() -> Int64 { 31 | let timestamp = Self.getTimestamp() 32 | Self.setTimestamp(timestamp) 33 | return timestamp 34 | } 35 | } 36 | 37 | public class SampleReferenceEnclose { 38 | 39 | public init() { 40 | 41 | } 42 | } 43 | 44 | public class SampleReference { 45 | 46 | // TODO: need some extra work for returning abstract type 47 | public weak var delegate: SampleDelegate? 48 | public var string: String = "str1" 49 | public static var staticString: String = "str1" 50 | 51 | public init() { 52 | 53 | } 54 | 55 | public func getRandomValue() -> SampleValue { 56 | return SampleValue(string: UUID().uuidString) 57 | } 58 | 59 | public func saveValue(_ value: SampleValue) { 60 | NSLog("save SampleValue: \(value.string)") 61 | } 62 | 63 | public func funcThrows() throws { 64 | throw NSError(domain: "Error", code: 1) 65 | } 66 | 67 | public func tick() -> Int64 { 68 | if let delegate = self.delegate { 69 | let value = getRandomValue() 70 | delegate.setSampleValue(value: value) 71 | return delegate.timeStampTest() 72 | } 73 | return -1 74 | } 75 | 76 | public func tickWithBlock(_ block: SampleBlockDelegate) { 77 | // For table overflow test 78 | for i in 0 ..< 129 { 79 | block.onCall(i, i * 100, Double(i) * 10_000.0, Double(i) * 1_000_000.0) 80 | } 81 | } 82 | 83 | public func funcWithNil() -> SampleValue? { 84 | delegate?.setSampleValue(value: nil) 85 | return delegate?.funcWithNil() 86 | } 87 | 88 | public func floatCheck(_ float: Float) -> Float { 89 | return float + 2.0 90 | } 91 | 92 | public func doubleCheck(_ double: Double) -> Double { 93 | return double + 2.0 94 | } 95 | 96 | public func exceptionCheck(_ var1: Error) -> Error { 97 | let domain = (var1 as NSError).domain 98 | let code = (var1 as NSError).code 99 | NSLog("Error: \(domain) \(code)") 100 | 101 | return var1 102 | } 103 | 104 | public func enclose(_ var1: SampleReferenceEnclose) -> SampleReferenceEnclose { 105 | return var1 106 | } 107 | 108 | public func funcWithBlock(completion: ((Error?, String?) -> String?)?) -> String? { 109 | return completion?(nil, "123") ?? "null" 110 | } 111 | 112 | public func getAbstractTypeList() -> [AbstractType] { 113 | return [FirstChild(), SecondChild(), ThirdChild(), FourthChild()] 114 | } 115 | 116 | public func getAbstractType() -> AbstractType { 117 | return FirstChild() 118 | } 119 | 120 | public func getFirstChild() -> FirstChild { 121 | return FirstChild() 122 | } 123 | 124 | public func getSecondChild() -> SecondChild { 125 | return SecondChild() 126 | } 127 | 128 | public func getThirdChild() -> ThirdChild { 129 | return ThirdChild() 130 | } 131 | 132 | public func getFourthChild() -> FourthChild { 133 | return FourthChild() 134 | } 135 | 136 | public func throwableFunc(_ delegate: SampleDelegate, _ flag: Bool) throws { 137 | return try delegate.throwableFunc(flag) 138 | } 139 | 140 | public func throwableFuncWithReturnType(_ delegate: SampleDelegate, _ flag: Bool) throws -> String { 141 | return try delegate.throwableFuncWithReturnType(flag) 142 | } 143 | 144 | public func getRandomCustomSampleValue() -> SampleValue { 145 | return SampleValue(string: UUID().uuidString) 146 | } 147 | 148 | public func saveCustomSampleValue(_ value: SampleValue) { 149 | NSLog("save SampleValue: \(value.string)") 150 | } 151 | 152 | public func oneMoreReferenceTableOverflow(_ delegate: SampleDelegate) { 153 | // For table overflow test 154 | for _ in 0 ..< 512 { 155 | let data = delegate.funcWithData() 156 | if data.count != 10 { 157 | fatalError("Wrong data count \(data.count) != 10") 158 | } 159 | } 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/SampleValue.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct SampleValue: Codable, Hashable { 4 | 5 | public var string: String 6 | 7 | public var integer: Int = 32 8 | public var int8: Int8 = 8 9 | public var int16: Int16 = 16 10 | public var int32: Int32 = 32 11 | public var int64: Int64 = 64 12 | 13 | public var uint: UInt = 32 14 | public var uint8: UInt8 = 8 15 | public var uint16: UInt16 = 16 16 | public var uint32: UInt32 = 32 17 | public var uint64: UInt64 = 64 18 | 19 | public var optionalInteger: Int? = 32 20 | public var optionalInt8: Int8? = 8 21 | public var optionalInt16: Int16? = 16 22 | public var optionalInt32: Int32? = 32 23 | public var optionalInt64: Int64? = 64 24 | 25 | public var optionalUint: UInt? = 32 26 | public var optionalUint8: UInt8? = 8 27 | public var optionalUint16: UInt16? = 16 28 | public var optionalUint32: UInt32? = 32 29 | public var optionalUint64: UInt64? = 64 30 | 31 | public var objectArray: [SampleValue] = [] 32 | public var stringArray: [String] = ["one", "two", "free"] 33 | public var numberArray: [Int] = [1, 2, 3] 34 | public var arrayInArray: [[Int]] = [[1, 2, 3]] 35 | public var dictInArray: [[Int: Int]] = [[1: 1, 2: 2, 3: 3]] 36 | 37 | public var dictSampleClass: [String: SampleValue] = [:] 38 | public var dictStrings: [String: String] = ["oneKey": "oneValue"] 39 | public var dictNumbers: [Int: Int] = [123: 2] 40 | public var dict64Numbers: [UInt64: UInt64] = [123: 2] 41 | public var dictInDict: [UInt64: [UInt64: UInt64]] = [123: [123: 2]] 42 | public var arrayInDict: [UInt64: [UInt64]] = [123: [1, 2, 3]] 43 | 44 | public var set = Set(arrayLiteral: 1, 2, 3) 45 | public var setValues = Set() 46 | 47 | public init(string: String) { 48 | self.string = string 49 | } 50 | 51 | public static func getRandomValue() -> SampleValue { 52 | return SampleValue(string: UUID().uuidString) 53 | } 54 | 55 | public func saveValue() { 56 | NSLog("save SampleValue: \(string)") 57 | } 58 | 59 | public func isSame(other: SampleValue) -> Bool { 60 | return self == other 61 | } 62 | 63 | public static func funcThrows() throws { 64 | throw NSError(domain: "Error", code: 1) 65 | } 66 | 67 | // MARK: - dump hashable impl 68 | public func hash(into hasher: inout Hasher) { 69 | hasher.combine(string) 70 | } 71 | 72 | public static func == (lhs: SampleValue, rhs: SampleValue) -> Bool { 73 | return lhs.string == rhs.string 74 | } 75 | 76 | public func copy() -> SampleValue { 77 | var copy = self 78 | copy.string = UUID().uuidString 79 | return copy 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/StringTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum StringEnum: String, Codable { 8 | case ONE 9 | case TWO 10 | case THREE 11 | } 12 | 13 | public struct StringTestStruct: Codable, Hashable { 14 | public var zero: String = "" 15 | public var optional: String? = "42" 16 | public var optionalNil: String? = nil 17 | } 18 | 19 | public protocol StringTestParamProtocol { 20 | func testParam(_ param: String) -> Bool 21 | } 22 | 23 | public protocol StringTestReturnTypeProtocol { 24 | func testReturnType() -> String 25 | } 26 | 27 | public protocol StringTestOptionalParamProtocol { 28 | func testOptionalParam(_ param: String?) -> Bool 29 | } 30 | 31 | public protocol StringTestOptionalReturnTypeProtocol { 32 | func testOptionalReturnType() -> String? 33 | } 34 | 35 | public typealias StringBlock = (_ value: String) -> String 36 | public typealias OptionalStringBlock = (_ value: String?) -> String? 37 | 38 | public class StringTest { 39 | 40 | public static func testZero() -> String { 41 | return "" 42 | } 43 | 44 | public static func testParam(_ param: String) -> Bool { 45 | return param == "" 46 | } 47 | 48 | public static func testReturnType() -> String { 49 | return "" 50 | } 51 | 52 | public static func testOptionalParam(_ param: String?) -> Bool { 53 | return param == "" 54 | } 55 | 56 | public static func testOptionalReturnType() -> String? { 57 | return "" 58 | } 59 | 60 | public static func testOptional32ReturnType() -> String? { 61 | return "" 62 | } 63 | 64 | public static func testProtocolParam(_ callback: StringTestParamProtocol) -> Bool { 65 | return callback.testParam("") 66 | } 67 | 68 | public static func testProtocolReturnType(_ callback: StringTestReturnTypeProtocol) -> String { 69 | return callback.testReturnType() 70 | } 71 | 72 | public static func testProtocolOptionalParam(_ callback: StringTestOptionalParamProtocol) -> Bool { 73 | return callback.testOptionalParam("") 74 | } 75 | 76 | public static func testProtocolOptionalReturnType(_ callback: StringTestOptionalReturnTypeProtocol) -> String? { 77 | return callback.testOptionalReturnType() 78 | } 79 | 80 | public static func testEncode() -> StringTestStruct { 81 | return StringTestStruct() 82 | } 83 | 84 | public static func testDecode(_ value: StringTestStruct) -> Bool { 85 | return value == StringTestStruct() 86 | } 87 | 88 | public static func testEnumEncode(_ rawValue: String) -> StringEnum { 89 | switch rawValue { 90 | case StringEnum.ONE.rawValue: return StringEnum.ONE 91 | case StringEnum.TWO.rawValue: return StringEnum.TWO 92 | case StringEnum.THREE.rawValue: return StringEnum.THREE 93 | default: fatalError("Can't find enum with rawValue \(rawValue)") 94 | } 95 | } 96 | 97 | public static func testEnumDecode(_ enumValue: StringEnum) -> String { 98 | return enumValue.rawValue 99 | } 100 | 101 | public static func testBlock(_ block: StringBlock) -> Bool { 102 | let value = block("") 103 | return value == "" 104 | } 105 | 106 | public static func testOptionalBlock(_ block: OptionalStringBlock) -> Bool { 107 | let value = block(nil) 108 | return value == nil 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/SwiftEnvironment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import AnyCodable 6 | import Foundation 7 | 8 | public class SwiftEnvironment { 9 | 10 | public static func initEnvironment() { 11 | AnyCodable.RegisterType(AbstractType.self) 12 | AnyCodable.RegisterType(FirstChild.self) 13 | AnyCodable.RegisterType(SecondChild.self) 14 | AnyCodable.RegisterType(ThirdChild.self) 15 | AnyCodable.RegisterType(FourthChild.self) 16 | } 17 | 18 | public static func is64BitArch() -> Bool { 19 | #if arch(x86_64) || arch(arm64) 20 | return true 21 | #else 22 | return false 23 | #endif 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/UInt16Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum UInt16Enum: UInt16, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct UInt16OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: UInt16 16 | 17 | public init(rawValue: UInt16) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = UInt16OptionsSet(rawValue: 1 << 0) 22 | static let two = UInt16OptionsSet(rawValue: 1 << 1) 23 | static let three = UInt16OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct UInt16TestStruct: Codable, Hashable { 27 | public var zero: UInt16 = UInt16.zero 28 | public var max: UInt16 = UInt16.max 29 | public var min: UInt16 = UInt16.min 30 | public var optional: UInt16? = UInt16.zero 31 | public var optionalNil: UInt16? = nil 32 | } 33 | 34 | public protocol UInt16TestParamProtocol { 35 | func testParam(_ param: UInt16) -> Bool 36 | } 37 | 38 | public protocol UInt16TestReturnTypeProtocol { 39 | func testReturnType() -> UInt16 40 | } 41 | 42 | public protocol UInt16TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: UInt16?) -> Bool 44 | } 45 | 46 | public protocol UInt16TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> UInt16? 48 | } 49 | 50 | public typealias UInt16Block = (_ value: UInt16) -> UInt16 51 | public typealias OptionalUInt16Block = (_ value: UInt16?) -> UInt16? 52 | 53 | public class UInt16Test { 54 | 55 | public static func testZero() -> UInt16 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> UInt16 { 60 | return UInt16.min 61 | } 62 | 63 | public static func testMax() -> UInt16 { 64 | return UInt16.max 65 | } 66 | 67 | public static func testParam(_ param: UInt16) -> Bool { 68 | return param == UInt16.max 69 | } 70 | 71 | public static func testReturnType() -> UInt16 { 72 | return UInt16.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: UInt16?) -> Bool { 76 | return param == UInt16.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> UInt16? { 80 | return UInt16.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: UInt16TestParamProtocol) -> Bool { 84 | return callback.testParam(UInt16.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: UInt16TestReturnTypeProtocol) -> UInt16 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: UInt16TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(UInt16.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: UInt16TestOptionalReturnTypeProtocol) -> UInt16? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> UInt16TestStruct { 100 | return UInt16TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: UInt16TestStruct) -> Bool { 104 | return value == UInt16TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: UInt16) -> UInt16Enum { 108 | switch rawValue { 109 | case UInt16Enum.one.rawValue: return UInt16Enum.one 110 | case UInt16Enum.two.rawValue: return UInt16Enum.two 111 | case UInt16Enum.three.rawValue: return UInt16Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: UInt16Enum) -> UInt16 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: UInt16) -> UInt16OptionsSet { 121 | return UInt16OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: UInt16OptionsSet) -> UInt16 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: UInt16Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalUInt16Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/UInt32Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum UInt32Enum: UInt32, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct UInt32OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: UInt32 16 | 17 | public init(rawValue: UInt32) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = UInt32OptionsSet(rawValue: 1 << 0) 22 | static let two = UInt32OptionsSet(rawValue: 1 << 1) 23 | static let three = UInt32OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct UInt32TestStruct: Codable, Hashable { 27 | public var zero: UInt32 = UInt32.zero 28 | public var max: UInt32 = UInt32.max 29 | public var min: UInt32 = UInt32.min 30 | public var optional: UInt32? = UInt32.zero 31 | public var optionalNil: UInt32? = nil 32 | } 33 | 34 | public protocol UInt32TestParamProtocol { 35 | func testParam(_ param: UInt32) -> Bool 36 | } 37 | 38 | public protocol UInt32TestReturnTypeProtocol { 39 | func testReturnType() -> UInt32 40 | } 41 | 42 | public protocol UInt32TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: UInt32?) -> Bool 44 | } 45 | 46 | public protocol UInt32TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> UInt32? 48 | } 49 | 50 | public typealias UInt32Block = (_ value: UInt32) -> UInt32 51 | public typealias OptionalUInt32Block = (_ value: UInt32?) -> UInt32? 52 | 53 | public class UInt32Test { 54 | 55 | public static func testZero() -> UInt32 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> UInt32 { 60 | return UInt32.min 61 | } 62 | 63 | public static func testMax() -> UInt32 { 64 | return UInt32.max 65 | } 66 | 67 | public static func testParam(_ param: UInt32) -> Bool { 68 | return param == UInt32.max 69 | } 70 | 71 | public static func testReturnType() -> UInt32 { 72 | return UInt32.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: UInt32?) -> Bool { 76 | return param == UInt32.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> UInt32? { 80 | return UInt32.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: UInt32TestParamProtocol) -> Bool { 84 | return callback.testParam(UInt32.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: UInt32TestReturnTypeProtocol) -> UInt32 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: UInt32TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(UInt32.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: UInt32TestOptionalReturnTypeProtocol) -> UInt32? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> UInt32TestStruct { 100 | return UInt32TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: UInt32TestStruct) -> Bool { 104 | return value == UInt32TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: UInt) -> UInt32Enum { 108 | switch UInt32(rawValue) { 109 | case UInt32Enum.one.rawValue: return UInt32Enum.one 110 | case UInt32Enum.two.rawValue: return UInt32Enum.two 111 | case UInt32Enum.three.rawValue: return UInt32Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: UInt32Enum) -> UInt { 117 | return UInt(enumValue.rawValue) 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: UInt) -> UInt32OptionsSet { 121 | return UInt32OptionsSet(rawValue: UInt32(rawValue)) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: UInt32OptionsSet) -> UInt { 125 | return UInt(optionSet.rawValue) 126 | } 127 | 128 | public static func testBlock(_ block: UInt32Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalUInt32Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/UInt64Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum UInt64Enum: UInt64, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct UInt64OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: UInt64 16 | 17 | public init(rawValue: UInt64) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = UInt64OptionsSet(rawValue: 1 << 0) 22 | static let two = UInt64OptionsSet(rawValue: 1 << 1) 23 | static let three = UInt64OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct UInt64TestStruct: Codable, Hashable { 27 | public var zero: UInt64 = UInt64.zero 28 | public var max: UInt64 = UInt64.max 29 | public var min: UInt64 = UInt64.min 30 | public var optional: UInt64? = UInt64.zero 31 | public var optionalNil: UInt64? = nil 32 | } 33 | 34 | public protocol UInt64TestParamProtocol { 35 | func testParam(_ param: UInt64) -> Bool 36 | } 37 | 38 | public protocol UInt64TestReturnTypeProtocol { 39 | func testReturnType() -> UInt64 40 | } 41 | 42 | public protocol UInt64TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: UInt64?) -> Bool 44 | } 45 | 46 | public protocol UInt64TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> UInt64? 48 | } 49 | 50 | public typealias UInt64Block = (_ value: UInt64) -> UInt64 51 | public typealias OptionalUInt64Block = (_ value: UInt64?) -> UInt64? 52 | 53 | public class UInt64Test { 54 | 55 | public static func testZero() -> UInt64 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> UInt64 { 60 | return UInt64.min 61 | } 62 | 63 | public static func testMax() -> UInt64 { 64 | return UInt64.max 65 | } 66 | 67 | public static func testParam(_ param: UInt64) -> Bool { 68 | return param == UInt64.max 69 | } 70 | 71 | public static func testReturnType() -> UInt64 { 72 | return UInt64.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: UInt64?) -> Bool { 76 | return param == UInt64.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> UInt64? { 80 | return UInt64.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: UInt64TestParamProtocol) -> Bool { 84 | return callback.testParam(UInt64.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: UInt64TestReturnTypeProtocol) -> UInt64 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: UInt64TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(UInt64.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: UInt64TestOptionalReturnTypeProtocol) -> UInt64? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> UInt64TestStruct { 100 | return UInt64TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: UInt64TestStruct) -> Bool { 104 | return value == UInt64TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: UInt64) -> UInt64Enum { 108 | switch rawValue { 109 | case UInt64Enum.one.rawValue: return UInt64Enum.one 110 | case UInt64Enum.two.rawValue: return UInt64Enum.two 111 | case UInt64Enum.three.rawValue: return UInt64Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: UInt64Enum) -> UInt64 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: UInt64) -> UInt64OptionsSet { 121 | return UInt64OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: UInt64OptionsSet) -> UInt64 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: UInt64Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalUInt64Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/UInt8Test.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum UInt8Enum: UInt8, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct UInt8OptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: UInt8 16 | 17 | public init(rawValue: UInt8) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = UInt8OptionsSet(rawValue: 1 << 0) 22 | static let two = UInt8OptionsSet(rawValue: 1 << 1) 23 | static let three = UInt8OptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct UInt8TestStruct: Codable, Hashable { 27 | public var zero: UInt8 = UInt8.zero 28 | public var max: UInt8 = UInt8.max 29 | public var min: UInt8 = UInt8.min 30 | public var optional: UInt8? = UInt8.zero 31 | public var optionalNil: UInt8? = nil 32 | } 33 | 34 | public protocol UInt8TestParamProtocol { 35 | func testParam(_ param: UInt8) -> Bool 36 | } 37 | 38 | public protocol UInt8TestReturnTypeProtocol { 39 | func testReturnType() -> UInt8 40 | } 41 | 42 | public protocol UInt8TestOptionalParamProtocol { 43 | func testOptionalParam(_ param: UInt8?) -> Bool 44 | } 45 | 46 | public protocol UInt8TestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> UInt8? 48 | } 49 | 50 | public typealias UInt8Block = (_ value: UInt8) -> UInt8 51 | public typealias OptionalUInt8Block = (_ value: UInt8?) -> UInt8? 52 | 53 | public class UInt8Test { 54 | 55 | public static func testZero() -> UInt8 { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> UInt8 { 60 | return UInt8.min 61 | } 62 | 63 | public static func testMax() -> UInt8 { 64 | return UInt8.max 65 | } 66 | 67 | public static func testParam(_ param: UInt8) -> Bool { 68 | return param == UInt8.max 69 | } 70 | 71 | public static func testReturnType() -> UInt8 { 72 | return UInt8.max 73 | } 74 | 75 | public static func testOptionalParam(_ param: UInt8?) -> Bool { 76 | return param == UInt8.max 77 | } 78 | 79 | public static func testOptionalReturnType() -> UInt8? { 80 | return UInt8.max 81 | } 82 | 83 | public static func testProtocolParam(_ callback: UInt8TestParamProtocol) -> Bool { 84 | return callback.testParam(UInt8.max) 85 | } 86 | 87 | public static func testProtocolReturnType(_ callback: UInt8TestReturnTypeProtocol) -> UInt8 { 88 | return callback.testReturnType() 89 | } 90 | 91 | public static func testProtocolOptionalParam(_ callback: UInt8TestOptionalParamProtocol) -> Bool { 92 | return callback.testOptionalParam(UInt8.max) 93 | } 94 | 95 | public static func testProtocolOptionalReturnType(_ callback: UInt8TestOptionalReturnTypeProtocol) -> UInt8? { 96 | return callback.testOptionalReturnType() 97 | } 98 | 99 | public static func testEncode() -> UInt8TestStruct { 100 | return UInt8TestStruct() 101 | } 102 | 103 | public static func testDecode(_ value: UInt8TestStruct) -> Bool { 104 | return value == UInt8TestStruct() 105 | } 106 | 107 | public static func testEnumEncode(_ rawValue: UInt8) -> UInt8Enum { 108 | switch rawValue { 109 | case UInt8Enum.one.rawValue: return UInt8Enum.one 110 | case UInt8Enum.two.rawValue: return UInt8Enum.two 111 | case UInt8Enum.three.rawValue: return UInt8Enum.three 112 | default: fatalError("Can't find enum with rawValue \(rawValue)") 113 | } 114 | } 115 | 116 | public static func testEnumDecode(_ enumValue: UInt8Enum) -> UInt8 { 117 | return enumValue.rawValue 118 | } 119 | 120 | public static func testOptionSetEncode(_ rawValue: UInt8) -> UInt8OptionsSet { 121 | return UInt8OptionsSet(rawValue: rawValue) 122 | } 123 | 124 | public static func testOptionSetDecode(_ optionSet: UInt8OptionsSet) -> UInt8 { 125 | return optionSet.rawValue 126 | } 127 | 128 | public static func testBlock(_ block: UInt8Block) -> Bool { 129 | let value = block(0) 130 | return value == 0 131 | } 132 | 133 | public static func testOptionalBlock(_ block: OptionalUInt8Block) -> Bool { 134 | let value = block(nil) 135 | return value == nil 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /sample/src/main/swift/Sources/SampleAppCore/UIntTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Andrew on 2/4/18. 3 | // 4 | 5 | import Foundation 6 | 7 | public enum UIntEnum: UInt, Codable { 8 | case one 9 | case two 10 | case three 11 | } 12 | 13 | public struct UIntOptionsSet: OptionSet, Codable { 14 | 15 | public let rawValue: UInt 16 | 17 | public init(rawValue: UInt) { 18 | self.rawValue = rawValue 19 | } 20 | 21 | static let one = UIntOptionsSet(rawValue: 1 << 0) 22 | static let two = UIntOptionsSet(rawValue: 1 << 1) 23 | static let three = UIntOptionsSet(rawValue: 1 << 2) 24 | } 25 | 26 | public struct UIntTestStruct: Codable, Hashable { 27 | public var zero: UInt = UInt.zero 28 | public var max: UInt = UInt(UInt32.max) 29 | public var min: UInt = UInt(UInt32.min) 30 | public var optional: UInt? = UInt.zero 31 | public var optionalNil: UInt? = nil 32 | } 33 | 34 | public protocol UIntTestParamProtocol { 35 | func testParam(_ param: UInt) -> Bool 36 | } 37 | 38 | public protocol UIntTestReturnTypeProtocol { 39 | func testReturnType() -> UInt 40 | } 41 | 42 | public protocol UIntTestOptionalParamProtocol { 43 | func testOptionalParam(_ param: UInt?) -> Bool 44 | } 45 | 46 | public protocol UIntTestOptionalReturnTypeProtocol { 47 | func testOptionalReturnType() -> UInt? 48 | } 49 | 50 | public typealias UIntBlock = (_ value: UInt) -> UInt 51 | public typealias OptionalUIntBlock = (_ value: UInt?) -> UInt? 52 | 53 | public class UIntTest { 54 | 55 | public static func testZero() -> UInt { 56 | return 0 57 | } 58 | 59 | public static func testMin() -> UInt { 60 | return UInt.min 61 | } 62 | 63 | public static func testMax() -> UInt { 64 | return UInt.max 65 | } 66 | 67 | public static func testMin32() -> UInt { 68 | return UInt(UInt32.min) 69 | } 70 | 71 | public static func testMax32() -> UInt { 72 | return UInt(UInt32.max) 73 | } 74 | 75 | public static func testParam(_ param: UInt) -> Bool { 76 | return param == UInt(UInt32.max) 77 | } 78 | 79 | public static func testReturnType() -> UInt { 80 | return UInt(UInt32.max) 81 | } 82 | 83 | public static func testOptionalParam(_ param: UInt?) -> Bool { 84 | return param == UInt(UInt32.max) 85 | } 86 | 87 | public static func testOptionalReturnType() -> UInt? { 88 | return UInt.max 89 | } 90 | 91 | public static func testOptional32ReturnType() -> UInt? { 92 | return UInt(UInt32.max) 93 | } 94 | 95 | public static func testProtocolParam(_ callback: UIntTestParamProtocol) -> Bool { 96 | return callback.testParam(UInt(UInt32.max)) 97 | } 98 | 99 | public static func testProtocolReturnType(_ callback: UIntTestReturnTypeProtocol) -> UInt { 100 | return callback.testReturnType() 101 | } 102 | 103 | public static func testProtocolOptionalParam(_ callback: UIntTestOptionalParamProtocol) -> Bool { 104 | return callback.testOptionalParam(UInt(UInt32.max)) 105 | } 106 | 107 | public static func testProtocolOptionalReturnType(_ callback: UIntTestOptionalReturnTypeProtocol) -> UInt? { 108 | return callback.testOptionalReturnType() 109 | } 110 | 111 | public static func testEncode() -> UIntTestStruct { 112 | return UIntTestStruct() 113 | } 114 | 115 | public static func testDecode(_ value: UIntTestStruct) -> Bool { 116 | return value == UIntTestStruct() 117 | } 118 | 119 | public static func testEnumEncode(_ rawValue: UInt) -> UIntEnum { 120 | switch rawValue { 121 | case UIntEnum.one.rawValue: return UIntEnum.one 122 | case UIntEnum.two.rawValue: return UIntEnum.two 123 | case UIntEnum.three.rawValue: return UIntEnum.three 124 | default: fatalError("Can't find enum with rawValue \(rawValue)") 125 | } 126 | } 127 | 128 | public static func testEnumDecode(_ enumValue: UIntEnum) -> UInt { 129 | return enumValue.rawValue 130 | } 131 | 132 | public static func testOptionSetEncode(_ rawValue: UInt) -> UIntOptionsSet { 133 | return UIntOptionsSet(rawValue: rawValue) 134 | } 135 | 136 | public static func testOptionSetDecode(_ optionSet: UIntOptionsSet) -> UInt { 137 | return optionSet.rawValue 138 | } 139 | 140 | public static func testBlock(_ block: UIntBlock) -> Bool { 141 | let value = block(0) 142 | return value == 0 143 | } 144 | 145 | public static func testOptionalBlock(_ block: OptionalUIntBlock) -> Bool { 146 | let value = block(nil) 147 | return value == nil 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':compiler', ':library', ':sample' 2 | --------------------------------------------------------------------------------