本文整理汇总了Java中com.intellij.psi.tree.TokenSet.contains方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSet.contains方法的具体用法?Java TokenSet.contains怎么用?Java TokenSet.contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.tree.TokenSet
的用法示例。
在下文中一共展示了TokenSet.contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMergeFunction
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@Override
public MergeFunction getMergeFunction() {
return new MergeFunction() {
@Override
public IElementType merge(IElementType type, Lexer originalLexer) {
if (!allMergables.contains(type)) {
return type;
}
TokenSet merging = tokensToMerge.contains(type) ? tokensToMerge : tokensToMerge2;
while (true) {
final IElementType tokenType = originalLexer.getTokenType();
if (!merging.contains(tokenType)) break;
originalLexer.advance();
}
return merging == tokensToMerge ? LONGSTRING : LONGCOMMENT;
}
};
}
示例2: checkNodeAndSiblings
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@Nullable
private static ASTNode checkNodeAndSiblings(@Nullable ASTNode node, TokenSet tokens, ArrayList<FoldingDescriptor> regions, Document document) {
if (node != null && tokens.contains(node.getElementType())) {
final ASTNode start = node;
ASTNode end = start;
node = node.getTreeNext();
if (node != null) {
do {
end = node;
node = node.getTreeNext();
} while (node != null && tokens.contains(node.getElementType()));
}
if (end != start) {
while (end.getPsi() instanceof PsiWhiteSpace) {
end = end.getTreePrev();
}
if (isOnDifferentLine(start, end, document)) {
regions.add(new FoldingDescriptor(start, new TextRange(start.getStartOffset(), end.getTextRange().getEndOffset())));
}
}
}
return node;
}
示例3: getChildrenAsPsiElements
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@NotNull
public <T extends PsiElement> T[] getChildrenAsPsiElements(@Nullable TokenSet filter, ArrayFactory<T> constructor) {
ApplicationManager.getApplication().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;
}
示例4: skipElementsBack
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@Nullable
public static ASTNode skipElementsBack(@Nullable ASTNode element, TokenSet types) {
if (element == null) return null;
if (!types.contains(element.getElementType())) return element;
ASTNode parent = element.getTreeParent();
ASTNode prev = element;
while (prev instanceof CompositeElement) {
if (!types.contains(prev.getElementType())) return prev;
prev = prev.getTreePrev();
}
if (prev == null) return null;
ASTNode firstChildNode = parent.getFirstChildNode();
ASTNode lastRelevant = null;
while (firstChildNode != prev) {
if (!types.contains(firstChildNode.getElementType())) lastRelevant = firstChildNode;
firstChildNode = firstChildNode.getTreeNext();
}
return lastRelevant;
}
示例5: getChildren
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@NotNull
@Override
public ASTNode[] getChildren(@Nullable TokenSet filter) {
int count = countChildren(filter);
if (count == 0) {
return EMPTY_ARRAY;
}
final ASTNode[] result = new ASTNode[count];
count = 0;
for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (filter == null || filter.contains(child.getElementType())) {
result[count++] = child;
}
}
return result;
}
示例6: annotate
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
if (psiElement instanceof TagElement) {
TagElement tagElement = (TagElement) psiElement;
TokenSet allowedRBraces = SoyTokenTypes.RIGHT_BRACES;
if (mustCloseRBraceTags.contains(tagElement.getClass())) {
allowedRBraces = TokenSet.andNot(allowedRBraces, SoyTokenTypes.SLASH_R_BRACES);
} else if (mustCloseSlashRBraceTags.contains(tagElement.getClass())) {
allowedRBraces = TokenSet.andSet(allowedRBraces, SoyTokenTypes.SLASH_R_BRACES);
}
if (tagElement.isDoubleBraced()) {
allowedRBraces = TokenSet.andSet(allowedRBraces, SoyTokenTypes.DOUBLE_BRACES);
} else {
allowedRBraces = TokenSet.andNot(allowedRBraces, SoyTokenTypes.DOUBLE_BRACES);
}
if (!allowedRBraces.contains(tagElement.getClosingBraceType())) {
annotationHolder.createErrorAnnotation(tagElement, "Must close by " +
Stream.of(allowedRBraces.getTypes())
.map(SoyTokenTypes.BRACE_TYPE_TO_STRING::get)
.sorted()
.collect(Collectors.joining(" or ")));
}
}
}
示例7: skipSiblingsBackward
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
/**
* Works similarly to {@link PsiTreeUtil#skipSiblingsBackward(PsiElement, Class[])}, but for AST nodes.
*/
@Nullable
public static ASTNode skipSiblingsBackward(@Nullable ASTNode node, @NotNull TokenSet types) {
if (node == null) {
return null;
}
for (ASTNode prev = node.getTreePrev(); prev != null; prev = prev.getTreePrev()) {
if (!types.contains(prev.getElementType())) {
return prev;
}
}
return null;
}
示例8: isComment
import com.intellij.psi.tree.TokenSet; //导入方法依赖的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());
}
示例9: findSiblingBackward
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@Nullable
public static ASTNode findSiblingBackward(ASTNode start, TokenSet types) {
ASTNode child = start;
while (true) {
if (child == null) return null;
if (types.contains(child.getElementType())) return child;
child = child.getTreePrev();
}
}
示例10: deriveNodeOfTargetType
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
/**
* There is a possible case that given base node doesn't have {@link AlignmentInColumnsConfig#getTargetDeclarationTypes() target type}
* but its first child node or first child node of the first child node etc does.
* <p/>
* This method tries to derive node of the target type from the given node.
*
* @param baseNode base node to process
* @param targetTypes target node types
* @return base node or its first descendant child that has
* {@link AlignmentInColumnsConfig#getTargetDeclarationTypes() target type} target type if the one if found;
* <code>null</code> otherwise
*/
@Nullable
private static ASTNode deriveNodeOfTargetType(ASTNode baseNode, TokenSet targetTypes) {
if (targetTypes.contains(baseNode.getElementType())) {
return baseNode;
}
for (ASTNode node = baseNode; node != null; node = node.getFirstChildNode()) {
IElementType nodeType = node.getElementType();
if (targetTypes.contains(nodeType)) {
return node;
}
}
return null;
}
示例11: parseModifierList
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
@NotNull
public Pair<PsiBuilder.Marker, Boolean> parseModifierList(final PsiBuilder builder, final TokenSet modifiers) {
final PsiBuilder.Marker modList = builder.mark();
boolean isEmpty = true;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == null) break;
if (modifiers.contains(tokenType)) {
builder.advanceLexer();
isEmpty = false;
}
else if (tokenType == JavaTokenType.AT) {
if (ElementType.KEYWORD_BIT_SET.contains(builder.lookAhead(1))) {
break;
}
parseAnnotation(builder);
isEmpty = false;
}
else {
break;
}
}
done(modList, JavaElementType.MODIFIER_LIST);
return Pair.create(modList, isEmpty);
}
示例12: scanChildren
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
private static void scanChildren(CompositeElement element, ASTNode node, TokenSet listTypes, boolean forward) {
ASTNode child = node;
while (true) {
child = (forward ? child.getTreeNext() : child.getTreePrev());
if (child == null || child.getElementType() == JavaTokenType.COMMA) break;
if (listTypes.contains(child.getElementType())) {
CharTable charTable = SharedImplUtil.findCharTableByTree(element);
PsiManager manager = element.getPsi().getManager();
TreeElement comma = Factory.createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, charTable, manager);
element.addInternal(comma, comma, (forward ? node : child), Boolean.FALSE);
break;
}
}
}
示例13: consumeBadTokens
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
private static void consumeBadTokens(PsiBuilder builder, TokenSet nextAccepted) {
if (nextAccepted.getTypes().length == 0 && builder.eof()) {
return;
}
if (!nextAccepted.contains(builder.getTokenType())) {
builder.error("Unexpected token");
do {
if (builder.eof()) {
builder.error("Unexpected end of file");
break;
}
builder.advanceLexer();
} while (!nextAccepted.contains(builder.getTokenType()));
}
}
示例14: skipSet
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
private static PsiElement skipSet(PsiElement elem, boolean forward, TokenSet set, boolean skipNLs) {
while (elem != null &&
elem.getNode() != null &&
set.contains(elem.getNode().getElementType()) &&
(skipNLs || elem.getText().indexOf('\n') == -1)) {
if (forward) {
elem = elem.getNextSibling();
}
else {
elem = elem.getPrevSibling();
}
}
return elem;
}
示例15: handleAfterJavaLT
import com.intellij.psi.tree.TokenSet; //导入方法依赖的package包/类
public static void handleAfterJavaLT(final Editor editor,
final IElementType lt,
final IElementType gt,
final TokenSet invalidInsideReference) {
if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) return;
int offset = editor.getCaretModel().getOffset();
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
while (iterator.getStart() > 0 && !invalidInsideReference.contains(iterator.getTokenType())) {
iterator.retreat();
}
if (invalidInsideReference.contains(iterator.getTokenType())) iterator.advance();
int balance = 0;
while (!iterator.atEnd() && balance >= 0) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == lt) {
balance++;
}
else if (tokenType == gt) {
balance--;
}
else if (invalidInsideReference.contains(tokenType)) {
break;
}
iterator.advance();
}
if (balance == 1) {
editor.getDocument().insertString(offset, ">");
}
}