Remove rest of whitespace on override or implement to insert generated at caret offset
This commit is contained in:
+44
-15
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.ide.util.MemberChooser;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LanguageCodeInsightActionHandler;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -25,9 +26,11 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -35,9 +38,9 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -75,9 +78,9 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
}
|
||||
|
||||
public static void generateMethods(
|
||||
Editor editor,
|
||||
JetClassOrObject classOrObject,
|
||||
List<DescriptorClassMember> selectedElements
|
||||
@NotNull Editor editor,
|
||||
@NotNull JetClassOrObject classOrObject,
|
||||
@NotNull List<DescriptorClassMember> selectedElements
|
||||
) {
|
||||
JetClassBody body = classOrObject.getBody();
|
||||
if (body == null) {
|
||||
@@ -106,26 +109,52 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
@Nullable
|
||||
private static PsiElement findInsertAfterAnchor(Editor editor, final JetClassBody body) {
|
||||
PsiElement afterAnchor = body.getLBrace();
|
||||
if (afterAnchor == null) {
|
||||
return null;
|
||||
}
|
||||
if (afterAnchor == null) return null;
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement offsetCursorElement = PsiTreeUtil.findFirstParent(body.getContainingFile().findElementAt(offset),
|
||||
new Condition<PsiElement>() {
|
||||
@Override
|
||||
public boolean value(PsiElement element) {
|
||||
return element.getParent() == body;
|
||||
}
|
||||
});
|
||||
PsiElement offsetCursorElement = PsiTreeUtil.findFirstParent(
|
||||
body.getContainingFile().findElementAt(offset),
|
||||
new Condition<PsiElement>() {
|
||||
@Override
|
||||
public boolean value(PsiElement element) {
|
||||
return element.getParent() == body;
|
||||
}
|
||||
});
|
||||
|
||||
if (offsetCursorElement instanceof PsiWhiteSpace) {
|
||||
return removeAfterOffset(offset, (PsiWhiteSpace) offsetCursorElement);
|
||||
}
|
||||
|
||||
if (offsetCursorElement != null && offsetCursorElement != body.getRBrace()) {
|
||||
afterAnchor = offsetCursorElement;
|
||||
return offsetCursorElement;
|
||||
}
|
||||
|
||||
return afterAnchor;
|
||||
}
|
||||
|
||||
private static PsiElement removeAfterOffset(int offset, PsiWhiteSpace whiteSpace) {
|
||||
ASTNode spaceNode = whiteSpace.getNode();
|
||||
if (spaceNode.getTextRange().contains(offset)) {
|
||||
String beforeWhiteSpaceText = spaceNode.getText().substring(0, offset - spaceNode.getStartOffset());
|
||||
if (!StringUtil.containsLineBreak(beforeWhiteSpaceText)) {
|
||||
// Prevent insertion on same line
|
||||
beforeWhiteSpaceText += "\n";
|
||||
}
|
||||
|
||||
JetPsiFactory factory = JetPsiFactory(whiteSpace.getProject());
|
||||
|
||||
PsiElement insertAfter = whiteSpace.getPrevSibling();
|
||||
whiteSpace.delete();
|
||||
|
||||
PsiElement beforeSpace = factory.createWhiteSpace(beforeWhiteSpaceText);
|
||||
insertAfter.getParent().addAfter(beforeSpace, insertAfter);
|
||||
|
||||
return insertAfter.getNextSibling();
|
||||
}
|
||||
|
||||
return whiteSpace;
|
||||
}
|
||||
|
||||
private static List<JetElement> generateOverridingMembers(List<DescriptorClassMember> selectedElements, JetFile file) {
|
||||
List<JetElement> overridingMembers = new ArrayList<JetElement>();
|
||||
for (DescriptorClassMember selectedElement : selectedElements) {
|
||||
|
||||
-1
@@ -5,7 +5,6 @@ import bar.Other
|
||||
import bar.Bar
|
||||
|
||||
class Impl: Foo() {
|
||||
|
||||
override fun foo(list: ArrayList<Int>?, other: Other?): Bar? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ open class Base<A, B, C>() {
|
||||
}
|
||||
|
||||
class C : Base<String, C, Unit>() {
|
||||
|
||||
override fun bar(value: () -> Unit): (String) -> Unit {
|
||||
return super<Base>.bar(value)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ trait T {
|
||||
}
|
||||
|
||||
class C(t :T) : T by t {
|
||||
|
||||
override fun bar() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ trait T {
|
||||
}
|
||||
|
||||
class C : T {
|
||||
|
||||
override fun Foo(): (String) -> Unit {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait Trait {
|
||||
}
|
||||
|
||||
class TraitImpl : Trait {
|
||||
|
||||
override fun <A, B : Runnable, E : Map.Entry<A, B>> foo() where B : Cloneable, B : Comparable<B> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ trait Some<T> {
|
||||
}
|
||||
|
||||
class SomeOther<S> : Some<S> {
|
||||
|
||||
override fun someFoo() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait G<T> {
|
||||
}
|
||||
|
||||
class GC() : G<Int> {
|
||||
|
||||
override fun foo(t: Int): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// from KT-488
|
||||
|
||||
class MyClass<A: Comparable<A>> : Iterable<A> {
|
||||
|
||||
override fun iterator(): Iterator<A> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package foo
|
||||
|
||||
class Impl: B {
|
||||
|
||||
override fun foo(r: Runnable?) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ trait B {
|
||||
}
|
||||
|
||||
class C : A(), B {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<A>.equals(other)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import foo.Intf
|
||||
|
||||
class Impl(): Intf {
|
||||
|
||||
override fun getFooBar(): String? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
-1
@@ -3,7 +3,6 @@ package foo
|
||||
import foo.Intf
|
||||
|
||||
class Impl(): Intf() {
|
||||
|
||||
override fun getFooBar(): String? {
|
||||
return super<Intf>.getFooBar()
|
||||
}
|
||||
|
||||
-1
@@ -3,7 +3,6 @@ package foo
|
||||
import foo.Intf
|
||||
|
||||
class Impl(): Intf() {
|
||||
|
||||
override fun getFooBar(): String? {
|
||||
return super<Intf>.getFooBar()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import foo.Intf
|
||||
|
||||
class Impl(): Intf {
|
||||
|
||||
override fun fooBar(i: Int, s: Array<out String>?, foo: Any?) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ trait A {
|
||||
}
|
||||
|
||||
class C : A {
|
||||
|
||||
override fun bar(): String {
|
||||
return super<A>.bar()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A {
|
||||
}
|
||||
|
||||
class B : A {
|
||||
|
||||
override fun String.foo() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A {
|
||||
}
|
||||
|
||||
class B : A {
|
||||
|
||||
override val String.prop: Int
|
||||
get() = 0
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A<T> {
|
||||
}
|
||||
|
||||
class C : A<C> {
|
||||
|
||||
override fun foo(value: C) {
|
||||
super<A>.foo(value)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import foo.A
|
||||
|
||||
class C : A() {
|
||||
|
||||
override fun getAnswer(array: Array<out String>?, number: Int, value: Any?): Int {
|
||||
return super<A>.getAnswer(array, number, value)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A {
|
||||
}
|
||||
|
||||
class B : A {
|
||||
|
||||
override var Int.foo: Double
|
||||
get() = 0.0
|
||||
set(value) {
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A {
|
||||
}
|
||||
|
||||
class C : A {
|
||||
|
||||
override fun foo(value: String): Int {
|
||||
return super<A>.foo(value)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ class C : A() {
|
||||
override fun toString(): String {
|
||||
return super<A>.toString()
|
||||
}
|
||||
|
||||
/*
|
||||
Some another comment
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package foo
|
||||
|
||||
class Impl: B() {
|
||||
|
||||
override fun foo(r: Runnable?) {
|
||||
super<B>.foo(r)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait A {
|
||||
}
|
||||
|
||||
class C : A {
|
||||
|
||||
override fun foo(value: String) {
|
||||
super<A>.foo(value)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package foo
|
||||
|
||||
class Impl : Bar() {
|
||||
|
||||
override fun f(): Any {
|
||||
return super<Bar>.f()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@ trait T {
|
||||
}
|
||||
|
||||
class GC() : T {
|
||||
|
||||
override val v: Int = 0
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ class SomeTest : Test {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
override val testProp: Int = 0
|
||||
|
||||
/**
|
||||
* test
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import lib.ArrayFactory
|
||||
|
||||
public class Impl : ArrayFactory {
|
||||
|
||||
override fun create(): lib.Array {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait G<T> {
|
||||
}
|
||||
|
||||
class GC<T>() : G<T> {
|
||||
|
||||
override fun foo(t: T): T {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ trait Some {
|
||||
}
|
||||
|
||||
class SomeOther : Some {
|
||||
|
||||
override fun foo(some: Int?): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ public open class B() : A() {
|
||||
}
|
||||
|
||||
public open class C() : B() {
|
||||
|
||||
override fun foo() {
|
||||
super<B>.foo()
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import javax.swing.SwingUtilities
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
SwingUtilities.invokeLater(object : Runnable {
|
||||
|
||||
<caret> override fun run() {
|
||||
override fun run() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user