mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ensure no whitespaces/comments left after dequalify with type annotations (IDEA-165140)
This commit is contained in:
+10
-28
@@ -208,9 +208,16 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
assert dot != null : this;
|
||||
deleteChildRange(child.getPsi(), dot.getPsi());
|
||||
|
||||
List<PsiAnnotation> annotations = PsiTreeUtil.getChildrenOfTypeAsList(this, PsiAnnotation.class);
|
||||
setAnnotations(annotations);
|
||||
|
||||
PsiModifierList modifierList = PsiImplUtil.findNeighbourModifierList(this);
|
||||
if (modifierList != null) {
|
||||
ASTNode ref = findChildByRole(ChildRole.REFERENCE_NAME);
|
||||
assert ref != null : this;
|
||||
PsiElement lastChild = ref.getPsi().getPrevSibling();
|
||||
if (lastChild != null) {
|
||||
modifierList.addRange(getFirstChild(), lastChild);
|
||||
deleteChildRange(getFirstChild(), lastChild);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -614,31 +621,6 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
return annotations;
|
||||
}
|
||||
|
||||
private void setAnnotations(List<PsiAnnotation> annotations) {
|
||||
if (annotations.isEmpty()) return;
|
||||
|
||||
PsiElement newParent = this;
|
||||
PsiElement anchor = SourceTreeToPsiMap.treeElementToPsi(findChildByType(JavaTokenType.DOT));
|
||||
if (anchor == null) {
|
||||
PsiModifierList modifierList = PsiImplUtil.findNeighbourModifierList(this);
|
||||
if (modifierList != null) {
|
||||
newParent = modifierList;
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiAnnotation annotation : annotations) {
|
||||
if (annotation.getParent() != newParent) {
|
||||
if (anchor != null) {
|
||||
newParent.addAfter(annotation, anchor);
|
||||
}
|
||||
else {
|
||||
newParent.add(annotation);
|
||||
}
|
||||
annotation.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFullyQualified(@NotNull PsiFile containingFile) {
|
||||
int kind = getKind(containingFile);
|
||||
switch (kind) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface TA { }
|
||||
|
||||
class Test {
|
||||
private void bar(java.util.@TA List<String> na<caret>me) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import java.lang.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface TA { }
|
||||
|
||||
class Test {
|
||||
private void bar(@TA List<String> name) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+14
@@ -81,6 +81,20 @@ public class ShortenClassReferencesTest extends LightCodeInsightFixtureTestCase
|
||||
"class Outer1 {class Inner {} {boolean b = new Inner() instanceof Inner;}}");
|
||||
}
|
||||
|
||||
public void testWhiteSpaceForMovedTypeAnnotations() throws Exception {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
PsiElement elementAtCaret = myFixture.getElementAtCaret();
|
||||
assertTrue(elementAtCaret instanceof PsiParameter);
|
||||
WriteCommandAction.runWriteCommandAction(getProject(),
|
||||
() -> {
|
||||
PsiTypeElement typeElement = (PsiTypeElement)JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(((PsiParameter)elementAtCaret).getTypeElement());
|
||||
assertTrue(typeElement != null && typeElement.isValid());
|
||||
assertEquals("List<String>", typeElement.getText());
|
||||
});
|
||||
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
doShortenRefs();
|
||||
|
||||
Reference in New Issue
Block a user