* Fix nullability for Note.getTags()
The returned property from this method is of type Array<String>, also the property is initialiazed with non null strings.
* Fix nullability for AddContentApi.addNote()
Changed the type of tags parameter from Set<String?>? to Set<String>? because:
- it doesn't make sense to have a null tag(what would that mean)
- the method addNotes() below uses a List<Set<String>?>? so either this method is incorrect or that one
- our current code would crash with a null tag string as Utils.joinTags() uses !! to reference the string tags when
doing its work
As a future todo maybe we can change parameter to a default one seeing that the database structure for notes specifies
this column as not null(use an empty String?).
* Fix nullability for AddContentApi.addNotes()
Changed the type of parameter fieldsList from List<Array<String>?> to List<Array<String>> because:
- it doesn't make sense to have null fields for a note(it is possible?)
- it would crash as with a null fields array, Utils.joinFields would return null and we would insert null in a
non null declared column flds
* Fix nullability for AddContentApi.updateNoteTags()
Changed the type of parameter tags from Set<String?>? to Set<String> because:
- same issue with null tag strings which doesn't make sense and it would crash our code in Utils.joinTags
- the tags parameter was made non null, this is an update call so using null(which would result in no tags update)
doesn't make sense
* Fix nullability for AddContentApi.updateNoteFields()
Made the parameter type non null because this is an update call and using null would do no update so the call would be
useless(why do it?).
* Fix nullability for AddContentApi.addNewBasicModel()
Made the name non null, can the model have a null name?
* Fix nullability for AddContentApi.addNewBasic2Model()
Made name non null(can the model have null as name?)
* Fix nullability for AddContentApi.addNewCustomModel()
Made name non null (can the model have null as name?)
Also silenced a silly IDE reported issue.
* Fix nullability for AddContentApi.addNewDeck()
Made the name parameter as non null, does it make sense to have adeck with null for name?!
* Fix nullability for AddContentApi.findDuplicateNotes()
Made the keys parameter as List<String> from List<String?>. What duplicates to find for a null key?
* Remove todo about nullability in AddContentApi
This cleanup includes:
- fixing ide lint issues
- adding extra @JvmField annotations to replicate the initial static fields in java, the targets were Uris and the
projection arrays(without the annotations these would have ended in the final bytecode as private static field + getter
method)
- enabled the explicit api mode as this is a library project and I think would be a good addition going forward. I made
the violations as warnings for now( to be able to suppress them for the other api classes) and fixed them for
FlashCardContract. When we finish cleaning up the api module we should move from warning to strict.
See https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors
This included specifying the visibility modifiers and the actual properties types(nothing to note here as we have only
strings, not null Uris and not null arrays of not null strings)
- adding some @ Suppress annotations for naming(_ID) and properties not being used(but part of the default projection)
This PR also adds two return types in AddContentApi which I missed in the cleanup of that file.
This is required before enabling explicitApi() mode in the build file of the api module.
Also adds the @JvmStatic annotation for one of the methods to follow the original method signature.
The original todos pointed at using @JvmField but this is not applicable as there's no backing field to use.
Also the changes in this commit replicate the java api(visibility and appearance(they were functions)). See last commit
as java file in f39b7fa10f
We're no longer in Java, so only a few annotations are still necessary.
These are mostly test methods (`@Parameter/@Rule`),
This is a potentially flaky commit, hopefully the reduction in code causes a reduction in compile times
It did not modify the API project public classes
We're no longer in Java, so only a few annotations are still necessary.
These are mostly test methods (`@Parameters/@MethodSource`),
a few which are useful for mocks, and a small number which cause tests
to fail if they're removed for no reasonable reason
This is a potentially flaky commit, hopefully the reduction in
code causes a reduction in compile times
This was a mostly automated process, adding comments manually
if removing the annotation failed tests
It did not modify the API project public classes
com.ichi2.anki.api.AddContentApi
The conversion caused breaking changes WRT nullability of parameters
AND changing `fun` to `val`
This is NOT the final nullability which we desire, we perform the conversion
in a single commit to reduce the chance of bugs being introduced
Changes from a 'pure' conversion':
- addNotes:
- fieldsList: changed to List<Array<String>?>
- tagsList: changed to List<Set<String>?>?
- addNewCustomModel changed from auto conversion:
- fields: -> Array<String>
- cards -> Array<String>
- qfmt -> Array<String>
- afmt -> Array<String>
- splitFields(flds).length -> splitFields(flds).size
suppress lint for name shadowing:
- `var preferredName = preferredName`
add `!!`
- `val fname = File(returnUri!!.path).toString()`
- `val fname = File(returnUri!!.path!!).toString()`
remove `private`:
- `private get() = if (apiHostSpecVersion < 2) CompatV1() else CompatV2()`
- `get() = if (apiHostSpecVersion < 2) CompatV1() else CompatV2()`
remove imports:
- NoteInfo.Companion.buildFromCursor
- Utils.fieldChecksum
- Utils.joinFields
- Utils.joinTags
- Utils.splitFields
add imports: FlashCardsContract
- Card
- CardTemplate
- Deck
- Model
- Note
many spacing changes:
- sample: values.put(Note.TAGS, Utils.joinTags(tagsList[i]))
- moved back to a single line
Moved api docs from <pre> to ```
----
Converted with disabled git hooks + tested manually
com.ichi2.anki.api.ApiUtilsTest
Git hooks were disabled for this commit due to the extra commit for the
java -> kt rename
(irrelevant) Issue with conversion file was listed: 12209
added kotlin-test for null-safe: `assertNull` required for lint
com.ichi2.anki.api.ApiUtilsTest
Git hooks were disabled for this commit due to the extra commit for the
java -> kt rename
Tested manually
(irrelevant) Issue with conversion file was listed: 12209
This method do not take nullable value anymore. And it seems that even from
java's code, it can't be called with nullable value, since it's only called from
either literals or result of Cursor. I.e. strings that are not null by
assumption about the database.
This method do not take nullable value anymore. And it seems that even from
java's code, it can't be called with nullable value, since it's only called from
result of Cursor. I.e. strings that are not null by assumption about the database.
1. Extract JUnit version to a constant, so all 3 testImplementations uses the same version
2. Add JUnitPlatform use to `build.gradle`
3. Fix imports to `kotlin.test.junit5.JUnit5Asserter`
4. Fix `AbstractFlashcardViewerTest.getSignalFromUrlTest`
- It is currently the only parameterized test that uses jupiter-params. It wasn't being discovered before, so it haven't raised any exception.
- Now that it's discovered, it needed to be fixed