use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class PythonCopyPasteProcessor method addLeadingSpacesToNormalizeSelection.
@NotNull
private static String addLeadingSpacesToNormalizeSelection(@NotNull Project project, @NotNull String text) {
if (!fragmentBeginsWithBlockStatement(text)) {
return text;
}
final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(project, "dummy.py", text, false);
//fragment.setContext(file);
final PyStatementListContainer statement = as(fragment.getFirstChild(), PyStatementListContainer.class);
if (statement == null) {
return text;
}
final String statementIndent = PyIndentUtil.getElementIndent(statement);
if (!statementIndent.isEmpty()) {
return text;
}
final String indentStep = PyIndentUtil.getIndentFromSettings(project);
final String bodyIndent = PyIndentUtil.getElementIndent(statement.getStatementList());
final String expectedBodyIndent = statementIndent + indentStep;
if (bodyIndent.startsWith(expectedBodyIndent)) {
return bodyIndent.substring(0, bodyIndent.length() - indentStep.length()) + text;
}
return text;
}
Aggregations