[java] clear deletion of reference expression qualifiers (IDEA-184557)

This commit is contained in:
Roman Shevchenko
2018-01-08 15:58:42 +01:00
parent d520056593
commit a61c8ba9e8
3 changed files with 34 additions and 5 deletions
@@ -21,6 +21,7 @@ import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
import com.intellij.psi.impl.source.SourceJavaCodeReference;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.impl.source.resolve.*;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.infos.CandidateInfo;
@@ -722,9 +723,19 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
if (getChildRole(child) == ChildRole.QUALIFIER) {
ASTNode dot = findChildByRole(ChildRole.DOT);
super.deleteChildInternal(child);
deleteChildInternal(dot);
ASTNode dot = findChildByType(JavaTokenType.DOT, child);
assert dot != null : this;
deleteChildRange(child.getPsi(), dot.getPsi());
ASTNode first = getFirstChildNode();
if (getChildRole(first) == ChildRole.REFERENCE_PARAMETER_LIST && first.getFirstChildNode() == null) {
ASTNode start = first.getTreeNext();
if (PsiImplUtil.isWhitespaceOrComment(start)) {
ASTNode next = PsiImplUtil.skipWhitespaceAndComments(start);
assert next != null : this;
CodeEditUtil.removeChildren(this, start, next.getTreePrev());
}
}
}
else if (child.getElementType() == JavaElementType.REFERENCE_PARAMETER_LIST) {
replaceChildInternal(child, createEmptyRefParameterList(getProject()));
@@ -3,6 +3,6 @@ import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.findVirtual(Types.class, "strMethod",<caret>);
lookup.findVirtual(Types.class, "strMethod", <caret>);
}
}
@@ -1,4 +1,6 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.java.psi
import com.intellij.openapi.command.WriteCommandAction
@@ -51,6 +53,22 @@ class JavaPsiTest extends LightCodeInsightFixtureTestCase {
assert statement.text == "exports pkg;"
}
void testReferenceQualifierDeletion() {
def file = configureFile("class C {\n Qualifier /*comment*/ . /*another*/ ref r;\n}")
def ref = file.classes[0].fields[0].typeElement.firstChild
assert ref != null
runCommand { ref.firstChild.delete() }
assert ref.text == "ref"
}
void testExpressionQualifierDeletion() {
def file = configureFile("class C {\n Object o = qualifier /*comment*/ . /*another*/ expr;\n}")
def expr = file.classes[0].fields[0].initializer
assert expr != null
runCommand { expr.firstChild.delete() }
assert expr.text == "expr"
}
private PsiJavaFile configureFile(String text) {
myFixture.configureByText("a.java", text) as PsiJavaFile
}