Search in sources :

Example 81 with FileType

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

the class AboutHttpService method getAbout.

public static void getAbout(@NotNull OutputStream out, @Nullable QueryStringDecoder urlDecoder) throws IOException {
    JsonWriter writer = createJsonWriter(out);
    writer.beginObject();
    IdeAboutInfoUtil.writeAboutJson(writer);
    if (urlDecoder != null && getBooleanParameter("registeredFileTypes", urlDecoder)) {
        writer.name("registeredFileTypes").beginArray();
        for (FileType fileType : FileTypeRegistry.getInstance().getRegisteredFileTypes()) {
            writer.beginObject();
            writer.name("name").value(fileType.getName());
            writer.name("description").value(fileType.getDescription());
            writer.name("isBinary").value(fileType.isBinary());
            writer.endObject();
        }
        writer.endArray();
    }
    if (urlDecoder != null && getBooleanParameter("more", urlDecoder)) {
        ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
        writer.name("vendor").value(appInfo.getCompanyName());
        writer.name("isEAP").value(appInfo.isEAP());
        writer.name("productCode").value(appInfo.getBuild().getProductCode());
        writer.name("buildDate").value(appInfo.getBuildDate().getTime().getTime());
        writer.name("isSnapshot").value(appInfo.getBuild().isSnapshot());
        writer.name("configPath").value(PathManager.getConfigPath());
        writer.name("systemPath").value(PathManager.getSystemPath());
        writer.name("binPath").value(PathManager.getBinPath());
        writer.name("logPath").value(PathManager.getLogPath());
        writer.name("homePath").value(PathManager.getHomePath());
    }
    writer.endObject();
    writer.close();
}
Also used : ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) FileType(com.intellij.openapi.fileTypes.FileType) JsonWriter(com.google.gson.stream.JsonWriter)

Example 82 with FileType

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

the class DiffHttpService method readContent.

@Nullable
private static String readContent(@NotNull JsonReader reader, @NotNull List<DiffContent> contents, @NotNull List<String> titles, @Nullable String defaultFileTypeName) throws IOException {
    FileTypeRegistry fileTypeRegistry = FileTypeRegistry.getInstance();
    FileType defaultFileType = defaultFileTypeName == null ? null : fileTypeRegistry.findFileTypeByName(defaultFileTypeName);
    reader.beginArray();
    while (reader.hasNext()) {
        String title = null;
        String fileType = null;
        String content = null;
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("title")) {
                title = reader.nextString();
            } else if (name.equals("fileType")) {
                fileType = reader.nextString();
            } else if (name.equals("content")) {
                content = reader.nextString();
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        if (content == null) {
            return "content is not specified";
        }
        FileType type = fileType == null ? defaultFileType : fileTypeRegistry.findFileTypeByName(fileType);
        contents.add(DiffContentFactory.getInstance().create(content, type));
        titles.add(StringUtil.isEmptyOrSpaces(title) ? "" : title);
    }
    reader.endArray();
    return null;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with FileType

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

the class DiffUtil method createEditorHighlighter.

@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content) {
    FileType type = content.getContentType();
    VirtualFile file = content.getHighlightFile();
    Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
    EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
    if (language != null) {
        SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
        return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
    }
    if (file != null && file.isValid()) {
        if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
            return highlighterFactory.createEditorHighlighter(project, file);
        }
    }
    if (type != null) {
        return highlighterFactory.createEditorHighlighter(project, type);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Language(com.intellij.lang.Language) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) EditorHighlighterFactory(com.intellij.openapi.editor.highlighter.EditorHighlighterFactory)

Example 84 with FileType

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

the class DefaultCreateFromTemplateHandler method createFromTemplate.

@NotNull
@Override
public PsiElement createFromTemplate(final Project project, final PsiDirectory directory, String fileName, final FileTemplate template, final String templateText, @NotNull final Map<String, Object> props) throws IncorrectOperationException {
    fileName = checkAppendExtension(fileName, template);
    if (FileTypeManager.getInstance().isFileIgnored(fileName)) {
        throw new IncorrectOperationException("This filename is ignored (Settings | Editor | File Types | Ignore files and folders)");
    }
    directory.checkCreateFile(fileName);
    FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
    PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, type, templateText);
    if (template.isReformatCode()) {
        CodeStyleManager.getInstance(project).reformat(file);
    }
    file = (PsiFile) directory.add(file);
    return file;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with FileType

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

the class FileTemplateUtil method canCreateFromTemplate.

public static boolean canCreateFromTemplate(PsiDirectory[] dirs, FileTemplate template) {
    FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
    if (fileType.equals(FileTypes.UNKNOWN))
        return false;
    CreateFromTemplateHandler handler = findHandler(template);
    return handler.canCreate(dirs);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType)

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