com.intellij.openapi.fileTypes.SyntaxHighlighter Java Examples
The following examples show how to use
com.intellij.openapi.fileTypes.SyntaxHighlighter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleViewUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void printWithHighlighting(@Nonnull ConsoleView console, @Nonnull String text, @Nonnull SyntaxHighlighter highlighter, Runnable doOnNewLine) { Lexer lexer = highlighter.getHighlightingLexer(); lexer.start(text, 0, text.length(), 0); IElementType tokenType; while ((tokenType = lexer.getTokenType()) != null) { ConsoleViewContentType contentType = getContentTypeForToken(tokenType, highlighter); StringTokenizer eolTokenizer = new StringTokenizer(lexer.getTokenText(), "\n", true); while (eolTokenizer.hasMoreTokens()) { String tok = eolTokenizer.nextToken(); console.print(tok, contentType); if (doOnNewLine != null && "\n".equals(tok)) { doOnNewLine.run(); } } lexer.advance(); } }
Example #2
Source File: DiffUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @Nonnull 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) { 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; }
Example #3
Source File: LatteEditorHighlighter.java From intellij-latte with MIT License | 6 votes |
public LatteEditorHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { super(new LatteSyntaxHighlighter() { @Override public @NotNull Lexer getHighlightingLexer() { return new LatteHtmlHighlightingLexer(super.getHighlightingLexer()); } }, colors); final SyntaxHighlighter highlighter = getHighlighter(project, virtualFile); this.registerLayer(LatteTypes.T_TEXT, new LayerDescriptor(new SyntaxHighlighter() { @NotNull public Lexer getHighlightingLexer() { return highlighter.getHighlightingLexer(); } @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return highlighter.getTokenHighlights(tokenType); } }, "")); }
Example #4
Source File: SyntaxHighlighterOverEditorHighlighter.java From consulo with Apache License 2.0 | 6 votes |
public SyntaxHighlighterOverEditorHighlighter(SyntaxHighlighter _highlighter, VirtualFile file, Project project) { if (file.getFileType() == PlainTextFileType.INSTANCE) { // optimization for large files, PlainTextSyntaxHighlighterFactory is slow highlighter = new PlainSyntaxHighlighter(); lexer = highlighter.getHighlightingLexer(); } else { highlighter = _highlighter; LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE); EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file); try { if (editorHighlighter instanceof LayeredLexerEditorHighlighter) { lexer = new LexerEditorHighlighterLexer(editorHighlighter, false); } else { lexer = highlighter.getHighlightingLexer(); } } finally { LayeredLexer.ourDisableLayersFlag.set(null); } } }
Example #5
Source File: SyntaxHighlighterOverEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { final SyntaxHighlighter activeSyntaxHighlighter = layeredHighlighterIterator != null ? layeredHighlighterIterator.getActiveSyntaxHighlighter() : highlighter; return activeSyntaxHighlighter.getTokenHighlights(tokenType); }
Example #6
Source File: ChunkExtractor.java From consulo with Apache License 2.0 | 5 votes |
private ChunkExtractor(@Nonnull PsiFile file) { myColorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); Project project = file.getProject(); myDocument = PsiDocumentManager.getInstance(project).getDocument(file); LOG.assertTrue(myDocument != null); final FileType fileType = file.getFileType(); SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, file.getVirtualFile()); highlighter = highlighter == null ? new PlainSyntaxHighlighter() : highlighter; myHighlighter = new SyntaxHighlighterOverEditorHighlighter(highlighter, file.getVirtualFile(), project); myDocumentStamp = -1; }
Example #7
Source File: ConsoleViewUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void printAsFileType(@Nonnull ConsoleView console, @Nonnull String text, @Nonnull FileType fileType) { SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null); if (highlighter != null) { printWithHighlighting(console, text, highlighter); } else { console.print(text, ConsoleViewContentType.NORMAL_OUTPUT); } }
Example #8
Source File: LexerEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
public LexerEditorHighlighter(@Nonnull SyntaxHighlighter highlighter, @Nonnull EditorColorsScheme scheme) { myScheme = scheme; myLexer = highlighter.getHighlightingLexer(); myLexer.start(ArrayUtil.EMPTY_CHAR_SEQUENCE); myInitialState = myLexer.getState(); myHighlighter = highlighter; mySegments = createSegments(); }
Example #9
Source File: LayeredLexerEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public SyntaxHighlighter getActiveSyntaxHighlighter() { if (myCurrentMapper != null) { return myCurrentMapper.mySyntaxHighlighter; } return getSyntaxHighlighter(); }
Example #10
Source File: ClickNavigator.java From consulo with Apache License 2.0 | 5 votes |
private void addMouseMotionListener(final Editor view, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { view.getContentComponent().addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { LogicalPosition pos = view.xyToLogicalPosition(new Point(e.getX(), e.getY())); navigate(view, false, pos, highlighter, data, isBackgroundImportant); } }); }
Example #11
Source File: CustomFileTypeHighlighterProvider.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public SyntaxHighlighter create(final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
Example #12
Source File: DslSyntaxHighlighterFactory.java From dsl-compiler-client with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { MapKey key = new MapKey(project, virtualFile != null ? virtualFile.getPath() + "/" + virtualFile.getName() : ""); DslSyntaxHighlighter highlighter = highlighters.get(key); if (highlighter == null || highlighter.virtualFile == null || !highlighter.virtualFile.isValid() || virtualFile != null && !virtualFile.equals(highlighter.virtualFile) || highlighter.isDisposed()) { if (highlighter != null) highlighter.stop(); highlighter = new DslSyntaxHighlighter(project, virtualFile); highlighters.put(key, highlighter); } return highlighter; }
Example #13
Source File: ClickNavigator.java From consulo with Apache License 2.0 | 5 votes |
public void addClickNavigator(final Editor view, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { addMouseMotionListener(view, highlighter, data, isBackgroundImportant); CaretListener listener = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { navigate(view, true, e.getNewPosition(), highlighter, data, isBackgroundImportant); } }; view.getCaretModel().addCaretListener(listener); }
Example #14
Source File: ClickNavigator.java From consulo with Apache License 2.0 | 5 votes |
private boolean selectItem(boolean select, HighlighterIterator itr, SyntaxHighlighter highlighter) { IElementType tokenType = itr.getTokenType(); if (tokenType == null) return false; String type = highlightingTypeFromTokenType(tokenType, highlighter); return setSelectedItem(type, select); }
Example #15
Source File: EditorWindowImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public EditorHighlighter getHighlighter() { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(myInjectedFile.getLanguage(), getProject(), myInjectedFile.getVirtualFile()); EditorHighlighter highlighter = HighlighterFactory.createHighlighter(syntaxHighlighter, scheme); highlighter.setText(getDocument().getText()); highlighter.setEditor(new LightHighlighterClient(getDocument(), getProject())); return highlighter; }
Example #16
Source File: BaseColorSettings.java From Custom-Syntax-Highlighter with MIT License | 5 votes |
static SyntaxHighlighter getSyntaxHighlighterWithFallback(final Language lang) { final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(lang, null, null); if (syntaxHighlighter == null) { return SyntaxHighlighterFactory.getSyntaxHighlighter(Language.ANY, null, null); } return syntaxHighlighter; }
Example #17
Source File: ClickNavigator.java From consulo with Apache License 2.0 | 5 votes |
public static String highlightingTypeFromTokenType(IElementType tokenType, SyntaxHighlighter highlighter) { TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType); String s = null; for (int i = highlights.length - 1; i >= 0; i--) { if (highlights[i] != HighlighterColors.TEXT) { s = highlights[i].getExternalName(); break; } } return s == null ? HighlighterColors.TEXT.getExternalName() : s; }
Example #18
Source File: SimpleEditorPreview.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static String selectItem(HighlighterIterator itr, SyntaxHighlighter highlighter) { IElementType tokenType = itr.getTokenType(); if (tokenType == null) return null; TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType); String s = null; for (int i = highlights.length - 1; i >= 0; i--) { if (highlights[i] != HighlighterColors.TEXT) { s = highlights[i].getExternalName(); break; } } return s == null ? HighlighterColors.TEXT.getExternalName() : s; }
Example #19
Source File: LatteSyntaxHighlighterFactory.java From intellij-latte with MIT License | 4 votes |
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { return new LatteSyntaxHighlighter(); }
Example #20
Source File: LatteColorSettingsPage.java From intellij-latte with MIT License | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new LatteSyntaxHighlighter(); }
Example #21
Source File: TemplateContextType.java From consulo with Apache License 2.0 | 4 votes |
@javax.annotation.Nullable public SyntaxHighlighter createHighlighter() { return null; }
Example #22
Source File: LanguageVersionableSyntaxHighlighterFactory.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public abstract SyntaxHighlighter getSyntaxHighlighter(@Nonnull LanguageVersion languageVersion);
Example #23
Source File: DefaultLanguageColorsPage.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public SyntaxHighlighter getHighlighter() { return new PlainSyntaxHighlighter(); }
Example #24
Source File: HaxeColorSettingsPage.java From intellij-haxe with Apache License 2.0 | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new HaxeSyntaxHighlighter(null); }
Example #25
Source File: XQueryColorSettingsPage.java From intellij-xquery with Apache License 2.0 | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new XQuerySyntaxHighlighter(); }
Example #26
Source File: SampleColorSettingsPage.java From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new SampleSyntaxHighlighter(); }
Example #27
Source File: SQFColorSettingsPage.java From arma-intellij-plugin with MIT License | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new SQFSyntaxHighlighter(); }
Example #28
Source File: HeaderColorSettingsPage.java From arma-intellij-plugin with MIT License | 4 votes |
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new HeaderSyntaxHighlighter(); }
Example #29
Source File: BashColorsAndFontsPage.java From BashSupport with Apache License 2.0 | 4 votes |
@NotNull public SyntaxHighlighter getHighlighter() { return new BashSyntaxHighlighter(); }
Example #30
Source File: TemplateDataHighlighterWrapper.java From consulo with Apache License 2.0 | 4 votes |
public TemplateDataHighlighterWrapper(SyntaxHighlighter highlighter) { myHighlighter = highlighter; }