Java Code Examples for com.intellij.psi.PsiElement#getNextSibling()
The following examples show how to use
com.intellij.psi.PsiElement#getNextSibling() .
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: PsiUtil.java From arma-intellij-plugin with MIT License | 6 votes |
private static <E extends PsiElement> void findDescendantElementsOfInstance(@NotNull PsiElement rootElement, @NotNull Class<?> type, @Nullable PsiElement cursor, @Nullable String textContent, @NotNull List<E> list) { PsiElement child = rootElement.getFirstChild(); while (child != null) { if (cursor != null && child == cursor) { continue; } if (type.isAssignableFrom(child.getClass()) && (textContent == null || child.getText().equals(textContent))) { list.add((E) child); } findDescendantElementsOfInstance(child, type, cursor, textContent, list); child = child.getNextSibling(); } }
Example 2
Source File: GLSLForStatement.java From glsl4idea with GNU Lesser General Public License v3.0 | 6 votes |
/** * Fetches the initialization, the condition and the counter elements and places them in an array. * The array will always have length 3 and the elements are always placed in their respective places. * They will be null if missing. * * @return an array containing the loop elements. */ @NotNull private GLSLElement[] getForElements() { GLSLElement[] result = new GLSLElement[3]; int numberOfSemicolonsPassed = 0; PsiElement current = getFirstChild(); while (current != null) { ASTNode node = current.getNode(); if (current instanceof GLSLExpression || current instanceof GLSLDeclaration) { result[numberOfSemicolonsPassed] = (GLSLElement) current; } else if (node != null) { if (node.getElementType() == GLSLTokenTypes.SEMICOLON) { numberOfSemicolonsPassed++; } if (node.getElementType() == GLSLTokenTypes.RIGHT_PAREN) { break; } } current = current.getNextSibling(); } return result; }
Example 3
Source File: CsvIntentionHelper.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public static PsiElement findQuotePositionsUntilSeparator(final PsiElement element, List<Integer> quotePositions, boolean stopAtEscapedTexts) { PsiElement currentElement = element; PsiElement separatorElement = null; while (separatorElement == null && currentElement != null) { if (CsvHelper.getElementType(currentElement) == CsvTypes.COMMA || CsvHelper.getElementType(currentElement) == CsvTypes.CRLF || (stopAtEscapedTexts && CsvHelper.getElementType(currentElement) == CsvTypes.ESCAPED_TEXT)) { separatorElement = currentElement; continue; } if (currentElement.getFirstChild() != null) { separatorElement = findQuotePositionsUntilSeparator(currentElement.getFirstChild(), quotePositions, stopAtEscapedTexts); } else if (currentElement.getText().equals("\"")) { quotePositions.add(currentElement.getTextOffset()); } currentElement = currentElement.getNextSibling(); } return separatorElement; }
Example 4
Source File: CSharpLocalVariableImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
private static void removeWithNextSibling(PsiElement element, IElementType token, List<PsiElement> collectForDelete) { PsiElement nextSibling = element.getNextSibling(); if(nextSibling instanceof PsiWhiteSpace) { collectForDelete.add(nextSibling); nextSibling = nextSibling.getNextSibling(); } if(nextSibling != null && nextSibling.getNode().getElementType() == token) { collectForDelete.add(nextSibling); nextSibling = nextSibling.getNextSibling(); } if(nextSibling instanceof PsiWhiteSpace) { collectForDelete.add(nextSibling); } }
Example 5
Source File: BashAnnotator.java From BashSupport with Apache License 2.0 | 6 votes |
private void annotateWord(PsiElement bashWord, AnnotationHolder annotationHolder) { //we have to mark the remapped tokens (which are words now) to have the default word formatting. PsiElement child = bashWord.getFirstChild(); while (child != null && false) { if (!noWordHighlightErase.contains(child.getNode().getElementType())) { Annotation annotation = annotationHolder.createInfoAnnotation(child, null); annotation.setEnforcedTextAttributes(TextAttributes.ERASE_MARKER); annotation = annotationHolder.createInfoAnnotation(child, null); annotation.setEnforcedTextAttributes(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(HighlighterColors.TEXT)); } child = child.getNextSibling(); } }
Example 6
Source File: PsiUtil.java From arma-intellij-plugin with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T findFirstDescendantElement(@NotNull PsiElement element, @NotNull Class<T> type) { PsiElement child = element.getFirstChild(); while (child != null) { if (type.isInstance(child)) { return (T) child; } T e = findFirstDescendantElement(child, type); if (e != null) { return e; } child = child.getNextSibling(); } return null; }
Example 7
Source File: ElmAddImportHelper.java From elm-plugin with MIT License | 5 votes |
private static PsiElement skipOverDocComments(PsiElement startElement) { PsiElement elt = startElement.getNextSibling(); if (elt == null) { return startElement; } else if (elt instanceof PsiComment) { IElementType commentType = ((PsiComment) elt).getTokenType(); if (commentType == START_DOC_COMMENT) { return PsiTreeUtil.skipSiblingsForward(elt, PsiComment.class); } } return elt; }
Example 8
Source File: PsiLetImpl.java From reasonml-idea-plugin with MIT License | 5 votes |
private boolean isRecursive() { // Find first element after the LET PsiElement firstChild = getFirstChild(); PsiElement sibling = firstChild.getNextSibling(); if (sibling instanceof PsiWhiteSpace) { sibling = sibling.getNextSibling(); } return sibling != null && "rec".equals(sibling.getText()); }
Example 9
Source File: AMDPsiUtil.java From needsmoredojo with Apache License 2.0 | 5 votes |
public static PsiElement getNextElementOfType(PsiElement start, Class type, Set<String> terminators, Set<String> exclusions) { PsiElement sibling = start.getNextSibling(); while(sibling != null && !(sibling instanceof JSLiteralExpression) && !(sibling instanceof JSParameter) && !(sibling.getText().equals("]")) && !terminators.contains(sibling.getText())) { if(type.isInstance(sibling) && !exclusions.contains(sibling.getText())) { return sibling; } sibling = sibling.getNextSibling(); } return null; }
Example 10
Source File: TemplateLineMarker.java From idea-php-laravel-plugin with MIT License | 5 votes |
/** * Like this @section('sidebar') */ @NotNull private Collection<LineMarkerInfo> collectOverwrittenSection(@NotNull LeafPsiElement psiElement, @NotNull String sectionName, @NotNull LazyVirtualFileTemplateResolver resolver) { List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>(); for(PsiElement psiElement1 : psiElement.getContainingFile().getChildren()) { PsiElement extendDirective = psiElement1.getFirstChild(); if(extendDirective != null && extendDirective.getNode().getElementType() == BladeTokenTypes.EXTENDS_DIRECTIVE) { PsiElement bladeParameter = extendDirective.getNextSibling(); if(bladeParameter instanceof BladePsiDirectiveParameter) { String extendTemplate = BladePsiUtil.getSection(bladeParameter); if(extendTemplate != null) { for(VirtualFile virtualFile: resolver.resolveTemplateName(psiElement.getProject(), extendTemplate)) { PsiFile psiFile = PsiManager.getInstance(psiElement.getProject()).findFile(virtualFile); if(psiFile != null) { visitOverwrittenTemplateFile(psiFile, gotoRelatedItems, sectionName, resolver); } } } } } } if(gotoRelatedItems.size() == 0) { return Collections.emptyList(); } return Collections.singletonList( getRelatedPopover("Parent Section", "Blade Section", psiElement, gotoRelatedItems, PhpIcons.OVERRIDES) ); }
Example 11
Source File: GLSLConditionalExpression.java From glsl4idea with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable public GLSLExpression getFalseBranch() { PsiElement condition = findChildByType(COLON); while (condition != null && !(condition instanceof GLSLExpression)) { condition = condition.getNextSibling(); } return (GLSLExpression) condition; }
Example 12
Source File: GLSLDefineDirective.java From glsl4idea with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public PsiElement getNameIdentifier() { PsiElement child = getFirstChild(); while (child != null) { // we can't iterate over getChildren(), as that ignores leaf elements if (child.getNode().getElementType() == GLSLTokenTypes.IDENTIFIER) return child; child = child.getNextSibling(); } return null; }
Example 13
Source File: CsvHelper.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public static PsiElement getNextCRLF(final PsiElement element) { PsiElement currentElement = element; while (currentElement != null) { if (CsvHelper.getElementType(currentElement) == CsvTypes.CRLF) { break; } currentElement = currentElement.getNextSibling(); } return currentElement; }
Example 14
Source File: DustTypedHandler.java From Intellij-Dust with MIT License | 5 votes |
/** * When appropriate, auto-inserts closing tags. i.e. When "{#tagName}" or "{^tagName} is typed, * {/tagName} is automatically inserted */ private void autoInsertCloseTag(Project project, int offset, Editor editor, FileViewProvider provider) { PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiElement elementAtCaret = provider.findElementAt(offset - 1, DustLanguage.class); PsiElement openTag = DustPsiUtil.findParentOpenTagElement(elementAtCaret); String tagName = getTagName(openTag); if (!tagName.trim().equals("")) { boolean addCloseTag = true; PsiElement sibling = openTag.getNextSibling(); DustCloseTag closeTag; while (sibling != null && addCloseTag) { if (sibling instanceof DustCloseTag) { closeTag = (DustCloseTag) sibling; if (getTagName(closeTag).equals(tagName)) { addCloseTag = false; } } sibling = sibling.getNextSibling(); } if (addCloseTag) { // insert the corresponding close tag editor.getDocument().insertString(offset, "{/" + tagName + "}"); } } }
Example 15
Source File: PsiElementUtils.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getNextSiblingOfType(@Nullable PsiElement sibling, ElementPattern<PsiElement> pattern) { if (sibling == null) return null; for (PsiElement child = sibling.getNextSibling(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T)child; } } return null; }
Example 16
Source File: TemplateLineMarker.java From idea-php-laravel-plugin with MIT License | 5 votes |
/** * Extract parameter: @foobar('my_value') */ @Nullable private Pair<BladePsiDirectiveParameter, String> extractSectionParameter(@NotNull PsiElement psiElement) { PsiElement nextSibling = psiElement.getNextSibling(); if(nextSibling instanceof BladePsiDirectiveParameter) { String sectionName = BladePsiUtil.getSection(nextSibling); if (sectionName != null && StringUtils.isNotBlank(sectionName)) { return Pair.create((BladePsiDirectiveParameter) nextSibling, sectionName); } } return null; }
Example 17
Source File: ORUtil.java From reasonml-idea-plugin with MIT License | 5 votes |
@Nullable public static <T> T nextSiblingOfClass(@Nullable PsiElement element, @NotNull Class<T> clazz) { if (element == null) { return null; } PsiElement nextSibling = element.getNextSibling(); while (nextSibling != null && !(nextSibling.getClass().isAssignableFrom(clazz))) { nextSibling = nextSibling.getNextSibling(); } return nextSibling != null && nextSibling.getClass().isAssignableFrom(clazz) ? (T) nextSibling : null; }
Example 18
Source File: CsvHelper.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public static PsiElement getParentFieldElement(final PsiElement element) { PsiElement currentElement = element; IElementType elementType = CsvHelper.getElementType(currentElement); if (elementType == CsvTypes.COMMA || elementType == CsvTypes.CRLF) { currentElement = currentElement.getPrevSibling(); elementType = CsvHelper.getElementType(currentElement); } if (elementType == CsvTypes.RECORD) { currentElement = currentElement.getLastChild(); elementType = CsvHelper.getElementType(currentElement); } if (elementType == TokenType.WHITE_SPACE) { if (CsvHelper.getElementType(currentElement.getParent()) == CsvTypes.FIELD) { currentElement = currentElement.getParent(); } else if (CsvHelper.getElementType(currentElement.getPrevSibling()) == CsvTypes.FIELD) { currentElement = currentElement.getPrevSibling(); } else if (CsvHelper.getElementType(currentElement.getNextSibling()) == CsvTypes.FIELD) { currentElement = currentElement.getNextSibling(); } else { currentElement = null; } } else { while (currentElement != null && elementType != CsvTypes.FIELD) { currentElement = currentElement.getParent(); elementType = CsvHelper.getElementType(currentElement); } } return currentElement; }
Example 19
Source File: PsiPhpHelper.java From yiistorm with MIT License | 5 votes |
public static PsiElement findNextSiblingOfType(PsiElement psiElement, String[] types) { PsiElement siblingElement = psiElement.getNextSibling(); while (siblingElement != null && isNotElementType(siblingElement, types)) { siblingElement = siblingElement.getNextSibling(); } return siblingElement; }
Example 20
Source File: TemplateBuilderImpl.java From consulo with Apache License 2.0 | 4 votes |
/** * Adds end variable after the specified element */ public void setEndVariableAfter(PsiElement element) { element = element.getNextSibling(); setEndVariableBefore(element); }