Search in sources :

Example 51 with ScopeOwner

use of com.jetbrains.python.codeInsight.controlflow.ScopeOwner in project intellij-community by JetBrains.

the class PyIntroduceParameterHandler method isNotDeclared.

private static boolean isNotDeclared(PsiElement element) {
    final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(element);
    final boolean[] isValid = { true };
    if (scopeOwner != null) {
        final String name = element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : element.getText();
        if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
            return false;
        }
        new PyRecursiveElementVisitor() {

            @Override
            public void visitPyReferenceExpression(PyReferenceExpression node) {
                super.visitPyReferenceExpression(node);
                final String name = node.getName();
                if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
                    isValid[0] = false;
                }
            }
        }.visitElement(element);
    }
    return !isResolvedToParameter(element) && isValid[0];
}
Also used : ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Aggregations

ScopeOwner (com.jetbrains.python.codeInsight.controlflow.ScopeOwner)51 PsiElement (com.intellij.psi.PsiElement)25 Nullable (org.jetbrains.annotations.Nullable)18 NotNull (org.jetbrains.annotations.NotNull)14 Pair (com.intellij.openapi.util.Pair)6 QualifiedName (com.intellij.psi.util.QualifiedName)6 ArrayList (java.util.ArrayList)6 Instruction (com.intellij.codeInsight.controlflow.Instruction)4 TextRange (com.intellij.openapi.util.TextRange)4 PsiFile (com.intellij.psi.PsiFile)4 Scope (com.jetbrains.python.codeInsight.dataflow.scope.Scope)4 List (java.util.List)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 Project (com.intellij.openapi.project.Project)3 Ref (com.intellij.openapi.util.Ref)3 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)3 CannotCreateCodeFragmentException (com.intellij.codeInsight.codeFragment.CannotCreateCodeFragmentException)2 ASTNode (com.intellij.lang.ASTNode)2