Search in sources :

Example 1 with FileType

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

the class PyMultiFileResolveTestCase method doResolve.

protected PsiElement doResolve(PsiFile psiFile) {
    final PsiReference ref = PyResolveTestCase.findReferenceByMarker(psiFile);
    final PsiManagerEx psiManager = (PsiManagerEx) myFixture.getPsiManager();
    psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() {

        @Override
        public boolean accept(VirtualFile file) {
            FileType fileType = file.getFileType();
            return fileType == PythonFileType.INSTANCE;
        }
    }, myFixture.getTestRootDisposable());
    final PsiElement result;
    if (ref instanceof PsiPolyVariantReference) {
        final ResolveResult[] resolveResults = ((PsiPolyVariantReference) ref).multiResolve(false);
        result = resolveResults.length == 0 || !resolveResults[0].isValidResult() ? null : resolveResults[0].getElement();
    } else {
        result = ref.resolve();
    }
    psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myFixture.getTestRootDisposable());
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) FileType(com.intellij.openapi.fileTypes.FileType) PythonFileType(com.jetbrains.python.PythonFileType) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 2 with FileType

use of com.intellij.openapi.fileTypes.FileType in project Main by SpartanRefactoring.

the class NanoPatternTipper method createUtilsFile.

@SuppressWarnings({ "OptionalGetWithoutIsPresent", "ResultOfMethodCallIgnored" })
private PsiFile createUtilsFile(PsiElement e, PsiDirectory d) throws IOException {
    URL is = getClass().getResource("/spartanizer/SpartanizerUtils.java");
    File file = new File(is.getPath());
    FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(file.getName());
    file.setReadable(true, false);
    String s = IOUtils.toString(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/spartanizer/SpartanizerUtils.java"))));
    PsiFile pf = PsiFileFactory.getInstance(e.getProject()).createFileFromText("SpartanizerUtils.java", type, s);
    d.add(pf);
    Arrays.stream(d.getFiles()).filter(f -> "SpartanizerUtils.java".equals(f.getName())).findFirst().get().getVirtualFile().setWritable(false);
    Toolbox.getInstance().excludeFile(pf);
    return pf;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileType(com.intellij.openapi.fileTypes.FileType) BufferedReader(java.io.BufferedReader) File(java.io.File) URL(java.net.URL)

Example 3 with FileType

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

the class KotlinTypedHandler method indentBrace.

/**
     * Copied from
     * @see com.intellij.codeInsight.editorActions.TypedHandler#indentBrace(Project, Editor, char)
     */
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, char braceChar) {
    final int offset = editor.getCaretModel().getOffset() - 1;
    Document document = editor.getDocument();
    CharSequence chars = document.getCharsSequence();
    if (offset < 0 || chars.charAt(offset) != braceChar)
        return;
    int spaceStart = CharArrayUtil.shiftBackward(chars, offset - 1, " \t");
    if (spaceStart < 0 || chars.charAt(spaceStart) == '\n' || chars.charAt(spaceStart) == '\r') {
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        documentManager.commitDocument(document);
        final PsiFile file = documentManager.getPsiFile(document);
        if (file == null || !file.isWritable())
            return;
        PsiElement element = file.findElementAt(offset);
        if (element == null)
            return;
        EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
        HighlighterIterator iterator = highlighter.createIterator(offset);
        FileType fileType = file.getFileType();
        BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
        boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || braceMatcher.isRBraceToken(iterator, chars, fileType);
        if (element.getNode() != null && isBrace) {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    int newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
                    editor.getCaretModel().moveToOffset(newOffset + 1);
                    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                    editor.getSelectionModel().removeSelection();
                }
            });
        }
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) Document(com.intellij.openapi.editor.Document) FileType(com.intellij.openapi.fileTypes.FileType) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 4 with FileType

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

the class JavaFxFileTypeFactory method createFileTypes.

@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
    final FileType fileType = consumer.getStandardFileTypeByName("XML");
    assert fileType != null;
    consumer.consume(fileType, FXML_EXTENSION);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType)

Example 5 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)

Aggregations

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