-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
Adding support for full method signatures in ForbiddenMethodCall #3505
Merged
BraisGabin
merged 1 commit into
detekt:master
from
DcortezMeleth:feature/ForbiddenMethodCall_full_method_signature
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
detekt-psi-utils/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/MethodSignatureSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.gitlab.arturbosch.detekt.rules | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
class MethodSignatureSpec : Spek({ | ||
describe("extractMethodNameAndParams") { | ||
listOf( | ||
TestCase( | ||
testDescription = "should return method name and null params list in case of simplifies signature", | ||
methodSignature = "java.time.LocalDate.now", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = null | ||
), | ||
TestCase( | ||
testDescription = "should return method name and empty params list for full signature parameterless method", | ||
methodSignature = "java.time.LocalDate.now()", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = emptyList() | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with single param", | ||
methodSignature = "java.time.LocalDate.now(java.time.Clock)", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = listOf("java.time.Clock") | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with multiple params", | ||
methodSignature = "java.time.LocalDate.of(kotlin.Int, kotlin.Int, kotlin.Int)", | ||
expectedMethodName = "java.time.LocalDate.of", | ||
expectedParams = listOf("kotlin.Int", "kotlin.Int", "kotlin.Int") | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with multiple params " + | ||
"where method name has spaces and special characters", | ||
methodSignature = "io.gitlab.arturbosch.detekt.SomeClass.`some , method`(kotlin.String)", | ||
expectedMethodName = "io.gitlab.arturbosch.detekt.SomeClass.some , method", | ||
expectedParams = listOf("kotlin.String") | ||
) | ||
).forEach { testCase -> | ||
it(testCase.testDescription) { | ||
val (methodName, params) = extractMethodNameAndParams(testCase.methodSignature) | ||
|
||
assertThat(methodName).isEqualTo(testCase.expectedMethodName) | ||
assertThat(params).isEqualTo(testCase.expectedParams) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private class TestCase( | ||
val testDescription: String, | ||
val methodSignature: String, | ||
val expectedMethodName: String, | ||
val expectedParams: List<String>? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily an issue for this PR, because
getJetTypeFqName
is used at several places. However, the package path looks very weird becausejs
appears.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned it is my first meeting with kotlin reflection and it was the solution I have found but if you have some idea how to achieve it with other method I will be happy to try that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can investigate further on why this is needed. I don't think this would block merging this PR