Create from usage (function/property): Suggest separate actions for extensions and non-extension declarations
#KT-6023 Fixed
This commit is contained in:
+2
-2
@@ -24,12 +24,12 @@ import java.util.Collections
|
|||||||
// TODO: Replace with trait when all subclasses are translated to Kotlin
|
// TODO: Replace with trait when all subclasses are translated to Kotlin
|
||||||
public abstract class JetIntentionActionsFactory {
|
public abstract class JetIntentionActionsFactory {
|
||||||
protected open fun isApplicableForCodeFragment(): Boolean = false
|
protected open fun isApplicableForCodeFragment(): Boolean = false
|
||||||
protected abstract fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>
|
protected abstract fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>?
|
||||||
|
|
||||||
public fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
public fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||||
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||||
return Collections.emptyList()
|
return Collections.emptyList()
|
||||||
}
|
}
|
||||||
return doCreateActions(diagnostic)
|
return doCreateActions(diagnostic) ?: Collections.emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-21
@@ -68,10 +68,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||||
import org.jetbrains.kotlin.idea.util.isUnit
|
import org.jetbrains.kotlin.idea.util.isUnit
|
||||||
import com.intellij.openapi.editor.ScrollType
|
import com.intellij.openapi.editor.ScrollType
|
||||||
import com.intellij.openapi.editor.LogicalPosition
|
|
||||||
import com.intellij.openapi.editor.actions.EditorActionUtil
|
|
||||||
import com.intellij.openapi.editor.actions.LineEndAction
|
|
||||||
import com.intellij.openapi.editor.actions.EnterAction
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
|
|
||||||
private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList"
|
private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList"
|
||||||
@@ -122,19 +118,11 @@ class CallableBuilderConfiguration(
|
|||||||
val callableInfos: List<CallableInfo>,
|
val callableInfos: List<CallableInfo>,
|
||||||
val originalElement: JetElement,
|
val originalElement: JetElement,
|
||||||
val currentFile: JetFile,
|
val currentFile: JetFile,
|
||||||
val currentEditor: Editor,
|
val currentEditor: Editor?,
|
||||||
|
val isExtension: Boolean = false,
|
||||||
val enableSubstitutions: Boolean = true
|
val enableSubstitutions: Boolean = true
|
||||||
)
|
)
|
||||||
|
|
||||||
fun CallableBuilderConfiguration(
|
|
||||||
callableInfo: CallableInfo,
|
|
||||||
originalExpression: JetExpression,
|
|
||||||
currentFile: JetFile,
|
|
||||||
currentEditor: Editor
|
|
||||||
): CallableBuilderConfiguration {
|
|
||||||
return CallableBuilderConfiguration(Collections.singletonList(callableInfo), originalExpression, currentFile, currentEditor)
|
|
||||||
}
|
|
||||||
|
|
||||||
trait CallablePlacement {
|
trait CallablePlacement {
|
||||||
class WithReceiver(val receiverTypeCandidate: TypeCandidate): CallablePlacement
|
class WithReceiver(val receiverTypeCandidate: TypeCandidate): CallablePlacement
|
||||||
class NoReceiver(val containingElement: JetElement): CallablePlacement
|
class NoReceiver(val containingElement: JetElement): CallablePlacement
|
||||||
@@ -207,6 +195,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
|
|
||||||
fun build() {
|
fun build() {
|
||||||
try {
|
try {
|
||||||
|
assert (config.currentEditor != null, "Can't run build() without editor")
|
||||||
if (finished) throw IllegalStateException("Current builder has already finished")
|
if (finished) throw IllegalStateException("Current builder has already finished")
|
||||||
buildNext(config.callableInfos.iterator())
|
buildNext(config.callableInfos.iterator())
|
||||||
}
|
}
|
||||||
@@ -217,7 +206,6 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
|
|
||||||
private inner class Context(val callableInfo: CallableInfo) {
|
private inner class Context(val callableInfo: CallableInfo) {
|
||||||
val skipReturnType: Boolean
|
val skipReturnType: Boolean
|
||||||
val isExtension: Boolean
|
|
||||||
val containingFile: JetFile
|
val containingFile: JetFile
|
||||||
val containingFileEditor: Editor
|
val containingFileEditor: Editor
|
||||||
val containingElement: JetElement
|
val containingElement: JetElement
|
||||||
@@ -233,7 +221,6 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
val placement = placement
|
val placement = placement
|
||||||
when {
|
when {
|
||||||
placement is CallablePlacement.NoReceiver -> {
|
placement is CallablePlacement.NoReceiver -> {
|
||||||
isExtension = false
|
|
||||||
containingElement = placement.containingElement
|
containingElement = placement.containingElement
|
||||||
receiverClassDescriptor = (containingElement as? JetClassOrObject)?.let { currentFileContext[BindingContext.CLASS, it] }
|
receiverClassDescriptor = (containingElement as? JetClassOrObject)?.let { currentFileContext[BindingContext.CLASS, it] }
|
||||||
}
|
}
|
||||||
@@ -241,8 +228,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
receiverClassDescriptor =
|
receiverClassDescriptor =
|
||||||
placement.receiverTypeCandidate.theType.getConstructor().getDeclarationDescriptor() as? ClassDescriptor
|
placement.receiverTypeCandidate.theType.getConstructor().getDeclarationDescriptor() as? ClassDescriptor
|
||||||
val classDeclaration = receiverClassDescriptor?.let { DescriptorToSourceUtils.classDescriptorToDeclaration(it) }
|
val classDeclaration = receiverClassDescriptor?.let { DescriptorToSourceUtils.classDescriptorToDeclaration(it) }
|
||||||
isExtension = !(classDeclaration is JetClassOrObject && classDeclaration.isWritable())
|
containingElement = if (config.isExtension) config.currentFile else classDeclaration as JetElement
|
||||||
containingElement = if (isExtension) config.currentFile else classDeclaration as JetElement
|
|
||||||
}
|
}
|
||||||
else -> throw IllegalArgumentException("Unexpected placement: $placement")
|
else -> throw IllegalArgumentException("Unexpected placement: $placement")
|
||||||
}
|
}
|
||||||
@@ -254,10 +240,10 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
containingFileEditor = FileEditorManager.getInstance(config.currentFile.getProject())!!.getSelectedTextEditor()!!
|
containingFileEditor = FileEditorManager.getInstance(config.currentFile.getProject())!!.getSelectedTextEditor()!!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
containingFileEditor = config.currentEditor
|
containingFileEditor = config.currentEditor!!
|
||||||
}
|
}
|
||||||
|
|
||||||
val scope = if (isExtension || receiverClassDescriptor == null) {
|
val scope = if (config.isExtension || receiverClassDescriptor == null) {
|
||||||
currentFileModule.getPackage(config.currentFile.getPackageFqName())!!.getMemberScope()
|
currentFileModule.getPackage(config.currentFile.getPackageFqName())!!.getMemberScope()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -531,7 +517,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
private fun setupTypeReferencesForShortening(declaration: JetNamedDeclaration,
|
private fun setupTypeReferencesForShortening(declaration: JetNamedDeclaration,
|
||||||
typeRefsToShorten: MutableList<JetElement>,
|
typeRefsToShorten: MutableList<JetElement>,
|
||||||
parameterTypeExpressions: List<TypeExpression>) {
|
parameterTypeExpressions: List<TypeExpression>) {
|
||||||
if (isExtension) {
|
if (config.isExtension) {
|
||||||
val receiverTypeRef = JetPsiFactory(declaration).createType(receiverTypeCandidate!!.theType.renderLong(typeParameterNameMap))
|
val receiverTypeRef = JetPsiFactory(declaration).createType(receiverTypeCandidate!!.theType.renderLong(typeParameterNameMap))
|
||||||
replaceWithLongerName(receiverTypeRef, receiverTypeCandidate.theType)
|
replaceWithLongerName(receiverTypeRef, receiverTypeCandidate.theType)
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||||
@@ -27,9 +26,10 @@ import java.util.Collections
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
public object CreateBinaryOperationActionFactory: JetSingleIntentionActionFactory() {
|
public object CreateBinaryOperationActionFactory: JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val callExpr = diagnostic.getPsiElement().getParent() as? JetBinaryExpression ?: return null
|
val callExpr = diagnostic.getPsiElement().getParent() as? JetBinaryExpression ?: return null
|
||||||
val token = callExpr.getOperationToken() as JetToken
|
val token = callExpr.getOperationToken() as JetToken
|
||||||
val operationName = when (token) {
|
val operationName = when (token) {
|
||||||
@@ -54,6 +54,6 @@ public object CreateBinaryOperationActionFactory: JetSingleIntentionActionFactor
|
|||||||
else -> TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
else -> TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
||||||
}
|
}
|
||||||
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
|
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
|
||||||
return CreateCallableFromUsageFix(callExpr, FunctionInfo(operationName, receiverType, returnType, Collections.emptyList(), parameters))
|
return CreateCallableFromUsageFixes(callExpr, FunctionInfo(operationName, receiverType, returnType, Collections.emptyList(), parameters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-12
@@ -28,16 +28,21 @@ import org.jetbrains.kotlin.idea.refactoring.chooseContainerElementIfNecessary
|
|||||||
import org.jetbrains.kotlin.psi.JetClassBody
|
import org.jetbrains.kotlin.psi.JetClassBody
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import org.jetbrains.kotlin.psi.JetElement
|
import org.jetbrains.kotlin.psi.JetElement
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
|
import java.util.Collections
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.canRefactor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
|
||||||
public class CreateCallableFromUsageFix(
|
public class CreateCallableFromUsageFix(
|
||||||
originalExpression: JetExpression,
|
originalExpression: JetExpression,
|
||||||
val callableInfos: List<CallableInfo>) : CreateFromUsageFixBase(originalExpression) {
|
val callableInfos: List<CallableInfo>,
|
||||||
|
val isExtension: Boolean
|
||||||
|
) : CreateFromUsageFixBase(originalExpression) {
|
||||||
{
|
{
|
||||||
|
assert (callableInfos.isNotEmpty(), "No CallableInfos: ${JetPsiUtil.getElementTextWithContext(originalExpression)}")
|
||||||
if (callableInfos.size > 1) {
|
if (callableInfos.size > 1) {
|
||||||
val receiverSet = callableInfos.mapTo(HashSet<TypeInfo>()) { it.receiverTypeInfo }
|
val receiverSet = callableInfos.mapTo(HashSet<TypeInfo>()) { it.receiverTypeInfo }
|
||||||
if (receiverSet.size > 1) throw AssertionError("All functions must have common receiver: $receiverSet")
|
if (receiverSet.size > 1) throw AssertionError("All functions must have common receiver: $receiverSet")
|
||||||
@@ -47,6 +52,13 @@ public class CreateCallableFromUsageFix(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDeclarationIfApplicable(project: Project, candidate: TypeCandidate): PsiElement? {
|
||||||
|
val descriptor = candidate.theType.getConstructor().getDeclarationDescriptor()
|
||||||
|
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor) ?: return null
|
||||||
|
if (declaration !is JetClassOrObject && declaration !is PsiClass) return null
|
||||||
|
return if (isExtension || declaration.canRefactor()) declaration else null
|
||||||
|
}
|
||||||
|
|
||||||
override fun getText(): String {
|
override fun getText(): String {
|
||||||
val renderedCallables = callableInfos.map {
|
val renderedCallables = callableInfos.map {
|
||||||
val kind = when (it.kind) {
|
val kind = when (it.kind) {
|
||||||
@@ -56,14 +68,31 @@ public class CreateCallableFromUsageFix(
|
|||||||
}
|
}
|
||||||
"$kind '${it.name}'"
|
"$kind '${it.name}'"
|
||||||
}
|
}
|
||||||
|
return JetBundle.message(
|
||||||
|
"create.0.from.usage",
|
||||||
|
renderedCallables.joinToString(prefix = if (isExtension) "extension " else "")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return JetBundle.message("create.0.from.usage", renderedCallables.joinToString())
|
fun isAvailable(): Boolean {
|
||||||
|
val callableInfo = callableInfos.first()
|
||||||
|
val receiverInfo = callableInfo.receiverTypeInfo
|
||||||
|
|
||||||
|
if (receiverInfo is TypeInfo.Empty) return !isExtension
|
||||||
|
|
||||||
|
val file = element.getContainingFile() as JetFile
|
||||||
|
val project = file.getProject()
|
||||||
|
val callableBuilder =
|
||||||
|
CallableBuilderConfiguration(callableInfos, element as JetExpression, file, null, isExtension).createBuilder()
|
||||||
|
val receiverTypeCandidates = callableBuilder.computeTypeCandidates(callableInfo.receiverTypeInfo)
|
||||||
|
return receiverTypeCandidates.any { getDeclarationIfApplicable(project, it) != null }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: JetFile?) {
|
override fun invoke(project: Project, editor: Editor?, file: JetFile?) {
|
||||||
val callableInfo = callableInfos.first()
|
val callableInfo = callableInfos.first()
|
||||||
|
|
||||||
val callableBuilder = CallableBuilderConfiguration(callableInfos, element as JetExpression, file!!, editor!!).createBuilder()
|
val callableBuilder =
|
||||||
|
CallableBuilderConfiguration(callableInfos, element as JetExpression, file!!, editor!!, isExtension).createBuilder()
|
||||||
|
|
||||||
fun runBuilder(placement: CallablePlacement) {
|
fun runBuilder(placement: CallablePlacement) {
|
||||||
callableBuilder.placement = placement
|
callableBuilder.placement = placement
|
||||||
@@ -74,11 +103,7 @@ public class CreateCallableFromUsageFix(
|
|||||||
val receiverTypeCandidates = callableBuilder.computeTypeCandidates(callableInfo.receiverTypeInfo)
|
val receiverTypeCandidates = callableBuilder.computeTypeCandidates(callableInfo.receiverTypeInfo)
|
||||||
if (receiverTypeCandidates.isNotEmpty()) {
|
if (receiverTypeCandidates.isNotEmpty()) {
|
||||||
val containers = receiverTypeCandidates
|
val containers = receiverTypeCandidates
|
||||||
.map { candidate ->
|
.map { candidate -> getDeclarationIfApplicable(project, candidate)?.let { candidate to it } }
|
||||||
val descriptor = candidate.theType.getConstructor().getDeclarationDescriptor()
|
|
||||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor)
|
|
||||||
if (declaration is JetClassOrObject || declaration is PsiClass) candidate to declaration else null
|
|
||||||
}
|
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
|
|
||||||
chooseContainerElementIfNecessary(containers, editor, popupTitle, false, { it.second }) {
|
chooseContainerElementIfNecessary(containers, editor, popupTitle, false, { it.second }) {
|
||||||
@@ -96,9 +121,19 @@ public class CreateCallableFromUsageFix(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun CreateCallableFromUsageFix(
|
public fun CreateCallableFromUsageFixes(
|
||||||
|
originalExpression: JetExpression,
|
||||||
|
callableInfos: List<CallableInfo>
|
||||||
|
) : List<CreateCallableFromUsageFix> {
|
||||||
|
return listOf(
|
||||||
|
CreateCallableFromUsageFix(originalExpression, callableInfos, false),
|
||||||
|
CreateCallableFromUsageFix(originalExpression, callableInfos, true)
|
||||||
|
).filter { it.isAvailable() }
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun CreateCallableFromUsageFixes(
|
||||||
originalExpression: JetExpression,
|
originalExpression: JetExpression,
|
||||||
callableInfo: CallableInfo
|
callableInfo: CallableInfo
|
||||||
) : CreateCallableFromUsageFix {
|
) : List<CreateCallableFromUsageFix> {
|
||||||
return CreateCallableFromUsageFix(originalExpression, callableInfo.singletonOrEmptyList())
|
return CreateCallableFromUsageFixes(originalExpression, Collections.singletonList(callableInfo))
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.resolve.dataClassUtils.*
|
import org.jetbrains.kotlin.resolve.dataClassUtils.*
|
||||||
@@ -26,9 +25,10 @@ import org.jetbrains.kotlin.psi.JetMultiDeclaration
|
|||||||
import org.jetbrains.kotlin.psi.JetForExpression
|
import org.jetbrains.kotlin.psi.JetForExpression
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateComponentFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateComponentFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic)
|
val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic)
|
||||||
val name = diagnosticWithParameters.getA()
|
val name = diagnosticWithParameters.getA()
|
||||||
if (!isComponentLike(name)) return null
|
if (!isComponentLike(name)) return null
|
||||||
@@ -50,6 +50,6 @@ object CreateComponentFunctionActionFactory : JetSingleIntentionActionFactory()
|
|||||||
val entry = entries[componentNumber]
|
val entry = entries[componentNumber]
|
||||||
val returnType = TypeInfo(entry, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(entry, Variance.OUT_VARIANCE)
|
||||||
|
|
||||||
return CreateCallableFromUsageFix(multiDeclaration!!, FunctionInfo(name.getIdentifier(), ownerType, returnType))
|
return CreateCallableFromUsageFixes(multiDeclaration!!, FunctionInfo(name.getIdentifier(), ownerType, returnType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||||
@@ -42,9 +41,10 @@ import org.jetbrains.kotlin.psi.JetTypeReference
|
|||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.psi.JetAnnotationEntry
|
import org.jetbrains.kotlin.psi.JetAnnotationEntry
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() {
|
object CreateFunctionOrPropertyFromCallActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val diagElement = diagnostic.getPsiElement()
|
val diagElement = diagnostic.getPsiElement()
|
||||||
if (PsiTreeUtil.getParentOfType(diagElement, javaClass<JetTypeReference>(), javaClass<JetAnnotationEntry>()) != null) return null
|
if (PsiTreeUtil.getParentOfType(diagElement, javaClass<JetTypeReference>(), javaClass<JetAnnotationEntry>()) != null) return null
|
||||||
|
|
||||||
@@ -119,6 +119,6 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionF
|
|||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateCallableFromUsageFix(callExpr, callableInfo)
|
return CreateCallableFromUsageFixes(callExpr, callableInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
||||||
@@ -24,9 +23,10 @@ import org.jetbrains.kotlin.psi.JetArrayAccessExpression
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateGetFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateGetFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetArrayAccessExpression>()) ?: return null
|
val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetArrayAccessExpression>()) ?: return null
|
||||||
val arrayExpr = accessExpr.getArrayExpression() ?: return null
|
val arrayExpr = accessExpr.getArrayExpression() ?: return null
|
||||||
val arrayType = TypeInfo(arrayExpr, Variance.IN_VARIANCE)
|
val arrayType = TypeInfo(arrayExpr, Variance.IN_VARIANCE)
|
||||||
@@ -36,6 +36,6 @@ object CreateGetFunctionActionFactory : JetSingleIntentionActionFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val returnType = TypeInfo(accessExpr, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(accessExpr, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(accessExpr, FunctionInfo("get", arrayType, returnType, Collections.emptyList(), parameters))
|
return CreateCallableFromUsageFixes(accessExpr, FunctionInfo("get", arrayType, returnType, Collections.emptyList(), parameters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
||||||
@@ -26,14 +25,15 @@ import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
|||||||
import org.jetbrains.kotlin.psi.JetForExpression
|
import org.jetbrains.kotlin.psi.JetForExpression
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateHasNextFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateHasNextFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
|
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
|
||||||
val ownerType = TypeInfo(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
|
val ownerType = TypeInfo(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
|
||||||
|
|
||||||
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
||||||
val returnType = TypeInfo(KotlinBuiltIns.getInstance().getBooleanType(), Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(KotlinBuiltIns.getInstance().getBooleanType(), Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(forExpr, FunctionInfo("hasNext", ownerType, returnType))
|
return CreateCallableFromUsageFixes(forExpr, FunctionInfo("hasNext", ownerType, returnType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
@@ -25,9 +24,10 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateInvokeFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateInvokeFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val callExpr = diagnostic.getPsiElement().getParent() as? JetCallExpression ?: return null
|
val callExpr = diagnostic.getPsiElement().getParent() as? JetCallExpression ?: return null
|
||||||
|
|
||||||
val expectedType = Errors.FUNCTION_EXPECTED.cast(diagnostic).getB()
|
val expectedType = Errors.FUNCTION_EXPECTED.cast(diagnostic).getB()
|
||||||
@@ -44,6 +44,6 @@ object CreateInvokeFunctionActionFactory : JetSingleIntentionActionFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val returnType = TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(callExpr, FunctionInfo("invoke", receiverType, returnType, Collections.emptyList(), parameters))
|
return CreateCallableFromUsageFixes(callExpr, FunctionInfo("invoke", receiverType, returnType, Collections.emptyList(), parameters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
@@ -30,9 +29,10 @@ import org.jetbrains.kotlin.types.TypeProjectionImpl
|
|||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import org.jetbrains.kotlin.types.JetTypeImpl
|
import org.jetbrains.kotlin.types.JetTypeImpl
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateIteratorFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateIteratorFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val file = diagnostic.getPsiFile() as? JetFile ?: return null
|
val file = diagnostic.getPsiFile() as? JetFile ?: return null
|
||||||
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
||||||
val iterableExpr = forExpr.getLoopRange() ?: return null
|
val iterableExpr = forExpr.getLoopRange() ?: return null
|
||||||
@@ -48,6 +48,6 @@ object CreateIteratorFunctionActionFactory : JetSingleIntentionActionFactory() {
|
|||||||
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
|
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
|
||||||
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isMarkedNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
|
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isMarkedNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
|
||||||
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(forExpr, FunctionInfo("iterator", iterableType, returnType))
|
return CreateCallableFromUsageFixes(forExpr, FunctionInfo("iterator", iterableType, returnType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
@@ -26,15 +25,16 @@ import org.jetbrains.kotlin.types.Variance
|
|||||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
||||||
import org.jetbrains.kotlin.psi.JetForExpression
|
import org.jetbrains.kotlin.psi.JetForExpression
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateNextFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateNextFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE)
|
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE)
|
||||||
val ownerType = TypeInfo(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
|
val ownerType = TypeInfo(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
|
||||||
|
|
||||||
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
|
||||||
val variableExpr: JetExpression = ((forExpr.getLoopParameter() ?: forExpr.getMultiParameter()) ?: return null) as JetExpression
|
val variableExpr: JetExpression = ((forExpr.getLoopParameter() ?: forExpr.getMultiParameter()) ?: return null) as JetExpression
|
||||||
val returnType = TypeInfo(variableExpr, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(variableExpr, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(forExpr, FunctionInfo("next", ownerType, returnType))
|
return CreateCallableFromUsageFixes(forExpr, FunctionInfo("next", ownerType, returnType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||||
@@ -33,9 +32,10 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Callab
|
|||||||
import com.intellij.util.SmartList
|
import com.intellij.util.SmartList
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreatePropertyDelegateAccessorsActionFactory : JetSingleIntentionActionFactory() {
|
object CreatePropertyDelegateAccessorsActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val expression = diagnostic.getPsiElement() as? JetExpression ?: return null
|
val expression = diagnostic.getPsiElement() as? JetExpression ?: return null
|
||||||
val context = expression.analyze()
|
val context = expression.analyze()
|
||||||
[suppress("UNCHECKED_CAST")]
|
[suppress("UNCHECKED_CAST")]
|
||||||
@@ -79,6 +79,6 @@ object CreatePropertyDelegateAccessorsActionFactory : JetSingleIntentionActionFa
|
|||||||
callableInfos.add(setterInfo)
|
callableInfos.add(setterInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateCallableFromUsageFix(expression, callableInfos)
|
return CreateCallableFromUsageFixes(expression, callableInfos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
||||||
@@ -33,9 +32,10 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() {
|
object CreateSetFunctionActionFactory : JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetArrayAccessExpression>()) ?: return null
|
val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetArrayAccessExpression>()) ?: return null
|
||||||
val arrayExpr = accessExpr.getArrayExpression() ?: return null
|
val arrayExpr = accessExpr.getArrayExpression() ?: return null
|
||||||
val arrayType = TypeInfo(arrayExpr, Variance.IN_VARIANCE)
|
val arrayType = TypeInfo(arrayExpr, Variance.IN_VARIANCE)
|
||||||
@@ -63,6 +63,6 @@ object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() {
|
|||||||
parameters.add(ParameterInfo(valType, "value"))
|
parameters.add(ParameterInfo(valType, "value"))
|
||||||
|
|
||||||
val returnType = TypeInfo(builtIns.getUnitType(), Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(builtIns.getUnitType(), Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(accessExpr, FunctionInfo("set", arrayType, returnType, Collections.emptyList(), parameters))
|
return CreateCallableFromUsageFixes(accessExpr, FunctionInfo("set", arrayType, returnType, Collections.emptyList(), parameters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
@@ -24,9 +23,10 @@ import org.jetbrains.kotlin.lexer.JetToken
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.psi.JetUnaryExpression
|
import org.jetbrains.kotlin.psi.JetUnaryExpression
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||||
|
|
||||||
public object CreateUnaryOperationActionFactory: JetSingleIntentionActionFactory() {
|
public object CreateUnaryOperationActionFactory: JetIntentionActionsFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val callExpr = diagnostic.getPsiElement().getParent() as? JetUnaryExpression ?: return null
|
val callExpr = diagnostic.getPsiElement().getParent() as? JetUnaryExpression ?: return null
|
||||||
val token = callExpr.getOperationToken() as JetToken
|
val token = callExpr.getOperationToken() as JetToken
|
||||||
val operationName = OperatorConventions.getNameForOperationSymbol(token) ?: return null
|
val operationName = OperatorConventions.getNameForOperationSymbol(token) ?: return null
|
||||||
@@ -36,6 +36,6 @@ public object CreateUnaryOperationActionFactory: JetSingleIntentionActionFactory
|
|||||||
|
|
||||||
val receiverType = TypeInfo(receiverExpr, Variance.IN_VARIANCE)
|
val receiverType = TypeInfo(receiverExpr, Variance.IN_VARIANCE)
|
||||||
val returnType = if (incDec) TypeInfo.ByReceiverType(Variance.OUT_VARIANCE) else TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
val returnType = if (incDec) TypeInfo.ByReceiverType(Variance.OUT_VARIANCE) else TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(callExpr, FunctionInfo(operationName.asString(), receiverType, returnType))
|
return CreateCallableFromUsageFixes(callExpr, FunctionInfo(operationName.asString(), receiverType, returnType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -112,7 +112,7 @@ public class CreateClassFromUsageFix(
|
|||||||
|
|
||||||
val constructorInfo = ConstructorInfo(classInfo, expectedTypeInfo)
|
val constructorInfo = ConstructorInfo(classInfo, expectedTypeInfo)
|
||||||
val builder = CallableBuilderConfiguration(
|
val builder = CallableBuilderConfiguration(
|
||||||
Collections.singletonList(constructorInfo), element as JetElement, file, editor, kind == PLAIN_CLASS || kind == TRAIT
|
Collections.singletonList(constructorInfo), element as JetElement, file, editor, false, kind == PLAIN_CLASS || kind == TRAIT
|
||||||
).createBuilder()
|
).createBuilder()
|
||||||
builder.placement = CallablePlacement.NoReceiver(targetParent)
|
builder.placement = CallablePlacement.NoReceiver(targetParent)
|
||||||
CommandProcessor.getInstance().executeCommand(project, { builder.build() }, getText(), null)
|
CommandProcessor.getInstance().executeCommand(project, { builder.build() }, getText(), null)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "false"
|
// "Import" "false"
|
||||||
|
// ACTION: Create extension function 'inc'
|
||||||
// ACTION: Create function 'inc'
|
// ACTION: Create function 'inc'
|
||||||
// ACTION: Create local variable '++'
|
// ACTION: Create local variable '++'
|
||||||
// ACTION: Create parameter '++'
|
// ACTION: Create parameter '++'
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// "Create class 'Foo'" "false"
|
// "Create class 'Foo'" "false"
|
||||||
// ACTION: Create function 'Foo'
|
// ACTION: Create extension function 'Foo'
|
||||||
// ACTION: Replace with infix function call
|
// ACTION: Replace with infix function call
|
||||||
// ACTION: Split property declaration
|
// ACTION: Split property declaration
|
||||||
// ERROR: Unresolved reference: Foo
|
// ERROR: Unresolved reference: Foo
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// "Create class 'Foo'" "false"
|
// "Create class 'Foo'" "false"
|
||||||
// ACTION: Create function 'Foo'
|
// ACTION: Create extension function 'Foo'
|
||||||
// ACTION: Convert to expression body
|
// ACTION: Convert to expression body
|
||||||
// ERROR: Unresolved reference: Foo
|
// ERROR: Unresolved reference: Foo
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// "Create class 'Foo'" "false"
|
// "Create class 'Foo'" "false"
|
||||||
// ACTION: Create function 'Foo'
|
// ACTION: Create extension function 'Foo'
|
||||||
// ERROR: Unresolved reference: Foo
|
// ERROR: Unresolved reference: Foo
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// "Create class 'A'" "false"
|
// "Create class 'A'" "false"
|
||||||
|
// ACTION: Create extension property 'A'
|
||||||
// ACTION: Create property 'A'
|
// ACTION: Create property 'A'
|
||||||
// ERROR: Unresolved reference: A
|
// ERROR: Unresolved reference: A
|
||||||
package p
|
package p
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// "Create enum constant 'A'" "false"
|
// "Create enum constant 'A'" "false"
|
||||||
|
// ACTION: Create extension property 'A'
|
||||||
// ACTION: Create property 'A'
|
// ACTION: Create property 'A'
|
||||||
// ERROR: Unresolved reference: A
|
// ERROR: Unresolved reference: A
|
||||||
package p
|
package p
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// "Create object 'A'" "false"
|
// "Create object 'A'" "false"
|
||||||
|
// ACTION: Create extension property 'A'
|
||||||
// ACTION: Create property 'A'
|
// ACTION: Create property 'A'
|
||||||
// ERROR: Unresolved reference: A
|
// ERROR: Unresolved reference: A
|
||||||
package p
|
package p
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'plus'" "true"
|
// "Create extension function 'plus'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'plus'" "true"
|
// "Create extension function 'plus'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a: Int = Unit.foo(2)
|
val a: Int = Unit.foo(2)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a: Int = Unit.<caret>foo(2)
|
val a: Int = Unit.<caret>foo(2)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
// ERROR: Unresolved reference: foo
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
// ERROR: Unresolved reference: foo
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'foo'" "true"
|
// "Create extension function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val items: List<T>) {
|
class A<T>(val items: List<T>) {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'component2'" "true"
|
// "Create extension function 'component2'" "true"
|
||||||
class FooIterator<T> {
|
class FooIterator<T> {
|
||||||
fun hasNext(): Boolean { return false }
|
fun hasNext(): Boolean { return false }
|
||||||
fun next(): Any {
|
fun next(): Any {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'component2'" "true"
|
// "Create extension function 'component2'" "true"
|
||||||
class FooIterator<T> {
|
class FooIterator<T> {
|
||||||
fun hasNext(): Boolean { return false }
|
fun hasNext(): Boolean { return false }
|
||||||
fun next(): Any {
|
fun next(): Any {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'get'" "true"
|
// "Create extension function 'get'" "true"
|
||||||
fun x (y: Any) {
|
fun x (y: Any) {
|
||||||
val z: Any = y[""]
|
val z: Any = y[""]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'get'" "true"
|
// "Create extension function 'get'" "true"
|
||||||
fun x (y: Any) {
|
fun x (y: Any) {
|
||||||
val z: Any = y<caret>[""]
|
val z: Any = y<caret>[""]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'invoke'" "true"
|
// "Create extension function 'invoke'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'invoke'" "true"
|
// "Create extension function 'invoke'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'set'" "true"
|
// "Create extension function 'set'" "true"
|
||||||
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'set'" "true"
|
// "Create extension function 'set'" "true"
|
||||||
|
|
||||||
class Foo<T> {
|
class Foo<T> {
|
||||||
fun <T> x (y: Any, w: java.util.ArrayList<T>) {
|
fun <T> x (y: Any, w: java.util.ArrayList<T>) {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'minus'" "true"
|
// "Create extension function 'minus'" "true"
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a = -false
|
val a = -false
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create function 'minus'" "true"
|
// "Create extension function 'minus'" "true"
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a = <caret>-false
|
val a = <caret>-false
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// "Create local variable 'foo'" "false"
|
// "Create local variable 'foo'" "false"
|
||||||
|
// ACTION: Create extension property 'foo'
|
||||||
// ACTION: Create property 'foo'
|
// ACTION: Create property 'foo'
|
||||||
// ACTION: Split property declaration
|
// ACTION: Split property declaration
|
||||||
// ERROR: Unresolved reference: foo
|
// ERROR: Unresolved reference: foo
|
||||||
|
|||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
// "Create parameter 'foo'" "false"
|
// "Create parameter 'foo'" "false"
|
||||||
// ACTION: Split property declaration
|
// ACTION: Split property declaration
|
||||||
|
// ACTION: Create extension property 'foo'
|
||||||
// ACTION: Create property 'foo'
|
// ACTION: Create property 'foo'
|
||||||
// ERROR: Unresolved reference: foo
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Create property 'foo'" "false"
|
// "Create property 'foo'" "false"
|
||||||
|
// ACTION: Create extension function 'bar'
|
||||||
// ACTION: Create function 'bar'
|
// ACTION: Create function 'bar'
|
||||||
// ACTION: Replace with infix function call
|
// ACTION: Replace with infix function call
|
||||||
// ERROR: Unresolved reference: bar
|
// ERROR: Unresolved reference: bar
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// "Create property 'foo'" "true"
|
// "Create extension property 'foo'" "true"
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
class A<T>(val n: T)
|
class A<T>(val n: T)
|
||||||
|
|||||||
Reference in New Issue
Block a user