Search in sources :

Example 6 with DaemonCodeAnalyzerImpl

use of com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl in project intellij-community by JetBrains.

the class LightAdvHighlightingTest method testAnnotatorWorksWithFileLevel.

public void testAnnotatorWorksWithFileLevel() {
    Annotator annotator = new MyTopFileAnnotator();
    Language java = StdFileTypes.JAVA.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(java, annotator);
    try {
        List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
        assertTrue(list.toString(), list.contains(annotator));
        configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
        // whole file fit onscreen
        ((EditorEx) getEditor()).getScrollPane().getViewport().setSize(new Dimension(1000, 1000));
        doHighlighting();
        List<HighlightInfo> fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        HighlightInfo info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        type("\n\n");
        doHighlighting();
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        //disable top level annotation
        type("//xxx");
        List<HighlightInfo> warnings = doHighlighting(HighlightSeverity.WARNING);
        assertEmpty(warnings);
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        assertEmpty(fileLevel);
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(java, annotator);
    }
    List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
    assertFalse(list.toString(), list.contains(annotator));
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Language(com.intellij.lang.Language) Annotator(com.intellij.lang.annotation.Annotator) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)

Example 7 with DaemonCodeAnalyzerImpl

use of com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl in project intellij-community by JetBrains.

the class GroovyOptimizeImportsFix method timeToOptimizeImports.

private boolean timeToOptimizeImports(GroovyFile myFile, Editor editor) {
    if (!CodeInsightWorkspaceSettings.getInstance(myFile.getProject()).optimizeImportsOnTheFly)
        return false;
    if (onTheFly && editor != null) {
        // if we stand inside import statements, do not optimize
        final VirtualFile vfile = myFile.getVirtualFile();
        if (vfile != null && ProjectRootManager.getInstance(myFile.getProject()).getFileIndex().isInSource(vfile)) {
            final GrImportStatement[] imports = myFile.getImportStatements();
            if (imports.length > 0) {
                final int offset = editor.getCaretModel().getOffset();
                if (imports[0].getTextRange().getStartOffset() <= offset && offset <= imports[imports.length - 1].getTextRange().getEndOffset()) {
                    return false;
                }
            }
        }
    }
    DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myFile.getProject());
    if (!codeAnalyzer.isHighlightingAvailable(myFile))
        return false;
    if (!codeAnalyzer.isErrorAnalyzingFinished(myFile))
        return false;
    Document myDocument = PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile);
    boolean errors = containsErrorsPreventingOptimize(myFile, myDocument);
    return !errors && DaemonListeners.canChangeFileSilently(myFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) Document(com.intellij.openapi.editor.Document)

Aggregations

DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)7 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 ShowIntentionsPass (com.intellij.codeInsight.daemon.impl.ShowIntentionsPass)1 LookupEx (com.intellij.codeInsight.lookup.LookupEx)1 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)1 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 FlexMxmlNSDescriptor (com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor)1 Language (com.intellij.lang.Language)1 Annotator (com.intellij.lang.annotation.Annotator)1 Document (com.intellij.openapi.editor.Document)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)1 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)1