Add quickfix for adding 'inline' to a function with reified generic #KT-6975 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6cf90cfc4e
commit
3e58283d7e
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
|
||||||
|
class AddInlineToFunctionWithReifiedFix(function: KtNamedFunction) : AddModifierFix(function, KtTokens.INLINE_KEYWORD) {
|
||||||
|
companion object Factory : KotlinSingleIntentionActionFactory() {
|
||||||
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
|
val element = Errors.REIFIED_TYPE_PARAMETER_NO_INLINE.cast(diagnostic)
|
||||||
|
val function = element.psiElement.getStrictParentOfType<KtNamedFunction>() ?: return null
|
||||||
|
return AddInlineToFunctionWithReifiedFix(function)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -401,5 +401,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
UNUSED_LAMBDA_EXPRESSION.registerFactory(AddRunToLambdaFix)
|
UNUSED_LAMBDA_EXPRESSION.registerFactory(AddRunToLambdaFix)
|
||||||
|
|
||||||
WRONG_LONG_SUFFIX.registerFactory(WrongLongSuffixFix)
|
WRONG_LONG_SUFFIX.registerFactory(WrongLongSuffixFix)
|
||||||
|
|
||||||
|
REIFIED_TYPE_PARAMETER_NO_INLINE.registerFactory(AddInlineToFunctionWithReifiedFix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// "Add 'inline' modifier" "true"
|
||||||
|
|
||||||
|
fun <<caret>reified T> fn() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// "Add 'inline' modifier" "true"
|
||||||
|
|
||||||
|
inline fun <reified T> fn() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -383,6 +383,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/addInlineToReifiedFunctionFix")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class AddInlineToReifiedFunctionFix extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInAddInlineToReifiedFunctionFix() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/addInlineToReifiedFunctionFix"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("basic.kt")
|
||||||
|
public void testBasic() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addInlineToReifiedFunctionFix/basic.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/addNoinline")
|
@TestMetadata("idea/testData/quickfix/addNoinline")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user