Skip to content

Field/accessor visibility divergence can't be represented in the Documentable model #2603

@owengray-google

Description

@owengray-google

Describe the bug
If, in Java, we have

public String getFoo();
public void setFoo(String new);
private String foo;

Then because the documentable model stores getters and setters inside of a DProperty, and private-visibility elements don't appear in the model, the model must contain a public foo: String with a .getter field containing the getter and a .setter field containing the setter.

This means that, viewing this Java code as-Kotlin, we see the correct public foo: String, but viewing this Java code as-Java we see a public getter, public setter, and public backing field.

In addition, if we have, in Kotlin,

public var bar: String

and this does not have @JvmField, this should only produce getters and setters as-Java, and not a public String bar.
However, there is a similar problem to the above: if the DProperty to which the getters and setters belong were private, it couldn't be in the model. If it were public, then we would have the public String bar (the latter is the current state of affairs).

Possibly of note is that the second issue above does not occur if you do

@get:@JvmName("someNewGetter")
public var baz: String

though I am not sure why.

One possible solution may involve introducing a new, fake visibility thisPropertyIsPublicInKotlinHiddenInJavaAndHasPublicJavaAccessors
though a naive approach like that might run into issues with needing duplicates for cases like protected, protected set public get, etc.

It is possible there may be further complexities around @JvmName and/or inheritance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfeedback: GoogleAn issue/PR submitted by colleagues at Google, most likely related to the Android API reference docslanguage: JavaIssue/PR related to the Java language feature/analysis/docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions