Create From Usage: Quick-fix for value parameters
This commit is contained in:
@@ -186,6 +186,7 @@ map.platform.class.to.kotlin.family=Change to Kotlin class
|
|||||||
create.from.usage.family=Create from usage
|
create.from.usage.family=Create from usage
|
||||||
create.function.from.usage=Create function ''{0}'' from usage
|
create.function.from.usage=Create function ''{0}'' from usage
|
||||||
create.local.variable.from.usage=Create local variable ''{0}''
|
create.local.variable.from.usage=Create local variable ''{0}''
|
||||||
|
create.parameter.from.usage=Create parameter ''{0}''
|
||||||
choose.target.class.or.trait.title=Choose target class or trait
|
choose.target.class.or.trait.title=Choose target class or trait
|
||||||
surround.with=Surround with
|
surround.with=Surround with
|
||||||
surround.with.string.template="${expr}"
|
surround.with.string.template="${expr}"
|
||||||
|
|||||||
@@ -240,6 +240,8 @@ public class QuickFixRegistrar {
|
|||||||
|
|
||||||
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$);
|
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$);
|
||||||
|
|
||||||
|
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateParameterActionFactory.INSTANCE$);
|
||||||
|
|
||||||
QuickFixes.factories.put(FUNCTION_EXPECTED, CreateInvokeFunctionActionFactory.INSTANCE$);
|
QuickFixes.factories.put(FUNCTION_EXPECTED, CreateInvokeFunctionActionFactory.INSTANCE$);
|
||||||
|
|
||||||
QuickFixes.factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError());
|
QuickFixes.factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError());
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ private fun getTypeParameterNamesNotInScope(typeParameters: Collection<TypeParam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JetType.getTypeParameters(): Set<TypeParameterDescriptor> {
|
fun JetType.getTypeParameters(): Set<TypeParameterDescriptor> {
|
||||||
val typeParameters = LinkedHashSet<TypeParameterDescriptor>()
|
val typeParameters = LinkedHashSet<TypeParameterDescriptor>()
|
||||||
val arguments = getArguments()
|
val arguments = getArguments()
|
||||||
if (arguments.empty) {
|
if (arguments.empty) {
|
||||||
|
|||||||
+132
@@ -0,0 +1,132 @@
|
|||||||
|
package org.jetbrains.jet.plugin.quickfix.createFromUsage.createVariable
|
||||||
|
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.createFromUsage.CreateFromUsageFixBase
|
||||||
|
import org.jetbrains.jet.plugin.JetBundle
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.JetSingleIntentionActionFactory
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.QuickFixUtil
|
||||||
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClass
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.guessTypes
|
||||||
|
import org.jetbrains.jet.plugin.caches.resolve.getBindingContext
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.runChangeSignature
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeSignatureConfiguration
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeSignatureData
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunction
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassInitializer
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassBody
|
||||||
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
|
import org.jetbrains.jet.lang.psi.psiUtil.parents
|
||||||
|
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.getTypeParameters
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptorWithResolutionScopes
|
||||||
|
import java.util.LinkedHashSet
|
||||||
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetValVar
|
||||||
|
import org.jetbrains.jet.lang.psi.JetEnumEntry
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor
|
||||||
|
import org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||||
|
|
||||||
|
object CreateParameterActionFactory: JetSingleIntentionActionFactory() {
|
||||||
|
private fun JetType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, context: BindingContext): Boolean {
|
||||||
|
val typeParametersToAdd = LinkedHashSet(getTypeParameters())
|
||||||
|
typeParametersToAdd.removeAll(functionDescriptor.getTypeParameters())
|
||||||
|
if (typeParametersToAdd.isEmpty()) return false
|
||||||
|
|
||||||
|
val scope = when(functionDescriptor) {
|
||||||
|
is ConstructorDescriptor -> {
|
||||||
|
val classDescriptor = (functionDescriptor as? ConstructorDescriptor)?.getContainingDeclaration()
|
||||||
|
(classDescriptor as? ClassDescriptorWithResolutionScopes)?.getScopeForClassHeaderResolution()
|
||||||
|
}
|
||||||
|
|
||||||
|
is FunctionDescriptor -> {
|
||||||
|
val function = DescriptorToSourceUtils.descriptorToDeclaration(functionDescriptor) as? JetFunction
|
||||||
|
function?.let { context[BindingContext.RESOLUTION_SCOPE, it.getBodyExpression()] }
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
} ?: return true
|
||||||
|
|
||||||
|
return typeParametersToAdd.any { scope.getClassifier(it.getName()) != it }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
|
val context = (diagnostic.getPsiFile() as? JetFile)?.getBindingContext() ?: return null
|
||||||
|
|
||||||
|
val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetSimpleNameExpression>()) ?: return null
|
||||||
|
if (refExpr.getQualifiedElement() != refExpr) return null
|
||||||
|
|
||||||
|
val paramType = refExpr.guessTypes(context).let {
|
||||||
|
when (it.size) {
|
||||||
|
0 -> KotlinBuiltIns.getInstance().getAnyType()
|
||||||
|
1 -> it.first()
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val parameterInfo = JetParameterInfo(refExpr.getReferencedName(), paramType)
|
||||||
|
|
||||||
|
fun chooseContainingClass(it: PsiElement): JetClass? {
|
||||||
|
parameterInfo.setValOrVar(JetValVar.Val)
|
||||||
|
return it.parents(false).filterIsInstance(javaClass<JetClassOrObject>()).firstOrNull() as? JetClass
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: skip lambdas for now because Change Signature doesn't apply to them yet
|
||||||
|
val container = refExpr.parents(false)
|
||||||
|
.filter { it is JetNamedFunction || it is JetPropertyAccessor || it is JetClassBody || it is JetClassInitializer }
|
||||||
|
.firstOrNull()
|
||||||
|
?.let {
|
||||||
|
when (it) {
|
||||||
|
is JetPropertyAccessor -> chooseContainingClass(it)
|
||||||
|
is JetClassInitializer ->
|
||||||
|
it.getParent()?.getParent() as? JetClass
|
||||||
|
is JetClassBody -> {
|
||||||
|
val klass = it.getParent() as? JetClass
|
||||||
|
when {
|
||||||
|
klass is JetEnumEntry -> chooseContainingClass(klass)
|
||||||
|
klass != null && klass.isTrait() -> null
|
||||||
|
else -> klass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> it
|
||||||
|
}
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
|
val functionDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, container]?.let {
|
||||||
|
if (it is ClassDescriptor) it.getUnsubstitutedPrimaryConstructor() else it
|
||||||
|
} as? FunctionDescriptor ?: return null
|
||||||
|
|
||||||
|
if (paramType.hasTypeParametersToAdd(functionDescriptor, context)) return null
|
||||||
|
|
||||||
|
return object: CreateFromUsageFixBase(refExpr) {
|
||||||
|
override fun getText(): String {
|
||||||
|
return JetBundle.message("create.parameter.from.usage", refExpr.getReferencedName())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun invoke(project: Project, editor: Editor?, file: JetFile?) {
|
||||||
|
val config = object : JetChangeSignatureConfiguration {
|
||||||
|
override fun configure(changeSignatureData: JetChangeSignatureData, bindingContext: BindingContext) {
|
||||||
|
changeSignatureData.addParameter(parameterInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun performSilently(affectedFunctions: Collection<PsiElement>): Boolean = false
|
||||||
|
}
|
||||||
|
|
||||||
|
runChangeSignature(project, functionDescriptor, config, context, refExpr, getText())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
||||||
// ACTION: Create local variable 'PrivateClass'
|
// ACTION: Create local variable 'PrivateClass'
|
||||||
|
// ACTION: Create parameter 'PrivateClass'
|
||||||
// ERROR: Unresolved reference: PrivateClass
|
// ERROR: Unresolved reference: PrivateClass
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Create local variable 'foo'" "false"
|
// "Create local variable 'foo'" "false"
|
||||||
|
// ACTION: Create parameter 'foo'
|
||||||
// ERROR: Unresolved reference: foo
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A(val foo: Int) {
|
||||||
|
val test: Int get() {
|
||||||
|
return foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T>(val foo: T) {
|
||||||
|
val test: T get() {
|
||||||
|
return foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A(val foo: Int) {
|
||||||
|
val test: Int get() = foo
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A(foo: Int) {
|
||||||
|
{
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: T) {
|
||||||
|
val t: T = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun test<T>(n: Int,
|
||||||
|
foo: T) {
|
||||||
|
val t: T = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
fun test<T>(n: Int,
|
||||||
|
foo: T) {
|
||||||
|
val t: T = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val f: () -> Int = { foo }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val f: (Int) -> Int = { foo }
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val f: (Int, Int) -> Int = { (a, b) -> foo }
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Any) {
|
||||||
|
val f = { (a: Int, b: Int) -> foo }
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val f: () -> Int = {
|
||||||
|
foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A(foo: Int) {
|
||||||
|
val test: Int = <caret>foo
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
|
||||||
|
enum class E(foo: Int) {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
|
||||||
|
enum class E(val foo: Int) {
|
||||||
|
A
|
||||||
|
B {
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
|
C
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T>(foo: T) {
|
||||||
|
val test: T = foo
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class B(foo: Int) {
|
||||||
|
val test: Int = foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val test: Int get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object {
|
||||||
|
val test: Int get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
val test: T get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
object A {
|
||||||
|
val test: Int get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
trait A {
|
||||||
|
val test: Int get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
val test: Int get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val test: Int get() = <caret>foo
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
{
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ACTION: Split property declaration
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object {
|
||||||
|
{
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun test(n: Int) {
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
fun test(n: Int) {
|
||||||
|
val t: T = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val <T> test: T get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Convert to expression body
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
val <T> test: T get() {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun test<T>(n: Int) {
|
||||||
|
val t: T = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
fun test<T>(n: Int) {
|
||||||
|
val t: T = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val <T> test: T = <caret>foo
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
val <T> test: T = <caret>foo
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val f: () -> Int = { <caret>foo }
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val f: (Int) -> Int = { <caret>foo }
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val f: (Int, Int) -> Int = { (a, b) -> <caret>foo }
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val f = { (a: Int, b: Int) -> <caret>foo }
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ACTION: Create local variable 'foo'
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val f: () -> Int = {
|
||||||
|
<caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val test: Int = <caret>foo
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object {
|
||||||
|
val test: Int = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
|
||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
// ERROR: Missing delegation specifier 'E'
|
||||||
|
|
||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B {
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
|
C
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
val test: T = <caret>foo
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class B {
|
||||||
|
val test: Int = <caret>foo
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
object A {
|
||||||
|
val test: Int = <caret>foo
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
val test: Int = <caret>foo
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Create parameter 'foo'" "false"
|
||||||
|
// ACTION: Split property declaration
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A) {
|
||||||
|
val t: Int = a.<caret>foo
|
||||||
|
}
|
||||||
@@ -1164,7 +1164,7 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/createFromUsage/createVariable")
|
@TestMetadata("idea/testData/quickfix/createFromUsage/createVariable")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({CreateVariable.LocalVariable.class})
|
@InnerTestClasses({CreateVariable.LocalVariable.class, CreateVariable.Parameter.class})
|
||||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
public static class CreateVariable extends AbstractQuickFixTest {
|
public static class CreateVariable extends AbstractQuickFixTest {
|
||||||
public void testAllFilesPresentInCreateVariable() throws Exception {
|
public void testAllFilesPresentInCreateVariable() throws Exception {
|
||||||
@@ -1229,6 +1229,208 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
|
public static class Parameter extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInParameter() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createVariable/parameter"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorInClass.kt")
|
||||||
|
public void testInAccessorInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorInClassObject.kt")
|
||||||
|
public void testInAccessorInClassObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClassObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorInGenClass.kt")
|
||||||
|
public void testInAccessorInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorInObject.kt")
|
||||||
|
public void testInAccessorInObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorInTrait.kt")
|
||||||
|
public void testInAccessorInTrait() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInTrait.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorNoClass.kt")
|
||||||
|
public void testInAccessorNoClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorNoClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInAccessorWithExpressionBodyInClass.kt")
|
||||||
|
public void testInAccessorWithExpressionBodyInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorWithExpressionBodyInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInClassInitializer.kt")
|
||||||
|
public void testInClassInitializer() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassInitializer.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInClassObjectInitializer.kt")
|
||||||
|
public void testInClassObjectInitializer() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassObjectInitializer.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInFun.kt")
|
||||||
|
public void testInFun() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInFun.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInFunInClass.kt")
|
||||||
|
public void testInFunInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInFunInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInFunInGenClass.kt")
|
||||||
|
public void testInFunInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInFunInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenAccessorInClass.kt")
|
||||||
|
public void testInGenAccessorInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenAccessorInGenClass.kt")
|
||||||
|
public void testInGenAccessorInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenFunInClass.kt")
|
||||||
|
public void testInGenFunInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenFunInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenFunInGenClass.kt")
|
||||||
|
public void testInGenFunInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenFunInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenPropertyInitializerInClass.kt")
|
||||||
|
public void testInGenPropertyInitializerInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInGenPropertyInitializerInGenClass.kt")
|
||||||
|
public void testInGenPropertyInitializerInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInLambdaNoParams.kt")
|
||||||
|
public void testInLambdaNoParams() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInLambdaNoParams.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInLambdaWithIt.kt")
|
||||||
|
public void testInLambdaWithIt() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInLambdaWithIt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInLambdaWithParams.kt")
|
||||||
|
public void testInLambdaWithParams() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInLambdaWithParams.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInLambdaWithTypedParams.kt")
|
||||||
|
public void testInLambdaWithTypedParams() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInLambdaWithTypedParams.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInMultiLineLambdaNoParams.kt")
|
||||||
|
public void testInMultiLineLambdaNoParams() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInMultiLineLambdaNoParams.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInClass.kt")
|
||||||
|
public void testInPropertyInitializerInClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInClassObject.kt")
|
||||||
|
public void testInPropertyInitializerInClassObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClassObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInEnumClass.kt")
|
||||||
|
public void testInPropertyInitializerInEnumClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInEnumClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInEnumEntry.kt")
|
||||||
|
public void testInPropertyInitializerInEnumEntry() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInEnumEntry.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInGenClass.kt")
|
||||||
|
public void testInPropertyInitializerInGenClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInGenClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInNestedClass.kt")
|
||||||
|
public void testInPropertyInitializerInNestedClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInNestedClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerInObject.kt")
|
||||||
|
public void testInPropertyInitializerInObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeInPropertyInitializerNoClass.kt")
|
||||||
|
public void testInPropertyInitializerNoClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerNoClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeQualifiedInFun.kt")
|
||||||
|
public void testQualifiedInFun() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeQualifiedInFun.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user