当前位置: 首页>>代码示例>>Java>>正文


Java ParserDefinition.getCommentTokens方法代码示例

本文整理汇总了Java中com.intellij.lang.ParserDefinition.getCommentTokens方法的典型用法代码示例。如果您正苦于以下问题:Java ParserDefinition.getCommentTokens方法的具体用法?Java ParserDefinition.getCommentTokens怎么用?Java ParserDefinition.getCommentTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.lang.ParserDefinition的用法示例。


在下文中一共展示了ParserDefinition.getCommentTokens方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: acceptInput

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
@Override
public boolean acceptInput(@NotNull final VirtualFile file) {
  if (!file.isInLocalFileSystem()) {
    return false; // do not index TODOs in library sources
  }

  final FileType fileType = file.getFileType();

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    return commentTokens != null;
  }

  return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
         fileType instanceof CustomSyntaxTableFileType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TodoIndex.java

示例2: isComment

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:IndentsPass.java

示例3: acceptInput

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
@Override
public boolean acceptInput(final VirtualFile file) {
  if (!(file.getFileSystem() instanceof LocalFileSystem)) {
    return false; // do not index TODOs in library sources
  }

  final FileType fileType = file.getFileType();

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    return commentTokens != null;
  }
  
  return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
         fileType instanceof CustomSyntaxTableFileType;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:TodoIndex.java

示例4: isComment

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
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);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:IndentsPass.java

示例5: insertWhitespaceIfNeeded

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
private static ASTNode insertWhitespaceIfNeeded(ASTNode anchorNode, final ASTNode elementNode, final ASTNode parentNode,
		final ASTNode insertionPlaceNode) throws IncorrectOperationException
{
	ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(parentNode.getPsi().getLanguage());
	final TokenSet comments = parserDef.getCommentTokens(parentNode.getPsi().getLanguage().getVersions()[0]);
	final TokenSet whitespaces = parserDef.getWhitespaceTokens(parentNode.getPsi().getLanguage().getVersions()[0]);

	if(anchorNode != null && ((!whitespaces.contains(anchorNode.getElementType()) && !whitespaces.contains(elementNode.getElementType())) ||
			comments.contains(anchorNode.getElementType()) ||
			comments.contains(elementNode.getElementType()) ||
			elementNode.getPsi() instanceof PsiComment))
	{
		String commentString = " ";
		if(comments.contains(anchorNode.getElementType()) ||
				comments.contains(elementNode.getElementType()) ||
				elementNode.getPsi() instanceof PsiComment)
		{
			commentString = "\n";
		}

		final ASTNode wsNode = PsiParserFacade.SERVICE.getInstance(parentNode.getPsi().getProject()).createWhiteSpaceFromText(commentString).getNode();
		parentNode.addChild(wsNode, insertionPlaceNode);
		anchorNode = wsNode;
	}
	return anchorNode;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:27,代码来源:JSChangeUtil.java

示例6: isComment

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
private static  boolean isComment(final ASTNode node) {
  final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
  if (psiElement instanceof PsiComment) return true;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
  if (parserDefinition == null) return false;
  final TokenSet commentTokens = parserDefinition.getCommentTokens();
  return commentTokens.contains(node.getElementType());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ShiftIndentInsideHelper.java

示例7: getTodoIndexer

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), 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);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

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

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:PlatformIdTableBuilding.java

示例8: isInComments

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
public static boolean isInComments(final IElementType tokenType) {
  final Language language = tokenType.getLanguage();
  boolean inComments = false;

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

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

    if (commentTokens.contains(tokenType)) {
      inComments = true;
    }
  }
  return inComments;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:CacheUtil.java

示例9: getTodoIndexer

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), 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);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

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

  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:PlatformIdTableBuilding.java

示例10: getTodoIndexer

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
@javax.annotation.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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:31,代码来源:PlatformIdTableBuilding.java

示例11: isComment

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
private static  boolean isComment(final ASTNode node) {
  final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
  if (psiElement instanceof PsiComment) return true;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
  if (parserDefinition == null) return false;
  final TokenSet commentTokens = parserDefinition.getCommentTokens(psiElement.getLanguageVersion());
  return commentTokens.contains(node.getElementType());
}
 
开发者ID:consulo,项目名称:consulo-xml,代码行数:9,代码来源:AbstractXmlBlock.java

示例12: isMinified

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
protected static boolean isMinified(Lexer lexer, ParserDefinition parserDefinition, TokenSet noWSRequireAfterTokenSet) {
  int offsetIgnoringComments = 0;
  int offsetIgnoringCommentsAndStrings = 0;
  int lineLength = 0;
  int unneededWhitespaceCount = 0;
  IElementType lastTokenType = null;
  TokenSet whitespaceTokens = parserDefinition.getWhitespaceTokens();
  TokenSet stringLiteralElements = parserDefinition.getStringLiteralElements();
  TokenSet commentTokens = parserDefinition.getCommentTokens();
  for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
    if (commentTokens.contains(tokenType)) {
      lastTokenType = tokenType;
      continue;
    }

    int tokenLength = lexer.getTokenEnd() - lexer.getTokenStart();
    offsetIgnoringComments += tokenLength;
    if (stringLiteralElements.contains(tokenType)) {
      lineLength += tokenLength;
      lastTokenType = tokenType;
      continue;
    }
    offsetIgnoringCommentsAndStrings += tokenLength;

    if (whitespaceTokens.contains(tokenType)) {
      if (!commentTokens.contains(lastTokenType) && tokenLength > 1) {
        lexer.advance();
        if (lexer.getTokenType() == null) {
          // it was last token
          break;
        } else {
          return false;
        }
      }

      if (lexer.getTokenText().contains("\n")) {
        if (lineLength > MIN_LINE_LENGTH) {
          break;
        }
        lineLength = 0;
      }

      if (" ".equals(lexer.getTokenText()) && noWSRequireAfterTokenSet.contains(lastTokenType)) {
        unneededWhitespaceCount++;
      }
    }
    else {
      lineLength += tokenLength;
    }

    if (offsetIgnoringComments >= MAX_OFFSET) {
      break;
    }
    lastTokenType = tokenType;
  }

  return offsetIgnoringComments >= MIN_SIZE &&
         (unneededWhitespaceCount + 0.0d) / offsetIgnoringCommentsAndStrings < MAX_UNNEEDED_OFFSET_PERCENTAGE;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:MinifiedFilesUtil.java

示例13: isMinified

import com.intellij.lang.ParserDefinition; //导入方法依赖的package包/类
/**
 * Finds out whether the file minified by using common (not language-specific) heuristics.
 * Can be used for checking of css/less/scss/sass and js files.
 *
 * @param lexer                    Lexer started on content of target file
 * @param parserDefinition         Parser definition of target language
 * @param noWSRequireAfterTokenSet TokenSet of types that doesn't require whitespaces after them.
 */
public static boolean isMinified(Lexer lexer,
                                 ParserDefinition parserDefinition,
                                 TokenSet noWSRequireAfterTokenSet) {
  int offsetIgnoringComments = 0;
  int offsetIgnoringCommentsAndStrings = 0;
  int lineLength = 0;
  int unneededWhitespaceCount = 0;
  IElementType lastTokenType = null;
  TokenSet whitespaceTokens = parserDefinition.getWhitespaceTokens();
  TokenSet stringLiteralElements = parserDefinition.getStringLiteralElements();
  TokenSet commentTokens = parserDefinition.getCommentTokens();
  for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
    if (commentTokens.contains(tokenType)) {
      lastTokenType = tokenType;
      continue;
    }

    int tokenLength = lexer.getTokenEnd() - lexer.getTokenStart();
    offsetIgnoringComments += tokenLength;
    if (stringLiteralElements.contains(tokenType)) {
      lineLength += tokenLength;
      lastTokenType = tokenType;
      continue;
    }
    offsetIgnoringCommentsAndStrings += tokenLength;

    if (whitespaceTokens.contains(tokenType)) {
      if (!commentTokens.contains(lastTokenType) && tokenLength > 1) {
        return false;
      }

      if (lexer.getTokenText().contains("\n")) {
        if (lineLength > MIN_LINE_LENGTH) {
          break;
        }
        lineLength = 0;
      }

      if (" ".equals(lexer.getTokenText()) && noWSRequireAfterTokenSet.contains(lastTokenType)) {
        unneededWhitespaceCount++;
      }
    }
    else {
      lineLength += tokenLength;
    }

    if (offsetIgnoringComments >= MAX_OFFSET) {
      break;
    }
    lastTokenType = tokenType;
  }

  return offsetIgnoringComments >= MIN_SIZE && (unneededWhitespaceCount + 0.0d) / offsetIgnoringCommentsAndStrings < MAX_UNNEEDED_OFFSET_PERCENTAGE;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:63,代码来源:MinifiedFilesUtil.java


注:本文中的com.intellij.lang.ParserDefinition.getCommentTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。