Search in sources :

Example 96 with FileType

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

the class AndroidLintExternalAnnotator method doAnnotate.

@Override
public State doAnnotate(final State state) {
    final LintIdeClient client = LintIdeClient.forEditor(state);
    try {
        final LintDriver lint = new LintDriver(new LintIdeIssueRegistry(), 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 == StdFileTypes.JAVA) {
            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 == GroovyFileType.GROOVY_FILE_TYPE) {
            scope = Scope.GRADLE_SCOPE;
        } 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);
        LintRequest request = new LintIdeRequest(client, project, files, Collections.singletonList(state.getModule()), true);
        request.setScope(scope);
        lint.analyze(request);
    } finally {
        Disposer.dispose(client);
    }
    return state;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LintRequest(com.android.tools.lint.client.api.LintRequest) Project(com.intellij.openapi.project.Project) Scope(com.android.tools.lint.detector.api.Scope) GroovyFileType(org.jetbrains.plugins.groovy.GroovyFileType) FileType(com.intellij.openapi.fileTypes.FileType) LintDriver(com.android.tools.lint.client.api.LintDriver)

Example 97 with FileType

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

the class CfmlBraceMatcher method isLBraceToken.

public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final IElementType tokenType = iterator.getTokenType();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getLeftBraceType() == tokenType)
                return true;
        }
    }
    if (!tokenType.getLanguage().equals(CfmlLanguage.INSTANCE)) {
        FileType tokenFileType = iterator.getTokenType().getLanguage().getAssociatedFileType();
        if (tokenFileType != null && tokenFileType != CfmlFileType.INSTANCE) {
            for (FileTypeExtensionPoint<BraceMatcher> ext : Extensions.getExtensions(BraceMatcher.EP_NAME)) {
                if (ext.filetype != null && ext.filetype.equals(tokenFileType.getName())) {
                    return ext.getInstance().isLBraceToken(iterator, fileText, tokenFileType instanceof XmlFileType ? StdFileTypes.HTML : tokenFileType);
                }
            }
        }
    }
    for (BracePair pair : PAIRS) {
        if (pair.getLeftBraceType() == tokenType) {
            return true;
        }
    }
    return tokenType.equals(CfmlTokenTypes.OPENER) && (!CfmlUtil.isEndTagRequired(getTagName(fileText, iterator), null) || findEndTag(fileText, iterator));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) BracePair(com.intellij.lang.BracePair) XmlFileType(com.intellij.ide.highlighter.XmlFileType)

Example 98 with FileType

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

the class CfmlStructureViewTest method createStructureViewModel.

private StructureView createStructureViewModel() {
    VirtualFile virtualFile = myFixture.getFile().getVirtualFile();
    final FileType fileType = virtualFile.getFileType();
    final StructureViewBuilder structureViewBuilder;
    if (fileType == CfmlFileType.INSTANCE) {
        CfmlFileViewProvider viewProvider = (CfmlFileViewProvider) myFixture.getFile().getViewProvider();
        structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.forLanguage(viewProvider.getBaseLanguage()).getStructureViewBuilder(viewProvider.getPsi(viewProvider.getBaseLanguage()));
    } else {
        structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(fileType, virtualFile, getProject());
    }
    return structureViewBuilder.createStructureView(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile), getProject());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) CfmlFileViewProvider(com.intellij.coldFusion.model.files.CfmlFileViewProvider)

Example 99 with FileType

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

the class CallTreeTest method getTestXMLFile.

@NotNull
private XmlFile getTestXMLFile(String fileName) throws IOException {
    File file = new File(getTestDataPath() + File.separator + fileName);
    assertTrue("File doesn't exists " + fileName, file.exists());
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
    return (XmlFile) createLightFile(fileType, FileUtil.loadFile(file));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FileType(com.intellij.openapi.fileTypes.FileType) XmlFile(com.intellij.psi.xml.XmlFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with FileType

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

the class KarmaUtil method listPossibleConfigFilesInProject.

@NotNull
public static List<VirtualFile> listPossibleConfigFilesInProject(@NotNull Project project) {
    GlobalSearchScope contentScope = ProjectScope.getContentScope(project);
    GlobalSearchScope scope = contentScope.intersectWith(GlobalSearchScope.notScope(ProjectScope.getLibrariesScope(project)));
    List<VirtualFile> result = ContainerUtil.newArrayList();
    List<FileType> fileTypes = JavaScriptFileType.getFileTypesCompilableToJavaScript();
    for (FileType type : fileTypes) {
        Collection<VirtualFile> files = FileTypeIndex.getFiles(type, scope);
        for (VirtualFile file : files) {
            if (file != null && file.isValid() && !file.isDirectory() && isKarmaConfigFile(file.getNameSequence(), false)) {
                if (!JSLibraryUtil.isProbableLibraryFile(file)) {
                    result.add(file);
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JavaScriptFileType(com.intellij.lang.javascript.JavaScriptFileType) FileType(com.intellij.openapi.fileTypes.FileType) NotNull(org.jetbrains.annotations.NotNull)

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