Search in sources :

Example 6 with PsiMetaOwner

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

the class CachesBasedRefSearcher method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
    final PsiElement refElement = p.getElementToSearch();
    boolean caseSensitive = refElement.getLanguage().isCaseSensitive();
    String text = null;
    if (refElement instanceof PsiFileSystemItem && !(refElement instanceof SyntheticFileSystemItem)) {
        final VirtualFile vFile = ((PsiFileSystemItem) refElement).getVirtualFile();
        if (vFile != null) {
            text = vFile.getNameWithoutExtension();
        }
        // We must not look for file references with the file language's case-sensitivity, 
        // since case-sensitivity of the references themselves depends either on file system 
        // or on the rules of the language of reference
        caseSensitive = false;
    } else if (refElement instanceof PsiNamedElement) {
        text = ((PsiNamedElement) refElement).getName();
        if (refElement instanceof PsiMetaOwner) {
            final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
            if (metaData != null)
                text = metaData.getName();
        }
    }
    if (text == null && refElement instanceof PsiMetaOwner) {
        final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
        if (metaData != null)
            text = metaData.getName();
    }
    if (StringUtil.isNotEmpty(text)) {
        final SearchScope searchScope = p.getEffectiveSearchScope();
        p.getOptimizer().searchWord(text, searchScope, caseSensitive, refElement);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyntheticFileSystemItem(com.intellij.psi.impl.SyntheticFileSystemItem) PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiNamedElement(com.intellij.psi.PsiNamedElement) SearchScope(com.intellij.psi.search.SearchScope) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiMetaOwner

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

the class RenameUtil method getStringToReplace.

private static String getStringToReplace(PsiElement element, String newName, boolean nonJava, final RenamePsiElementProcessor theProcessor) {
    if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData != null) {
            return metaData.getName();
        }
    }
    if (theProcessor != null) {
        String result = theProcessor.getQualifiedNameAfterRename(element, newName, nonJava);
        if (result != null) {
            return result;
        }
    }
    if (element instanceof PsiNamedElement) {
        return newName;
    } else {
        LOG.error("Unknown element type : " + element);
        return null;
    }
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Example 8 with PsiMetaOwner

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

the class RenameUtil method doRenameGenericNamedElement.

public static void doRenameGenericNamedElement(@NotNull PsiElement namedElement, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
    PsiWritableMetaData writableMetaData = null;
    if (namedElement instanceof PsiMetaOwner) {
        final PsiMetaData metaData = ((PsiMetaOwner) namedElement).getMetaData();
        if (metaData instanceof PsiWritableMetaData) {
            writableMetaData = (PsiWritableMetaData) metaData;
        }
    }
    if (writableMetaData == null && !(namedElement instanceof PsiNamedElement)) {
        LOG.error("Unknown element type:" + namedElement);
    }
    boolean hasBindables = false;
    for (UsageInfo usage : usages) {
        if (!(usage.getReference() instanceof BindablePsiReference)) {
            rename(usage, newName);
        } else {
            hasBindables = true;
        }
    }
    if (writableMetaData != null) {
        writableMetaData.setName(newName);
    } else {
        PsiElement namedElementAfterRename = ((PsiNamedElement) namedElement).setName(newName);
        if (namedElementAfterRename != null)
            namedElement = namedElementAfterRename;
    }
    if (hasBindables) {
        for (UsageInfo usage : usages) {
            final PsiReference ref = usage.getReference();
            if (ref instanceof BindablePsiReference) {
                boolean fallback = true;
                if (!(ref instanceof FragmentaryPsiReference && ((FragmentaryPsiReference) ref).isFragmentOnlyRename())) {
                    try {
                        ref.bindToElement(namedElement);
                        fallback = false;
                    } catch (IncorrectOperationException ignored) {
                    }
                }
                if (fallback) {
                    //fall back to old scheme
                    ref.handleElementRename(newName);
                }
            }
        }
    }
    if (listener != null) {
        listener.elementRenamed(namedElement);
    }
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiWritableMetaData(com.intellij.psi.meta.PsiWritableMetaData) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) UsageInfo(com.intellij.usageView.UsageInfo) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Example 9 with PsiMetaOwner

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

the class DescriptiveNameUtil method getDescriptiveName.

@NotNull
public static String getDescriptiveName(@NotNull PsiElement psiElement) {
    LOG.assertTrue(psiElement.isValid());
    if (psiElement instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) psiElement;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData != null)
            return getMetaDataName(metaData);
    }
    if (psiElement instanceof PsiFile) {
        return ((PsiFile) psiElement).getName();
    }
    final Language lang = psiElement.getLanguage();
    final FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
    assert provider != null : lang;
    return provider.getDescriptiveName(psiElement);
}
Also used : Language(com.intellij.lang.Language) PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiFile(com.intellij.psi.PsiFile) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PsiMetaOwner

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

the class DomNameSuggestionProvider method getSuggestedNames.

@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, final PsiElement nameSuggestionContext, final Set<String> result) {
    if (element instanceof PsiMetaOwner) {
        final PsiMetaData psiMetaData = ((PsiMetaOwner) element).getMetaData();
        if (psiMetaData instanceof DomMetaData) {
            final DomMetaData domMetaData = (DomMetaData) psiMetaData;
            final GenericDomValue value = domMetaData.getNameElement(domMetaData.getElement());
            ContainerUtil.addIfNotNull(result, getNameFromNameValue(value, true));
        }
    }
    return null;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Aggregations

PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)12 PsiMetaData (com.intellij.psi.meta.PsiMetaData)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)2 PsiWritableMetaData (com.intellij.psi.meta.PsiWritableMetaData)2 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)2 XmlTag (com.intellij.psi.xml.XmlTag)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 Nullable (org.jetbrains.annotations.Nullable)2 EmptyResolveMessageProvider (com.intellij.codeInsight.daemon.EmptyResolveMessageProvider)1 LookupValueFactory (com.intellij.codeInsight.lookup.LookupValueFactory)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 Language (com.intellij.lang.Language)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)1