├── .github ├── actions │ └── prepare_env │ │ └── action.yml ├── scripts │ └── validate_sample.sh └── workflows │ └── pull_request.yml ├── .gitignore ├── .licenseignore ├── .unacceptablelanguageignore ├── Benchmarks ├── Benchmarks │ └── JavaApiCallBenchmarks │ │ └── JavaApiCallBenchmarks.swift └── Package.swift ├── BuildLogic ├── .gitignore ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── build-logic.java-application-conventions.gradle.kts │ ├── build-logic.java-common-conventions.gradle.kts │ └── build-logic.java-library-conventions.gradle.kts ├── CONTRIBUTING.md ├── LICENSE.txt ├── Package.swift ├── Plugins ├── JExtractSwiftCommandPlugin │ ├── JExtractSwiftCommandPlugin.swift │ └── _PluginsShared ├── JExtractSwiftPlugin │ ├── JExtractSwiftPlugin.swift │ └── _PluginsShared ├── Java2SwiftPlugin │ ├── Java2SwiftPlugin.swift │ └── _PluginsShared ├── JavaCompilerPlugin │ ├── JavaCompilerPlugin.swift │ └── _PluginsShared └── PluginsShared │ ├── 0_PLEASE_SYMLINK.txt │ ├── JavaKitConfigurationShared │ ├── PluginUtils.swift │ ├── SwiftJavaPlugin+Errors.swift │ └── SwiftJavaPluginProtocol.swift ├── README.md ├── Samples ├── JavaDependencySampleApp │ ├── Package.swift │ ├── Sources │ │ ├── JavaCommonsCSV │ │ │ ├── dummy.swift │ │ │ └── swift-java.config │ │ ├── JavaDependencySample │ │ │ ├── main.swift │ │ │ └── swift-java.config │ │ └── JavaExample │ │ │ └── JavaExample.swift │ ├── ci-validate.sh │ ├── gradle │ ├── gradlew │ └── gradlew.bat ├── JavaKitSampleApp │ ├── Package.swift │ ├── Sources │ │ └── JavaKitExample │ │ │ ├── JavaKitExample.swift │ │ │ ├── com │ │ │ └── example │ │ │ │ └── swift │ │ │ │ ├── HelloSubclass.java │ │ │ │ ├── HelloSwift.java │ │ │ │ ├── JavaKitSampleMain.java │ │ │ │ ├── ThreadSafe.java │ │ │ │ └── ThreadSafeHelperClass.java │ │ │ └── swift-java.config │ └── ci-validate.sh ├── JavaProbablyPrime │ ├── Package.swift │ ├── README.md │ ├── Sources │ │ └── JavaProbablyPrime │ │ │ ├── prime.swift │ │ │ └── swift-java.config │ └── ci-validate.sh ├── JavaSieve │ ├── .gitignore │ ├── Package.swift │ ├── README.md │ ├── Sources │ │ ├── JavaMath │ │ │ ├── dummy.swift │ │ │ └── swift-java.config │ │ └── JavaSieve │ │ │ ├── main.swift │ │ │ └── swift-java.config │ └── ci-validate.sh ├── SwiftAndJavaJarSampleLib │ ├── Example.java │ ├── Package.swift │ ├── Sources │ │ └── MySwiftLibrary │ │ │ ├── MySwiftLibrary.swift │ │ │ └── swift-java.config │ ├── build.gradle │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── jmh │ │ └── java │ │ │ └── org │ │ │ └── swift │ │ │ └── swiftkit │ │ │ └── JavaToSwiftBenchmark.java │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── swift │ │ │ └── HelloJava2Swift.java │ │ └── test │ │ └── java │ │ ├── com │ │ └── example │ │ │ └── swift │ │ │ ├── MySwiftClassTest.java │ │ │ └── MySwiftLibraryTest.java │ │ └── org │ │ └── swift │ │ └── swiftkit │ │ ├── MySwiftClassTest.java │ │ └── SwiftArenaTest.java ├── SwiftKitSampleApp │ ├── Package.swift │ ├── Sources │ │ └── MySwiftLibrary │ │ │ ├── MySwiftClass.swift │ │ │ ├── MySwiftLibrary.swift │ │ │ ├── MySwiftStruct.swift │ │ │ ├── _RuntimeWorkarounds.swift │ │ │ ├── jni │ │ │ └── JNIImplementations.swift │ │ │ └── swift-java.config │ ├── build.gradle │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── jmh │ │ └── java │ │ │ └── org │ │ │ └── swift │ │ │ └── swiftkit │ │ │ ├── JavaToSwiftBenchmark.java │ │ │ └── StringPassingBenchmark.java │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── swift │ │ │ └── HelloJava2Swift.java │ │ └── test │ │ └── java │ │ ├── com │ │ └── example │ │ │ └── swift │ │ │ ├── MySwiftClassTest.java │ │ │ └── MySwiftLibraryTest.java │ │ └── org │ │ └── swift │ │ └── swiftkit │ │ ├── MySwiftClassTest.java │ │ ├── MySwiftStructTest.java │ │ └── SwiftArenaTest.java ├── gradle └── gradlew ├── Sources ├── ExampleSwiftLibrary │ └── MySwiftLibrary.swift ├── JExtractSwift │ ├── CDeclLowering │ │ ├── CRepresentation.swift │ │ └── Swift2JavaTranslator+FunctionLowering.swift │ ├── CTypes │ │ ├── CEnum.swift │ │ ├── CFunction.swift │ │ ├── CParameter.swift │ │ ├── CStruct.swift │ │ ├── CTag.swift │ │ ├── CType.swift │ │ └── CUnion.swift │ ├── CodePrinter.swift │ ├── Convenience │ │ ├── Collection+Extensions.swift │ │ ├── String+Extensions.swift │ │ └── SwiftSyntax+Extensions.swift │ ├── ConversionStep.swift │ ├── ImportedDecls.swift │ ├── JavaConstants │ │ ├── ForeignValueLayouts.swift │ │ └── JavaTypes.swift │ ├── Logger.swift │ ├── Swift2Java.swift │ ├── Swift2JavaTranslator+JavaBindingsPrinting.swift │ ├── Swift2JavaTranslator+JavaTranslation.swift │ ├── Swift2JavaTranslator+Printing.swift │ ├── Swift2JavaTranslator+SwiftThunkPrinting.swift │ ├── Swift2JavaTranslator.swift │ ├── Swift2JavaVisitor.swift │ ├── SwiftKit+Printing.swift │ ├── SwiftTypes │ │ ├── SwiftFunctionSignature.swift │ │ ├── SwiftFunctionType.swift │ │ ├── SwiftModuleSymbolTable.swift │ │ ├── SwiftNominalTypeDeclaration.swift │ │ ├── SwiftParameter.swift │ │ ├── SwiftParsedModuleSymbolTable.swift │ │ ├── SwiftResult.swift │ │ ├── SwiftStandardLibraryTypes.swift │ │ ├── SwiftSymbolTable.swift │ │ └── SwiftType.swift │ └── ThunkNameRegistry.swift ├── JExtractSwiftTool │ └── JExtractSwiftTool.swift ├── Java2Swift │ ├── JavaToSwift+EmitConfiguration.swift │ ├── JavaToSwift+FetchDependencies.swift │ ├── JavaToSwift+GenerateWrappers.swift │ ├── JavaToSwift.swift │ └── String+Extensions.swift ├── Java2SwiftLib │ ├── JavaClassTranslator.swift │ ├── JavaTranslator+Configuration.swift │ ├── JavaTranslator+Validation.swift │ ├── JavaTranslator.swift │ ├── MethodVariance.swift │ ├── OptionalKind.swift │ ├── StringExtras.swift │ └── TranslationError.swift ├── JavaKit │ ├── AnyJavaObject.swift │ ├── BridgedValues │ │ ├── JavaValue+Array.swift │ │ ├── JavaValue+Bool.swift │ │ ├── JavaValue+FloatingPoint.swift │ │ ├── JavaValue+Integers.swift │ │ └── JavaValue+String.swift │ ├── Exceptions │ │ ├── Exception+Error.swift │ │ ├── ExceptionHandling.swift │ │ └── Throwable+Error.swift │ ├── JavaClass+Initialization.swift │ ├── JavaEnvironment.swift │ ├── JavaKitVM │ │ ├── JavaVirtualMachine.swift │ │ ├── LockedState.swift │ │ └── ThreadLocalStorage.swift │ ├── JavaObject+Inheritance.swift │ ├── JavaObject+MethodCalls.swift │ ├── JavaObjectHolder.swift │ ├── JavaRuntime+Reexport.swift │ ├── JavaValue.swift │ ├── Macros.swift │ ├── Optional+JavaObject.swift │ ├── Optional+JavaOptional.swift │ ├── generated │ │ ├── Appendable.swift │ │ ├── CharSequence.swift │ │ ├── Exception.swift │ │ ├── JavaArray.swift │ │ ├── JavaBoolean.swift │ │ ├── JavaByte.swift │ │ ├── JavaCharacter.swift │ │ ├── JavaClass.swift │ │ ├── JavaClassLoader.swift │ │ ├── JavaDouble.swift │ │ ├── JavaError.swift │ │ ├── JavaFloat.swift │ │ ├── JavaInteger.swift │ │ ├── JavaLong.swift │ │ ├── JavaNumber.swift │ │ ├── JavaObject.swift │ │ ├── JavaOptional.swift │ │ ├── JavaOptionalDouble.swift │ │ ├── JavaOptionalInt.swift │ │ ├── JavaOptionalLong.swift │ │ ├── JavaShort.swift │ │ ├── JavaString.swift │ │ ├── JavaVoid.swift │ │ ├── RuntimeException.swift │ │ └── Throwable.swift │ └── swift-java.config ├── JavaKitCollection │ ├── JavaEnumeration+Sequence.swift │ ├── JavaIterator+Iterator.swift │ ├── List+Sequence.swift │ ├── generated │ │ ├── ArrayDeque.swift │ │ ├── ArrayList.swift │ │ ├── BitSet.swift │ │ ├── Enumeration.swift │ │ ├── HashMap.swift │ │ ├── HashSet.swift │ │ ├── JavaCollection.swift │ │ ├── JavaDictionary.swift │ │ ├── JavaIterator.swift │ │ ├── JavaSet.swift │ │ ├── LinkedList.swift │ │ ├── List.swift │ │ ├── ListIterator.swift │ │ ├── PriorityQueue.swift │ │ ├── Queue.swift │ │ ├── RandomAccess.swift │ │ ├── Stack.swift │ │ ├── TreeMap.swift │ │ └── TreeSet.swift │ └── swift-java.config ├── JavaKitConfigurationShared │ └── Configuration.swift ├── JavaKitDependencyResolver │ ├── DependencyResolver.swift │ └── swift-java.config ├── JavaKitFunction │ ├── generated │ │ ├── JavaBiConsumer.swift │ │ ├── JavaBiFunction.swift │ │ ├── JavaBiPredicate.swift │ │ ├── JavaBinaryOperator.swift │ │ ├── JavaBooleanSupplier.swift │ │ ├── JavaConsumer.swift │ │ ├── JavaDoubleBinaryOperator.swift │ │ ├── JavaDoubleConsumer.swift │ │ ├── JavaDoubleFunction.swift │ │ ├── JavaDoublePredicate.swift │ │ ├── JavaDoubleSupplier.swift │ │ ├── JavaDoubleToIntFunction.swift │ │ ├── JavaDoubleToLongFunction.swift │ │ ├── JavaDoubleUnaryOperator.swift │ │ ├── JavaFunction.swift │ │ ├── JavaIntBinaryOperator.swift │ │ ├── JavaIntConsumer.swift │ │ ├── JavaIntFunction.swift │ │ ├── JavaIntPredicate.swift │ │ ├── JavaIntSupplier.swift │ │ ├── JavaIntToDoubleFunction.swift │ │ ├── JavaIntToLongFunction.swift │ │ ├── JavaIntUnaryOperator.swift │ │ ├── JavaLongBinaryOperator.swift │ │ ├── JavaLongConsumer.swift │ │ ├── JavaLongFunction.swift │ │ ├── JavaLongPredicate.swift │ │ ├── JavaLongSupplier.swift │ │ ├── JavaLongToDoubleFunction.swift │ │ ├── JavaLongToIntFunction.swift │ │ ├── JavaLongUnaryOperator.swift │ │ ├── JavaObjDoubleConsumer.swift │ │ ├── JavaObjIntConsumer.swift │ │ ├── JavaObjLongConsumer.swift │ │ ├── JavaPredicate.swift │ │ ├── JavaSupplier.swift │ │ ├── JavaToDoubleBiFunction.swift │ │ ├── JavaToDoubleFunction.swift │ │ ├── JavaToIntBiFunction.swift │ │ ├── JavaToIntFunction.swift │ │ ├── JavaToLongBiFunction.swift │ │ ├── JavaToLongFunction.swift │ │ └── JavaUnaryOperator.swift │ └── swift-java.config ├── JavaKitIO │ ├── generated │ │ ├── BufferedInputStream.swift │ │ ├── Charset.swift │ │ ├── Closeable.swift │ │ ├── File.swift │ │ ├── FileDescriptor.swift │ │ ├── FileReader.swift │ │ ├── Flushable.swift │ │ ├── InputStream.swift │ │ ├── InputStreamReader.swift │ │ ├── OutputStream.swift │ │ ├── Path.swift │ │ ├── Readable.swift │ │ ├── Reader.swift │ │ ├── StringReader.swift │ │ ├── WatchService.swift │ │ └── Writer.swift │ └── swift-java.config ├── JavaKitJar │ ├── generated │ │ ├── Attributes.swift │ │ ├── JarEntry.swift │ │ ├── JarFile.swift │ │ ├── JarInputStream.swift │ │ ├── JarOutputStream.swift │ │ ├── Manifest.swift │ │ └── ZipEntry.swift │ └── swift-java.config ├── JavaKitMacros │ ├── GenerationMode.swift │ ├── ImplementsJavaMacro.swift │ ├── JavaClassMacro.swift │ ├── JavaFieldMacro.swift │ ├── JavaKitMacrosPlugin.swift │ ├── JavaMethodMacro.swift │ ├── MacroErrors.swift │ └── SwiftSyntaxUtils.swift ├── JavaKitNetwork │ ├── generated │ │ ├── URI.swift │ │ ├── URL.swift │ │ ├── URLClassLoader.swift │ │ └── URLConnection.swift │ └── swift-java.config ├── JavaKitReflection │ ├── Constructor+Utilities.swift │ ├── Executable+Utilities.swift │ ├── Field+Utilities.swift │ ├── JavaClass+Reflection.swift │ ├── Method+Utilities.swift │ ├── generated │ │ ├── AccessibleObject.swift │ │ ├── AnnotatedType.swift │ │ ├── Annotation.swift │ │ ├── Constructor.swift │ │ ├── Executable.swift │ │ ├── Field.swift │ │ ├── GenericArrayType.swift │ │ ├── GenericDeclaration.swift │ │ ├── Method.swift │ │ ├── Parameter.swift │ │ ├── ParameterizedType.swift │ │ ├── Type.swift │ │ ├── TypeVariable.swift │ │ └── WildcardType.swift │ └── swift-java.config ├── JavaKitShared │ └── TerminalColors.swift ├── JavaRuntime │ ├── dummy.c │ └── include │ │ └── JavaRuntime.h ├── JavaTypes │ ├── JavaDemanglingError.swift │ ├── JavaType+JNI.swift │ ├── JavaType+JavaSource.swift │ ├── JavaType+SwiftNames.swift │ ├── JavaType.swift │ ├── Mangling.swift │ └── MethodSignature.swift ├── SwiftKitSwift │ └── SwiftKit.swift ├── _CShims │ ├── include │ │ ├── _CShimsTargetConditionals.h │ │ └── process_shims.h │ └── process_shims.c └── _Subprocess │ ├── LockedState.swift │ ├── Platforms │ ├── Subprocess+Darwin.swift │ ├── Subprocess+Linux.swift │ ├── Subprocess+Unix.swift │ └── Subprocess+Windows.swift │ ├── Subprocess+API.swift │ ├── Subprocess+AsyncDataSequence.swift │ ├── Subprocess+Configuration.swift │ ├── Subprocess+IO.swift │ ├── Subprocess+Teardown.swift │ ├── Subprocess.swift │ └── _nio_locks.swift ├── SwiftKit ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── swift │ │ └── swiftkit │ │ ├── AutoSwiftMemorySession.java │ │ ├── ClosableSwiftArena.java │ │ ├── ConfinedSwiftMemorySession.java │ │ ├── ManagedSwiftType.java │ │ ├── MemorySegmentUtils.java │ │ ├── SwiftAnyType.java │ │ ├── SwiftArena.java │ │ ├── SwiftHeapObject.java │ │ ├── SwiftInstance.java │ │ ├── SwiftInstanceCleanup.java │ │ ├── SwiftKit.java │ │ ├── SwiftValue.java │ │ ├── SwiftValueLayout.java │ │ ├── SwiftValueWitnessTable.java │ │ └── util │ │ ├── PlatformUtils.java │ │ └── StringUtils.java │ └── test │ └── java │ └── org │ └── swift │ └── swiftkit │ ├── AutoArenaTest.java │ └── SwiftRuntimeMetadataTest.java ├── Tests ├── JExtractSwiftTests │ ├── Asserts │ │ ├── LoweringAssertions.swift │ │ └── TextAssertions.swift │ ├── CTypeTests.swift │ ├── ClassPrintingTests.swift │ ├── FuncCallbackImportTests.swift │ ├── FunctionDescriptorImportTests.swift │ ├── FunctionLoweringTests.swift │ ├── MethodImportTests.swift │ ├── MethodThunkTests.swift │ ├── StringPassingTests.swift │ ├── SwiftSymbolTableTests.swift │ └── VariableImportTests.swift ├── Java2SwiftTests │ ├── Java2SwiftTests.swift │ └── JavaTranslatorValidationTests.swift ├── JavaKitMacroTests │ └── JavaClassMacroTests.swift ├── JavaKitTests │ └── BasicRuntimeTests.swift └── JavaTypesTests │ └── ManglingTests.swift ├── USER_GUIDE.md ├── WIP.md ├── buildSrc ├── README.md ├── build.gradle └── src │ └── main │ └── groovy │ └── org │ └── swift │ └── swiftkit │ └── gradle │ └── BuildUtils.groovy ├── docker ├── Dockerfile ├── docker-compose.2204.main.yaml ├── docker-compose.yaml ├── install_jdk.sh └── install_untested_nightly_swift.sh ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/actions/prepare_env/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Swift Java CI Env' 2 | description: 'Prepare the CI environment by installing Swift and selected JDK etc.' 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Install System Dependencies 8 | run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev 9 | shell: bash 10 | - name: Cache JDK 11 | id: cache-jdk 12 | uses: actions/cache@v4 13 | continue-on-error: true 14 | with: 15 | path: /usr/lib/jvm/default-jdk/ 16 | key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }} 17 | restore-keys: | 18 | ${{ runner.os }}-jdk- 19 | - name: Install JDK 20 | if: steps.cache-jdk.outputs.cache-hit != 'true' 21 | run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'" 22 | shell: bash 23 | # TODO: not using setup-java since incompatible with the swiftlang/swift base image 24 | # - name: Install Untested Nightly Swift 25 | # run: "bash -xc './docker/install_untested_nightly_swift.sh'" 26 | - name: Cache local Gradle repository 27 | uses: actions/cache@v4 28 | continue-on-error: true 29 | with: 30 | path: | 31 | /root/.gradle/caches 32 | /root/.gradle/wrapper 33 | key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }} 34 | restore-keys: | 35 | ${{ runner.os }}-gradle- 36 | - name: Cache local SwiftPM repository 37 | uses: actions/cache@v4 38 | continue-on-error: true 39 | with: 40 | path: /__w/swift-java/swift-java/.build/checkouts 41 | key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }} 42 | restore-keys: | 43 | ${{ runner.os }}-swiftpm-cache 44 | ${{ runner.os }}-swiftpm- 45 | -------------------------------------------------------------------------------- /.github/scripts/validate_sample.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # shellcheck disable=SC2034 4 | declare -r GREEN='\033[0;32m' 5 | declare -r BOLD='\033[1m' 6 | declare -r RESET='\033[0m' 7 | 8 | declare -r sampleDir="$1" 9 | declare -r CI_VALIDATE_SCRIPT='ci-validate.sh' 10 | 11 | echo "" 12 | echo "" 13 | echo "========================================================================" 14 | printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir" 15 | cd "$sampleDir" || exit 16 | if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then 17 | echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..." 18 | ./${CI_VALIDATE_SCRIPT} || exit 19 | elif [[ $(find . -name 'build.gradle*' -maxdepth 1) ]]; then 20 | echo -e "${BOLD}Gradle${RESET} build..." 21 | ./gradlew build || ./gradlew build --info # re-run to get better failure output 22 | else 23 | echo -e "${BOLD}SwiftPM${RESET} build..." 24 | swift build || exit 25 | fi 26 | 27 | echo -e "Validated sample '${BOLD}${sampleDir}${RESET}': ${BOLD}passed${RESET}." 28 | cd - || exit 29 | 30 | echo 31 | printf "Done validating sample: %s" "${sampleDir}" 32 | echo -e "${GREEN}done${RESET}." 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .build 3 | .idea 4 | Packages 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm 8 | .swiftpm/configuration/registries.json 9 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 10 | .netrc 11 | *.class 12 | bin/ 13 | BuildLogic/out/ 14 | .index-build 15 | .build-vscode 16 | 17 | # Ignore gradle build artifacts 18 | .gradle 19 | **/build/ 20 | lib/ 21 | 22 | # Ignore JVM crash logs 23 | **/*.log 24 | 25 | # Ignore package resolved 26 | Package.resolved 27 | 28 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 29 | !gradle-wrapper.jar 30 | 31 | # Avoid ignore Gradle wrappper properties 32 | !gradle-wrapper.properties 33 | 34 | # Cache of project 35 | .gradletasknamecache 36 | 37 | # Ignore files generated by jextract, we always can re-generate them 38 | */**/src/generated/java/**/* 39 | 40 | */**/*.d 41 | */**/*.o 42 | */**/*.swiftdeps 43 | */**/*.swiftdeps~ 44 | -------------------------------------------------------------------------------- /.licenseignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .licenseignore 3 | .swiftformatignore 4 | .spi.yml 5 | .swift-format 6 | .github/* 7 | *.md 8 | **/*.config 9 | CONTRIBUTORS.txt 10 | LICENSE.txt 11 | NOTICE.txt 12 | Package.swift 13 | Package.resolved 14 | README.md 15 | SECURITY.md 16 | scripts/unacceptable-language.txt 17 | .unacceptablelanguageignore 18 | docker/* 19 | **/*.docc/* 20 | **/.gitignore 21 | **/Package.swift 22 | **/Package.resolved 23 | **/*.md 24 | **/openapi.yml 25 | **/petstore.yaml 26 | **/openapi-generator-config.yaml 27 | **/openapi-generator-config.yml 28 | **/docker-compose.yaml 29 | **/docker/* 30 | **/.dockerignore 31 | Makefile 32 | **/Makefile 33 | **/*.html 34 | **/CMakeLists.txt 35 | **/*.jar 36 | **/generated/*.java 37 | **/generated/*.swift 38 | gradle/wrapper/gradle-wrapper.properties 39 | gradlew 40 | gradlew.bat 41 | **/gradlew 42 | **/gradlew.bat 43 | **/ci-validate.sh 44 | **/DO_NOT_EDIT.txt 45 | Plugins/**/_PluginsShared 46 | Plugins/**/0_PLEASE_SYMLINK* 47 | Plugins/PluginsShared/JavaKitConfigurationShared 48 | Samples/JavaDependencySampleApp/gradle 49 | Sources/_Subprocess/_nio_locks.swift 50 | Samples/gradle 51 | -------------------------------------------------------------------------------- /.unacceptablelanguageignore: -------------------------------------------------------------------------------- 1 | Sources/SwiftJavaBootstrapJavaTool/SwiftJavaBootstrapJavaTool.swift 2 | Sources/_Subprocess/Platforms/Subprocess+Darwin.swift 3 | Sources/_Subprocess/Platforms/Subprocess+Linux.swift 4 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 5 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 6 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 7 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 8 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 9 | Sources/_Subprocess/Platforms/Subprocess+Unix.swift 10 | Sources/_Subprocess/Subprocess+Teardown.swift 11 | Sources/_Subprocess/Subprocess+Teardown.swift 12 | Sources/_Subprocess/Subprocess+Teardown.swift 13 | Sources/_Subprocess/Subprocess+Teardown.swift 14 | Sources/_Subprocess/Subprocess+Teardown.swift 15 | Sources/_Subprocess/Subprocess+Teardown.swift 16 | Sources/_Subprocess/Subprocess+Teardown.swift 17 | Sources/_Subprocess/Subprocess.swift -------------------------------------------------------------------------------- /Benchmarks/Benchmarks/JavaApiCallBenchmarks/JavaApiCallBenchmarks.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import Benchmark 16 | import Foundation 17 | import JavaKit 18 | import JavaKitNetwork 19 | 20 | @MainActor let benchmarks = { 21 | var jvm: JavaVirtualMachine { 22 | get throws { 23 | try .shared() 24 | } 25 | } 26 | Benchmark("Simple call to Java library") { benchmark in 27 | for _ in benchmark.scaledIterations { 28 | let environment = try jvm.environment() 29 | 30 | let urlConnectionClass = try JavaClass(environment: environment) 31 | blackHole(urlConnectionClass.getDefaultAllowUserInteraction()) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BuildLogic/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .gradle 3 | -------------------------------------------------------------------------------- /BuildLogic/build.gradle.kts: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | repositories { 16 | gradlePluginPortal() 17 | mavenCentral() 18 | } 19 | 20 | dependencies { 21 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.7.3") 22 | } 23 | 24 | plugins { 25 | `kotlin-dsl` 26 | } 27 | -------------------------------------------------------------------------------- /BuildLogic/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | rootProject.name = "BuildLogic" 16 | -------------------------------------------------------------------------------- /BuildLogic/src/main/kotlin/build-logic.java-application-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | plugins { 16 | id("build-logic.java-common-conventions") 17 | 18 | id("application") 19 | } 20 | -------------------------------------------------------------------------------- /BuildLogic/src/main/kotlin/build-logic.java-library-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | plugins { 16 | id("build-logic.java-common-conventions") 17 | 18 | id("application") 19 | } 20 | -------------------------------------------------------------------------------- /Plugins/JExtractSwiftCommandPlugin/_PluginsShared: -------------------------------------------------------------------------------- 1 | ../PluginsShared -------------------------------------------------------------------------------- /Plugins/JExtractSwiftPlugin/_PluginsShared: -------------------------------------------------------------------------------- 1 | ../PluginsShared -------------------------------------------------------------------------------- /Plugins/Java2SwiftPlugin/_PluginsShared: -------------------------------------------------------------------------------- 1 | ../PluginsShared -------------------------------------------------------------------------------- /Plugins/JavaCompilerPlugin/_PluginsShared: -------------------------------------------------------------------------------- 1 | ../PluginsShared -------------------------------------------------------------------------------- /Plugins/PluginsShared/0_PLEASE_SYMLINK.txt: -------------------------------------------------------------------------------- 1 | This directory should be symlinked from all plugins so that we can avoid copy-pasting the contents. 2 | 3 | Package plugins cannot have dependencies, so this is a way to share sources common between all the plugins. -------------------------------------------------------------------------------- /Plugins/PluginsShared/JavaKitConfigurationShared: -------------------------------------------------------------------------------- 1 | ../../Sources/JavaKitConfigurationShared -------------------------------------------------------------------------------- /Plugins/PluginsShared/SwiftJavaPlugin+Errors.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | enum SwiftJavaPluginError: Error { 16 | case missingConfiguration(sourceDir: String, key: String?, file: String = #file, line: UInt = #line) 17 | } 18 | -------------------------------------------------------------------------------- /Plugins/PluginsShared/SwiftJavaPluginProtocol.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | protocol SwiftJavaPluginProtocol { 16 | var verbose: Bool { get } 17 | var pluginName: String { get } 18 | 19 | func log(_ message: @autoclosure () -> String, terminator: String) 20 | } 21 | 22 | extension SwiftJavaPluginProtocol { 23 | func log(_ message: @autoclosure () -> String, terminator: String = "\n") { 24 | // if self.verbose { 25 | print("[\(pluginName)] \(message())", terminator: terminator) 26 | // } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/dummy.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "org.apache.commons.io.FilenameUtils" : "FilenameUtils", 4 | "org.apache.commons.io.IOCase" : "IOCase", 5 | "org.apache.commons.csv.CSVFormat" : "CSVFormat", 6 | "org.apache.commons.csv.CSVParser" : "CSVParser", 7 | "org.apache.commons.csv.CSVRecord" : "CSVRecord" 8 | }, 9 | "dependencies" : [ 10 | "org.apache.commons:commons-csv:1.12.0" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/Sources/JavaDependencySample/main.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | import JavaKitFunction 17 | import JavaKitIO 18 | import JavaKitConfigurationShared 19 | import Foundation 20 | 21 | // Import the commons-csv library wrapper: 22 | import JavaCommonsCSV 23 | 24 | print("") 25 | print("") 26 | print("-----------------------------------------------------------------------") 27 | print("Start Sample app...") 28 | 29 | // TODO: locating the classpath is more complex, need to account for dependencies of our module 30 | let swiftJavaClasspath = findSwiftJavaClasspaths() // scans for .classpath files 31 | 32 | // 1) Start a JVM with appropriate classpath 33 | let jvm = try JavaVirtualMachine.shared(classpath: swiftJavaClasspath) 34 | 35 | // 2) Get the FilenameUtils Java class so we can call the static methods on it 36 | let FilenameUtilsClass = try JavaClass() 37 | 38 | // Some silly sample path we want to work with: 39 | let path = "/example/path/executable.exe" 40 | print("Path = \(path)") 41 | 42 | let ext = try! FilenameUtilsClass.getExtension(path) 43 | print("org.apache.commons.io.FilenameUtils.getExtension = \(ext)") 44 | precondition(ext == "exe") 45 | 46 | let CSVFormatClass = try JavaClass() 47 | 48 | let reader = StringReader("hello,example") 49 | for record in try CSVFormatClass.RFC4180.parse(reader)!.getRecords()! { 50 | for field in record.toList()! { 51 | print("Field: \(field)") 52 | } 53 | } 54 | 55 | print("Done.") 56 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/Sources/JavaDependencySample/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/Sources/JavaExample/JavaExample.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) YEARS Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/ci-validate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -x 5 | 6 | swift run --disable-sandbox 7 | -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle/ -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /Samples/JavaDependencySampleApp/gradlew.bat: -------------------------------------------------------------------------------- 1 | ../../gradlew.bat -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/com/example/swift/HelloSubclass.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | public class HelloSubclass extends HelloSwift { 18 | private String greeting; 19 | 20 | public HelloSubclass(String greeting) { 21 | this.greeting = greeting; 22 | } 23 | 24 | public void greetMe() { 25 | super.greet(greeting); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/com/example/swift/HelloSwift.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | import java.util.function.Predicate; 18 | 19 | public class HelloSwift { 20 | public double value; 21 | public static double initialValue = 3.14159; 22 | public String name = "Java"; 23 | 24 | static { 25 | System.loadLibrary("JavaKitExample"); 26 | } 27 | 28 | public HelloSwift() { 29 | this.value = initialValue; 30 | } 31 | 32 | native int sayHello(int x, int y); 33 | native String throwMessageFromSwift(String message) throws Exception; 34 | 35 | // To be called back by the native code 36 | public double sayHelloBack(int i) { 37 | System.out.println("And hello back from " + name + "! You passed me " + i); 38 | return value; 39 | } 40 | 41 | public void greet(String name) { 42 | System.out.println("Salutations, " + name); 43 | } 44 | 45 | public Predicate lessThanTen() { 46 | Predicate predicate = i -> (i < 10); 47 | return predicate; 48 | } 49 | 50 | public String[] doublesToStrings(double[] doubles) { 51 | int size = doubles.length; 52 | String[] strings = new String[size]; 53 | 54 | for(int i = 0; i < size; i++) { 55 | strings[i] = "" + doubles[i]; 56 | } 57 | 58 | return strings; 59 | } 60 | 61 | public void throwMessage(String message) throws Exception { 62 | throw new Exception(message); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/com/example/swift/JavaKitSampleMain.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | /** 18 | * This sample shows off a {@link HelloSwift} type which is partially implemented in Swift. 19 | * For the Swift implementation refer to 20 | */ 21 | public class JavaKitSampleMain { 22 | public static void main(String[] args) { 23 | int result = new HelloSubclass("Swift").sayHello(17, 25); 24 | System.out.println("sayHello(17, 25) = " + result); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/com/example/swift/ThreadSafe.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | 20 | @Retention(RetentionPolicy.RUNTIME) 21 | public @interface ThreadSafe { 22 | } 23 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/com/example/swift/ThreadSafeHelperClass.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | import java.util.Optional; 18 | import java.util.OptionalLong; 19 | import java.util.OptionalInt; 20 | import java.util.OptionalDouble; 21 | 22 | @ThreadSafe 23 | public class ThreadSafeHelperClass { 24 | public ThreadSafeHelperClass() { } 25 | 26 | public Optional text = Optional.of(""); 27 | 28 | public final OptionalDouble val = OptionalDouble.of(2); 29 | 30 | public String getValue(Optional name) { 31 | return name.orElse(""); 32 | } 33 | 34 | public Optional getText() { 35 | return text; 36 | } 37 | 38 | public OptionalLong from(OptionalInt value) { 39 | return OptionalLong.of(value.getAsInt()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/Sources/JavaKitExample/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "com.example.swift.HelloSwift" : "HelloSwift", 4 | "com.example.swift.HelloSubclass" : "HelloSubclass", 5 | "com.example.swift.JavaKitSampleMain" : "JavaKitSampleMain", 6 | "com.example.swift.ThreadSafeHelperClass" : "ThreadSafeHelperClass" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Samples/JavaKitSampleApp/ci-validate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -x 5 | 6 | swift build 7 | "$JAVA_HOME/bin/java" \ 8 | -cp .build/plugins/outputs/javakitsampleapp/JavaKitExample/destination/JavaCompilerPlugin/Java \ 9 | -Djava.library.path=.build/debug \ 10 | "com.example.swift.JavaKitSampleMain" 11 | -------------------------------------------------------------------------------- /Samples/JavaProbablyPrime/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 6.0 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import CompilerPluginSupport 5 | import PackageDescription 6 | 7 | let package = Package( 8 | name: "JavaProbablyPrime", 9 | platforms: [ 10 | .macOS(.v10_15), 11 | ], 12 | 13 | products: [ 14 | .executable( 15 | name: "JavaProbablyPrime", 16 | targets: ["JavaProbablyPrime"] 17 | ), 18 | ], 19 | 20 | dependencies: [ 21 | .package(name: "swift-java", path: "../../"), 22 | .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), 23 | ], 24 | 25 | targets: [ 26 | .executableTarget( 27 | name: "JavaProbablyPrime", 28 | dependencies: [ 29 | .product(name: "JavaKitCollection", package: "swift-java"), 30 | .product(name: "JavaKit", package: "swift-java"), 31 | .product(name: "ArgumentParser", package: "swift-argument-parser"), 32 | ], 33 | swiftSettings: [ 34 | .swiftLanguageMode(.v5) 35 | ], 36 | plugins: [ 37 | .plugin(name: "Java2SwiftPlugin", package: "swift-java"), 38 | ] 39 | ), 40 | ] 41 | ) 42 | -------------------------------------------------------------------------------- /Samples/JavaProbablyPrime/README.md: -------------------------------------------------------------------------------- 1 | # JavaKit Example: Using Java APIs from Swift 2 | 3 | This package contains an example program that uses Java's [`java.math.BigInteger`](https://docs.oracle.com/javase/8/docs/api/?java/math/BigInteger.html) from Swift to determine whether a given number is probably prime. You can try it out with your own very big number: 4 | 5 | ``` 6 | swift run JavaProbablyPrime 7 | ``` 8 | 9 | The package itself demonstrates how to: 10 | 11 | * Use the Java2Swift build tool plugin to wrap the `java.math.BigInteger` type in Swift. 12 | * Create an instance of `BigInteger` in Swift and use its `isProbablyPrime`. 13 | -------------------------------------------------------------------------------- /Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/prime.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import ArgumentParser 16 | import JavaKit 17 | 18 | @main 19 | struct ProbablyPrime: ParsableCommand { 20 | @Argument(help: "The number to check for primality") 21 | var number: String 22 | 23 | @Option(help: "The certainty to require in the prime check") 24 | var certainty: Int32 = 10 25 | 26 | func run() throws { 27 | let bigInt = BigInteger(number) 28 | if bigInt.isProbablePrime(certainty) { 29 | print("\(number) is probably prime") 30 | } else { 31 | print("\(number) is definitely not prime") 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.math.BigInteger" : "BigInteger" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Samples/JavaProbablyPrime/ci-validate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -x 5 | 6 | swift run JavaProbablyPrime 1337 -------------------------------------------------------------------------------- /Samples/JavaSieve/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .netrc 9 | quadratic-sieve-Java -------------------------------------------------------------------------------- /Samples/JavaSieve/README.md: -------------------------------------------------------------------------------- 1 | # JavaKit Example: Using a Java library from Swift 2 | 3 | This package contains an example program that demonstrates importing a Java library distributed as a Jar file into Swift and using some APIs from that library. It demonstrates how to: 4 | 5 | * Use the Java2Swift tool to discover the classes in a Jar file and make them available in Swift 6 | * Layer Swift wrappers for Java classes as separate Swift modules using Java2Swift 7 | * Access static methods of Java classes from Swift 8 | 9 | This example wraps an [open-source Java library](https://github.com/gazman-sdk/quadratic-sieve-Java) implementing the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) algorithm for finding prime numbers, among other algorithms. To get started, clone that repository and build a Jar file containing the library: 10 | 11 | ``` 12 | git clone https://github.com/gazman-sdk/quadratic-sieve-Java 13 | cd quadratic-sieve-Java 14 | sh ./gradlew jar 15 | cd .. 16 | ``` 17 | 18 | Now we're ready to build and run the Swift program from `Samples/JavaSieve`: 19 | 20 | ``` 21 | swift run JavaSieve 22 | ``` 23 | 24 | The core of the example code is in `Sources/JavaSieve/main.swift`, using the static Java method `SieveOfEratosthenes.findPrimes`: 25 | 26 | ```swift 27 | let sieveClass = try JavaClass(in: jvm.environment()) 28 | for prime in sieveClass.findPrimes(100)! { 29 | print("Found prime: \(prime.intValue())") 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /Samples/JavaSieve/Sources/JavaMath/dummy.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | -------------------------------------------------------------------------------- /Samples/JavaSieve/Sources/JavaMath/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.math.BigDecimal" : "BigDecimal", 4 | "java.math.BigInteger" : "BigInteger", 5 | "java.math.MathContext" : "MathContext", 6 | "java.math.RoundingMode" : "RoundingMode" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Samples/JavaSieve/Sources/JavaSieve/main.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | import JavaMath 17 | 18 | let jvm = try JavaVirtualMachine.shared(classpath: [ 19 | "quadratic-sieve-Java/build/libs/QuadraticSieve-1.0.jar", 20 | ".", 21 | ]) 22 | 23 | do { 24 | let sieveClass = try JavaClass(environment: jvm.environment()) 25 | for prime in sieveClass.findPrimes(100)! { 26 | print("Found prime: \(prime.intValue())") 27 | } 28 | 29 | try JavaClass().HALF_UP 30 | } catch { 31 | print("Failure: \(error)") 32 | } 33 | -------------------------------------------------------------------------------- /Samples/JavaSieve/Sources/JavaSieve/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classpath" : ".:quadratic-sieve-Java/build/libs/QuadraticSieve-1.0.jar", 3 | "classes" : { 4 | "com.gazman.quadratic_sieve.QuadraticSieve" : "QuadraticSieve", 5 | "com.gazman.quadratic_sieve.core.BaseFact" : "BaseFact", 6 | "com.gazman.quadratic_sieve.core.matrix.GaussianEliminationMatrix" : "GaussianEliminationMatrix", 7 | "com.gazman.quadratic_sieve.core.matrix.Matrix" : "Matrix", 8 | "com.gazman.quadratic_sieve.core.poly.PolyMiner" : "PolyMiner", 9 | "com.gazman.quadratic_sieve.core.poly.WheelPool" : "WheelPool", 10 | "com.gazman.quadratic_sieve.core.siever.BSmoothData" : "BSmoothData", 11 | "com.gazman.quadratic_sieve.core.siever.BSmoothDataPool" : "BSmoothDataPool", 12 | "com.gazman.quadratic_sieve.core.siever.Siever" : "Siever", 13 | "com.gazman.quadratic_sieve.core.siever.VectorExtractor" : "VectorExtractor", 14 | "com.gazman.quadratic_sieve.data.BSmooth" : "BSmooth", 15 | "com.gazman.quadratic_sieve.data.DataQueue" : "DataQueue", 16 | "com.gazman.quadratic_sieve.data.MagicNumbers" : "MagicNumbers", 17 | "com.gazman.quadratic_sieve.data.PolynomialData" : "PolynomialData", 18 | "com.gazman.quadratic_sieve.data.PrimeBase" : "PrimeBase", 19 | "com.gazman.quadratic_sieve.data.VectorData" : "VectorData", 20 | "com.gazman.quadratic_sieve.data.VectorWorkData" : "VectorWorkData", 21 | "com.gazman.quadratic_sieve.debug.Analytics" : "Analytics", 22 | "com.gazman.quadratic_sieve.debug.AssertUtils" : "AssertUtils", 23 | "com.gazman.quadratic_sieve.debug.AssertUtils$Tester" : "AssertUtils.Tester", 24 | "com.gazman.quadratic_sieve.debug.Logger" : "Logger", 25 | "com.gazman.quadratic_sieve.fact.TrivialDivision" : "TrivialDivision", 26 | "com.gazman.quadratic_sieve.primes.BigPrimes" : "BigPrimes", 27 | "com.gazman.quadratic_sieve.primes.SieveOfEratosthenes" : "SieveOfEratosthenes", 28 | "com.gazman.quadratic_sieve.utils.MathUtils" : "MathUtils", 29 | "com.gazman.quadratic_sieve.wheel.Wheel" : "Wheel" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Samples/JavaSieve/ci-validate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This sample is not verified in CI because old Gradle in the project making it hard to use its ./gradlew" -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/Example.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import com.example.swift.MySwiftLibrary; 16 | 17 | public class Example { 18 | 19 | public static void main(String[] args) { 20 | MySwiftLibrary.helloWorld(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/Sources/MySwiftLibrary/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "javaPackage": "com.example.swift" 3 | } 4 | -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/gradlew.bat: -------------------------------------------------------------------------------- 1 | ../../gradlew.bat -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/src/main/java/com/example/swift/HelloJava2Swift.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | // Import swift-extract generated sources 18 | 19 | import com.example.swift.MySwiftLibrary; 20 | import com.example.swift.MySwiftClass; 21 | 22 | // Import javakit/swiftkit support libraries 23 | import org.swift.swiftkit.SwiftArena; 24 | import org.swift.swiftkit.SwiftKit; 25 | import org.swift.swiftkit.SwiftValueWitnessTable; 26 | 27 | import java.util.Arrays; 28 | 29 | public class HelloJava2Swift { 30 | 31 | public static void main(String[] args) { 32 | boolean traceDowncalls = Boolean.getBoolean("jextract.trace.downcalls"); 33 | System.out.println("Property: jextract.trace.downcalls = " + traceDowncalls); 34 | 35 | System.out.print("Property: java.library.path = " +SwiftKit.getJavaLibraryPath()); 36 | 37 | examples(); 38 | } 39 | 40 | static void examples() { 41 | MySwiftLibrary.helloWorld(); 42 | 43 | MySwiftLibrary.globalTakeInt(1337); 44 | 45 | // Example of using an arena; MyClass.deinit is run at end of scope 46 | try (var arena = SwiftArena.ofConfined()) { 47 | MySwiftClass obj = MySwiftClass.init(2222, 7777, arena); 48 | 49 | // just checking retains/releases work 50 | SwiftKit.retain(obj); 51 | SwiftKit.release(obj); 52 | 53 | obj.voidMethod(); 54 | obj.takeIntMethod(42); 55 | } 56 | 57 | System.out.println("DONE."); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/src/test/java/com/example/swift/MySwiftLibraryTest.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package com.example.swift; 16 | 17 | import org.junit.jupiter.api.BeforeAll; 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | import org.swift.swiftkit.SwiftKit; 21 | 22 | import java.util.Arrays; 23 | import java.util.concurrent.CountDownLatch; 24 | import java.util.stream.Collectors; 25 | 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class MySwiftLibraryTest { 29 | 30 | @Test 31 | void call_helloWorld() { 32 | MySwiftLibrary.helloWorld(); 33 | } 34 | 35 | @Test 36 | void call_globalTakeInt() { 37 | MySwiftLibrary.globalTakeInt(12); 38 | } 39 | 40 | @Test 41 | @Disabled("Upcalls not yet implemented in new scheme") 42 | @SuppressWarnings({"Convert2Lambda", "Convert2MethodRef"}) 43 | void call_globalCallMeRunnable() { 44 | CountDownLatch countDownLatch = new CountDownLatch(3); 45 | 46 | MySwiftLibrary.globalCallMeRunnable(new Runnable() { 47 | @Override 48 | public void run() { 49 | countDownLatch.countDown(); 50 | } 51 | }); 52 | assertEquals(2, countDownLatch.getCount()); 53 | 54 | MySwiftLibrary.globalCallMeRunnable(() -> countDownLatch.countDown()); 55 | assertEquals(1, countDownLatch.getCount()); 56 | 57 | MySwiftLibrary.globalCallMeRunnable(countDownLatch::countDown); 58 | assertEquals(0, countDownLatch.getCount()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/src/test/java/org/swift/swiftkit/MySwiftClassTest.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import com.example.swift.MySwiftClass; 22 | 23 | public class MySwiftClassTest { 24 | 25 | @Test 26 | void call_retain_retainCount_release() { 27 | var arena = SwiftArena.ofConfined(); 28 | var obj = MySwiftClass.init(1, 2, arena); 29 | 30 | assertEquals(1, SwiftKit.retainCount(obj)); 31 | // TODO: test directly on SwiftHeapObject inheriting obj 32 | 33 | SwiftKit.retain(obj); 34 | assertEquals(2, SwiftKit.retainCount(obj)); 35 | 36 | SwiftKit.release(obj); 37 | assertEquals(1, SwiftKit.retainCount(obj)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Samples/SwiftAndJavaJarSampleLib/src/test/java/org/swift/swiftkit/SwiftArenaTest.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import com.example.swift.MySwiftClass; 18 | import org.junit.jupiter.api.BeforeAll; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.condition.DisabledIf; 21 | import org.swift.swiftkit.util.PlatformUtils; 22 | 23 | import java.util.Arrays; 24 | import java.util.stream.Collectors; 25 | 26 | import static org.junit.jupiter.api.Assertions.*; 27 | import static org.swift.swiftkit.SwiftKit.*; 28 | import static org.swift.swiftkit.SwiftKit.retainCount; 29 | 30 | public class SwiftArenaTest { 31 | 32 | static boolean isAmd64() { 33 | return PlatformUtils.isAmd64(); 34 | } 35 | 36 | // FIXME: The destroy witness table call hangs on x86_64 platforms during the destroy witness table call 37 | // See: https://github.com/swiftlang/swift-java/issues/97 38 | @Test 39 | @DisabledIf("isAmd64") 40 | public void arena_releaseClassOnClose_class_ok() { 41 | try (var arena = SwiftArena.ofConfined()) { 42 | var obj = MySwiftClass.init(1, 2, arena); 43 | 44 | retain(obj); 45 | assertEquals(2, retainCount(obj)); 46 | 47 | release(obj); 48 | assertEquals(1, retainCount(obj)); 49 | } 50 | 51 | // TODO: should we zero out the $memorySegment perhaps? 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/MySwiftClass.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | public class MySwiftClass { 16 | 17 | public var len: Int 18 | public var cap: Int 19 | 20 | public init(len: Int, cap: Int) { 21 | self.len = len 22 | self.cap = cap 23 | 24 | p("\(MySwiftClass.self).len = \(self.len)") 25 | p("\(MySwiftClass.self).cap = \(self.cap)") 26 | let addr = unsafeBitCast(self, to: UInt64.self) 27 | p("initializer done, self = 0x\(String(addr, radix: 16, uppercase: true))") 28 | } 29 | 30 | deinit { 31 | let addr = unsafeBitCast(self, to: UInt64.self) 32 | p("Deinit, self = 0x\(String(addr, radix: 16, uppercase: true))") 33 | } 34 | 35 | public var counter: Int32 = 0 36 | 37 | public static func factory(len: Int, cap: Int) -> MySwiftClass { 38 | return MySwiftClass(len: len, cap: cap) 39 | } 40 | 41 | public func voidMethod() { 42 | p("") 43 | } 44 | 45 | public func takeIntMethod(i: Int) { 46 | p("i:\(i)") 47 | } 48 | 49 | public func echoIntMethod(i: Int) -> Int { 50 | p("i:\(i)") 51 | return i 52 | } 53 | 54 | public func makeIntMethod() -> Int { 55 | p("make int -> 12") 56 | return 12 57 | } 58 | 59 | public func makeRandomIntMethod() -> Int { 60 | return Int.random(in: 1..<256) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/MySwiftLibrary.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | // This is a "plain Swift" file containing various types of declarations, 16 | // that is exported to Java by using the `jextract-swift` tool. 17 | // 18 | // No annotations are necessary on the Swift side to perform the export. 19 | 20 | #if os(Linux) 21 | import Glibc 22 | #else 23 | import Darwin.C 24 | #endif 25 | 26 | public func helloWorld() { 27 | p("\(#function)") 28 | } 29 | 30 | public func globalTakeInt(i: Int) { 31 | p("i:\(i)") 32 | } 33 | 34 | public func globalMakeInt() -> Int { 35 | return 42 36 | } 37 | 38 | public func globalWriteString(string: String) -> Int { 39 | return string.count 40 | } 41 | 42 | public func globalTakeIntInt(i: Int, j: Int) { 43 | p("i:\(i), j:\(j)") 44 | } 45 | 46 | public func globalCallMeRunnable(run: () -> ()) { 47 | run() 48 | } 49 | 50 | // ==== Internal helpers 51 | 52 | func p(_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function) { 53 | print("[swift][\(file):\(line)](\(function)) \(msg)") 54 | fflush(stdout) 55 | } 56 | 57 | #if os(Linux) 58 | // FIXME: why do we need this workaround? 59 | @_silgen_name("_objc_autoreleaseReturnValue") 60 | public func _objc_autoreleaseReturnValue(a: Any) {} 61 | 62 | @_silgen_name("objc_autoreleaseReturnValue") 63 | public func objc_autoreleaseReturnValue(a: Any) {} 64 | #endif 65 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/MySwiftStruct.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | public struct MySwiftStruct { 16 | 17 | private var cap: Int 18 | private var len: Int 19 | 20 | public init(cap: Int, len: Int) { 21 | self.cap = cap 22 | self.len = len 23 | } 24 | 25 | public func voidMethod() { 26 | p("") 27 | } 28 | 29 | public func takeIntMethod(i: Int) { 30 | p("i:\(i)") 31 | } 32 | 33 | public func echoIntMethod(i: Int) -> Int { 34 | p("i:\(i)") 35 | return i 36 | } 37 | 38 | public func makeIntMethod() -> Int { 39 | p("make int -> 12") 40 | return 12 41 | } 42 | 43 | public func getCapacity() -> Int { 44 | self.cap 45 | } 46 | 47 | public func getLength() -> Int { 48 | self.len 49 | } 50 | 51 | public mutating func increaseCap(by value: Int) -> Int { 52 | precondition(value > 0) 53 | self.cap += value 54 | return self.cap 55 | } 56 | 57 | public func makeRandomIntMethod() -> Int { 58 | return Int.random(in: 1..<256) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/_RuntimeWorkarounds.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #if os(Linux) 16 | // FIXME: why do we need this workaround? 17 | @_silgen_name("_objc_autoreleaseReturnValue") 18 | public func _objc_autoreleaseReturnValue(a: Any) {} 19 | 20 | @_silgen_name("objc_autoreleaseReturnValue") 21 | public func objc_autoreleaseReturnValue(a: Any) {} 22 | #endif 23 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/jni/JNIImplementations.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | import JavaRuntime 17 | 18 | @JavaClass("com.example.swift.HelloJava2Swift") 19 | open class HelloJava2Swift: JavaObject { 20 | } 21 | 22 | extension JavaClass { 23 | } 24 | 25 | /// Describes the Java `native` methods for ``HelloJava2Swift``. 26 | /// 27 | /// To implement all of the `native` methods for HelloSwift in Swift, 28 | /// extend HelloSwift to conform to this protocol and mark each 29 | /// implementation of the protocol requirement with `@JavaMethod`. 30 | protocol HelloJava2SwiftNativeMethods { 31 | func jniWriteString(_ message: String) -> Int32 32 | func jniGetInt() -> Int32 33 | } 34 | 35 | @JavaImplementation("com.example.swift.HelloJava2Swift") 36 | extension HelloJava2Swift: HelloJava2SwiftNativeMethods { 37 | @JavaMethod 38 | func jniWriteString(_ message: String) -> Int32 { 39 | return Int32(message.count) 40 | } 41 | 42 | @JavaMethod 43 | func jniGetInt() -> Int32 { 44 | return 12 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "javaPackage": "com.example.swift" 3 | } 4 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/gradlew.bat: -------------------------------------------------------------------------------- 1 | ../../gradlew.bat -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/MySwiftClassTest.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import com.example.swift.MySwiftClass; 22 | 23 | public class MySwiftClassTest { 24 | 25 | @Test 26 | void call_retain_retainCount_release() { 27 | var arena = SwiftArena.ofConfined(); 28 | var obj = MySwiftClass.init(1, 2, arena); 29 | 30 | assertEquals(1, SwiftKit.retainCount(obj)); 31 | // TODO: test directly on SwiftHeapObject inheriting obj 32 | 33 | SwiftKit.retain(obj); 34 | assertEquals(2, SwiftKit.retainCount(obj)); 35 | 36 | SwiftKit.release(obj); 37 | assertEquals(1, SwiftKit.retainCount(obj)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/MySwiftStructTest.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import com.example.swift.MySwiftStruct; 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | public class MySwiftStructTest { 23 | 24 | @Test 25 | void create_struct() { 26 | try (var arena = SwiftArena.ofConfined()) { 27 | long cap = 12; 28 | long len = 34; 29 | var struct = MySwiftStruct.init(cap, len, arena); 30 | 31 | assertEquals(cap, struct.getCapacity()); 32 | assertEquals(len, struct.getLength()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Samples/gradle: -------------------------------------------------------------------------------- 1 | ../gradle -------------------------------------------------------------------------------- /Samples/gradlew: -------------------------------------------------------------------------------- 1 | ../gradlew -------------------------------------------------------------------------------- /Sources/JExtractSwift/CTypes/CEnum.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes a C enum type. 16 | public class CEnum { 17 | public var name: String 18 | public init(name: String) { 19 | self.name = name 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/CTypes/CParameter.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes a parameter to a C function. 16 | public struct CParameter { 17 | /// The name of the parameter, if provided. 18 | public var name: String? 19 | 20 | /// The type of the parameter. 21 | public var type: CType 22 | 23 | public init(name: String? = nil, type: CType) { 24 | self.name = name 25 | self.type = type 26 | } 27 | } 28 | 29 | extension CParameter: CustomStringConvertible { 30 | public var description: String { 31 | type.print(placeholder: name ?? "") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/CTypes/CStruct.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes a C struct type. 16 | public class CStruct { 17 | public var name: String 18 | 19 | public init(name: String) { 20 | self.name = name 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/CTypes/CTag.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes a tag type in C, which is either a struct or an enum. 16 | public enum CTag { 17 | case `struct`(CStruct) 18 | case `enum`(CEnum) 19 | case `union`(CUnion) 20 | 21 | public var name: String { 22 | switch self { 23 | case .struct(let cStruct): return cStruct.name 24 | case .enum(let cEnum): return cEnum.name 25 | case .union(let cUnion): return cUnion.name 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/CTypes/CUnion.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes a C union type. 16 | public class CUnion { 17 | public var name: String 18 | public init(name: String) { 19 | self.name = name 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/Convenience/Collection+Extensions.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | public extension Dictionary { 16 | /// Same values, corresponding to mapped keys. 17 | func mapKeys( 18 | _ transform: (Key) throws -> Transformed 19 | ) rethrows -> [Transformed: Value] { 20 | .init( 21 | uniqueKeysWithValues: try map { 22 | (try transform($0.key), $0.value) 23 | } 24 | ) 25 | } 26 | 27 | } 28 | 29 | extension Collection { 30 | typealias IsLastElement = Bool 31 | var withIsLast: any Collection<(Element, IsLastElement)> { 32 | var i = 1 33 | let totalCount = self.count 34 | 35 | return self.map { element in 36 | let isLast = i == totalCount 37 | i += 1 38 | return (element, isLast) 39 | } 40 | } 41 | } 42 | 43 | extension Collection where Element == Int { 44 | var sum: Int { 45 | var s = 0 46 | for i in self { 47 | s += i 48 | } 49 | return s 50 | } 51 | } -------------------------------------------------------------------------------- /Sources/JExtractSwift/Convenience/String+Extensions.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension String { 16 | 17 | // TODO: naive implementation good enough for our simple case `methodMethodSomething` -> `MethodSomething` 18 | var toCamelCase: String { 19 | guard let f = first else { 20 | return self 21 | } 22 | 23 | return "\(f.uppercased())\(String(dropFirst()))" 24 | } 25 | } -------------------------------------------------------------------------------- /Sources/JExtractSwift/JavaConstants/JavaTypes.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaTypes 16 | 17 | extension JavaType { 18 | /// The description of the type java.lang.foreign.MemorySegment. 19 | static var javaForeignMemorySegment: JavaType { 20 | .class(package: "java.lang.foreign", name: "MemorySegment") 21 | } 22 | 23 | /// The description of the type java.lang.String. 24 | static var javaLangString: JavaType { 25 | .class(package: "java.lang", name: "String") 26 | } 27 | 28 | /// The description of the type java.lang.Runnable. 29 | static var javaLangRunnable: JavaType { 30 | .class(package: "java.lang", name: "Runnable") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/SwiftKit+Printing.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import Foundation 16 | import SwiftBasicFormat 17 | import SwiftParser 18 | import SwiftSyntax 19 | 20 | /// Helper for printing calls into SwiftKit generated code from generated sources. 21 | package struct SwiftKitPrinting { 22 | 23 | /// Forms syntax for a Java call to a swiftkit exposed function. 24 | static func renderCallGetSwiftType(module: String, nominal: ImportedNominalType) -> String { 25 | """ 26 | SwiftKit.swiftjava.getType("\(module)", "\(nominal.swiftNominal.qualifiedName)") 27 | """ 28 | } 29 | } 30 | 31 | // ==== ------------------------------------------------------------------------ 32 | // Helpers to form names of "well known" SwiftKit generated functions 33 | 34 | extension SwiftKitPrinting { 35 | enum Names { 36 | } 37 | } 38 | 39 | extension SwiftKitPrinting.Names { 40 | static func getType(module: String, nominal: ImportedNominalType) -> String { 41 | "swiftjava_getType_\(module)_\(nominal.swiftNominal.qualifiedName)" 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/SwiftTypes/SwiftModuleSymbolTable.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import SwiftSyntax 16 | import SwiftSyntaxBuilder 17 | 18 | struct SwiftModuleSymbolTable: SwiftSymbolTableProtocol { 19 | /// The name of this module. 20 | let moduleName: String 21 | 22 | /// The top-level nominal types, found by name. 23 | var topLevelTypes: [String: SwiftNominalTypeDeclaration] = [:] 24 | 25 | /// The nested types defined within this module. The map itself is indexed by the 26 | /// identifier of the nominal type declaration, and each entry is a map from the nested 27 | /// type name to the nominal type declaration. 28 | var nestedTypes: [SwiftNominalTypeDeclaration: [String: SwiftNominalTypeDeclaration]] = [:] 29 | 30 | /// Look for a top-level type with the given name. 31 | func lookupTopLevelNominalType(_ name: String) -> SwiftNominalTypeDeclaration? { 32 | topLevelTypes[name] 33 | } 34 | 35 | // Look for a nested type with the given name. 36 | func lookupNestedType(_ name: String, parent: SwiftNominalTypeDeclaration) -> SwiftNominalTypeDeclaration? { 37 | nestedTypes[parent]?[name] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/JExtractSwift/SwiftTypes/SwiftResult.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import SwiftSyntax 16 | 17 | struct SwiftResult: Equatable { 18 | var convention: SwiftResultConvention // currently not used. 19 | var type: SwiftType 20 | } 21 | 22 | enum SwiftResultConvention: Equatable { 23 | case direct 24 | case indirect 25 | } 26 | 27 | extension SwiftResult { 28 | static var void: Self { 29 | return Self(convention: .direct, type: .void) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/JExtractSwiftTool/JExtractSwiftTool.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JExtractSwift 16 | 17 | @main 18 | struct JExtractSwift { 19 | static func main() throws { 20 | let command = SwiftToJava.parseOrExit(CommandLine.arguments) 21 | try command.run() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/Java2Swift/String+Extensions.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import Foundation 16 | import ArgumentParser 17 | import Java2SwiftLib 18 | import JavaKit 19 | import JavaKitJar 20 | import Java2SwiftLib 21 | import JavaKitConfigurationShared 22 | 23 | extension String { 24 | /// For a String that's of the form java.util.Vector, return the "Vector" 25 | /// part. 26 | var defaultSwiftNameForJavaClass: String { 27 | if let dotLoc = lastIndex(of: ".") { 28 | let afterDot = index(after: dotLoc) 29 | return String(self[afterDot...]).javaClassNameToCanonicalName.adjustedSwiftTypeName 30 | } 31 | 32 | return javaClassNameToCanonicalName.adjustedSwiftTypeName 33 | } 34 | } 35 | 36 | extension String { 37 | /// Replace all of the $'s for nested names with "." to turn a Java class 38 | /// name into a Java canonical class name, 39 | var javaClassNameToCanonicalName: String { 40 | return replacing("$", with: ".") 41 | } 42 | 43 | /// Whether this is the name of an anonymous class. 44 | var isLocalJavaClass: Bool { 45 | for segment in split(separator: "$") { 46 | if let firstChar = segment.first, firstChar.isNumber { 47 | return true 48 | } 49 | } 50 | 51 | return false 52 | } 53 | 54 | /// Adjust type name for "bad" type names that don't work well in Swift. 55 | var adjustedSwiftTypeName: String { 56 | switch self { 57 | case "Type": return "JavaType" 58 | default: return self 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Sources/Java2SwiftLib/JavaTranslator+Configuration.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import Foundation 16 | import JavaKitConfigurationShared 17 | 18 | extension JavaTranslator { 19 | /// Read a configuration file from the given URL. 20 | package static func readConfiguration(from url: URL) throws -> Configuration { 21 | let contents = try Data(contentsOf: url) 22 | return try JSONDecoder().decode(Configuration.self, from: contents) 23 | } 24 | 25 | /// Load the configuration file with the given name to populate the known set of 26 | /// translated Java classes. 27 | package func addConfiguration(_ config: Configuration, forSwiftModule swiftModule: String) { 28 | guard let classes = config.classes else { 29 | return 30 | } 31 | 32 | for (javaClassName, swiftName) in classes { 33 | translatedClasses[javaClassName] = ( 34 | swiftType: swiftName, 35 | swiftModule: swiftModule 36 | ) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/Java2SwiftLib/OptionalKind.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes the kind of optional type to use. 16 | enum OptionalKind { 17 | /// The value is nonoptional. 18 | case nonoptional 19 | 20 | /// The value is optional. 21 | case optional 22 | 23 | /// The value uses an implicitly-unwrapped optional. 24 | case implicitlyUnwrappedOptional 25 | 26 | /// Adjust the given type name string based on the optionality of this type. 27 | func adjustTypeName(_ string: String) -> String { 28 | switch self { 29 | case .implicitlyUnwrappedOptional: return string + "!" 30 | case .optional: return string + "?" 31 | case .nonoptional: return string 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/Java2SwiftLib/TranslationError.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKitReflection 16 | 17 | /// Errors that can occur when translating Java types into Swift. 18 | enum TranslationError: Error { 19 | /// The given Java class has not been translated into Swift. 20 | case untranslatedJavaClass(String) 21 | 22 | /// Unhandled Java type 23 | case unhandledJavaType(Type) 24 | } 25 | 26 | extension TranslationError: CustomStringConvertible { 27 | var description: String { 28 | switch self { 29 | case .untranslatedJavaClass(let name): 30 | return "Java class '\(name)' has not been translated into Swift" 31 | 32 | case .unhandledJavaType(let type): 33 | return "Unhandled Java type \(type.getTypeName())" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/JavaKit/Exceptions/Exception+Error.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension JavaClass { 16 | /// Determine whether this instance is a checked exception (which must be 17 | /// handled) vs. an unchecked exception (which is not handled). 18 | public var isCheckedException: Bool { 19 | return !self.is(RuntimeException.self) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/JavaKit/Exceptions/ExceptionHandling.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension JNIEnvironment { 16 | /// Execute a JNI call and check for an exception at the end. Translate 17 | /// any Java exception into an error. 18 | func translatingJNIExceptions(body: () throws -> Result) throws -> Result { 19 | let result = try body() 20 | 21 | // Check whether a Java exception occurred. 22 | if let exception = interface.ExceptionOccurred(self) { 23 | interface.ExceptionClear(self) 24 | throw Throwable(javaThis: exception, environment: self) 25 | } 26 | 27 | return result 28 | } 29 | 30 | /// Throw the given Swift error as a Java exception. 31 | public func throwAsException(_ error: some Error) { 32 | // If we're throwing something that's already a Java Throwable object, 33 | // post it directly. 34 | if let javaObject = error as? any AnyJavaObject, 35 | let throwable = javaObject.as(Throwable.self) 36 | { 37 | _ = interface.Throw(self, throwable.javaThis) 38 | return 39 | } 40 | 41 | // Otherwise, create a exception with a message. 42 | _ = try! JavaClass.withJNIClass(in: self) { exceptionClass in 43 | interface.ThrowNew(self, exceptionClass, String(describing: error)) 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/JavaKit/Exceptions/Throwable+Error.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | // Translate all Java Throwable instances in a Swift error. 16 | extension Throwable: Error, CustomStringConvertible { 17 | public var description: String { 18 | return toString() 19 | } 20 | } 21 | 22 | extension JavaClass { 23 | /// Determine whether this instance is a checked exception (which must be 24 | /// handled) vs. an unchecked exception (which is not handled). 25 | public var isCheckedException: Bool { 26 | return !self.is(RuntimeException.self) && !self.is(JavaError.self) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/JavaKit/JavaClass+Initialization.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaRuntime 16 | 17 | extension JavaClass { 18 | public typealias ObjectType = T 19 | 20 | /// Lookup this Java class within the given environment. 21 | @_nonoverride 22 | public convenience init(environment: JNIEnvironment? = nil) throws { 23 | let environment = try environment ?? JavaVirtualMachine.shared().environment() 24 | var javaClassHolder: JavaObjectHolder! 25 | 26 | javaClassHolder = try ObjectType.withJNIClass(in: environment) { javaClass in 27 | JavaObjectHolder(object: javaClass, environment: environment) 28 | } 29 | self.init(javaHolder: javaClassHolder) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/JavaKit/JavaEnvironment.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaRuntime 16 | 17 | extension UnsafeMutablePointer { 18 | var interface: JNINativeInterface_ { self.pointee!.pointee } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/JavaKit/JavaObject+Inheritance.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaRuntime 16 | 17 | extension AnyJavaObject { 18 | /// Look up the other class type 19 | /// 20 | /// - Returns: `nil` when either `OtherClass` isn't known to the 21 | /// Java environment or this object isn't an instance of that type. 22 | private func isInstanceOf( 23 | _ otherClass: OtherClass.Type 24 | ) -> jclass? { 25 | try? otherClass.withJNIClass(in: javaEnvironment) { otherJavaClass in 26 | if javaEnvironment.interface.IsInstanceOf( 27 | javaEnvironment, 28 | javaThis, 29 | otherJavaClass 30 | ) == 0 { 31 | return nil 32 | } 33 | 34 | return otherJavaClass 35 | } 36 | } 37 | 38 | /// Determine whether this object is an instance of a specific 39 | /// Java class. 40 | public func `is`(_ otherClass: OtherClass.Type) -> Bool { 41 | return isInstanceOf(otherClass) != nil 42 | } 43 | 44 | /// Attempt to downcast this object to a specific Java class. 45 | public func `as`(_ otherClass: OtherClass.Type) -> OtherClass? { 46 | if `is`(otherClass) { 47 | return OtherClass(javaHolder: javaHolder) 48 | } 49 | 50 | return nil 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/JavaKit/JavaObjectHolder.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaRuntime 16 | 17 | /// Stores a reference to a Java object, managing it as a global reference so 18 | /// that the Java virtual machine will not move or deallocate the object 19 | /// while this instance is live. 20 | public class JavaObjectHolder { 21 | public private(set) var object: jobject? 22 | public let environment: JNIEnvironment 23 | 24 | /// Take a reference to a Java object and promote it to a global reference 25 | /// so that the Java virtual machine will not garbage-collect it. 26 | public init(object: jobject, environment: JNIEnvironment) { 27 | self.object = environment.interface.NewGlobalRef(environment, object) 28 | self.environment = environment 29 | } 30 | 31 | /// Forget this Java object, meaning that it is no longer used from anywhere 32 | /// in Swift and the Java virtual machine is free to move or deallocate it. 33 | func forget() { 34 | if let object { 35 | environment.interface.DeleteGlobalRef(environment, object) 36 | self.object = nil 37 | } 38 | } 39 | 40 | deinit { 41 | self.forget() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/JavaKit/JavaRuntime+Reexport.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | @_exported import JavaRuntime 16 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/Appendable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaInterface("java.lang.Appendable") 5 | public struct Appendable { 6 | @JavaMethod 7 | public func append(_ arg0: CharSequence?) throws -> Appendable! 8 | 9 | @JavaMethod 10 | public func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Appendable! 11 | 12 | @JavaMethod 13 | public func append(_ arg0: UInt16) throws -> Appendable! 14 | } 15 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/CharSequence.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaInterface("java.lang.CharSequence") 5 | public struct CharSequence { 6 | @JavaMethod 7 | public func length() -> Int32 8 | 9 | @JavaMethod 10 | public func toString() -> String 11 | 12 | @JavaMethod 13 | public func charAt(_ arg0: Int32) -> UInt16 14 | 15 | @JavaMethod 16 | public func isEmpty() -> Bool 17 | 18 | @JavaMethod 19 | public func subSequence(_ arg0: Int32, _ arg1: Int32) -> CharSequence! 20 | } 21 | extension JavaClass { 22 | @JavaStaticMethod 23 | public func compare(_ arg0: CharSequence?, _ arg1: CharSequence?) -> Int32 24 | } 25 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/Exception.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Exception") 5 | open class Exception: Throwable { 6 | @JavaMethod 7 | @_nonoverride public convenience init(_ arg0: Throwable?, environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | @_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil) 11 | 12 | @JavaMethod 13 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 14 | 15 | @JavaMethod 16 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 17 | } 18 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaBoolean.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Boolean") 5 | open class JavaBoolean: JavaObject { 6 | @JavaMethod 7 | @_nonoverride public convenience init(_ arg0: Bool, environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 11 | 12 | @JavaMethod 13 | open override func equals(_ arg0: JavaObject?) -> Bool 14 | 15 | @JavaMethod 16 | open override func toString() -> String 17 | 18 | @JavaMethod 19 | open override func hashCode() -> Int32 20 | 21 | @JavaMethod 22 | open func compareTo(_ arg0: JavaBoolean?) -> Int32 23 | 24 | @JavaMethod 25 | open func compareTo(_ arg0: JavaObject?) -> Int32 26 | 27 | @JavaMethod 28 | open func booleanValue() -> Bool 29 | } 30 | extension JavaClass { 31 | @JavaStaticField(isFinal: true) 32 | public var TRUE: JavaBoolean! 33 | 34 | @JavaStaticField(isFinal: true) 35 | public var FALSE: JavaBoolean! 36 | 37 | @JavaStaticField(isFinal: true) 38 | public var TYPE: JavaClass! 39 | 40 | @JavaStaticMethod 41 | public func toString(_ arg0: Bool) -> String 42 | 43 | @JavaStaticMethod 44 | public func hashCode(_ arg0: Bool) -> Int32 45 | 46 | @JavaStaticMethod 47 | public func getBoolean(_ arg0: String) -> Bool 48 | 49 | @JavaStaticMethod 50 | public func compare(_ arg0: Bool, _ arg1: Bool) -> Int32 51 | 52 | @JavaStaticMethod 53 | public func valueOf(_ arg0: String) -> JavaBoolean! 54 | 55 | @JavaStaticMethod 56 | public func valueOf(_ arg0: Bool) -> JavaBoolean! 57 | 58 | @JavaStaticMethod 59 | public func parseBoolean(_ arg0: String) -> Bool 60 | 61 | @JavaStaticMethod 62 | public func logicalAnd(_ arg0: Bool, _ arg1: Bool) -> Bool 63 | 64 | @JavaStaticMethod 65 | public func logicalOr(_ arg0: Bool, _ arg1: Bool) -> Bool 66 | 67 | @JavaStaticMethod 68 | public func logicalXor(_ arg0: Bool, _ arg1: Bool) -> Bool 69 | } 70 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaError.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Error") 5 | open class JavaError: Throwable { 6 | @JavaMethod 7 | @_nonoverride public convenience init(_ arg0: Throwable?, environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | @_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil) 11 | 12 | @JavaMethod 13 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 14 | 15 | @JavaMethod 16 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 17 | } 18 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaNumber.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Number") 5 | open class JavaNumber: JavaObject { 6 | @JavaMethod 7 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | open func byteValue() -> Int8 11 | 12 | @JavaMethod 13 | open func shortValue() -> Int16 14 | 15 | @JavaMethod 16 | open func intValue() -> Int32 17 | 18 | @JavaMethod 19 | open func longValue() -> Int64 20 | 21 | @JavaMethod 22 | open func floatValue() -> Float 23 | 24 | @JavaMethod 25 | open func doubleValue() -> Double 26 | } 27 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaObject.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Object") 5 | open class JavaObject { 6 | @JavaMethod 7 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | open func finalize() throws 11 | 12 | @JavaMethod 13 | open func equals(_ arg0: JavaObject?) -> Bool 14 | 15 | @JavaMethod 16 | open func toString() -> String 17 | 18 | @JavaMethod 19 | open func hashCode() -> Int32 20 | 21 | @JavaMethod 22 | open func getClass() -> JavaClass! 23 | 24 | @JavaMethod 25 | open func clone() throws -> JavaObject! 26 | 27 | @JavaMethod 28 | open func notify() 29 | 30 | @JavaMethod 31 | open func notifyAll() 32 | 33 | @JavaMethod 34 | open func wait(_ arg0: Int64) throws 35 | 36 | @JavaMethod 37 | open func wait(_ arg0: Int64, _ arg1: Int32) throws 38 | 39 | @JavaMethod 40 | open func wait() throws 41 | } 42 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaOptional.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.util.Optional") 5 | open class JavaOptional: JavaObject { 6 | @JavaMethod 7 | open func get() -> JavaObject! 8 | 9 | @JavaMethod 10 | open override func equals(_ arg0: JavaObject?) -> Bool 11 | 12 | @JavaMethod 13 | open override func toString() -> String 14 | 15 | @JavaMethod 16 | open override func hashCode() -> Int32 17 | 18 | @JavaMethod 19 | open func isEmpty() -> Bool 20 | 21 | @JavaMethod 22 | open func isPresent() -> Bool 23 | 24 | @JavaMethod 25 | open func orElse(_ arg0: JavaObject?) -> JavaObject! 26 | 27 | @JavaMethod 28 | open func orElseThrow() -> JavaObject! 29 | } 30 | extension JavaClass { 31 | @JavaStaticMethod 32 | public func of(_ arg0: JavaObject?) -> JavaOptional! where ObjectType == JavaOptional 33 | 34 | public func ofOptional(_ arg0: JavaObject?) -> JavaObject? where ObjectType == JavaOptional { 35 | Optional(javaOptional: of(arg0)) 36 | } 37 | 38 | @JavaStaticMethod 39 | public func empty() -> JavaOptional! where ObjectType == JavaOptional 40 | 41 | public func emptyOptional() -> JavaObject? where ObjectType == JavaOptional { 42 | Optional(javaOptional: empty()) 43 | } 44 | 45 | @JavaStaticMethod 46 | public func ofNullable(_ arg0: JavaObject?) -> JavaOptional! where ObjectType == JavaOptional 47 | 48 | public func ofNullableOptional(_ arg0: JavaObject?) -> JavaObject? where ObjectType == JavaOptional { 49 | Optional(javaOptional: ofNullable(arg0)) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaOptionalDouble.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.util.OptionalDouble") 5 | open class JavaOptionalDouble: JavaObject { 6 | @JavaMethod 7 | open override func equals(_ arg0: JavaObject?) -> Bool 8 | 9 | @JavaMethod 10 | open override func toString() -> String 11 | 12 | @JavaMethod 13 | open override func hashCode() -> Int32 14 | 15 | @JavaMethod 16 | open func isEmpty() -> Bool 17 | 18 | @JavaMethod 19 | open func isPresent() -> Bool 20 | 21 | @JavaMethod 22 | open func orElse(_ arg0: Double) -> Double 23 | 24 | @JavaMethod 25 | open func orElseThrow() -> Double 26 | 27 | @JavaMethod 28 | open func getAsDouble() -> Double 29 | } 30 | extension JavaClass { 31 | @JavaStaticMethod 32 | public func of(_ arg0: Double) -> JavaOptionalDouble! 33 | 34 | public func ofOptional(_ arg0: Double) -> Double? { 35 | Optional(javaOptional: of(arg0)) 36 | } 37 | 38 | @JavaStaticMethod 39 | public func empty() -> JavaOptionalDouble! 40 | 41 | public func emptyOptional() -> Double? { 42 | Optional(javaOptional: empty()) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaOptionalInt.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.util.OptionalInt") 5 | open class JavaOptionalInt: JavaObject { 6 | @JavaMethod 7 | open override func equals(_ arg0: JavaObject?) -> Bool 8 | 9 | @JavaMethod 10 | open override func toString() -> String 11 | 12 | @JavaMethod 13 | open override func hashCode() -> Int32 14 | 15 | @JavaMethod 16 | open func isEmpty() -> Bool 17 | 18 | @JavaMethod 19 | open func isPresent() -> Bool 20 | 21 | @JavaMethod 22 | open func orElse(_ arg0: Int32) -> Int32 23 | 24 | @JavaMethod 25 | open func orElseThrow() -> Int32 26 | 27 | @JavaMethod 28 | open func getAsInt() -> Int32 29 | } 30 | extension JavaClass { 31 | @JavaStaticMethod 32 | public func of(_ arg0: Int32) -> JavaOptionalInt! 33 | 34 | public func ofOptional(_ arg0: Int32) -> Int32? { 35 | Optional(javaOptional: of(arg0)) 36 | } 37 | 38 | @JavaStaticMethod 39 | public func empty() -> JavaOptionalInt! 40 | 41 | public func emptyOptional() -> Int32? { 42 | Optional(javaOptional: empty()) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaOptionalLong.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.util.OptionalLong") 5 | open class JavaOptionalLong: JavaObject { 6 | @JavaMethod 7 | open override func equals(_ arg0: JavaObject?) -> Bool 8 | 9 | @JavaMethod 10 | open override func toString() -> String 11 | 12 | @JavaMethod 13 | open override func hashCode() -> Int32 14 | 15 | @JavaMethod 16 | open func isEmpty() -> Bool 17 | 18 | @JavaMethod 19 | open func isPresent() -> Bool 20 | 21 | @JavaMethod 22 | open func orElse(_ arg0: Int64) -> Int64 23 | 24 | @JavaMethod 25 | open func orElseThrow() -> Int64 26 | 27 | @JavaMethod 28 | open func getAsLong() -> Int64 29 | } 30 | extension JavaClass { 31 | @JavaStaticMethod 32 | public func of(_ arg0: Int64) -> JavaOptionalLong! 33 | 34 | public func ofOptional(_ arg0: Int64) -> Int64? { 35 | Optional(javaOptional: of(arg0)) 36 | } 37 | 38 | @JavaStaticMethod 39 | public func empty() -> JavaOptionalLong! 40 | 41 | public func emptyOptional() -> Int64? { 42 | Optional(javaOptional: empty()) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/JavaVoid.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Void") 5 | open class JavaVoid: JavaObject { 6 | 7 | } 8 | extension JavaClass { 9 | @JavaStaticField(isFinal: true) 10 | public var TYPE: JavaClass! 11 | } 12 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/RuntimeException.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.RuntimeException") 5 | open class RuntimeException: Exception { 6 | @JavaMethod 7 | @_nonoverride public convenience init(_ arg0: Throwable?, environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | @_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil) 11 | 12 | @JavaMethod 13 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 14 | 15 | @JavaMethod 16 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 17 | } 18 | -------------------------------------------------------------------------------- /Sources/JavaKit/generated/Throwable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaRuntime 3 | 4 | @JavaClass("java.lang.Throwable") 5 | open class Throwable: JavaObject { 6 | @JavaMethod 7 | @_nonoverride public convenience init(_ arg0: Throwable?, environment: JNIEnvironment? = nil) 8 | 9 | @JavaMethod 10 | @_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil) 11 | 12 | @JavaMethod 13 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 14 | 15 | @JavaMethod 16 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 17 | 18 | @JavaMethod 19 | open func printStackTrace() 20 | 21 | @JavaMethod 22 | open func fillInStackTrace() -> Throwable! 23 | 24 | @JavaMethod 25 | open func getCause() -> Throwable! 26 | 27 | @JavaMethod 28 | open func initCause(_ arg0: Throwable?) -> Throwable! 29 | 30 | @JavaMethod 31 | open override func toString() -> String 32 | 33 | @JavaMethod 34 | open func getMessage() -> String 35 | 36 | @JavaMethod 37 | open func getSuppressed() -> [Throwable?] 38 | 39 | @JavaMethod 40 | open func getLocalizedMessage() -> String 41 | 42 | @JavaMethod 43 | open func addSuppressed(_ arg0: Throwable?) 44 | } 45 | -------------------------------------------------------------------------------- /Sources/JavaKit/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.lang.reflect.Array" : "JavaArray", 4 | "java.lang.Boolean" : "JavaBoolean", 5 | "java.lang.Byte" : "JavaByte", 6 | "java.lang.Character" : "JavaCharacter", 7 | "java.lang.Class" : "JavaClass", 8 | "java.lang.ClassLoader" : "JavaClassLoader", 9 | "java.lang.Double" : "JavaDouble", 10 | "java.lang.Error" : "JavaError", 11 | "java.lang.Exception" : "Exception", 12 | "java.lang.Float" : "JavaFloat", 13 | "java.lang.Integer" : "JavaInteger", 14 | "java.lang.Long" : "JavaLong", 15 | "java.lang.Number" : "JavaNumber", 16 | "java.lang.Object" : "JavaObject", 17 | "java.lang.RuntimeException" : "RuntimeException", 18 | "java.lang.Short" : "JavaShort", 19 | "java.lang.String" : "JavaString", 20 | "java.lang.Throwable" : "Throwable", 21 | "java.lang.Void" : "JavaVoid", 22 | "java.lang.CharSequence": "CharSequence", 23 | "java.lang.Appendable": "Appendable", 24 | "java.util.Optional": "JavaOptional", 25 | "java.util.OptionalDouble": "JavaOptionalDouble", 26 | "java.util.OptionalInt": "JavaOptionalInt", 27 | "java.util.OptionalLong": "JavaOptionalLong" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/JavaEnumeration+Sequence.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension Enumeration: Sequence, IteratorProtocol { 16 | public typealias Element = E 17 | 18 | public mutating func next() -> Element? { 19 | guard hasMoreElements() else { return nil } 20 | 21 | return nextElement()?.as(Element.self)! 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/JavaIterator+Iterator.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | import JavaKit 15 | 16 | extension JavaIterator: IteratorProtocol { 17 | public typealias Element = E 18 | 19 | public func next() -> E? { 20 | if hasNext() { 21 | let nextResult: JavaObject? = next() 22 | return nextResult.map { $0.as(E.self)! } 23 | } 24 | 25 | return nil 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/List+Sequence.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension List: Sequence { 16 | public typealias Element = E 17 | public typealias Iterator = JavaIterator 18 | 19 | public func makeIterator() -> Iterator { 20 | return self.iterator()!.as(JavaIterator.self)! 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/Enumeration.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.Enumeration") 6 | public struct Enumeration { 7 | @JavaMethod 8 | public func asIterator() -> JavaIterator! 9 | 10 | @JavaMethod 11 | public func hasMoreElements() -> Bool 12 | 13 | @JavaMethod 14 | public func nextElement() -> JavaObject! 15 | } 16 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/HashSet.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.HashSet", implements: JavaSet.self) 6 | open class HashSet: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: Int32, _ arg1: Float, environment: JNIEnvironment? = nil) 12 | 13 | @JavaMethod 14 | @_nonoverride public convenience init(_ arg0: JavaCollection?, environment: JNIEnvironment? = nil) 15 | 16 | @JavaMethod 17 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 18 | 19 | @JavaMethod 20 | open func remove(_ arg0: JavaObject?) -> Bool 21 | 22 | @JavaMethod 23 | open func size() -> Int32 24 | 25 | @JavaMethod 26 | open override func clone() -> JavaObject! 27 | 28 | @JavaMethod 29 | open func clear() 30 | 31 | @JavaMethod 32 | open func isEmpty() -> Bool 33 | 34 | @JavaMethod 35 | open func add(_ arg0: JavaObject?) -> Bool 36 | 37 | @JavaMethod 38 | open func toArray(_ arg0: [JavaObject?]) -> [JavaObject?] 39 | 40 | @JavaMethod 41 | open func toArray() -> [JavaObject?] 42 | 43 | @JavaMethod 44 | open func iterator() -> JavaIterator! 45 | 46 | @JavaMethod 47 | open func contains(_ arg0: JavaObject?) -> Bool 48 | } 49 | extension JavaClass { 50 | @JavaStaticMethod 51 | public func newHashSet(_ arg0: Int32) -> HashSet! where ObjectType == HashSet 52 | } 53 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/JavaCollection.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.Collection") 6 | public struct JavaCollection { 7 | @JavaMethod 8 | public func remove(_ arg0: JavaObject?) -> Bool 9 | 10 | @JavaMethod 11 | public func size() -> Int32 12 | 13 | @JavaMethod 14 | public func equals(_ arg0: JavaObject?) -> Bool 15 | 16 | @JavaMethod 17 | public func hashCode() -> Int32 18 | 19 | @JavaMethod 20 | public func clear() 21 | 22 | @JavaMethod 23 | public func isEmpty() -> Bool 24 | 25 | @JavaMethod 26 | public func add(_ arg0: JavaObject?) -> Bool 27 | 28 | @JavaMethod 29 | public func toArray(_ arg0: [JavaObject?]) -> [JavaObject?] 30 | 31 | @JavaMethod 32 | public func toArray() -> [JavaObject?] 33 | 34 | @JavaMethod 35 | public func iterator() -> JavaIterator! 36 | 37 | @JavaMethod 38 | public func contains(_ arg0: JavaObject?) -> Bool 39 | 40 | @JavaMethod 41 | public func addAll(_ arg0: JavaCollection?) -> Bool 42 | 43 | @JavaMethod 44 | public func removeAll(_ arg0: JavaCollection?) -> Bool 45 | 46 | @JavaMethod 47 | public func retainAll(_ arg0: JavaCollection?) -> Bool 48 | 49 | @JavaMethod 50 | public func containsAll(_ arg0: JavaCollection?) -> Bool 51 | } 52 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/JavaDictionary.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.Dictionary") 6 | open class JavaDictionary: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open func remove(_ arg0: JavaObject?) -> JavaObject! 12 | 13 | @JavaMethod 14 | open func size() -> Int32 15 | 16 | @JavaMethod 17 | open func get(_ arg0: JavaObject?) -> JavaObject! 18 | 19 | @JavaMethod 20 | open func put(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject! 21 | 22 | @JavaMethod 23 | open func isEmpty() -> Bool 24 | 25 | @JavaMethod 26 | open func elements() -> Enumeration! 27 | 28 | @JavaMethod 29 | open func keys() -> Enumeration! 30 | } 31 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/JavaIterator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.Iterator") 6 | public struct JavaIterator { 7 | @JavaMethod 8 | public func remove() 9 | 10 | @JavaMethod 11 | public func hasNext() -> Bool 12 | 13 | @JavaMethod 14 | public func next() -> JavaObject! 15 | } 16 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/ListIterator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.ListIterator", extends: JavaIterator.self) 6 | public struct ListIterator { 7 | @JavaMethod 8 | public func remove() 9 | 10 | @JavaMethod 11 | public func add(_ arg0: JavaObject?) 12 | 13 | @JavaMethod 14 | public func hasNext() -> Bool 15 | 16 | @JavaMethod 17 | public func next() -> JavaObject! 18 | 19 | @JavaMethod 20 | public func set(_ arg0: JavaObject?) 21 | 22 | @JavaMethod 23 | public func nextIndex() -> Int32 24 | 25 | @JavaMethod 26 | public func previousIndex() -> Int32 27 | 28 | @JavaMethod 29 | public func hasPrevious() -> Bool 30 | 31 | @JavaMethod 32 | public func previous() -> JavaObject! 33 | } 34 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/PriorityQueue.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.PriorityQueue") 6 | open class PriorityQueue: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: PriorityQueue?, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: JavaCollection?, environment: JNIEnvironment? = nil) 12 | 13 | @JavaMethod 14 | @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) 15 | 16 | @JavaMethod 17 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 18 | 19 | @JavaMethod 20 | open func remove(_ arg0: JavaObject?) -> Bool 21 | 22 | @JavaMethod 23 | open func size() -> Int32 24 | 25 | @JavaMethod 26 | open func clear() 27 | 28 | @JavaMethod 29 | open func add(_ arg0: JavaObject?) -> Bool 30 | 31 | @JavaMethod 32 | open func toArray(_ arg0: [JavaObject?]) -> [JavaObject?] 33 | 34 | @JavaMethod 35 | open func toArray() -> [JavaObject?] 36 | 37 | @JavaMethod 38 | open func iterator() -> JavaIterator! 39 | 40 | @JavaMethod 41 | open func contains(_ arg0: JavaObject?) -> Bool 42 | 43 | @JavaMethod 44 | open func peek() -> JavaObject! 45 | 46 | @JavaMethod 47 | open func removeAll(_ arg0: JavaCollection?) -> Bool 48 | 49 | @JavaMethod 50 | open func retainAll(_ arg0: JavaCollection?) -> Bool 51 | 52 | @JavaMethod 53 | open func poll() -> JavaObject! 54 | 55 | @JavaMethod 56 | open func offer(_ arg0: JavaObject?) -> Bool 57 | } 58 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/Queue.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.Queue", extends: JavaCollection.self) 6 | public struct Queue { 7 | @JavaMethod 8 | public func remove() -> JavaObject! 9 | 10 | @JavaMethod 11 | public func add(_ arg0: JavaObject?) -> Bool 12 | 13 | @JavaMethod 14 | public func peek() -> JavaObject! 15 | 16 | @JavaMethod 17 | public func element() -> JavaObject! 18 | 19 | @JavaMethod 20 | public func poll() -> JavaObject! 21 | 22 | @JavaMethod 23 | public func offer(_ arg0: JavaObject?) -> Bool 24 | 25 | @JavaMethod 26 | public func remove(_ arg0: JavaObject?) -> Bool 27 | 28 | @JavaMethod 29 | public func size() -> Int32 30 | 31 | @JavaMethod 32 | public func equals(_ arg0: JavaObject?) -> Bool 33 | 34 | @JavaMethod 35 | public func hashCode() -> Int32 36 | 37 | @JavaMethod 38 | public func clear() 39 | 40 | @JavaMethod 41 | public func isEmpty() -> Bool 42 | 43 | @JavaMethod 44 | public func toArray(_ arg0: [JavaObject?]) -> [JavaObject?] 45 | 46 | @JavaMethod 47 | public func toArray() -> [JavaObject?] 48 | 49 | @JavaMethod 50 | public func iterator() -> JavaIterator! 51 | 52 | @JavaMethod 53 | public func contains(_ arg0: JavaObject?) -> Bool 54 | 55 | @JavaMethod 56 | public func addAll(_ arg0: JavaCollection?) -> Bool 57 | 58 | @JavaMethod 59 | public func removeAll(_ arg0: JavaCollection?) -> Bool 60 | 61 | @JavaMethod 62 | public func retainAll(_ arg0: JavaCollection?) -> Bool 63 | 64 | @JavaMethod 65 | public func containsAll(_ arg0: JavaCollection?) -> Bool 66 | } 67 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/RandomAccess.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.RandomAccess") 6 | public struct RandomAccess { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/Stack.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.Stack") 6 | open class Stack: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open func empty() -> Bool 12 | 13 | @JavaMethod 14 | open func peek() -> JavaObject! 15 | 16 | @JavaMethod 17 | open func search(_ arg0: JavaObject?) -> Int32 18 | 19 | @JavaMethod 20 | open func push(_ arg0: JavaObject?) -> JavaObject! 21 | 22 | @JavaMethod 23 | open func pop() -> JavaObject! 24 | } 25 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/generated/TreeSet.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.TreeSet") 6 | open class TreeSet: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: JavaCollection?, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 12 | 13 | @JavaMethod 14 | open func remove(_ arg0: JavaObject?) -> Bool 15 | 16 | @JavaMethod 17 | open func size() -> Int32 18 | 19 | @JavaMethod 20 | open override func clone() -> JavaObject! 21 | 22 | @JavaMethod 23 | open func floor(_ arg0: JavaObject?) -> JavaObject! 24 | 25 | @JavaMethod 26 | open func clear() 27 | 28 | @JavaMethod 29 | open func isEmpty() -> Bool 30 | 31 | @JavaMethod 32 | open func add(_ arg0: JavaObject?) -> Bool 33 | 34 | @JavaMethod 35 | open func iterator() -> JavaIterator! 36 | 37 | @JavaMethod 38 | open func contains(_ arg0: JavaObject?) -> Bool 39 | 40 | @JavaMethod 41 | open func last() -> JavaObject! 42 | 43 | @JavaMethod 44 | open func addAll(_ arg0: JavaCollection?) -> Bool 45 | 46 | @JavaMethod 47 | open func first() -> JavaObject! 48 | 49 | @JavaMethod 50 | open func addFirst(_ arg0: JavaObject?) 51 | 52 | @JavaMethod 53 | open func addLast(_ arg0: JavaObject?) 54 | 55 | @JavaMethod 56 | open func lower(_ arg0: JavaObject?) -> JavaObject! 57 | 58 | @JavaMethod 59 | open func pollFirst() -> JavaObject! 60 | 61 | @JavaMethod 62 | open func pollLast() -> JavaObject! 63 | 64 | @JavaMethod 65 | open func descendingIterator() -> JavaIterator! 66 | 67 | @JavaMethod 68 | open func ceiling(_ arg0: JavaObject?) -> JavaObject! 69 | 70 | @JavaMethod 71 | open func higher(_ arg0: JavaObject?) -> JavaObject! 72 | } 73 | -------------------------------------------------------------------------------- /Sources/JavaKitCollection/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.util.Collection" : "JavaCollection", 4 | "java.util.Enumeration" : "Enumeration", 5 | "java.util.Iterator" : "JavaIterator", 6 | "java.util.List" : "List", 7 | "java.util.ListIterator" : "ListIterator", 8 | "java.util.Queue" : "Queue", 9 | "java.util.RandomAccess" : "RandomAccess", 10 | "java.util.Set" : "JavaSet", 11 | "java.util.ArrayDeque" : "ArrayDeque", 12 | "java.util.ArrayList" : "ArrayList", 13 | "java.util.BitSet" : "BitSet", 14 | "java.util.Dictionary" : "JavaDictionary", 15 | "java.util.HashMap" : "HashMap", 16 | "java.util.HashSet" : "HashSet", 17 | "java.util.PriorityQueue" : "PriorityQueue", 18 | "java.util.Stack" : "Stack", 19 | "java.util.TreeMap" : "TreeMap", 20 | "java.util.TreeSet" : "TreeSet" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/JavaKitDependencyResolver/DependencyResolver.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | import JavaRuntime 17 | 18 | @JavaInterface("org.swift.javakit.dependencies.DependencyResolver") 19 | public struct DependencyResolver { 20 | } 21 | 22 | extension JavaClass { 23 | 24 | @JavaStaticMethod 25 | public func resolveDependenciesToClasspath( 26 | projectBaseDirectory: String, 27 | dependencies: [String]) throws -> String 28 | 29 | @JavaStaticMethod 30 | public func hasDependencyResolverDependenciesLoaded() -> Bool 31 | 32 | } -------------------------------------------------------------------------------- /Sources/JavaKitDependencyResolver/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | ":JavaKit", 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaBiConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.BiConsumer") 6 | public struct JavaBiConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: JavaObject?, _ arg1: JavaObject?) 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaBiConsumer?) -> JavaBiConsumer< 12 | JavaObject, JavaObject 13 | >? 14 | } 15 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaBiFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.BiFunction") 6 | public struct JavaBiFunction { 7 | @JavaMethod 8 | public func apply(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject? 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaFunction?) -> JavaBiFunction< 12 | JavaObject, JavaObject, JavaObject 13 | >? 14 | } 15 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaBiPredicate.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.BiPredicate") 6 | public struct JavaBiPredicate { 7 | @JavaMethod 8 | public func test(_ arg0: JavaObject?, _ arg1: JavaObject?) -> Bool 9 | 10 | @JavaMethod 11 | public func or(_ arg0: JavaBiPredicate?) -> JavaBiPredicate< 12 | JavaObject, JavaObject 13 | >? 14 | 15 | @JavaMethod 16 | public func and(_ arg0: JavaBiPredicate?) -> JavaBiPredicate< 17 | JavaObject, JavaObject 18 | >? 19 | 20 | @JavaMethod 21 | public func negate() -> JavaBiPredicate? 22 | } 23 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaBinaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface( 6 | "java.util.function.BinaryOperator", 7 | extends: JavaBiFunction.self) 8 | public struct JavaBinaryOperator { 9 | @JavaMethod 10 | public func apply(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject? 11 | 12 | @JavaMethod 13 | public func andThen(_ arg0: JavaFunction?) -> JavaBiFunction< 14 | JavaObject, JavaObject, JavaObject 15 | >? 16 | } 17 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaBooleanSupplier.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.BooleanSupplier") 6 | public struct JavaBooleanSupplier { 7 | @JavaMethod 8 | public func getAsBoolean() -> Bool 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.Consumer") 6 | public struct JavaConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: JavaObject?) 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaConsumer?) -> JavaConsumer? 12 | } 13 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleBinaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleBinaryOperator") 6 | public struct JavaDoubleBinaryOperator { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: Double, _ arg1: Double) -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleConsumer") 6 | public struct JavaDoubleConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: Double) 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaDoubleConsumer?) -> JavaDoubleConsumer? 12 | } 13 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleFunction") 6 | public struct JavaDoubleFunction { 7 | @JavaMethod 8 | public func apply(_ arg0: Double) -> JavaObject? 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoublePredicate.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoublePredicate") 6 | public struct JavaDoublePredicate { 7 | @JavaMethod 8 | public func test(_ arg0: Double) -> Bool 9 | 10 | @JavaMethod 11 | public func or(_ arg0: JavaDoublePredicate?) -> JavaDoublePredicate? 12 | 13 | @JavaMethod 14 | public func and(_ arg0: JavaDoublePredicate?) -> JavaDoublePredicate? 15 | 16 | @JavaMethod 17 | public func negate() -> JavaDoublePredicate? 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleSupplier.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleSupplier") 6 | public struct JavaDoubleSupplier { 7 | @JavaMethod 8 | public func getAsDouble() -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleToIntFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleToIntFunction") 6 | public struct JavaDoubleToIntFunction { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: Double) -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleToLongFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleToLongFunction") 6 | public struct JavaDoubleToLongFunction { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: Double) -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaDoubleUnaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.DoubleUnaryOperator") 6 | public struct JavaDoubleUnaryOperator { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: Double) -> Double 9 | 10 | @JavaMethod 11 | public func compose(_ arg0: JavaDoubleUnaryOperator?) -> JavaDoubleUnaryOperator? 12 | 13 | @JavaMethod 14 | public func andThen(_ arg0: JavaDoubleUnaryOperator?) -> JavaDoubleUnaryOperator? 15 | } 16 | extension JavaClass { 17 | @JavaStaticMethod 18 | public func identity() -> JavaDoubleUnaryOperator? 19 | } 20 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.Function") 6 | public struct JavaFunction { 7 | @JavaMethod 8 | public func apply(_ arg0: JavaObject?) -> JavaObject? 9 | 10 | @JavaMethod 11 | public func compose(_ arg0: JavaFunction?) -> JavaFunction< 12 | JavaObject, JavaObject 13 | >? 14 | 15 | @JavaMethod 16 | public func andThen(_ arg0: JavaFunction?) -> JavaFunction< 17 | JavaObject, JavaObject 18 | >? 19 | } 20 | extension JavaClass { 21 | @JavaStaticMethod 22 | public func identity() -> JavaFunction< 23 | JavaObject, JavaObject 24 | >? where ObjectType == JavaFunction 25 | } 26 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntBinaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntBinaryOperator") 6 | public struct JavaIntBinaryOperator { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: Int32, _ arg1: Int32) -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntConsumer") 6 | public struct JavaIntConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: Int32) 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaIntConsumer?) -> JavaIntConsumer? 12 | } 13 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntFunction") 6 | public struct JavaIntFunction { 7 | @JavaMethod 8 | public func apply(_ arg0: Int32) -> JavaObject? 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntPredicate.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntPredicate") 6 | public struct JavaIntPredicate { 7 | @JavaMethod 8 | public func test(_ arg0: Int32) -> Bool 9 | 10 | @JavaMethod 11 | public func or(_ arg0: JavaIntPredicate?) -> JavaIntPredicate? 12 | 13 | @JavaMethod 14 | public func and(_ arg0: JavaIntPredicate?) -> JavaIntPredicate? 15 | 16 | @JavaMethod 17 | public func negate() -> JavaIntPredicate? 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntSupplier.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntSupplier") 6 | public struct JavaIntSupplier { 7 | @JavaMethod 8 | public func getAsInt() -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntToDoubleFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntToDoubleFunction") 6 | public struct JavaIntToDoubleFunction { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: Int32) -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntToLongFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntToLongFunction") 6 | public struct JavaIntToLongFunction { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: Int32) -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaIntUnaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.IntUnaryOperator") 6 | public struct JavaIntUnaryOperator { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: Int32) -> Int32 9 | 10 | @JavaMethod 11 | public func compose(_ arg0: JavaIntUnaryOperator?) -> JavaIntUnaryOperator? 12 | 13 | @JavaMethod 14 | public func andThen(_ arg0: JavaIntUnaryOperator?) -> JavaIntUnaryOperator? 15 | } 16 | extension JavaClass { 17 | @JavaStaticMethod 18 | public func identity() -> JavaIntUnaryOperator? 19 | } 20 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongBinaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongBinaryOperator") 6 | public struct JavaLongBinaryOperator { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: Int64, _ arg1: Int64) -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongConsumer") 6 | public struct JavaLongConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: Int64) 9 | 10 | @JavaMethod 11 | public func andThen(_ arg0: JavaLongConsumer?) -> JavaLongConsumer? 12 | } 13 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongFunction") 6 | public struct JavaLongFunction { 7 | @JavaMethod 8 | public func apply(_ arg0: Int64) -> JavaObject? 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongPredicate.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongPredicate") 6 | public struct JavaLongPredicate { 7 | @JavaMethod 8 | public func test(_ arg0: Int64) -> Bool 9 | 10 | @JavaMethod 11 | public func or(_ arg0: JavaLongPredicate?) -> JavaLongPredicate? 12 | 13 | @JavaMethod 14 | public func and(_ arg0: JavaLongPredicate?) -> JavaLongPredicate? 15 | 16 | @JavaMethod 17 | public func negate() -> JavaLongPredicate? 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongSupplier.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongSupplier") 6 | public struct JavaLongSupplier { 7 | @JavaMethod 8 | public func getAsLong() -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongToDoubleFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongToDoubleFunction") 6 | public struct JavaLongToDoubleFunction { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: Int64) -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongToIntFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongToIntFunction") 6 | public struct JavaLongToIntFunction { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: Int64) -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaLongUnaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.LongUnaryOperator") 6 | public struct JavaLongUnaryOperator { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: Int64) -> Int64 9 | 10 | @JavaMethod 11 | public func compose(_ arg0: JavaLongUnaryOperator?) -> JavaLongUnaryOperator? 12 | 13 | @JavaMethod 14 | public func andThen(_ arg0: JavaLongUnaryOperator?) -> JavaLongUnaryOperator? 15 | } 16 | extension JavaClass { 17 | @JavaStaticMethod 18 | public func identity() -> JavaLongUnaryOperator? 19 | } 20 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaObjDoubleConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ObjDoubleConsumer") 6 | public struct JavaObjDoubleConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: JavaObject?, _ arg1: Double) 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaObjIntConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ObjIntConsumer") 6 | public struct JavaObjIntConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: JavaObject?, _ arg1: Int32) 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaObjLongConsumer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ObjLongConsumer") 6 | public struct JavaObjLongConsumer { 7 | @JavaMethod 8 | public func accept(_ arg0: JavaObject?, _ arg1: Int64) 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaPredicate.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.Predicate") 6 | public struct JavaPredicate { 7 | @JavaMethod 8 | public func test(_ arg0: JavaObject?) -> Bool 9 | 10 | @JavaMethod 11 | public func or(_ arg0: JavaPredicate?) -> JavaPredicate? 12 | 13 | @JavaMethod 14 | public func and(_ arg0: JavaPredicate?) -> JavaPredicate? 15 | 16 | @JavaMethod 17 | public func negate() -> JavaPredicate? 18 | } 19 | extension JavaClass { 20 | @JavaStaticMethod 21 | public func not(_ arg0: JavaPredicate?) -> JavaPredicate< 22 | JavaObject 23 | >? where ObjectType == JavaPredicate 24 | 25 | @JavaStaticMethod 26 | public func isEqual(_ arg0: JavaObject?) -> JavaPredicate? 27 | where ObjectType == JavaPredicate 28 | } 29 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaSupplier.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.Supplier") 6 | public struct JavaSupplier { 7 | @JavaMethod 8 | public func get() -> JavaObject? 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToDoubleBiFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToDoubleBiFunction") 6 | public struct JavaToDoubleBiFunction { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: JavaObject?, _ arg1: JavaObject?) -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToDoubleFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToDoubleFunction") 6 | public struct JavaToDoubleFunction { 7 | @JavaMethod 8 | public func applyAsDouble(_ arg0: JavaObject?) -> Double 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToIntBiFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToIntBiFunction") 6 | public struct JavaToIntBiFunction { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: JavaObject?, _ arg1: JavaObject?) -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToIntFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToIntFunction") 6 | public struct JavaToIntFunction { 7 | @JavaMethod 8 | public func applyAsInt(_ arg0: JavaObject?) -> Int32 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToLongBiFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToLongBiFunction") 6 | public struct JavaToLongBiFunction { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: JavaObject?, _ arg1: JavaObject?) -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaToLongFunction.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.util.function.ToLongFunction") 6 | public struct JavaToLongFunction { 7 | @JavaMethod 8 | public func applyAsLong(_ arg0: JavaObject?) -> Int64 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitFunction/generated/JavaUnaryOperator.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface( 6 | "java.util.function.UnaryOperator", extends: JavaFunction.self) 7 | public struct JavaUnaryOperator { 8 | @JavaMethod 9 | public func apply(_ arg0: JavaObject?) -> JavaObject? 10 | 11 | @JavaMethod 12 | public func compose(_ arg0: JavaFunction?) -> JavaFunction< 13 | JavaObject, JavaObject 14 | >? 15 | 16 | @JavaMethod 17 | public func andThen(_ arg0: JavaFunction?) -> JavaFunction< 18 | JavaObject, JavaObject 19 | >? 20 | } 21 | extension JavaClass { 22 | @JavaStaticMethod 23 | public func identity() -> JavaUnaryOperator? 24 | where ObjectType == JavaUnaryOperator 25 | } 26 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/BufferedInputStream.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.BufferedInputStream") 6 | open class BufferedInputStream: InputStream { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: InputStream?, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: Int32, environment: JNIEnvironment? = nil) 12 | 13 | @JavaMethod 14 | open override func reset() throws 15 | 16 | @JavaMethod 17 | open override func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 18 | 19 | @JavaMethod 20 | open override func read() throws -> Int32 21 | 22 | @JavaMethod 23 | open override func close() throws 24 | 25 | @JavaMethod 26 | open override func mark(_ arg0: Int32) 27 | 28 | @JavaMethod 29 | open override func transferTo(_ arg0: OutputStream?) throws -> Int64 30 | 31 | @JavaMethod 32 | open override func skip(_ arg0: Int64) throws -> Int64 33 | 34 | @JavaMethod 35 | open override func available() throws -> Int32 36 | 37 | @JavaMethod 38 | open override func markSupported() -> Bool 39 | } 40 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Charset.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.nio.charset.Charset") 6 | open class Charset: JavaObject { 7 | @JavaMethod 8 | open func name() -> String 9 | 10 | @JavaMethod 11 | open override func equals(_ arg0: JavaObject?) -> Bool 12 | 13 | @JavaMethod 14 | open override func toString() -> String 15 | 16 | @JavaMethod 17 | open override func hashCode() -> Int32 18 | 19 | @JavaMethod 20 | open func compareTo(_ arg0: JavaObject?) -> Int32 21 | 22 | @JavaMethod 23 | open func compareTo(_ arg0: Charset?) -> Int32 24 | 25 | @JavaMethod 26 | open func canEncode() -> Bool 27 | 28 | @JavaMethod 29 | open func contains(_ arg0: Charset?) -> Bool 30 | 31 | @JavaMethod 32 | open func isRegistered() -> Bool 33 | 34 | @JavaMethod 35 | open func displayName() -> String 36 | } 37 | extension JavaClass { 38 | @JavaStaticMethod 39 | public func forName(_ arg0: String, _ arg1: Charset?) -> Charset! 40 | 41 | @JavaStaticMethod 42 | public func forName(_ arg0: String) -> Charset! 43 | 44 | @JavaStaticMethod 45 | public func defaultCharset() -> Charset! 46 | 47 | @JavaStaticMethod 48 | public func isSupported(_ arg0: String) -> Bool 49 | } 50 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Closeable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.io.Closeable") 6 | public struct Closeable { 7 | @JavaMethod 8 | public func close() throws 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/FileDescriptor.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.FileDescriptor") 6 | open class FileDescriptor: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open func sync() throws 12 | 13 | @JavaMethod 14 | open func valid() -> Bool 15 | } 16 | extension JavaClass { 17 | @JavaStaticField(isFinal: true) 18 | public var `in`: FileDescriptor! 19 | 20 | @JavaStaticField(isFinal: true) 21 | public var out: FileDescriptor! 22 | 23 | @JavaStaticField(isFinal: true) 24 | public var err: FileDescriptor! 25 | } 26 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/FileReader.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.FileReader") 6 | open class FileReader: InputStreamReader { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: File?, _ arg1: Charset?, environment: JNIEnvironment? = nil) throws 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: String, _ arg1: Charset?, environment: JNIEnvironment? = nil) throws 12 | 13 | @JavaMethod 14 | @_nonoverride public convenience init(_ arg0: FileDescriptor?, environment: JNIEnvironment? = nil) 15 | 16 | @JavaMethod 17 | @_nonoverride public convenience init(_ arg0: File?, environment: JNIEnvironment? = nil) throws 18 | 19 | @JavaMethod 20 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) throws 21 | } 22 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Flushable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.io.Flushable") 6 | public struct Flushable { 7 | @JavaMethod 8 | public func flush() throws 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/InputStream.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.InputStream", implements: Closeable.self) 6 | open class InputStream: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open func reset() throws 12 | 13 | @JavaMethod 14 | open func read(_ arg0: [Int8]) throws -> Int32 15 | 16 | @JavaMethod 17 | open func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 18 | 19 | @JavaMethod 20 | open func read() throws -> Int32 21 | 22 | @JavaMethod 23 | open func close() throws 24 | 25 | @JavaMethod 26 | open func readAllBytes() throws -> [Int8] 27 | 28 | @JavaMethod 29 | open func mark(_ arg0: Int32) 30 | 31 | @JavaMethod 32 | open func readNBytes(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 33 | 34 | @JavaMethod 35 | open func readNBytes(_ arg0: Int32) throws -> [Int8] 36 | 37 | @JavaMethod 38 | open func transferTo(_ arg0: OutputStream?) throws -> Int64 39 | 40 | @JavaMethod 41 | open func skip(_ arg0: Int64) throws -> Int64 42 | 43 | @JavaMethod 44 | open func available() throws -> Int32 45 | 46 | @JavaMethod 47 | open func markSupported() -> Bool 48 | 49 | @JavaMethod 50 | open func skipNBytes(_ arg0: Int64) throws 51 | } 52 | extension JavaClass { 53 | @JavaStaticMethod 54 | public func nullInputStream() -> InputStream! 55 | } 56 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/InputStreamReader.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.InputStreamReader") 6 | open class InputStreamReader: Reader { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: Charset?, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: String, environment: JNIEnvironment? = nil) throws 12 | 13 | @JavaMethod 14 | @_nonoverride public convenience init(_ arg0: InputStream?, environment: JNIEnvironment? = nil) 15 | 16 | @JavaMethod 17 | open override func ready() throws -> Bool 18 | 19 | @JavaMethod 20 | open override func read() throws -> Int32 21 | 22 | @JavaMethod 23 | open override func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 24 | 25 | @JavaMethod 26 | open override func close() throws 27 | 28 | @JavaMethod 29 | open func getEncoding() -> String 30 | } 31 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/OutputStream.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.OutputStream", implements: Closeable.self, Flushable.self) 6 | open class OutputStream: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open func flush() throws 12 | 13 | @JavaMethod 14 | open func write(_ arg0: [Int8]) throws 15 | 16 | @JavaMethod 17 | open func write(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws 18 | 19 | @JavaMethod 20 | open func write(_ arg0: Int32) throws 21 | 22 | @JavaMethod 23 | open func close() throws 24 | } 25 | extension JavaClass { 26 | @JavaStaticMethod 27 | public func nullOutputStream() -> OutputStream! 28 | } 29 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Readable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.Readable") 6 | public struct Readable { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Reader.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.Reader", implements: Readable.self, Closeable.self) 6 | open class Reader: JavaObject { 7 | @JavaMethod 8 | open func ready() throws -> Bool 9 | 10 | @JavaMethod 11 | open func reset() throws 12 | 13 | @JavaMethod 14 | open func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 15 | 16 | @JavaMethod 17 | open func read() throws -> Int32 18 | 19 | @JavaMethod 20 | open func read(_ arg0: [UInt16]) throws -> Int32 21 | 22 | @JavaMethod 23 | open func close() throws 24 | 25 | @JavaMethod 26 | open func mark(_ arg0: Int32) throws 27 | 28 | @JavaMethod 29 | open func transferTo(_ arg0: Writer?) throws -> Int64 30 | 31 | @JavaMethod 32 | open func skip(_ arg0: Int64) throws -> Int64 33 | 34 | @JavaMethod 35 | open func markSupported() -> Bool 36 | } 37 | extension JavaClass { 38 | @JavaStaticMethod 39 | public func nullReader() -> Reader! 40 | } 41 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/StringReader.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.StringReader") 6 | open class StringReader: Reader { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | open override func ready() throws -> Bool 12 | 13 | @JavaMethod 14 | open override func reset() throws 15 | 16 | @JavaMethod 17 | open override func read() throws -> Int32 18 | 19 | @JavaMethod 20 | open override func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 21 | 22 | @JavaMethod 23 | open override func close() 24 | 25 | @JavaMethod 26 | open override func mark(_ arg0: Int32) throws 27 | 28 | @JavaMethod 29 | open override func skip(_ arg0: Int64) throws -> Int64 30 | 31 | @JavaMethod 32 | open override func markSupported() -> Bool 33 | } 34 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/WatchService.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.nio.file.WatchService", extends: Closeable.self) 6 | public struct WatchService { 7 | @JavaMethod 8 | public func close() throws 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/generated/Writer.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.io.Writer", implements: Appendable.self, Closeable.self, Flushable.self) 6 | open class Writer: JavaObject { 7 | @JavaMethod 8 | open func append(_ arg0: UInt16) throws -> Writer! 9 | 10 | @JavaMethod 11 | open func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Writer! 12 | 13 | @JavaMethod 14 | open func append(_ arg0: CharSequence?) throws -> Writer! 15 | 16 | @JavaMethod 17 | open func append(_ arg0: CharSequence?) throws -> Appendable! 18 | 19 | @JavaMethod 20 | open func append(_ arg0: UInt16) throws -> Appendable! 21 | 22 | @JavaMethod 23 | open func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Appendable! 24 | 25 | @JavaMethod 26 | open func flush() throws 27 | 28 | @JavaMethod 29 | open func write(_ arg0: Int32) throws 30 | 31 | @JavaMethod 32 | open func write(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws 33 | 34 | @JavaMethod 35 | open func write(_ arg0: String) throws 36 | 37 | @JavaMethod 38 | open func write(_ arg0: String, _ arg1: Int32, _ arg2: Int32) throws 39 | 40 | @JavaMethod 41 | open func write(_ arg0: [UInt16]) throws 42 | 43 | @JavaMethod 44 | open func close() throws 45 | } 46 | extension JavaClass { 47 | @JavaStaticMethod 48 | public func nullWriter() -> Writer! 49 | } 50 | -------------------------------------------------------------------------------- /Sources/JavaKitIO/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.io.FileReader" : "FileReader", 4 | "java.io.StringReader" : "StringReader", 5 | "java.io.InputStreamReader" : "InputStreamReader", 6 | "java.io.BufferedInputStream" : "BufferedInputStream", 7 | "java.io.InputStream" : "InputStream", 8 | "java.io.OutputStream" : "OutputStream", 9 | "java.io.Reader" : "Reader", 10 | "java.lang.Readable" : "Readable", 11 | "java.io.Writer" : "Writer", 12 | "java.io.File" : "File", 13 | "java.nio.file.Path" : "Path", 14 | "java.io.FileDescriptor" : "FileDescriptor", 15 | "java.nio.charset.Charset" : "Charset", 16 | "java.io.Closeable" : "Closeable", 17 | "java.io.Flushable" : "Flushable", 18 | "java.io.Flushable" : "ByteBuffer", 19 | "java.nio.file.WatchService" : "WatchService", 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/JavaKitJar/generated/Manifest.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.util.jar.Manifest") 6 | open class Manifest: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: Manifest?, environment: JNIEnvironment? = nil) 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(environment: JNIEnvironment? = nil) 12 | 13 | @JavaMethod 14 | open override func equals(_ arg0: JavaObject?) -> Bool 15 | 16 | @JavaMethod 17 | open override func hashCode() -> Int32 18 | 19 | @JavaMethod 20 | open override func clone() -> JavaObject! 21 | 22 | @JavaMethod 23 | open func clear() 24 | 25 | @JavaMethod 26 | open func getMainAttributes() -> Attributes! 27 | 28 | @JavaMethod 29 | open func getAttributes(_ arg0: String) -> Attributes! 30 | } 31 | -------------------------------------------------------------------------------- /Sources/JavaKitJar/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.util.jar.Attributes" : "Attributes", 4 | "java.util.jar.JarEntry" : "JarEntry", 5 | "java.util.jar.JarFile" : "JarFile", 6 | "java.util.jar.JarInputStream" : "JarInputStream", 7 | "java.util.jar.JarOutputStream" : "JarOutputStream", 8 | "java.util.jar.Manifest" : "Manifest", 9 | "java.util.zip.ZipEntry" : "ZipEntry" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/JavaKitMacros/JavaKitMacrosPlugin.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import SwiftCompilerPlugin 16 | import SwiftSyntaxMacros 17 | 18 | @main 19 | struct JavaKitMacrosPlugin: CompilerPlugin { 20 | var providingMacros: [Macro.Type] = [ 21 | JavaImplementationMacro.self, 22 | JavaClassMacro.self, 23 | JavaFieldMacro.self, 24 | JavaMethodMacro.self, 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /Sources/JavaKitMacros/MacroErrors.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | enum MacroErrors: Error { 16 | case unrecognizedJavaClassMacro(String) 17 | case javaImplementationRequiresExtension 18 | case classNameNotStringLiteral 19 | case classNameNotFullyQualified(String) 20 | case javaClassNotOnType 21 | case methodNotOnFunction 22 | case missingEnvironment 23 | case macroOutOfContext(String) 24 | } 25 | -------------------------------------------------------------------------------- /Sources/JavaKitMacros/SwiftSyntaxUtils.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import SwiftSyntax 16 | 17 | extension FunctionParameterSyntax { 18 | var argumentName: String? { 19 | // If we have two names, the first one is the argument label 20 | if secondName != nil { 21 | return firstName.text 22 | } 23 | 24 | // If we have only one name, it might be an argument label. 25 | if let superparent = parent?.parent?.parent, superparent.is(SubscriptDeclSyntax.self) { 26 | return nil 27 | } 28 | 29 | return firstName.text 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/JavaKitNetwork/generated/URL.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.net.URL") 6 | open class URL: JavaObject { 7 | @JavaMethod 8 | @_nonoverride public convenience init(_ arg0: URL?, _ arg1: String, environment: JNIEnvironment? = nil) throws 9 | 10 | @JavaMethod 11 | @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) throws 12 | 13 | @JavaMethod 14 | @_nonoverride public convenience init(_ arg0: String, _ arg1: String, _ arg2: Int32, _ arg3: String, environment: JNIEnvironment? = nil) throws 15 | 16 | @JavaMethod 17 | @_nonoverride public convenience init(_ arg0: String, _ arg1: String, _ arg2: String, environment: JNIEnvironment? = nil) throws 18 | 19 | @JavaMethod 20 | open override func equals(_ arg0: JavaObject?) -> Bool 21 | 22 | @JavaMethod 23 | open override func toString() -> String 24 | 25 | @JavaMethod 26 | open override func hashCode() -> Int32 27 | 28 | @JavaMethod 29 | open func getHost() -> String 30 | 31 | @JavaMethod 32 | open func getPort() -> Int32 33 | 34 | @JavaMethod 35 | open func getDefaultPort() -> Int32 36 | 37 | @JavaMethod 38 | open func sameFile(_ arg0: URL?) -> Bool 39 | 40 | @JavaMethod 41 | open func toExternalForm() -> String 42 | 43 | @JavaMethod 44 | open func getContent() throws -> JavaObject! 45 | 46 | @JavaMethod 47 | open func getContent(_ arg0: [JavaClass?]) throws -> JavaObject! 48 | 49 | @JavaMethod 50 | open func getProtocol() -> String 51 | 52 | @JavaMethod 53 | open func getAuthority() -> String 54 | 55 | @JavaMethod 56 | open func getFile() -> String 57 | 58 | @JavaMethod 59 | open func getRef() -> String 60 | 61 | @JavaMethod 62 | open func getQuery() -> String 63 | 64 | @JavaMethod 65 | open func getPath() -> String 66 | 67 | @JavaMethod 68 | open func getUserInfo() -> String 69 | 70 | @JavaMethod 71 | open func toURI() throws -> URI! 72 | } 73 | -------------------------------------------------------------------------------- /Sources/JavaKitNetwork/generated/URLClassLoader.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaKitCollection 4 | import JavaRuntime 5 | 6 | @JavaClass("java.net.URLClassLoader") 7 | open class URLClassLoader: JavaObject { 8 | @JavaMethod 9 | @_nonoverride public convenience init(_ arg0: [URL?], environment: JNIEnvironment? = nil) 10 | 11 | @JavaMethod 12 | open func findResource(_ arg0: String) -> URL! 13 | 14 | @JavaMethod 15 | open func findClass(_ arg0: String) throws -> JavaClass! 16 | 17 | @JavaMethod 18 | open func findResources(_ arg0: String) throws -> Enumeration! 19 | 20 | @JavaMethod 21 | open func close() throws 22 | 23 | @JavaMethod 24 | open func addURL(_ arg0: URL?) 25 | 26 | @JavaMethod 27 | open func getURLs() -> [URL?] 28 | } 29 | extension JavaClass { 30 | @JavaStaticMethod 31 | public func newInstance(_ arg0: [URL?], _ arg1: JavaClassLoader?) -> URLClassLoader! 32 | 33 | @JavaStaticMethod 34 | public func newInstance(_ arg0: [URL?]) -> URLClassLoader! 35 | } 36 | -------------------------------------------------------------------------------- /Sources/JavaKitNetwork/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.net.URI" : "URI", 4 | "java.net.URL" : "URL", 5 | "java.net.URLClassLoader" : "URLClassLoader" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/Constructor+Utilities.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension Constructor { 16 | /// Whether this is a 'public' constructor. 17 | public var isPublic: Bool { 18 | return (getModifiers() & 1) != 0 19 | } 20 | 21 | /// Whether this is a 'native' constructor. 22 | public var isNative: Bool { 23 | return (getModifiers() & 256) != 0 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/Executable+Utilities.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | 17 | extension Executable { 18 | /// Whether this executable throws any checked exception. 19 | public var throwsCheckedException: Bool { 20 | for exceptionType in getExceptionTypes() { 21 | guard let exceptionType else { continue } 22 | if let throwableType = exceptionType.as(JavaClass.self) { 23 | if throwableType.isCheckedException { 24 | return true 25 | } 26 | } 27 | } 28 | 29 | return false 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/Field+Utilities.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension Field { 16 | /// Whether this is a 'static' field. 17 | public var isStatic: Bool { 18 | return (getModifiers() & 0x08) != 0 19 | } 20 | 21 | /// Whether this is a 'final' field. 22 | public var isFinal: Bool { 23 | return (getModifiers() & 16) != 0 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/JavaClass+Reflection.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaKit 16 | 17 | // TODO: We should be able to autogenerate this as an extension based on 18 | // knowing that JavaClass was defined elsewhere. 19 | extension JavaClass { 20 | @JavaMethod 21 | public func getDeclaredMethods() -> [Method?] 22 | 23 | @JavaMethod 24 | public func getMethods() -> [Method?] 25 | 26 | @JavaMethod 27 | public func getDeclaredMethod( 28 | _ name: String, 29 | _ parameterTypes: [JavaClass?] 30 | ) throws -> Method? 31 | 32 | @JavaMethod 33 | public func getFields() -> [Field?] 34 | 35 | @JavaMethod 36 | public func getConstructors() -> [Constructor?] 37 | 38 | @JavaMethod 39 | public func getParameters() -> [Parameter?] 40 | 41 | @JavaMethod 42 | public func getTypeParameters() -> [TypeVariable>?] 43 | 44 | @JavaMethod 45 | public func getGenericInterfaces() -> [Type?] 46 | 47 | @JavaMethod 48 | public func getAnnotations() -> [Annotation?] 49 | } 50 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/Method+Utilities.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | extension Method { 16 | /// Whether this is a 'public' method. 17 | public var isPublic: Bool { 18 | return (getModifiers() & 1) != 0 19 | } 20 | 21 | /// Whether this is a 'protected' method. 22 | public var isProtected: Bool { 23 | return (getModifiers() & 4) != 0 24 | } 25 | 26 | /// Whether this is a 'static' method. 27 | public var isStatic: Bool { 28 | return (getModifiers() & 0x08) != 0 29 | } 30 | 31 | /// Whether this is a 'native' method. 32 | public var isNative: Bool { 33 | return (getModifiers() & 256) != 0 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/AccessibleObject.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaClass("java.lang.reflect.AccessibleObject") 6 | open class AccessibleObject: JavaObject { 7 | @JavaMethod 8 | open func isAnnotationPresent(_ arg0: JavaClass?) -> Bool 9 | 10 | @JavaMethod 11 | open func getAnnotation(_ arg0: JavaClass?) -> Annotation! 12 | 13 | @JavaMethod 14 | open func getAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 15 | 16 | @JavaMethod 17 | open func getAnnotations() -> [Annotation?] 18 | 19 | @JavaMethod 20 | open func getDeclaredAnnotation(_ arg0: JavaClass?) -> Annotation! 21 | 22 | @JavaMethod 23 | open func getDeclaredAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 24 | 25 | @JavaMethod 26 | open func getDeclaredAnnotations() -> [Annotation?] 27 | 28 | @JavaMethod 29 | open func setAccessible(_ arg0: Bool) 30 | 31 | @JavaMethod 32 | open func trySetAccessible() -> Bool 33 | 34 | @JavaMethod 35 | open func canAccess(_ arg0: JavaObject?) -> Bool 36 | 37 | @JavaMethod 38 | open func isAccessible() -> Bool 39 | } 40 | extension JavaClass { 41 | @JavaStaticMethod 42 | public func setAccessible(_ arg0: [AccessibleObject?], _ arg1: Bool) 43 | } 44 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/AnnotatedType.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.AnnotatedType") 6 | public struct AnnotatedType { 7 | @JavaMethod 8 | public func getAnnotatedOwnerType() -> AnnotatedType! 9 | 10 | @JavaMethod 11 | public func getAnnotation(_ arg0: JavaClass?) -> Annotation! 12 | 13 | @JavaMethod 14 | public func getAnnotations() -> [Annotation?] 15 | 16 | @JavaMethod 17 | public func getDeclaredAnnotations() -> [Annotation?] 18 | 19 | @JavaMethod 20 | public func getType() -> Type! 21 | 22 | @JavaMethod 23 | public func isAnnotationPresent(_ arg0: JavaClass?) -> Bool 24 | 25 | @JavaMethod 26 | public func getAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 27 | 28 | @JavaMethod 29 | public func getDeclaredAnnotation(_ arg0: JavaClass?) -> Annotation! 30 | 31 | @JavaMethod 32 | public func getDeclaredAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 33 | } 34 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/Annotation.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.annotation.Annotation") 6 | public struct Annotation { 7 | @JavaMethod 8 | public func equals(_ arg0: JavaObject?) -> Bool 9 | 10 | @JavaMethod 11 | public func toString() -> String 12 | 13 | @JavaMethod 14 | public func hashCode() -> Int32 15 | 16 | @JavaMethod 17 | public func annotationType() -> JavaClass! 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/GenericArrayType.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.GenericArrayType", extends: Type.self) 6 | public struct GenericArrayType { 7 | @JavaMethod 8 | public func getGenericComponentType() -> Type! 9 | 10 | @JavaMethod 11 | public func getTypeName() -> String 12 | } 13 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/GenericDeclaration.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.GenericDeclaration") 6 | public struct GenericDeclaration { 7 | @JavaMethod 8 | public func getTypeParameters() -> [TypeVariable?] 9 | 10 | @JavaMethod 11 | public func isAnnotationPresent(_ arg0: JavaClass?) -> Bool 12 | 13 | @JavaMethod 14 | public func getAnnotation(_ arg0: JavaClass?) -> Annotation! 15 | 16 | @JavaMethod 17 | public func getAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 18 | 19 | @JavaMethod 20 | public func getAnnotations() -> [Annotation?] 21 | 22 | @JavaMethod 23 | public func getDeclaredAnnotation(_ arg0: JavaClass?) -> Annotation! 24 | 25 | @JavaMethod 26 | public func getDeclaredAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 27 | 28 | @JavaMethod 29 | public func getDeclaredAnnotations() -> [Annotation?] 30 | } 31 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/Parameter.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaKitCollection 4 | import JavaRuntime 5 | 6 | @JavaClass("java.lang.reflect.Parameter") 7 | open class Parameter: JavaObject { 8 | @JavaMethod 9 | open func getName() -> String 10 | 11 | @JavaMethod 12 | open override func equals(_ arg0: JavaObject?) -> Bool 13 | 14 | @JavaMethod 15 | open override func toString() -> String 16 | 17 | @JavaMethod 18 | open override func hashCode() -> Int32 19 | 20 | @JavaMethod 21 | open func getModifiers() -> Int32 22 | 23 | @JavaMethod 24 | open func isSynthetic() -> Bool 25 | 26 | @JavaMethod 27 | open func getAnnotation(_ arg0: JavaClass?) -> Annotation! 28 | 29 | @JavaMethod 30 | open func getAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 31 | 32 | @JavaMethod 33 | open func getAnnotations() -> [Annotation?] 34 | 35 | @JavaMethod 36 | open func getDeclaredAnnotation(_ arg0: JavaClass?) -> Annotation! 37 | 38 | @JavaMethod 39 | open func getDeclaredAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 40 | 41 | @JavaMethod 42 | open func getDeclaredAnnotations() -> [Annotation?] 43 | 44 | @JavaMethod 45 | open func getType() -> JavaClass! 46 | 47 | @JavaMethod 48 | open func getAnnotatedType() -> AnnotatedType! 49 | 50 | @JavaMethod 51 | open func getParameterizedType() -> Type! 52 | 53 | @JavaMethod 54 | open func isVarArgs() -> Bool 55 | 56 | @JavaMethod 57 | open func isNamePresent() -> Bool 58 | 59 | @JavaMethod 60 | open func getDeclaringExecutable() -> Executable! 61 | 62 | @JavaMethod 63 | open func isImplicit() -> Bool 64 | } 65 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/ParameterizedType.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.ParameterizedType", extends: Type.self) 6 | public struct ParameterizedType { 7 | @JavaMethod 8 | public func getOwnerType() -> Type! 9 | 10 | @JavaMethod 11 | public func getRawType() -> Type! 12 | 13 | @JavaMethod 14 | public func getActualTypeArguments() -> [Type?] 15 | 16 | @JavaMethod 17 | public func getTypeName() -> String 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/Type.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.Type") 6 | public struct Type { 7 | @JavaMethod 8 | public func getTypeName() -> String 9 | } 10 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/TypeVariable.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.TypeVariable", extends: Type.self) 6 | public struct TypeVariable { 7 | @JavaMethod 8 | public func getGenericDeclaration() -> GenericDeclaration! 9 | 10 | @JavaMethod 11 | public func getAnnotatedBounds() -> [AnnotatedType?] 12 | 13 | @JavaMethod 14 | public func getName() -> String 15 | 16 | @JavaMethod 17 | public func getBounds() -> [Type?] 18 | 19 | @JavaMethod 20 | public func getTypeName() -> String 21 | 22 | @JavaMethod 23 | public func isAnnotationPresent(_ arg0: JavaClass?) -> Bool 24 | 25 | @JavaMethod 26 | public func getAnnotation(_ arg0: JavaClass?) -> Annotation! 27 | 28 | @JavaMethod 29 | public func getAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 30 | 31 | @JavaMethod 32 | public func getAnnotations() -> [Annotation?] 33 | 34 | @JavaMethod 35 | public func getDeclaredAnnotation(_ arg0: JavaClass?) -> Annotation! 36 | 37 | @JavaMethod 38 | public func getDeclaredAnnotationsByType(_ arg0: JavaClass?) -> [Annotation?] 39 | 40 | @JavaMethod 41 | public func getDeclaredAnnotations() -> [Annotation?] 42 | } 43 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/generated/WildcardType.swift: -------------------------------------------------------------------------------- 1 | // Auto-generated by Java-to-Swift wrapper generator. 2 | import JavaKit 3 | import JavaRuntime 4 | 5 | @JavaInterface("java.lang.reflect.WildcardType", extends: Type.self) 6 | public struct WildcardType { 7 | @JavaMethod 8 | public func getUpperBounds() -> [Type?] 9 | 10 | @JavaMethod 11 | public func getLowerBounds() -> [Type?] 12 | 13 | @JavaMethod 14 | public func getTypeName() -> String 15 | } 16 | -------------------------------------------------------------------------------- /Sources/JavaKitReflection/swift-java.config: -------------------------------------------------------------------------------- 1 | { 2 | "classes" : { 3 | "java.lang.annotation.Annotation" : "Annotation", 4 | "java.lang.reflect.AccessibleObject" : "AccessibleObject", 5 | "java.lang.reflect.AnnotatedType" : "AnnotatedType", 6 | "java.lang.reflect.Constructor" : "Constructor", 7 | "java.lang.reflect.Executable" : "Executable", 8 | "java.lang.reflect.Field" : "Field", 9 | "java.lang.reflect.GenericArrayType" : "GenericArrayType", 10 | "java.lang.reflect.GenericDeclaration" : "GenericDeclaration", 11 | "java.lang.reflect.Method" : "Method", 12 | "java.lang.reflect.Parameter" : "Parameter", 13 | "java.lang.reflect.ParameterizedType" : "ParameterizedType", 14 | "java.lang.reflect.Type" : "Type", 15 | "java.lang.reflect.TypeVariable" : "TypeVariable", 16 | "java.lang.reflect.WildcardType" : "WildcardType" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/JavaRuntime/dummy.c: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | // Dummy file so that SwiftPM produces an object file 16 | -------------------------------------------------------------------------------- /Sources/JavaRuntime/include/JavaRuntime.h: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef Swift_JavaRuntime_h 16 | #define Swift_JavaRuntime_h 17 | 18 | #include 19 | 20 | #endif /* Swift_JavaRuntime_h */ 21 | -------------------------------------------------------------------------------- /Sources/JavaTypes/JavaDemanglingError.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes an error that can occur when demangling a Java name. 16 | enum JavaDemanglingError: Error { 17 | /// This does not match the form of a Java mangled type name. 18 | case invalidMangledName(String) 19 | 20 | /// Extra text after the mangled name. 21 | case extraText(String) 22 | } 23 | -------------------------------------------------------------------------------- /Sources/JavaTypes/JavaType.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | /// Describes the Java type system. 16 | public enum JavaType: Equatable, Hashable { 17 | case boolean 18 | case byte 19 | case char 20 | case short 21 | case int 22 | case long 23 | case float 24 | case double 25 | case void 26 | 27 | /// A Java class separated into its package (e.g., "java.lang") and class name 28 | /// (e.g., "Object") 29 | case `class`(package: String?, name: String) 30 | 31 | /// A Java array. 32 | indirect case array(JavaType) 33 | 34 | /// Given a class name such as "java.lang.Object", split it into 35 | /// its package and class name to form a class instance. 36 | public init(className name: some StringProtocol) { 37 | if let lastDot = name.lastIndex(of: ".") { 38 | self = .class( 39 | package: String(name[..) -> Any.Type? { 17 | let string = String(cString: name) 18 | let type = _typeByName(string) 19 | precondition(type != nil, "Unable to find type for name: \(string)!") 20 | return type 21 | } 22 | 23 | @_silgen_name("swift_retain") 24 | public func _swiftjava_swift_retain(object: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer 25 | 26 | @_silgen_name("swift_release") 27 | public func _swiftjava_swift_release(object: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer 28 | 29 | @_silgen_name("swift_retainCount") 30 | public func _swiftjava_swift_retainCount(object: UnsafeMutableRawPointer) -> Int 31 | 32 | @_silgen_name("swift_isUniquelyReferenced") 33 | public func _swiftjava_swift_isUniquelyReferenced(object: UnsafeMutableRawPointer) -> Bool 34 | 35 | 36 | @_alwaysEmitIntoClient @_transparent 37 | internal func _swiftjava_withHeapObject( 38 | of object: AnyObject, 39 | _ body: (UnsafeMutableRawPointer) -> R 40 | ) -> R { 41 | defer { _fixLifetime(object) } 42 | let unmanaged = Unmanaged.passUnretained(object) 43 | return body(unmanaged.toOpaque()) 44 | } 45 | -------------------------------------------------------------------------------- /Sources/_CShims/include/_CShimsTargetConditionals.h: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef _SHIMS_TARGET_CONDITIONALS_H 16 | #define _SHIMS_TARGET_CONDITIONALS_H 17 | 18 | #if __has_include() 19 | #include 20 | #endif 21 | 22 | #if (defined(__APPLE__) && defined(__MACH__)) 23 | #define TARGET_OS_MAC 1 24 | #else 25 | #define TARGET_OS_MAC 0 26 | #endif 27 | 28 | #if defined(__linux__) 29 | #define TARGET_OS_LINUX 1 30 | #else 31 | #define TARGET_OS_LINUX 0 32 | #endif 33 | 34 | #if defined(__unix__) 35 | #define TARGET_OS_BSD 1 36 | #else 37 | #define TARGET_OS_BSD 0 38 | #endif 39 | 40 | #if defined(_WIN32) 41 | #define TARGET_OS_WINDOWS 1 42 | #else 43 | #define TARGET_OS_WINDOWS 0 44 | #endif 45 | 46 | #if defined(__wasi__) 47 | #define TARGET_OS_WASI 1 48 | #else 49 | #define TARGET_OS_WASI 0 50 | #endif 51 | 52 | #endif // _SHIMS_TARGET_CONDITIONALS_H 53 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/ClosableSwiftArena.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | /** 18 | * Auto-closable version of {@link SwiftArena}. 19 | */ 20 | public interface ClosableSwiftArena extends SwiftArena, AutoCloseable { 21 | 22 | /** 23 | * Close the arena and make sure all objects it managed are released. 24 | * Throws if unable to verify all resources have been release (e.g. over retained Swift classes) 25 | */ 26 | void close(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/ManagedSwiftType.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import java.lang.foreign.MemorySegment; 18 | 19 | public interface ManagedSwiftType { 20 | /** 21 | * The memory segment of `self` of the managed Swift object/value. 22 | */ 23 | public MemorySegment $memorySegment(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/MemorySegmentUtils.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import java.lang.foreign.MemorySegment; 18 | import java.lang.foreign.ValueLayout; 19 | 20 | public class MemorySegmentUtils { 21 | /** 22 | * Set the value of `target` to the {@link MemorySegment#address()} of the `memorySegment`, 23 | * adjusting for the fact that Swift pointer may be 32 or 64 bit, depending on runtime. 24 | * 25 | * @param target the target to set a value on 26 | * @param memorySegment the origin of the address value to write into `target` 27 | */ 28 | static void setSwiftPointerAddress(MemorySegment target, MemorySegment memorySegment) { 29 | // Write the address of as the value of the newly created pointer. 30 | // We need to type-safely set the pointer value which may be 64 or 32-bit. 31 | if (SwiftValueLayout.SWIFT_INT == ValueLayout.JAVA_LONG) { 32 | target.set(ValueLayout.JAVA_LONG, /*offset=*/0, memorySegment.address()); 33 | } else { 34 | target.set(ValueLayout.JAVA_INT, /*offset=*/0, (int) memorySegment.address()); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/SwiftAnyType.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import java.lang.foreign.GroupLayout; 18 | import java.lang.foreign.MemoryLayout; 19 | import java.lang.foreign.MemorySegment; 20 | 21 | public final class SwiftAnyType { 22 | 23 | private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( 24 | SwiftValueLayout.SWIFT_POINTER 25 | ); 26 | 27 | private final MemorySegment memorySegment; 28 | 29 | public SwiftAnyType(MemorySegment memorySegment) { 30 | // if (SwiftKit.getSwiftInt(memorySegment, 0) > 0) { 31 | // throw new IllegalArgumentException("A Swift Any.Type cannot be null!"); 32 | // } 33 | 34 | this.memorySegment = memorySegment.asReadOnly(); 35 | } 36 | 37 | public MemorySegment $memorySegment() { 38 | return memorySegment; 39 | } 40 | 41 | public GroupLayout $layout() { 42 | return $LAYOUT; 43 | } 44 | 45 | /** 46 | * Get the human-readable Swift type name of this type. 47 | */ 48 | public String getSwiftName() { 49 | return SwiftKit.nameOfSwiftType(memorySegment, true); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "AnySwiftType{" + 55 | "name=" + getSwiftName() + 56 | ", memorySegment=" + memorySegment + 57 | '}'; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/SwiftHeapObject.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import java.lang.foreign.MemorySegment; 18 | 19 | /** 20 | * Represents a wrapper around a Swift heap object, e.g. a {@code class} or an {@code actor}. 21 | */ 22 | public interface SwiftHeapObject { 23 | MemorySegment $memorySegment(); 24 | 25 | /** 26 | * Pointer to the instance. 27 | */ 28 | public default MemorySegment $instance() { 29 | return this.$memorySegment().get(SwiftValueLayout.SWIFT_POINTER, 0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/SwiftInstanceCleanup.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | import java.lang.foreign.MemorySegment; 18 | 19 | /** 20 | * A Swift memory instance cleanup, e.g. count-down a reference count and destroy a class, or destroy struct/enum etc. 21 | */ 22 | record SwiftInstanceCleanup( 23 | MemorySegment selfPointer, 24 | SwiftAnyType selfType, 25 | Runnable markAsDestroyed 26 | ) implements Runnable { 27 | 28 | @Override 29 | public void run() { 30 | markAsDestroyed.run(); 31 | 32 | // Allow null pointers just for AutoArena tests. 33 | if (selfType != null && selfPointer != null) { 34 | System.out.println("[debug] Destroy swift value [" + selfType.getSwiftName() + "]: " + selfPointer); 35 | SwiftValueWitnessTable.destroy(selfType, selfPointer); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/SwiftValue.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit; 16 | 17 | /** 18 | * Represent a wrapper around a Swift value object. e.g. {@code struct} or {@code enum}. 19 | */ 20 | public interface SwiftValue { 21 | } 22 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/util/PlatformUtils.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit.util; 16 | 17 | public class PlatformUtils { 18 | public static boolean isLinux() { 19 | return System.getProperty("os.name").toLowerCase().contains("linux"); 20 | } 21 | 22 | public static boolean isMacOS() { 23 | return System.getProperty("os.name").toLowerCase().contains("mac"); 24 | } 25 | 26 | public static boolean isWindows() { 27 | return System.getProperty("os.name").toLowerCase().contains("windows"); 28 | } 29 | 30 | public static boolean isAarch64() { 31 | return System.getProperty("os.arch").equals("aarm64"); 32 | } 33 | 34 | public static boolean isAmd64() { 35 | String arch = System.getProperty("os.arch"); 36 | return arch.equals("amd64") || arch.equals("x86_64"); 37 | } 38 | 39 | public static String dynamicLibraryName(String base) { 40 | if (isLinux()) { 41 | return "lib" + uppercaseFistLetter(base) + ".so"; 42 | } else { 43 | return "lib" + uppercaseFistLetter(base) + ".dylib"; 44 | } 45 | } 46 | 47 | static String uppercaseFistLetter(String base) { 48 | if (base == null || base.isEmpty()) { 49 | return base; 50 | } 51 | return base.substring(0, 1).toUpperCase() + base.substring(1); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /SwiftKit/src/main/java/org/swift/swiftkit/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | package org.swift.swiftkit.util; 16 | 17 | public class StringUtils { 18 | public static String stripPrefix(String mangledName, String prefix) { 19 | if (mangledName.startsWith(prefix)) { 20 | return mangledName.substring(prefix.length()); 21 | } 22 | return mangledName; 23 | } 24 | 25 | public static String stripSuffix(String mangledName, String suffix) { 26 | if (mangledName.endsWith(suffix)) { 27 | return mangledName.substring(0, mangledName.length() - suffix.length()); 28 | } 29 | return mangledName; 30 | } 31 | 32 | public static String hexString(long number) { 33 | return String.format("0x%02x", number); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024-2025 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | @_spi(Testing) import JExtractSwift 16 | import SwiftSyntax 17 | import SwiftParser 18 | import Testing 19 | 20 | @Suite("Swift symbol table") 21 | struct SwiftSymbolTableSuite { 22 | 23 | @Test func lookupBindingTests() throws { 24 | let symbolTable = SwiftSymbolTable(parsedModuleName: "MyModule") 25 | let sourceFile1: SourceFileSyntax = """ 26 | extension X.Y { 27 | struct Z { } 28 | } 29 | extension X { 30 | struct Y {} 31 | } 32 | """ 33 | let sourceFile2: SourceFileSyntax = """ 34 | struct X {} 35 | """ 36 | 37 | symbolTable.setup([sourceFile1, sourceFile2]) 38 | 39 | let x = try #require(symbolTable.lookupType("X", parent: nil)) 40 | let xy = try #require(symbolTable.lookupType("Y", parent: x)) 41 | let xyz = try #require(symbolTable.lookupType("Z", parent: xy)) 42 | #expect(xyz.qualifiedName == "X.Y.Z") 43 | 44 | #expect(symbolTable.lookupType("Y", parent: nil) == nil) 45 | #expect(symbolTable.lookupType("Z", parent: nil) == nil) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/Java2SwiftTests/JavaTranslatorValidationTests.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import Java2SwiftLib 16 | import XCTest 17 | 18 | final class JavaTranslatorValidationTests: XCTestCase { 19 | func testValidationError() throws { 20 | let translator = try JavaTranslator(swiftModuleName: "SwiftModule", environment: jvm.environment()) 21 | translator.translatedClasses = [ 22 | "TestClass": ("Class1", "Module1"), 23 | "TestClass2": ("Class1", "Module2"), 24 | "TestClass3": ("Class1", "Module1"), 25 | "TestClass4": ("Class1", nil) 26 | ] 27 | 28 | XCTAssertThrowsError(try translator.validateClassConfiguration()) { error in 29 | XCTAssertTrue(error is JavaTranslator.ValidationError) 30 | let validationError = error as! JavaTranslator.ValidationError 31 | switch validationError { 32 | case .multipleClassesMappedToSameName(let swiftToJavaMapping): 33 | XCTAssertEqual(swiftToJavaMapping, [ 34 | JavaTranslator.SwiftToJavaMapping(swiftType: .init(swiftType: "Class1", swiftModule: "Module1"), 35 | javaTypes: ["TestClass", "TestClass3"]) 36 | ]) 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tests/JavaTypesTests/ManglingTests.swift: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | import JavaTypes 16 | import Testing 17 | 18 | @Suite 19 | struct ManglingTests { 20 | 21 | @Test 22 | func methodMangling() throws { 23 | let demangledSignature = try MethodSignature( 24 | mangledName: "(ILjava/lang/String;[I)J" 25 | ) 26 | let expectedSignature = MethodSignature( 27 | resultType: .long, 28 | parameterTypes: [ 29 | .int, 30 | .class(package: "java.lang", name: "String"), 31 | .array(.int), 32 | ] 33 | ) 34 | #expect(demangledSignature == expectedSignature) 35 | #expect(expectedSignature.mangledName == "(ILjava/lang/String;[I)J") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /buildSrc/README.md: -------------------------------------------------------------------------------- 1 | buildSrc are shared "build library code" that is available to all sub-projects of the primary build. 2 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.7.3") 21 | } 22 | 23 | def cleanSwift = tasks.register("cleanSwift", Exec) { 24 | workingDir = layout.projectDirectory 25 | commandLine "swift" 26 | args("package", "clean") 27 | } 28 | tasks.clean { 29 | dependsOn("cleanSwift") 30 | } 31 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG swift_version=nightly-main 2 | ARG ubuntu_version=jammy 3 | ARG base_image=docker.io/swiftlang/swift:$swift_version-$ubuntu_version 4 | FROM $base_image 5 | # needed to do again after FROM due to docker limitation 6 | ARG swift_version 7 | ARG ubuntu_version 8 | 9 | # set as UTF-8 10 | RUN apt-get update && apt-get install -y \ 11 | locales locales-all \ 12 | make \ 13 | libc6-dev \ 14 | curl \ 15 | libjemalloc2 \ 16 | libjemalloc-dev 17 | ENV LC_ALL=en_US.UTF-8 18 | ENV LANG=en_US.UTF-8 19 | ENV LANGUAGE=en_US.UTF-8 20 | 21 | # JDK dependency 22 | COPY install_jdk.sh . 23 | RUN bash -xc 'JDK_VENDOR=Corretto ./install_jdk.sh' 24 | ENV JAVA_HOME="/usr/lib/jvm/default-jdk" 25 | ENV PATH="$PATH:/usr/lib/jvm/default-jdk/bin" 26 | 27 | # Install "untested" nightly 'main' Swift 28 | # TODO: Only do this if the released Swift is older than what we require 29 | #COPY install_untested_nightly_swift.sh . 30 | RUN #bash -xc './install_untested_nightly_swift.sh' 31 | -------------------------------------------------------------------------------- /docker/docker-compose.2204.main.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | runtime-setup: 4 | image: swift-java:22.04-main 5 | build: 6 | args: 7 | base_image: "swiftlang/swift:nightly-main-jammy" 8 | 9 | unit-tests: 10 | image: swift-java:22.04-main 11 | 12 | integration-tests: 13 | image: swift-java:22.04-main 14 | 15 | documentation-check: 16 | image: swift-java:22.04-main 17 | 18 | test-swift: 19 | image: swift-java:22.04-main 20 | test-java: 21 | image: swift-java:22.04-main 22 | test: 23 | image: swift-java:22.04-main 24 | -------------------------------------------------------------------------------- /docker/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # this file is not designed to be run directly 2 | # instead, use the docker-compose.. files 3 | # eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.1604.41.yaml run test 4 | services: 5 | 6 | runtime-setup: 7 | image: swift-java:default 8 | build: 9 | context: . 10 | dockerfile: Dockerfile 11 | 12 | common: &common 13 | image: swift-java:default 14 | depends_on: [runtime-setup] 15 | volumes: 16 | - ~/.ssh:/root/.ssh 17 | - ..:/swift-java:z 18 | working_dir: /swift-java 19 | environment: 20 | JAVA_HOME: /usr/lib/jvm/default-jdk 21 | 22 | soundness: 23 | <<: *common 24 | command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh" 25 | 26 | unit-tests: 27 | <<: *common 28 | command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${IMPORT_CHECK_ARG-}" 29 | 30 | test-swift: 31 | <<: *common 32 | command: /bin/bash -xcl "uname -a && swift -version && java -version && swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}" 33 | 34 | test-java: 35 | <<: *common 36 | command: /bin/bash -xcl "uname -a && swift -version && java -version && make jextract-generate && ./gradlew test --debug" 37 | 38 | test: 39 | <<: *common 40 | command: /bin/bash -xcl "uname -a && swift -version && java -version && make jextract-generate && swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} && ./gradlew test --debug" 41 | 42 | # util 43 | 44 | shell: 45 | <<: *common 46 | entrypoint: /bin/bash 47 | -------------------------------------------------------------------------------- /docker/install_untested_nightly_swift.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift.org project authors 7 | ## Licensed under Apache License v2.0 8 | ## 9 | ## See LICENSE.txt for license information 10 | ## See CONTRIBUTORS.txt for the list of Swift.org project authors 11 | ## 12 | ## SPDX-License-Identifier: Apache-2.0 13 | ## 14 | ##===----------------------------------------------------------------------===## 15 | set -euo pipefail 16 | 17 | echo "Download [nightly] [untested] Swift toolchain for: $(uname -m)" 18 | 19 | ARCH="$(arch)" 20 | if [[ "$ARCH" = "i386" || "$ARCH" = "x86_64" ]]; then 21 | SWIFT_UNTESTED_TOOLCHAIN_JOB_URL="https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastSuccessfulBuild/consoleText" 22 | else 23 | SWIFT_UNTESTED_TOOLCHAIN_JOB_URL="https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64/lastSuccessfulBuild/consoleText" 24 | fi 25 | 26 | if [[ "$(grep "22.04" /etc/lsb-release)" = "" ]]; then 27 | echo "This script specifically only supports Ubuntu 22.04 due to nightly toolchain availability" 28 | exit 1 29 | fi 30 | 31 | UNTESTED_TOOLCHAIN_URL=$(curl -s $SWIFT_UNTESTED_TOOLCHAIN_JOB_URL | grep 'Toolchain: ' | sed 's/Toolchain: //g') 32 | UNTESTED_TOOLCHAIN_FILENAME=$"toolchain.tar.gz" 33 | 34 | echo "Download toolchain: $UNTESTED_TOOLCHAIN_URL" 35 | 36 | cd / 37 | curl -s "$UNTESTED_TOOLCHAIN_URL" > "$UNTESTED_TOOLCHAIN_FILENAME" 38 | 39 | swift -version 40 | 41 | echo "Extract toolchain: $UNTESTED_TOOLCHAIN_FILENAME" 42 | tar xzf "$UNTESTED_TOOLCHAIN_FILENAME" 43 | swift -version 44 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftlang/swift-java/6267c8fdef12691830dd5775493da8e9abf22974/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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift.org project authors 6 | // Licensed under Apache License v2.0 7 | // 8 | // See LICENSE.txt for license information 9 | // See CONTRIBUTORS.txt for the list of Swift.org project authors 10 | // 11 | // SPDX-License-Identifier: Apache-2.0 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | pluginManagement { 16 | includeBuild("BuildLogic") 17 | } 18 | 19 | rootProject.name = "swift-java" 20 | 21 | include "SwiftKit" 22 | 23 | // Include sample apps -- you can run them via `gradle Name:run` 24 | new File(rootDir, "Samples").listFiles().each { 25 | if (it.directory && new File(it, 'build.gradle').exists()) { 26 | include ":Samples:${it.name}" 27 | } 28 | } 29 | --------------------------------------------------------------------------------