From c8d9f9ac50e41cacc0c320f222717c1b8ff82877 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 28 Nov 2017 12:00:55 +0300 Subject: [PATCH] Refactoring: Rename copyable property delegates for PsiElement --- .../frontend/src/org/jetbrains/kotlin/psi/userDataUtil.kt | 4 ++-- .../idea/codeInsight/shorten/delayedRequestsWaitingSet.kt | 2 +- .../jetbrains/kotlin/idea/completion/CompletionUtils.kt | 2 +- .../debugger/evaluate/extractFunctionForDebuggerUtil.kt | 4 ++-- .../idea/formatter/CollectChangesWithoutApplyModel.kt | 4 ++-- .../changeSignature/usages/KotlinFunctionCallUsage.kt | 2 +- .../kotlin/idea/refactoring/inline/inlineUtils.kt | 2 +- .../introduce/extractionEngine/ExtractionData.kt | 2 +- .../introduce/extractionEngine/extractorUtil.kt | 4 ++-- .../introduce/introduceTypeAlias/extractionModel.kt | 2 +- .../introduce/introduceTypeAlias/introduceTypeAliasImpl.kt | 2 +- .../introduceVariable/KotlinIntroduceVariableHandler.kt | 2 +- .../jetbrains/kotlin/idea/refactoring/move/moveUtils.kt | 2 +- .../pullUp/JavaToKotlinPreconversionPullUpHelper.kt | 2 +- .../kotlin/idea/refactoring/pullUp/markingUtils.kt | 7 +++---- 15 files changed, 21 insertions(+), 22 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/userDataUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/userDataUtil.kt index e4bbe723d1e..43192e8ba7a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/userDataUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/userDataUtil.kt @@ -35,13 +35,13 @@ class NotNullableUserDataProperty(val key: Key(val key: Key) { +class CopyablePsiUserDataProperty(val key: Key) { operator fun getValue(thisRef: R, property: KProperty<*>) = thisRef.getCopyableUserData(key) operator fun setValue(thisRef: R, property: KProperty<*>, value: T?) = thisRef.putCopyableUserData(key, value) } -class NotNullableCopyableUserDataProperty(val key: Key, val defaultValue: T) { +class NotNullablePsiCopyableUserDataProperty(val key: Key, val defaultValue: T) { operator fun getValue(thisRef: R, property: KProperty<*>) = thisRef.getCopyableUserData(key) ?: defaultValue operator fun setValue(thisRef: R, property: KProperty<*>, value: T) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/delayedRequestsWaitingSet.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/delayedRequestsWaitingSet.kt index 6cec72e59c6..1bdf7c3bc13 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/delayedRequestsWaitingSet.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/shorten/delayedRequestsWaitingSet.kt @@ -133,7 +133,7 @@ fun prepareDelayedRequests(project: Project) { } } -var KtElement.isToBeShortened: Boolean? by CopyableUserDataProperty(Key.create("IS_TO_BE_SHORTENED")) +var KtElement.isToBeShortened: Boolean? by CopyablePsiUserDataProperty(Key.create("IS_TO_BE_SHORTENED")) fun KtElement.addToBeShortenedDescendantsToWaitingSet() { forEachDescendantOfType { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt index c676139aa5b..4714733d010 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt @@ -421,7 +421,7 @@ fun OffsetMap.tryGetOffset(key: OffsetKey): Int? { } } -var KtCodeFragment.extraCompletionFilter: ((LookupElement) -> Boolean)? by CopyableUserDataProperty(Key.create("EXTRA_COMPLETION_FILTER")) +var KtCodeFragment.extraCompletionFilter: ((LookupElement) -> Boolean)? by CopyablePsiUserDataProperty(Key.create("EXTRA_COMPLETION_FILTER")) val DeclarationDescriptor.isArtificialImportAliasedDescriptor: Boolean get() = original.name != name \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index a67a62bbcd0..e4660cf954d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -137,7 +137,7 @@ fun addDebugExpressionIntoTmpFileForExtractFunction(originalFile: KtFile, codeFr return contentElementsInTmpFile } -private var PsiElement.IS_CONTEXT_ELEMENT: Boolean by NotNullableCopyableUserDataProperty(Key.create("IS_CONTEXT_ELEMENT"), false) +private var PsiElement.IS_CONTEXT_ELEMENT: Boolean by NotNullablePsiCopyableUserDataProperty(Key.create("IS_CONTEXT_ELEMENT"), false) private fun KtCodeFragment.markContextElement() { getOriginalContext()?.IS_CONTEXT_ELEMENT = true @@ -151,7 +151,7 @@ private fun KtFile.findContextElement(): KtElement? { return this.findDescendantOfType { it.IS_CONTEXT_ELEMENT == true } } -private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyableUserDataProperty(Key.create("DEBUG_SMART_CAST")) +private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyablePsiUserDataProperty(Key.create("DEBUG_SMART_CAST")) private fun KtCodeFragment.markSmartCasts() { val bindingContext = runInReadActionWithWriteActionPriorityWithPCE { analyzeFully() } diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/CollectChangesWithoutApplyModel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/CollectChangesWithoutApplyModel.kt index 8ba1069f970..e11682e8701 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/CollectChangesWithoutApplyModel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/CollectChangesWithoutApplyModel.kt @@ -27,10 +27,10 @@ import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.formatter.FormattingDocumentModelImpl import org.jetbrains.kotlin.idea.formatter.FormattingChange.ReplaceWhiteSpace import org.jetbrains.kotlin.idea.formatter.FormattingChange.ShiftIndentInsideRange -import org.jetbrains.kotlin.psi.NotNullableCopyableUserDataProperty +import org.jetbrains.kotlin.psi.NotNullablePsiCopyableUserDataProperty import org.jetbrains.kotlin.psi.UserDataProperty -private var PsiFile.collectFormattingChanges: Boolean by NotNullableCopyableUserDataProperty(Key.create("COLLECT_FORMATTING_CHANGES"), false) +private var PsiFile.collectFormattingChanges: Boolean by NotNullablePsiCopyableUserDataProperty(Key.create("COLLECT_FORMATTING_CHANGES"), false) private var PsiFile.collectChangesFormattingModel: CollectChangesWithoutApplyModel? by UserDataProperty(Key.create("COLLECT_CHANGES_FORMATTING_MODEL")) fun createCollectFormattingChangesModel(file: PsiFile, block: Block): FormattingModel? { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt index b457f94f68e..78a88e5abab 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt @@ -276,7 +276,7 @@ class KotlinFunctionCallUsage( } private var KtValueArgument.generatedArgumentValue: Boolean - by NotNullableCopyableUserDataProperty(Key.create("GENERATED_ARGUMENT_VALUE"), false) + by NotNullablePsiCopyableUserDataProperty(Key.create("GENERATED_ARGUMENT_VALUE"), false) private fun ArgumentInfo.getArgumentByDefaultValue( element: KtCallElement, diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/inlineUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/inlineUtils.kt index ac06e214669..f4e61eb5b9d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/inlineUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/inlineUtils.kt @@ -86,7 +86,7 @@ fun showDialog( } internal var KtSimpleNameExpression.internalUsageInfos: MutableMap UsageInfo?>? - by CopyableUserDataProperty(Key.create("INTERNAL_USAGE_INFOS")) + by CopyablePsiUserDataProperty(Key.create("INTERNAL_USAGE_INFOS")) internal fun preProcessInternalUsages(element: KtElement, usages: Collection) { val mainFile = element.containingKtFile diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractionData.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractionData.kt index ae2074af9d5..307aabea950 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractionData.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractionData.kt @@ -78,7 +78,7 @@ data class ResolvedReferenceInfo( val shouldSkipPrimaryReceiver: Boolean ) -internal var KtSimpleNameExpression.resolveResult: ResolveResult? by CopyableUserDataProperty(Key.create("RESOLVE_RESULT")) +internal var KtSimpleNameExpression.resolveResult: ResolveResult? by CopyablePsiUserDataProperty(Key.create("RESOLVE_RESULT")) data class ExtractionData( val originalFile: KtFile, diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index 1dcfe7ad7a2..e6292a8e95d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -404,10 +404,10 @@ private fun makeCall( } private var KtExpression.isJumpElementToReplace: Boolean - by NotNullableCopyableUserDataProperty(Key.create("IS_JUMP_ELEMENT_TO_REPLACE"), false) + by NotNullablePsiCopyableUserDataProperty(Key.create("IS_JUMP_ELEMENT_TO_REPLACE"), false) private var KtReturnExpression.isReturnForLabelRemoval: Boolean - by NotNullableCopyableUserDataProperty(Key.create("IS_RETURN_FOR_LABEL_REMOVAL"), false) + by NotNullablePsiCopyableUserDataProperty(Key.create("IS_RETURN_FOR_LABEL_REMOVAL"), false) fun ExtractionGeneratorConfiguration.generateDeclaration( declarationToReplace: KtNamedDeclaration? = null diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/extractionModel.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/extractionModel.kt index 3862bc4fec3..da6c939af87 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/extractionModel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/extractionModel.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.KotlinType class TypeReferenceInfo(val reference: KtTypeReference, val type: KotlinType) -internal var KtTypeReference.resolveInfo : TypeReferenceInfo? by CopyableUserDataProperty(Key.create("RESOLVE_INFO")) +internal var KtTypeReference.resolveInfo : TypeReferenceInfo? by CopyablePsiUserDataProperty(Key.create("RESOLVE_INFO")) class IntroduceTypeAliasData( val originalTypeElement: KtElement, diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/introduceTypeAliasImpl.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/introduceTypeAliasImpl.kt index f4847bd46a7..a8b61bc11e9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/introduceTypeAliasImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeAlias/introduceTypeAliasImpl.kt @@ -237,7 +237,7 @@ fun findDuplicates(typeAlias: KtTypeAlias): Map Unit> { return rangesWithReplacers.toMap() } -private var KtTypeReference.typeParameterInfo : TypeParameter? by CopyableUserDataProperty(Key.create("TYPE_PARAMETER_INFO")) +private var KtTypeReference.typeParameterInfo : TypeParameter? by CopyablePsiUserDataProperty(Key.create("TYPE_PARAMETER_INFO")) fun IntroduceTypeAliasDescriptor.generateTypeAlias(previewOnly: Boolean = false): KtTypeAlias { val originalElement = originalData.originalTypeElement diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt index 8c100dfaebf..706f206efff 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt @@ -80,7 +80,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler { private val REPLACE_KEY = Key.create("REPLACE_KEY") private val COMMON_PARENT_KEY = Key.create("COMMON_PARENT_KEY") - private var KtExpression.isOccurrence: Boolean by NotNullableCopyableUserDataProperty(Key.create("OCCURRENCE"), false) + private var KtExpression.isOccurrence: Boolean by NotNullablePsiCopyableUserDataProperty(Key.create("OCCURRENCE"), false) private class IntroduceVariableContext( private val expression: KtExpression, diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt index c7e1671c5da..a909aca0649 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt @@ -197,7 +197,7 @@ fun KtElement.processInternalReferencesToUpdateOnPackageNameChange( } } -internal var KtSimpleNameExpression.internalUsageInfo: UsageInfo? by CopyableUserDataProperty(Key.create("INTERNAL_USAGE_INFO")) +internal var KtSimpleNameExpression.internalUsageInfo: UsageInfo? by CopyablePsiUserDataProperty(Key.create("INTERNAL_USAGE_INFO")) internal fun markInternalUsages(usages: Collection) { usages.forEach { (it.element as? KtSimpleNameExpression)?.internalUsageInfo = it } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt index cab442199eb..7b14ece498a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt @@ -63,7 +63,7 @@ class JavaToKotlinPreconversionPullUpHelper( private val jvmStaticAnnotation = KtPsiFactory(data.sourceClass.project).createAnnotationEntry("@kotlin.jvm.JvmStatic") companion object { - private var PsiMember.originalMember: PsiMember? by CopyableUserDataProperty(Key.create("ORIGINAL_MEMBER")) + private var PsiMember.originalMember: PsiMember? by CopyablePsiUserDataProperty(Key.create("ORIGINAL_MEMBER")) } private fun collectFieldReferencesToEncapsulate(member: PsiField) { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/markingUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/markingUtils.kt index b1afee98e5f..3e3beb5b39e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/markingUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/markingUtils.kt @@ -36,14 +36,13 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.Variance import java.util.* -private var KtElement.newFqName: FqName? by CopyableUserDataProperty(Key.create("NEW_FQ_NAME")) -private var KtElement.replaceWithTargetThis: Boolean? by CopyableUserDataProperty(Key.create("REPLACE_WITH_TARGET_THIS")) -private var KtElement.newTypeText: ((TypeSubstitutor) -> String?)? by CopyableUserDataProperty(Key.create("NEW_TYPE_TEXT")) +private var KtElement.newFqName: FqName? by CopyablePsiUserDataProperty(Key.create("NEW_FQ_NAME")) +private var KtElement.replaceWithTargetThis: Boolean? by CopyablePsiUserDataProperty(Key.create("REPLACE_WITH_TARGET_THIS")) +private var KtElement.newTypeText: ((TypeSubstitutor) -> String?)? by CopyablePsiUserDataProperty(Key.create("NEW_TYPE_TEXT")) fun markElements( declaration: KtNamedDeclaration,