Merge pull request #140 from crazyproger/KT-1985
KT-1985 Creating class body in time of 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);
|
||||
@@ -87,6 +88,11 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
elementsToCompact.add((JetElement) added);
|
||||
}
|
||||
ReferenceToClassesShortening.compactReferenceToClasses(elementsToCompact);
|
||||
|
||||
if (!body.isPhysical()) {
|
||||
classOrObject.add(JetPsiFactory.createWhiteSpace(project));
|
||||
classOrObject.add(body);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// From KT-1254
|
||||
trait T {
|
||||
fun Foo() : (String) -> Unit
|
||||
}
|
||||
|
||||
class C : <caret>T
|
||||
@@ -0,0 +1,10 @@
|
||||
// From KT-1254
|
||||
trait T {
|
||||
fun Foo() : (String) -> Unit
|
||||
}
|
||||
|
||||
class C : T {
|
||||
override fun Foo(): (String) -> Unit {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,10 @@ public class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/overrideImplement");
|
||||
}
|
||||
|
||||
public void testEmptyClassBodyFunctionMethod() {
|
||||
doImplementFileTest();
|
||||
}
|
||||
|
||||
public void testFunctionMethod() {
|
||||
doImplementFileTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user