Java Code Examples for com.intellij.lang.ASTNode.findChildByType()

The following are Jave code examples for showing how to use findChildByType() of the com.intellij.lang.ASTNode class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TS-IJ   File: TSPsiImplUtil.java   Source Code and License Vote up 6 votes
public static String getName(TSObjectExpr obj) {
    //Should be the first element after the open paren
    ASTNode node = obj.getNode();
    if (node == null) {
        return null;
    }
    ASTNode openParen = node.findChildByType(TSTypes.PAREN_OPEN);
    if (openParen == null) {
        return null;
    }
    PsiElement nameNode = openParen.getPsi().getNextSibling();
    if (nameNode == null) {
        return null;
    }
    if (nameNode instanceof TSLiteralExpr) {
        return ((TSLiteralExpr) nameNode).getName();
    }
    if (nameNode.getNode().getElementType().equals(TSTypes.ID)) {
        return nameNode.getText();
    }
    return null;
}
 
Example 2
Project: TS-IJ   File: TSClassNameAnnotator.java   Source Code and License Vote up 5 votes
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    PsiElement classElement = null;
    if (element instanceof  TSDatablockDecl) {
        TSDatablockDecl db = (TSDatablockDecl) element;

        //Find the first id node, this is kinda wonky since we have to account for whitespace nodes
        //datablock ClassName(...)
        ASTNode node = db.getNode();
        if (node == null) {
            return;
        }
        node = node.findChildByType(TSTypes.ID);
        if (node == null) {
            return;
        }
        classElement = node.getPsi();
    } else if (element instanceof TSObjectExpr) {
        TSObjectExpr obj = (TSObjectExpr) element;

        //Class name should be the second thing in the element:
        // new ClassName(...)
        classElement = PsiTreeUtil.getChildOfType(obj, TSClassNameExpr.class);

        if (classElement == null) {
            return;
        }
        classElement = classElement.getFirstChild();
    }
    if (classElement == null) {
        return;
    }

    //Only annotate if it's an id, can't really tell if it's an expr
    if (classElement.getNode().getElementType().equals(TSTypes.ID)) {
        createSuccessAnnotation(classElement, holder, TSSyntaxHighlighter.CLASSNAME);
    }
}
 
Example 3
Project: AppleScript-IDEA   File: AppleScriptPsiImplUtil.java   Source Code and License Vote up 4 votes
public static boolean useStandardAdditions(AppleScriptUseStatement useStatement) {
  ASTNode node = useStatement.getNode();
  return node.findChildByType(AppleScriptTypes.SCRIPTING_ADDITIONS) != null;
}
 
Example 4
Project: AppleScript-IDEA   File: AppleScriptPsiImplUtil.java   Source Code and License Vote up 4 votes
public static boolean withImportingStdLibrary(AppleScriptUsingTermsFromStatement usingTermsStatement) {
  ASTNode node = usingTermsStatement.getNode();
  return node.findChildByType(AppleScriptTypes.SCRIPTING_ADDITIONS) != null;
}