Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow private fields as properties #133

Closed
Sxtanna opened this issue Jun 5, 2020 · 3 comments
Closed

Allow private fields as properties #133

Sxtanna opened this issue Jun 5, 2020 · 3 comments
Labels
Milestone

Comments

@Sxtanna
Copy link
Contributor

Sxtanna commented Jun 5, 2020

Allowing for private fields would make usage from Kotlin less ugly.

In its current state, the library resolves all fields, private included, and just throws away fields that are inaccessible.

Simply inserting Field#setAccessible(true) above this line here:

Will resolve this issue.

@ljacqu
Copy link
Member

ljacqu commented Jun 6, 2020

I don't have much experience with Kotlin—are there any other shortcomings that could be improved for Kotlin integration? I'd like to get a better picture as to maybe bundle a few improvements to facilitate usage from Kotlin.

@Sxtanna
Copy link
Contributor Author

Sxtanna commented Jun 6, 2020

Aside from that, a benefit not only for Kotlin, but Java as well would be for the project to utilize the jetbrains annotations to mark nullability and contracts.

IntelliJ is able to infer some of them, but proper definition is always better.

@ljacqu ljacqu added this to the 1.3.0 Release milestone Aug 3, 2020
@ljacqu ljacqu added the kotlin label Nov 22, 2020
@ljacqu ljacqu modified the milestones: 1.3.0 Release, 1.4.0 Release Apr 19, 2021
ljacqu added a commit that referenced this issue Aug 10, 2023
- Use Field#setAccessible if a field is not private to make the code compatible with Kotlin constants without the need of the JvmField annotation.
@ljacqu
Copy link
Member

ljacqu commented Aug 10, 2023

As long as the field is static, it will be picked up by the default configuration data builder. Sample Kotlin code that will work with the next release:

import ch.jalu.configme.Comment
import ch.jalu.configme.SettingsHolder
import ch.jalu.configme.SettingsManagerBuilder
import ch.jalu.configme.properties.PropertyInitializer
import ch.jalu.configme.utils.Utils
import java.nio.file.Paths

fun main(args: Array<String>) {
    val path = Paths.get("./configme-kt-test.yml")
    Utils.createFileIfNotExists(path);

    val settings = SettingsManagerBuilder
        .withYamlFile(path)
        .configurationData(TitleSettings.javaClass)
        .create()

    println("App: ${settings.getProperty(TitleSettings.TITLE_TEXT)}")
}

object TitleSettings: SettingsHolder {

    @Comment("Demo")
    val TITLE_TEXT = PropertyInitializer.newProperty("title.text", "woof")

}

Previously, @JvmField was required.

ljacqu added a commit that referenced this issue Aug 10, 2023
- Use Field#setAccessible if a field is not private to make the code compatible with Kotlin constants without the need of the JvmField annotation.
@ljacqu ljacqu closed this as completed Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants