Search in sources :

Example 6 with PsiNameIdentifierOwner

use of com.intellij.psi.PsiNameIdentifierOwner in project intellij-community by JetBrains.

the class PyRenameElementQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (element instanceof PyReferenceExpression) {
        final PsiReference reference = element.getReference();
        if (reference == null)
            return;
        element = reference.resolve();
    }
    final PsiNameIdentifierOwner nameOwner = element instanceof PsiNameIdentifierOwner ? (PsiNameIdentifierOwner) element : PsiTreeUtil.getParentOfType(element, PsiNameIdentifierOwner.class, true);
    if (nameOwner != null) {
        final VirtualFile virtualFile = nameOwner.getContainingFile().getVirtualFile();
        if (virtualFile != null) {
            final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
            if (ApplicationManager.getApplication().isUnitTestMode()) {
                renameInUnitTestMode(project, nameOwner, editor);
            } else {
                if (checkLocalScope(element) != null && (nameOwner instanceof PyNamedParameter || nameOwner instanceof PyTargetExpression)) {
                    new VariableInplaceRenamer(nameOwner, editor).performInplaceRename();
                } else {
                    PsiElementRenameHandler.invoke(nameOwner, project, ScopeUtil.getScopeOwner(nameOwner), editor);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) PsiReference(com.intellij.psi.PsiReference) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PyNamedParameter(com.jetbrains.python.psi.PyNamedParameter) Editor(com.intellij.openapi.editor.Editor) VariableInplaceRenamer(com.intellij.refactoring.rename.inplace.VariableInplaceRenamer) PsiElement(com.intellij.psi.PsiElement) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression)

Aggregations

PsiNameIdentifierOwner (com.intellij.psi.PsiNameIdentifierOwner)6 PsiElement (com.intellij.psi.PsiElement)5 PsiReference (com.intellij.psi.PsiReference)2 Nullable (org.jetbrains.annotations.Nullable)2 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 ChangeSignatureHandler (com.intellij.refactoring.changeSignature.ChangeSignatureHandler)1 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)1 VariableInplaceRenamer (com.intellij.refactoring.rename.inplace.VariableInplaceRenamer)1 PyNamedParameter (com.jetbrains.python.psi.PyNamedParameter)1 PyReferenceExpression (com.jetbrains.python.psi.PyReferenceExpression)1 PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)1 NotNull (org.jetbrains.annotations.NotNull)1