fixed nullability for various listeners update in 183
This commit is contained in:
committed by
xiexed
parent
d9473c0b6e
commit
d415ca9cf6
+8
-3
@@ -18,8 +18,13 @@ package org.jetbrains.kotlin.android.intention
|
|||||||
|
|
||||||
import com.android.resources.ResourceType
|
import com.android.resources.ResourceType
|
||||||
import com.intellij.CommonBundle
|
import com.intellij.CommonBundle
|
||||||
import com.intellij.codeInsight.template.*
|
import com.intellij.codeInsight.template.Template
|
||||||
import com.intellij.codeInsight.template.impl.*
|
import com.intellij.codeInsight.template.TemplateEditingAdapter
|
||||||
|
import com.intellij.codeInsight.template.TemplateManager
|
||||||
|
import com.intellij.codeInsight.template.impl.ConstantNode
|
||||||
|
import com.intellij.codeInsight.template.impl.MacroCallNode
|
||||||
|
import com.intellij.codeInsight.template.impl.TemplateImpl
|
||||||
|
import com.intellij.codeInsight.template.impl.TemplateState
|
||||||
import com.intellij.codeInsight.template.macro.VariableOfTypeMacro
|
import com.intellij.codeInsight.template.macro.VariableOfTypeMacro
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.command.undo.UndoUtil
|
import com.intellij.openapi.command.undo.UndoUtil
|
||||||
@@ -167,7 +172,7 @@ class KotlinAndroidAddStringResource : SelfTargetingIntention<KtLiteralStringTem
|
|||||||
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
|
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeTemplateFinished(state: TemplateState?, template: Template?) {
|
override fun beforeTemplateFinished(state: TemplateState, template: Template?) {
|
||||||
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
|
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ class KotlinSetupEnvironmentNotificationProvider(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
myProject.messageBus.connect(myProject).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
myProject.messageBus.connect(myProject).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
notifications.updateAllNotifications()
|
notifications.updateAllNotifications()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom
|
|||||||
|
|
||||||
val connection = project.messageBus.connect()
|
val connection = project.messageBus.connect()
|
||||||
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
if (!project.isInitialized) return
|
if (!project.isInitialized) return
|
||||||
|
|
||||||
if (notificationPostponed && !isSyncing) {
|
if (notificationPostponed && !isSyncing) {
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
init {
|
init {
|
||||||
val connection = project.messageBus.connect()
|
val connection = project.messageBus.connect()
|
||||||
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
updateNotifications()
|
updateNotifications()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ internal class AnonymousTemplateEditingListener(private val psiFile: PsiFile, pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
editor.putUserData(LISTENER_KEY, null)
|
editor.putUserData(LISTENER_KEY, null)
|
||||||
if (brokenOff) return
|
if (brokenOff) return
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class BatchTemplateRunner(private val project: Project) {
|
|||||||
editor,
|
editor,
|
||||||
template,
|
template,
|
||||||
object : TemplateEditingAdapter() {
|
object : TemplateEditingAdapter() {
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
if (brokenOff) return
|
if (brokenOff) return
|
||||||
ApplicationManager.getApplication().invokeLater { runTemplates(iterator) }
|
ApplicationManager.getApplication().invokeLater { runTemplates(iterator) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class KotlinFacetSettingsProviderImpl(private val project: Project) : KotlinFace
|
|||||||
project.messageBus.connect(project).subscribe(
|
project.messageBus.connect(project).subscribe(
|
||||||
ProjectTopics.PROJECT_ROOTS,
|
ProjectTopics.PROJECT_ROOTS,
|
||||||
object : ModuleRootListener {
|
object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
ModuleManager.getInstance(project).modules.forEach { it.facetSettingsCache = null }
|
ModuleManager.getInstance(project).modules.forEach { it.facetSettingsCache = null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class LibraryEffectiveKindProviderImpl(project: Project) : LibraryEffectiveKindP
|
|||||||
project.messageBus.connect(project).subscribe(
|
project.messageBus.connect(project).subscribe(
|
||||||
ProjectTopics.PROJECT_ROOTS,
|
ProjectTopics.PROJECT_ROOTS,
|
||||||
object : ModuleRootListener {
|
object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
synchronized(effectiveKindMap) {
|
synchronized(effectiveKindMap) {
|
||||||
effectiveKindMap.clear()
|
effectiveKindMap.clear()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -114,13 +114,13 @@ class ConvertCamelCaseTestFunctionToSpacedIntention : SelfTargetingRangeIntentio
|
|||||||
private var chosenId: String = newId
|
private var chosenId: String = newId
|
||||||
private var range: TextRange? = null
|
private var range: TextRange? = null
|
||||||
|
|
||||||
override fun beforeTemplateFinished(state: TemplateState?, template: Template?) {
|
override fun beforeTemplateFinished(state: TemplateState, template: Template?) {
|
||||||
val varName = (template as? TemplateImpl)?.getVariableNameAt(0) ?: return
|
val varName = (template as? TemplateImpl)?.getVariableNameAt(0) ?: return
|
||||||
chosenId = state?.getVariableValue(varName)?.text?.quoteIfNeeded() ?: return
|
chosenId = state?.getVariableValue(varName)?.text?.quoteIfNeeded() ?: return
|
||||||
range = state.getVariableRange(varName)
|
range = state.getVariableRange(varName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
range?.let {
|
range?.let {
|
||||||
val doc = editor.document
|
val doc = editor.document
|
||||||
runWriteAction { doc.replaceString(it.startOffset, it.endOffset, oldId) }
|
runWriteAction { doc.replaceString(it.startOffset, it.endOffset, oldId) }
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ class ConvertReceiverToParameterIntention : SelfTargetingOffsetIndependentIntent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
val newName = addedParameter.name
|
val newName = addedParameter.name
|
||||||
revertChanges()
|
revertChanges()
|
||||||
if (!brokenOff) {
|
if (!brokenOff) {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class SpecifyTypeExplicitlyIntention : SelfTargetingRangeIntention<KtCallableDec
|
|||||||
editor: Editor? = null
|
editor: Editor? = null
|
||||||
): TemplateEditingAdapter {
|
): TemplateEditingAdapter {
|
||||||
return object : TemplateEditingAdapter() {
|
return object : TemplateEditingAdapter() {
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
val typeRef = declaration.typeReference
|
val typeRef = declaration.typeReference
|
||||||
if (typeRef != null && typeRef.isValid) {
|
if (typeRef != null && typeRef.isValid) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ class DoubleBangToIfThenIntention : SelfTargetingRangeIntention<KtPostfixExpress
|
|||||||
editor.caretModel.moveToOffset(thrownExpression.node!!.startOffset)
|
editor.caretModel.moveToOffset(thrownExpression.node!!.startOffset)
|
||||||
|
|
||||||
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), object: TemplateEditingAdapter() {
|
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), object: TemplateEditingAdapter() {
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
if (!isStable && !isStatement) {
|
if (!isStable && !isStatement) {
|
||||||
ifStatement.introduceValueForCondition(ifStatement.then!!, editor)
|
ifStatement.introduceValueForCondition(ifStatement.then!!, editor)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class MapPlatformClassToKotlinFix(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), object : TemplateEditingAdapter() {
|
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), object : TemplateEditingAdapter() {
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
caretModel.moveToOffset(oldOffset)
|
caretModel.moveToOffset(oldOffset)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -1013,7 +1013,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
finishTemplate(true)
|
finishTemplate(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
finishTemplate(brokenOff)
|
finishTemplate(brokenOff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ private fun smartSelectElement(
|
|||||||
.setItemChoosenCallback { callback(list.selectedValue as KtElement) }
|
.setItemChoosenCallback { callback(list.selectedValue as KtElement) }
|
||||||
.addListener(
|
.addListener(
|
||||||
object : JBPopupAdapter() {
|
object : JBPopupAdapter() {
|
||||||
override fun onClosed(event: LightweightWindowEvent?) {
|
override fun onClosed(event: LightweightWindowEvent) {
|
||||||
highlighter.dropHighlight()
|
highlighter.dropHighlight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -307,14 +307,14 @@ class ExtractSuperRefactoring(
|
|||||||
project.executeWriteCommand(KotlinExtractSuperclassHandler.REFACTORING_NAME) {
|
project.executeWriteCommand(KotlinExtractSuperclassHandler.REFACTORING_NAME) {
|
||||||
val newClass = createClass(superClassEntry) ?: return@executeWriteCommand
|
val newClass = createClass(superClassEntry) ?: return@executeWriteCommand
|
||||||
|
|
||||||
val subClass = extractInfo.originalClass.toLightClass()
|
val subClass = extractInfo.originalClass.toLightClass() ?: return@executeWriteCommand
|
||||||
val superClass = newClass.toLightClass()
|
val superClass = newClass.toLightClass() ?: return@executeWriteCommand
|
||||||
|
|
||||||
PullUpProcessor(
|
PullUpProcessor(
|
||||||
subClass,
|
subClass,
|
||||||
superClass ?: return@executeWriteCommand,
|
superClass,
|
||||||
extractInfo.memberInfos.mapNotNull { it.toJavaMemberInfo() }.toTypedArray(),
|
extractInfo.memberInfos.mapNotNull { it.toJavaMemberInfo() }.toTypedArray(),
|
||||||
extractInfo.docPolicy
|
extractInfo.docPolicy
|
||||||
).moveMembersToBase()
|
).moveMembersToBase()
|
||||||
|
|
||||||
performDelayedRefactoringRequests(project)
|
performDelayedRefactoringRequests(project)
|
||||||
|
|||||||
+1
-1
@@ -450,7 +450,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
|||||||
FinishMarkAction.finish(project, editor, startMarkAction)
|
FinishMarkAction.finish(project, editor, startMarkAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
if (!brokenOff) {
|
if (!brokenOff) {
|
||||||
postProcess(declaration)
|
postProcess(declaration)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ fun <T, E : PsiElement> getPsiElementPopup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
addListener(object : JBPopupAdapter() {
|
addListener(object : JBPopupAdapter() {
|
||||||
override fun onClosed(event: LightweightWindowEvent?) {
|
override fun onClosed(event: LightweightWindowEvent) {
|
||||||
highlighter?.dropHighlight()
|
highlighter?.dropHighlight()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+2
-2
@@ -72,13 +72,13 @@ class ChangePackageIntention: SelfTargetingOffsetIndependentIntention<KtPackageD
|
|||||||
editor,
|
editor,
|
||||||
builder.buildInlineTemplate(),
|
builder.buildInlineTemplate(),
|
||||||
object: TemplateEditingAdapter() {
|
object: TemplateEditingAdapter() {
|
||||||
override fun beforeTemplateFinished(state: TemplateState?, template: Template?) {
|
override fun beforeTemplateFinished(state: TemplateState, template: Template?) {
|
||||||
if (state == null) return
|
if (state == null) return
|
||||||
enteredName = state.getVariableValue(PACKAGE_NAME_VAR)!!.text
|
enteredName = state.getVariableValue(PACKAGE_NAME_VAR)!!.text
|
||||||
affectedRange = state.getSegmentRange(0)
|
affectedRange = state.getSegmentRange(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun templateFinished(template: Template?, brokenOff: Boolean) {
|
override fun templateFinished(template: Template, brokenOff: Boolean) {
|
||||||
if (brokenOff || enteredName == null || affectedRange == null) return
|
if (brokenOff || enteredName == null || affectedRange == null) return
|
||||||
|
|
||||||
// Restore original name and run refactoring
|
// Restore original name and run refactoring
|
||||||
|
|||||||
@@ -162,10 +162,11 @@ class KotlinPullUpDialog(
|
|||||||
targetClass: PsiNamedElement,
|
targetClass: PsiNamedElement,
|
||||||
memberInfos: List<KotlinMemberInfo>): PullUpProcessor {
|
memberInfos: List<KotlinMemberInfo>): PullUpProcessor {
|
||||||
val targetPsiClass = targetClass as? PsiClass ?: (targetClass as KtClass).toLightClass()
|
val targetPsiClass = targetClass as? PsiClass ?: (targetClass as KtClass).toLightClass()
|
||||||
return PullUpProcessor(sourceClass.toLightClass(),
|
return PullUpProcessor(
|
||||||
targetPsiClass,
|
sourceClass.toLightClass() ?: error("can't build lightClass for $sourceClass"),
|
||||||
memberInfos.mapNotNull { it.toJavaMemberInfo() }.toTypedArray(),
|
targetPsiClass,
|
||||||
DocCommentPolicy<PsiComment>(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC))
|
memberInfos.mapNotNull { it.toJavaMemberInfo() }.toTypedArray(),
|
||||||
|
DocCommentPolicy<PsiComment>(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
init {
|
init {
|
||||||
val connection = project.messageBus.connect()
|
val connection = project.messageBus.connect()
|
||||||
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
||||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
override fun rootsChanged(event: ModuleRootEvent) {
|
||||||
if (project.isInitialized) {
|
if (project.isInitialized) {
|
||||||
var templatesChanged = false
|
var templatesChanged = false
|
||||||
lock.read {
|
lock.read {
|
||||||
|
|||||||
Reference in New Issue
Block a user