@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
33
33
import org.jetbrains.kotlin.idea.core.ShortenReferences
34
34
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
35
35
import org.jetbrains.kotlin.idea.refactoring.getOrCreateKotlinFile
36
+ import org.jetbrains.kotlin.idea.util.application.runWriteAction
36
37
import org.jetbrains.kotlin.lexer.KtTokens
37
38
import org.jetbrains.kotlin.psi.*
38
39
import org.jetbrains.kotlin.psi.KtPsiFactory.ClassHeaderBuilder
@@ -78,6 +79,8 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
78
79
else /* open class */ -> " Create subclass"
79
80
}
80
81
82
+ override fun startInWriteAction () = false
83
+
81
84
override fun applyTo (element : KtClass , editor : Editor ? ) {
82
85
if (editor == null ) throw IllegalArgumentException (" This intention requires an editor" )
83
86
@@ -100,10 +103,12 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
100
103
101
104
private fun createSealedSubclass (sealedClass : KtClass , sealedName : String , editor : Editor ) {
102
105
val project = sealedClass.project
103
- val builder = buildClassHeader(targetNameWithoutConflicts(sealedName, sealedClass), sealedClass, sealedName)
104
- val classFromText = KtPsiFactory (project).createClass(builder.asString())
105
- val body = sealedClass.getOrCreateBody()
106
- val klass = body.addBefore(classFromText, body.rBrace) as KtClass
106
+ val klass = runWriteAction {
107
+ val builder = buildClassHeader(targetNameWithoutConflicts(sealedName, sealedClass), sealedClass, sealedName)
108
+ val classFromText = KtPsiFactory (project).createClass(builder.asString())
109
+ val body = sealedClass.getOrCreateBody()
110
+ body.addBefore(classFromText, body.rBrace) as KtClass
111
+ }
107
112
runInteractiveRename(klass, project, sealedClass, editor)
108
113
chooseAndImplementMethods(project, klass, editor)
109
114
}
@@ -134,18 +139,23 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
134
139
if (container.containingClassOrObject == null && ! ApplicationManager .getApplication().isUnitTestMode) {
135
140
val dlg = chooseSubclassToCreate(baseClass, baseName) ? : return
136
141
val targetName = dlg.className
137
- val file = getOrCreateKotlinFile(" $targetName .kt" , dlg.targetDirectory)!!
138
- val builder = buildClassHeader(targetName, baseClass, baseClass.fqName!! .asString())
139
- file.add(factory.createClass(builder.asString()))
140
- val klass = file.getChildOfType<KtClass >()!!
141
- ShortenReferences .DEFAULT .process(klass)
142
+ val (file, klass) = runWriteAction {
143
+ val file = getOrCreateKotlinFile(" $targetName .kt" , dlg.targetDirectory)!!
144
+ val builder = buildClassHeader(targetName, baseClass, baseClass.fqName!! .asString())
145
+ file.add(factory.createClass(builder.asString()))
146
+ val klass = file.getChildOfType<KtClass >()!!
147
+ ShortenReferences .DEFAULT .process(klass)
148
+ file to klass
149
+ }
142
150
chooseAndImplementMethods(project, klass, CodeInsightUtil .positionCursor(project, file, klass) ? : editor)
143
151
}
144
152
else {
145
- val builder = buildClassHeader(targetNameWithoutConflicts(baseName, baseClass.containingClassOrObject),
146
- baseClass, name, visibility)
147
- val classFromText = factory.createClass(builder.asString())
148
- val klass = container.parent.addAfter(classFromText, container) as KtClass
153
+ val klass = runWriteAction {
154
+ val builder = buildClassHeader(targetNameWithoutConflicts(baseName, baseClass.containingClassOrObject),
155
+ baseClass, name, visibility)
156
+ val classFromText = factory.createClass(builder.asString())
157
+ container.parent.addAfter(classFromText, container) as KtClass
158
+ }
149
159
runInteractiveRename(klass, project, container, editor)
150
160
chooseAndImplementMethods(project, klass, editor)
151
161
}
0 commit comments