Search in sources :

Example 91 with FileType

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

the class LanguageTextField method createEditor.

@Override
protected EditorEx createEditor() {
    final EditorEx ex = super.createEditor();
    if (myLanguage != null) {
        final FileType fileType = myLanguage.getAssociatedFileType();
        ex.setHighlighter(HighlighterFactory.createHighlighter(myProject, fileType));
    }
    ex.setEmbeddedIntoDialogWrapper(true);
    return ex;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) FileType(com.intellij.openapi.fileTypes.FileType)

Example 92 with FileType

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

the class TodoIndex method getVersion.

@Override
public int getVersion() {
    int version = 9;
    FileType[] types = myFileTypeManager.getRegisteredFileTypes();
    Arrays.sort(types, (o1, o2) -> Comparing.compare(o1.getName(), o2.getName()));
    for (FileType fileType : types) {
        DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = TodoIndexers.INSTANCE.forFileType(fileType);
        if (indexer == null)
            continue;
        int versionFromIndexer = indexer instanceof VersionedTodoIndexer ? (((VersionedTodoIndexer) indexer).getVersion()) : 0xFF;
        version = version * 31 + (versionFromIndexer ^ indexer.getClass().getName().hashCode());
    }
    return version;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType)

Example 93 with FileType

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

the class AndroidLintExternalAnnotator method doAnnotate.

@Override
public State doAnnotate(final State state) {
    final IntellijLintClient client = IntellijLintClient.forEditor(state);
    try {
        final LintDriver lint = new LintDriver(new IntellijLintIssueRegistry(), client);
        EnumSet<Scope> scope;
        VirtualFile mainFile = state.getMainFile();
        final FileType fileType = mainFile.getFileType();
        String name = mainFile.getName();
        if (fileType == StdFileTypes.XML) {
            if (name.equals(ANDROID_MANIFEST_XML)) {
                scope = Scope.MANIFEST_SCOPE;
            } else {
                scope = Scope.RESOURCE_FILE_SCOPE;
            }
        } else if (fileType == KotlinFileType.INSTANCE) {
            scope = Scope.JAVA_FILE_SCOPE;
        } else if (name.equals(OLD_PROGUARD_FILE) || name.equals(FN_PROJECT_PROGUARD_FILE)) {
            scope = EnumSet.of(Scope.PROGUARD_FILE);
        } else if (fileType == StdFileTypes.PROPERTIES) {
            scope = Scope.PROPERTY_SCOPE;
        } else {
            // #collectionInformation above should have prevented this
            assert false;
            return state;
        }
        Project project = state.getModule().getProject();
        if (project.isDisposed()) {
            return state;
        }
        List<VirtualFile> files = Collections.singletonList(mainFile);
        final LintRequest request = new IntellijLintRequest(client, project, files, Collections.singletonList(state.getModule()), true);
        request.setScope(scope);
        ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(new Runnable() {

            @Override
            public void run() {
                lint.analyze(request);
            }
        });
    } finally {
        Disposer.dispose(client);
    }
    return state;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LintRequest(com.android.tools.klint.client.api.LintRequest) Project(com.intellij.openapi.project.Project) Scope(com.android.tools.klint.detector.api.Scope) KotlinFileType(org.jetbrains.kotlin.idea.KotlinFileType) FileType(com.intellij.openapi.fileTypes.FileType) LintDriver(com.android.tools.klint.client.api.LintDriver)

Example 94 with FileType

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

the class AndroidLintExternalAnnotator method collectInformation.

@Override
public State collectInformation(@NotNull PsiFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return null;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null && !IntellijLintProject.hasAndroidModule(module.getProject())) {
        return null;
    }
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) {
        return null;
    }
    final FileType fileType = file.getFileType();
    if (fileType == FileTypes.PLAIN_TEXT) {
        if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
            return null;
        }
    } else if (fileType != KotlinFileType.INSTANCE && fileType != StdFileTypes.PROPERTIES) {
        return null;
    }
    final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
    if (issues.size() == 0) {
        return null;
    }
    return new State(module, vFile, file.getText(), issues);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Issue(com.android.tools.klint.detector.api.Issue) KotlinFileType(org.jetbrains.kotlin.idea.KotlinFileType) FileType(com.intellij.openapi.fileTypes.FileType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 95 with FileType

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

the class AbstractQuickFixMultiFileTest method createVirtualFileFromTestFile.

/**
     * @param sourceRootDir Base path of test file(Test source directory)
     * @param testFile      source of VFile content
     * @return created VirtualFile
     */
protected static VirtualFile createVirtualFileFromTestFile(File sourceRootDir, final TestFile testFile) {
    try {
        assertFalse("Please don't use absolute path for multifile test 'FILE' directive: " + testFile.path, FileUtil.isAbsolutePlatformIndependent(testFile.path));
        FileType fileType = guessFileType(testFile);
        String extension = fileType.getDefaultExtension();
        final File fileInSourceRoot = new File(testFile.path);
        File container = FileUtil.getParentFile(fileInSourceRoot);
        if (container == null) {
            container = sourceRootDir;
        } else {
            container = new File(sourceRootDir, container.getPath());
        }
        if (!container.exists()) {
            assertTrue(container.mkdirs());
        }
        final File tempFile = FileUtil.createTempFile(container, FileUtil.getNameWithoutExtension(testFile.path), "." + extension, true);
        final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
        assert vFile != null;
        new WriteAction() {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                vFile.setCharset(CharsetToolkit.UTF8_CHARSET);
                VfsUtil.saveText(vFile, testFile.content);
            }
        }.execute();
        return vFile;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) KotlinFileType(org.jetbrains.kotlin.idea.KotlinFileType) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) JavaFileType(com.intellij.ide.highlighter.JavaFileType) FileType(com.intellij.openapi.fileTypes.FileType) WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

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