Java Code Examples for com.intellij.lang.ParserDefinition#getCommentTokens()

The following examples show how to use com.intellij.lang.ParserDefinition#getCommentTokens() . 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: FilteredIndentsHighlightingPass.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens();
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 2
Source File: FilteredIndentsHighlightingPass.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens();
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 3
Source File: CacheUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean isInComments(final IElementType tokenType, LanguageVersion languageVersion) {
  final Language language = tokenType.getLanguage();

  //for (CommentTokenSetProvider provider : CommentTokenSetProvider.EXTENSION.allForLanguage(language)) {
  //  if (provider.isInComments(tokenType)) {
  //    return true;
  //  }
  //}

  boolean inComments = false;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);

  if (parserDefinition != null) {
    final TokenSet commentTokens = parserDefinition.getCommentTokens(languageVersion);

    if (commentTokens.contains(tokenType)) {
      inComments = true;
    }
  }
  return inComments;
}
 
Example 4
Source File: IndentsPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens(LanguageVersionUtil.findLanguageVersion(language, myFile));
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 5
Source File: PlatformIdTableBuilding.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project);
  }

  return null;
}