├── .github ├── dependabot.yml ├── getdeps.py ├── libadwaita-appstream.diff └── workflows │ ├── dependency-submission.yml │ ├── publish-maven.yml │ └── windows-gtk.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ ├── GenerateSources.java │ └── GirParserService.java │ └── kotlin │ ├── java-gi.library-conventions.gradle.kts │ ├── java-gi.module.gradle.kts │ └── java-gi.test-conventions.gradle.kts ├── docs ├── advanced.md ├── examples.md ├── generate.md ├── getting-started │ ├── getting_started_00.md │ ├── getting_started_01.md │ ├── getting_started_02.md │ ├── getting_started_03.md │ ├── getting_started_04.md │ ├── getting_started_05.md │ ├── getting_started_06.md │ ├── getting_started_07.md │ ├── getting_started_08.md │ ├── getting_started_09.md │ ├── getting_started_10.md │ ├── getting_started_11.md │ ├── getting_started_12.md │ ├── getting_started_13.md │ ├── getting_started_14.md │ └── img │ │ ├── drawing.png │ │ ├── exampleapp.png │ │ ├── getting-started-app1.png │ │ ├── getting-started-app2.png │ │ ├── getting-started-app3.png │ │ ├── getting-started-app4.png │ │ ├── getting-started-app6.png │ │ ├── getting-started-app7.png │ │ ├── getting-started-app8.png │ │ ├── getting-started-app9.png │ │ ├── grid-packing.png │ │ ├── hello-world.png │ │ └── window-default.png ├── img │ ├── browser-screenshot.png │ ├── gnome-builder-screenshot.png │ ├── javadoc.png │ └── simple-helloworld.png ├── index.md ├── macros │ └── mkdocs-macros.py ├── register.md ├── templates.md └── usage.md ├── ext └── build.gradle.kts ├── generator ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── java │ ├── io │ └── github │ │ └── jwharm │ │ └── javagi │ │ ├── JavaGI.java │ │ ├── configuration │ │ ├── ClassNames.java │ │ ├── LicenseNotice.java │ │ ├── ModuleInfo.java │ │ └── Patches.java │ │ ├── generators │ │ ├── AliasGenerator.java │ │ ├── BoxedGenerator.java │ │ ├── BuilderGenerator.java │ │ ├── CallableGenerator.java │ │ ├── CallbackGenerator.java │ │ ├── ClassGenerator.java │ │ ├── ClosureGenerator.java │ │ ├── ConstructorGenerator.java │ │ ├── DocGenerator.java │ │ ├── EnumGenerator.java │ │ ├── FieldGenerator.java │ │ ├── InterfaceGenerator.java │ │ ├── MemoryLayoutGenerator.java │ │ ├── MethodGenerator.java │ │ ├── ModuleInfoGenerator.java │ │ ├── NamespaceGenerator.java │ │ ├── PackageInfoGenerator.java │ │ ├── PostprocessingGenerator.java │ │ ├── PreprocessingGenerator.java │ │ ├── RecordGenerator.java │ │ ├── RegisteredTypeGenerator.java │ │ ├── SignalGenerator.java │ │ ├── TypedValueGenerator.java │ │ └── UnionGenerator.java │ │ ├── gir │ │ ├── Alias.java │ │ ├── AnyType.java │ │ ├── Array.java │ │ ├── Attribute.java │ │ ├── Bitfield.java │ │ ├── Boxed.java │ │ ├── CInclude.java │ │ ├── Callable.java │ │ ├── CallableAttrs.java │ │ ├── Callback.java │ │ ├── Class.java │ │ ├── Constant.java │ │ ├── Constructor.java │ │ ├── Direction.java │ │ ├── Doc.java │ │ ├── DocDeprecated.java │ │ ├── DocFormat.java │ │ ├── DocStability.java │ │ ├── DocVersion.java │ │ ├── Docsection.java │ │ ├── Documentation.java │ │ ├── EnumType.java │ │ ├── Enumeration.java │ │ ├── Field.java │ │ ├── FieldContainer.java │ │ ├── Function.java │ │ ├── FunctionInline.java │ │ ├── FunctionMacro.java │ │ ├── GirElement.java │ │ ├── GirParser.java │ │ ├── Implements.java │ │ ├── Include.java │ │ ├── InfoAttrs.java │ │ ├── InfoElements.java │ │ ├── InstanceParameter.java │ │ ├── Interface.java │ │ ├── Library.java │ │ ├── Member.java │ │ ├── Method.java │ │ ├── MethodInline.java │ │ ├── Multiplatform.java │ │ ├── Namespace.java │ │ ├── Node.java │ │ ├── Package.java │ │ ├── Parameter.java │ │ ├── Parameters.java │ │ ├── Prerequisite.java │ │ ├── Property.java │ │ ├── Record.java │ │ ├── RegisteredType.java │ │ ├── Repository.java │ │ ├── ReturnValue.java │ │ ├── Scope.java │ │ ├── Signal.java │ │ ├── SourcePosition.java │ │ ├── Stability.java │ │ ├── StandardLayoutType.java │ │ ├── TransferOwnership.java │ │ ├── Type.java │ │ ├── TypeReference.java │ │ ├── TypedValue.java │ │ ├── Union.java │ │ ├── Varargs.java │ │ ├── VirtualMethod.java │ │ └── When.java │ │ ├── patches │ │ ├── AdwPatch.java │ │ ├── BasePatch.java │ │ ├── FreetypePatch.java │ │ ├── GIMarshallingTestsPatch.java │ │ ├── GLibPatch.java │ │ ├── GObjectPatch.java │ │ ├── GdkPatch.java │ │ ├── GioPatch.java │ │ ├── GstAudioPatch.java │ │ ├── GstBasePatch.java │ │ ├── GstPatch.java │ │ ├── GstVideoPatch.java │ │ ├── GtkPatch.java │ │ ├── HarfBuzzPatch.java │ │ ├── PangoPatch.java │ │ ├── SoupPatch.java │ │ └── WebKitPatch.java │ │ └── util │ │ ├── CollectionUtils.java │ │ ├── Conversions.java │ │ ├── GeneratedAnnotationBuilder.java │ │ ├── Javadoc.java │ │ ├── Numbers.java │ │ ├── PartialStatement.java │ │ ├── Patch.java │ │ └── Platform.java │ └── module-info.java ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mkdocs.yml ├── modules ├── main │ ├── adw │ │ └── build.gradle.kts │ ├── gdk │ │ └── build.gradle.kts │ ├── gdkpixbuf │ │ └── build.gradle.kts │ ├── gio │ │ ├── build.gradle.kts │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── jwharm │ │ │ │ └── javagi │ │ │ │ └── gio │ │ │ │ ├── AutoCloseable.java │ │ │ │ ├── ListIndexModel.java │ │ │ │ ├── ListModelJavaList.java │ │ │ │ ├── ListModelJavaListMutable.java │ │ │ │ ├── ListModelJavaListSpliceable.java │ │ │ │ └── package-info.java │ │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── jwharm │ │ │ └── javagi │ │ │ └── test │ │ │ └── gio │ │ │ ├── FileTest.java │ │ │ ├── IdleCallbackTest.java │ │ │ ├── ListModelTest.java │ │ │ ├── PropertiesTest.java │ │ │ ├── SignalTest.java │ │ │ ├── StrvArrayTest.java │ │ │ ├── ValueTest.java │ │ │ └── WeakRefTest.java │ ├── glib │ │ ├── build.gradle.kts │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ ├── io │ │ │ │ └── github │ │ │ │ │ └── jwharm │ │ │ │ │ └── javagi │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── base │ │ │ │ │ ├── Alias.java │ │ │ │ │ ├── Enumeration.java │ │ │ │ │ ├── Floating.java │ │ │ │ │ ├── FunctionPointer.java │ │ │ │ │ ├── GErrorException.java │ │ │ │ │ ├── GLibLogger.java │ │ │ │ │ ├── Out.java │ │ │ │ │ ├── Proxy.java │ │ │ │ │ ├── ProxyInstance.java │ │ │ │ │ ├── TransferOwnership.java │ │ │ │ │ ├── UnsupportedPlatformException.java │ │ │ │ │ └── package-info.java │ │ │ │ │ ├── glib │ │ │ │ │ └── types │ │ │ │ │ │ ├── VariantTypes.java │ │ │ │ │ │ └── package-info.java │ │ │ │ │ ├── interop │ │ │ │ │ ├── ArenaCloseAction.java │ │ │ │ │ ├── Arenas.java │ │ │ │ │ ├── Interop.java │ │ │ │ │ ├── InteropException.java │ │ │ │ │ ├── LibLoad.java │ │ │ │ │ ├── MemoryCleaner.java │ │ │ │ │ ├── Platform.java │ │ │ │ │ ├── VarargsInvoker.java │ │ │ │ │ ├── VarargsUtil.java │ │ │ │ │ └── package-info.java │ │ │ │ │ └── package-info.java │ │ │ │ └── org │ │ │ │ └── gnome │ │ │ │ └── glib │ │ │ │ ├── ByteArray.java │ │ │ │ ├── HashTable.java │ │ │ │ ├── List.java │ │ │ │ └── SList.java │ │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── jwharm │ │ │ └── javagi │ │ │ └── interop │ │ │ ├── ArrayTest.java │ │ │ ├── BytesTest.java │ │ │ ├── FlagsTest.java │ │ │ ├── HashTableTest.java │ │ │ ├── MarshalTest.java │ │ │ └── VarargsTest.java │ ├── gmodule │ │ └── build.gradle.kts │ ├── gobject │ │ ├── build.gradle.kts │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── jwharm │ │ │ │ └── javagi │ │ │ │ └── gobject │ │ │ │ ├── BindingBuilder.java │ │ │ │ ├── Builder.java │ │ │ │ ├── BuilderInterface.java │ │ │ │ ├── InstanceCache.java │ │ │ │ ├── JavaClosure.java │ │ │ │ ├── SignalConnection.java │ │ │ │ ├── ValueUtil.java │ │ │ │ ├── annotations │ │ │ │ ├── ClassInit.java │ │ │ │ ├── Flags.java │ │ │ │ ├── GType.java │ │ │ │ ├── InstanceInit.java │ │ │ │ ├── InterfaceInit.java │ │ │ │ ├── Layout.java │ │ │ │ ├── Namespace.java │ │ │ │ ├── Property.java │ │ │ │ ├── RegisteredType.java │ │ │ │ ├── Signal.java │ │ │ │ └── package-info.java │ │ │ │ ├── package-info.java │ │ │ │ └── types │ │ │ │ ├── Overrides.java │ │ │ │ ├── Properties.java │ │ │ │ ├── Signals.java │ │ │ │ ├── TypeCache.java │ │ │ │ ├── TypeRegistrationException.java │ │ │ │ ├── Types.java │ │ │ │ └── package-info.java │ │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── jwharm │ │ │ └── javagi │ │ │ └── test │ │ │ └── gobject │ │ │ ├── ClosureTest.java │ │ │ ├── CustomEnumTest.java │ │ │ ├── CustomInterfaceTest.java │ │ │ ├── DerivedClassTest.java │ │ │ ├── NewSignalTest.java │ │ │ ├── PropertyBindingTest.java │ │ │ ├── PropertyTest.java │ │ │ └── ToStringTest.java │ ├── graphene │ │ └── build.gradle.kts │ ├── gsk │ │ └── build.gradle.kts │ ├── gst │ │ └── build.gradle.kts │ ├── gstaudio │ │ └── build.gradle.kts │ ├── gstbase │ │ └── build.gradle.kts │ ├── gstpbutils │ │ └── build.gradle.kts │ ├── gstvideo │ │ └── build.gradle.kts │ ├── gtk │ │ ├── build.gradle.kts │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── jwharm │ │ │ │ └── javagi │ │ │ │ └── gtk │ │ │ │ ├── annotations │ │ │ │ ├── GtkCallback.java │ │ │ │ ├── GtkChild.java │ │ │ │ ├── GtkTemplate.java │ │ │ │ └── package-info.java │ │ │ │ ├── types │ │ │ │ ├── TemplateTypes.java │ │ │ │ └── package-info.java │ │ │ │ └── util │ │ │ │ ├── BuilderJavaScope.java │ │ │ │ └── package-info.java │ │ │ └── test │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── jwharm │ │ │ │ └── javagi │ │ │ │ └── test │ │ │ │ └── gtk │ │ │ │ ├── ExpressionTest.java │ │ │ │ ├── ListTest.java │ │ │ │ ├── MutableListTest.java │ │ │ │ ├── NestedStructTest.java │ │ │ │ ├── PangoLayoutLineTest.java │ │ │ │ ├── SpliceableListTest.java │ │ │ │ ├── SubClassingTest.java │ │ │ │ ├── TemplateChildTest.java │ │ │ │ └── TemplateSignalTest.java │ │ │ └── resources │ │ │ ├── TemplateChildTest.ui │ │ │ ├── TemplateSignalTest.ui │ │ │ ├── test.gresource │ │ │ └── test.gresource.xml │ ├── gtksourceview │ │ └── build.gradle.kts │ ├── harfbuzz │ │ └── build.gradle.kts │ ├── javascriptcore │ │ └── build.gradle.kts │ ├── pango │ │ └── build.gradle.kts │ ├── pangocairo │ │ └── build.gradle.kts │ ├── soup │ │ └── build.gradle.kts │ ├── webkit │ │ └── build.gradle.kts │ └── webkitwebprocessextension │ │ └── build.gradle.kts └── test │ ├── gimarshallingtests │ ├── build.gradle.kts │ └── src │ │ └── test │ │ └── java │ │ └── org │ │ └── gnome │ │ └── gi │ │ └── gimarshallingtests │ │ └── TestGiMarshalling.java │ ├── regress │ └── build.gradle.kts │ ├── regressunix │ └── build.gradle.kts │ ├── utility │ └── build.gradle.kts │ └── warnlib │ └── build.gradle.kts └── settings.gradle.kts /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: 'github-actions' 4 | directory: '/' 5 | schedule: 6 | interval: 'weekly' 7 | groups: 8 | non-breaking-changes: 9 | update-types: [minor, patch] 10 | 11 | - package-ecosystem: 'gradle' 12 | directory: '/' 13 | schedule: 14 | interval: 'weekly' 15 | groups: 16 | non-breaking-changes: 17 | update-types: [minor, patch] 18 | 19 | -------------------------------------------------------------------------------- /.github/getdeps.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | from pathlib import Path 3 | 4 | 5 | def get_dll_dependencies(dll_path): 6 | try: 7 | result = subprocess.run(['dumpbin', '/dependents', dll_path], 8 | capture_output=True, text=True, check=True) 9 | dependencies = [] 10 | for line in result.stdout.splitlines(): 11 | line = line.strip() 12 | if line.lower().endswith('.dll'): 13 | dependencies.append(line) 14 | return dependencies 15 | except subprocess.CalledProcessError: 16 | return [] 17 | 18 | 19 | def scan_current_directory(): 20 | current_dir = Path('.') 21 | dll_files = [f for f in current_dir.glob('*.dll')] 22 | 23 | dependency_map = {} 24 | for dll in dll_files: 25 | deps = get_dll_dependencies(str(dll)) 26 | existing_deps = [d for d in deps if Path(d).exists()] 27 | if existing_deps: 28 | dependency_map[dll.name] = existing_deps 29 | 30 | with open('java-gi-meta-v1.txt', 'w') as f: 31 | for dll, deps in dependency_map.items(): 32 | f.write(f"{dll}: {', '.join(deps)}\n") 33 | 34 | 35 | if __name__ == '__main__': 36 | scan_current_directory() 37 | -------------------------------------------------------------------------------- /.github/workflows/dependency-submission.yml: -------------------------------------------------------------------------------- 1 | name: Dependency Submission 2 | 3 | on: 4 | push: 5 | branches: [ 'main' ] 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | dependency-submission: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-java@v4 16 | with: 17 | distribution: temurin 18 | java-version: 22 19 | 20 | - name: Generate and submit dependency graph 21 | uses: gradle/actions/dependency-submission@v4 22 | with: 23 | gradle-version: 8.8 24 | -------------------------------------------------------------------------------- /.github/workflows/publish-maven.yml: -------------------------------------------------------------------------------- 1 | name: Publish package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Setup Pages 15 | uses: actions/configure-pages@v5 16 | 17 | - name: Setup Python 18 | uses: actions/setup-python@v5 19 | with: 20 | python-version: '3.x' 21 | 22 | - name: Setup MkDocs 23 | run: pip3 install mkdocs mkdocs-material mkdocs-macros-plugin 24 | 25 | - name: Setup Java 26 | uses: actions/setup-java@v4 27 | with: 28 | java-version: 22 29 | distribution: 'temurin' 30 | 31 | - name: Checkout java-gi repository 32 | uses: actions/checkout@v4 33 | with: 34 | repository: 'jwharm/java-gi' 35 | path: 'java-gi' 36 | submodules: 'true' 37 | 38 | - name: Install dependencies to build gobject-introspection-test 39 | uses: awalsh128/cache-apt-pkgs-action@v1 40 | with: 41 | packages: meson pkg-config libglib2.0-dev libgirepository1.0-dev libcairo2-dev 42 | version: 1.0 43 | 44 | - name: Setup Gradle 45 | uses: gradle/actions/setup-gradle@v4 46 | 47 | - name: Run Gradle build 48 | working-directory: java-gi/ 49 | run: ./gradlew build javadoc 50 | 51 | - name: Run Mkdocs build 52 | working-directory: java-gi/ 53 | run: mkdocs build 54 | 55 | - name: Move generated Javadoc to website 56 | run: | 57 | mv java-gi/site site 58 | mv java-gi/build/docs/javadoc site/javadoc 59 | 60 | - name: Upload Site Artifact 61 | uses: actions/upload-pages-artifact@v3 62 | with: 63 | path: 'site' 64 | 65 | pages: 66 | runs-on: ubuntu-latest 67 | needs: publish 68 | if: github.event_name == 'push' 69 | permissions: 70 | pages: write 71 | id-token: write 72 | environment: 73 | name: github-pages 74 | url: ${{ steps.deployment.outputs.page_url }} 75 | steps: 76 | - name: Deploy to GitHub Pages 77 | id: deployment 78 | uses: actions/deploy-pages@v4 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ############################## 2 | ## Java 3 | ############################## 4 | .mtj.tmp/ 5 | *.class 6 | *.jar 7 | *.war 8 | *.ear 9 | *.nar 10 | hs_err_pid* 11 | replay_pid* 12 | 13 | ############################## 14 | ## Maven 15 | ############################## 16 | target/ 17 | pom.xml.tag 18 | pom.xml.releaseBackup 19 | pom.xml.versionsBackup 20 | pom.xml.next 21 | pom.xml.bak 22 | release.properties 23 | dependency-reduced-pom.xml 24 | buildNumber.properties 25 | .mvn/timing.properties 26 | .mvn/wrapper/maven-wrapper.jar 27 | 28 | ############################## 29 | ## Gradle 30 | ############################## 31 | bin/ 32 | build/ 33 | .gradle 34 | .gradletasknamecache 35 | gradle-app.setting 36 | !gradle-wrapper.jar 37 | 38 | ############################## 39 | ## IntelliJ 40 | ############################## 41 | out/ 42 | .idea/ 43 | .idea_modules/ 44 | *.iml 45 | *.ipr 46 | *.iws 47 | 48 | ############################## 49 | ## Eclipse 50 | ############################## 51 | .settings/ 52 | tmp/ 53 | .metadata 54 | .classpath 55 | .project 56 | *.tmp 57 | *.bak 58 | *.swp 59 | *~.nib 60 | local.properties 61 | .loadpath 62 | .factorypath 63 | 64 | ############################## 65 | ## NetBeans 66 | ############################## 67 | nbproject/private/ 68 | nbbuild/ 69 | dist/ 70 | nbdist/ 71 | nbactions.xml 72 | nb-configuration.xml 73 | 74 | ############################## 75 | ## Visual Studio Code 76 | ############################## 77 | .vscode/ 78 | .code-workspace 79 | 80 | ############################## 81 | ## OS X 82 | ############################## 83 | .DS_Store 84 | 85 | ############################## 86 | ## MkDocs 87 | ############################## 88 | site/ 89 | __pycache__ 90 | 91 | ############################## 92 | ## Compiled GResource files 93 | ############################## 94 | src/test/resources/*.gresource 95 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ext/gir-files"] 2 | path = ext/gir-files 3 | url = https://github.com/gircore/gir-files 4 | [submodule "ext/gobject-introspection-tests"] 5 | path = ext/gobject-introspection-tests 6 | url = https://gitlab.gnome.org/gnome/gobject-introspection-tests 7 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | } 4 | 5 | tasks.named("build") { 6 | dependsOn(gradle.includedBuild("generator").task(":build")) 7 | dependsOn(gradle.includedBuild("generator").task(":assembleDist")) 8 | } 9 | 10 | tasks.named("clean") { 11 | dependsOn(gradle.includedBuild("generator").task(":clean")) 12 | } 13 | 14 | tasks.register("assembleDist") { 15 | dependsOn(gradle.includedBuild("generator").task(":assembleDist")) 16 | } 17 | 18 | tasks.withType().configureEach { 19 | options.encoding = "UTF-8" 20 | } 21 | 22 | // Disable jar for top-level project 23 | tasks.withType().configureEach { 24 | enabled = false 25 | } 26 | 27 | java { 28 | toolchain.languageVersion = JavaLanguageVersion.of(libs.versions.jdk.get()) 29 | } 30 | 31 | // Generate javadoc for all modules 32 | tasks.withType().configureEach { 33 | options { 34 | this as StandardJavadocDocletOptions 35 | addStringOption("tag", "apiNote:a:API Note:") 36 | addStringOption("Xdoclint:none", "-quiet") 37 | addStringOption("-add-modules", "org.jetbrains.annotations,org.freedesktop.cairo") 38 | encoding = "UTF-8" 39 | } 40 | exclude("**/module-info.java") 41 | 42 | // Include only the main modules in the javadoc 43 | val mainModules = subprojects.filter { 44 | it.plugins.hasPlugin("java-gi.library-conventions") 45 | } 46 | 47 | source(mainModules.flatMap { 48 | it.sourceSets["main"].allJava.srcDirs 49 | }) 50 | 51 | // Exclude external dependencies from the classpath 52 | classpath = files(mainModules.flatMap { subproject -> 53 | subproject.sourceSets["main"].compileClasspath.filter { file -> 54 | val path = file.absolutePath.replace("\\", "/") 55 | path.contains("/org.jetbrains/annotations/") 56 | || path.contains("/io.github.jwharm.cairobindings/cairo/") 57 | } 58 | }) 59 | 60 | // Ensure all source code is generated before the Javadoc task starts 61 | mainModules.forEach { 62 | dependsOn(it.tasks.named("generateSources")) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | gradlePluginPortal() 8 | } 9 | 10 | dependencies { 11 | implementation(libs.javapoet) 12 | implementation(libs.annotations) 13 | implementation(libs.javagi.generator) 14 | implementation(libs.mavenpublish) 15 | } 16 | 17 | tasks.withType().configureEach { 18 | options.encoding = "UTF-8" 19 | } 20 | 21 | java { 22 | toolchain.languageVersion = JavaLanguageVersion.of(libs.versions.jdk.get()) 23 | } 24 | 25 | kotlin { 26 | jvmToolchain(libs.versions.jdk.get().toInt()) 27 | } 28 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "buildSrc" 2 | 3 | plugins { 4 | id("dev.panuszewski.typesafe-conventions") version "0.7.3" 5 | } 6 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/java-gi.library-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.vanniktech.maven.publish.SonatypeHost 2 | 3 | plugins { 4 | id("java-gi.module") 5 | id("com.vanniktech.maven.publish") 6 | } 7 | 8 | mavenPublishing { 9 | publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 10 | signAllPublications() 11 | coordinates("io.github.jwharm.javagi", project.name, project.version.toString()) 12 | pom { 13 | val capitalizedId = project.name.replaceFirstChar(Char::titlecase) 14 | name = capitalizedId 15 | description = "Java language bindings for $capitalizedId, generated with Java-GI" 16 | url = "https://jwharm.github.io/java-gi/" 17 | licenses { 18 | license { 19 | name = "GNU Lesser General Public License, version 2.1" 20 | url = "https://www.gnu.org/licenses/lgpl-2.1.txt" 21 | } 22 | } 23 | developers { 24 | developer { 25 | id = "jwharm" 26 | name = "Jan-Willem Harmannij" 27 | email = "jwharmannij@gmail.com" 28 | url = "https://github.com/jwharm" 29 | } 30 | } 31 | scm { 32 | connection = "scm:git:git://github.com/jwharm/java-gi.git" 33 | developerConnection = "scm:git:ssh://github.com:jwharm/java-gi.git" 34 | url = "https://github.com/jwharm/java-gi/tree/master" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/java-gi.test-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.module") 3 | } 4 | 5 | with(gradle.sharedServices.registrations["gir"].service.get() as GirParserService) { 6 | parameters.inputDirectories.from(project(":ext") 7 | .layout.buildDirectory 8 | .dir("meson") 9 | ) 10 | } 11 | 12 | afterEvaluate { 13 | tasks.withType().configureEach { 14 | dependsOn(project(":ext").tasks.named("mesonBuild")) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples.md: -------------------------------------------------------------------------------- 1 | # Example applications 2 | 3 | A set of example applications is available on the [java-gi-examples GitHub repository](https://github.com/jwharm/java-gi-examples). To run an example, install Java 22 and Gradle 8.3 (or newer), and clone the Git repository: 4 | 5 | ``` 6 | git clone https://github.com/jwharm/java-gi-examples 7 | ``` 8 | 9 | Move into one of the example folders and run `gradle run`: 10 | 11 | ``` 12 | cd HelloWorld 13 | gradle run 14 | ``` 15 | 16 | If you see an error about a missing library, make sure that all dependencies are installed, and available on Java library path (the `"java.library.path"` system property). If necessary, you can override the Java library path with the `-Djava.library.path=` JVM argument in the `gradle.build` file. By default, it contains the system library folders of the common (RedHat/Fedora, Arch and Debian/Ubuntu) Linux distributions. Read [here](usage.md) for instructions about other distributions and operating systems. 17 | -------------------------------------------------------------------------------- /docs/getting-started/getting_started_00.md: -------------------------------------------------------------------------------- 1 | This guide is based off the "[Getting Started](https://docs.gtk.org/gtk4/getting_started.html)" guide on [docs.gtk.org](https://docs.gtk.org/). The examples have been ported to Java, and the build instructions will help you setup a Java project and build it with Gradle. 2 | 3 | GTK is a [widget toolkit](http://en.wikipedia.org/wiki/Widget_toolkit). Each user interface created by GTK consists of widgets. This is implemented in C using {{ javadoc('GObject') }}, an object-oriented framework for C. Widgets are organized in a hierarchy. The window widget is the main container. The user interface is then built by adding buttons, drop-down menus, input fields, and other widgets to the window. If you are creating complex user interfaces it is recommended to use GtkBuilder and its GTK-specific markup description language, instead of assembling the interface manually. 4 | 5 | GTK is event-driven. The toolkit listens for events such as a click on a button, and passes the event to your application. 6 | 7 | This chapter contains some tutorial information to get you started with GTK programming. It assumes that you have GTK, its dependencies, a Java compiler and the Gradle build tool installed and ready to use. If you need to build GTK itself first, refer to the [Compiling the GTK libraries](https://docs.gtk.org/gtk4/building.html/building.html) section in this 8 | reference. If you don't know how to install Java or Gradle (we use Gradle in this tutorial), just install a Java IDE and follow its instructions, or use a command-line toolkit manager such as [SDKMAN!](https://sdkman.io/). 9 | 10 | [Next](getting_started_01.md){ .md-button } 11 | -------------------------------------------------------------------------------- /docs/getting-started/img/drawing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/drawing.png -------------------------------------------------------------------------------- /docs/getting-started/img/exampleapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/exampleapp.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app1.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app2.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app3.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app4.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app6.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app7.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app8.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/getting-started-app9.png -------------------------------------------------------------------------------- /docs/getting-started/img/grid-packing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/grid-packing.png -------------------------------------------------------------------------------- /docs/getting-started/img/hello-world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/hello-world.png -------------------------------------------------------------------------------- /docs/getting-started/img/window-default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/getting-started/img/window-default.png -------------------------------------------------------------------------------- /docs/img/browser-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/img/browser-screenshot.png -------------------------------------------------------------------------------- /docs/img/gnome-builder-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/img/gnome-builder-screenshot.png -------------------------------------------------------------------------------- /docs/img/javadoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/img/javadoc.png -------------------------------------------------------------------------------- /docs/img/simple-helloworld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/docs/img/simple-helloworld.png -------------------------------------------------------------------------------- /docs/macros/mkdocs-macros.py: -------------------------------------------------------------------------------- 1 | def define_env(env): 2 | "Hook function" 3 | 4 | urls = { 'GLib': 'https://docs.gtk.org/glib/', 5 | 'GObject': 'https://docs.gtk.org/gobject/', 6 | 'GModule': 'https://docs.gtk.org/gmodule/', 7 | 'GIO': 'https://docs.gtk.org/gio/', 8 | 'Gsk': 'https://docs.gtk.org/gsk4/', 9 | 'Gdk': 'https://docs.gtk.org/gdk4/', 10 | 'Pango': 'https://docs.gtk.org/Pango/', 11 | 'GdkPixbuf': 'https://docs.gtk.org/gdk-pixbuf/', 12 | 'Gtk': 'https://docs.gtk.org/gtk4/' 13 | } 14 | 15 | @env.macro 16 | def doc(docstr): 17 | ns = get_ns(docstr) 18 | name = docstr.split(ns + '.')[1] 19 | url = urls[ns] + get_type(docstr) + '.' + name 20 | return f'[{name}]({url})' 21 | 22 | def get_ns(docstr): 23 | name = docstr.split('@')[1] 24 | return name.split('.')[0] 25 | 26 | def get_type(docstr): 27 | return docstr.split('@')[0] 28 | 29 | @env.macro 30 | def javadoc(docstr): 31 | url = 'https://jwharm.github.io/java-gi/javadoc/search.html' 32 | return f'[{docstr}]({url}?q={docstr}&r=1)' 33 | 34 | -------------------------------------------------------------------------------- /ext/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("base") // for the 'clean' task 3 | } 4 | 5 | tasks { 6 | val sourceDir = layout.projectDirectory.dir("gobject-introspection-tests") 7 | val buildDir = layout.buildDirectory.dir("meson") 8 | 9 | register("mesonBuild", Exec::class) { 10 | group = "build" 11 | description = "Runs the meson build for gobject-introspection-tests" 12 | 13 | commandLine("sh", "-c", """ 14 | meson setup "${buildDir.get().asFile.absolutePath}" "${sourceDir.asFile.absolutePath}" && \ 15 | meson compile -C "${buildDir.get().asFile.absolutePath}" 16 | """.trimIndent()) 17 | workingDir = sourceDir.asFile 18 | inputs.dir(sourceDir) 19 | outputs.dir(buildDir) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /generator/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.io.* 2 | 3 | plugins { 4 | id("application") 5 | id("java-library") 6 | } 7 | 8 | group = "io.github.jwharm.javagi" 9 | version = libs.versions.javagi.get() 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation(libs.picocli) 17 | implementation(libs.annotations) 18 | implementation(libs.javapoet) 19 | } 20 | 21 | java { 22 | toolchain.languageVersion = JavaLanguageVersion.of(libs.versions.jdk.get()) 23 | } 24 | 25 | application { 26 | applicationName = "java-gi" 27 | mainModule = "io.github.jwharm.javagi.generator" 28 | mainClass = "io.github.jwharm.javagi.JavaGI" 29 | applicationDefaultJvmArgs = listOf("-Dapp.version=$version") 30 | } 31 | 32 | // This task should really be in ext, but that would mean this module 33 | // would have to be `include`d, which would mean we couldn't use it in our build 34 | 35 | // Include the gir-files repository as a zip file with the java-gi command-line 36 | // utility. To decrease size, the documentation is excluded. 37 | tasks.register("includeGirFiles") { 38 | destinationDirectory = layout.buildDirectory.dir("gir-files") 39 | archiveFileName = "gir-files.zip" 40 | 41 | // Use `../` instead of `rootDir/`, because generator is an included build 42 | from(projectDir.resolve("../ext/gir-files")) { 43 | include("**/*.gir") 44 | 45 | // Strip out doc elements from zipped gir files. 46 | filter(RemoveDocs::class.java) 47 | } 48 | } 49 | 50 | // Filter class that will remove ... elements 51 | class RemoveDocs(reader: Reader) : FilterReader(StringReader( 52 | reader.readText().replace(Regex("", RegexOption.MULTILINE), "") 53 | )) 54 | 55 | // Add the created gir-files archive to the resources 56 | tasks.named("processResources") { 57 | dependsOn("includeGirFiles") 58 | from(layout.buildDirectory.dir("gir-files")) 59 | } 60 | -------------------------------------------------------------------------------- /generator/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "generator" 2 | 3 | plugins { 4 | id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" 5 | id("dev.panuszewski.typesafe-conventions") version "0.7.3" 6 | } 7 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/configuration/LicenseNotice.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.configuration; 21 | 22 | /** 23 | * Defines the license note that is generated above every class file 24 | */ 25 | public final class LicenseNotice { 26 | 27 | public final static String NOTICE = """ 28 | This file was automatically generated by Java-GI. Do not edit this file 29 | directly! Visit for more information. 30 | 31 | The API documentation in this file was derived from GObject-Introspection 32 | metadata and may include text or comments from the original C sources. 33 | 34 | Copyright (c), upstream authors as identified in the GObject-Introspection 35 | metadata. 36 | 37 | This generated file is distributed under the same license as the original 38 | GObject-Introspection data, unless otherwise specified. Users of this file 39 | are responsible for complying with any licenses or terms required by the 40 | original authors. 41 | 42 | THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. 45 | """; 46 | } 47 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/configuration/Patches.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.configuration; 21 | 22 | import io.github.jwharm.javagi.patches.*; 23 | import io.github.jwharm.javagi.util.Patch; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Defines the list of patches that are applied to all GIR elements. 29 | */ 30 | public class Patches { 31 | public static final List PATCHES = List.of( 32 | // Main modules 33 | new AdwPatch(), 34 | new BasePatch(), 35 | new FreetypePatch(), 36 | new GLibPatch(), 37 | new GioPatch(), 38 | new GObjectPatch(), 39 | new GstPatch(), 40 | new GstAudioPatch(), 41 | new GstVideoPatch(), 42 | new GstBasePatch(), 43 | new GdkPatch(), 44 | new GtkPatch(), 45 | new HarfBuzzPatch(), 46 | new PangoPatch(), 47 | new SoupPatch(), 48 | new WebKitPatch(), 49 | 50 | // Test modules 51 | new GIMarshallingTestsPatch() 52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/generators/BoxedGenerator.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.generators; 21 | 22 | import com.squareup.javapoet.TypeSpec; 23 | import io.github.jwharm.javagi.configuration.ClassNames; 24 | import io.github.jwharm.javagi.gir.Boxed; 25 | import io.github.jwharm.javagi.util.GeneratedAnnotationBuilder; 26 | 27 | import javax.lang.model.element.Modifier; 28 | 29 | public class BoxedGenerator extends RegisteredTypeGenerator { 30 | 31 | private final Boxed boxed; 32 | private final TypeSpec.Builder builder; 33 | 34 | public BoxedGenerator(Boxed boxed) { 35 | super(boxed); 36 | this.boxed = boxed; 37 | this.builder = TypeSpec.classBuilder(boxed.typeName()); 38 | this.builder.addAnnotation(GeneratedAnnotationBuilder.generate()); 39 | } 40 | 41 | public TypeSpec generate() { 42 | if (boxed.infoElements().doc() != null) 43 | builder.addJavadoc( 44 | new DocGenerator(boxed.infoElements().doc()).generate()); 45 | 46 | if (boxed.infoAttrs().deprecated()) 47 | builder.addAnnotation(Deprecated.class); 48 | 49 | builder.addModifiers(Modifier.PUBLIC) 50 | .superclass(ClassNames.PROXY_INSTANCE) 51 | .addStaticBlock(staticBlock()) 52 | .addMethod(memoryAddressConstructor()); 53 | 54 | if (hasTypeMethod()) 55 | builder.addMethod(getTypeMethod()); 56 | 57 | addFunctions(builder); 58 | 59 | if (boxed.toStringTarget() != null) 60 | builder.addMethod(toStringRedirect()); 61 | 62 | if (hasDowncallHandles()) 63 | builder.addType(downcallHandlesClass()); 64 | 65 | return builder.build(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/generators/CallbackGenerator.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.generators; 21 | 22 | import com.squareup.javapoet.TypeSpec; 23 | import io.github.jwharm.javagi.gir.Callback; 24 | 25 | public class CallbackGenerator extends RegisteredTypeGenerator { 26 | 27 | private final Callback cb; 28 | 29 | public CallbackGenerator(Callback cb) { 30 | super(cb); 31 | this.cb = cb; 32 | } 33 | 34 | public TypeSpec generate() { 35 | return new ClosureGenerator(cb).generateFunctionalInterface(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/AnyType.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import com.squareup.javapoet.TypeName; 23 | 24 | public sealed interface AnyType extends Node permits Type, Array { 25 | 26 | TypeName typeName(); 27 | String toTypeTag(); 28 | 29 | default String name() { 30 | return attr("name"); 31 | } 32 | 33 | default String cType() { 34 | return attr("c:type"); 35 | } 36 | 37 | default boolean isVoid() { 38 | return "void".equals(cType()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Attribute.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Attribute extends GirElement { 25 | 26 | public Attribute(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | public String name() { 31 | return attr("name"); 32 | } 33 | 34 | public String value() { 35 | return attr("value"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Bitfield.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Objects; 27 | 28 | public final class Bitfield extends Multiplatform implements EnumType { 29 | 30 | public Bitfield(Map attributes, 31 | List children, 32 | int platforms) { 33 | super(attributes, children, platforms); 34 | } 35 | 36 | @Override 37 | public Namespace parent() { 38 | return (Namespace) super.parent(); 39 | } 40 | 41 | @Override 42 | public RegisteredType mergeWith(RegisteredType rt) { 43 | if (rt instanceof Bitfield other) 44 | return new Bitfield( 45 | attributes(), 46 | union(children(), other.children()), 47 | platforms() | other.platforms()); 48 | return this; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | if (obj == this) 54 | return true; 55 | 56 | if (obj == null || obj.getClass() != this.getClass()) 57 | return false; 58 | 59 | var that = (Bitfield) obj; 60 | return Objects.equals(this.name(), that.name()); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return Objects.hash(name()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/CInclude.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class CInclude extends GirElement { 25 | 26 | public CInclude(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Repository parent() { 32 | return (Repository) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/CallableAttrs.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.io.Serializable; 23 | 24 | public record CallableAttrs( 25 | boolean introspectable, 26 | boolean deprecated, 27 | String deprecatedVersion, 28 | String version, 29 | Stability stability, 30 | String name, 31 | String cIdentifier, 32 | String shadowedBy, 33 | String shadows, 34 | boolean throws_, 35 | String movedTo, 36 | String asyncFunc, 37 | String syncFunc, 38 | String finishFunc 39 | ) implements Serializable { 40 | } 41 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Callback.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | public final class Callback extends Multiplatform 28 | implements RegisteredType, Callable { 29 | 30 | public Callback(Map attributes, 31 | List children, 32 | int platforms) { 33 | super(attributes, children, platforms); 34 | } 35 | 36 | @Override 37 | public String name() { 38 | return RegisteredType.super.name(); 39 | } 40 | 41 | @Override 42 | public String glibTypeName() { 43 | return attr("c:type"); 44 | } 45 | 46 | @Override 47 | public String getTypeFunc() { 48 | return null; // Callback has no glib:get-type 49 | } 50 | 51 | @Override 52 | public Callback mergeWith(RegisteredType rt) { 53 | // No need to merge 54 | return this; 55 | } 56 | 57 | @Override 58 | public boolean throws_() { 59 | return attrBool("throws", false); 60 | } 61 | 62 | @Override 63 | public Parameters parameters() { 64 | return findAny(children(), Parameters.class); 65 | } 66 | 67 | @Override 68 | public ReturnValue returnValue() { 69 | return findAny(children(), ReturnValue.class); 70 | } 71 | 72 | @Override 73 | public boolean deprecated() { 74 | return infoAttrs().deprecated(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Constant.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | public final class Constant extends Multiplatform implements TypedValue { 27 | 28 | public Constant(Map attributes, 29 | List children, 30 | int platforms) { 31 | super(attributes, children, platforms); 32 | } 33 | 34 | @Override 35 | public Namespace parent() { 36 | return (Namespace) super.parent(); 37 | } 38 | 39 | @Override 40 | public boolean allocatesMemory() { 41 | return false; 42 | } 43 | 44 | public String value() { 45 | return attr("value"); 46 | } 47 | 48 | public String cType() { 49 | return attr("c:type"); 50 | } 51 | 52 | public String cIdentifier() { 53 | return attr("c:identifier"); 54 | } 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | if (obj == this) 59 | return true; 60 | 61 | if (obj == null || obj.getClass() != this.getClass()) 62 | return false; 63 | 64 | var that = (Constant) obj; 65 | return Objects.equals(this.name(), that.name()); 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | return Objects.hash(name()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Constructor.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | public final class Constructor extends Multiplatform implements Callable { 27 | 28 | public Constructor(Map attributes, 29 | List children, 30 | int platforms) { 31 | super(attributes, children, platforms); 32 | } 33 | 34 | @Override 35 | public RegisteredType parent() { 36 | return (RegisteredType) super.parent(); 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | if (this == o) return true; 42 | if (o == null || getClass() != o.getClass()) return false; 43 | Constructor other = (Constructor) o; 44 | return Objects.equals(callableAttrs().cIdentifier(), 45 | other.callableAttrs().cIdentifier()); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(super.hashCode(), callableAttrs().cIdentifier()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Direction.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public enum Direction { 23 | OUT, // "out" 24 | IN, // "in" 25 | INOUT; // "inout" 26 | 27 | public static Direction from(String value) { 28 | return value == null ? null : Direction.valueOf(value.toUpperCase()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Doc.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Doc extends GirElement implements Documentation { 25 | 26 | private final String text; 27 | 28 | public Doc(Map attributes, String text) { 29 | this.text = text; 30 | } 31 | 32 | public String filename() { 33 | return attr("filename"); 34 | } 35 | 36 | public int line() { 37 | return attrInt("line"); 38 | } 39 | 40 | public int column() { 41 | return attrInt("column"); 42 | } 43 | 44 | public String text() { 45 | return text; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object obj) { 50 | if (obj == this) 51 | return true; 52 | return obj != null && obj.getClass() == this.getClass(); 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return 1; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/DocDeprecated.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public final class DocDeprecated extends GirElement implements Documentation { 23 | 24 | private final String text; 25 | 26 | public DocDeprecated(String text) { 27 | this.text = text; 28 | } 29 | 30 | public String text() { 31 | return text; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (obj == this) 37 | return true; 38 | return obj != null && obj.getClass() == this.getClass(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return 1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/DocFormat.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class DocFormat extends GirElement { 25 | 26 | public DocFormat(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Repository parent() { 32 | return (Repository) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/DocStability.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public final class DocStability extends GirElement implements Documentation { 23 | 24 | private final String text; 25 | 26 | public DocStability(String text) { 27 | this.text = text; 28 | } 29 | 30 | public String text() { 31 | return text; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (obj == this) 37 | return true; 38 | return obj != null && obj.getClass() == this.getClass(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return 1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/DocVersion.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public final class DocVersion extends GirElement implements Documentation { 23 | 24 | private final String text; 25 | 26 | public DocVersion(String text) { 27 | this.text = text; 28 | } 29 | 30 | public String text() { 31 | return text; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (obj == this) 37 | return true; 38 | return obj != null && obj.getClass() == this.getClass(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return 1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Docsection.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | public final class Docsection extends GirElement { 28 | 29 | public Docsection(Map attributes, Listchildren) { 30 | super(attributes, children); 31 | } 32 | 33 | public String name() { 34 | return attr("name"); 35 | } 36 | 37 | public Doc doc() { 38 | return findAny(children(), Doc.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Documentation.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public sealed interface Documentation 23 | extends Node 24 | permits Doc, DocDeprecated, DocVersion, DocStability { 25 | 26 | String text(); 27 | Namespace namespace(); 28 | } 29 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/EnumType.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import io.github.jwharm.javagi.util.PartialStatement; 23 | 24 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 25 | 26 | import java.util.List; 27 | 28 | public sealed interface EnumType 29 | extends RegisteredType 30 | permits Bitfield, Enumeration { 31 | 32 | @Override 33 | default PartialStatement constructorName() { 34 | return PartialStatement.of("$" + typeTag() + ":T::of", 35 | typeTag(), typeName()); 36 | } 37 | 38 | @Override 39 | default PartialStatement destructorName() { 40 | return PartialStatement.of("(_ -> {})"); 41 | } 42 | 43 | default List members() { 44 | return filter(children(), Member.class); 45 | } 46 | 47 | default List functions() { 48 | return filter(children(), Function.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Enumeration.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Objects; 27 | 28 | public final class Enumeration extends Multiplatform implements EnumType { 29 | 30 | public Enumeration(Map attributes, 31 | List children, 32 | int platforms) { 33 | super(attributes, children, platforms); 34 | } 35 | 36 | @Override 37 | public Namespace parent() { 38 | return (Namespace) super.parent(); 39 | } 40 | 41 | public Enumeration mergeWith(RegisteredType rt) { 42 | if (rt instanceof Enumeration other) 43 | return new Enumeration( 44 | attributes(), 45 | union(children(), other.children()), 46 | platforms() | other.platforms()); 47 | return this; 48 | } 49 | 50 | public String errorDomain() { 51 | return attr("error-domain"); 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) { 56 | if (obj == this) 57 | return true; 58 | 59 | if (obj == null || obj.getClass() != this.getClass()) 60 | return false; 61 | 62 | var that = (Enumeration) obj; 63 | return Objects.equals(this.name(), that.name()); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return Objects.hash(name()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/FieldContainer.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | 24 | public sealed interface FieldContainer 25 | extends RegisteredType 26 | permits StandardLayoutType, Class, Interface { 27 | 28 | List fields(); 29 | 30 | default boolean opaque() { 31 | return false; 32 | } 33 | 34 | default Field getAtIndex(int index) { 35 | return index == -1 ? null : fields().get(index); 36 | } 37 | 38 | /** 39 | * If one of the fields directly refers to an opaque struct (recursively), 40 | * we cannot generate the memory layout or allocate memory for this type. 41 | * 42 | * @return whether on of the fields refers (recursively) to an opaque 43 | * struct 44 | */ 45 | default boolean hasOpaqueStructFields() { 46 | for (Field field : fields()) 47 | if (field.anyType() instanceof Type type 48 | && !type.isPointer() 49 | && type.lookup() instanceof FieldContainer fc 50 | && (fc.opaque() || fc.hasOpaqueStructFields())) 51 | return true; 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Function.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | public final class Function extends Multiplatform implements Callable { 27 | 28 | public Function(Map attributes, 29 | List children, 30 | int platforms) { 31 | super(attributes, children, platforms); 32 | } 33 | 34 | @Override 35 | public boolean equals(Object o) { 36 | if (this == o) return true; 37 | if (o == null || getClass() != o.getClass()) return false; 38 | Function other = (Function) o; 39 | return Objects.equals(callableAttrs().cIdentifier(), 40 | other.callableAttrs().cIdentifier()); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return Objects.hash(super.hashCode(), callableAttrs().cIdentifier()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/FunctionInline.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | /** 23 | * function-inline is unsupported 24 | */ 25 | public final class FunctionInline extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/FunctionMacro.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | /** 23 | * function-macro is unsupported 24 | */ 25 | public final class FunctionMacro extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Implements.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Implements extends GirElement implements TypeReference { 25 | 26 | public Implements(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Class parent() { 32 | return (Class) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Include.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Include extends GirElement { 25 | 26 | public Include(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Namespace parent() { 32 | return (Namespace) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | 39 | public String version() { 40 | return attr("version"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/InfoAttrs.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.io.Serializable; 23 | 24 | public record InfoAttrs( 25 | boolean introspectable, 26 | boolean deprecated, 27 | String deprecatedVersion, 28 | String version, 29 | Stability stability 30 | ) implements Serializable { 31 | } 32 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/InfoElements.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.io.Serializable; 23 | import java.util.List; 24 | 25 | public record InfoElements( 26 | DocVersion docVersion, 27 | DocStability docStability, 28 | Doc doc, 29 | DocDeprecated docDeprecated, 30 | SourcePosition sourcePosition, 31 | List attributes 32 | ) implements Serializable { 33 | } 34 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/InstanceParameter.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import static io.github.jwharm.javagi.util.CollectionUtils.findAny; 26 | 27 | public final class InstanceParameter extends GirElement implements TypedValue { 28 | 29 | public InstanceParameter(Map attributes, 30 | List children) { 31 | super(attributes, children); 32 | if (anyType() instanceof Array) 33 | throw new UnsupportedOperationException("InstanceParameter cannot be an array"); 34 | } 35 | 36 | @Override 37 | public Parameters parent() { 38 | return (Parameters) super.parent(); 39 | } 40 | 41 | @Override 42 | public boolean allocatesMemory() { 43 | return false; 44 | } 45 | 46 | public Type type() { 47 | return findAny(children(), Type.class); 48 | } 49 | 50 | public boolean nullable() { 51 | return attrBool("nullable", false); 52 | } 53 | 54 | @Deprecated 55 | public boolean allowNone() { 56 | return attrBool("allow-none", false); 57 | } 58 | 59 | public Direction direction() { 60 | return Direction.from(attr("direction")); 61 | } 62 | 63 | public boolean callerAllocates() { 64 | return attrBool("caller-allocates", true); 65 | } 66 | 67 | @Override 68 | public TransferOwnership transferOwnership() { 69 | return TransferOwnership.from(attr("transfer-ownership")); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Member.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | public final class Member extends GirElement { 27 | 28 | public Member(Map attributes, List children) { 29 | super(attributes, children); 30 | } 31 | 32 | @Override 33 | public EnumType parent() { 34 | return (EnumType) super.parent(); 35 | } 36 | 37 | public String name() { 38 | return attr("name"); 39 | } 40 | 41 | public String value() { 42 | return attr("value"); 43 | } 44 | 45 | public String cIdentifier() { 46 | return attr("c:identifier"); 47 | } 48 | 49 | public String nick() { 50 | return attr("nick"); 51 | } 52 | 53 | public InfoElements infoElements() { 54 | return super.infoElements(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | if (obj == this) 60 | return true; 61 | 62 | if (obj == null || obj.getClass() != this.getClass()) 63 | return false; 64 | 65 | var that = (Member) obj; 66 | return Objects.equals(this.name(), that.name()) 67 | && Objects.equals(this.value(), that.value()); 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return Objects.hash(name(), value()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Method.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | public final class Method extends Multiplatform implements Callable { 27 | 28 | public Method(Map attributes, 29 | List children, 30 | int platforms) { 31 | super(attributes, children, platforms); 32 | } 33 | 34 | @Override 35 | public RegisteredType parent() { 36 | return (RegisteredType) super.parent(); 37 | } 38 | 39 | public String setProperty() { 40 | return attr("set-property"); 41 | } 42 | 43 | public String getProperty() { 44 | return attr("get-property"); 45 | } 46 | 47 | public VirtualMethod invokerFor() { 48 | return parent().children().stream() 49 | .filter(VirtualMethod.class::isInstance) 50 | .map(VirtualMethod.class::cast) 51 | .filter(vm -> name().equals(vm.attr("invoker"))) 52 | .filter(vm -> vm.equalTypeSignature(this)) 53 | .findAny() 54 | .orElse(null); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) return true; 60 | if (o == null || getClass() != o.getClass()) return false; 61 | Method other = (Method) o; 62 | return Objects.equals(callableAttrs().cIdentifier(), 63 | other.callableAttrs().cIdentifier()); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return Objects.hash(super.hashCode(), callableAttrs().cIdentifier()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/MethodInline.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | /** 23 | * method-inline is unsupported 24 | */ 25 | public final class MethodInline extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Node.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.function.Predicate; 25 | 26 | public interface Node { 27 | Namespace namespace(); 28 | Node parent(); 29 | void setParent(Node parent); 30 | 31 | List children(); 32 | Map attributes(); 33 | 34 | String attr(String key); 35 | int attrInt(String key); 36 | boolean attrBool(String key, boolean defaultValue); 37 | 38 | T withAttribute(String attrName, String newValue); 39 | T withChildren(GirElement... newChildren); 40 | T withChildren(List newChildren); 41 | 42 | /** 43 | * Apply the predicate on this node and its children recursively, and 44 | * return whether a match was found. 45 | * 46 | * @param predicate the predicate to apply 47 | * @param skip skip nodes of this type and their children 48 | * @return whether the predicate matched for this node or one of its 49 | * children (recursively) 50 | */ 51 | default boolean deepMatch(Predicate predicate, 52 | java.lang.Class skip) { 53 | if (skip.isAssignableFrom(this.getClass())) 54 | return false; 55 | if (predicate.test(this)) 56 | return true; 57 | return children().stream().anyMatch(c -> c.deepMatch(predicate, skip)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Package.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Package extends GirElement { 25 | 26 | public Package(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Repository parent() { 32 | return (Repository) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Parameters.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 23 | 24 | import java.util.List; 25 | 26 | public final class Parameters extends GirElement { 27 | 28 | public Parameters(List children) { 29 | super(children); 30 | } 31 | 32 | public List parameters() { 33 | return filter(children(), Parameter.class); 34 | } 35 | 36 | public InstanceParameter instanceParameter() { 37 | return findAny(children(), InstanceParameter.class); 38 | } 39 | 40 | Parameter getAtIndex(int index) { 41 | return index == -1 ? null : parameters().get(index); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Prerequisite.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class Prerequisite extends GirElement implements TypeReference { 25 | 26 | public Prerequisite(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | @Override 31 | public Interface parent() { 32 | return (Interface) super.parent(); 33 | } 34 | 35 | public String name() { 36 | return attr("name"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Signal.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import com.squareup.javapoet.TypeName; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | import static io.github.jwharm.javagi.util.Conversions.toJavaSimpleType; 28 | 29 | public final class Signal extends Multiplatform implements Callable { 30 | 31 | public Signal(Map attributes, 32 | List children, 33 | int platforms) { 34 | super(attributes, children, platforms); 35 | } 36 | 37 | @Override 38 | public RegisteredType parent() { 39 | return (RegisteredType) super.parent(); 40 | } 41 | 42 | public TypeName typeName() { 43 | return parent().typeName().nestedClass( 44 | toJavaSimpleType(name() + "_callback", namespace())); 45 | } 46 | 47 | public boolean detailed() { 48 | return attrBool("detailed", false); 49 | } 50 | 51 | public When when() { 52 | return When.from(attr("when")); 53 | } 54 | 55 | public boolean action() { 56 | return attrBool("action", false); 57 | } 58 | 59 | public boolean noHooks() { 60 | return attrBool("no-hooks", false); 61 | } 62 | 63 | public boolean noRecurse() { 64 | return attrBool("no-recurse", false); 65 | } 66 | 67 | public String emitter() { 68 | return attr("emitter"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/SourcePosition.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import java.util.Map; 23 | 24 | public final class SourcePosition extends GirElement { 25 | 26 | public SourcePosition(Map attributes) { 27 | super(attributes); 28 | } 29 | 30 | public String filename() { 31 | return attr("filename"); 32 | } 33 | 34 | public int line() { 35 | return attrInt("line"); 36 | } 37 | 38 | public int column() { 39 | return attrInt("column"); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (obj == this) 45 | return true; 46 | return obj != null && obj.getClass() == this.getClass(); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return 1; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Stability.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public enum Stability { 23 | STABLE, // "Stable" 24 | UNSTABLE, // "Unstable" 25 | PRIVATE; // "Private" 26 | 27 | public static Stability from(String value) { 28 | return value == null ? null : Stability.valueOf(value.toUpperCase()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/StandardLayoutType.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public sealed interface StandardLayoutType 23 | extends FieldContainer 24 | permits Boxed, Record, Union { 25 | 26 | default String cSymbolPrefix() { 27 | return attr("c:symbol-prefix"); 28 | } 29 | 30 | private Callable lookup(String cIdentifier) { 31 | if (cIdentifier == null) 32 | return null; 33 | 34 | Node node = namespace().parent().lookupCIdentifier(cIdentifier); 35 | if (node instanceof Callable callable) 36 | return callable; 37 | 38 | return null; 39 | } 40 | 41 | default Callable copyFunction() { 42 | return lookup(attr("copy-function")); 43 | } 44 | 45 | default Callable freeFunction() { 46 | return lookup(attr("free-function")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/TransferOwnership.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public enum TransferOwnership { 23 | NONE, // "none" 24 | CONTAINER, // "container" 25 | FULL; // "full" 26 | 27 | /** 28 | * Defaults to "none" when unspecified 29 | */ 30 | public static TransferOwnership from(String value) { 31 | return value == null ? NONE 32 | : TransferOwnership.valueOf(value.toUpperCase()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/TypedValue.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | import com.squareup.javapoet.TypeName; 23 | 24 | import static io.github.jwharm.javagi.util.CollectionUtils.*; 25 | 26 | public sealed interface TypedValue 27 | extends Node 28 | permits Constant, Field, InstanceParameter, Parameter, Property, 29 | ReturnValue { 30 | 31 | InfoElements infoElements(); 32 | 33 | default String name() { 34 | return attr("name"); 35 | } 36 | 37 | default AnyType anyType() { 38 | return findAny(children(), AnyType.class); 39 | } 40 | 41 | default boolean allocatesMemory() { 42 | return switch(anyType()) { 43 | case null -> true; // callback 44 | case Array _ -> true; 45 | case Type type -> type.isActuallyAnArray() 46 | || TypeName.get(String.class).equals(type.typeName()); 47 | }; 48 | } 49 | 50 | default TransferOwnership transferOwnership() { 51 | return TransferOwnership.NONE; 52 | } 53 | 54 | default boolean isBitfield() { 55 | if (anyType() instanceof Type type && (!type.isPrimitive())) { 56 | RegisteredType target = type.lookup(); 57 | if (target instanceof Alias alias) 58 | target = alias.lookup(); 59 | return target instanceof Bitfield; 60 | } 61 | return false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/Varargs.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public final class Varargs extends GirElement { 23 | } 24 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/gir/When.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gir; 21 | 22 | public enum When { 23 | FIRST, // "first" 24 | LAST, // "last" 25 | CLEANUP; // "cleanup" 26 | 27 | public static When from(String value) { 28 | return value == null ? null : When.valueOf(value.toUpperCase()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/AdwPatch.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.patches; 21 | 22 | import io.github.jwharm.javagi.gir.GirElement; 23 | import io.github.jwharm.javagi.gir.Method; 24 | import io.github.jwharm.javagi.util.Patch; 25 | 26 | public class AdwPatch implements Patch { 27 | 28 | @Override 29 | public GirElement patch(GirElement element, String namespace) { 30 | 31 | if (!"Adw".equals(namespace)) 32 | return element; 33 | 34 | /* 35 | * SplitButton.getDirection() overrides Widget.getDirection() with a 36 | * different return type. Rename to getArrowDirection() 37 | */ 38 | if (element instanceof Method m 39 | && "adw_split_button_get_direction" 40 | .equals(m.callableAttrs().cIdentifier())) 41 | return m.withAttribute("name", "get_arrow_direction"); 42 | 43 | return element; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/FreetypePatch.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.patches; 21 | 22 | import io.github.jwharm.javagi.gir.GirElement; 23 | import io.github.jwharm.javagi.util.Patch; 24 | 25 | public class FreetypePatch implements Patch { 26 | @Override 27 | public GirElement patch(GirElement element, String namespace) { 28 | 29 | if (!"freetype2".equals(namespace)) 30 | return element; 31 | 32 | // Mark all Freetype nodes as foreign 33 | return element.withAttribute("foreign", "1"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/GIMarshallingTestsPatch.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.patches; 21 | 22 | import io.github.jwharm.javagi.gir.Function; 23 | import io.github.jwharm.javagi.gir.GirElement; 24 | import io.github.jwharm.javagi.gir.Namespace; 25 | import io.github.jwharm.javagi.util.Patch; 26 | 27 | public class GIMarshallingTestsPatch implements Patch { 28 | 29 | @Override 30 | public GirElement patch(GirElement element, String namespace) { 31 | 32 | if (!"GIMarshallingTests".equals(namespace)) 33 | return element; 34 | 35 | /* 36 | * Disabled testcases 37 | */ 38 | if (element instanceof Namespace ns) { 39 | return remove(ns, Function.class, "name", "return_gvalue_zero_terminated_array"); 40 | } 41 | 42 | return element; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/GstPatch.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.patches; 2 | 3 | import io.github.jwharm.javagi.gir.*; 4 | import io.github.jwharm.javagi.util.Patch; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import static java.util.Collections.emptyList; 10 | import static java.util.Collections.emptyMap; 11 | 12 | public class GstPatch implements Patch { 13 | 14 | // Utility function quickly create a 15 | private static Type gintType() { 16 | return new Type(Map.of("name", "gint", "c:type", "gint"), emptyList()); 17 | } 18 | 19 | @Override 20 | public GirElement patch(GirElement element, String namespace) { 21 | 22 | /* 23 | * GstMapFlags is an "extendable" bitfield type. Flags values are added 24 | * in other namespaces. Java doesn't allow extending an enum, so we 25 | * generate integer constants instead. 26 | */ 27 | 28 | // Replace all references to GstMapFlags with integers 29 | if (element instanceof Type t && "GstMapFlags".equals(t.cType())) 30 | return gintType(); 31 | 32 | if (!"Gst".equals(namespace)) 33 | return element; 34 | 35 | if (element instanceof Namespace ns) { 36 | // Add integer constants for all GstMapFlags members 37 | ns = add(ns, new Constant( 38 | Map.of("name", "MAP_READ", "value", "1"), 39 | List.of(new Doc(emptyMap(), "map for read access"), 40 | gintType()), 41 | ns.platforms())); 42 | ns = add(ns, new Constant( 43 | Map.of("name", "MAP_WRITE", "value", "2"), 44 | List.of(new Doc(emptyMap(), "map for write access"), 45 | gintType()), 46 | ns.platforms())); 47 | ns = add(ns, new Constant( 48 | Map.of("name", "MAP_FLAG_LAST", "value", "65536"), 49 | List.of(new Doc(emptyMap(), "first flag that can be used for custom purposes"), 50 | gintType()), 51 | ns.platforms())); 52 | 53 | // Remove GstMapFlags 54 | return remove(ns, Bitfield.class, "name", "MapFlags"); 55 | } 56 | 57 | return element; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/SoupPatch.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.patches; 21 | 22 | import io.github.jwharm.javagi.gir.GirElement; 23 | import io.github.jwharm.javagi.gir.VirtualMethod; 24 | import io.github.jwharm.javagi.util.Patch; 25 | 26 | import java.util.Map; 27 | 28 | public class SoupPatch implements Patch { 29 | 30 | @Override 31 | public GirElement patch(GirElement element, String namespace) { 32 | 33 | if (!"Soup".equals(namespace)) 34 | return element; 35 | 36 | /* 37 | * Virtual method Auth.update() has a HashTable argument where the 38 | * invoker method has a String argument. Remove the "invoker" 39 | * attribute, so they are generated as two separate methods in Java. 40 | */ 41 | if (element instanceof VirtualMethod vm 42 | && "update".equals(vm.name()) 43 | && "Auth".equals(vm.parameters() 44 | .instanceParameter() 45 | .type().name())) 46 | return new VirtualMethod( 47 | Map.of("name", "update"), 48 | vm.children(), 49 | vm.platforms() 50 | ); 51 | 52 | return element; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/patches/WebKitPatch.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.patches; 21 | 22 | import io.github.jwharm.javagi.gir.GirElement; 23 | import io.github.jwharm.javagi.gir.Method; 24 | import io.github.jwharm.javagi.util.Patch; 25 | 26 | public class WebKitPatch implements Patch { 27 | 28 | @Override 29 | public GirElement patch(GirElement element, String namespace) { 30 | 31 | if (!"WebKit".equals(namespace)) 32 | return element; 33 | 34 | /* 35 | * WebView.getSettings() overrides Widget.getSettings() with a 36 | * different return type. Rename to getWebViewSettings() 37 | */ 38 | if (element instanceof Method m 39 | && "webkit_web_view_get_settings" 40 | .equals(m.callableAttrs().cIdentifier())) 41 | return m.withAttribute("name", "get_web_view_settings"); 42 | 43 | return element; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/util/GeneratedAnnotationBuilder.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.util; 21 | 22 | import com.squareup.javapoet.AnnotationSpec; 23 | 24 | import javax.annotation.processing.Generated; 25 | 26 | public class GeneratedAnnotationBuilder { 27 | 28 | public static AnnotationSpec generate() { 29 | var generatedAnnotation = AnnotationSpec.builder(Generated.class) 30 | .addMember("value", "$S", "io.github.jwharm.JavaGI"); 31 | 32 | return generatedAnnotation.build(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /generator/src/main/java/io/github/jwharm/javagi/util/Numbers.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 the Java-GI developers 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.util; 21 | 22 | /** 23 | * Utility class for parsing numbers where it is unknown whether they are signed 24 | */ 25 | public class Numbers { 26 | public static Byte parseByte(String s) throws NumberFormatException { 27 | return negative(s) ? Byte.parseByte(s) : (byte) Integer.parseInt(s); 28 | } 29 | 30 | public static Short parseShort(String s) throws NumberFormatException { 31 | return negative(s) ? Short.parseShort(s) : (short) Integer.parseInt(s); 32 | } 33 | 34 | public static Integer parseInt(String s) throws NumberFormatException { 35 | return negative(s) ? Integer.parseInt(s) : Integer.parseUnsignedInt(s); 36 | } 37 | 38 | public static Long parseLong(String s) throws NumberFormatException { 39 | return negative(s) ? Long.parseLong(s) : Long.parseUnsignedLong(s); 40 | } 41 | 42 | private static boolean negative(String s) { 43 | return !s.isEmpty() && s.charAt(0) == '-'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module io.github.jwharm.javagi.generator { 2 | requires java.compiler; 3 | requires java.xml; 4 | requires com.squareup.javapoet; 5 | requires info.picocli; 6 | requires org.jetbrains.annotations; 7 | exports io.github.jwharm.javagi; 8 | exports io.github.jwharm.javagi.configuration; 9 | exports io.github.jwharm.javagi.generators; 10 | exports io.github.jwharm.javagi.gir; 11 | exports io.github.jwharm.javagi.patches; 12 | exports io.github.jwharm.javagi.util; 13 | opens io.github.jwharm.javagi to info.picocli; 14 | } 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4096M 2 | org.gradle.caching=true 3 | org.gradle.parallel=true 4 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | javagi = "0.12.2" 3 | jdk = "22" 4 | cairo = "1.18.4.2" 5 | picocli = "4.7.7" 6 | javapoet = "1.13.0" 7 | annotations = "26.0.2" 8 | junit = "5.13.0" 9 | mavenpublish = "0.32.0" 10 | 11 | [libraries] 12 | javagi-generator = { module = "io.github.jwharm.javagi:generator", version.ref = "javagi" } 13 | cairo = { module = "io.github.jwharm.cairobindings:cairo", version.ref = "cairo" } 14 | picocli = { module = "info.picocli:picocli", version.ref = "picocli" } 15 | javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" } 16 | annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" } 17 | junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } 18 | junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" } 19 | mavenpublish = { module = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin", version.ref = "mavenpublish" } 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/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.13-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Java-GI 2 | site_url: https://jwharm.github.io/java-gi/ 3 | nav: 4 | - Home: index.md 5 | - Basic usage: usage.md 6 | - Advanced usage: advanced.md 7 | - Examples: examples.md 8 | - Registering new types: register.md 9 | - Composite template classes: templates.md 10 | - Getting started guide: 11 | - Introduction: getting-started/getting_started_00.md 12 | - Basics: getting-started/getting_started_01.md 13 | - Hello, world: getting-started/getting_started_02.md 14 | - Packing: getting-started/getting_started_03.md 15 | - Custom drawing: getting-started/getting_started_04.md 16 | - Building user interfaces: getting-started/getting_started_05.md 17 | - Building applications: getting-started/getting_started_06.md 18 | - Populating the window: getting-started/getting_started_07.md 19 | - Opening files: getting-started/getting_started_08.md 20 | - A menu: getting-started/getting_started_09.md 21 | - A preferences dialog: getting-started/getting_started_10.md 22 | - Adding a search bar: getting-started/getting_started_11.md 23 | - Adding a side bar: getting-started/getting_started_12.md 24 | - Properties: getting-started/getting_started_13.md 25 | - Using icons: getting-started/getting_started_14.md 26 | - Generating bindings: generate.md 27 | 28 | theme: 29 | name: material 30 | palette: 31 | 32 | # Palette toggle for automatic mode 33 | - media: "(prefers-color-scheme)" 34 | toggle: 35 | icon: material/brightness-auto 36 | name: Switch to light mode 37 | 38 | # Palette toggle for light mode 39 | - media: "(prefers-color-scheme: light)" 40 | scheme: default 41 | primary: blue grey 42 | toggle: 43 | icon: material/brightness-7 44 | name: Switch to dark mode 45 | 46 | # Palette toggle for dark mode 47 | - media: "(prefers-color-scheme: dark)" 48 | scheme: slate 49 | primary: blue grey 50 | toggle: 51 | icon: material/brightness-4 52 | name: Switch to system preference 53 | 54 | icon: 55 | logo: material/coffee 56 | 57 | features: 58 | - content.tabs.link 59 | 60 | markdown_extensions: 61 | - pymdownx.highlight: 62 | anchor_linenums: true 63 | - admonition 64 | - pymdownx.superfences 65 | - pymdownx.tabbed: 66 | alternate_style: true 67 | - pymdownx.details 68 | - attr_list 69 | - def_list 70 | 71 | plugins: 72 | - search 73 | - macros: 74 | module_name: docs/macros/mkdocs-macros 75 | 76 | -------------------------------------------------------------------------------- /modules/main/adw/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | api(project(":gtk")) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "Adw" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/gdk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gdkpixbuf")) 7 | api(project(":gio")) 8 | api(project(":pango")) 9 | api(project(":pangocairo")) 10 | } 11 | 12 | tasks.withType { 13 | namespace = "Gdk" 14 | } 15 | -------------------------------------------------------------------------------- /modules/main/gdkpixbuf/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gmodule")) 7 | api(project(":gio")) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "GdkPixbuf" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/gio/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gmodule")) 7 | api(project(":gobject")) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "Gio" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/gio/src/main/java/io/github/jwharm/javagi/gio/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI helper classes used by the GIO bindings. 3 | */ 4 | package io.github.jwharm.javagi.gio; -------------------------------------------------------------------------------- /modules/main/gio/src/test/java/io/github/jwharm/javagi/test/gio/ListModelTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gio; 2 | 3 | import io.github.jwharm.javagi.gio.ListIndexModel; 4 | import org.gnome.gio.DBusMessage; 5 | import org.gnome.gio.Gio; 6 | import org.gnome.gio.ListStore; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | /** 13 | * Test some operations on ListIndexModel and ListStore 14 | */ 15 | public class ListModelTest { 16 | 17 | // Make sure the GIO library is loaded 18 | @BeforeAll 19 | public static void ensureInitialized() { 20 | Gio.javagi$ensureInitialized(); 21 | } 22 | 23 | @Test 24 | public void createListModel() { 25 | // verify that ListIndexModel works as expected 26 | var listIndexModel = new ListIndexModel(1000); 27 | assertEquals(listIndexModel.getItemType(), ListIndexModel.ListIndex.getType()); 28 | assertEquals(1000, listIndexModel.getNItems()); 29 | 30 | var item500 = listIndexModel.getItem(500); 31 | assertNotNull(item500); 32 | assertEquals(500, item500.getIndex()); 33 | 34 | // foreach loop on a ListModel 35 | int i = 0; 36 | for (var item : listIndexModel) 37 | assertEquals(item.getIndex(), i++); 38 | 39 | // stream() operations on a ListModel 40 | var product = listIndexModel.stream() 41 | .map(ListIndexModel.ListIndex::getIndex) 42 | .reduce(0, Integer::sum); 43 | assertEquals(499500, product); 44 | } 45 | 46 | @Test 47 | public void createListStore() { 48 | var listStore = new ListStore(DBusMessage.getType()); 49 | var item = new DBusMessage(); 50 | listStore.append(item); 51 | assertEquals(1, listStore.size()); 52 | assertEquals(item, listStore.getFirst()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /modules/main/gio/src/test/java/io/github/jwharm/javagi/test/gio/StrvArrayTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gio; 2 | 3 | import io.github.jwharm.javagi.interop.Platform; 4 | import org.gnome.gio.DesktopAppInfo; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | import static org.junit.jupiter.api.Assumptions.assumeTrue; 9 | 10 | /** 11 | * Get a String[][] array from a Gio function, and check that it contains 12 | * usable data. 13 | */ 14 | public class StrvArrayTest { 15 | 16 | @Test 17 | public void testStrvArrayToJava() { 18 | // DesktopAppInfo is only available on Linux 19 | assumeTrue(Platform.LINUX.equals(Platform.getRuntimePlatform())); 20 | 21 | // Unless there are absolutely no applications installed, searching 22 | // for "e" should return a few usable results 23 | String[][] array = DesktopAppInfo.search("e"); 24 | assertNotNull(array); 25 | for (String[] inner : array) { 26 | assertNotNull(inner); 27 | for (String str : inner) { 28 | // Check for NULL 29 | assertNotNull(str); 30 | 31 | // Check for valid strings 32 | assertTrue(str.endsWith(".desktop")); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /modules/main/gio/src/test/java/io/github/jwharm/javagi/test/gio/WeakRefTest.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.test.gio; 21 | 22 | import org.gnome.gio.SimpleAction; 23 | import org.gnome.gobject.WeakRef; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | /** 29 | * Create a GWeakRef to a GObject and read it back. 30 | */ 31 | public class WeakRefTest { 32 | 33 | @Test 34 | public void createWeakRef() { 35 | SimpleAction gobject = new SimpleAction("test", null); 36 | 37 | WeakRef weakRef = new WeakRef<>(); 38 | weakRef.init(gobject); 39 | 40 | SimpleAction action2 = weakRef.get(); 41 | weakRef.clear(); 42 | 43 | assertEquals(gobject, action2); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/main/glib/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | tasks.withType { 6 | namespace = "GLib" 7 | } 8 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/Constants.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi; 21 | 22 | /** 23 | * Java-GI global constant definitions 24 | */ 25 | public class Constants { 26 | 27 | /** 28 | * The LOG_DOMAIN to use for GLib.log() 29 | */ 30 | public static final String LOG_DOMAIN = "java-gi"; 31 | } 32 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/Enumeration.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | /** 23 | * Interface implemented by all enums generated by Java-GI. 24 | */ 25 | public interface Enumeration { 26 | 27 | /** 28 | * Get the integer value of this enum. 29 | * 30 | * @return the integer value of this enum 31 | */ 32 | int getValue(); 33 | } 34 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/Floating.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | /** 23 | * Classes that implement the Floating interface, have a refSink method. 24 | */ 25 | public interface Floating extends Proxy { 26 | 27 | /** 28 | * Sink the floating reference. 29 | * 30 | * @return the instance 31 | */ 32 | Floating refSink(); 33 | 34 | /** 35 | * Decrease the reference count of the instance. 36 | */ 37 | void unref(); 38 | } 39 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/FunctionPointer.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | import java.lang.foreign.Arena; 23 | import java.lang.foreign.MemorySegment; 24 | 25 | /** 26 | * A common interface to create a function pointer in native memory for a Java 27 | * functional interface. All Java-GI callbacks extend from this interface. 28 | */ 29 | public interface FunctionPointer { 30 | 31 | /** 32 | * Create a function pointer in native memory for this callback. 33 | * 34 | * @param arena the function pointer will be allocated in this arena 35 | * @return the newly created function pointer 36 | */ 37 | MemorySegment toCallback(Arena arena); 38 | } 39 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/GLibLogger.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | import io.github.jwharm.javagi.Constants; 23 | import org.gnome.glib.GLib; 24 | import org.gnome.glib.LogLevelFlags; 25 | 26 | /** 27 | * Utility class to call {@link GLib#log} for debug purposes. 28 | */ 29 | public final class GLibLogger { 30 | 31 | // Prevent instantiation 32 | private GLibLogger() {} 33 | 34 | /** 35 | * Call {@link GLib#log} with log domain "java-gi" and level 36 | * {@link LogLevelFlags#LEVEL_DEBUG}. 37 | * 38 | * @param message the message format. See the {@code printf()} 39 | * documentation 40 | * @param varargs the parameters to insert into the format string 41 | */ 42 | public static void debug(String message, Object... varargs) { 43 | GLib.log(Constants.LOG_DOMAIN, 44 | LogLevelFlags.LEVEL_DEBUG, 45 | message, 46 | varargs); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/Out.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | /** 23 | * A wrapper class for out-parameters of (usually primitive) values. When a 24 | * method expects an {@code Out<>} object, the user must create it, optionally 25 | * fill it with an initial value, and pass it to the method. After the method 26 | * has returned, the user can read the the value of the out-parameter with a 27 | * call to {@link #get()}. 28 | * 29 | * @param The parameter type. 30 | */ 31 | public class Out { 32 | 33 | private T value; 34 | 35 | /** 36 | * Create an Out object with no initial value. 37 | */ 38 | public Out() { 39 | } 40 | 41 | /** 42 | * Create an Out object and set the initial value. 43 | * 44 | * @param value the initial value 45 | */ 46 | public Out(T value) { 47 | this.value = value; 48 | } 49 | 50 | /** 51 | * Get the value from the out-parameter. 52 | * 53 | * @return the value of the out-parameter 54 | */ 55 | public T get() { 56 | return value; 57 | } 58 | 59 | /** 60 | * Set the parameter to the provided value. 61 | * 62 | * @param value the value to set 63 | */ 64 | public void set(T value) { 65 | this.value = value; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/Proxy.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | import java.lang.foreign.MemorySegment; 23 | 24 | /** 25 | * Represents an instance of a proxy object with a handle to an object in 26 | * native memory. 27 | */ 28 | public interface Proxy { 29 | 30 | /** 31 | * Get the native memory address of the object. 32 | * 33 | * @return the native memory address 34 | */ 35 | MemorySegment handle(); 36 | } 37 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/ProxyInstance.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | import java.lang.foreign.MemorySegment; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Base type for a Java proxy object to an instance in native memory. 27 | */ 28 | public class ProxyInstance implements Proxy { 29 | 30 | public MemorySegment address; 31 | 32 | /** 33 | * Create a new {@code ProxyInstance} object for an instance in native 34 | * memory. 35 | * 36 | * @param address the memory address of the instance 37 | */ 38 | public ProxyInstance(MemorySegment address) { 39 | this.address = address; 40 | } 41 | 42 | /** 43 | * Get the memory address of the instance. 44 | * 45 | * @return the memory address of the instance 46 | */ 47 | @Override 48 | public MemorySegment handle() { 49 | return address; 50 | } 51 | 52 | /** 53 | * Compare two proxy instances for equality. This will compare both the type 54 | * of the instances, and their memory addresses. 55 | * 56 | * @param o the proxy instance to compare 57 | * @return whether the instances are equal 58 | */ 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) return true; 62 | if (o == null || getClass() != o.getClass()) return false; 63 | ProxyInstance that = (ProxyInstance) o; 64 | return Objects.equals(address, that.address); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | return Objects.hashCode(address); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/TransferOwnership.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | /** 23 | * Types of ownership transfer used by GObject-Introspection for many elements, 24 | * for example, a returned value. 25 | */ 26 | public enum TransferOwnership { 27 | /** 28 | * The recipient does not own the value 29 | */ 30 | NONE, 31 | 32 | /** 33 | * The recipient owns the container but not the values 34 | */ 35 | CONTAINER, 36 | 37 | /** 38 | * The recipient owns the entire value 39 | */ 40 | FULL 41 | } 42 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/UnsupportedPlatformException.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.base; 21 | 22 | /** 23 | * This exception is thrown when a function is run on a platform where it is 24 | * not available. 25 | */ 26 | public class UnsupportedPlatformException extends RuntimeException { 27 | 28 | /** 29 | * Create a new UnsupportedPlatformException with the provided message. 30 | * 31 | * @param message the exception message 32 | */ 33 | public UnsupportedPlatformException(String message) { 34 | super(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/base/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI base classes that are used or extended by generated bindings. 3 | */ 4 | package io.github.jwharm.javagi.base; -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/glib/types/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI type declarations. 3 | */ 4 | package io.github.jwharm.javagi.glib.types; -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/interop/ArenaCloseAction.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | package io.github.jwharm.javagi.interop; 20 | 21 | import java.lang.foreign.Arena; 22 | import java.lang.ref.Cleaner; 23 | 24 | /** 25 | * Helper class to separate the cleanup logic from the object being cleaned 26 | * 27 | * @param arena the Arena that will be closed 28 | */ 29 | public record ArenaCloseAction(Arena arena) implements Runnable { 30 | 31 | // Cleaner used to close the arena 32 | public static final Cleaner CLEANER = Cleaner.create(); 33 | 34 | @Override 35 | public void run() { 36 | arena.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/interop/InteropException.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.interop; 21 | 22 | /** 23 | * Thrown when an unexpected error occurs when calling a native function or 24 | * reading/writing from/to native memory. 25 | */ 26 | public class InteropException extends RuntimeException { 27 | 28 | /** 29 | * Create an InteropException that wraps another Throwable. 30 | * 31 | * @param cause the Throwable to wrap in the InteropException 32 | */ 33 | public InteropException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | /** 38 | * Create an InteropException with the provided message. 39 | * 40 | * @param message the exception message. 41 | */ 42 | public InteropException(String message) { 43 | super(message); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/interop/VarargsUtil.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.interop; 21 | 22 | import org.jetbrains.annotations.Nullable; 23 | 24 | import java.util.Arrays; 25 | 26 | /** 27 | * Utility functions to split an array of variadic arguments into a first 28 | * argument and a null-terminated array of remaining arguments. 29 | */ 30 | public class VarargsUtil { 31 | 32 | /** 33 | * Return the first array element. 34 | * 35 | * @param array input array, can be {@code null} 36 | * @param array element type 37 | * @return the first element, or {@code null} if the input array is 38 | * {@code null} or empty 39 | */ 40 | public static @Nullable T first(@Nullable T @Nullable[] array) { 41 | return array == null || array.length == 0 ? null : array[0]; 42 | } 43 | 44 | /** 45 | * Return all but the first array elements, terminated with a {@code null}. 46 | * For example, {@code [1, 2, 3]} returns {@code [2, 3, null]}. 47 | * 48 | * @param array input array, can be {@code null} 49 | * @param array element type 50 | * @return a new array of all elements except the first, terminated with a 51 | * {@code null}, or {@code null} if the input array is {@code null} 52 | * or empty 53 | */ 54 | @SuppressWarnings("unchecked") // cast is safe because the array is empty 55 | public static @Nullable T @Nullable[] rest(@Nullable T @Nullable[] array) { 56 | return array == null ? null 57 | : array.length == 0 ? (T[]) new Object[] {} 58 | : Arrays.copyOfRange(array, 1, array.length + 1); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/interop/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI classes used by generated bindings to load native libraries, call 3 | * native functions, allocate and release memory, and check the runtime 4 | * platform. 5 | */ 6 | package io.github.jwharm.javagi.interop; -------------------------------------------------------------------------------- /modules/main/glib/src/main/java/io/github/jwharm/javagi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI global constant definitions. 3 | */ 4 | package io.github.jwharm.javagi; -------------------------------------------------------------------------------- /modules/main/glib/src/test/java/io/github/jwharm/javagi/interop/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.interop; 2 | 3 | import org.gnome.glib.GLib; 4 | import org.gnome.glib.HashTable; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.lang.foreign.Arena; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | /** 12 | * Test reading values from a GPtrArray 13 | */ 14 | public class ArrayTest { 15 | 16 | @Test 17 | void testArray() { 18 | try (var arena = Arena.ofConfined()) { 19 | var table = HashTable.new_(GLib::strHash, GLib::strEqual); 20 | for (int i = 0; i < 3; i++) 21 | table.insert( 22 | Interop.allocateNativeString("key" + i, arena), 23 | Interop.allocateNativeString("val" + i, arena)); 24 | var values = table.getValuesAsPtrArray(); 25 | assertNotNull(values); 26 | assertEquals(3, values.length); 27 | for (int i = 0; i < 3; i++) { 28 | String str = Interop.getStringFrom(values[i]); 29 | assertEquals(4, str.length()); 30 | assertTrue(str.startsWith("val")); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /modules/main/glib/src/test/java/io/github/jwharm/javagi/interop/BytesTest.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.interop; 21 | 22 | import io.github.jwharm.javagi.base.GErrorException; 23 | import org.gnome.glib.GString; 24 | import org.gnome.glib.KeyFile; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | import static org.junit.jupiter.api.Assertions.assertTrue; 29 | 30 | public class BytesTest { 31 | 32 | @Test 33 | public void testFromGBytes() { 34 | var input = "test"; 35 | var gstring = new GString(input); 36 | var bytes = gstring.freeToBytes(); 37 | var output = new String(bytes); 38 | assertEquals(input, output); 39 | } 40 | 41 | @Test 42 | public void testToGBytes() throws GErrorException { 43 | byte[] data = """ 44 | [MyGroup] 45 | FirstKey=Hello 46 | SecondKey=Goodbye 47 | """.getBytes(); 48 | var keyFile = new KeyFile(); 49 | var success = keyFile.loadFromBytes(data); 50 | assertTrue(success); 51 | assertEquals("MyGroup", keyFile.getStartGroup()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /modules/main/glib/src/test/java/io/github/jwharm/javagi/interop/FlagsTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.interop; 2 | 3 | import org.gnome.glib.AsciiType; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Set; 7 | 8 | import static org.gnome.glib.AsciiType.*; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | /** 12 | * Test conversion of int to EnumSet and back 13 | */ 14 | public class FlagsTest { 15 | 16 | @Test 17 | void testFlags() { 18 | int input = 1 + 2 + 4 + 8 + 64 + 512; 19 | var set = Interop.intToEnumSet(AsciiType.class, AsciiType::of, input); 20 | assertEquals(Set.of(ALNUM, ALPHA, CNTRL, DIGIT, PRINT, UPPER), set); 21 | int output = Interop.enumSetToInt(set); 22 | assertEquals(input, output); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/main/glib/src/test/java/io/github/jwharm/javagi/interop/HashTableTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.interop; 2 | 3 | import io.github.jwharm.javagi.base.GErrorException; 4 | import org.gnome.glib.HashTable; 5 | import org.gnome.glib.Uri; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | /** 11 | * Test GHashTable wrapper class 12 | */ 13 | public class HashTableTest { 14 | 15 | @Test 16 | void testHashTable() { 17 | try { 18 | HashTable hashTable = Uri.parseParams("name=john&age=41", -1, "&"); 19 | assertEquals(2, hashTable.size()); 20 | assertTrue(hashTable.contains("name")); 21 | assertTrue(hashTable.contains("age")); 22 | assertEquals("john", hashTable.get("name")); 23 | assertEquals("41", hashTable.lookup("age")); 24 | } catch (GErrorException e) { 25 | fail(e); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /modules/main/glib/src/test/java/io/github/jwharm/javagi/interop/VarargsTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.interop; 2 | 3 | import org.gnome.glib.GLib; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.List; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertTrue; 9 | 10 | /** 11 | * Test calling a variadic function with string, int, float and char values 12 | */ 13 | public class VarargsTest { 14 | 15 | @Test 16 | void testVarargs() { 17 | var str = GLib.strdupPrintf("%s %d %.2f %c", "abc", 123, 4.56f, 'c'); 18 | 19 | // both are OK, depending on the locale 20 | var possibleResults = List.of("abc 123 4.56 c", "abc 123 4,56 c"); 21 | assertTrue(possibleResults.contains(str)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /modules/main/gmodule/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GModule" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gobject/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GObject" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/BuilderInterface.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject; 21 | 22 | import io.github.jwharm.javagi.base.FunctionPointer; 23 | import org.gnome.gobject.Value; 24 | 25 | import java.lang.foreign.Arena; 26 | 27 | /** 28 | * Base interface for nested Builder types in interfaces. 29 | */ 30 | public interface BuilderInterface { 31 | 32 | /** 33 | * Get the arena for allocating memory in this builder 34 | * 35 | * @return the arena for allocating memory in this builder 36 | */ 37 | Arena getArena(); 38 | 39 | /** 40 | * Add the provided property name and value to the builder 41 | * 42 | * @param name name of the property 43 | * @param value value of the property (a {@code GValue}) 44 | */ 45 | void addBuilderProperty(String name, Value value); 46 | 47 | /** 48 | * Add the provided signal to the builder 49 | * 50 | * @param name the signal name 51 | * @param callback the signal callback 52 | */ 53 | void connect(String name, FunctionPointer callback); 54 | 55 | /** 56 | * Add the provided detailed signal to the builder 57 | * 58 | * @param name the signal name 59 | * @param detail the signal detail 60 | * @param callback the signal callback 61 | */ 62 | void connect(String name, String detail, FunctionPointer callback); 63 | } 64 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/ClassInit.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface ClassInit { 30 | } 31 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/Flags.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | import io.github.jwharm.javagi.gobject.types.Types; 28 | 29 | /** 30 | * The {@code @Flags} annotation is used by {@link Types#register} to register 31 | * a Java enum as a GObject Flags type. Flags types are like enumerations, but 32 | * allow bitwise comparison of their values. 33 | */ 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Target(ElementType.TYPE) 36 | public @interface Flags { 37 | } 38 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/GType.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface GType { 30 | } 31 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/InstanceInit.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface InstanceInit { 30 | } 31 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/InterfaceInit.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface InterfaceInit { 30 | } 31 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/Layout.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface Layout { 30 | } 31 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/Namespace.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.PACKAGE) 29 | public @interface Namespace { 30 | String name() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/Property.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2024 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import org.gnome.gobject.ParamSpec; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * The {@code @Property} annotation is used to indicate that a method (or pair 31 | * of methods) is a property, to set a property name and flags, or to specify 32 | * that a pair of get- and set-methods are not properties (using 33 | * {@code skip=false}). 34 | *

35 | * Always set the {@code @Property} annotation with the same parameters on both 36 | * the get- and set-method. 37 | */ 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target(ElementType.METHOD) 40 | public @interface Property { 41 | String NOT_SET = "JAVA-GI-DEFAULT-PLACEHOLDER-VALUE"; 42 | 43 | String name() default ""; 44 | Class type() default ParamSpec.class; 45 | boolean skip() default false; 46 | boolean readable() default true; 47 | boolean writable() default true; 48 | boolean construct() default false; 49 | boolean constructOnly() default false; 50 | boolean explicitNotify() default false; 51 | boolean deprecated() default false; 52 | String minimumValue() default NOT_SET; 53 | String maximumValue() default NOT_SET; 54 | String defaultValue() default NOT_SET; 55 | } 56 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/RegisteredType.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.TYPE) 29 | public @interface RegisteredType { 30 | String name() default ""; 31 | Class[] prerequisites() default {}; 32 | } 33 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI annotations that are useful when registering Java objects as new 3 | * GTypes in the GObject type system. 4 | */ 5 | package io.github.jwharm.javagi.gobject.annotations; -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI helper classes used for GObject-specific functionality and GValues. 3 | */ 4 | package io.github.jwharm.javagi.gobject; -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/types/TypeRegistrationException.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gobject.types; 21 | 22 | public class TypeRegistrationException extends RuntimeException { 23 | public TypeRegistrationException(String message) { 24 | super(message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /modules/main/gobject/src/main/java/io/github/jwharm/javagi/gobject/types/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI functionality to register a Java class as a new GType in the GObject 3 | * type system, and various constants and utility functions for working with 4 | * GTypes and GVariants. 5 | */ 6 | package io.github.jwharm.javagi.gobject.types; -------------------------------------------------------------------------------- /modules/main/gobject/src/test/java/io/github/jwharm/javagi/test/gobject/CustomEnumTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gobject; 2 | 3 | import io.github.jwharm.javagi.gobject.annotations.Flags; 4 | import io.github.jwharm.javagi.gobject.types.Types; 5 | import org.gnome.glib.Type; 6 | import org.gnome.gobject.GObjects; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; 11 | 12 | /** 13 | * Test custom registered enum and flags types 14 | */ 15 | public class CustomEnumTest { 16 | 17 | @Test 18 | public void testCustomEnum() { 19 | var foo = MyEnum.FOO; 20 | var bar = MyEnum.BAR; 21 | var baz = MyEnum.BAZ; 22 | 23 | assertNotNull(foo); 24 | assertNotNull(bar); 25 | assertNotNull(baz); 26 | 27 | assertEquals(foo.toString(), GObjects.enumToString(MyEnum.getType(), 0)); 28 | assertEquals(bar.toString(), GObjects.enumToString(MyEnum.getType(), 1)); 29 | assertEquals(baz.toString(), GObjects.enumToString(MyEnum.getType(), 2)); 30 | } 31 | 32 | @Test 33 | public void testCustomFlags() { 34 | var foo = MyFlags.FOO; 35 | var bar = MyFlags.BAR; 36 | var baz = MyFlags.BAZ; 37 | 38 | assertNotNull(foo); 39 | assertNotNull(bar); 40 | assertNotNull(baz); 41 | 42 | assertEquals("FOO | BAR | BAZ", 43 | GObjects.flagsToString(MyFlags.getType(), 1|2|4)); 44 | } 45 | 46 | public enum MyEnum { 47 | FOO, 48 | BAR, 49 | BAZ; 50 | 51 | private static final Type gtype = Types.register(MyEnum.class); 52 | 53 | public static Type getType() { 54 | return gtype; 55 | } 56 | } 57 | 58 | @Flags 59 | public enum MyFlags { 60 | FOO, 61 | BAR, 62 | BAZ; 63 | 64 | private static final Type gtype = Types.register(MyFlags.class); 65 | 66 | public static Type getType() { 67 | return gtype; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /modules/main/gobject/src/test/java/io/github/jwharm/javagi/test/gobject/ToStringTest.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.test.gobject; 21 | 22 | import io.github.jwharm.javagi.gobject.types.Types; 23 | import org.gnome.glib.Variant; 24 | import org.gnome.gobject.Value; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import java.lang.foreign.Arena; 28 | 29 | import static org.junit.jupiter.api.Assertions.assertEquals; 30 | 31 | /** 32 | * GValue, GType and GVariant have an extra {@code toString()} method. 33 | * Test if these methods work as expected. 34 | */ 35 | public class ToStringTest { 36 | 37 | @Test 38 | public void testValueToString() { 39 | Value vInt = new Value(Arena.ofAuto()).init(Types.INT); 40 | vInt.setInt(123); 41 | assertEquals("123", vInt.toString()); 42 | vInt.unset(); 43 | 44 | Value vBool = new Value(Arena.ofAuto()).init(Types.BOOLEAN); 45 | vBool.setBoolean(true); 46 | assertEquals("TRUE", vBool.toString()); 47 | vBool.unset(); 48 | 49 | Value vStr = new Value(Arena.ofAuto()).init(Types.STRING); 50 | vStr.setString("abc"); 51 | assertEquals("\"abc\"", vStr.toString()); 52 | vStr.unset(); 53 | } 54 | 55 | @Test 56 | public void testVariantToString() { 57 | var vInt = new Variant("u", 40); 58 | assertEquals("uint32 40", vInt.toString()); 59 | } 60 | 61 | @Test 62 | public void testTypeToString() { 63 | // todo 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /modules/main/graphene/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gobject")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "Graphene" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gsk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gdk")) 7 | api(project(":graphene")) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "Gsk" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/gst/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(project(":gmodule")) 8 | api(project(":gobject")) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "Gst" 13 | } 14 | -------------------------------------------------------------------------------- /modules/main/gstaudio/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gstbase")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GstAudio" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gstbase/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gst")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GstBase" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gstpbutils/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gst")) 7 | api(project(":gstaudio")) 8 | api(project(":gstbase")) 9 | api(project(":gstvideo")) 10 | } 11 | 12 | tasks.withType { 13 | namespace = "GstPbutils" 14 | } 15 | -------------------------------------------------------------------------------- /modules/main/gstvideo/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gstbase")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GstVideo" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/gtk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gdk")) 7 | api(project(":gsk")) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "Gtk" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/annotations/GtkCallback.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gtk.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface GtkCallback { 30 | String name() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/annotations/GtkChild.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gtk.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.FIELD) 29 | public @interface GtkChild { 30 | String name() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/annotations/GtkTemplate.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2023 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.gtk.annotations; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.TYPE) 29 | public @interface GtkTemplate { 30 | String name() default ""; 31 | String ui(); 32 | } 33 | -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI annotations to register a Java class as a Gtk composite template 3 | * class. 4 | */ 5 | package io.github.jwharm.javagi.gtk.annotations; -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/types/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI functionality to register a Java class as a Gtk composite template 3 | * class. 4 | */ 5 | package io.github.jwharm.javagi.gtk.types; -------------------------------------------------------------------------------- /modules/main/gtk/src/main/java/io/github/jwharm/javagi/gtk/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI utility classes for use with the Gtk bindings. 3 | */ 4 | package io.github.jwharm.javagi.gtk.util; -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/ExpressionTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import io.github.jwharm.javagi.gobject.JavaClosure; 4 | import io.github.jwharm.javagi.gobject.types.Types; 5 | import org.gnome.glib.Type; 6 | import org.gnome.gobject.Closure; 7 | import org.gnome.gobject.Value; 8 | import org.gnome.gtk.ClosureExpression; 9 | import org.gnome.gtk.ConstantExpression; 10 | import org.gnome.gtk.Expression; 11 | import org.junit.jupiter.api.Test; 12 | 13 | import java.util.function.IntBinaryOperator; 14 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals; 16 | 17 | /** 18 | * Evaluate Expressions and check the result 19 | */ 20 | public class ExpressionTest { 21 | 22 | @Test 23 | public void testConstantExpression() { 24 | Value value = new Value(); 25 | int input = 100; 26 | Expression expression = new ConstantExpression(Types.INT, input); 27 | expression.evaluate(null, value); 28 | int output = value.getInt(); 29 | assertEquals(input, output); 30 | } 31 | 32 | @Test 33 | public void testClosureExpression() { 34 | Value value = new Value(); 35 | Type integer = Types.INT; 36 | Closure closure = new JavaClosure((IntBinaryOperator) (a, b) -> a * b); 37 | Expression[] params = { 38 | new ConstantExpression(integer, 2), 39 | new ConstantExpression(integer, 3) 40 | }; 41 | Expression expression = new ClosureExpression(integer, closure, params); 42 | expression.evaluate(null, value); 43 | int output = value.getInt(); 44 | assertEquals(2 * 3, output); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/ListTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import org.gnome.glib.List; 4 | import org.gnome.gtk.Gtk; 5 | import org.gnome.gtk.Window; 6 | import org.gnome.gtk.WindowGroup; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.util.ArrayList; 10 | import java.util.ListIterator; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | /** 16 | * Test GList wrapper class 17 | */ 18 | public class ListTest { 19 | 20 | @Test 21 | public void testList() { 22 | Gtk.init(); 23 | 24 | // Generate a glist with 10 elements 25 | ArrayList input = new ArrayList<>(); 26 | for (int i = 0; i < 10; i++) 27 | input.add(new Window()); 28 | 29 | WindowGroup group = new WindowGroup(); 30 | for (Window win : input) 31 | group.addWindow(win); 32 | 33 | // Check glist size 34 | List glist = group.listWindows(); 35 | assertEquals(10, glist.size()); 36 | 37 | // Check all elements are in the glist 38 | for (Window win : glist) 39 | assertTrue(input.contains(win)); 40 | 41 | // Add and remove element at head 42 | Window newElem = new Window(); 43 | ListIterator iter = glist.listIterator(); 44 | iter.add(newElem); 45 | 46 | assertEquals(11, glist.size()); 47 | assertEquals(newElem, glist.getFirst()); 48 | 49 | iter.next(); 50 | iter.previous(); 51 | iter.remove(); 52 | 53 | assertEquals(10, glist.size()); 54 | 55 | // Add element in between 56 | iter.next(); 57 | iter.next(); 58 | iter.add(newElem); 59 | iter.next(); 60 | assertEquals(newElem, iter.previous()); 61 | 62 | // Empty list 63 | List emptyList = new WindowGroup().listWindows(); 64 | assertEquals(0, emptyList.size()); 65 | assertTrue(emptyList.isEmpty()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/MutableListTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import org.gnome.gtk.*; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | public class MutableListTest { 9 | @Test 10 | public void testMutableList() { 11 | Gtk.init(); 12 | 13 | AnyFilter list = new AnyFilter(); 14 | assertEquals(0, list.size()); 15 | 16 | list.add(StringFilter.builder().setSearch("a").build()); 17 | list.add(StringFilter.builder().setSearch("b").build()); 18 | list.add(StringFilter.builder().setSearch("c").build()); 19 | 20 | assertEquals(3, list.size()); 21 | 22 | list.set(0, StringFilter.builder().setSearch("d").build()); 23 | 24 | assertEquals(3, list.size()); 25 | assertEquals("d", list.get(0).toString()); 26 | 27 | list.add(1, StringFilter.builder().setSearch("e").build()); 28 | 29 | assertEquals(4, list.size()); 30 | assertEquals("d", list.get(0).toString()); 31 | assertEquals("e", list.get(1).toString()); 32 | assertEquals("b", list.get(2).toString()); 33 | 34 | list.remove(1); 35 | 36 | assertEquals(3, list.size()); 37 | assertEquals("d", list.get(0).toString()); 38 | assertEquals("b", list.get(1).toString()); 39 | 40 | list.clear(); 41 | 42 | assertEquals(0, list.size()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/NestedStructTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import org.gnome.graphene.Point; 4 | import org.gnome.graphene.Rect; 5 | import org.gnome.graphene.Size; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.lang.foreign.Arena; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | /** 13 | * Test creating, reading and writing nested structs 14 | */ 15 | public class NestedStructTest { 16 | 17 | @Test 18 | public void testGrapheneRect() { 19 | float x = 1.1f; 20 | float y = 2.22f; 21 | float w = 3.333f; 22 | float h = 4.4444f; 23 | float newX = 9.87654f; 24 | float newH = 100.0001f; 25 | 26 | try (var arena = Arena.ofConfined()) { 27 | var rect = new Rect(Point.alloc().init(x, y), Size.alloc().init(w, h), arena); 28 | 29 | assertEquals(x, rect.readOrigin().readX()); 30 | assertEquals(y, rect.readOrigin().readY()); 31 | assertEquals(w, rect.readSize().readWidth()); 32 | assertEquals(h, rect.readSize().readHeight()); 33 | 34 | rect.writeOrigin(Point.alloc().init(newX, y)); 35 | rect.writeSize(Size.alloc().init(w, newH)); 36 | 37 | assertEquals(newX, rect.readOrigin().readX()); 38 | assertEquals(y, rect.readOrigin().readY()); 39 | assertEquals(w, rect.readSize().readWidth()); 40 | assertEquals(newH, rect.readSize().readHeight()); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/PangoLayoutLineTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import org.gnome.glib.SList; 4 | import org.gnome.gtk.Gtk; 5 | import org.gnome.gtk.Label; 6 | import org.gnome.pango.Context; 7 | import org.gnome.pango.Layout; 8 | import org.gnome.pango.LayoutLine; 9 | import org.gnome.pango.LayoutRun; 10 | import org.junit.jupiter.api.Test; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; 13 | 14 | /** 15 | * Test reading an {@link SList} from a field. 16 | */ 17 | public class PangoLayoutLineTest { 18 | 19 | @Test 20 | public void testPangoLayoutLine() { 21 | Gtk.init(); 22 | 23 | String TEST_STR = "test"; 24 | int TEST_LENGTH = TEST_STR.length(); 25 | 26 | Label label = new Label(); 27 | Context context = label.getPangoContext(); 28 | Layout layout = new Layout(context); 29 | layout.setText(TEST_STR, TEST_LENGTH); 30 | SList lines = layout.getLinesReadonly(); 31 | LayoutLine line = lines.getFirst(); 32 | SList runs = line.readRuns(); 33 | LayoutRun run = runs.getFirst(); 34 | assertEquals(TEST_LENGTH, run.readItem().readNumChars()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/SpliceableListTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jwharm.javagi.test.gtk; 2 | 3 | import org.gnome.gtk.Gtk; 4 | import org.gnome.gtk.StringList; 5 | import org.gnome.gtk.StringObject; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | public class SpliceableListTest { 13 | @Test 14 | public void testSpliceableList() { 15 | Gtk.init(); 16 | 17 | StringList list = new StringList(); 18 | assertEquals(0, list.size()); 19 | 20 | list.append("a"); 21 | list.append("b"); 22 | list.append("c"); 23 | 24 | assertEquals(3, list.size()); 25 | 26 | list.set(0, new StringObject("d")); 27 | 28 | assertEquals(3, list.size()); 29 | assertEquals("d", list.getFirst().toString()); 30 | 31 | list.add(1, new StringObject("e")); 32 | 33 | assertEquals(4, list.size()); 34 | assertEquals("d", list.get(0).toString()); 35 | assertEquals("e", list.get(1).toString()); 36 | assertEquals("b", list.get(2).toString()); 37 | 38 | list.clear(); 39 | 40 | assertEquals(0, list.size()); 41 | 42 | list.addAll(List.of(new StringObject("a"), new StringObject("b"), new StringObject("c"))); 43 | 44 | assertEquals(3, list.size()); 45 | assertEquals("a", list.get(0).toString()); 46 | assertEquals("b", list.get(1).toString()); 47 | assertEquals("c", list.get(2).toString()); 48 | 49 | list.removeAt(1); 50 | 51 | assertEquals(2, list.size()); 52 | 53 | list.addAll(1, List.of(new StringObject("d"), new StringObject("e"))); 54 | 55 | assertEquals(4, list.size()); 56 | assertEquals("a", list.get(0).toString()); 57 | assertEquals("d", list.get(1).toString()); 58 | assertEquals("e", list.get(2).toString()); 59 | assertEquals("c", list.get(3).toString()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/java/io/github/jwharm/javagi/test/gtk/SubClassingTest.java: -------------------------------------------------------------------------------- 1 | /* Java-GI - Java language bindings for GObject-Introspection-based libraries 2 | * Copyright (C) 2022-2025 Jan-Willem Harmannij 3 | * 4 | * SPDX-License-Identifier: LGPL-2.1-or-later 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | package io.github.jwharm.javagi.test.gtk; 21 | 22 | import io.github.jwharm.javagi.gobject.types.TypeCache; 23 | import org.gnome.gtk.FlowBox; 24 | import org.gnome.gtk.Gtk; 25 | import org.gnome.gtk.SignalListItemFactory; 26 | import org.junit.jupiter.api.Test; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | 30 | public class SubClassingTest { 31 | 32 | /** 33 | * Create a subclass for a class that is final/opaque in native code. 34 | * The resulting class instances will have the GType of the parent 35 | * class. The subclass is only defined in Java. 36 | */ 37 | @Test 38 | void testFinalSubclass() { 39 | Gtk.init(); 40 | 41 | // FlowBox has no TypeClass. 42 | // Subclassing should not throw an exception. 43 | new FlowBoxExtended(); 44 | 45 | // The new subclass should have the parent GType 46 | assertEquals( 47 | TypeCache.getType(FlowBox.class), 48 | TypeCache.getType(FlowBoxExtended.class) 49 | ); 50 | 51 | // SignalListItemFactory has a TypeClass, but without a memory layout. 52 | // Subclassing should not throw an exception. 53 | new ItemFactoryExtended(); 54 | } 55 | 56 | public static class FlowBoxExtended extends FlowBox { 57 | public FlowBoxExtended() { 58 | super(); 59 | } 60 | } 61 | 62 | public static class ItemFactoryExtended extends SignalListItemFactory { 63 | public ItemFactoryExtended() { 64 | super(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/resources/TemplateChildTest.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/resources/TemplateSignalTest.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /modules/main/gtk/src/test/resources/test.gresource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/8b7e6cea9367cb7eccccbb2ae567f9dac7fb3f77/modules/main/gtk/src/test/resources/test.gresource -------------------------------------------------------------------------------- /modules/main/gtk/src/test/resources/test.gresource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TemplateChildTest.ui 5 | TemplateSignalTest.ui 6 | 7 | 8 | -------------------------------------------------------------------------------- /modules/main/gtksourceview/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gtk")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GtkSource" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/harfbuzz/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gobject")) 7 | api(libs.cairo) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "HarfBuzz" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/javascriptcore/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gobject")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "JavaScriptCore" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/pango/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | api(project(":harfbuzz")) 8 | api(libs.cairo) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "Pango" 13 | } 14 | -------------------------------------------------------------------------------- /modules/main/pangocairo/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":pango")) 7 | api(libs.cairo) 8 | } 9 | 10 | tasks.withType { 11 | namespace = "PangoCairo" 12 | } 13 | -------------------------------------------------------------------------------- /modules/main/soup/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "Soup" 11 | } 12 | -------------------------------------------------------------------------------- /modules/main/webkit/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gtk")) 7 | api(project(":javascriptcore")) 8 | api(project(":soup")) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "WebKit" 13 | } 14 | -------------------------------------------------------------------------------- /modules/main/webkitwebprocessextension/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gtk")) 7 | api(project(":javascriptcore")) 8 | api(project(":soup")) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "WebKitWebProcessExtension" 13 | } 14 | -------------------------------------------------------------------------------- /modules/test/gimarshallingtests/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "GIMarshallingTests" 11 | } 12 | -------------------------------------------------------------------------------- /modules/test/gimarshallingtests/src/test/java/org/gnome/gi/gimarshallingtests/TestGiMarshalling.java: -------------------------------------------------------------------------------- 1 | package org.gnome.gi.gimarshallingtests; 2 | 3 | import io.github.jwharm.javagi.base.Out; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class TestGiMarshalling { 10 | 11 | @Test 12 | void testBooleanReturnTrue() { 13 | assertTrue(booleanReturnTrue()); 14 | } 15 | 16 | @Test 17 | void testBooleanReturnFalse() { 18 | assertFalse(booleanReturnFalse()); 19 | } 20 | 21 | @Test 22 | void testBooleanInTrue() { 23 | booleanInTrue(true); 24 | } 25 | 26 | @Test 27 | void testBooleanInFalse() { 28 | booleanInFalse(false); 29 | } 30 | 31 | @Test 32 | void testBooleanOutTrue() { 33 | var v = new Out(); 34 | booleanOutTrue(v); 35 | assertTrue(v.get()); 36 | } 37 | 38 | @Test 39 | void testBooleanOutFalse() { 40 | var v = new Out(); 41 | booleanOutFalse(v); 42 | assertFalse(v.get()); 43 | } 44 | 45 | @Test 46 | void testBooleanOutUninitialized() { 47 | assertFalse(booleanOutUninitialized(null)); 48 | } 49 | 50 | @Test 51 | void testBooleanInOutTrueFalse() { 52 | var v = new Out<>(true); 53 | booleanInoutTrueFalse(v); 54 | assertFalse(v.get()); 55 | } 56 | 57 | @Test 58 | void testBooleanInOutFalseTrue() { 59 | var v = new Out<>(false); 60 | booleanInoutFalseTrue(v); 61 | assertTrue(v.get()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /modules/test/regress/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | api(project(":utility")) 8 | api(libs.cairo) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "Regress" 13 | } 14 | -------------------------------------------------------------------------------- /modules/test/regressunix/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | api(project(":utility")) 8 | api(libs.cairo) 9 | } 10 | 11 | tasks.withType { 12 | namespace = "RegressUnix" 13 | } 14 | -------------------------------------------------------------------------------- /modules/test/utility/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gobject")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "Utility" 11 | } 12 | -------------------------------------------------------------------------------- /modules/test/warnlib/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gio")) 7 | } 8 | 9 | tasks.withType { 10 | namespace = "WarnLib" 11 | } 12 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" 3 | } 4 | 5 | rootProject.name = "java-gi" 6 | 7 | includeBuild("generator") 8 | include ("adw") 9 | include("gdk") 10 | include("gdkpixbuf") 11 | include("gio") 12 | include("glib") 13 | include("gmodule") 14 | include("gobject") 15 | include("graphene") 16 | include("gsk") 17 | include("gst") 18 | include("gstaudio") 19 | include("gstbase") 20 | include("gstpbutils") 21 | include("gstvideo") 22 | include("gtk") 23 | include("gtksourceview") 24 | include("harfbuzz") 25 | include("javascriptcore") 26 | include("pango") 27 | include("pangocairo") 28 | include("soup") 29 | include("webkit") 30 | include("webkitwebprocessextension") 31 | 32 | include("gimarshallingtests") 33 | include("regress") 34 | include("regressunix") 35 | include("utility") 36 | include("warnlib") 37 | 38 | // All child projects are located in modules/main or modules/test 39 | for (p in rootProject.children) { 40 | p.projectDir = listOf( 41 | File(settingsDir, "modules/main/${p.name}"), 42 | File(settingsDir, "modules/test/${p.name}") 43 | ).firstOrNull { it.exists() }!! 44 | } 45 | 46 | include("ext") 47 | --------------------------------------------------------------------------------