├── .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 │ ├── header.svg │ ├── javadoc.png │ └── simple-helloworld.png ├── index.md ├── macros │ └── mkdocs-macros.py ├── register.md ├── stylesheets │ └── extra.css ├── templates.md └── usage.md ├── ext └── build.gradle.kts ├── generator ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ ├── module-info.java │ └── org │ │ └── javagi │ │ ├── JavaGI.java │ │ ├── configuration │ │ ├── ClassNames.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 │ │ ├── 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 │ │ ├── metadata │ │ ├── Matcher.java │ │ ├── Parser.java │ │ ├── Rule.java │ │ ├── Scanner.java │ │ ├── Token.java │ │ └── TokenType.java │ │ ├── patches │ │ ├── BasePatch.java │ │ ├── FreetypePatch.java │ │ ├── GLibPatch.java │ │ ├── GObjectPatch.java │ │ ├── GdkPatch.java │ │ ├── GstPatch.java │ │ ├── GtkPatch.java │ │ └── HarfBuzzPatch.java │ │ └── util │ │ ├── CollectionUtils.java │ │ ├── Conversions.java │ │ ├── GeneratedAnnotationBuilder.java │ │ ├── Javadoc.java │ │ ├── Numbers.java │ │ ├── PartialStatement.java │ │ ├── Patch.java │ │ └── Platform.java │ └── resources │ ├── LicenseNotice.txt │ └── metadata │ ├── Adw-1.metadata │ ├── GLib-2.0.metadata │ ├── GObject-2.0.metadata │ ├── Gio-2.0.metadata │ ├── GstApp-1.0.metadata │ ├── GstAudio-1.0.metadata │ ├── GstBase-1.0.metadata │ ├── GstVideo-1.0.metadata │ ├── Gtk-4.0.metadata │ ├── Pango-1.0.metadata │ ├── Regress-1.0.metadata │ ├── Soup-3.0.metadata │ └── WebKit-6.0.metadata ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mkdocs.yml ├── modules ├── adw │ └── build.gradle.kts ├── gdkpixbuf │ └── build.gradle.kts ├── glib │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ ├── gnome │ │ │ └── glib │ │ │ │ ├── ByteArray.java │ │ │ │ ├── HashTable.java │ │ │ │ ├── List.java │ │ │ │ └── SList.java │ │ │ └── javagi │ │ │ ├── base │ │ │ ├── Alias.java │ │ │ ├── Constants.java │ │ │ ├── Enumeration.java │ │ │ ├── Floating.java │ │ │ ├── FunctionPointer.java │ │ │ ├── GErrorException.java │ │ │ ├── Out.java │ │ │ ├── Proxy.java │ │ │ ├── ProxyInstance.java │ │ │ ├── TransferOwnership.java │ │ │ └── package-info.java │ │ │ ├── gio │ │ │ ├── AutoCloseable.java │ │ │ ├── ListIndexModel.java │ │ │ ├── ListModelJavaList.java │ │ │ ├── ListModelJavaListMutable.java │ │ │ ├── ListModelJavaListSpliceable.java │ │ │ └── package-info.java │ │ │ ├── glib │ │ │ └── types │ │ │ │ ├── VariantTypes.java │ │ │ │ └── package-info.java │ │ │ ├── gobject │ │ │ ├── BindingBuilder.java │ │ │ ├── BoxedUtil.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 │ │ │ ├── interop │ │ │ ├── ArenaCloseAction.java │ │ │ ├── Arenas.java │ │ │ ├── Interop.java │ │ │ ├── InteropException.java │ │ │ ├── LibLoad.java │ │ │ ├── MemoryCleaner.java │ │ │ ├── Platform.java │ │ │ ├── VarargsInvoker.java │ │ │ ├── VarargsUtil.java │ │ │ ├── Variants.java │ │ │ └── package-info.java │ │ │ └── util │ │ │ └── Intl.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javagi │ │ ├── gio │ │ ├── FileTest.java │ │ ├── IdleCallbackTest.java │ │ ├── ListModelTest.java │ │ ├── PropertiesTest.java │ │ ├── SignalTest.java │ │ ├── StrvArrayTest.java │ │ ├── ValueTest.java │ │ └── WeakRefTest.java │ │ ├── glib │ │ ├── ArrayTest.java │ │ ├── BytesTest.java │ │ ├── FlagsTest.java │ │ ├── HashTableTest.java │ │ ├── MarshalTest.java │ │ ├── VarargsTest.java │ │ └── VariantTest.java │ │ └── gobject │ │ ├── ClosureTest.java │ │ ├── CustomEnumTest.java │ │ ├── CustomInterfaceTest.java │ │ ├── DerivedClassTest.java │ │ ├── NewSignalTest.java │ │ ├── PropertyBindingTest.java │ │ ├── PropertyTest.java │ │ └── ToStringTest.java ├── gobject-introspection-tests │ ├── build.gradle.kts │ └── src │ │ └── test │ │ └── java │ │ └── org │ │ └── javagi │ │ ├── gimarshallingtests │ │ ├── TestArray.java │ │ ├── TestArrayFixedSize.java │ │ ├── TestArrayGStrv.java │ │ ├── TestArrayGStrvFixedSize.java │ │ ├── TestArrayGStrvZeroTerminated.java │ │ ├── TestArrayGVariant.java │ │ ├── TestArrayUtf8.java │ │ ├── TestArrayUtf8FixedSize.java │ │ ├── TestArrayUtf8ZeroTerminated.java │ │ ├── TestArrayZeroTerminated.java │ │ ├── TestBaseUnixTypes.java │ │ ├── TestBoolean.java │ │ ├── TestCallback.java │ │ ├── TestDouble.java │ │ ├── TestEnum.java │ │ ├── TestFlags.java │ │ ├── TestFloat.java │ │ ├── TestGArray.java │ │ ├── TestGByteArray.java │ │ ├── TestGBytes.java │ │ ├── TestGClosure.java │ │ ├── TestGError.java │ │ ├── TestGHashTable.java │ │ ├── TestGList.java │ │ ├── TestGPtrArray.java │ │ ├── TestGSList.java │ │ ├── TestGStrv.java │ │ ├── TestGType.java │ │ ├── TestGValue.java │ │ ├── TestInitFunction.java │ │ ├── TestInt.java │ │ ├── TestInt16.java │ │ ├── TestInt32.java │ │ ├── TestInt64.java │ │ ├── TestInt8.java │ │ ├── TestInterface.java │ │ ├── TestLong.java │ │ ├── TestObject.java │ │ ├── TestObjectMethod.java │ │ ├── TestObjectProperties.java │ │ ├── TestObjectPropertiesAccessors.java │ │ ├── TestObjectSignals.java │ │ ├── TestObjectVirtualMethod.java │ │ ├── TestObjectVirtualMethodWrong.java │ │ ├── TestParamSpec.java │ │ ├── TestPointer.java │ │ ├── TestReturnValueCombinations.java │ │ ├── TestSSize.java │ │ ├── TestShort.java │ │ ├── TestStructBoxed.java │ │ ├── TestStructPointer.java │ │ ├── TestStructSimple.java │ │ └── TestUtf8.java │ │ └── regress │ │ ├── TestAbstractDrawableObject.java │ │ ├── TestAliasedType.java │ │ ├── TestAnnotationObject.java │ │ ├── TestArguments.java │ │ ├── TestArray.java │ │ ├── TestArrayFixedSize.java │ │ ├── TestArrayStruct.java │ │ ├── TestBoxedStruct.java │ │ ├── TestBoxedTypeReturn.java │ │ ├── TestCairo.java │ │ ├── TestCallback.java │ │ ├── TestClassWithActionSignals.java │ │ ├── TestEnumAndFlags.java │ │ ├── TestFooBoxedVarious.java │ │ ├── TestFooEnumsAndFlags.java │ │ ├── TestFooInterface.java │ │ ├── TestFooObject.java │ │ ├── TestFooSubobject.java │ │ ├── TestFooVarious.java │ │ ├── TestFundamentalObjects.java │ │ ├── TestFundamentalType.java │ │ ├── TestGArray.java │ │ ├── TestGHashTable.java │ │ ├── TestGList.java │ │ ├── TestGPtrArray.java │ │ ├── TestGSList.java │ │ ├── TestGValueBoxing.java │ │ ├── TestInitiallyUnowned.java │ │ ├── TestIntrospectedInterface.java │ │ ├── TestMisc.java │ │ ├── TestNonstandardPrefix.java │ │ ├── TestObjectConstruct.java │ │ ├── TestObjectInherited.java │ │ ├── TestObjectMethods.java │ │ ├── TestObjectProperties.java │ │ ├── TestObjectSignals.java │ │ ├── TestSimpleMarshalling.java │ │ ├── TestStruct.java │ │ ├── TestUnixTypes.java │ │ ├── TestUtf8.java │ │ └── TestVariant.java ├── gstreamer │ └── build.gradle.kts ├── gtk │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── javagi │ │ │ └── gtk │ │ │ ├── BuilderJavaScope.java │ │ │ ├── annotations │ │ │ ├── GtkCallback.java │ │ │ ├── GtkChild.java │ │ │ ├── GtkTemplate.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── types │ │ │ ├── TemplateTypes.java │ │ │ └── package-info.java │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── javagi │ │ │ └── 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 ├── pango │ └── build.gradle.kts ├── rsvg │ └── build.gradle.kts ├── soup │ └── build.gradle.kts └── webkit │ └── 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@v5 15 | - uses: actions/setup-java@v5 16 | with: 17 | distribution: temurin 18 | java-version: 22 19 | 20 | - name: Generate and submit dependency graph 21 | uses: gradle/actions/dependency-submission@v5 22 | with: 23 | gradle-version: 8.8 24 | -------------------------------------------------------------------------------- /.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 | doFirst { 53 | classpath = files(mainModules.flatMap { subproject -> 54 | subproject.sourceSets["main"].compileClasspath.filter { file -> 55 | val path = file.absolutePath.replace("\\", "/") 56 | path.contains("/org.jetbrains/annotations/") 57 | || path.contains("/io.github.jwharm.cairobindings/cairo/") 58 | } 59 | }) 60 | } 61 | 62 | // Ensure all source code is generated before the Javadoc task starts 63 | mainModules.forEach { 64 | dependsOn(it.tasks.named("generateSources")) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /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.8.1" 5 | } 6 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/java-gi.library-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.module") 3 | id("com.vanniktech.maven.publish") 4 | } 5 | 6 | mavenPublishing { 7 | signAllPublications() 8 | coordinates("org.java-gi", project.name, project.version.toString()) 9 | pom { 10 | val capitalizedId = project.name.replaceFirstChar(Char::titlecase) 11 | name = capitalizedId 12 | description = "Java language bindings for $capitalizedId, generated with Java-GI" 13 | url = "https://java-gi.org/" 14 | licenses { 15 | license { 16 | name = "GNU Lesser General Public License, version 2.1" 17 | url = "https://www.gnu.org/licenses/lgpl-2.1.txt" 18 | } 19 | } 20 | developers { 21 | developer { 22 | id = "jwharm" 23 | name = "Jan-Willem Harmannij" 24 | email = "jwharmannij@gmail.com" 25 | url = "https://github.com/jwharm" 26 | } 27 | } 28 | scm { 29 | connection = "scm:git:git://github.com/jwharm/java-gi.git" 30 | developerConnection = "scm:git:ssh://github.com:jwharm/java-gi.git" 31 | url = "https://github.com/jwharm/java-gi/tree/main" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/java-gi.test-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.module") 3 | } 4 | 5 | afterEvaluate { 6 | tasks.withType().configureEach { 7 | dependsOn(project(":ext").tasks.named("mesonBuild")) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/drawing.png -------------------------------------------------------------------------------- /docs/getting-started/img/exampleapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/exampleapp.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app1.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app2.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app3.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app4.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app6.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app7.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app8.png -------------------------------------------------------------------------------- /docs/getting-started/img/getting-started-app9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/getting-started-app9.png -------------------------------------------------------------------------------- /docs/getting-started/img/grid-packing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/grid-packing.png -------------------------------------------------------------------------------- /docs/getting-started/img/hello-world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/hello-world.png -------------------------------------------------------------------------------- /docs/getting-started/img/window-default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/getting-started/img/window-default.png -------------------------------------------------------------------------------- /docs/img/browser-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/img/browser-screenshot.png -------------------------------------------------------------------------------- /docs/img/gnome-builder-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/img/gnome-builder-screenshot.png -------------------------------------------------------------------------------- /docs/img/header.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/img/javadoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/docs/img/javadoc.png -------------------------------------------------------------------------------- /docs/img/simple-helloworld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/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 | -------------------------------------------------------------------------------- /docs/stylesheets/extra.css: -------------------------------------------------------------------------------- 1 | .md-header { 2 | background-image: url('../img/header.svg'); 3 | background-repeat: repeat-x; 4 | background-size: auto 48px; 5 | background-position: top left; 6 | } 7 | -------------------------------------------------------------------------------- /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 = "org.java-gi" 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 = "org.javagi.generator" 28 | mainClass = "org.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.8.1" 6 | } 7 | -------------------------------------------------------------------------------- /generator/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module org.javagi.generator { 2 | requires java.compiler; 3 | requires java.logging; 4 | requires java.xml; 5 | requires com.squareup.javapoet; 6 | requires info.picocli; 7 | requires org.jetbrains.annotations; 8 | exports org.javagi; 9 | exports org.javagi.configuration; 10 | exports org.javagi.generators; 11 | exports org.javagi.gir; 12 | exports org.javagi.patches; 13 | exports org.javagi.util; 14 | opens org.javagi to info.picocli; 15 | } 16 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/configuration/Patches.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 org.javagi.configuration; 21 | 22 | import org.javagi.util.Patch; 23 | import org.javagi.patches.*; 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 | new BasePatch(), 33 | new FreetypePatch(), 34 | new GLibPatch(), 35 | new GObjectPatch(), 36 | new GstPatch(), 37 | new GdkPatch(), 38 | new GtkPatch(), 39 | new HarfBuzzPatch() 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/generators/CallbackGenerator.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 org.javagi.generators; 21 | 22 | import com.squareup.javapoet.TypeSpec; 23 | import org.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/org/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 org.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 | int allocatedSize(boolean longAsInt); 29 | 30 | default String name() { 31 | return attr("name"); 32 | } 33 | 34 | default String cType() { 35 | return attr("c:type"); 36 | } 37 | 38 | default boolean isVoid() { 39 | return "void".equals(cType()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/Attribute.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 org.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/org/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 org.javagi.gir; 21 | 22 | import static org.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 GirElement implements EnumType { 29 | 30 | public Bitfield(Map attributes, List children) { 31 | super(attributes, children); 32 | } 33 | 34 | @Override 35 | public Namespace parent() { 36 | return (Namespace) super.parent(); 37 | } 38 | 39 | @Override 40 | public RegisteredType mergeWith(RegisteredType rt) { 41 | if (rt instanceof Bitfield other) 42 | return new Bitfield(attributes(), union(children(), other.children())); 43 | return this; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (obj == this) 49 | return true; 50 | 51 | if (obj == null || obj.getClass() != this.getClass()) 52 | return false; 53 | 54 | var that = (Bitfield) obj; 55 | return Objects.equals(this.name(), that.name()); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(name()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/CInclude.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 org.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/org/javagi/gir/CallableAttrs.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 org.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/org/javagi/gir/Constant.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 org.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 GirElement implements TypedValue { 27 | 28 | public Constant(Map attributes, List children) { 29 | super(attributes, children); 30 | } 31 | 32 | @Override 33 | public Namespace parent() { 34 | return (Namespace) super.parent(); 35 | } 36 | 37 | @Override 38 | public boolean allocatesMemory() { 39 | return false; 40 | } 41 | 42 | public String value() { 43 | return attr("value"); 44 | } 45 | 46 | public String cType() { 47 | return attr("c:type"); 48 | } 49 | 50 | public String cIdentifier() { 51 | return attr("c:identifier"); 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 = (Constant) 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/org/javagi/gir/Constructor.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 org.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 GirElement implements Callable { 27 | 28 | public Constructor(Map attributes, List children) { 29 | super(attributes, children); 30 | } 31 | 32 | @Override 33 | public RegisteredType parent() { 34 | return (RegisteredType) super.parent(); 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (this == o) return true; 40 | if (o == null || getClass() != o.getClass()) return false; 41 | Constructor other = (Constructor) o; 42 | return Objects.equals(callableAttrs().cIdentifier(), 43 | other.callableAttrs().cIdentifier()); 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | return Objects.hash(super.hashCode(), callableAttrs().cIdentifier()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/Direction.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 org.javagi.gir; 21 | 22 | /** 23 | * Specifies the direction of function parameters. 24 | */ 25 | public enum Direction { 26 | /** 27 | * The argument will be modified by the function 28 | */ 29 | OUT, 30 | 31 | /** 32 | * Normal function argument 33 | */ 34 | IN, 35 | 36 | /** 37 | * The argument will be set by the function 38 | */ 39 | INOUT; 40 | 41 | public static Direction from(String value) { 42 | return value == null ? null : Direction.valueOf(value.toUpperCase()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/Doc.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 org.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/org/javagi/gir/DocDeprecated.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 org.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/org/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 org.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/org/javagi/gir/DocStability.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 org.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/org/javagi/gir/DocVersion.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 org.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/org/javagi/gir/Docsection.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 org.javagi.gir; 21 | 22 | import static org.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/org/javagi/gir/Documentation.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 org.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/org/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 org.javagi.gir; 21 | 22 | import org.javagi.util.PartialStatement; 23 | 24 | import static org.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/org/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 org.javagi.gir; 21 | 22 | import static org.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 GirElement implements EnumType { 29 | 30 | public Enumeration(Map attributes, List children) { 31 | super(attributes, children); 32 | } 33 | 34 | @Override 35 | public Namespace parent() { 36 | return (Namespace) super.parent(); 37 | } 38 | 39 | public Enumeration mergeWith(RegisteredType rt) { 40 | if (rt instanceof Enumeration other) 41 | return new Enumeration(attributes(), union(children(), other.children())); 42 | return this; 43 | } 44 | 45 | public String errorDomain() { 46 | return attr("error-domain"); 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (obj == this) 52 | return true; 53 | 54 | if (obj == null || obj.getClass() != this.getClass()) 55 | return false; 56 | 57 | var that = (Enumeration) obj; 58 | return Objects.equals(this.name(), that.name()); 59 | } 60 | 61 | @Override 62 | public int hashCode() { 63 | return Objects.hash(name()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /generator/src/main/java/org/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 org.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/org/javagi/gir/Function.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 org.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 GirElement implements Callable { 27 | 28 | public Function(Map attributes, List children) { 29 | super(attributes, children); 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | if (this == o) return true; 35 | if (o == null || getClass() != o.getClass()) return false; 36 | Function other = (Function) o; 37 | return Objects.equals(callableAttrs().cIdentifier(), 38 | other.callableAttrs().cIdentifier()); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return Objects.hash(super.hashCode(), callableAttrs().cIdentifier()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/FunctionInline.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 org.javagi.gir; 21 | 22 | /** 23 | * function-inline is unsupported 24 | */ 25 | public final class FunctionInline extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/FunctionMacro.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 org.javagi.gir; 21 | 22 | /** 23 | * function-macro is unsupported 24 | */ 25 | public final class FunctionMacro extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/Implements.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 org.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/org/javagi/gir/Include.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 org.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/org/javagi/gir/InfoAttrs.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 org.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/org/javagi/gir/InfoElements.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 org.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/org/javagi/gir/MethodInline.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 org.javagi.gir; 21 | 22 | /** 23 | * method-inline is unsupported 24 | */ 25 | public final class MethodInline extends GirElement { 26 | } 27 | -------------------------------------------------------------------------------- /generator/src/main/java/org/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 org.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/org/javagi/gir/Parameters.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 org.javagi.gir; 21 | 22 | import static org.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/org/javagi/gir/Prerequisite.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 org.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/org/javagi/gir/Signal.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 org.javagi.gir; 21 | 22 | import com.squareup.javapoet.TypeName; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | import static org.javagi.util.Conversions.toJavaSimpleType; 28 | 29 | public final class Signal extends GirElement implements Callable { 30 | 31 | public Signal(Map attributes, List children) { 32 | super(attributes, children); 33 | } 34 | 35 | @Override 36 | public RegisteredType parent() { 37 | return (RegisteredType) super.parent(); 38 | } 39 | 40 | public TypeName typeName() { 41 | return parent().typeName().nestedClass( 42 | toJavaSimpleType(name() + "_callback", namespace())); 43 | } 44 | 45 | public boolean detailed() { 46 | return attrBool("detailed", false); 47 | } 48 | 49 | public When when() { 50 | return When.from(attr("when")); 51 | } 52 | 53 | public boolean action() { 54 | return attrBool("action", false); 55 | } 56 | 57 | public boolean noHooks() { 58 | return attrBool("no-hooks", false); 59 | } 60 | 61 | public boolean noRecurse() { 62 | return attrBool("no-recurse", false); 63 | } 64 | 65 | public String emitter() { 66 | return attr("emitter"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/SourcePosition.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 org.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/org/javagi/gir/Stability.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 org.javagi.gir; 21 | 22 | /** 23 | * Specifies the stability status of a GIR element. 24 | */ 25 | public enum Stability { 26 | STABLE, 27 | UNSTABLE, 28 | PRIVATE; 29 | 30 | public static Stability from(String value) { 31 | return value == null ? null : Stability.valueOf(value.toUpperCase()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /generator/src/main/java/org/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 org.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/org/javagi/gir/TransferOwnership.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 org.javagi.gir; 21 | 22 | /** 23 | * Specifies the ownership of the responsibility to free function parameters. 24 | */ 25 | public enum TransferOwnership { 26 | /** 27 | * The data is owned by the caller 28 | */ 29 | NONE, 30 | 31 | /** 32 | * The callee takes ownership of the data container, but not the data inside it 33 | */ 34 | CONTAINER, 35 | 36 | /** 37 | * The callee takes ownership of the data, and is responsible for freeing it 38 | */ 39 | FULL; 40 | 41 | /** 42 | * Defaults to "none" when unspecified 43 | */ 44 | public static TransferOwnership from(String value) { 45 | return value == null ? NONE : TransferOwnership.valueOf(value.toUpperCase()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/Varargs.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 org.javagi.gir; 21 | 22 | public final class Varargs extends GirElement { 23 | } 24 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/gir/When.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 org.javagi.gir; 21 | 22 | /** 23 | * Specifies when a signal handler is called. 24 | */ 25 | public enum When { 26 | /** 27 | * The default handler is called before the handlers added via {@code g_signal_connect()} 28 | */ 29 | FIRST, // "first" 30 | 31 | /** 32 | * The default handler is called after the handlers added via {@code g_signal_connect()} 33 | */ 34 | LAST, // "last" 35 | 36 | /** 37 | * The default handler is called after the handlers added via {@code g_signal_connect_after()} 38 | */ 39 | CLEANUP; // "cleanup" 40 | 41 | public static When from(String value) { 42 | return value == null ? null : When.valueOf(value.toUpperCase()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/metadata/Rule.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 org.javagi.metadata; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * Represents a metadata rule: a pattern, selector, zero or more arguments, and 27 | * zero or more nested (relative) rules. 28 | * 29 | * @param glob a glob pattern to match against Gir node names 30 | * @param selector an optional selector of the Gir element type 31 | * @param args argument names and values 32 | * @param children nested (relative) rules 33 | */ 34 | public record Rule(String glob, String selector, Map args, 35 | List children) { 36 | } 37 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/metadata/Token.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 org.javagi.metadata; 21 | 22 | /** 23 | * Represents a single token that is read by the metadata scanner. 24 | * 25 | * @param type the token type 26 | * @param text the parsed lexeme (character string) 27 | * @param position the position of the token in the metadata source file 28 | */ 29 | record Token(TokenType type, String text, int position) { 30 | } 31 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/metadata/TokenType.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 org.javagi.metadata; 21 | 22 | /** 23 | * The types of tokens that are read by the metadata scanner. 24 | */ 25 | enum TokenType { 26 | /** 27 | * A {@code .} character 28 | */ 29 | DOT, 30 | 31 | /** 32 | * A {@code =} character 33 | */ 34 | EQUAL, 35 | 36 | /** 37 | * A {@code #} character 38 | */ 39 | HASH, 40 | 41 | /** 42 | * A pattern (glob), selector, argument name or argument value. 43 | *

44 | * Valid characters for an identifier: 45 | *

    46 | *
  • Alphabetic letters (upper and lower case) 47 | *
  • Digits 48 | *
  • Parens {@code ()}, to denote an empty/unset argument 49 | *
  • Underscore {@code _}, dash {@code -} and semicolon {@code :} 50 | *
  • Glob wildcards {@code ?} and {@code *}, and groups {@code {,}} 51 | *
52 | */ 53 | IDENTIFIER, 54 | 55 | /** 56 | * A double-quoted string. The quotes are not included in the 57 | * {@link Token#text()} 58 | */ 59 | STRING, 60 | 61 | /** 62 | * A {@code \n} character 63 | */ 64 | NEW_LINE, 65 | 66 | /** 67 | * End of file 68 | */ 69 | EOF 70 | } 71 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/patches/FreetypePatch.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 org.javagi.patches; 21 | 22 | import org.javagi.gir.GirElement; 23 | import org.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/org/javagi/patches/GstPatch.java: -------------------------------------------------------------------------------- 1 | package org.javagi.patches; 2 | 3 | import org.javagi.util.Patch; 4 | import org.javagi.gir.*; 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 to 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"), gintType()))); 40 | ns = add(ns, new Constant( 41 | Map.of("name", "MAP_WRITE", "value", "2"), 42 | List.of(new Doc(emptyMap(), "map for write access"), gintType()))); 43 | ns = add(ns, new Constant( 44 | Map.of("name", "MAP_FLAG_LAST", "value", "65536"), 45 | List.of(new Doc(emptyMap(), "first flag that can be used for custom purposes"), gintType()))); 46 | 47 | // Remove GstMapFlags 48 | return remove(ns, Bitfield.class, "name", "MapFlags"); 49 | } 50 | 51 | return element; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /generator/src/main/java/org/javagi/util/GeneratedAnnotationBuilder.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 org.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/resources/LicenseNotice.txt: -------------------------------------------------------------------------------- 1 | This file was automatically generated by Java-GI. Do not edit this file 2 | directly! Visit for more information. 3 | 4 | The API documentation in this file was derived from GObject-Introspection 5 | metadata and may include text or comments from the original C sources. 6 | 7 | Copyright (c), upstream authors of the GObject-Introspection data. 8 | 9 | This generated file is distributed under the same license as the original 10 | GObject-Introspection data, unless otherwise specified. Users of this file 11 | are responsible for complying with any licenses or terms required by the 12 | original authors. 13 | 14 | THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. 17 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/Adw-1.metadata: -------------------------------------------------------------------------------- 1 | // SplitButton.getDirection() overrides Widget.getDirection() 2 | // with a different return type. Rename to getArrowDirection() 3 | SplitButton.get_direction name=get_arrow_direction 4 | 5 | // Set generic type of EnumListModel and ViewStackPages 6 | EnumListModel java-gi-generic-actual="Adw.EnumListItem" 7 | ViewStackPages java-gi-generic-actual="Adw.ViewStackPage" 8 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/GObject-2.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * VaList parameters are excluded from the Java bindings. 3 | * Therefore, the VaList marshaller classes and the 4 | * "signal_set_va_marshaller" function are excluded too. 5 | */ 6 | VaClosureMarshal java-gi-skip 7 | SignalCVaMarshaller java-gi-skip 8 | signal_set_va_marshaller java-gi-skip 9 | 10 | /* 11 | * `TYPE_FLAG_RESERVED_ID_BIT` is defined as GType but that doesn't 12 | * make sense in the Java bindings. Change it to a numeric type. 13 | */ 14 | TYPE_FLAG_RESERVED_ID_BIT.*#type name=gsize c:type=gsize 15 | 16 | /* 17 | * Replace the gtype declaration in GObject with an alias for the GLib 18 | * gtype that was added there, so it will inherit in Java and the 19 | * instances of both classes can be used interchangeably in many cases. 20 | */ 21 | Type.*#type name="GLib.Type" c:type=gtype 22 | 23 | /* 24 | * The method "g_type_module_use" overrides "g_type_plugin_use", but 25 | * with a different return type. This is not allowed in Java. 26 | * Therefore, it is renamed from "use" to "use_type_module". 27 | */ 28 | TypeModule.use name=use_type_module 29 | 30 | /* 31 | * Make GWeakRef generic (replacing all GObject arguments with generic 32 | * type {@code }). 33 | */ 34 | WeakRef java-gi-generic 35 | 36 | // Closure construction functions return floating references. 37 | Closure free-function=g_closure_unref 38 | 39 | /* 40 | * CClosure construction functions return floating references. As 41 | * CClosure shouldn't be used from Java anyway, we remove these 42 | * functions. 43 | */ 44 | CClosure.new*#function java-gi-skip 45 | 46 | // Implement GValue.toString() with g_strdup_value_contents() 47 | Value java-gi-to-string="org.gnome.gobject.GObjects.strdupValueContents(this)" 48 | 49 | // GByteArray is marshaled to a byte[] 50 | ByteArray java-gi-skip 51 | 52 | // GString is marshaled to a java.lang.String 53 | String java-gi-skip 54 | 55 | /* 56 | * The GObject gir file contains boxed type definitions for many GLib types. 57 | * We already register those in GLib.java so we can skip the GObject 58 | * definitions. 59 | */ 60 | *#glib:boxed java-gi-skip 61 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/GstApp-1.0.metadata: -------------------------------------------------------------------------------- 1 | // AppSrc.setCaps() and AppSink.setCaps() override BaseSrc.setCaps() with a 2 | // different return type, which is not allowed in Java. Rename both methods to 3 | // setCapabilities(). 4 | App{Src,Sink}.set_caps name=set_capabilities 5 | 6 | // The "try-pull-object" signal returns a GstMiniObject directly (not a 7 | // pointer), but java-gi doesn't support that right now. Exclude it for now. 8 | AppSink.try-pull-object java-gi-skip 9 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/GstAudio-1.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * Property "output-buffer-duration-fraction" has type "Gst.Fraction". 3 | * A Gst.Fraction cannot automatically be put into a GValue, so we 4 | * cannot generate a builder setter in Java. 5 | */ 6 | AudioAggregator.output-buffer-duration-fraction java-gi-skip 7 | 8 | /* 9 | * Virtual method AudioSink::stop overrides BaseSink::stop but returns 10 | * void instead of boolean. This is not allowed in Java, so it is 11 | * removed from the Java bindings. 12 | */ 13 | AudioSink.stop java-gi-skip 14 | 15 | /* 16 | * AudioInfo::fromCaps clashes with AudioInfo::newFromCaps because the 17 | * "new" prefix is removed in Java-GI. The same happens in DsdInfo. 18 | * Change the name of these methods to "withCaps". 19 | */ 20 | {Audio,Dsd}Info.from_caps name=with_caps 21 | 22 | /* 23 | * Constructor AudioChannelMixer.new has two out-parameters, but they 24 | * aren't annotated as such. 25 | */ 26 | AudioChannelMixer.new.{in,out}_position direction=inout 27 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/GstBase-1.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * Aggregator::peekNextSample is a virtual method with an invoker 3 | * method, but the name of the "pad" parameter is "aggregatorPad". 4 | * We rename the parameter to "pad" so it is the same. 5 | */ 6 | Aggregator.peek_next_sample#virtual-method.aggregator_pad name=pad 7 | 8 | /* 9 | * Virtual method BaseSrc::query and BaseSink::query would be 10 | * protected in Java, but they override a public method with the same 11 | * name in Element. Therefore, they must also be public. 12 | */ 13 | Base{Src,Sink}.query java-gi-override-visibility=PUBLIC 14 | 15 | /* 16 | * ByteReader::dupStringUtf16 has a parameter with an array of int16 17 | * values, but the size is unspecified, so we cannot convert this to a 18 | * short[] array. Remove it from the Java bindings. 19 | */ 20 | ByteReader.dup_string_utf16 java-gi-skip 21 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/GstVideo-1.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * VideoInfo::fromCaps clashes with VideoInfo::newFromCaps because the 3 | * "new" prefix is removed in Java-GI. The same happens in 4 | * VideoInfoDmaDrm. Change the name to "withCaps". 5 | */ 6 | VideoInfo.from_caps name=with_caps 7 | VideoInfoDmaDrm.from_caps name=with_caps 8 | 9 | /* 10 | * Function GstVideo.bufferAddVideoGlTextureUploadMeta has an 11 | * out-parameter "texture_type", but it isn't annotated as such. 12 | */ 13 | buffer_add_video_gl_texture_upload_meta.texture_type direction=inout 14 | 15 | /* 16 | * Function Navigation.eventParseModifierState has an out-parameter 17 | * "state", but it isn't annotated as such. 18 | */ 19 | Navigation.event_parse_modifier_state.state direction=out 20 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/Pango-1.0.metadata: -------------------------------------------------------------------------------- 1 | // pango_log2vis_get_embedding_levels has missing annotations 2 | log2vis_get_embedding_levels java-gi-skip 3 | 4 | /* 5 | * Unsure how to interpret this return type: 6 | * 7 | * 8 | * 9 | * Removing the method from the Java bindings for now. 10 | */ 11 | Font.get_languages java-gi-skip 12 | 13 | /* 14 | * Font::getFeatures has different parameter attributes between 15 | * platforms. Remove the Java binding for now. 16 | */ 17 | Font.get_features java-gi-skip 18 | 19 | /* 20 | * Java-GI automatically calls ref() but this one is deprecated. 21 | * We can safely remove it from the Java bindings. 22 | */ 23 | Coverage.ref java-gi-skip 24 | 25 | /* 26 | * FontFamily::getName, isMonospace and isVariable have a 27 | * "glib:get-property" attribute on Linux, but not on Windows and 28 | * macOS. We set the same attribute on all, so they are correctly 29 | * merged into one method in the Java bindings. 30 | */ 31 | FontFamily 32 | .get_name glib:get-property=name 33 | .is_monospace glib:get-property=name 34 | .is_variable glib:get-property=name 35 | 36 | // Set ListModel generic type on FontFamily and FontMap 37 | FontFamily java-gi-generic-actual="FontFace" 38 | FontMap java-gi-generic-actual="FontFamily" 39 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/Regress-1.0.metadata: -------------------------------------------------------------------------------- 1 | /* Incorrect value of constant larger than 32 bits: 2 | * https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/526 3 | * Change the type to a gint64. 4 | */ 5 | ANNOTATION_CALCULATED_LARGE.gint#type name=gint64 c:type=gint64 6 | 7 | /* c:type of the TestStruct[] elements is incorrectly specified as 8 | * "RegressTestStructA*" in the gir file. It is not an array of pointers; 9 | * the array contains the flat structs. */ 10 | test_array_struct_out*.arr.*#array.TestStructA#type c:type=RegressTestStructA 11 | 12 | // Field declarations with a missing c:type. 13 | TestStructD 14 | .array2.*.TestObj c:type="TestObj*" 15 | .field.TestObj c:type="TestObj*" 16 | .list.*.TestObj c:type="TestObj*" 17 | .garray.*.TestObj c:type="TestObj*" 18 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/Soup-3.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * Virtual method Auth.update() has a HashTable argument where the 3 | * invoker method has a String argument. Remove the "invoker" 4 | * attribute, so they are generated as two separate methods in Java. 5 | */ 6 | Auth.update invoker=() 7 | -------------------------------------------------------------------------------- /generator/src/main/resources/metadata/WebKit-6.0.metadata: -------------------------------------------------------------------------------- 1 | /* 2 | * WebView.getSettings() overrides Widget.getSettings() with a 3 | * different return type. Rename to getWebViewSettings() 4 | */ 5 | WebView.get_settings name=get_web_view_settings 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4096M 2 | org.gradle.configuration-cache=false 3 | org.gradle.caching=true 4 | org.gradle.parallel=true 5 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | javagi = "0.13.0-RC1" 3 | jdk = "22" 4 | cairo = "1.18.4.2" 5 | picocli = "4.7.7" 6 | javapoet = "1.13.0" 7 | annotations = "26.0.2-1" 8 | junit = "6.0.0" 9 | mavenpublish = "0.34.0" 10 | 11 | [libraries] 12 | javagi-generator = { module = "org.java-gi: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/d74da2beec01bea5c4a1abb82cc959122465ded5/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-9.0.0-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /modules/adw/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(project(":gtk")) 8 | } 9 | 10 | tasks.withType { 11 | girFiles.set(listOf("Adw-1")) 12 | } 13 | -------------------------------------------------------------------------------- /modules/gdkpixbuf/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 | girFiles.set(listOf("GdkPixbuf-2.0")) 11 | } 12 | -------------------------------------------------------------------------------- /modules/glib/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | tasks.withType { 6 | girFiles.set(listOf("GLib-2.0", "GObject-2.0", "GModule-2.0", "Gio-2.0")) 7 | } 8 | -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/base/Constants.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 org.javagi.base; 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/glib/src/main/java/org/javagi/base/Enumeration.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 org.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/glib/src/main/java/org/javagi/base/Floating.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 org.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/glib/src/main/java/org/javagi/base/FunctionPointer.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 org.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/glib/src/main/java/org/javagi/base/Out.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 org.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/glib/src/main/java/org/javagi/base/Proxy.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 org.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/glib/src/main/java/org/javagi/base/TransferOwnership.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 org.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 values but not the container 39 | */ 40 | VALUES, 41 | 42 | /** 43 | * The recipient owns the entire value 44 | */ 45 | FULL 46 | } 47 | -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/base/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI base classes that are used or extended by generated bindings. 3 | */ 4 | package org.javagi.base; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/gio/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI helper classes used by the GIO bindings. 3 | */ 4 | package org.javagi.gio; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/glib/types/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI type declarations. 3 | */ 4 | package org.javagi.glib.types; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/gobject/BuilderInterface.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 org.javagi.gobject; 21 | 22 | import org.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/glib/src/main/java/org/javagi/gobject/annotations/ClassInit.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/Flags.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 org.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/GType.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/InstanceInit.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/InterfaceInit.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/Layout.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/Namespace.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 org.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/glib/src/main/java/org/javagi/gobject/annotations/RegisteredType.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 org.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/glib/src/main/java/org/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 org.javagi.gobject.annotations; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/gobject/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI helper classes used for GObject-specific functionality and GValues. 3 | */ 4 | package org.javagi.gobject; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/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 org.javagi.gobject.types; 21 | 22 | public class TypeRegistrationException extends RuntimeException { 23 | public TypeRegistrationException(String message) { 24 | super(message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/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 org.javagi.gobject.types; -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/javagi/interop/ArenaCloseAction.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 | package org.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/glib/src/main/java/org/javagi/interop/InteropException.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 org.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/glib/src/main/java/org/javagi/interop/Platform.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 org.javagi.interop; 21 | 22 | /** 23 | * The Platform enum represents the runtime platform. 24 | */ 25 | public enum Platform { 26 | WINDOWS, 27 | LINUX, 28 | MACOS; 29 | 30 | private static Platform runtimePlatform = null; 31 | 32 | /** 33 | * Determine the runtime platform 34 | * @return the runtime platform: "windows", "linux" or "macos" 35 | */ 36 | public static Platform getRuntimePlatform() { 37 | if (runtimePlatform == null) { 38 | String osName = System.getProperty("os.name").toLowerCase(); 39 | if (osName.contains("win")) 40 | runtimePlatform = WINDOWS; 41 | else if (osName.contains("nux")) 42 | runtimePlatform = LINUX; 43 | else if (osName.contains("mac") || osName.contains("darwin")) 44 | runtimePlatform = MACOS; 45 | } 46 | return runtimePlatform; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/glib/src/main/java/org/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 org.javagi.interop; -------------------------------------------------------------------------------- /modules/glib/src/test/java/org/javagi/gio/ListModelTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.gio; 2 | 3 | import org.gnome.gio.DBusMessage; 4 | import org.gnome.gio.Gio; 5 | import org.gnome.gio.ListStore; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | /** 12 | * Test some operations on ListIndexModel and ListStore 13 | */ 14 | public class ListModelTest { 15 | 16 | // Make sure the GIO library is loaded 17 | @BeforeAll 18 | public static void ensureInitialized() { 19 | Gio.javagi$ensureInitialized(); 20 | } 21 | 22 | @Test 23 | public void createListModel() { 24 | // verify that ListIndexModel works as expected 25 | var listIndexModel = new ListIndexModel(1000); 26 | assertEquals(listIndexModel.getItemType(), ListIndexModel.ListIndex.getType()); 27 | assertEquals(1000, listIndexModel.getNItems()); 28 | 29 | var item500 = listIndexModel.getItem(500); 30 | assertNotNull(item500); 31 | assertEquals(500, item500.getIndex()); 32 | 33 | // foreach loop on a ListModel 34 | int i = 0; 35 | for (var item : listIndexModel) 36 | assertEquals(item.getIndex(), i++); 37 | 38 | // stream() operations on a ListModel 39 | var product = listIndexModel.stream() 40 | .map(ListIndexModel.ListIndex::getIndex) 41 | .reduce(0, Integer::sum); 42 | assertEquals(499500, product); 43 | } 44 | 45 | @Test 46 | public void createListStore() { 47 | var listStore = new ListStore(DBusMessage.getType()); 48 | var item = new DBusMessage(); 49 | listStore.append(item); 50 | assertEquals(1, listStore.size()); 51 | assertEquals(item, listStore.getFirst()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /modules/glib/src/test/java/org/javagi/gio/StrvArrayTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.gio; 2 | 3 | import org.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/glib/src/test/java/org/javagi/gio/WeakRefTest.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 org.javagi.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/glib/src/test/java/org/javagi/glib/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.glib; 2 | 3 | import org.javagi.base.Out; 4 | import org.javagi.interop.Interop; 5 | import org.gnome.glib.GLib; 6 | import org.gnome.glib.HashTable; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.lang.foreign.Arena; 10 | import java.nio.charset.StandardCharsets; 11 | 12 | import static org.junit.jupiter.api.Assertions.*; 13 | 14 | public class ArrayTest { 15 | 16 | /** 17 | * Test reading values from a GPtrArray 18 | */ 19 | @Test 20 | void testArray() { 21 | try (var arena = Arena.ofConfined()) { 22 | var table = HashTable.new_(GLib::strHash, GLib::strEqual); 23 | for (int i = 0; i < 3; i++) 24 | table.insert( 25 | Interop.allocateNativeString("key" + i, arena), 26 | Interop.allocateNativeString("val" + i, arena)); 27 | var values = table.getValuesAsPtrArray(); 28 | assertNotNull(values); 29 | assertEquals(3, values.length); 30 | for (int i = 0; i < 3; i++) { 31 | String str = Interop.getStringFrom(values[i]); 32 | assertEquals(4, str.length()); 33 | assertTrue(str.startsWith("val")); 34 | } 35 | } 36 | } 37 | 38 | /** 39 | * Test writing to and reading from an inout array parameter 40 | */ 41 | @Test 42 | void testArrayInOut() { 43 | String input = "c3RyaW5nIHRvIGRlY29kZQ=="; 44 | String base64Decoded = "string to decode"; 45 | 46 | Out bytesOut = new Out<>(); 47 | bytesOut.set(input.getBytes(StandardCharsets.UTF_8)); 48 | GLib.base64DecodeInplace(bytesOut); 49 | String decodedString = new String(bytesOut.get()); 50 | assertEquals(base64Decoded, decodedString); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /modules/glib/src/test/java/org/javagi/glib/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 org.javagi.glib; 21 | 22 | import org.gnome.glib.ChecksumType; 23 | import org.gnome.glib.GLib; 24 | import org.javagi.base.GErrorException; 25 | import org.gnome.glib.KeyFile; 26 | import org.junit.jupiter.api.Test; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | import static org.junit.jupiter.api.Assertions.assertTrue; 30 | 31 | public class BytesTest { 32 | 33 | @Test 34 | public void testFromGBytes() { 35 | var expected = "e2fc714c4727ee9395f324cd2e7f331f"; 36 | var computed = GLib.computeChecksumForBytes(ChecksumType.MD5, "abcd".getBytes()); 37 | assertEquals(expected, computed); 38 | } 39 | 40 | @Test 41 | public void testToGBytes() throws GErrorException { 42 | byte[] data = """ 43 | [MyGroup] 44 | FirstKey=Hello 45 | SecondKey=Goodbye 46 | """.getBytes(); 47 | var keyFile = new KeyFile(); 48 | var success = keyFile.loadFromBytes(data); 49 | assertTrue(success); 50 | assertEquals("MyGroup", keyFile.getStartGroup()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /modules/glib/src/test/java/org/javagi/glib/FlagsTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.glib; 2 | 3 | import org.javagi.interop.Interop; 4 | import org.gnome.glib.AsciiType; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.Set; 8 | 9 | import static org.gnome.glib.AsciiType.*; 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | /** 13 | * Test conversion of int to EnumSet and back 14 | */ 15 | public class FlagsTest { 16 | 17 | @Test 18 | void testFlags() { 19 | int input = 1 + 2 + 4 + 8 + 64 + 512; 20 | var set = Interop.intToEnumSet(AsciiType.class, AsciiType::of, input); 21 | assertEquals(Set.of(ALNUM, ALPHA, CNTRL, DIGIT, PRINT, UPPER), set); 22 | int output = Interop.enumSetToInt(set); 23 | assertEquals(input, output); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /modules/glib/src/test/java/org/javagi/glib/HashTableTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.glib; 2 | 3 | import org.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/glib/src/test/java/org/javagi/glib/VarargsTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.glib; 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/glib/src/test/java/org/javagi/gobject/CustomEnumTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.gobject; 2 | 3 | import org.javagi.gobject.annotations.Flags; 4 | import org.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/gobject-introspection-tests/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.test-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(libs.cairo) 8 | } 9 | 10 | tasks.withType { 11 | girFiles.set(listOf("GIMarshallingTests-1.0", "Regress-1.0", "RegressUnix-1.0", "Utility-1.0", "WarnLib-1.0")) 12 | } 13 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestGByteArray.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 org.javagi.gimarshallingtests; 21 | 22 | import org.javagi.base.Out; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestGByteArray { 29 | private static final byte[] TEST_BYTE_ARRAY = new byte[] { 0, 49, -1, 51 }; 30 | 31 | @Test 32 | void fullReturn() { 33 | assertArrayEquals(TEST_BYTE_ARRAY, bytearrayFullReturn()); 34 | } 35 | 36 | @Test 37 | void noneIn() { 38 | bytearrayNoneIn(TEST_BYTE_ARRAY); 39 | } 40 | 41 | @Test 42 | void fullOut() { 43 | var v = new Out(); 44 | bytearrayFullOut(v); 45 | assertArrayEquals(TEST_BYTE_ARRAY, v.get()); 46 | } 47 | 48 | @Test 49 | void fullInout() { 50 | var v = new Out<>(TEST_BYTE_ARRAY); 51 | bytearrayFullInout(v); 52 | assertArrayEquals(new byte[] { 104, 101, 108, 0, -1 }, v.get()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestGBytes.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 org.javagi.gimarshallingtests; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestGBytes { 28 | private static final byte[] TEST_BYTE_ARRAY = new byte[] { 0, 49, -1, 51 }; 29 | 30 | @Test 31 | void fullReturn() { 32 | assertArrayEquals(TEST_BYTE_ARRAY, gbytesFullReturn()); 33 | } 34 | @Test 35 | void noneIn() { 36 | gbytesNoneIn(TEST_BYTE_ARRAY); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestGClosure.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 org.javagi.gimarshallingtests; 21 | 22 | import org.gnome.gobject.Value; 23 | import org.javagi.gobject.JavaClosure; 24 | import org.javagi.gobject.types.Types; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import java.util.function.IntSupplier; 28 | 29 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 30 | import static org.junit.jupiter.api.Assertions.*; 31 | 32 | public class TestGClosure { 33 | @Test 34 | void in() { 35 | gclosureIn(new JavaClosure((IntSupplier) () -> 42)); 36 | } 37 | 38 | @Test 39 | void return_() { 40 | var closure = gclosureReturn(); 41 | assertNotNull(closure); 42 | var returnValue = new Value(); 43 | returnValue.init(Types.INT); 44 | closure.invoke(returnValue, new Value[] {}, null); 45 | assertEquals(42, returnValue.getInt()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestGStrv.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 org.javagi.gimarshallingtests; 21 | 22 | import org.javagi.base.Out; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestGStrv { 29 | private static final String[] TEST_UTF8_ARRAY = {"0", "1", "2"}; 30 | 31 | @Test 32 | void return_() { 33 | assertArrayEquals(TEST_UTF8_ARRAY, gstrvReturn()); 34 | } 35 | 36 | @Test 37 | void in() { 38 | gstrvIn(TEST_UTF8_ARRAY); 39 | } 40 | 41 | @Test 42 | void out() { 43 | var v = new Out(); 44 | gstrvOut(v); 45 | assertArrayEquals(TEST_UTF8_ARRAY, v.get()); 46 | } 47 | 48 | @Test 49 | void outUninitialized() { 50 | var v = new Out(); 51 | assertFalse(gstrvOutUninitialized(v)); 52 | assertNull(v.get()); 53 | } 54 | 55 | @Test 56 | void inout() { 57 | var v = new Out<>(TEST_UTF8_ARRAY); 58 | gstrvInout(v); 59 | assertArrayEquals(new String[] {"-1", "0", "1", "2"}, v.get()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestInitFunction.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 org.javagi.gimarshallingtests; 21 | 22 | import org.javagi.base.Out; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestInitFunction { 29 | @Test 30 | void marshalsNull() { 31 | assertTrue(initFunction(null)); 32 | } 33 | 34 | @Test 35 | void marshalsInoutEmptyArray() { 36 | var params = new String[] {}; 37 | var v = new Out<>(params); 38 | assertTrue(initFunction(v)); 39 | assertArrayEquals(params, v.get()); 40 | } 41 | 42 | @Test 43 | void marshalsInoutArray() { 44 | var params = new String[] {"--foo", "--bar"}; 45 | var v = new Out<>(params); 46 | assertTrue(initFunction(v)); 47 | assertArrayEquals(new String[] {"--foo"}, v.get()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestPointer.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 org.javagi.gimarshallingtests; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import java.lang.foreign.Arena; 25 | import java.lang.foreign.MemorySegment; 26 | 27 | import static org.gnome.gi.gimarshallingtests.GIMarshallingTests.*; 28 | import static org.junit.jupiter.api.Assertions.*; 29 | 30 | public class TestPointer { 31 | @Test 32 | void inReturn() { 33 | try (var arena = Arena.ofConfined()) { 34 | var pointer = arena.allocate(1); 35 | assertEquals(pointer, pointerInReturn(pointer)); 36 | } 37 | 38 | assertNull(pointerInReturn(MemorySegment.NULL)); 39 | 40 | assertNull(pointerInReturn(null)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestStructPointer.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 org.javagi.gimarshallingtests; 21 | 22 | import org.gnome.gi.gimarshallingtests.PointerStruct; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestStructPointer { 28 | @Test 29 | void returnv() { 30 | PointerStruct struct = PointerStruct.returnv(); 31 | assertNotNull(struct); 32 | assertEquals(42, struct.readLong()); 33 | } 34 | 35 | @Test 36 | void inv() { 37 | new PointerStruct(42).inv(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/gimarshallingtests/TestStructSimple.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 org.javagi.gimarshallingtests; 21 | 22 | import org.gnome.gi.gimarshallingtests.SimpleStruct; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestStructSimple { 28 | @Test 29 | void returnv() { 30 | SimpleStruct struct = SimpleStruct.returnv(); 31 | assertNotNull(struct); 32 | assertEquals(6, struct.readLong()); 33 | assertEquals(7, struct.readInt8()); 34 | } 35 | 36 | @Test 37 | void inv() { 38 | new SimpleStruct(6, (byte) 7).inv(); 39 | } 40 | 41 | @Test 42 | void method() { 43 | new SimpleStruct(6, (byte) 7).method(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestAliasedType.java: -------------------------------------------------------------------------------- 1 | package org.javagi.regress; 2 | 3 | import org.gnome.gi.regress.AliasedTestBoxed; 4 | import org.gnome.gi.regress.PtrArrayAlias; 5 | import org.gnome.gi.regress.TestBoxed; 6 | import org.gnome.gi.regress.VaListAlias; 7 | import org.gnome.glib.PtrArray; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import java.lang.foreign.MemorySegment; 11 | 12 | import static org.gnome.gi.regress.Regress.*; 13 | 14 | public class TestAliasedType { 15 | @Test 16 | void isIntrospectableViaAlias() { 17 | PtrArrayAlias data = PtrArrayAlias.fromPtrArray(new PtrArray()); 18 | introspectableViaAlias(data); 19 | } 20 | 21 | @Test 22 | void isNotIntrospectableViaAlias() { 23 | // This actually needs a `va_list`, which we don't support. 24 | VaListAlias ok = new VaListAlias(MemorySegment.NULL); 25 | notIntrospectableViaAlias(ok); 26 | } 27 | 28 | @Test 29 | void callerAlloc() { 30 | AliasedTestBoxed boxed = AliasedTestBoxed.fromTestBoxed(new TestBoxed()); 31 | aliasedCallerAlloc(boxed); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestClassWithActionSignals.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.TestAction; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestClassWithActionSignals { 29 | TestAction o; 30 | 31 | @BeforeEach 32 | void init() { 33 | o = new TestAction(); 34 | } 35 | 36 | @Test 37 | void returnsNewObject() { 38 | Object otherObj = o.emit("action"); 39 | assertInstanceOf(TestAction.class, otherObj); 40 | assertNotEquals(o, otherObj); 41 | 42 | TestAction otherObj2 = o.emitAction(); 43 | assertNotEquals(o, otherObj2); 44 | } 45 | 46 | @Test 47 | void returnsNull() { 48 | assertNull(o.emit("action2")); 49 | assertNull(o.emitAction2()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestFooBoxedVarious.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.FooBRect; 23 | import org.gnome.gi.regress.FooBUnion; 24 | import org.gnome.gi.regress.FooBoxed; 25 | import org.gnome.gi.regress.FooRectangle; 26 | import org.junit.jupiter.api.Disabled; 27 | import org.junit.jupiter.api.Test; 28 | 29 | import static org.junit.jupiter.api.Assertions.*; 30 | 31 | public class TestFooBoxedVarious { 32 | @Test 33 | void fooBoxedMethod() { 34 | var o1 = new FooBoxed(); 35 | o1.method(); 36 | } 37 | 38 | @Test 39 | void fooBRect() { 40 | var o2 = new FooBRect(1.5, -2.5); 41 | assertEquals(1.5, o2.readX()); 42 | assertEquals(-2.5, o2.readY()); 43 | 44 | var o3 = new FooBRect(-1.4, 2.6); 45 | assertEquals(-1.4, o3.readX()); 46 | assertEquals(2.6, o3.readY()); 47 | 48 | o2.add(o3); 49 | o3.add(o2); 50 | } 51 | 52 | @Test 53 | @Disabled("Not supported") 54 | void fooBUnion() { 55 | var u = new FooBUnion(); 56 | } 57 | 58 | @Test 59 | void rectangleInstance() { 60 | var o1 = new FooRectangle(0, 0, 10, 10); 61 | var o2 = new FooRectangle(1, 1, 12, 12); 62 | o1.add(o2); 63 | o2.add(o1); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestFundamentalObjects.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.TestFundamentalSubObject; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.gnome.gi.regress.Regress.*; 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestFundamentalObjects { 29 | @Test 30 | void arrayIn() { 31 | var objects = new TestFundamentalSubObject[] { 32 | new TestFundamentalSubObject("data1"), 33 | new TestFundamentalSubObject("data2") 34 | }; 35 | boolean result = testArrayOfFundamentalObjectsIn(objects); 36 | assertTrue(result); 37 | } 38 | 39 | @Test 40 | void arrayOut() { 41 | var objects = testArrayOfFundamentalObjectsOut(); 42 | assertNotNull(objects); 43 | assertEquals(2, objects.length); 44 | assertNotNull(objects[0]); 45 | assertNotNull(objects[1]); 46 | } 47 | 48 | @Test 49 | void in() { 50 | var object = new TestFundamentalSubObject("data"); 51 | assertTrue(testFundamentalArgumentIn(object)); 52 | } 53 | 54 | @Test 55 | void out() { 56 | var object = new TestFundamentalSubObject("data"); 57 | var sameObject = testFundamentalArgumentOut(object); 58 | assertEquals(object, sameObject); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestFundamentalType.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.*; 23 | import org.gnome.gobject.GObjects; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | public class TestFundamentalType { 29 | @Test 30 | void constructSubtype() { 31 | var o = new TestFundamentalSubObject("plop"); 32 | assertEquals(TestFundamentalSubObject.getType(), o.readGClass().readGType()); 33 | } 34 | 35 | @Test 36 | void constructHiddenType() { 37 | var o = Regress.testCreateFundamentalHiddenClassInstance(); 38 | assertNotNull(o); 39 | assertTrue(GObjects.typeIsA(o.readGClass().readGType(), TestFundamentalObject.getType())); 40 | assertNotEquals(TestFundamentalObject.getType(), o.readGClass().readGType()); 41 | } 42 | 43 | @Test 44 | void constructNoGetSetFunc() { 45 | var o = new TestFundamentalObjectNoGetSetFunc("plop"); 46 | assertEquals("plop", o.getData()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestGArray.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 org.javagi.regress; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.gnome.gi.regress.Regress.*; 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestGArray { 28 | @Test 29 | void containerReturn() { 30 | assertArrayEquals(new String[] {"regress"}, testGarrayContainerReturn()); 31 | } 32 | 33 | @Test 34 | void fullReturn() { 35 | assertArrayEquals(new String[] {"regress"}, testGarrayFullReturn()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestGPtrArray.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 org.javagi.regress; 21 | 22 | import org.gnome.gobject.Value; 23 | import org.javagi.gobject.types.Types; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.gnome.gi.regress.Regress.*; 27 | 28 | public class TestGPtrArray { 29 | @Test 30 | void nullGValuePtrArray() { 31 | annotationPtrArray(null); 32 | } 33 | 34 | @Test 35 | void emptyGValuePtrArray() { 36 | annotationPtrArray(new Value[] {}); 37 | } 38 | 39 | @Test 40 | void nonEmptyGValuePtrArray() { 41 | Value[] values = new Value[] {new Value(), new Value()}; 42 | values[0].init(Types.INT); 43 | values[1].init(Types.INT); 44 | values[0].setInt(1); 45 | values[1].setInt(2); 46 | annotationPtrArray(values); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestGValueBoxing.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 org.javagi.regress; 21 | 22 | import org.gnome.glib.Date; 23 | import org.gnome.glib.DateMonth; 24 | import org.gnome.gobject.Value; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.gnome.gi.regress.Regress.*; 28 | import static org.javagi.gobject.ValueUtil.valueToObject; 29 | import static org.junit.jupiter.api.Assertions.*; 30 | 31 | public class TestGValueBoxing { 32 | @Test 33 | void withDate() { 34 | Value value = testDateInGvalue(); 35 | Date date = (Date) valueToObject(value); 36 | assertNotNull(date); 37 | assertEquals((short) 1984, date.getYear().getValue()); 38 | assertEquals(DateMonth.DECEMBER, date.getMonth()); 39 | assertEquals((byte) 5, date.getDay().getValue()); 40 | } 41 | 42 | @Test 43 | void withStrv() { 44 | Value value = testStrvInGvalue(); 45 | String[] strv = (String[]) valueToObject(value); 46 | assertArrayEquals(new String[] {"one", "two", "three"}, strv); 47 | } 48 | 49 | @Test 50 | void withStrvNull() { 51 | Value value = testNullStrvInGvalue(); 52 | String[] strv = (String[]) valueToObject(value); 53 | assertNull(strv); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestInitiallyUnowned.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.*; 23 | import org.gnome.glib.Variant; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.gnome.gi.regress.Regress.*; 27 | import static org.junit.jupiter.api.Assertions.*; 28 | 29 | public class TestInitiallyUnowned { 30 | @Test 31 | void construct() { 32 | var o = new TestFloating(); 33 | assertNotNull(o); 34 | } 35 | 36 | @Test 37 | void transferFloatingVariant() { 38 | Variant variant = getVariant(); 39 | assertNotNull(variant); 40 | assertEquals(42, variant.unpack()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestIntrospectedInterface.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.*; 23 | import org.gnome.gobject.GObject; 24 | import org.javagi.gobject.annotations.Property; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import java.lang.foreign.MemorySegment; 28 | import java.util.concurrent.atomic.AtomicBoolean; 29 | 30 | import static org.junit.jupiter.api.Assertions.*; 31 | 32 | public class TestIntrospectedInterface { 33 | public static class Implementor extends GObject implements TestInterface { 34 | @Property 35 | public int getNumber() { 36 | return 5; 37 | } 38 | } 39 | 40 | @Test 41 | void correctlyEmitsInterfaceSignals() { 42 | // Explicitly call Regress initalization, or else TestInterface is not registered 43 | Regress.javagi$ensureInitialized(); 44 | 45 | var hasBeenCalled = new AtomicBoolean(false); 46 | var obj = new Implementor(); 47 | obj.onInterfaceSignal(_ -> hasBeenCalled.set(true)); 48 | obj.emitInterfaceSignal(MemorySegment.NULL); 49 | assertTrue(hasBeenCalled.get()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestNonstandardPrefix.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.*; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestNonstandardPrefix { 28 | @Test 29 | void construct() { 30 | var o = new TestWi8021x(); 31 | assertTrue((boolean) o.getProperty("testbool")); 32 | 33 | var o2 = TestWi8021x.builder().setTestbool(false).build(); 34 | assertFalse((boolean) o2.getProperty("testbool")); 35 | o2.setProperty("testbool", true); 36 | assertTrue((boolean) o2.getProperty("testbool")); 37 | } 38 | 39 | @Test 40 | void callInstanceMethod() { 41 | var o = new TestWi8021x(); 42 | assertTrue(o.getTestbool()); 43 | o.setTestbool(false); 44 | assertFalse(o.getTestbool()); 45 | } 46 | 47 | @Test 48 | void callStaticMethod() { 49 | assertEquals(42, TestWi8021x.staticMethod(21)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestObjectInherited.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 org.javagi.regress; 21 | 22 | import org.gnome.gi.regress.*; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestObjectInherited { 28 | @Test 29 | void canBeConstructed() { 30 | var subobj = new TestSubObj(); 31 | assertEquals(TestSubObj.getType(), subobj.readGClass().readGType()); 32 | } 33 | 34 | @Test 35 | void callOverridedInstanceMethod() { 36 | var subobj = new TestSubObj(); 37 | assertEquals(0, subobj.instanceMethod()); 38 | } 39 | 40 | @Test 41 | void hasProperties() { 42 | var subobj = TestSubObj.builder().setBoolean(true).build(); 43 | assertTrue((boolean) subobj.getProperty("boolean")); 44 | subobj.setProperty("boolean", false); 45 | assertFalse((boolean) subobj.getProperty("boolean")); 46 | } 47 | 48 | @Test 49 | void overriddenInterfaceProperties() { 50 | var subobj1 = TestSubObj.builder().setNumber(4).build(); 51 | assertEquals(4, subobj1.getProperty("number")); 52 | 53 | var subobj2 = new TestSubObj(); 54 | assertEquals(0, subobj2.getProperty("number")); 55 | 56 | subobj2.setProperty("number", 4); 57 | assertEquals(4, subobj2.getProperty("number")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestUnixTypes.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 org.javagi.regress; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.gnome.gi.regressunix.RegressUnix.*; 25 | import static org.junit.jupiter.api.Assertions.*; 26 | 27 | public class TestUnixTypes { 28 | @Test 29 | void devt() { 30 | assertEquals(12345, testDevt(12345)); 31 | } 32 | 33 | @Test 34 | void gidt() { 35 | assertEquals(12345, testGidt(12345)); 36 | } 37 | 38 | @Test 39 | void pidt() { 40 | assertEquals(12345, testPidt(12345)); 41 | } 42 | 43 | @Test 44 | void socklent() { 45 | assertEquals(12345, testSocklent(12345)); 46 | } 47 | 48 | @Test 49 | void uidt() { 50 | assertEquals(12345, testUidt(12345)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /modules/gobject-introspection-tests/src/test/java/org/javagi/regress/TestUtf8.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 org.javagi.regress; 21 | 22 | import org.javagi.base.Out; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import java.util.List; 26 | 27 | import static org.gnome.gi.regress.Regress.*; 28 | import static org.junit.jupiter.api.Assertions.*; 29 | 30 | public class TestUtf8 { 31 | private static final String CONST_STR = "const ♥ utf8"; 32 | private static final String NONCONST_STR = "nonconst ♥ utf8"; 33 | 34 | @Test 35 | void constReturn() { 36 | assertEquals(CONST_STR, testUtf8ConstReturn()); 37 | } 38 | 39 | @Test 40 | void nonconstReturn() { 41 | assertEquals(NONCONST_STR, testUtf8NonconstReturn()); 42 | } 43 | 44 | @Test 45 | void constIn() { 46 | testUtf8ConstIn(CONST_STR); 47 | } 48 | 49 | @Test 50 | void out() { 51 | var out = new Out(); 52 | testUtf8Out(out); 53 | assertEquals(NONCONST_STR, out.get()); 54 | } 55 | 56 | @Test 57 | void inout() { 58 | var inout = new Out<>(CONST_STR); 59 | testUtf8Inout(inout); 60 | assertEquals(NONCONST_STR, inout.get()); 61 | } 62 | 63 | @Test 64 | void filenameReturn() { 65 | assertEquals(List.of("åäö", "/etc/fstab"), testFilenameReturn()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /modules/gstreamer/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 | girFiles.set(listOf("Gst-1.0", "GstApp-1.0", "GstAudio-1.0", "GstBase-1.0", "GstPbutils-1.0", "GstVideo-1.0")) 11 | } 12 | -------------------------------------------------------------------------------- /modules/gtk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(project(":gdkpixbuf")) 8 | api(project(":harfbuzz")) 9 | api(project(":pango")) 10 | api(libs.cairo) 11 | } 12 | 13 | tasks.withType { 14 | girFiles.set(listOf("Gdk-4.0", "Graphene-1.0", "Gsk-4.0", "Gtk-4.0")) 15 | } 16 | -------------------------------------------------------------------------------- /modules/gtk/src/main/java/org/javagi/gtk/annotations/GtkCallback.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 org.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/gtk/src/main/java/org/javagi/gtk/annotations/GtkChild.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 org.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/gtk/src/main/java/org/javagi/gtk/annotations/GtkTemplate.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 org.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/gtk/src/main/java/org/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 org.javagi.gtk.annotations; -------------------------------------------------------------------------------- /modules/gtk/src/main/java/org/javagi/gtk/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java-GI helper classes for use with the Gtk bindings. 3 | */ 4 | package org.javagi.gtk; -------------------------------------------------------------------------------- /modules/gtk/src/main/java/org/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 org.javagi.gtk.types; -------------------------------------------------------------------------------- /modules/gtk/src/test/java/org/javagi/gtk/ExpressionTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.gtk; 2 | 3 | import org.javagi.gobject.JavaClosure; 4 | import org.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 | .ignoreFirstParameter(); 38 | Expression[] params = { 39 | new ConstantExpression(integer, 2), 40 | new ConstantExpression(integer, 3) 41 | }; 42 | Expression expression = new ClosureExpression(integer, closure, params); 43 | expression.evaluate(null, value); 44 | int output = value.getInt(); 45 | assertEquals(2 * 3, output); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /modules/gtk/src/test/java/org/javagi/gtk/ListTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.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/gtk/src/test/java/org/javagi/gtk/MutableListTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.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/gtk/src/test/java/org/javagi/gtk/NestedStructTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.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/gtk/src/test/java/org/javagi/gtk/PangoLayoutLineTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.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/gtk/src/test/java/org/javagi/gtk/SpliceableListTest.java: -------------------------------------------------------------------------------- 1 | package org.javagi.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/gtk/src/test/resources/TemplateChildTest.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /modules/gtk/src/test/resources/TemplateSignalTest.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /modules/gtk/src/test/resources/test.gresource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwharm/java-gi/d74da2beec01bea5c4a1abb82cc959122465ded5/modules/gtk/src/test/resources/test.gresource -------------------------------------------------------------------------------- /modules/gtk/src/test/resources/test.gresource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TemplateChildTest.ui 5 | TemplateSignalTest.ui 6 | 7 | 8 | -------------------------------------------------------------------------------- /modules/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 | girFiles.set(listOf("GtkSource-5")) 11 | } 12 | -------------------------------------------------------------------------------- /modules/harfbuzz/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(libs.cairo) 8 | } 9 | 10 | tasks.withType { 11 | girFiles.set(listOf("HarfBuzz-0.0")) 12 | } 13 | -------------------------------------------------------------------------------- /modules/pango/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(project(":harfbuzz")) 8 | api(libs.cairo) 9 | } 10 | 11 | tasks.withType { 12 | girFiles.set(listOf("Pango-1.0", "PangoCairo-1.0")) 13 | } 14 | -------------------------------------------------------------------------------- /modules/rsvg/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":glib")) 7 | api(project(":gdkpixbuf")) 8 | api(libs.cairo) 9 | } 10 | 11 | tasks.withType { 12 | girFiles.set(listOf("Rsvg-2.0")) 13 | } 14 | -------------------------------------------------------------------------------- /modules/soup/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 | girFiles.set(listOf("Soup-3.0")) 11 | } 12 | -------------------------------------------------------------------------------- /modules/webkit/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gi.library-conventions") 3 | } 4 | 5 | dependencies { 6 | api(project(":gtk")) 7 | api(project(":soup")) 8 | } 9 | 10 | tasks.withType { 11 | girFiles.set(listOf("WebKit-6.0", "WebKitWebProcessExtension-6.0", "JavaScriptCore-6.0")) 12 | } 13 | -------------------------------------------------------------------------------- /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 | 9 | include("adw") 10 | include("gdkpixbuf") 11 | include("glib") 12 | include("gobject-introspection-tests") 13 | include("gstreamer") 14 | include("gtk") 15 | include("gtksourceview") 16 | include("harfbuzz") 17 | include("pango") 18 | include("rsvg") 19 | include("soup") 20 | include("webkit") 21 | 22 | // All child projects are located in the modules/ directory 23 | for (p in rootProject.children) { 24 | p.projectDir = File(settingsDir, "modules/${p.name}") 25 | } 26 | 27 | include("ext") 28 | --------------------------------------------------------------------------------