Search in sources :

Example 6 with FileType

use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.

the class JavaFxLocationReferenceProvider method collectRefs.

private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
    final int atSignIndex = value.indexOf('@');
    if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
        value = value.substring(atSignIndex + 1);
        startInElement += atSignIndex + 1;
    }
    final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {

        @Override
        protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
            return item -> {
                if (item instanceof PsiDirectory)
                    return true;
                final VirtualFile virtualFile = item.getVirtualFile();
                if (virtualFile == null)
                    return false;
                final FileType fileType = virtualFile.getFileType();
                return myAcceptedFileTypes.contains(fileType);
            };
        }
    };
    if (value.startsWith("/")) {
        set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
    }
    return set.getAllReferences();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) FileType(com.intellij.openapi.fileTypes.FileType) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) ArrayList(java.util.ArrayList) List(java.util.List) com.intellij.psi(com.intellij.psi) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)

Example 7 with FileType

use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.

the class ResourceBundleEditorProvider method accept.

@Override
public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) {
    if (file instanceof ResourceBundleAsVirtualFile)
        return true;
    if (!file.isValid())
        return false;
    final FileType type = file.getFileType();
    if (type != StdFileTypes.PROPERTIES && type != StdFileTypes.XML)
        return false;
    return ReadAction.compute(() -> {
        if (project.isDisposed())
            return Boolean.FALSE;
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
        return propertiesFile != null && propertiesFile.getResourceBundle().getPropertiesFiles().size() > 1;
    });
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 8 with FileType

use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.

the class SelectorBasedResponseHandler method getConfigurationComponent.

@NotNull
@Override
public JComponent getConfigurationComponent(@NotNull Project project) {
    FileType fileType = getResponseType().getSelectorFileType();
    HighlightedSelectorsTable table = new HighlightedSelectorsTable(fileType, project, getSelectors());
    return new JBScrollPane(table);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) JBScrollPane(com.intellij.ui.components.JBScrollPane) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with FileType

use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.

the class CustomRegexpFilter method createOpenFileHyperlink.

protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, int column) {
    if ((fileName == null || fileName.length() == 0)) {
        if (myBase != null) {
            fileName = myBase.getPresentableUrl();
        } else {
            return null;
        }
    }
    fileName = fileName.replace(File.separatorChar, '/');
    VirtualFile file;
    // try to interpret the filename as URL
    if (URLUtil.containsScheme(fileName)) {
        try {
            file = VfsUtil.findFileByURL(new URL(fileName));
        } catch (MalformedURLException e) {
            file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(fileName));
        }
    } else {
        file = VfsUtil.findRelativeFile(fileName, myBase);
    }
    if (file == null) {
        //noinspection ConstantConditions
        return null;
    }
    final FileType fileType = file.getFileType();
    if (fileType != null && column > 0) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        final int start = document.getLineStartOffset(line);
        final int max = document.getLineEndOffset(line);
        final int tabSize = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getTabSize(fileType);
        column = EditorUtil.calcColumnNumber(null, document.getCharsSequence(), start, Math.min(start + column, max), tabSize);
    }
    return new OpenFileHyperlinkInfo(myProject, file, line, column);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) FileType(com.intellij.openapi.fileTypes.FileType) Document(com.intellij.openapi.editor.Document) URL(java.net.URL)

Example 10 with FileType

use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.

the class ConfigFilesTreeBuilder method buildModuleNodes.

public Set<PsiFile> buildModuleNodes(final MultiMap<Module, PsiFile> files, final MultiMap<VirtualFile, PsiFile> jars, DefaultMutableTreeNode root) {
    final HashSet<PsiFile> psiFiles = new HashSet<>();
    final List<Module> modules = new ArrayList<>(files.keySet());
    Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
    for (Module module : modules) {
        DefaultMutableTreeNode moduleNode = createFileNode(module);
        root.add(moduleNode);
        if (files.containsKey(module)) {
            List<PsiFile> moduleFiles = new ArrayList<>(files.get(module));
            MultiMap<FileType, PsiFile> filesByType = new MultiMap<>();
            for (PsiFile file : moduleFiles) {
                filesByType.putValue(file.getFileType(), file);
            }
            if (hasNonEmptyGroups(filesByType)) {
                for (Map.Entry<FileType, Collection<PsiFile>> entry : filesByType.entrySet()) {
                    DefaultMutableTreeNode fileTypeNode = createFileNode(entry.getKey());
                    moduleNode.add(fileTypeNode);
                    addChildrenFiles(psiFiles, fileTypeNode, new ArrayList<>(entry.getValue()));
                }
            } else {
                addChildrenFiles(psiFiles, moduleNode, moduleFiles);
            }
        }
    }
    List<VirtualFile> sortedJars = new ArrayList<>(jars.keySet());
    Collections.sort(sortedJars, (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName()));
    for (VirtualFile file : sortedJars) {
        if (!file.isValid())
            continue;
        final List<PsiFile> list = new ArrayList<>(jars.get(file));
        final PsiFile jar = list.get(0).getManager().findFile(file);
        if (jar != null) {
            final DefaultMutableTreeNode jarNode = createFileNode(jar);
            root.add(jarNode);
            Collections.sort(list, FILE_COMPARATOR);
            for (PsiFile psiFile : list) {
                jarNode.add(createFileNode(psiFile));
                psiFiles.add(psiFile);
            }
        }
    }
    return psiFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MultiMap(com.intellij.util.containers.MultiMap) FileType(com.intellij.openapi.fileTypes.FileType) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

FileType (com.intellij.openapi.fileTypes.FileType)198 VirtualFile (com.intellij.openapi.vfs.VirtualFile)60 NotNull (org.jetbrains.annotations.NotNull)38 Language (com.intellij.lang.Language)31 PsiFile (com.intellij.psi.PsiFile)31 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)30 Nullable (org.jetbrains.annotations.Nullable)28 Project (com.intellij.openapi.project.Project)27 Document (com.intellij.openapi.editor.Document)20 IncorrectOperationException (com.intellij.util.IncorrectOperationException)13 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 Editor (com.intellij.openapi.editor.Editor)10 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)10 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)10 PlainTextFileType (com.intellij.openapi.fileTypes.PlainTextFileType)9 UnknownFileType (com.intellij.openapi.fileTypes.UnknownFileType)9 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)8 AbstractFileType (com.intellij.openapi.fileTypes.impl.AbstractFileType)8 PsiElement (com.intellij.psi.PsiElement)8