Java Code Examples for com.intellij.lang.ASTNode#getText()
The following examples show how to use
com.intellij.lang.ASTNode#getText() .
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: JSGraphQLEndpointFindUsagesProvider.java From js-graphql-intellij-plugin with MIT License | 6 votes |
@NotNull @Override public String getType(@NotNull PsiElement element) { if(element instanceof JSGraphQLEndpointInputValueDefinitionIdentifier) { return "argument"; } if(element instanceof JSGraphQLEndpointPropertyPsiElement) { return "field"; } final JSGraphQLEndpointNamedTypeDefinition definition = PsiTreeUtil.getParentOfType(element, JSGraphQLEndpointNamedTypeDefinition.class); if(definition != null) { // if it's a definition, use the keyword, e.g. 'type', 'interface' etc. final ASTNode keyword = definition.getNode().findChildByType(JSGraphQLEndpointTokenTypesSets.KEYWORDS); if(keyword != null) { return keyword.getText(); } } return "element"; }
Example 2
Source File: JSGraphQLEndpointNamedTypeDefPsiElement.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public String getDeclaration() { final StringBuilder sb = new StringBuilder(); for (ASTNode child : this.getParent().getNode().getChildren(null)) { final String text = child.getText(); if(text.startsWith("{")) { // don't include field definitions break; } sb.append(text); } return sb.toString(); }
Example 3
Source File: HaxeAstUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static boolean isNumber(@Nullable ASTNode t) { if (t != null) { String text = t.getText(); // Optimization: If it doesn't start with '+', '-', '.', or digit, it's not a number (ignoring 'Nan' and Infinity). // Using the Float class to detect numbers is fairly expensive. Before this optimization, about 2/3 of the // time we spent evaluating a conditional expression was spent in isFloat(). char firstChar = text.charAt(0); if (Character.isDigit(firstChar) || '.' == firstChar || '-' == firstChar || '+' == firstChar) { return isInteger(text) || isFloat(text); } } return false; }
Example 4
Source File: XQueryXmlSlashTypedHandler.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public Result charTyped(char c, final Project project, final @NotNull Editor editor, @NotNull final PsiFile editedFile) { if ((editedFile.getLanguage() instanceof XQueryLanguage) && c == '/') { PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return Result.CONTINUE; FileViewProvider provider = file.getViewProvider(); final int offset = editor.getCaretModel().getOffset(); PsiElement element = provider.findElementAt(offset - 1, XQueryLanguage.class); if (element == null) return Result.CONTINUE; if (!(element.getLanguage() instanceof XQueryLanguage)) return Result.CONTINUE; ASTNode prevLeaf = element.getNode(); if (prevLeaf == null) return Result.CONTINUE; final String prevLeafText = prevLeaf.getText(); if (isStartOfEndOfTag(prevLeaf, prevLeafText)) { XQueryXmlFullTag tag = PsiTreeUtil.getParentOfType(element, XQueryXmlFullTag.class); if (tag != null) { XQueryXmlTagName tagName = tag.getXmlTagNameList().get(0); if (hasNoClosingTagName(prevLeaf, tag, tagName)) { finishClosingTag(editor, tagName); return Result.STOP; } } } if (!"/".equals(prevLeafText.trim())) return Result.CONTINUE; prevLeaf = getPreviousNonWhiteSpaceLeaf(prevLeaf); if (prevLeaf == null) return Result.CONTINUE; if (PsiTreeUtil.getParentOfType(element, XQueryDirAttributeValue.class) != null) return Result.CONTINUE; if (prevLeaf.getElementType() == XQueryTypes.ELEMENTCONTENTCHAR) return Result.CONTINUE; XQueryEnclosedExpression parentEnclosedExpression = PsiTreeUtil.getParentOfType(element, XQueryEnclosedExpression.class, true, XQueryXmlFullTag.class); XQueryXmlFullTag fullTag = getParentFullTag(prevLeaf); if (isInEnclosedExpressionNestedInXmlTag(parentEnclosedExpression, fullTag)) return Result.CONTINUE; if (isInUnclosedXmlTag(fullTag)) { closeEmptyTag(editor); return Result.STOP; } } return Result.CONTINUE; }
Example 5
Source File: LombokConfigPsiUtil.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static String getKey(@NotNull LombokConfigCleaner element) { ASTNode keyNode = element.getNode().findChildByType(LombokConfigTypes.KEY); if (keyNode != null) { return keyNode.getText(); } else { return null; } }
Example 6
Source File: HXMLPsiImplUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static String getValue(HXMLProperty property) { ASTNode node = property.getNode().findChildByType(HXMLTypes.VALUE); if (node != null) { return node.getText(); } else { return null; } }
Example 7
Source File: MapNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 5 votes |
@Override public String getFieldName() { ASTNode nameNode = getFieldNameNode(); if (nameNode != null) { return nameNode.getText(); } return ""; }
Example 8
Source File: LombokConfigPsiUtil.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static String getValue(@NotNull LombokConfigProperty element) { ASTNode valueNode = element.getNode().findChildByType(LombokConfigTypes.VALUE); if (valueNode != null) { return valueNode.getText(); } else { return null; } }
Example 9
Source File: ASTShallowComparator.java From consulo with Apache License 2.0 | 5 votes |
private ThreeState textMatches(ASTNode oldNode, ASTNode newNode) { myIndicator.checkCanceled(); String oldText = TreeUtil.isCollapsedChameleon(oldNode) ? oldNode.getText() : null; String newText = TreeUtil.isCollapsedChameleon(newNode) ? newNode.getText() : null; if (oldText != null && newText != null) return oldText.equals(newText) ? ThreeState.YES : ThreeState.UNSURE; if (oldText != null) { return compareTreeToText((TreeElement)newNode, oldText) ? ThreeState.YES : ThreeState.UNSURE; } if (newText != null) { return compareTreeToText((TreeElement)oldNode, newText) ? ThreeState.YES : ThreeState.UNSURE; } if (oldNode instanceof ForeignLeafPsiElement) { return newNode instanceof ForeignLeafPsiElement && oldNode.getText().equals(newNode.getText()) ? ThreeState.YES : ThreeState.NO; } if (newNode instanceof ForeignLeafPsiElement) return ThreeState.NO; if (oldNode instanceof LeafElement) { return ((LeafElement)oldNode).textMatches(newNode.getText()) ? ThreeState.YES : ThreeState.NO; } if (newNode instanceof LeafElement) { return ((LeafElement)newNode).textMatches(oldNode.getText()) ? ThreeState.YES : ThreeState.NO; } if (oldNode instanceof PsiErrorElement && newNode instanceof PsiErrorElement) { final PsiErrorElement e1 = (PsiErrorElement)oldNode; final PsiErrorElement e2 = (PsiErrorElement)newNode; if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription())) return ThreeState.NO; } return ThreeState.UNSURE; }
Example 10
Source File: SqliteMagicLightMethodBuilder.java From sqlitemagic with Apache License 2.0 | 5 votes |
@Override public String getText() { ASTNode node = getNode(); if (null != node) { return node.getText(); } return ""; }
Example 11
Source File: HXMLPsiImplUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static String getValue(HXMLLib lib) { ASTNode node = lib.getNode().findChildByType(HXMLTypes.VALUE); if (node != null) { return node.getText(); } else { return null; } }
Example 12
Source File: BlockSupportImpl.java From consulo with Apache License 2.0 | 4 votes |
/** * Find ast node that could be reparsed incrementally * * @return Pair (target reparseable node, new replacement node) * or {@code null} if can't parse incrementally. */ @Nullable public static Couple<ASTNode> findReparseableRoots(@Nonnull PsiFileImpl file, @Nonnull FileASTNode oldFileNode, @Nonnull TextRange changedPsiRange, @Nonnull CharSequence newFileText) { final FileElement fileElement = (FileElement)oldFileNode; final CharTable charTable = fileElement.getCharTable(); int lengthShift = newFileText.length() - fileElement.getTextLength(); if (fileElement.getElementType() instanceof ITemplateDataElementType || isTooDeep(file)) { // unable to perform incremental reparse for template data in JSP, or in exceptionally deep trees return null; } final ASTNode leafAtStart = fileElement.findLeafElementAt(Math.max(0, changedPsiRange.getStartOffset() - 1)); final ASTNode leafAtEnd = fileElement.findLeafElementAt(Math.min(changedPsiRange.getEndOffset(), fileElement.getTextLength() - 1)); ASTNode node = leafAtStart != null && leafAtEnd != null ? TreeUtil.findCommonParent(leafAtStart, leafAtEnd) : fileElement; Language baseLanguage = file.getViewProvider().getBaseLanguage(); while (node != null && !(node instanceof FileElement)) { IElementType elementType = node.getElementType(); if (elementType instanceof IReparseableElementTypeBase || elementType instanceof IReparseableLeafElementType) { final TextRange textRange = node.getTextRange(); if (textRange.getLength() + lengthShift > 0 && (baseLanguage.isKindOf(elementType.getLanguage()) || !TreeUtil.containsOuterLanguageElements(node))) { final int start = textRange.getStartOffset(); final int end = start + textRange.getLength() + lengthShift; if (end > newFileText.length()) { reportInconsistentLength(file, newFileText, node, start, end); break; } CharSequence newTextStr = newFileText.subSequence(start, end); ASTNode newNode; if (elementType instanceof IReparseableElementTypeBase) { newNode = tryReparseNode((IReparseableElementTypeBase)elementType, node, newTextStr, file.getManager(), baseLanguage, charTable); } else { newNode = tryReparseLeaf((IReparseableLeafElementType)elementType, node, newTextStr); } if (newNode != null) { if (newNode.getTextLength() != newTextStr.length()) { String details = ApplicationManager.getApplication().isInternal() ? "text=" + newTextStr + "; treeText=" + newNode.getText() + ";" : ""; LOG.error("Inconsistent reparse: " + details + " type=" + elementType); } return Couple.of(node, newNode); } } } node = node.getTreeParent(); } return null; }
Example 13
Source File: FuncallExpression.java From intellij with Apache License 2.0 | 4 votes |
/** The name of the function being called. */ @Nullable public String getFunctionName() { ASTNode node = getFunctionNameNode(); return node != null ? node.getText() : null; }
Example 14
Source File: CodeEditUtil.java From consulo with Apache License 2.0 | 4 votes |
private static void markWhitespaceForReformat(final ASTNode right) { final String text = right.getText(); final LeafElement merged = ASTFactory.whitespace(text); right.getTreeParent().replaceChild(right, merged); }
Example 15
Source File: PsiCodeSnippetBody.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public PsiCodeSnippetBody(@Nonnull final ASTNode node) { super(node); text = node.getText(); }
Example 16
Source File: PsiTopicLevel.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public PsiTopicLevel(@Nonnull final ASTNode node) { super(node); final String text = node.getText(); this.level = ModelUtils.calcCharsOnStart('#', text); }
Example 17
Source File: HaxeExpressionEvaluator.java From intellij-haxe with Apache License 2.0 | 4 votes |
static private String getOperator(PsiElement element, TokenSet set) { ASTNode operatorNode = element.getNode().findChildByType(set); if (operatorNode == null) return ""; return operatorNode.getText(); }
Example 18
Source File: CompositeFoldingBuilder.java From consulo with Apache License 2.0 | 4 votes |
@RequiredReadAction @Override public String getPlaceholderText(@Nonnull ASTNode node) { final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER); return builder == null ? node.getText() : builder.getPlaceholderText(node); }
Example 19
Source File: SyntaxTraverser.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public CharSequence textOf(@Nonnull ASTNode node) { return node.getText(); }
Example 20
Source File: SampleItemPresentation.java From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License | 4 votes |
@Nullable @Override public String getPresentableText() { ASTNode node = element.getNode(); return node.getText(); }