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));
}
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);
}
Aggregations