change extends <-> implements: ensure resulted list is formatted (IDEA-201751)

lists are created from light elements which are created from canonical texts and they just do not contain whitespaces
This commit is contained in:
Anna.Kozlova
2018-11-06 19:04:10 +01:00
parent b7c8e98770
commit 316f8bfc63
3 changed files with 14 additions and 3 deletions
@@ -22,6 +22,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
@@ -147,6 +148,7 @@ public class ExtendsListFix extends LocalQuickFixAndIntentionActionOnPsiElement
}
}
PsiReferenceList list = extendsList;
Project project = extendsList.getProject();
if (add && !alreadyExtends) {
PsiElement anchor;
if (position == -1) {
@@ -158,8 +160,7 @@ public class ExtendsListFix extends LocalQuickFixAndIntentionActionOnPsiElement
else {
anchor = referenceElements[position - 1];
}
PsiJavaCodeReferenceElement classReferenceElement =
JavaPsiFacade.getElementFactory(extendsList.getProject()).createReferenceElementByType(myTypeToExtendFrom);
PsiJavaCodeReferenceElement classReferenceElement = JavaPsiFacade.getElementFactory(project).createReferenceElementByType(myTypeToExtendFrom);
PsiElement element;
if (anchor == null) {
if (referenceElements.length == 0) {
@@ -180,6 +181,6 @@ public class ExtendsListFix extends LocalQuickFixAndIntentionActionOnPsiElement
return;
}
JavaCodeStyleManager.getInstance(extendsList.getProject()).shortenClassReferences(list);
CodeStyleManager.getInstance(project).reformat(JavaCodeStyleManager.getInstance(project).shortenClassReferences(list));
}
}
@@ -0,0 +1,5 @@
// "Change 'implements b' to 'extends b'" "true"
class a extends b<String, Integer> {
}
class b<T, K> {}
@@ -0,0 +1,5 @@
// "Change 'implements b' to 'extends b'" "true"
class a implements <caret>b<String, Integer> {
}
class b<T, K> {}