Search in sources :

Example 41 with PsiFileSystemItem

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

the class AntDomProperty method getNavigationElement.

public PsiElement getNavigationElement(final String propertyName) {
    DomTarget domTarget = DomTarget.getTarget(this);
    if (domTarget == null) {
        final GenericAttributeValue<String> environment = getEnvironment();
        if (environment.getRawText() != null) {
            domTarget = DomTarget.getTarget(this, environment);
        }
        if (domTarget == null) {
            final GenericAttributeValue<String> resource = getResource();
            if (resource.getRawText() != null) {
                domTarget = DomTarget.getTarget(this, resource);
            }
        }
    }
    if (domTarget != null) {
        final PsiElement psi = PomService.convertToPsi(domTarget);
        if (psi != null) {
            return psi;
        }
    }
    final PsiFileSystemItem psiFile = getFile().getValue();
    if (psiFile != null) {
        final String prefix = getPropertyPrefixValue();
        String _propertyName = propertyName;
        if (prefix != null) {
            if (!propertyName.startsWith(prefix)) {
                return null;
            }
            _propertyName = propertyName.substring(prefix.length());
        }
        final PropertiesFile pf = toPropertiesFile(psiFile);
        if (pf != null) {
            final IProperty property = pf.findPropertyByKey(_propertyName);
            return property != null ? property.getPsiElement() : null;
        }
    }
    return null;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) DomTarget(com.intellij.util.xml.DomTarget) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement)

Example 42 with PsiFileSystemItem

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

the class FilePathCompletionContributor method fileMatchesPathPrefix.

private static boolean fileMatchesPathPrefix(@Nullable final PsiFileSystemItem file, @NotNull final List<String> pathPrefix) {
    if (file == null)
        return false;
    final List<String> contextParts = new ArrayList<>();
    PsiFileSystemItem parentFile = file;
    PsiFileSystemItem parent;
    while ((parent = parentFile.getParent()) != null) {
        if (parent.getName().length() > 0)
            contextParts.add(0, parent.getName().toLowerCase());
        parentFile = parent;
    }
    final String path = StringUtil.join(contextParts, "/");
    int nextIndex = 0;
    for (@NonNls final String s : pathPrefix) {
        if ((nextIndex = path.indexOf(s.toLowerCase(), nextIndex)) == -1)
            return false;
    }
    return true;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 43 with PsiFileSystemItem

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

the class PsiFileSystemItemUtil method getRelativePath.

@Nullable
public static String getRelativePath(PsiFileSystemItem src, PsiFileSystemItem dst) {
    final PsiFileSystemItem commonAncestor = getCommonAncestor(src, dst);
    if (commonAncestor != null) {
        StringBuilder buffer = new StringBuilder();
        if (!src.equals(commonAncestor)) {
            while (!commonAncestor.equals(src.getParent())) {
                buffer.append("..").append('/');
                src = src.getParent();
                assert src != null;
            }
        }
        buffer.append(getRelativePathFromAncestor(dst, commonAncestor));
        return buffer.toString();
    }
    return null;
}
Also used : PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with PsiFileSystemItem

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

the class PsiFileSystemItemUtil method getRelativePathFromAncestor.

@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
    int length = 0;
    PsiFileSystemItem parent = file;
    while (true) {
        if (parent == null)
            return null;
        if (parent.equals(ancestor))
            break;
        if (length > 0) {
            length++;
        }
        String name = parent.getName();
        if (name == null) {
            throw new AssertionError("Null name for " + parent + " of " + parent.getClass());
        }
        length += name.length();
        parent = parent.getParent();
    }
    char[] chars = new char[length];
    int index = chars.length;
    parent = file;
    while (true) {
        if (parent.equals(ancestor))
            break;
        if (index < length) {
            chars[--index] = '/';
        }
        String name = parent.getName();
        for (int i = name.length() - 1; i >= 0; i--) {
            chars[--index] = name.charAt(i);
        }
        parent = parent.getParent();
    }
    return StringFactory.createShared(chars);
}
Also used : PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with PsiFileSystemItem

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

Aggregations

PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)60 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 Nullable (org.jetbrains.annotations.Nullable)20 PsiElement (com.intellij.psi.PsiElement)18 PsiFile (com.intellij.psi.PsiFile)18 Project (com.intellij.openapi.project.Project)14 PsiDirectory (com.intellij.psi.PsiDirectory)14 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ArrayList (java.util.ArrayList)5 PsiManager (com.intellij.psi.PsiManager)4 IProperty (com.intellij.lang.properties.IProperty)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 SearchScope (com.intellij.psi.search.SearchScope)2 QualifiedName (com.intellij.psi.util.QualifiedName)2 XmlFile (com.intellij.psi.xml.XmlFile)2