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 LanguageVersionSettings and DataFlowValueFactory to BaseRule #2929

Merged
merged 2 commits into from
Aug 9, 2020

Conversation

t-kameyama
Copy link
Contributor

We need to detect smart cast types in #2903.

In order to detect the smart cast types, LanguageVersionSettings and DataFlowValueFactory are required as follows:
https://github.com/JetBrains/kotlin/blob/040204e36e8d55395cdbbda2c8145dbb68bb0f00/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt#L116-L119

So we should add them to BaseRule like BindingContext.

@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #2929 into master will increase coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2929      +/-   ##
============================================
+ Coverage     80.23%   80.26%   +0.03%     
- Complexity     2449     2455       +6     
============================================
  Files           421      422       +1     
  Lines          7407     7414       +7     
  Branches       1354     1356       +2     
============================================
+ Hits           5943     5951       +8     
+ Misses          764      760       -4     
- Partials        700      703       +3     
Impacted Files Coverage Δ Complexity Δ
...rturbosch/detekt/api/internal/CompilerResources.kt 33.33% <33.33%> (ø) 1.00 <1.00> (?)
.../gitlab/arturbosch/detekt/api/internal/BaseRule.kt 93.75% <75.00%> (-6.25%) 6.00 <1.00> (ø)
...otlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt 67.85% <75.00%> (+1.81%) 7.00 <2.00> (ø)
...urbosch/detekt/rules/style/UselessCallOnNotNull.kt 76.47% <0.00%> (-4.30%) 13.00% <0.00%> (+5.00%) ⬇️
...gitlab/arturbosch/detekt/generator/out/Markdown.kt 18.18% <0.00%> (-2.51%) 4.00% <0.00%> (ø%)
...ls/src/main/kotlin/io/github/detekt/psi/KtFiles.kt 50.00% <0.00%> (+5.55%) 0.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d0d8c9...ec39fca. Read the comment docs.

@@ -23,9 +27,16 @@ abstract class BaseRule(
* receive the correct compile classpath for the code being analyzed otherwise the default value
* BindingContext.EMPTY will be used and it will not be possible for detekt to resolve types or symbols.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the documentation of the functions should be updated to comply with the new parameters and implementation.

Copy link
Member

Choose a reason for hiding this comment

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

lets better hide the information for now :)

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this change. Looks good! I have 2 minor remarks. Are there also tests available?

root: KtFile,
bindingContext: BindingContext = BindingContext.EMPTY,
languageVersionSettings: LanguageVersionSettings? = null,
dataFlowValueFactory: DataFlowValueFactory? = null
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should group the 3 objects concerning type and symbol solving into a new object. As a result the parameter list would be smaller.

Copy link
Member

Choose a reason for hiding this comment

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

Lets go with an object for the new two and leave the BindingContext extra so we do not need to update all rules?

Copy link
Contributor Author

@t-kameyama t-kameyama Aug 7, 2020

Choose a reason for hiding this comment

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

Introduced CompilerResources class.

@arturbosch
Copy link
Member

@t-kameyama thanks for the contribution and showing us a new way of writing more complex rules with smart casting.

I'm afraid to tell you that I have to decline this change. I really do not want to make our current rule api and design more complex. It is not the direction we want to go with the Rule and BaseRule classes. There are already things like the context, excludes and aliases which we regret to have added to it.

In #2680 we discuss further breaking api changes and list design improvements we want to make for 2.0.
Especially for the Rule api e.g. #2680 (comment) the information in this PR will be helpful and gonna make sure that the new Rule api will provide access to more constructs like the LanguageVersionSettings.

@schalkms
Copy link
Member

schalkms commented Aug 5, 2020

I don’t fully agree with declining this change.
The API could introduce a new object containing all objects required for writing more complex rules.

@BraisGabin
Copy link
Member

Or we can just allow extending the current rule api following its "spirit" and once we have the new api we can port it.

@arturbosch
Copy link
Member

arturbosch commented Aug 5, 2020

Hm, convinced.
I like @schalkms suggestion using an object containing additional useful analysis classes.
We should leave BindingContext as a property though to not update every other rule needing the BindingContext.

Edit: thanks for the discussion! Yep, exploring the compiler's possibilities is definately the way to go 👍

@arturbosch arturbosch reopened this Aug 5, 2020
@t-kameyama
Copy link
Contributor Author

Are there also tests available?

#2903 has tests that requires the detection of smart casting.

@t-kameyama t-kameyama force-pushed the detect_smart_cast_types branch 2 times, most recently from 84f8a17 to f07877d Compare August 7, 2020 12:18
Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Good! I previously meant tests that assert the changed functions?

val findingsPerFile: FindingsResult =
if (settings.spec.executionSpec.parallelAnalysis) {
runAsync(ktFiles, bindingContext)
runAsync(ktFiles, bindingContext, compilerResources)
Copy link
Member

Choose a reason for hiding this comment

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

Should bindingContext also be moved to compilerResources? @arturbosch

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes on the core side we definitely should do this. On the rule side I would like them to be separated as we rey heavily on the BindingContext.
Lets do this in another PR.

@arturbosch
Copy link
Member

I've restarted the CI and will merge it then.

@arturbosch arturbosch merged commit 7328075 into detekt:master Aug 9, 2020
@arturbosch arturbosch added this to the 1.11.0 milestone Aug 9, 2020
@t-kameyama t-kameyama deleted the detect_smart_cast_types branch August 9, 2020 10:22
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