com.intellij.openapi.editor.ex.util.LayerDescriptor Java Examples

The following examples show how to use com.intellij.openapi.editor.ex.util.LayerDescriptor. 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: SoyLayeredHighlighter.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
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, ""));
}
 
Example #2
Source File: LatteEditorHighlighter.java    From intellij-latte with MIT License 6 votes vote down vote up
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 #3
Source File: FileTemplateConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private EditorHighlighter createHighlighter() {
  if (myTemplate != null && myVelocityFileType != UnknownFileType.INSTANCE) {
    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 = PlainTextFileType.INSTANCE;
  }

  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;
}
 
Example #4
Source File: DustLayeredSyntaxHighlighter.java    From Intellij-Dust with MIT License 6 votes vote down vote up
public DustLayeredSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
  // create main highlighter
  super(new DustSyntaxHighlighter(), colors);

  // highlighter for outer lang
  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 = StdFileTypes.HTML;
  }
  SyntaxHighlighter outerHighlighter = SyntaxHighlighter.PROVIDER.create(type, project, virtualFile);

  registerLayer(DustTypes.HTML, new LayerDescriptor(outerHighlighter, ""));
}
 
Example #5
Source File: FluidTemplateHighlighter.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public FluidTemplateHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
    super(new FluidFileHighlighter(), colors);

    FileType fileType = null;
    if (project != null && virtualFile != null) {
        fileType = TemplateLanguageFileUtil.getTemplateDataLanguage(project, virtualFile).getAssociatedFileType();
    }

    if (fileType == null) {
        fileType = FileTypes.PLAIN_TEXT;
    }

    this.registerLayer(FluidTypes.TEXT, new LayerDescriptor(SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), ""));
}
 
Example #6
Source File: CSharpEditorHighlighter.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public CSharpEditorHighlighter(@Nullable final VirtualFile virtualFile, @Nonnull final EditorColorsScheme colors)
{
	super(new CSharpSyntaxHighlighter(), colors);

	registerLayer(CSharpCfsLanguageVersion.getInstance().getExpressionElementType(), new LayerDescriptor(new CSharpSyntaxHighlighter(), ""));

	registerLayer(CSharpTokens.STRING_LITERAL, new LayerDescriptor(new CSharpSyntaxHighlighter()
	{
		@Nonnull
		@Override
		public Lexer getHighlightingLexer()
		{
			return new StringLiteralLexer('\"', CSharpTokens.STRING_LITERAL);
		}
	}, ""));
	registerLayer(CSharpTokensImpl.LINE_DOC_COMMENT, new LayerDescriptor(new CSharpDocSyntaxHighlighter(), ""));
	registerLayer(CSharpTokens.CHARACTER_LITERAL, new LayerDescriptor(new CSharpSyntaxHighlighter()
	{
		@Nonnull
		@Override
		public Lexer getHighlightingLexer()
		{
			return new StringLiteralLexer('\'', CSharpTokens.CHARACTER_LITERAL);
		}
	}, ""));
	registerLayer(CSharpTokensImpl.INTERPOLATION_STRING_LITERAL, new LayerDescriptor(new CfsSyntaxHighlighter(CSharpCfsLanguageVersion.getInstance())
	{
		@Nonnull
		@Override
		public TextAttributesKey[] getTokenHighlights(IElementType elementType)
		{
			if(elementType == CfsTokens.TEXT)
			{
				return pack(CSharpHighlightKey.STRING);
			}
			return super.getTokenHighlights(elementType);
		}
	}, ""));
	registerLayer(CSharpTemplateTokens.PREPROCESSOR_FRAGMENT, new LayerDescriptor(new CSharpPreprocessorSyntaxHighlighter(), ""));
}