Java 类com.intellij.openapi.fileTypes.SyntaxHighlighter 实例源码

项目:bamboo-soy    文件:SoyLayeredHighlighter.java   
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, ""));
}
项目:intellij-ce-playground    文件:JavaSyntaxHighlighterFactory.java   
/**
 * 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();
}
项目:intellij-ce-playground    文件:SimpleEditorPreview.java   
@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();

}
项目:intellij    文件:BuildColorsPage.java   
@Override
public SyntaxHighlighter getHighlighter() {
  final SyntaxHighlighter highlighter =
      SyntaxHighlighterFactory.getSyntaxHighlighter(BuildFileType.INSTANCE, null, null);
  assert highlighter != null;
  return highlighter;
}
项目:sutr-io    文件:SutrColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    log.info("Building new SutrSyntaxHighlighter for Sutr Color settings page.");

    return new SutrSyntaxHighlighter();
}
项目:sutr-io    文件:UtrSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile){
    log.info("Creating new Utr Syntax Highlight for [" + project.getName() + "]");

    return new UtrSyntaxHighlighter();
}
项目:RtplPlugin    文件:RtplLanguage.java   
protected RtplLanguage() {
    super(NAME);
    SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this,
            new SingleLazyInstanceSyntaxHighlighterFactory() {
                @NotNull
                protected SyntaxHighlighter createHighlighter() {
                    return new RtplSyntaxHighlighter();
                }
            }
    );
}
项目:intellij-ce-playground    文件:LexerEditorHighlighter.java   
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();
}
项目:intellij-ce-playground    文件:LayeredLexerEditorHighlighter.java   
public SyntaxHighlighter getActiveSyntaxHighlighter() {
  if (myCurrentMapper != null) {
    return myCurrentMapper.mySyntaxHighlighter;
  }

  return LayeredLexerEditorHighlighter.this.getSyntaxHighlighter();
}
项目:intellij-ce-playground    文件:ChunkExtractor.java   
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;
}
项目:intellij-ce-playground    文件:ConsoleViewUtil.java   
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();
  }
}
项目:intellij-ce-playground    文件:ConsoleViewUtil.java   
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);
  }
}
项目:intellij-ce-playground    文件:TemplateEditorUtil.java   
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);
}
项目:intellij-ce-playground    文件:PropertiesLanguage.java   
public PropertiesLanguage() {
  super("Properties", "text/properties");
  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() {
    @NotNull
    protected SyntaxHighlighter createHighlighter() {
      return new PropertiesHighlighter();
    }
  });
}
项目:intellij-ce-playground    文件:ClickNavigator.java   
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);
}
项目:intellij-ce-playground    文件:ClickNavigator.java   
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);
  }
项目:intellij-ce-playground    文件:ClickNavigator.java   
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);
    }
  });
}
项目:intellij-ce-playground    文件:ClickNavigator.java   
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);
    }
  }
}
项目:intellij-ce-playground    文件:SimpleEditorPreview.java   
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);
  }
}
项目:intellij-ce-playground    文件:ByteCodeViewerComponent.java   
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);
}
项目:intellij-ce-playground    文件:LanguageConsoleImpl.java   
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;
}
项目:intellij-ce-playground    文件:CustomFileTypeFoldingBuilder.java   
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();
  }
}
项目:intellij-ce-playground    文件:CustomFileTypeHighlighterProvider.java   
@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;
}
项目:intellij-ce-playground    文件:PySyntaxHighlighterFactory.java   
@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);
}
项目:intellij-ce-playground    文件:BuildoutCfgLanguage.java   
private BuildoutCfgLanguage() {
  super("BuildoutCfg");
  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() {
    @NotNull
    protected SyntaxHighlighter createHighlighter() {
      return new BuildoutCfgSyntaxHighlighter();
    }
  });
}
项目:TS-IJ    文件:TSColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    return new TSSyntaxHighlighter();
}
项目:TS-IJ    文件:TSSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) {
    return new TSSyntaxHighlighter();
}
项目:AppleScript-IDEA    文件:AppleScriptColorsAndFontsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
  return new AppleScriptSyntaxHighlighter();
}
项目:AppleScript-IDEA    文件:AppleScriptSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
  return new AppleScriptSyntaxHighlighter();
}
项目:AppleScript-IDEA    文件:AppleScriptTemplateContextType.java   
@Override
public SyntaxHighlighter createHighlighter() {
  return SyntaxHighlighterFactory.getSyntaxHighlighter(AppleScriptFileType.INSTANCE, null, null);
}
项目:greycat-idea-plugin    文件:GCMSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) {
    return new GCMSyntaxHighlighter();
}
项目:greycat-idea-plugin    文件:GCMColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    return new GCMSyntaxHighlighter();
}
项目:bamboo-soy    文件:SoySyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
  return new SoySyntaxHighlighter();
}
项目:bamboo-soy    文件:SoyColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
  return new SoySyntaxHighlighter();
}
项目:EmojiPrefix    文件:EmojiResourceSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) {
    return new EmojiResourceSyntaxHighlighter();
}
项目:intellij-postfix-templates    文件:CptColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    return new CptSyntaxHighlighter();
}
项目:hybris-integration-intellij-idea-plugin    文件:FlexibleSearchSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
    return new FlexibleSearchSyntaxHighlighter();
}
项目:hybris-integration-intellij-idea-plugin    文件:FlexibleSearchColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    return ServiceManager.getService(FlexibleSearchSyntaxHighlighter.class);
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexSyntaxHighlighterFactory.java   
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(final Project project, final VirtualFile virtualFile) {
    return ServiceManager.getService(ImpexSyntaxHighlighter.class);
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexColorSettingsPage.java   
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
    return ServiceManager.getService(ImpexSyntaxHighlighter.class);
}