當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。