public SoyLayeredHighlighter( @Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { // Creating main highlighter. super(new SoySyntaxHighlighter(), colors); // Highlighter for the outer language. FileType type = null; if (project == null || virtualFile == null) { type = StdFileTypes.PLAIN_TEXT; } else { Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile); if (language != null) type = language.getAssociatedFileType(); if (type == null) type = SoyLanguage.getDefaultTemplateLang(); } SyntaxHighlighter outerHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(type, project, virtualFile); registerLayer(OTHER, new LayerDescriptor(outerHighlighter, "")); }
/** * SyntaxHighlighterProvider implementation (for .class files). */ @Nullable @Override public SyntaxHighlighter create(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { if (project != null && file != null) { PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (fileType == JavaClassFileType.INSTANCE && psiFile != null) { Language language = psiFile.getLanguage(); if (language != JavaLanguage.INSTANCE) { return SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file); } } if (psiFile instanceof ClsFileImpl) { LanguageLevel sourceLevel = ((ClsFileImpl)psiFile).getLanguageLevel(); return new JavaFileHighlighter(sourceLevel); } } return new JavaFileHighlighter(); }
@Override public void updateView() { EditorColorsScheme scheme = myOptions.getSelectedScheme(); myEditor.setColorsScheme(scheme); EditorHighlighter highlighter = null; if (myPage instanceof EditorHighlightingProvidingColorSettingsPage) { highlighter = ((EditorHighlightingProvidingColorSettingsPage)myPage).createEditorHighlighter(scheme); } if (highlighter == null) { final SyntaxHighlighter pageHighlighter = myPage.getHighlighter(); highlighter = HighlighterFactory.createHighlighter(pageHighlighter, scheme); } myEditor.setHighlighter(highlighter); updateHighlighters(); myEditor.reinitSettings(); }
@Override public SyntaxHighlighter getHighlighter() { final SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(BuildFileType.INSTANCE, null, null); assert highlighter != null; return highlighter; }
@NotNull @Override public SyntaxHighlighter getHighlighter() { log.info("Building new SutrSyntaxHighlighter for Sutr Color settings page."); return new SutrSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile){ log.info("Creating new Utr Syntax Highlight for [" + project.getName() + "]"); return new UtrSyntaxHighlighter(); }
protected RtplLanguage() { super(NAME); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() { @NotNull protected SyntaxHighlighter createHighlighter() { return new RtplSyntaxHighlighter(); } } ); }
public LexerEditorHighlighter(@NotNull SyntaxHighlighter highlighter, @NotNull EditorColorsScheme scheme) { myScheme = scheme; myLexer = highlighter.getHighlightingLexer(); myLexer.start(ArrayUtil.EMPTY_CHAR_SEQUENCE); myInitialState = myLexer.getState(); myHighlighter = highlighter; mySegments = createSegments(); }
public SyntaxHighlighter getActiveSyntaxHighlighter() { if (myCurrentMapper != null) { return myCurrentMapper.mySyntaxHighlighter; } return LayeredLexerEditorHighlighter.this.getSyntaxHighlighter(); }
private ChunkExtractor(@NotNull 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; }
public static void printWithHighlighting(@NotNull ConsoleView console, @NotNull String text, @NotNull SyntaxHighlighter highlighter) { Lexer lexer = highlighter.getHighlightingLexer(); lexer.start(text, 0, text.length(), 0); IElementType tokenType; while ((tokenType = lexer.getTokenType()) != null) { console.print(lexer.getTokenText(), getContentTypeForToken(tokenType, highlighter)); lexer.advance(); } }
public static void printAsFileType(@NotNull ConsoleView console, @NotNull String text, @NotNull FileType fileType) { SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null); if (highlighter != null) { printWithHighlighting(console, text, highlighter); } else { console.print(text, ConsoleViewContentType.NORMAL_OUTPUT); } }
public static void setHighlighter(Editor editor, @Nullable TemplateContext templateContext) { SyntaxHighlighter highlighter = null; if (templateContext != null) { for(TemplateContextType type: TemplateManagerImpl.getAllContextTypes()) { if (templateContext.isEnabled(type)) { highlighter = type.createHighlighter(); if (highlighter != null) break; } } } setHighlighter((EditorEx)editor, highlighter); }
public PropertiesLanguage() { super("Properties", "text/properties"); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() { @NotNull protected SyntaxHighlighter createHighlighter() { return new PropertiesHighlighter(); } }); }
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); }
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); }
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); } }); }
private void navigate(final Editor editor, boolean select, LogicalPosition pos, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { int offset = editor.logicalPositionToOffset(pos); if (!isBackgroundImportant && editor.offsetToLogicalPosition(offset).column != pos.column) { if (!select) { setCursor(editor, Cursor.TEXT_CURSOR); return; } } if (data != null) { for (HighlightData highlightData : data) { if (highlightDataContainsOffset(highlightData, editor.logicalPositionToOffset(pos))) { if (!select) setCursor(editor, Cursor.HAND_CURSOR); setSelectedItem(highlightData.getHighlightType(), select); return; } } } if (highlighter != null) { HighlighterIterator itr = ((EditorEx)editor).getHighlighter().createIterator(offset); boolean selection = selectItem(select, itr, highlighter); if (!select && selection) { setCursor(editor, Cursor.HAND_CURSOR); } else { setCursor(editor, Cursor.TEXT_CURSOR); } } }
private void navigate(final Editor editor, boolean select, LogicalPosition pos, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { int offset = editor.logicalPositionToOffset(pos); if (!isBackgroundImportant && editor.offsetToLogicalPosition(offset).column != pos.column) { if (!select) { ClickNavigator.setCursor(editor, Cursor.TEXT_CURSOR); return; } } if (data != null) { for (HighlightData highlightData : data) { if (ClickNavigator.highlightDataContainsOffset(highlightData, editor.logicalPositionToOffset(pos))) { if (!select) { ClickNavigator.setCursor(editor, Cursor.HAND_CURSOR); } else { myDispatcher.getMulticaster().selectionInPreviewChanged(highlightData.getHighlightType()); } return; } } } if (highlighter != null) { HighlighterIterator itr = ((EditorEx)editor).getHighlighter().createIterator(offset); selectItem(itr, highlighter, select); ClickNavigator.setCursor(editor, select ? Cursor.TEXT_CURSOR : Cursor.HAND_CURSOR); } }
public ByteCodeViewerComponent(Project project, AnAction[] additionalActions) { super(new BorderLayout()); final EditorFactory factory = EditorFactory.getInstance(); final Document doc = ((EditorFactoryImpl)factory).createDocument("", true, false); doc.setReadOnly(true); myEditor = factory.createEditor(doc, project); EditorHighlighterFactory editorHighlighterFactory = EditorHighlighterFactory.getInstance(); final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(StdFileTypes.JAVA, project, null); ((EditorEx)myEditor).setHighlighter(editorHighlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme())); ((EditorEx)myEditor).setCaretVisible(true); final EditorSettings settings = myEditor.getSettings(); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setLineNumbersShown(false); settings.setFoldingOutlineShown(false); myEditor.setBorder(null); add(myEditor.getComponent(), BorderLayout.CENTER); final ActionManager actionManager = ActionManager.getInstance(); final DefaultActionGroup actions = new DefaultActionGroup(); if (additionalActions != null) { for (final AnAction action : additionalActions) { actions.add(action); } } add(actionManager.createActionToolbar(ActionPlaces.JAVADOC_TOOLBAR, actions, true).getComponent(), BorderLayout.NORTH); }
public static String printWithHighlighting(@NotNull LanguageConsoleView console, @NotNull Editor inputEditor, @NotNull TextRange textRange) { String text; EditorHighlighter highlighter; if (inputEditor instanceof EditorWindow) { PsiFile file = ((EditorWindow)inputEditor).getInjectedFile(); highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), console.getProject()); String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null); highlighter.setText(fullText); text = textRange.substring(fullText); } else { text = inputEditor.getDocument().getText(textRange); highlighter = ((EditorEx)inputEditor).getHighlighter(); } SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter)highlighter).getSyntaxHighlighter() : null; ((LanguageConsoleImpl)console).doAddPromptToHistory(); if (syntax != null) { ConsoleViewUtil.printWithHighlighting(console, text, syntax); } else { console.print(text, ConsoleViewContentType.USER_INPUT); } console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); return text; }
public static void buildBraceMatcherBasedFolding(List<FoldingDescriptor> descriptors, PsiElement root, Document document, SyntaxHighlighter highlighter) { LexerEditorHighlighter editorHighlighter = new LexerEditorHighlighter(highlighter, EditorColorsManager.getInstance().getGlobalScheme()); editorHighlighter.setText(document.getText()); FileType fileType = root.getContainingFile().getFileType(); BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, root.getLanguage()); TextRange totalRange = root.getTextRange(); final HighlighterIterator iterator = editorHighlighter.createIterator(totalRange.getStartOffset()); final LinkedList<Trinity<Integer, Integer, IElementType>> stack = new LinkedList<Trinity<Integer, Integer, IElementType>>(); String editorText = document.getText(); while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) { final Trinity<Integer, Integer, IElementType> last; if (braceMatcher.isLBraceToken(iterator, editorText, fileType) && braceMatcher.isStructuralBrace(iterator, editorText, fileType)) { stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType())); } else if (braceMatcher.isRBraceToken(iterator, editorText, fileType) && braceMatcher.isStructuralBrace(iterator, editorText, fileType) && !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) { stack.removeLast(); TextRange range = new TextRange(last.first, iterator.getEnd()); if (StringUtil.countChars(document.getText(range), '\n') >= 3) { descriptors.add(new FoldingDescriptor(root, range)); } } iterator.advance(); } }
@Override @Nullable public SyntaxHighlighter create(@NotNull final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
@NotNull public SyntaxHighlighter getSyntaxHighlighter(@Nullable final Project project, @Nullable final VirtualFile virtualFile) { final LanguageLevel level = project != null && virtualFile != null ? PyUtil.getLanguageLevelForVirtualFile(project, virtualFile) : LanguageLevel.getDefault(); return myMap.get(level); }
private BuildoutCfgLanguage() { super("BuildoutCfg"); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() { @NotNull protected SyntaxHighlighter createHighlighter() { return new BuildoutCfgSyntaxHighlighter(); } }); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new TSSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { return new TSSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new AppleScriptSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { return new AppleScriptSyntaxHighlighter(); }
@Override public SyntaxHighlighter createHighlighter() { return SyntaxHighlighterFactory.getSyntaxHighlighter(AppleScriptFileType.INSTANCE, null, null); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { return new GCMSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new GCMSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { return new SoySyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new SoySyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { return new EmojiResourceSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new CptSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { return new FlexibleSearchSyntaxHighlighter(); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return ServiceManager.getService(FlexibleSearchSyntaxHighlighter.class); }
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(final Project project, final VirtualFile virtualFile) { return ServiceManager.getService(ImpexSyntaxHighlighter.class); }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return ServiceManager.getService(ImpexSyntaxHighlighter.class); }