PSI: Delete succeeding semicolon along with KtElement
#KT-5487 Fixed
This commit is contained in:
@@ -110,7 +110,7 @@ abstract public class KtClassOrObject :
|
|||||||
|
|
||||||
val file = getContainingKtFile();
|
val file = getContainingKtFile();
|
||||||
if (!isTopLevel() || file.getDeclarations().size() > 1) {
|
if (!isTopLevel() || file.getDeclarations().size() > 1) {
|
||||||
CodeEditUtil.removeChild(getParent().getNode(), getNode());
|
super.delete()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile;
|
|||||||
import com.intellij.psi.PsiReference;
|
import com.intellij.psi.PsiReference;
|
||||||
import com.intellij.psi.PsiReferenceService;
|
import com.intellij.psi.PsiReferenceService;
|
||||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||||
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||||
|
|
||||||
@@ -71,6 +72,12 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
|
|||||||
return visitor.visitKtElement(this, data);
|
return visitor.visitKtElement(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete() throws IncorrectOperationException {
|
||||||
|
KtElementUtilsKt.deleteSemicolon(this);
|
||||||
|
super.delete();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiReference getReference() {
|
public PsiReference getReference() {
|
||||||
PsiReference[] references = getReferences();
|
PsiReference[] references = getReferences();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||||
import com.intellij.psi.stubs.IStubElementType;
|
import com.intellij.psi.stubs.IStubElementType;
|
||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementType;
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementType;
|
||||||
@@ -85,6 +86,12 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
|
|||||||
return visitor.visitKtElement(this, data);
|
return visitor.visitKtElement(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete() throws IncorrectOperationException {
|
||||||
|
KtElementUtilsKt.deleteSemicolon(this);
|
||||||
|
super.delete();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiReference getReference() {
|
public PsiReference getReference() {
|
||||||
PsiReference[] references = getReferences();
|
PsiReference[] references = getReferences();
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.psi
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiComment
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
|
||||||
|
internal fun KtElement.deleteSemicolon() {
|
||||||
|
if (this is KtEnumEntry) return
|
||||||
|
|
||||||
|
val sibling = PsiTreeUtil.skipSiblingsForward(this, PsiWhiteSpace::class.java, PsiComment::class.java)
|
||||||
|
if (sibling == null || sibling.node.elementType != KtTokens.SEMICOLON) return
|
||||||
|
|
||||||
|
val lastSiblingToDelete = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace::class.java)?.prevSibling ?: sibling
|
||||||
|
parent?.deleteChildRange(nextSibling, lastSiblingToDelete)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun f() {
|
||||||
|
val <caret>x = 5;
|
||||||
|
println(x + x)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
println(5 + 5)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun f() {
|
||||||
|
val <caret>x = 5 /**/ ;
|
||||||
|
println(x + x)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
println(5 + 5)
|
||||||
|
}
|
||||||
@@ -95,6 +95,18 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("semicolon.kt")
|
||||||
|
public void testSemicolon() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/semicolon.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("semicolonWithSpacesAndComments.kt")
|
||||||
|
public void testSemicolonWithSpacesAndComments() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/semicolonWithSpacesAndComments.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("SeparateInitializer.kt")
|
@TestMetadata("SeparateInitializer.kt")
|
||||||
public void testSeparateInitializer() throws Exception {
|
public void testSeparateInitializer() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/SeparateInitializer.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/SeparateInitializer.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user