Search in sources :

Example 1 with PsiNameIdentifierOwner

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

the class RenameChangeInfo method perform.

public void perform() {
    final PsiNameIdentifierOwner element = getNamedElement();
    if (element != null) {
        final String name = element.getName();
        ApplicationManager.getApplication().runWriteAction(() -> {
            element.setName(myOldName);
        });
        new RenameProcessor(element.getProject(), element, name, false, false).run();
    }
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor)

Example 2 with PsiNameIdentifierOwner

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

the class NamedElementDuplicateHandler method findNameIdentifier.

@Nullable
private static PsiElement findNameIdentifier(Editor editor, PsiFile file, TextRange toDuplicate) {
    int nonWs = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), toDuplicate.getStartOffset(), "\n\t ");
    PsiElement psi = file.findElementAt(nonWs);
    PsiElement named = null;
    while (psi != null) {
        TextRange range = psi.getTextRange();
        if (range == null || psi instanceof PsiFile || !toDuplicate.contains(psi.getTextRange())) {
            break;
        }
        if (psi instanceof PsiNameIdentifierOwner) {
            named = ((PsiNameIdentifierOwner) psi).getNameIdentifier();
        }
        psi = psi.getParent();
    }
    return named;
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiNameIdentifierOwner

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

the class ChangeSignatureAction method findTargetMember.

@Nullable
private static PsiElement findTargetMember(@Nullable PsiElement element) {
    if (element == null)
        return null;
    final ChangeSignatureHandler fileHandler = getChangeSignatureHandler(element.getLanguage());
    if (fileHandler != null) {
        final PsiElement targetMember = fileHandler.findTargetMember(element);
        if (targetMember != null)
            return targetMember;
    }
    PsiReference reference = element.getReference();
    if (reference == null && element instanceof PsiNameIdentifierOwner) {
        return element;
    }
    if (reference != null) {
        return reference.resolve();
    }
    return null;
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) ChangeSignatureHandler(com.intellij.refactoring.changeSignature.ChangeSignatureHandler) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PsiNameIdentifierOwner

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

the class RelatedItemLineMarkerProvider method collectNavigationMarkers.

public void collectNavigationMarkers(List<PsiElement> elements, Collection<? super RelatedItemLineMarkerInfo> result, boolean forNavigation) {
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0, size = elements.size(); i < size; i++) {
        PsiElement element = elements.get(i);
        collectNavigationMarkers(element, result);
        if (forNavigation && element instanceof PsiNameIdentifierOwner) {
            PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
            if (nameIdentifier != null && !elements.contains(nameIdentifier)) {
                collectNavigationMarkers(nameIdentifier, result);
            }
        }
    }
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PsiNameIdentifierOwner

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

the class UnfocusedNameIdentifier method shouldFocusLookup.

@NotNull
@Override
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
    final PsiElement position = parameters.getPosition();
    final PsiElement parent = position.getParent();
    if (parent instanceof PsiNameIdentifierOwner) {
        final PsiElement nameIdentifier = ((PsiNameIdentifierOwner) parent).getNameIdentifier();
        if (nameIdentifier == position) {
            return ThreeState.NO;
        }
        if (nameIdentifier != null && position.getTextRange().equals(nameIdentifier.getTextRange())) {
            //sometimes name identifiers are non-physical (e.g. Groovy)
            return ThreeState.NO;
        }
    }
    return ThreeState.UNSURE;
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiNameIdentifierOwner (com.intellij.psi.PsiNameIdentifierOwner)7 PsiElement (com.intellij.psi.PsiElement)6 PsiReference (com.intellij.psi.PsiReference)2 NotNull (org.jetbrains.annotations.NotNull)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