Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✚ Add type safety to dependencies.implementation() #237

Merged
merged 4 commits into from
Aug 31, 2020

Conversation

jmfayard
Copy link
Member

@jmfayard jmfayard commented Aug 29, 2020

This is a follow up on #229

It focuses on typesafety only

There is an elegant Kotlin solution for every problem.

The IDE now imports two version of implementation.

fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? =
    add("implementation", dependencyNotation)

@kotlin.Deprecated(ErrorIsNotADependency)
fun DependencyHandler.`implementation`(dependencyNotation: IsNotADependency): Dependency? =
    null

Since the second one is more specific, it takes precedence when the parameter is IsNotADependency or in practice DependencyNotationAndGroup

This way the IDE shows you that made a mistake

GraySky____IdeaProjects_gray-sky-weather__-_build_gradle_kts___app_

This is a follow up on #229

It focuses on typesafety only

There is an elegant Kotlin solution for every problem.

Since implentation is defined like this

```
fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? =
    add("implementation", dependencyNotation)
```

Then we can overwrite this function for when the parameter is IsNotADependency or DependencyNotationAndGroup

This way the IDE shows you that made a mistake
@jmfayard jmfayard requested a review from LouisCAD August 29, 2020 21:07
@jmfayard jmfayard changed the title ✚ Add typesafety to dependencies.implementation() ✚ Add type safety to dependencies.implementation() Aug 29, 2020
@jmfayard jmfayard requested a review from LouisCAD August 31, 2020 08:48
@LouisCAD
Copy link
Member

Something that would be cool it to have a test to ensure we don't forget to extend either IsNotADependency or DependencyNotationAndGroup for dependency objects. We can do it in another PR though.

@jmfayard jmfayard merged commit ae21caa into develop Aug 31, 2020
@LouisCAD LouisCAD deleted the 229-typesafe-implementation branch August 31, 2020 15:07
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.

None yet

2 participants