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

Public Java property is shown as val #2539

Closed
atyrin opened this issue Jun 16, 2022 · 1 comment · Fixed by #2540
Closed

Public Java property is shown as val #2539

atyrin opened this issue Jun 16, 2022 · 1 comment · Fixed by #2540
Labels

Comments

@atyrin
Copy link
Contributor

atyrin commented Jun 16, 2022

For public properties without getter or setter Dokka shows keyword val instead of var

public class JavaClass {
    public int publicProperty;
}

image

Installation

  • Dokka version: 1.7.0-dev-170
@atyrin atyrin added the bug label Jun 16, 2022
@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Jun 16, 2022

Yeah, turns out it's not as easy to fix :(

Adding this will solve it for java classes

private fun DProperty.isMutable(sourceSet: DokkaSourceSet): Boolean {
    return when(this.documentableLanguage(sourceSet)) {
        DocumentableLanguage.KOTLIN -> this.setter != null
        DocumentableLanguage.JAVA -> {
            // java properties without getters and setters should be `var`
            if (this.getter == null && this.setter == null) true else this.setter != null
        }
    }
}


if (p.isMutable(sourceSet)) keyword("var ") else keyword("val ")

But Kotlin inheriting Java will result in sourceLanguage == Kotlin, and it will be val.

We would need a way to see from which language this property came from, and if it came from Java - apply this special rule

This information is available in descriptors, so we'd have to pass it somehow, so not as difficult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants