Java Code Examples for com.intellij.lang.ASTNode#findChildByType()
The following examples show how to use
com.intellij.lang.ASTNode#findChildByType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoSyntaxKeywordsAnnotator.java From protobuf-jetbrains-plugin with Apache License 2.0 | 6 votes |
@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof KeywordsContainer) { KeywordsContainer container = (KeywordsContainer) element; for (PsiElement psiElement : container.keywords()) { setHighlighting(psiElement, holder, ProtoSyntaxHighlighter.KEYWORD); } } if (element instanceof EnumConstantNode) { ASTNode node = element.getNode(); ASTNode name = node.findChildByType(ProtoParserDefinition.rule(ProtoParser.RULE_enumFieldName)); if (name != null) { setHighlighting(name.getPsi(), holder, ProtoSyntaxHighlighter.ENUM_CONSTANT); } } }
Example 2
Source File: RemoveVariableInitializer.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override @RequiredWriteAction public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { DotNetVariable element = myPointer.getElement(); if(element == null) { return; } PsiDocumentManager.getInstance(project).commitAllDocuments(); DotNetExpression initializer = element.getInitializer(); if(initializer == null) { return; } initializer.delete(); ASTNode node = element.getNode(); ASTNode childByType = node.findChildByType(CSharpTokenSets.EQ); if(childByType != null) { node.removeChild(childByType); } }
Example 3
Source File: LattePsiImplUtil.java From intellij-latte with MIT License | 5 votes |
private static @Nullable ASTNode getMacroNameNode(LatteMacroTag element) { ASTNode elementNode = element.getNode(); ASTNode nameNode = elementNode.findChildByType(T_MACRO_NAME); if (nameNode != null) { return nameNode; } return elementNode.findChildByType(T_MACRO_SHORTNAME); }
Example 4
Source File: JSGraphQLEndpointImportFileReferencePsiElement.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Nullable @Override public PsiElement getNameIdentifier() { final PsiElement stringElement = this.findChildByType(JSGraphQLEndpointTokenTypes.QUOTED_STRING); if(stringElement != null) { final ASTNode string = stringElement.getNode().findChildByType(JSGraphQLEndpointTokenTypes.STRING); if(string != null) { final ASTNode stringBody = string.findChildByType(JSGraphQLEndpointTokenTypes.STRING_BODY); if (stringBody != null) { return stringBody.getPsi(); } } } return null; }
Example 5
Source File: GraphQLFoldingBuilder.java From js-graphql-intellij-plugin with MIT License | 5 votes |
private static void buildFolding(ASTNode node, List<FoldingDescriptor> list) { boolean isBlock = GraphQLBlock.INDENT_PARENTS.contains(node.getElementType()); if(!isBlock && GraphQLElementTypes.QUOTED_STRING.equals(node.getElementType())) { // triple quoted multi-line strings should support folding ASTNode quote = node.findChildByType(GraphQLElementTypes.OPEN_QUOTE); isBlock = quote != null && quote.getTextLength() == 3; } if (isBlock && !node.getTextRange().isEmpty()) { final TextRange range = node.getTextRange(); list.add(new FoldingDescriptor(node, range)); } for (ASTNode child : node.getChildren(null)) { buildFolding(child, list); } }
Example 6
Source File: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public JSExpression getCollection() { final ASTNode myNode = getNode(); final ASTNode secondExpression = myNode.findChildByType( JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) ); return secondExpression != null ? (JSExpression) secondExpression.getPsi() : null; }
Example 7
Source File: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public JSExpression getCollection() { final ASTNode myNode = getNode(); final ASTNode secondExpression = myNode.findChildByType( JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) ); return secondExpression != null ? (JSExpression) secondExpression.getPsi() : null; }
Example 8
Source File: BuildFileFoldingBuilder.java From intellij with Apache License 2.0 | 5 votes |
private static void foldFunctionDefinition(List<FoldingDescriptor> descriptors, ASTNode node) { ASTNode colon = node.findChildByType(BuildToken.fromKind(TokenKind.COLON)); if (colon == null) { return; } ASTNode stmtList = node.findChildByType(BuildElementTypes.STATEMENT_LIST); if (stmtList == null) { return; } int start = colon.getStartOffset() + 1; int end = endOfList(stmtList); descriptors.add(new FoldingDescriptor(node, range(start, end))); }
Example 9
Source File: GroupNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 5 votes |
@Override public Collection<PsiElement> keywords() { ASTNode node = getNode(); List<PsiElement> result = new ArrayList<>(); result.addAll(Util.findKeywords(getNode())); ASTNode fieldModifier = node.findChildByType(R_FIELD_MODIFIER); if (fieldModifier != null) { result.addAll(Util.findKeywords(fieldModifier)); } return result; }
Example 10
Source File: CSharpSmartEnterProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public boolean process(@Nonnull Editor editor, @Nonnull PsiFile psiFile) { PsiElement statementAtCaret = getStatementAtCaret(editor, psiFile); DotNetStatement statement = PsiTreeUtil.getParentOfType(statementAtCaret, DotNetStatement.class); if(statement == null) { return false; } if(statement instanceof CSharpBlockStatementImpl) { return false; } if(statement instanceof CSharpStatementAsStatementOwner) { DotNetStatement childStatement = ((CSharpStatementAsStatementOwner) statement).getChildStatement(); if(childStatement == null) { insertStringAtEndWithReformat("{}", statement, editor, 1, true); return false; } } else { ASTNode node = statement.getNode(); ASTNode semicolonNode = node.findChildByType(CSharpTokens.SEMICOLON); if(semicolonNode != null) { return false; } insertStringAtEndWithReformat(";", statement, editor, 1, true); } return true; }
Example 11
Source File: CS0145.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { DotNetVariable element = myVariablePointer.getElement(); if(element == null) { return; } PsiDocumentManager.getInstance(project).commitAllDocuments(); String defaultValueForType = MethodGenerateUtil.getDefaultValueForType(element.toTypeRef(false), element); if(defaultValueForType == null) { return; } DotNetExpression expression = CSharpFileFactory.createExpression(project, defaultValueForType); PsiElement nameIdentifier = element.getNameIdentifier(); if(nameIdentifier == null) { return; } ASTNode variableNode = element.getNode(); ASTNode semicolon = variableNode.findChildByType(CSharpTokens.SEMICOLON); variableNode.addLeaf(CSharpTokens.WHITE_SPACE, " ", semicolon); variableNode.addLeaf(CSharpTokens.EQ, "=", semicolon); variableNode.addLeaf(CSharpTokens.WHITE_SPACE, " ", semicolon); ASTNode node = expression.getNode(); CodeEditUtil.setOldIndentation((TreeElement) node, 0); variableNode.addChild(node, semicolon); editor.getCaretModel().moveToOffset(element.getTextRange().getEndOffset()); }
Example 12
Source File: BashVarDefImpl.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Returns either a assignment word element or a array assignment word. * * @return The element which represents the left part of the assignment. */ @NotNull public PsiElement findAssignmentWord() { if (assignmentWord == null) { //no other lock is used in the callees, it's safe to synchronize around the whole calculation synchronized (stateLock) { if (assignmentWord == null) { PsiElement element = findChildByType(accepted); PsiElement newAssignmentWord; if (element != null) { newAssignmentWord = element; } else { //if null we probably represent a single var without assignment, i.e. the var node is nested inside of //a parsed var PsiElement firstChild = getFirstChild(); ASTNode childNode = firstChild != null ? firstChild.getNode() : null; ASTNode node = childNode != null ? childNode.findChildByType(accepted) : null; newAssignmentWord = (node != null) ? node.getPsi() : firstChild; } assignmentWord = newAssignmentWord; } } } return assignmentWord; }
Example 13
Source File: MapNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
@Override public ASTNode getTagNode() { ASTNode node = getNode(); return node.findChildByType(R_TAG); }
Example 14
Source File: GroupNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
@Override public ASTNode getFieldNameNode() { ASTNode node = getNode(); return node.findChildByType(R_GROUP_NAME); }
Example 15
Source File: GroupNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
@Override public ASTNode getTagNode() { ASTNode node = getNode(); return node.findChildByType(R_TAG); }
Example 16
Source File: GroupNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
@Override public ASTNode getFieldLabelNode() { ASTNode node = getNode(); return node.findChildByType(R_FIELD_MODIFIER); }
Example 17
Source File: MarkdownDocumentationProvider.java From markdown-doclet with GNU General Public License v3.0 | 4 votes |
@Nullable @Override public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { boolean process = false; for ( Class supported: SUPPORTED_ELEMENT_TYPES ) { if ( supported.isInstance(element) ) { process = true; break; } } if ( !process ) { return null; } PsiFile file = null; if ( element instanceof PsiDirectory ) { // let's see whether we can map the directory to a package; if so, change the // element to the package and continue PsiPackage pkg = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element); if ( pkg != null ) { element = pkg; } else { return null; } } if ( element instanceof PsiPackage ) { for ( PsiDirectory dir : ((PsiPackage)element).getDirectories() ) { PsiFile info = dir.findFile(PsiPackage.PACKAGE_INFO_FILE); if ( info != null ) { ASTNode node = info.getNode(); if ( node != null ) { ASTNode docCommentNode = node.findChildByType(JavaDocElementType.DOC_COMMENT); if ( docCommentNode != null ) { // the default implementation will now use this file // we're going to take over below, if Markdown is enabled in // the corresponding module // see JavaDocInfoGenerator.generatePackageJavaDoc() file = info; break; } } } if ( dir.findFile("package.html") != null ) { // leave that to the default return null; } } } else { if ( JavaLanguage.INSTANCE.equals(element.getLanguage()) ) { element = element.getNavigationElement(); if ( element.getContainingFile() != null ) { file = element.getContainingFile(); } } } if ( file != null ) { DocCommentProcessor processor = new DocCommentProcessor(file); if ( processor.isEnabled() ) { String docHtml; if ( element instanceof PsiMethod ) { docHtml = super.generateDoc(PsiProxy.forMethod((PsiMethod)element), originalElement); } else if ( element instanceof PsiParameter ) { docHtml = super.generateDoc(PsiProxy.forParameter((PsiParameter)element), originalElement); } else { MarkdownJavaDocInfoGenerator javaDocInfoGenerator = new MarkdownJavaDocInfoGenerator(element.getProject(), element, processor); List<String> docURLs = getExternalJavaDocUrl(element); String text = javaDocInfoGenerator.generateDocInfo(docURLs); Plugin.print("Intermediate HTML output", text); docHtml = JavaDocExternalFilter.filterInternalDocInfo(text); } docHtml = extendCss(docHtml); Plugin.print("Final HTML output", docHtml); return docHtml; } else { return null; } } else { return null; } }
Example 18
Source File: MapNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
@Override public ASTNode getFieldNameNode() { ASTNode node = getNode(); return node.findChildByType(R_FIELD_NAME); }
Example 19
Source File: EnumConstantNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
public ASTNode getConstantValueNode() { ASTNode node = getNode(); return node.findChildByType(rule(RULE_enumFieldValue)); }
Example 20
Source File: EnumConstantNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 4 votes |
public ASTNode getConstantNameNode() { ASTNode node = getNode(); return node.findChildByType(rule(RULE_enumFieldName)); }