Skip to content

Complete Kotlin Migration 🚀 🚀 #12312

Merged
Arthur-Milchior merged 9 commits into
ankidroid:mainfrom
david-allison:finish-kotlin-migration
Sep 4, 2022
Merged

Complete Kotlin Migration 🚀 🚀 #12312
Arthur-Milchior merged 9 commits into
ankidroid:mainfrom
david-allison:finish-kotlin-migration

Conversation

@david-allison

@david-allison david-allison commented Sep 4, 2022

Copy link
Copy Markdown
Member

Pull Request template

Purpose / Description

I wanted to get this one in for discussion - still blocked on a 3 files, which cause a CI break:

Fixes

We don't have an issue for this

Approach

  • remove Java only lint rules
  • remove migration related tooling + documents
  • remove @JvmOverloads
  • remove @NonNull/@Nullable + lint rule
  • plan to remove @JvmStatic and @JvmField

How Has This Been Tested?

CI only

Learning (optional, can help others)

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added the Blocked by dependency Currently blocked by some other dependent / related change label Sep 4, 2022
@BrayanDSO

Copy link
Copy Markdown
Member

Just remembered this: an issue to replace all usages of TextUtils.isEmpty with kotlin methods can be created now

And remember to remove the wiki page about kotlin migration and Java code style

@BrayanDSO

Copy link
Copy Markdown
Member

As some JvmStatic and JvmName will have to stay, like on protected static methods, and someone will have to go through each case, it would be nice to add comments on the code explaining why each annotation was kept

No longer necessary. API has been converted to Kotlin
No longer necessary. Anki-Android has been converted to Kotlin
No more Java in project

PreferIsEmptyOverSizeCheck is now an IDE Lint
reason: No more Java in project

* (Java)NonPublicNonStaticJavaFieldDetector:
  - Lint: NonPublicNonStaticFieldName
* ConstantJavaFieldDetector:
  - Lint: ConstantFieldName
* Remove `InconsistentAnnotationUsage` + Tests
* Remove unnecessary `@NonNull` and `@Nullable` annotations

No longer needed as everything is in Kotlin
No longer necessary: all files are in Kotlin
@david-allison david-allison force-pushed the finish-kotlin-migration branch 2 times, most recently from 32faa88 to 5418774 Compare September 4, 2022 17:29
@david-allison

david-allison commented Sep 4, 2022

Copy link
Copy Markdown
Member Author

TextUtils.isEmpty

Added this in the PR, it actually goes further. If we remove all Android references from a class (of which TextUtils was a common one), then we can remove AndroidJUnit which can be up to a 100x speed increase with tests.

This gets better, as translations are the major cause, and I plan for these to go from Android -> Rust at some point

@david-allison

This comment was marked as resolved.

@david-allison david-allison force-pushed the finish-kotlin-migration branch 2 times, most recently from 3cce257 to 479783c Compare September 4, 2022 18:46
@david-allison david-allison marked this pull request as ready for review September 4, 2022 18:46
@david-allison

This comment was marked as resolved.

@david-allison david-allison added Needs Review and removed Blocked by dependency Currently blocked by some other dependent / related change labels Sep 4, 2022
@mikehardy

Copy link
Copy Markdown
Member

standing-ovation

@david-allison

Copy link
Copy Markdown
Member Author

I'd prefer this one was rebased - some of the changes (JvmOverloads have introduced issues which I fixed in testing, and would want a targeted revert if more issues appear, rather than reverting it all)

@Arthur-Milchior Arthur-Milchior left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go as far as code change go. Maybe would love slightly more explanation, but not blocking

JUnitNullAssertionDetector.ISSUE,
KotlinMigrationBrokenEmails.ISSUE,
KotlinMigrationFixLineBreaks.ISSUE,
PreferIsEmptyOverSizeCheck.ISSUE,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's in IDE, I guess it won't be detected by the linter we use in CI, or did I understand it wrongly?
Fine to remove it anyway, assuming that it'll still be seen by people when writing code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code that we wrote ourselves for Java only. This has nothing to do with the IDE lint which will still run

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that it was java only anyway. So clearly, no reason to keep it.
My remark about IDE was an answer to the commit message, if I recall correctly, mentionning taht IDE detects this error in Kotlin.

I wonder whether it's right that it's only detected by IDE and not by the CI, but at least that's not a new problem then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that it was java only anyway. So clearly, no reason to keep it.
My remark about IDE was an answer to the commit message, if I recall correctly, mentionning taht IDE detects this error in Kotlin.

I wonder whether it's right that it's only detected by IDE and not by the CI, but at least that's not a new problem then

Comment thread tools/migrate.sh
@@ -1,243 +0,0 @@
#!/bin/bash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to give it a licence.

Too late.

It's strange to see it go. Probably the only part where I was proactive in this migration.
First time ever I create a tool whose usage was not either a single day or expected to be a long future, but with a clear end.

Comment thread AnkiDroid/src/main/java/com/ichi2/preferences/HeaderPreference.kt
AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION,
AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.LOCAL_VARIABLE,
AnnotationTarget.CONSTRUCTOR
AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FILE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get this properly, it means that KotlinCleanup can now apply at the file level.
How does it relate to the plan to remove @JvmStatic. I assume it's because you are adding the @file: above. But I don't understand what is the point to applying this KotlinCleanup to current file. If it's just a todo list for the whole project, I don't believe annotation adds anything compared to just having a standard text file/wiki with a todo list

@david-allison david-allison Sep 4, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a to-do that means we can't remove KotlinCleanup before we handle the issue.

We could then tie each instance of file:KotlinCleanup to an issue on GitHub, but it's probably best to do them in one PR per annotation rather than waste time on overheard.

JvmOverloads wasn't hard to remove

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me.

@Arthur-Milchior Arthur-Milchior added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Sep 4, 2022

@BrayanDSO BrayanDSO left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think things won't crash, ao LGTM

I'd prefer this one was rebased - some of the changes (JvmOverloads have introduced issues which I fixed in testing, and would want a targeted revert if more issues appear, rather than reverting it all)

Agreed. If I were to squash something, it would be the docs: plan X commits, implementer's choice.

My comments are just notes. Do resolve them at will

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/widgets/FabBehavior.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/ui/GesturePicker.kt
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 4, 2022
@david-allison david-allison force-pushed the finish-kotlin-migration branch from 479783c to 9cee3c1 Compare September 4, 2022 20:31
This is no longer necessary (besides the API and a few
preferences, where a Java XML inflater is used to call the constructor)

Fixed a couple of cleanup comments referring to the annotation
**TextUtils**

Once TextUtils is removed from a class, we may have no references to
Android

A non-Android class does not need AndroidJUnit, speeding up tests

**JvmField/JvmStatic**

Now all files are Kotlin, we only need a few `JvmField/JvmStatic`
annotations for APIs which use Java reflection, the rest can go.
We no longer have Java files in the project
@david-allison david-allison force-pushed the finish-kotlin-migration branch from 9cee3c1 to bc55f58 Compare September 4, 2022 20:35
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Sep 4, 2022
@david-allison

Copy link
Copy Markdown
Member Author

Agreed. If I were to squash something, it would be the docs: plan X commits, implementer's choice.

done, commit message for re-review

@Arthur-Milchior Arthur-Milchior merged commit 3c37900 into ankidroid:main Sep 4, 2022
@github-actions github-actions Bot added this to the 2.16 release milestone Sep 4, 2022
@github-actions github-actions Bot removed the Needs Second Approval Has one approval, one more approval to merge label Sep 4, 2022
@david-allison david-allison deleted the finish-kotlin-migration branch September 4, 2022 22:45
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.

4 participants