类com.intellij.psi.tree.TokenSet源码实例Demo

下面列出了怎么用com.intellij.psi.tree.TokenSet的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: consulo   文件: CompositeElement.java
@Nonnull
public <T extends PsiElement> T[] getChildrenAsPsiElements(@Nullable TokenSet filter, @Nonnull ArrayFactory<? extends T> constructor) {
  assertReadAccessAllowed();
  int count = countChildren(filter);
  T[] result = constructor.create(count);
  if (count == 0) {
    return result;
  }
  int idx = 0;
  for (ASTNode child = getFirstChildNode(); child != null && idx < count; child = child.getTreeNext()) {
    if (filter == null || filter.contains(child.getElementType())) {
      @SuppressWarnings("unchecked") T element = (T)child.getPsi();
      LOG.assertTrue(element != null, child);
      result[idx++] = element;
    }
  }
  return result;
}
 
源代码2 项目: BashSupport   文件: WordParsing.java
/**
 * Looks ahead if the current token is the start of a static double-quoted string value.
 *
 * @param builder         the current bulder
 * @param allowWhitespace if whitespace content is allowed
 * @return true if this is a quoted string which only consists of quotes and static string content
 */
public boolean isSimpleComposedString(BashPsiBuilder builder, boolean allowWhitespace) {
    if (builder.getTokenType() != STRING_BEGIN) {
        return false;
    }

    TokenSet accepted = TokenSet.create(STRING_CONTENT);
    if (allowWhitespace) {
        accepted = TokenSet.orSet(accepted, TokenSet.create(WHITESPACE));
    }

    int lookahead = 1;
    while (accepted.contains(builder.rawLookup(lookahead))) {
        lookahead++;
    }

    if (builder.rawLookup(lookahead) != STRING_END) {
        return false;
    }

    IElementType end = builder.rawLookup(lookahead + 1);
    return end == null || end == WHITESPACE || end == LINE_FEED;
}
 
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);
}
 
源代码4 项目: consulo   文件: ASTDelegatePsiElement.java
@RequiredReadAction
@Nonnull
protected <T extends PsiElement> List<T> findChildrenByType(TokenSet elementType) {
  List<T> result = EMPTY;
  ASTNode child = getNode().getFirstChildNode();
  while (child != null) {
    final IElementType tt = child.getElementType();
    if (elementType.contains(tt)) {
      if (result == EMPTY) {
        result = new ArrayList<T>();
      }
      result.add((T)child.getPsi());
    }
    child = child.getTreeNext();
  }
  return result;
}
 
源代码5 项目: Intellij-Plugin   文件: ConceptFoldingBuilder.java
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode astNode, @NotNull Document document) {
    List<FoldingDescriptor> descriptors = new ArrayList<>();
    for (ASTNode node : astNode.getChildren(TokenSet.create(ConceptTokenTypes.CONCEPT)))
        addNode(descriptors, node, node.findChildByType(ConceptTokenTypes.CONCEPT_HEADING));
    return descriptors.toArray(new FoldingDescriptor[0]);
}
 
源代码6 项目: consulo   文件: SyntaxHighlighterBase.java
/**
 * Tries to update the map by associating given keys with a given value.
 * Throws error if the map already contains different mapping for one of given keys.
 */
protected static void safeMap(
  @Nonnull final Map<IElementType, TextAttributesKey> map,
  @Nonnull final TokenSet keys,
  @Nonnull final TextAttributesKey value)
{
  for (final IElementType type : keys.getTypes()) {
    safeMap(map, type, value);
  }
}
 
源代码7 项目: consulo   文件: GeneratedParserUtilBase.java
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
  state.extendsSets = extendsSets;
  PsiFile file = builder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
  state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
  Language language = file == null? root.getLanguage() : file.getLanguage();
  state.caseSensitive = language.isCaseSensitive();
  PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
  state.braces = matcher == null ? null : matcher.getPairs();
  if (state.braces != null && state.braces.length == 0) state.braces = null;
}
 
@Nonnull
@Override
public TokenSet getWhitespaceTokens(@Nonnull LanguageVersion languageVersion) {
  if(languageVersion instanceof LanguageVersionWithParsing) {
    return ((LanguageVersionWithParsing)languageVersion).getWhitespaceTokens();
  }
  throw new IllegalArgumentException("'getWhitespaceTokens' need override for language version '" + languageVersion + "'");
}
 
源代码9 项目: consulo   文件: BaseIndentEnterHandler.java
public BaseIndentEnterHandler(
        final Language language,
        final TokenSet indentTokens,
        final IElementType lineCommentType,
        final String lineCommentPrefix,
        final TokenSet whitespaceTokens,
        final boolean worksWithFormatter)
{
  myLanguage = language;
  myIndentTokens = indentTokens;
  myLineCommentType = lineCommentType;
  myLineCommentPrefix = lineCommentPrefix;
  myWhitespaceTokens = whitespaceTokens;
  myWorksWithFormatter = worksWithFormatter;
}
 
源代码10 项目: consulo   文件: TokenSetBidiRegionsSeparator.java
@Override
public boolean createBorderBetweenTokens(@Nonnull IElementType previousTokenType, @Nonnull IElementType tokenType) {
  for (TokenSet set : myTokenSets) {
    if (set.contains(previousTokenType) && set.contains(tokenType)) {
      return false;
    }
  }
  return true;
}
 
@Nullable
@Override
public WordsScanner getWordsScanner() {
    RmlTypes types = RmlTypes.INSTANCE;
    return new DefaultWordsScanner(new RmlLexer(), TokenSet.create(types.C_UPPER_SYMBOL, types.C_LOWER_SYMBOL, types.C_VARIANT), TokenSet.EMPTY,
                                   TokenSet.EMPTY);
}
 
源代码12 项目: consulo   文件: PsiAwareLineWrapPositionStrategy.java
/**
 * Creates new <code>PsiAwareLineWrapPositionStrategy</code> object.
 * 
 * @param nonVirtualOnly  defines if current PSI-aware logic should be exploited only for 'real wrap' position requests
 * @param enabledTypes    target element/token types where line wrapping is allowed
 */
public PsiAwareLineWrapPositionStrategy(boolean nonVirtualOnly, @Nonnull IElementType ... enabledTypes) {
  myEnabledTypes = TokenSet.create(enabledTypes);
  myNonVirtualOnly = nonVirtualOnly;
  if (enabledTypes.length <= 0) {
    LOG.warn(String.format("%s instance is created with empty token/element types. That will lead to inability to perform line wrap",
                           getClass().getName()));
  }
}
 
源代码13 项目: consulo   文件: TreeUtil.java
@Nullable
public static ASTNode findParent(ASTNode element, TokenSet types) {
  for (ASTNode parent = element.getTreeParent(); parent != null; parent = parent.getTreeParent()) {
    if (types.contains(parent.getElementType())) return parent;
  }
  return null;
}
 
源代码14 项目: consulo-csharp   文件: CSharpCfsLanguageVersion.java
@Nonnull
@Override
public Lexer createInnerLexer()
{
	if(myExpressionElementType == null)
	{
		myExpressionElementType = createExpressionElementType();
	}
	return new MergingLexerAdapter(new CSharpInterpolationStringLexer(myExpressionElementType), TokenSet.create(myExpressionElementType, CfsTokens.TEXT, CfsTokens.FORMAT));
}
 
源代码15 项目: intellij-latte   文件: LatteFindUsagesProvider.java
@Nullable
@Override
public WordsScanner getWordsScanner() {
    return new DefaultWordsScanner(
            new LatteMacroLexerAdapter(),
            TokenSet.create(LatteTypes.PHP_VARIABLE),
            TokenSet.create(LatteTypes.MACRO_COMMENT),
            TokenSet.EMPTY
    );
}
 
源代码16 项目: glsl4idea   文件: GLSLTokenTypes.java
public static TokenSet merge(TokenSet... sets) {
    TokenSet tokenSet = TokenSet.create();
    for (TokenSet set : sets) {
        tokenSet = TokenSet.orSet(tokenSet, set);
    }
    return tokenSet;
}
 
源代码17 项目: consulo   文件: CompositeElement.java
@Override
@Nullable
public ASTNode findChildByType(@Nonnull TokenSet types) {
  if (DebugUtil.CHECK_INSIDE_ATOMIC_ACTION_ENABLED) {
    assertReadAccessAllowed();
  }
  for (ASTNode element = getFirstChildNode(); element != null; element = element.getTreeNext()) {
    if (types.contains(element.getElementType())) return element;
  }
  return null;
}
 
源代码18 项目: consulo-csharp   文件: CSharpBuilderWrapper.java
public boolean enableSoftKeyword(@Nonnull IElementType elementType)
{
	if(mySoftSet.contains(elementType))
	{
		return false;
	}
	mySoftSet = TokenSet.orSet(mySoftSet, TokenSet.create(elementType));
	return true;
}
 
源代码19 项目: consulo   文件: LightTreeUtil.java
@Nullable
public static LighterASTNode getParentOfType(@Nonnull LighterAST tree, @Nullable LighterASTNode node,
                                             @Nonnull TokenSet types, @Nonnull TokenSet stopAt) {
  if (node == null) return null;
  node = tree.getParent(node);
  while (node != null) {
    final IElementType type = node.getTokenType();
    if (types.contains(type)) return node;
    if (stopAt.contains(type)) return null;
    node = tree.getParent(node);
  }
  return null;
}
 
源代码20 项目: consulo   文件: PrattParsingUtil.java
public static boolean searchFor(final PrattBuilder builder, final boolean consume, final PrattTokenType... types) {
  final TokenSet set = TokenSet.create(types);
  if (!set.contains(builder.getTokenType())) {
    builder.assertToken(types[0]);
    while (!set.contains(builder.getTokenType()) && !builder.isEof()) {
      builder.advance();
    }
  }
  if (consume) {
    builder.advance();
  }
  return !builder.isEof();
}
 
源代码21 项目: consulo-csharp   文件: SharedParsingHelpers.java
@Nonnull
protected static <T> Pair<PsiBuilder.Marker, T> parseWithSoftElements(Function<CSharpBuilderWrapper, Pair<PsiBuilder.Marker, T>> func, CSharpBuilderWrapper builderWrapper, IElementType... softs)
{
	return parseWithSoftElements(func, builderWrapper, TokenSet.create(softs));
}
 
源代码22 项目: consulo   文件: IdTableBuilding.java
private static WordsScanner createWordScanner(final CustomSyntaxTableFileType customSyntaxTableFileType) {
  return new DefaultWordsScanner(new CustomFileTypeLexer(customSyntaxTableFileType.getSyntaxTable(), true), TokenSet.create(CustomHighlighterTokenType.IDENTIFIER),
                                 TokenSet.create(CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.MULTI_LINE_COMMENT),
                                 TokenSet.create(CustomHighlighterTokenType.STRING, CustomHighlighterTokenType.SINGLE_QUOTED_STRING));

}
 
@Nonnull
@Override
public TokenSet getWhitespaceTokens(@Nonnull LanguageVersion languageVersion)
{
	return TokenSet.create(CSharpTokens.WHITE_SPACE);
}
 
@Nullable
private static PsiBuilder.Marker parseBinary(final PsiBuilder builder, final ExprType type, final TokenSet ops)
{
	PsiBuilder.Marker result = parseExpression(builder, type);
	if(result == null)
	{
		return null;
	}
	int operandCount = 1;

	IElementType tokenType = builder.getTokenType();
	IElementType currentExprTokenType = tokenType;
	while(true)
	{
		if(tokenType == null || !ops.contains(tokenType))
		{
			break;
		}

		builder.advanceLexer();

		final PsiBuilder.Marker right = parseExpression(builder, type);
		operandCount++;
		tokenType = builder.getTokenType();
		if(tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType || right == null)
		{
			// save
			result = result.precede();
			if(right == null)
			{
				builder.error("Expression expected");
			}
			result.done(operandCount > 2 ? POLYADIC_EXPRESSION : BINARY_EXPRESSION);
			if(right == null)
			{
				break;
			}
			currentExprTokenType = tokenType;
			operandCount = 1;
		}
	}

	return result;
}
 
源代码25 项目: consulo   文件: LazyParseablePsiElement.java
@Override
@Nonnull
public PsiElement[] getChildren() {
  return getChildrenAsPsiElements((TokenSet)null, PsiElement.ARRAY_FACTORY);
}
 
@NotNull
public TokenSet getCommentTokens() {
	return COMMENTS;
}
 
@NotNull
public TokenSet getStringLiteralElements() {
    return STRINGS;
}
 
@NotNull
public TokenSet getCommentTokens() {
    return COMMENTS;
}
 
源代码29 项目: intellij-latte   文件: LatteParserDefinition.java
@NotNull
@Override
public TokenSet getCommentTokens() {
	return COMMENTS;
}
 
源代码30 项目: consulo-csharp   文件: SharedParsingHelpers.java
@Nullable
public static TypeInfo parseType(@Nonnull CSharpBuilderWrapper builder)
{
	return parseType(builder, NONE, TokenSet.EMPTY);
}
 
 类所在包
 同包方法