Skip to content

Kotlin: hide more internal elements when accessed from Java#1794

Draft
pwrobeldev wants to merge 18 commits intomasterfrom
pwrobeldev/kotlin-jvm-synthetic-nested-elements
Draft

Kotlin: hide more internal elements when accessed from Java#1794
pwrobeldev wants to merge 18 commits intomasterfrom
pwrobeldev/kotlin-jvm-synthetic-nested-elements

Conversation

@pwrobeldev
Copy link
Contributor

No description provided.

This is not a functional change. The logic is preserved.
All tests work in the identical way.

This change introduces a new function, which will be used
later for all types.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The logic was simplified to use 'return when' statement.
This improves readability and prepares for further changes.

This is not a functional change. The code works as previously.
All tests pass.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…internal

This change ensures that all elements nested in internal
types hierarchy are internal and annotated with JvmSyntetic.

Note: this change is ugly and will be refactored in the next commit
      to remove the logic from mustache and put it in Kotlin generator.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
All elements nested in internal types hierarchy are
internal.

This does not apply to direct members of interfaces.
According to Kotlin rules such types cannot be internal.

This will be fixed in the next commits.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…pile

The previous changes ensure that more elements are not accessible in Java.
The following errors were visible -- the test cases were removed, because
with the new handling of nested internal the compilation error was expected.

```
> Task :functional:compileReleaseUnitTestJavaWithJavac FAILED
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:56: error: cannot find symbol
    SomeInternalClassWithMembers someObject = SomeInternalClassWithMembers.create();
                                                                          ^
  symbol:   method create()
  location: class SomeInternalClassWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:57: error: cannot find symbol
    assertEquals(987, someObject.someFunction());
                                ^
  symbol:   method someFunction()
  location: variable someObject of type SomeInternalClassWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:62: error: cannot find symbol
    assertEquals(765, SomeInternalClassWithMembers.someStaticFunction());
                                                  ^
  symbol:   method someStaticFunction()
  location: class SomeInternalClassWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:67: error: cannot find symbol
    SomeInternalStructWithMembers someObject = SomeInternalStructWithMembers.create();
                                                                            ^
  symbol:   method create()
  location: class SomeInternalStructWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:68: error: cannot find symbol
    assertEquals(123, someObject.someInteger);
                                ^
  symbol:   variable someInteger
  location: variable someObject of type SomeInternalStructWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:69: error: cannot find symbol
    assertEquals(456, someObject.someLong);
                                ^
  symbol:   variable someLong
  location: variable someObject of type SomeInternalStructWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:74: error: cannot find symbol
    SomeInternalStructWithMembers someObject = SomeInternalStructWithMembers.create();
                                                                            ^
  symbol:   method create()
  location: class SomeInternalStructWithMembers
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:75: error: cannot find symbol
    assertEquals(32, someObject.someFunction());
                               ^
  symbol:   method someFunction()
  location: variable someObject of type SomeInternalStructWithMembers
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The logic will be handled in dedicated classes
for resolving synthetic annotation and visibility.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Some elements cannot use internal keyword even though
conceptually they are internal.

A good example are direct children elements of interfaces.
Kotlin interface disallows internal elements as the direct
children elements.

Even though such children elements are not visible when
accessed from Kotlin (because interface is internal), in
Java they are accessible.

To remove them from Java we will need to annotate them
as synthetic via annotation. We need to have a way to
nicely check whether element should be annotated as synthetic
instead of having logic in mustache template.

This change introduces new class, which checks for the conceptual
internal visibility. The new class is applied in KotlinVisibilityResolver.

No changes in smoke tests are present -- the logic is preserved.

In next commits the new class will be used to create synthetic resolver.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
In the past we had special logic for properties getters/setters
when resolving visibility for extensions.

Now the logic is identical so the special predicate can be removed.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This allows to minimize the logic in mustache files.

Moreover, the JvmSynthetic is used for elements defined in
internal interfaces and internal lambda.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…pile

Due to usage of jvm synthetic for members of
internal interfaces the interoperability cases
stopped to compile -- members of such interfaces
are not visible.

```
> Task :functional:compileReleaseUnitTestJavaWithJavac FAILED
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:34: error: method does not override or implement a method from a supertype
  @OverRide
  ^
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:39: error: method does not override or implement a method from a supertype
  @OverRide
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…ail to compile

Previously they were commented instead of removed.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This hides them from Java.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…aces

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Hide what can be hidden via jvm synthetic.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
…pile

Test cases related to usage of enum 'value' field
and aliasing enumerators are removed, because they
fail to compile with the latest changes.

```
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:69: error: cannot find symbol
    assertEquals(2, someObject.value);
                              ^
  symbol:   variable value
  location: variable someObject of type SomeInternalEnum
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:75: error: cannot find symbol
    SomeInternalEnum someObject = SomeInternalEnum.SINGLE;
                                                  ^
  symbol:   variable SINGLE
  location: class SomeInternalEnum
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:76: error: cannot find symbol
    assertEquals(1, someObject.value);
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
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.

1 participant