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


Java ParserDefinition.getWhitespaceTokens方法代码示例

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


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

示例1: 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

示例2: 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

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