本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isJavaToken方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isJavaToken方法的具体用法?Java PsiUtil.isJavaToken怎么用?Java PsiUtil.isJavaToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.isJavaToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void delete() throws IncorrectOperationException {
final PsiElement next = PsiTreeUtil.skipSiblingsForward(this, PsiWhiteSpace.class, PsiComment.class);
if (PsiUtil.isJavaToken(next, JavaTokenType.SEMICOLON)) {
getParent().deleteChildRange(this, next);
return;
}
final PsiElement prev = PsiTreeUtil.skipSiblingsBackward(this, PsiWhiteSpace.class, PsiComment.class);
if (PsiUtil.isJavaToken(prev, JavaTokenType.SEMICOLON)) {
getParent().deleteChildRange(prev, this);
return;
}
super.delete();
}
示例2: invoke
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
if (element != null && PsiUtil.isJavaToken(element, JavaTokenType.CHARACTER_LITERAL)) {
final String text = StringUtil.unescapeStringCharacters(element.getText());
final int length = text.length();
if (length > 1 && text.charAt(0) == '\'' && text.charAt(length - 1) == '\'') {
final String value = StringUtil.escapeStringCharacters(text.substring(1, length - 1));
final PsiExpression expression = JavaPsiFacade.getElementFactory(project).createExpressionFromText('"' + value + '"', null);
final PsiElement literal = expression.getFirstChild();
if (literal != null && PsiUtil.isJavaToken(literal, JavaTokenType.STRING_LITERAL)) {
element.replace(literal);
}
}
}
}
示例3: collectAnnotations
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static List<PsiAnnotation[]> collectAnnotations(PsiElement anchor, PsiAnnotation stopAt) {
List<PsiAnnotation[]> annotations = ContainerUtil.newSmartList();
List<PsiAnnotation> current = null;
boolean found = (stopAt == null), stop = false;
for (PsiElement child = anchor.getNextSibling(); child != null; child = child.getNextSibling()) {
if (child instanceof PsiComment || child instanceof PsiWhiteSpace) continue;
if (child instanceof PsiAnnotation) {
if (current == null) current = ContainerUtil.newSmartList();
current.add((PsiAnnotation)child);
if (child == stopAt) found = stop = true;
continue;
}
if (PsiUtil.isJavaToken(child, JavaTokenType.LBRACKET)) {
annotations.add(ContainerUtil.toArray(current, PsiAnnotation.ARRAY_FACTORY));
current = null;
if (stop) return annotations;
}
else if (!PsiUtil.isJavaToken(child, JavaTokenType.RBRACKET)) {
break;
}
}
// annotation is misplaced (either located before the anchor or has no following brackets)
return !found || stop ? null : annotations;
}
示例4: visitAnnotationArrayInitializer
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitAnnotationArrayInitializer(final PsiArrayInitializerMemberValue initializer) {
if (PsiUtil.isLanguageLevel7OrHigher(initializer)) return;
final PsiElement lastElement = PsiTreeUtil.skipSiblingsBackward(initializer.getLastChild(), PsiWhiteSpace.class, PsiComment.class);
if (lastElement != null && PsiUtil.isJavaToken(lastElement, JavaTokenType.COMMA)) {
final String message = InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.problem");
final String fixName = InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.fix");
myHolder.registerProblem(lastElement, message, new RemoveElementQuickFix(fixName));
}
}
示例5: findTopLevelSemicolons
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void findTopLevelSemicolons(PsiElement element) {
for (PsiElement sibling = element.getFirstChild(); sibling != null; sibling = skipForwardWhiteSpacesAndComments(sibling)) {
if (PsiUtil.isJavaToken(sibling, JavaTokenType.SEMICOLON)) {
registerError(sibling, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
示例6: match
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
if (patternNode instanceof PsiComment) {
return myCommentHandler.match(patternNode, matchedNode, context);
}
if (!super.match(patternNode,matchedNode,context)) return false;
final PsiDeclarationStatement dcl = (PsiDeclarationStatement)patternNode;
if (matchedNode instanceof PsiDeclarationStatement) {
return GlobalMatchingVisitor.continueMatchingSequentially(
new SsrFilteringNodeIterator(patternNode.getFirstChild()),
new SsrFilteringNodeIterator(matchedNode.getFirstChild()),
context
);
}
final PsiElement[] declared = dcl.getDeclaredElements();
// declaration statement could wrap class or dcl
if (declared.length > 0 && !(matchedNode.getParent() instanceof PsiDeclarationStatement) /* skip twice matching for child*/) {
if (!(matchedNode instanceof PsiField)) {
return GlobalMatchingVisitor.continueMatchingSequentially(
new ArrayBackedNodeIterator(declared),
new CountingNodeIterator(declared.length, new SsrFilteringNodeIterator(matchedNode)),
context
);
}
// special handling for multiple fields in single declaration
final PsiElement sibling = PsiTreeUtil.skipSiblingsBackward(matchedNode, PsiWhiteSpace.class);
if (PsiUtil.isJavaToken(sibling, JavaTokenType.COMMA)) {
return false;
}
final List<PsiElement> matchNodes = new ArrayList<PsiElement>();
matchNodes.add(matchedNode);
PsiElement node = matchedNode;
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
while (PsiUtil.isJavaToken(node, JavaTokenType.COMMA)) {
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
if (node != null) {
matchNodes.add(node);
}
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
}
boolean result = GlobalMatchingVisitor.continueMatchingSequentially(
new ArrayBackedNodeIterator(declared),
new ArrayBackedNodeIterator(matchNodes.toArray(new PsiElement[matchNodes.size()])),
context
);
if (result && declared[0] instanceof PsiVariable) {
// we may have comments behind to match!
final PsiElement lastChild = dcl.getLastChild();
if (lastChild instanceof PsiComment) {
final PsiElement[] fieldChildren = matchedNode.getChildren();
result = context.getPattern().getHandler(lastChild).match(
lastChild,
fieldChildren[fieldChildren.length-1],
context
);
}
}
return result;
}
return false;
}
示例7: isAvailable
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
return PsiUtil.isJavaToken(element, JavaTokenType.CHARACTER_LITERAL);
}