mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] clear deletion of reference expression qualifiers (IDEA-184557)
This commit is contained in:
+14
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user