|
14 | 14 | import com.intellij.util.IncorrectOperationException; |
15 | 15 | import com.jetbrains.php.lang.psi.elements.*; |
16 | 16 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; |
| 17 | +import fr.adrienbrault.idea.symfony2plugin.util.CodeUtil; |
17 | 18 | import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil; |
18 | 19 | import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils; |
19 | 20 | import icons.SymfonyIcons; |
@@ -74,61 +75,8 @@ private void removeCommandExtends(@NotNull PhpClass phpClass) { |
74 | 75 | return; |
75 | 76 | } |
76 | 77 |
|
77 | | - // Navigate the PSI tree to find the extends clause |
78 | | - var extendsList = phpClass.getExtendsList(); |
79 | | - |
80 | | - List<ClassReference> references = extendsList.getReferenceElements(); |
81 | | - if (references.isEmpty()) { |
82 | | - return; |
83 | | - } |
84 | | - |
85 | | - // Find the Command reference |
86 | | - ClassReference commandRef = null; |
87 | | - for (ClassReference classRef : references) { |
88 | | - PhpClass resolvedClass = (PhpClass) classRef.resolve(); |
89 | | - if (resolvedClass != null && "\\Symfony\\Component\\Console\\Command\\Command".equals(resolvedClass.getFQN())) { |
90 | | - commandRef = classRef; |
91 | | - break; |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - if (commandRef == null) { |
96 | | - return; |
97 | | - } |
98 | | - |
99 | | - // If this is the only extends, remove the entire extends clause using Document API |
100 | | - // This avoids PSI null issues by editing at the text level |
101 | | - if (references.size() == 1) { |
102 | | - // Find whitespace before the extends list - we want to delete from there |
103 | | - // to include any spaces between the class name and "extends" |
104 | | - PsiElement startElement = extendsList; |
105 | | - PsiElement prev = extendsList.getPrevSibling(); |
106 | | - |
107 | | - // Skip backwards through whitespace to find the actual start |
108 | | - while (prev != null && (prev.getText().trim().isEmpty() || "extends".equals(prev.getText().trim()))) { |
109 | | - startElement = prev; |
110 | | - prev = prev.getPrevSibling(); |
111 | | - } |
112 | | - |
113 | | - // Use Document API to delete the text range |
114 | | - PsiFile file = phpClass.getContainingFile(); |
115 | | - Document document = PsiDocumentManager.getInstance(phpClass.getProject()).getDocument(file); |
116 | | - |
117 | | - if (document != null) { |
118 | | - int startOffset = startElement.getTextRange().getStartOffset(); |
119 | | - int endOffset = extendsList.getTextRange().getEndOffset(); |
120 | | - |
121 | | - document.deleteString(startOffset, endOffset); |
122 | | - |
123 | | - // Commit and synchronize PSI |
124 | | - PsiDocumentManager psiDocManager = PsiDocumentManager.getInstance(phpClass.getProject()); |
125 | | - psiDocManager.commitDocument(document); |
126 | | - psiDocManager.doPostponedOperationsAndUnblockDocument(document); |
127 | | - } |
128 | | - } else { |
129 | | - // Multiple extends, just remove this one reference (PSI deletion is safe here) |
130 | | - commandRef.delete(); |
131 | | - } |
| 78 | + // Use shared utility method to remove the extends clause |
| 79 | + CodeUtil.removeExtendsClause(phpClass, "\\Symfony\\Component\\Console\\Command\\Command"); |
132 | 80 | } |
133 | 81 |
|
134 | 82 | private void optimizeImports(@NotNull PsiFile file) { |
|
0 commit comments