ASTNode (int role) { assert ChildRole.isUnique(role); switch (role) { default: return null; case ChildRole.DOC_COMMENT: return PsiImplUtil.findDocComment(this); case ChildRole.ENUM_CONSTANT_LIST_DELIMITER: return isEnum() ? findEnumConstantListDelimiter() : null; case ChildRole.MODIFIER_LIST: return findChildByType(MODIFIER_LIST); case ChildRole.EXTENDS_LIST: return findChildByType(EXTENDS_LIST); case ChildRole.IMPLEMENTS_LIST: return findChildByType(IMPLEMENTS_LIST); case ChildRole.PERMITS_LIST: return findChildByType(PERMITS_LIST); case ChildRole.TYPE_PARAMETER_LIST: return findChildByType(TYPE_PARAMETER_LIST); case ChildRole.CLASS_OR_INTERFACE_KEYWORD: if (this instanceof UnnamedClassElement) { return null; } for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) { if (CLASS_KEYWORD_BIT_SET.contains(child.getElementType())) return child; } String message = "Node not found. Immediate children are:---\n"; for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) { message += child.getClass() + "(" + child.getElementType() + ") " + child + "\n"; } message += "---"; LOG.error(message); return null; case ChildRole.NAME: return findChildByType(IDENTIFIER); case ChildRole.LBRACE: return findChildByType(LBRACE); case ChildRole.RBRACE: return TreeUtil.findChildBackward(this, RBRACE); case ChildRole.AT: ASTNode modifierList = findChildByRole(ChildRole.MODIFIER_LIST); if (modifierList != null) { ASTNode treeNext = modifierList.getTreeNext(); if (treeNext != null) { treeNext = PsiImplUtil.skipWhitespaceAndComments(treeNext); if (treeNext.getElementType() == AT) return treeNext; } } return null; } }