PY-61639 Move PyPreFormatProcessor to python.syntax.core

GitOrigin-RevId: 4832fe901219342bb7f1babf41280830e16fec49
This commit is contained in:
Petr
2024-02-10 18:08:47 +01:00
committed by intellij-monorepo-bot
parent f075a5653e
commit 2c7f5b4b32
3 changed files with 7 additions and 7 deletions

View File

@@ -67,7 +67,6 @@
implementationClass="com.jetbrains.python.psi.impl.references.PyKeywordPatternManipulator"/>
<lang.parserDefinition language="Python" implementationClass="com.jetbrains.python.PythonParserDefinition"/>
<preFormatProcessor implementation="com.jetbrains.python.formatter.PyPreFormatProcessor"/>
<postFormatProcessor implementation="com.jetbrains.python.formatter.PyTrailingBlankLinesPostFormatProcessor"/>
<postFormatProcessor implementation="com.jetbrains.python.formatter.PyFromImportPostFormatProcessor"/>
<lang.lineWrapStrategy language="Python" implementationClass="com.jetbrains.python.formatter.PyLineWrapPositionStrategy"/>

View File

@@ -10,5 +10,6 @@
serviceImplementation="com.jetbrains.python.PythonCodeStyleServiceImpl"/>
<lang.formatter language="Python" implementationClass="com.jetbrains.python.formatter.PythonFormattingModelBuilder"/>
<preFormatProcessor implementation="com.jetbrains.python.formatter.PyPreFormatProcessor"/>
</extensions>
</idea-plugin>

View File

@@ -11,10 +11,10 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.codeStyle.PreFormatProcessor;
import com.jetbrains.python.PythonLanguage;
import com.jetbrains.python.ast.PyAstRecursiveElementVisitor;
import com.jetbrains.python.ast.impl.PyPsiUtilsCore;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyElementGenerator;
import com.jetbrains.python.psi.PyRecursiveElementVisitor;
import com.jetbrains.python.psi.impl.PyPsiUtils;
import com.jetbrains.python.psi.PyAstElementGenerator;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -29,7 +29,7 @@ public final class PyPreFormatProcessor implements PreFormatProcessor {
if (!psiElement.getLanguage().is(PythonLanguage.getInstance())) return range;
PyPsiUtils.assertValid(psiElement);
PyPsiUtilsCore.assertValid(psiElement);
PsiFile file = psiElement.isValid() ? psiElement.getContainingFile() : null;
if (file == null) return range;
@@ -37,7 +37,7 @@ public final class PyPreFormatProcessor implements PreFormatProcessor {
return new PyCommentFormatter(file).process(psiElement, range);
}
public static class PyCommentFormatter extends PyRecursiveElementVisitor {
public static class PyCommentFormatter extends PyAstRecursiveElementVisitor {
private final Project myProject;
private final PyCodeStyleSettings myPyCodeStyleSettings;
private final List<Couple<PsiComment>> myCommentReplacements = new ArrayList<>();
@@ -94,7 +94,7 @@ public final class PyPreFormatProcessor implements PreFormatProcessor {
}
if (!newText.equals(origText)) {
myDelta += newText.length() - origText.length();
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(myProject);
final PyAstElementGenerator elementGenerator = PyAstElementGenerator.getInstance(myProject);
final PsiComment newComment = elementGenerator.createFromText(LanguageLevel.forElement(comment), PsiComment.class, newText);
myCommentReplacements.add(Couple.of(comment, newComment));
}