Search in sources :

Example 16 with PsiMetaData

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

the class DefaultLookupItemRenderer method getName.

private static String getName(final LookupItem item) {
    final String presentableText = item.getPresentableText();
    if (presentableText != null)
        return presentableText;
    final Object o = item.getObject();
    String name = null;
    if (o instanceof PsiElement) {
        final PsiElement element = (PsiElement) o;
        if (element.isValid()) {
            name = PsiUtilCore.getName(element);
        }
    } else if (o instanceof PsiMetaData) {
        name = ((PsiMetaData) o).getName();
    } else if (o instanceof PresentableLookupValue) {
        name = ((PresentableLookupValue) o).getPresentation();
    } else {
        name = String.valueOf(o);
    }
    if (name == null) {
        name = "";
    }
    return name;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiElement(com.intellij.psi.PsiElement)

Example 17 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 18 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 19 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 20 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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)

Aggregations

PsiMetaData (com.intellij.psi.meta.PsiMetaData)24 PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)10 XmlDocument (com.intellij.psi.xml.XmlDocument)5 NotNull (org.jetbrains.annotations.NotNull)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)3 TailType (com.intellij.codeInsight.TailType)2 Template (com.intellij.codeInsight.template.Template)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)2 JavaMethodCallElement (com.intellij.codeInsight.completion.JavaMethodCallElement)1