KT-1985 Creating class body on override/implement if necessary
This commit is contained in:
@@ -147,6 +147,11 @@ public class JetPsiFactory {
|
||||
return function.getBodyExpression();
|
||||
}
|
||||
|
||||
public static JetClassBody createEmptyClassBody(Project project) {
|
||||
JetClass aClass = createClass(project, "class A(){}");
|
||||
return aClass.getBody();
|
||||
}
|
||||
|
||||
public static JetParameter createParameter(Project project, String name, String type) {
|
||||
JetNamedFunction function = createFunction(project, "fun foo(" + name + " : " + type + ") {}");
|
||||
return function.getValueParameters().get(0);
|
||||
|
||||
@@ -68,9 +68,10 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
JetClassOrObject classOrObject,
|
||||
List<DescriptorClassMember> selectedElements
|
||||
) {
|
||||
final JetClassBody body = classOrObject.getBody();
|
||||
JetClassBody body = classOrObject.getBody();
|
||||
Project project = classOrObject.getProject();
|
||||
if (body == null) {
|
||||
return;
|
||||
body = JetPsiFactory.createEmptyClassBody(project);
|
||||
}
|
||||
|
||||
PsiElement afterAnchor = findInsertAfterAnchor(editor, body);
|
||||
@@ -86,6 +87,10 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
afterAnchor = added;
|
||||
elementsToCompact.add((JetElement) added);
|
||||
}
|
||||
if (!body.isPhysical()) {
|
||||
classOrObject.add(JetPsiFactory.createWhiteSpace(project));
|
||||
classOrObject.add(body);
|
||||
}
|
||||
ReferenceToClassesShortening.compactReferenceToClasses(elementsToCompact);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user