use of com.jetbrains.python.codeInsight.dataflow.scope.Scope in project intellij-community by JetBrains.
the class PyExtractMethodUtil method processNonlocalWrites.
private static void processNonlocalWrites(@NotNull PyFunction function, @NotNull PyCodeFragment fragment) {
final Set<String> nonlocalWrites = fragment.getNonlocalWrites();
final Set<String> newNonlocalNames = new LinkedHashSet<>();
final Scope scope = ControlFlowCache.getScope(function);
for (String name : nonlocalWrites) {
if (!scope.isNonlocal(name)) {
newNonlocalNames.add(name);
}
}
if (!newNonlocalNames.isEmpty()) {
final PyElementGenerator generator = PyElementGenerator.getInstance(function.getProject());
final PyNonlocalStatement nonlocalStatement = generator.createFromText(LanguageLevel.forElement(function), PyNonlocalStatement.class, "nonlocal " + StringUtil.join(newNonlocalNames, ", "));
final PyStatementList statementList = function.getStatementList();
statementList.addBefore(nonlocalStatement, statementList.getFirstChild());
}
}
Aggregations