From b31da56e09a0959024e91ad2442d0797de1e86dc Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 10 Feb 2015 17:47:46 +0300 Subject: [PATCH] Shorten References: Introduce shortening options --- .../codeInsight/shorten/shortenWaitingSet.kt | 18 +++--- .../idea/references/JetSimpleNameReference.kt | 2 +- .../kotlin/idea/util/ShortenReferences.kt | 61 +++++++++++++------ .../JetAddFunctionToClassifierAction.java | 4 +- ...otlinShortenReferencesRefactoringHelper.kt | 7 ++- .../OverrideImplementMethodsHandler.java | 2 +- .../MoveDeclarationsOutHelper.java | 2 +- .../KotlinRuntimeTypeCastSurrounder.kt | 2 +- .../handlers/KotlinCallableInsertHandler.kt | 2 +- .../handlers/KotlinClassInsertHandler.kt | 2 +- .../kotlin/idea/completion/smart/Utils.kt | 2 +- .../ConvertAssertToIfWithThrowIntention.kt | 2 +- .../ConvertFunctionToPropertyIntention.kt | 2 +- .../ConvertIfWithThrowToAssertIntention.kt | 2 +- .../intentions/InsertExplicitTypeArguments.kt | 2 +- .../MakeTypeExplicitInLambdaIntention.kt | 6 +- .../ReconstructTypeInCastOrIsAction.java | 4 +- .../SpecifyTypeExplicitlyAction.java | 4 +- .../jetbrains/kotlin/idea/intentions/Utils.kt | 2 +- .../declarations/DeclarationUtils.java | 4 +- .../KotlinShortenFQNamesProcessor.kt | 2 +- .../idea/quickfix/CastExpressionFix.java | 2 +- .../idea/quickfix/ChangeAccessorTypeFix.java | 2 +- .../ChangeFunctionLiteralReturnTypeFix.java | 2 +- .../quickfix/ChangeFunctionReturnTypeFix.java | 2 +- .../ChangeMemberFunctionSignatureFix.java | 6 +- .../idea/quickfix/ChangeParameterTypeFix.java | 2 +- .../kotlin/idea/quickfix/ChangeTypeFix.java | 2 +- .../idea/quickfix/ChangeVariableTypeFix.java | 2 +- .../callableBuilder/CallableBuilder.kt | 2 +- .../usages/JetFunctionDefinitionUsage.java | 10 ++- .../extractFunction/extractorUtil.kt | 2 +- .../inline/KotlinInlineValHandler.java | 6 +- .../KotlinIntroduceVariableHandler.java | 4 +- .../shortenRefs/AbstractShortenRefsTest.kt | 3 +- 35 files changed, 108 insertions(+), 73 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/shortenWaitingSet.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/shortenWaitingSet.kt index 518ac856801..f728f575ddf 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/shortenWaitingSet.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/shortenWaitingSet.kt @@ -26,8 +26,11 @@ import java.util.HashSet import com.intellij.openapi.application.ApplicationManager import com.intellij.psi.SmartPointerManager import com.intellij.openapi.diagnostic.Logger +import org.jetbrains.kotlin.idea.util.ShortenReferences.Options -private var Project.elementsToShorten: MutableSet>? +class ShorteningRequest(val pointer: SmartPsiElementPointer, val options: Options) + +private var Project.elementsToShorten: MutableSet? by UserDataProperty(Key.create("ELEMENTS_TO_SHORTEN_KEY")) /* @@ -37,7 +40,7 @@ private var Project.elementsToShorten: MutableSet> { +private fun Project.getOrCreateElementsToShorten(): MutableSet { var elements = elementsToShorten if (elements == null) { elements = HashSet() @@ -47,16 +50,17 @@ private fun Project.getOrCreateElementsToShorten(): MutableSet>) -> Unit) { - project.elementsToShorten?.let { bindRequests -> +public fun withElementsToShorten(project: Project, f: (Set) -> Unit) { + project.elementsToShorten?.let { requests -> project.elementsToShorten = null - f(bindRequests) + f(requests) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt index aabac146cd6..ea665a477f8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt @@ -123,7 +123,7 @@ public class JetSimpleNameReference( PsiTreeUtil.getParentOfType(expression, javaClass(), javaClass()) == null if (needToShorten) { if (shorteningMode == ShorteningMode.FORCED_SHORTENING) { - ShortenReferences.process(newQualifiedElement) + ShortenReferences.DEFAULT.process(newQualifiedElement) } else { newQualifiedElement.addToShorteningWaitSet() diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt index 459911cf102..2c337ec5af8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt @@ -39,8 +39,36 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver +import org.jetbrains.kotlin.idea.util.ShortenReferences.Options + +public class ShortenReferences(val options: (JetElement) -> Options = { Options.DEFAULT }) { + public data class Options( + val removeThisLabels: Boolean = false, + val removeThis: Boolean = false + ) { + class object { + val DEFAULT = Options() + } + } + + class object { + val DEFAULT = ShortenReferences() + + private fun DeclarationDescriptor.asString() + = DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this) + + private fun JetReferenceExpression.targets(context: BindingContext): Collection { + return context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it.getImportableDescriptor()) } + ?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]?.map { it.getImportableDescriptor() }?.toSet() + ?: listOf() + } + + private fun mayImport(descriptor: DeclarationDescriptor, file: JetFile): Boolean { + if (descriptor !is ClassDescriptor && descriptor !is PackageViewDescriptor) return false + return ImportInsertHelper.getInstance(file.getProject()).mayImportByCodeStyle(descriptor) + } + } -public object ShortenReferences { public fun process(element: JetElement) { process(listOf(element)) } @@ -158,6 +186,7 @@ public object ShortenReferences { private fun analyzeReferences(elements: Iterable, visitor: ShorteningVisitor<*>): Set { for (element in elements) { + visitor.options = options(element) element.accept(visitor) } return visitor.getDescriptorsToImport() @@ -168,6 +197,8 @@ public object ShortenReferences { protected val elementFilter: (PsiElement) -> FilterResult, protected val failedToImportDescriptors: Set ) : JetVisitorVoid() { + var options: Options = Options.DEFAULT + private val elementsToShorten = ArrayList() private val descriptorsToImport = LinkedHashSet() @@ -211,7 +242,6 @@ public object ShortenReferences { elementFilter: (PsiElement) -> FilterResult, failedToImportDescriptors: Set ) : ShorteningVisitor(file, elementFilter, failedToImportDescriptors) { - override fun visitUserType(userType: JetUserType) { val filterResult = elementFilter(userType) if (filterResult == FilterResult.SKIP) return @@ -272,8 +302,15 @@ public object ShortenReferences { val bindingContext = resolutionFacade.analyze(qualifiedExpression) val receiver = qualifiedExpression.getReceiverExpression() - if (receiver !is JetThisExpression && bindingContext[BindingContext.QUALIFIER, receiver] == null) return false - + when { + receiver is JetThisExpression -> { + if (!options.removeThis) return false + } + else -> { + if (bindingContext[BindingContext.QUALIFIER, receiver] == null) return false + } + } + if (PsiTreeUtil.getParentOfType( qualifiedExpression, javaClass(), javaClass()) != null) return true @@ -327,7 +364,7 @@ public object ShortenReferences { private val simpleThis = JetPsiFactory(file).createExpression("this") as JetThisExpression private fun process(thisExpression: JetThisExpression) { - if (thisExpression.getTargetLabel() == null) return + if (!options.removeThisLabels || thisExpression.getTargetLabel() == null) return val bindingContext = resolutionFacade.analyze(thisExpression) @@ -354,20 +391,6 @@ public object ShortenReferences { } } - private fun DeclarationDescriptor.asString() - = DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this) - - private fun JetReferenceExpression.targets(context: BindingContext): Collection { - return context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it.getImportableDescriptor()) } - ?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]?.map { it.getImportableDescriptor() }?.toSet() - ?: listOf() - } - - private fun mayImport(descriptor: DeclarationDescriptor, file: JetFile): Boolean { - if (descriptor !is ClassDescriptor && descriptor !is PackageViewDescriptor) return false - return ImportInsertHelper.getInstance(file.getProject()).mayImportByCodeStyle(descriptor) - } - // this class is needed to optimize imports only when we actually insert any import (optimization) private class ImportInserter(val file: JetFile) { private var optimizeImports = true diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/JetAddFunctionToClassifierAction.java b/idea/src/org/jetbrains/kotlin/idea/actions/JetAddFunctionToClassifierAction.java index 9677222e128..414f4a81b6c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/JetAddFunctionToClassifierAction.java +++ b/idea/src/org/jetbrains/kotlin/idea/actions/JetAddFunctionToClassifierAction.java @@ -36,8 +36,8 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.Modality; import org.jetbrains.kotlin.idea.JetBundle; import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil; -import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; +import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.psi.JetClass; import org.jetbrains.kotlin.psi.JetClassBody; import org.jetbrains.kotlin.psi.JetNamedFunction; @@ -105,7 +105,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction { PsiElement anchor = body.getRBrace(); JetNamedFunction insertedFunctionElement = (JetNamedFunction) body.addBefore(functionElement, anchor); - ShortenReferences.INSTANCE$.process(insertedFunctionElement); + ShortenReferences.DEFAULT.process(insertedFunctionElement); } }); } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinShortenReferencesRefactoringHelper.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinShortenReferencesRefactoringHelper.kt index 5fba82c9215..e4775a8706c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinShortenReferencesRefactoringHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinShortenReferencesRefactoringHelper.kt @@ -35,8 +35,11 @@ public class KotlinShortenReferencesRefactoringHelper: RefactoringHelper { override fun performOperation(project: Project, operationData: Any?) { ApplicationManager.getApplication()!!.runWriteAction { - withElementsToShorten(project) { bindRequests -> - ShortenReferences.process(bindRequests.map() { it.getElement() }.filterNotNull()) + withElementsToShorten(project) { requests -> + val elements = requests.map { it.pointer.getElement() } + val options = requests.map { it.options } + val elementToOptions = (elements zip options).toMap() + ShortenReferences({ elementToOptions[it] ?: ShortenReferences.Options.DEFAULT }).process(elements.filterNotNull()) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/OverrideImplementMethodsHandler.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/OverrideImplementMethodsHandler.java index e8647aca092..4fec4dc74ab 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/OverrideImplementMethodsHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/OverrideImplementMethodsHandler.java @@ -114,7 +114,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns elementsToCompact.add((JetElement) added); } - ShortenReferences.INSTANCE$.process(elementsToCompact); + ShortenReferences.DEFAULT.process(elementsToCompact); if (firstGenerated == null) return; diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/MoveDeclarationsOutHelper.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/MoveDeclarationsOutHelper.java index b61678f9775..c8c41d38ff4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/MoveDeclarationsOutHelper.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/MoveDeclarationsOutHelper.java @@ -86,7 +86,7 @@ public class MoveDeclarationsOutHelper { dummyFirstStatement.delete(); } - ShortenReferences.INSTANCE$.process(propertiesDeclarations); + ShortenReferences.DEFAULT.process(propertiesDeclarations); return PsiUtilCore.toPsiElementArray(resultStatements); } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinRuntimeTypeCastSurrounder.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinRuntimeTypeCastSurrounder.kt index cb79d3a2ac9..08b926fa406 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinRuntimeTypeCastSurrounder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinRuntimeTypeCastSurrounder.kt @@ -99,7 +99,7 @@ public class KotlinRuntimeTypeCastSurrounder: KotlinExpressionSurrounder() { cast.getLeft().replace(myElement) val expr = myElement.replace(parentCast) as JetExpression - ShortenReferences.process(expr) + ShortenReferences.DEFAULT.process(expr) val range = expr.getTextRange() myEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()) diff --git a/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt b/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt index cf9cae1b196..da028ae9347 100644 --- a/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt @@ -269,7 +269,7 @@ object CastReceiverInsertHandler : KotlinCallableInsertHandler() { val expr = receiver.replace(parentCast) as JetParenthesizedExpression - ShortenReferences.process((expr.getExpression() as JetBinaryExpressionWithTypeRHS).getRight()) + ShortenReferences.DEFAULT.process((expr.getExpression() as JetBinaryExpressionWithTypeRHS).getRight()) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassInsertHandler.kt b/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassInsertHandler.kt index 40f5a6852c7..50fa2c24621 100644 --- a/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassInsertHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassInsertHandler.kt @@ -69,7 +69,7 @@ public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() { val rangeMarker = document.createRangeMarker(classNameStart, classNameEnd) val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length()) - ShortenReferences.process(file, classNameStart, classNameEnd) + ShortenReferences.DEFAULT.process(file, classNameStart, classNameEnd) psiDocumentManager.doPostponedOperationsAndUnblockDocument(document) if (rangeMarker.isValid() && wholeRangeMarker.isValid()) { diff --git a/idea/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 226055a739a..2b935755f51 100644 --- a/idea/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -62,7 +62,7 @@ class ArtificialElementInsertHandler( fun shortenReferences(context: InsertionContext, startOffset: Int, endOffset: Int) { PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments(); - ShortenReferences.process(context.getFile() as JetFile, startOffset, endOffset) + ShortenReferences.DEFAULT.process(context.getFile() as JetFile, startOffset, endOffset) } fun mergeTails(tails: Collection): Tail? { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt index 3a452867d26..76d70cc49bf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt @@ -80,7 +80,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention { JetTypeReference typeRef = castExpression.getRight(); assert typeRef != null; - ShortenReferences.INSTANCE$.process(typeRef); + ShortenReferences.DEFAULT.process(typeRef); } @NotNull diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java index 26fce42cd4d..b93f8685b7d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java @@ -81,7 +81,7 @@ public class ChangeAccessorTypeFix extends JetIntentionAction JetTypeReference newTypeRef = JetPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)); newTypeRef = element.setTypeReference(newTypeRef); assert newTypeRef != null; - ShortenReferences.INSTANCE$.process(newTypeRef); + ShortenReferences.DEFAULT.process(newTypeRef); } else { element.setTypeReference(null); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.java index 19dd09f1365..5da9936ae87 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.java @@ -40,8 +40,8 @@ import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.diagnostics.Diagnostic; import org.jetbrains.kotlin.idea.JetBundle; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; -import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; +import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.renderer.DescriptorRenderer; @@ -376,11 +376,11 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction { JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)); newTypeRef = element.setTypeReference(newTypeRef); assert newTypeRef != null; - ShortenReferences.INSTANCE$.process(newTypeRef); + ShortenReferences.DEFAULT.process(newTypeRef); } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeTypeFix.java index c1b769f75c4..2621c93d1d9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeTypeFix.java @@ -61,7 +61,7 @@ public class ChangeTypeFix extends JetIntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { JetTypeReference newTypeRef = (JetTypeReference) element.replace(JetPsiFactory(file).createType(renderedType)); - ShortenReferences.INSTANCE$.process(newTypeRef); + ShortenReferences.DEFAULT.process(newTypeRef); } @NotNull diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java index b6c65a82e4e..f7a0df183a6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java @@ -105,7 +105,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction extends JetUsageIn //TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) { - ShortenPackage.addToShorteningWaitSet(function.setTypeReference(JetPsiFactory(function).createType(returnTypeText))); + ShortenPackage.addToShorteningWaitSet( + function.setTypeReference(JetPsiFactory(function).createType(returnTypeText)), + Options.DEFAULT + ); } } } @@ -205,7 +209,7 @@ public class JetFunctionDefinitionUsage extends JetUsageIn paramIndex++; } - ShortenPackage.addToShorteningWaitSet(parameterList); + ShortenPackage.addToShorteningWaitSet(parameterList, Options.DEFAULT); } if (changeInfo.isVisibilityChanged() && !JetPsiUtil.isLocal((JetDeclaration) element)) { @@ -284,7 +288,7 @@ public class JetFunctionDefinitionUsage extends JetUsageIn } if (newParameterList != null) { - ShortenPackage.addToShorteningWaitSet(newParameterList); + ShortenPackage.addToShorteningWaitSet(newParameterList, Options.DEFAULT); } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/extractFunction/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/extractFunction/extractorUtil.kt index c11d42d1dd7..f6354a7ad32 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/extractFunction/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/extractFunction/extractorUtil.kt @@ -530,7 +530,7 @@ fun ExtractableCodeDescriptor.generateDeclaration(options: ExtractionGeneratorOp if (options.inTempFile) return ExtractionResult(declaration, Collections.emptyMap(), nameByOffset) makeCall(this, declaration, controlFlow, extractionData.originalRange, parameters.map { it.argumentText }) - ShortenReferences.process(declaration) + ShortenReferences.DEFAULT.process(declaration) val duplicateReplacers = duplicates.map { it.range to { makeCall(this, declaration, it.controlFlow, it.range, it.arguments) } }.toMap() return ExtractionResult(declaration, duplicateReplacers, nameByOffset) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.java index 5992ba9297e..b3dc28537d2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.java @@ -54,8 +54,8 @@ import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.idea.JetLanguage; import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; -import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; +import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingContext; @@ -295,7 +295,7 @@ public class KotlinInlineValHandler extends InlineActionHandler { functionLiteral.addAfter(whitespaceToAdd, openBraceElement); } } - ShortenReferences.INSTANCE$.process(functionLiteralExpression.getValueParameters()); + ShortenReferences.DEFAULT.process(functionLiteralExpression.getValueParameters()); } } @@ -337,7 +337,7 @@ public class KotlinInlineValHandler extends InlineActionHandler { JetPsiFactory psiFactory = JetPsiFactory(containingFile); for (JetCallExpression call : callsToAddArguments) { call.addAfter(psiFactory.createTypeArguments("<" + typeArguments + ">"), call.getCalleeExpression()); - ShortenReferences.INSTANCE$.process(call.getTypeArgumentList()); + ShortenReferences.DEFAULT.process(call.getTypeArgumentList()); } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java index 59baf528a6e..6db92b0bd44 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java @@ -39,7 +39,6 @@ import org.jetbrains.kotlin.analyzer.AnalyzerPackage; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils; -import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyAction; import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention; import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester; @@ -48,6 +47,7 @@ import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle; import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil; import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; +import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange; import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier; import org.jetbrains.kotlin.idea.util.psi.patternMatching.PatternMatchingPackage; @@ -425,7 +425,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { } propertyRef.set(property); if (noTypeInference) { - ShortenReferences.INSTANCE$.process(property); + ShortenReferences.DEFAULT.process(property); } } diff --git a/idea/tests/org/jetbrains/kotlin/shortenRefs/AbstractShortenRefsTest.kt b/idea/tests/org/jetbrains/kotlin/shortenRefs/AbstractShortenRefsTest.kt index fca7ca695e3..93224ef00d4 100644 --- a/idea/tests/org/jetbrains/kotlin/shortenRefs/AbstractShortenRefsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/shortenRefs/AbstractShortenRefsTest.kt @@ -24,7 +24,8 @@ public abstract class AbstractShortenRefsTest : AbstractImportsTest() { override fun doTest(file: JetFile) { val selectionModel = myFixture.getEditor().getSelectionModel() if (!selectionModel.hasSelection()) error("No selection in input file") - ShortenReferences.process(file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) + ShortenReferences { ShortenReferences.Options(removeThis = true, removeThisLabels = true) } + .process(file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) selectionModel.removeSelection() }