Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
0b57d8eb
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0b57d8eb
编写于
10月 28, 2016
作者:
S
shiraji
提交者:
Mikhail Glukhikh
10月 27, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use "Remove redundant '.let' call" when receiver is used #KT-14390 Fixed
上级
6a1b0b9c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
4 deletion
+76
-4
idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt
...s/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt
+13
-4
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver.kt
...entions/replaceSingleLineLetIntention/multipleReceiver.kt
+6
-0
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver2.kt
...ntions/replaceSingleLineLetIntention/multipleReceiver2.kt
+6
-0
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver3.kt
...ntions/replaceSingleLineLetIntention/multipleReceiver3.kt
+6
-0
idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda.kt
...tions/replaceSingleLineLetIntention/receiverWithLambda.kt
+6
-0
idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda2.kt
...ions/replaceSingleLineLetIntention/receiverWithLambda2.kt
+9
-0
idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
...brains/kotlin/idea/intentions/IntentionTestGenerated.java
+30
-0
未找到文件。
idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt
浏览文件 @
0b57d8eb
...
...
@@ -17,12 +17,10 @@
package
org.jetbrains.kotlin.idea.intentions
import
com.intellij.openapi.editor.Editor
import
org.jetbrains.kotlin.idea.caches.resolve.analyze
import
org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import
org.jetbrains.kotlin.lexer.KtTokens
import
org.jetbrains.kotlin.psi.*
import
org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import
org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import
org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
class
ReplaceSingleLineLetInspection
:
IntentionBasedInspection
<
KtCallExpression
>(
ReplaceSingleLineLetIntention
::
class
)
{
override
fun
inspectionTarget
(
element
:
KtCallExpression
)
=
element
.
calleeExpression
...
...
@@ -66,6 +64,9 @@ class ReplaceSingleLineLetIntention : SelfTargetingOffsetIndependentIntention<Kt
val
parameterName
=
lambdaExpression
.
getParameterName
()
?:
return
false
val
receiverExpression
=
dotQualifiedExpression
.
getLeftMostReceiverExpression
()
if
(
receiverExpression
.
text
!=
parameterName
)
return
false
dotQualifiedExpression
.
selectorExpression
?.
let
{
if
(
it
.
anyDescendantOfType
<
KtLambdaExpression
>())
return
false
}
return
!
dotQualifiedExpression
.
receiverUsedAsArgument
(
parameterName
)
}
...
...
@@ -79,7 +80,15 @@ class ReplaceSingleLineLetIntention : SelfTargetingOffsetIndependentIntention<Kt
}
private
fun
KtDotQualifiedExpression
.
receiverUsedAsArgument
(
receiverName
:
String
):
Boolean
{
if
((
selectorExpression
as
?
KtCallExpression
)
?.
valueArguments
?.
firstOrNull
{
it
.
text
==
receiverName
}
!=
null
)
return
true
(
selectorExpression
as
?
KtCallExpression
)
?.
valueArguments
?.
let
{
if
(
it
.
any
{
it
.
receiverUsedAsArgument
(
receiverName
)
})
return
true
}
return
(
receiverExpression
as
?
KtDotQualifiedExpression
)
?.
receiverUsedAsArgument
(
receiverName
)
?:
false
}
private
fun
KtValueArgument
.
receiverUsedAsArgument
(
receiverName
:
String
)
=
text
==
receiverName
||
anyDescendantOfType
<
KtDotQualifiedExpression
>
{
it
.
getLeftMostReceiverExpression
().
text
==
receiverName
||
it
.
receiverUsedAsArgument
(
receiverName
)
}
}
\ No newline at end of file
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver.kt
0 → 100644
浏览文件 @
0b57d8eb
// WITH_RUNTIME
// IS_APPLICABLE: false
fun
baz
(
foo
:
String
)
{
foo
.
let
<
caret
>
{
it
.
substringAfterLast
(
it
.
capitalize
())
}
}
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver2.kt
0 → 100644
浏览文件 @
0b57d8eb
// WITH_RUNTIME
// IS_APPLICABLE: false
fun
baz
(
foo
:
String
)
{
foo
.
let
<
caret
>
{
it
.
substringAfterLast
(
""
.
equals
(
it
).
toString
())
}
}
idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver3.kt
0 → 100644
浏览文件 @
0b57d8eb
// WITH_RUNTIME
// IS_APPLICABLE: false
fun
baz
(
foo
:
String
)
{
foo
.
let
<
caret
>
{
it
.
substring
(
0
,
it
.
length
)
}
}
idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda.kt
0 → 100644
浏览文件 @
0b57d8eb
// WITH_RUNTIME
// IS_APPLICABLE: false
fun
baz
(
foo
:
String
)
{
foo
.
let
<
caret
>
{
it
.
indexOfLast
{
c
->
c
==
it
[
0
]
}
}
}
\ No newline at end of file
idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda2.kt
0 → 100644
浏览文件 @
0b57d8eb
// WITH_RUNTIME
// IS_APPLICABLE: false
// This should be reported. However, in order to avoid too complecate logic, the intention ignore this case.
import
java.util.*
fun
baz2
(
foo
:
List
<
String
>)
{
foo
.
let
<
caret
>
{
it
.
binarySearch
(
""
,
Comparator
<
kotl
in
.
String
>
{
o1
,
o2
->
0
})
}
}
\ No newline at end of file
idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
浏览文件 @
0b57d8eb
...
...
@@ -11768,6 +11768,36 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("multipleReceiver.kt")
public void testMultipleReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver.kt");
doTest(fileName);
}
@TestMetadata("multipleReceiver2.kt")
public void testMultipleReceiver2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver2.kt");
doTest(fileName);
}
@TestMetadata("multipleReceiver3.kt")
public void testMultipleReceiver3() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/multipleReceiver3.kt");
doTest(fileName);
}
@TestMetadata("receiverWithLambda.kt")
public void testReceiverWithLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda.kt");
doTest(fileName);
}
@TestMetadata("receiverWithLambda2.kt")
public void testReceiverWithLambda2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda2.kt");
doTest(fileName);
}
@TestMetadata("sameLets.kt")
public void testSameLets() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/sameLets.kt");
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录