Search in sources :

Example 61 with FileType

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

the class DetectAndAdjustIndentOptionsTask method getDefaultIndentOptions.

@NotNull
public static TimeStampedIndentOptions getDefaultIndentOptions(@NotNull PsiFile file, @NotNull Document document) {
    Project project = file.getProject();
    FileType fileType = file.getFileType();
    CodeStyleSettings manager = CodeStyleSettingsManager.getSettings(project);
    return new TimeStampedIndentOptions(manager.getIndentOptions(fileType), document.getModificationStamp());
}
Also used : Project(com.intellij.openapi.project.Project) FileType(com.intellij.openapi.fileTypes.FileType) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with FileType

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

the class CompletionUtil method getCompletionDataByElement.

@Nullable
public static CompletionData getCompletionDataByElement(@Nullable final PsiElement position, @NotNull PsiFile originalFile) {
    if (position == null)
        return null;
    PsiElement parent = position.getParent();
    Language language = parent == null ? position.getLanguage() : parent.getLanguage();
    final FileType fileType = language.getAssociatedFileType();
    if (fileType != null) {
        final CompletionData mainData = getCompletionDataByFileType(fileType);
        if (mainData != null) {
            return mainData;
        }
    }
    final CompletionData mainData = getCompletionDataByFileType(originalFile.getFileType());
    return mainData != null ? mainData : ourGenericCompletionData;
}
Also used : Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LookupValueWithPsiElement(com.intellij.codeInsight.lookup.LookupValueWithPsiElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with FileType

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

the class TypedHandler method getQuoteHandler.

@Nullable
public static QuoteHandler getQuoteHandler(@NotNull PsiFile file, @NotNull Editor editor) {
    FileType fileType = getFileType(file, editor);
    QuoteHandler quoteHandler = getQuoteHandlerForType(fileType);
    if (quoteHandler == null) {
        FileType fileFileType = file.getFileType();
        if (fileFileType != fileType) {
            quoteHandler = getQuoteHandlerForType(fileFileType);
        }
    }
    if (quoteHandler == null) {
        return getLanguageQuoteHandler(file.getViewProvider().getBaseLanguage());
    }
    return quoteHandler;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with FileType

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

the class CommentByLineCommentHandler method findCommenter.

@Nullable
private static Commenter findCommenter(Editor editor, PsiFile file, final int line) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof AbstractFileType) {
        return ((AbstractFileType) fileType).getCommenter();
    }
    Document document = editor.getDocument();
    int lineStartOffset = document.getLineStartOffset(line);
    int lineEndOffset = document.getLineEndOffset(line) - 1;
    final CharSequence charSequence = document.getCharsSequence();
    lineStartOffset = Math.max(0, CharArrayUtil.shiftForward(charSequence, lineStartOffset, " \t"));
    lineEndOffset = Math.max(0, CharArrayUtil.shiftBackward(charSequence, lineEndOffset < 0 ? 0 : lineEndOffset, " \t"));
    final Language lineStartLanguage = PsiUtilCore.getLanguageAtOffset(file, lineStartOffset);
    final Language lineEndLanguage = PsiUtilCore.getLanguageAtOffset(file, lineEndOffset);
    return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage);
}
Also used : AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 65 with FileType

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

the class CommentByBlockCommentHandler method findCommenter.

@Nullable
private static Commenter findCommenter(PsiFile file, Editor editor, Caret caret) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof AbstractFileType) {
        return ((AbstractFileType) fileType).getCommenter();
    }
    Language lang = PsiUtilBase.getLanguageInEditor(caret, file.getProject());
    return getCommenter(file, editor, lang, lang);
}
Also used : AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

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