Create From Usage: Fix template insertion when target container is not empty
This commit is contained in:
+7
-2
@@ -61,6 +61,8 @@ import org.jetbrains.kotlin.util.printAndReturn
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
||||
import org.jetbrains.jet.plugin.intentions.declarations.DeclarationUtils
|
||||
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import com.intellij.psi.SmartPointerManager
|
||||
|
||||
private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList"
|
||||
private val TEMPLATE_FROM_USAGE_FUNCTION_BODY = "New Kotlin Function Body.kt"
|
||||
@@ -541,8 +543,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
fun buildAndRunTemplate() {
|
||||
val declaration = createDeclarationSkeleton()
|
||||
val project = declaration.getProject()
|
||||
val declarationSkeleton = createDeclarationSkeleton()
|
||||
val project = declarationSkeleton.getProject()
|
||||
val declarationPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(declarationSkeleton)
|
||||
|
||||
// build templates
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
@@ -551,6 +554,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
val caretModel = containingFileEditor.getCaretModel()
|
||||
caretModel.moveToOffset(containingFile.getNode().getStartOffset())
|
||||
|
||||
val declaration = declarationPointer.getElement()
|
||||
|
||||
val builder = TemplateBuilderImpl(containingFile)
|
||||
if (declaration is JetProperty) {
|
||||
setupValVarTemplate(builder, declaration)
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Create function 'foo' from usage" "true"
|
||||
class F {
|
||||
fun bar() {
|
||||
|
||||
}
|
||||
|
||||
fun foo(i: Int, s: String): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
class X {
|
||||
val f: Int = F().foo(1, "2")
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Create function 'foo' from usage" "true"
|
||||
class F {
|
||||
fun bar() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class X {
|
||||
val f: Int = F().<caret>foo(1, "2")
|
||||
}
|
||||
@@ -795,7 +795,13 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunOnUserType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
|
||||
@TestMetadata("beforeFunOnUserTypeWithDeclarations.kt")
|
||||
public void testFunOnUserTypeWithDeclarations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunOnUserTypeWithDeclarations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeFunOnUserTypeWithTypeParams.kt")
|
||||
public void testFunOnUserTypeWithTypeParams() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunOnUserTypeWithTypeParams.kt");
|
||||
|
||||
Reference in New Issue
Block a user