本文整理汇总了Java中com.intellij.openapi.editor.highlighter.EditorHighlighter类的典型用法代码示例。如果您正苦于以下问题:Java EditorHighlighter类的具体用法?Java EditorHighlighter怎么用?Java EditorHighlighter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EditorHighlighter类属于com.intellij.openapi.editor.highlighter包,在下文中一共展示了EditorHighlighter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHighlighter
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
private EditorHighlighter createHighlighter(LanguageFileType fileType) {
// FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension("");
// if (fileType == null) {
// fileType = FileTypes.PLAIN_TEXT;
// }
SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null);
if (originalHighlighter == null) {
originalHighlighter = new PlainSyntaxHighlighter();
}
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(getFileHighlighter(fileType), scheme);// TODO: 2017/8/3 HTML
highlighter.registerLayer(TextElementType, new LayerDescriptor(originalHighlighter, ""));
return highlighter;
}
示例2: calcParensBalance
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
private static int calcParensBalance(Document document, EditorHighlighter highlighter, int rangeStart, int rangeEnd){
LOG.assertTrue(0 <= rangeStart);
LOG.assertTrue(rangeStart <= rangeEnd);
LOG.assertTrue(rangeEnd <= document.getTextLength());
HighlighterIterator iterator = highlighter.createIterator(rangeStart);
int balance = 0;
while(!iterator.atEnd() && iterator.getStart() < rangeEnd){
IElementType tokenType = iterator.getTokenType();
if (tokenType == JavaTokenType.LPARENTH){
balance++;
}
else if (tokenType == JavaTokenType.RPARENTH){
balance--;
}
iterator.advance();
}
return balance;
}
示例3: testCpp
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
public void testCpp() throws Exception {
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.cpp");
// 0123456789012345678 9 0123 45 6 7
highlighter.setText("#include try enum \"\\xff\\z\\\"xxx\"");
HighlighterIterator iterator = highlighter.createIterator(2);
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
iterator = highlighter.createIterator(9);
assertEquals(CustomHighlighterTokenType.KEYWORD_2, iterator.getTokenType());
iterator = highlighter.createIterator(15);
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
iterator = highlighter.createIterator(19);
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(23);
assertEquals(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(25);
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(27);
assertEquals(CustomHighlighterTokenType.STRING, iterator.getTokenType());
}
示例4: buildHighlighter
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@Nullable
private EditorHighlighter buildHighlighter(@Nullable Project project,
@NotNull DocumentContent content1,
@NotNull DocumentContent content2,
@NotNull CharSequence text1,
@NotNull CharSequence text2,
@NotNull List<HighlightRange> ranges,
int textLength) {
EditorHighlighter highlighter1 = DiffUtil.initEditorHighlighter(project, content1, text1);
EditorHighlighter highlighter2 = DiffUtil.initEditorHighlighter(project, content2, text2);
if (highlighter1 == null && highlighter2 == null) return null;
if (highlighter1 == null) highlighter1 = DiffUtil.initEmptyEditorHighlighter(text1);
if (highlighter2 == null) highlighter2 = DiffUtil.initEmptyEditorHighlighter(text2);
return new UnifiedEditorHighlighter(myDocument, highlighter1, highlighter2, ranges, textLength);
}
示例5: buildExtensions
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@NotNull
@Override
protected List<EditorHighlighterProvider> buildExtensions(@NotNull String stringKey, @NotNull final FileType key) {
List<EditorHighlighterProvider> fromEP = super.buildExtensions(stringKey, key);
if (fromEP.isEmpty()) {
EditorHighlighterProvider defaultProvider = new EditorHighlighterProvider() {
@Override
public EditorHighlighter getEditorHighlighter(@Nullable Project project,
@NotNull FileType fileType,
@Nullable VirtualFile virtualFile,
@NotNull EditorColorsScheme colors) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(
SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), colors);
}
};
return Collections.singletonList(defaultProvider);
}
return fromEP;
}
示例6: setupHighlighterSettings
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
private void setupHighlighterSettings(Editor left, Editor base, Editor right) {
Editor[] editors = new Editor[]{left, base, right};
DiffContent[] contents = myData.getContents();
FileType[] types = DiffUtil.chooseContentTypes(contents);
VirtualFile fallbackFile = contents[1].getFile();
FileType fallbackType = contents[1].getContentType();
for (int i = 0; i < 3; i++) {
Editor editor = editors[i];
DiffContent content = contents[i];
EditorHighlighter highlighter =
createHighlighter(types[i], content.getFile(), fallbackFile, fallbackType, myData.getProject()).createHighlighter();
if (highlighter != null) {
((EditorEx)editor).setHighlighter(highlighter);
}
}
}
示例7: getEditorHighlighterForCachesBuilding
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@Nullable
public static EditorHighlighter getEditorHighlighterForCachesBuilding(Document document) {
if (document == null) {
return null;
}
final WeakReference<EditorHighlighter> editorHighlighterWeakReference = document.getUserData(ourSomeEditorSyntaxHighlighter);
final EditorHighlighter someEditorHighlighter = SoftReference.dereference(editorHighlighterWeakReference);
if (someEditorHighlighter instanceof LexerEditorHighlighter &&
((LexerEditorHighlighter)someEditorHighlighter).isValid()
) {
return someEditorHighlighter;
}
document.putUserData(ourSomeEditorSyntaxHighlighter, null);
return null;
}
示例8: getLexerBasedOnLexerHighlighter
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@Nullable
public static Lexer getLexerBasedOnLexerHighlighter(CharSequence text, VirtualFile virtualFile, Project project) {
EditorHighlighter highlighter = null;
PsiFile psiFile = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null;
final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null;
final EditorHighlighter cachedEditorHighlighter;
boolean alreadyInitializedHighlighter = false;
if (document != null &&
(cachedEditorHighlighter = getEditorHighlighterForCachesBuilding(document)) != null &&
PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(text, cachedEditorHighlighter)) {
highlighter = cachedEditorHighlighter;
alreadyInitializedHighlighter = true;
}
else if (virtualFile != null) {
highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, virtualFile);
}
if (highlighter != null) {
return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter);
}
return null;
}
示例9: createEditor
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) {
EditorFactory editorFactory = EditorFactory.getInstance();
Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project));
editor.getContentComponent().setFocusable(!isReadOnly);
EditorSettings editorSettings = editor.getSettings();
editorSettings.setVirtualSpace(false);
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setIndentGuidesShown(false);
editorSettings.setLineNumbersShown(false);
editorSettings.setFoldingOutlineShown(false);
editorSettings.setCaretRowShown(false);
EditorColorsScheme scheme = editor.getColorsScheme();
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
((EditorEx) editor).setHighlighter(highlighter);
}
return editor;
}
示例10: updateView
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@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();
}
示例11: beforeCharDeleted
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@Override
public void beforeCharDeleted(char c, PsiFile file, Editor editor) {
if (c != '{') return;
if (!(file instanceof GroovyFile)) return;
final int offset = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
if (offset < 1) return;
HighlighterIterator iterator = highlighter.createIterator(offset);
if (iterator.getTokenType() != GroovyTokenTypes.mRCURLY) return;
iterator.retreat();
if (iterator.getStart() < 1 || iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return;
editor.getDocument().deleteString(offset, offset + 1);
}
示例12: TodoTreeBuilder
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
TodoTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
super(tree, treeModel, null, MyComparator.ourInstance, false);
myProject = project;
myFileTree = new FileTree();
myDirtyFileSet = new HashSet<VirtualFile>();
myFile2Highlighter = new HashMap<VirtualFile, EditorHighlighter>();
PsiManager psiManager = PsiManager.getInstance(myProject);
mySearchHelper = PsiTodoSearchHelper.SERVICE.getInstance(myProject);
psiManager.addPsiTreeChangeListener(new MyPsiTreeChangeListener());
myFileStatusListener = new MyFileStatusListener();
setCanYieldUpdate(true);
}
示例13: createHighlighter
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
private EditorHighlighter createHighlighter() {
if (myTemplate != null && myVelocityFileType != FileTypes.UNKNOWN) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, new LightVirtualFile("aaa." + myTemplate.getExtension() + ".ft"));
}
FileType fileType = null;
if (myTemplate != null) {
fileType = FileTypeManager.getInstance().getFileTypeByExtension(myTemplate.getExtension());
}
if (fileType == null) {
fileType = FileTypes.PLAIN_TEXT;
}
SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null);
if (originalHighlighter == null) {
originalHighlighter = new PlainSyntaxHighlighter();
}
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), scheme);
highlighter.registerLayer(FileTemplateTokenType.TEXT, new LayerDescriptor(originalHighlighter, ""));
return highlighter;
}
示例14: rehighlightOpenEditors
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
/**
* Force re-highlighting in all open editors that belong to specified project.
*/
public static void rehighlightOpenEditors(final @NotNull Project project) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
if (editor instanceof EditorEx && editor.getProject() == project) {
final VirtualFile vFile = ((EditorEx)editor).getVirtualFile();
if (vFile != null) {
final EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, vFile);
((EditorEx)editor).setHighlighter(highlighter);
}
}
}
}
});
}
示例15: charTyped
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入依赖的package包/类
@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (c != '{' || project == null || !HandlerUtils.canBeInvoked(editor, project)) {
return Result.CONTINUE;
}
if (!(file instanceof GroovyFile)) return Result.CONTINUE;
int caret = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
if (caret < 1) return Result.CONTINUE;
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
if (iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return Result.CONTINUE;
iterator.retreat();
if (iterator.atEnd() || iterator.getTokenType() != GroovyTokenTypes.mDOLLAR) return Result.CONTINUE;
iterator.advance();
if (iterator.atEnd()) return Result.CONTINUE;
iterator.advance();
if (iterator.getTokenType() != GroovyTokenTypes.mGSTRING_BEGIN) return Result.CONTINUE;
editor.getDocument().insertString(caret, "}");
return Result.STOP;
}