Skip to content

Kotlin: generate static properties as get/set functions#1800

Merged
pwrobeldev merged 14 commits intomasterfrom
pwrobeldev/kotlin-generate-static-properties-as-getter-setter-pair
Feb 19, 2026
Merged

Kotlin: generate static properties as get/set functions#1800
pwrobeldev merged 14 commits intomasterfrom
pwrobeldev/kotlin-generate-static-properties-as-getter-setter-pair

Conversation

@pwrobeldev
Copy link
Copy Markdown
Contributor

@pwrobeldev pwrobeldev commented Feb 18, 2026

---------- Motivation ----------
During internal testing I found that static internal properties do not work correctly.
Basically, the combination of JvmStatic property + JvmName for get/set sometimes is
not correctly resolved in runtime.

Moreover, I identified the gap related to internal static properties and functions in interfaces.
Even though companion object of interface allows usage of internal keyword, we cannot use
JvmStatic. Therefore, such usage must be flagged during validation.

---------- Solution ----------

  1. This commit brings reproducer of runtime problems in functional tests.
  2. It also provides a fix for such problems.
  3. Validation is adjusted.

A note before showing design decision:

  • in the past the static properties were implemented in interfaces as get/set functions pair,
    because of similar problems
  • moreover, we had to provide extension functions for get/set of static properties in classes
    to preserve compatibility with Java

Because of that and the problem stated in 'Motivation' section, the static properties in classes
are also handled using get/set function pair. This way internal static properties work as expected.

This commit additionally removes the generation of extension functions because they are not needed
now. Furthermore, validation of LimeInterface in Kotlin is adjusted to disallow static internal properties
and functions.

This commit showcases the runtime error related to
usage of internal static property from Kotlin generated
code.

The current syntax for static internal properties
does not guarantee that they work properly. It seems
that combination of 'JvmName()' for property get/set
and 'JvmStatic' does not work. The following runtime
error is visible:

```
java.lang.NoSuchMethodError:
'java.lang.String com.here.android.test.InternalAttributeClassWithStaticProperty$Companion.getFooBar$functional_release()'
	at com.here.android.test.VisibilityAttributeTest.checkInternalStaticProperty(VisibilityAttributeTest.kt:205)
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The usage of static property with annotations did not work
for internal static properties in Kotlin. This is fixed by
representing properties via get/set functions.

The additional extension functions for static properties are
removed, because they are not needed -- functions are used
by default.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Showcase that after the fix the code works as expected.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev force-pushed the pwrobeldev/kotlin-generate-static-properties-as-getter-setter-pair branch from 890800e to 14e8936 Compare February 18, 2026 20:05
This commit ensures that definition of 'InternalClassWithStaticProperty'
is identical in both smoke and functional tests.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The static properties in interfaces can use 'internal' and JvmSynthetic.
Moreover, the 'Impl' class uses wrong syntax -- ordinary static properties
instead of get/set function.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Such properties when internal should not be accessible from Java
and should use 'internal' and 'JvmSynthetic' keywords.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change reworks handling of static properties in interfaces.
The getter/setter is used in the impl class. Moreover, the code
is simplified by including 'KotlinFunction.mustache'.

The 'JvmSynthetic' is properly generated now. One missing piece
is 'internal' keyword -- it will be added in upcoming change.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Because of the previous change the test stopped to compile as expected.
JvmSynthetic hides the getter/setter of internal static property for interface
from Java.

```
> Task :functional:compileReleaseUnitTestJavaWithJavac FAILED
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:126: error: cannot find symbol
    assertEquals("FOO_BAR", InternalAttributeInterfaceParent.getSomeInternalProperty());
                                                            ^
  symbol:   method getSomeInternalProperty()
  location: interface InternalAttributeInterfaceParent
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:128: error: cannot find symbol
    InternalAttributeInterfaceParent.setSomeInternalProperty("abc");
                                    ^
  symbol:   method setSomeInternalProperty(String)
  location: interface InternalAttributeInterfaceParent
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:129: error: cannot find symbol
    assertEquals("abc", InternalAttributeInterfaceParent.getSomeInternalProperty());
                                                        ^
  symbol:   method getSomeInternalProperty()
  location: interface InternalAttributeInterfaceParent
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
'JvmStatic' annotation cannot be used for non-public
members of companion object in interfaces.

The following error was observed when I tried to add 'internal' keyword
to such static elements:
```
Only public members in interface companion objects can be annotated with '@JvmStatic'
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev marked this pull request as ready for review February 19, 2026 08:14
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Hsilgos
Hsilgos previously approved these changes Feb 19, 2026
It seems that this usage fails for Java generator and its tests.
This is not critical for Kotlin generator. It will be handled in
a separate ticket.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev merged commit e1a418b into master Feb 19, 2026
19 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/kotlin-generate-static-properties-as-getter-setter-pair branch February 19, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants