com.intellij.psi.PsiElement#getNextSibling ( )源码实例Demo

下面列出了com.intellij.psi.PsiElement#getNextSibling ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
源代码2 项目: BashSupport   文件: BashAnnotator.java
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();
    }
}
 
源代码3 项目: consulo-csharp   文件: CSharpLocalVariableImpl.java
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);
	}
}
 
源代码4 项目: glsl4idea   文件: GLSLForStatement.java
/**
 * 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;
}
 
源代码5 项目: arma-intellij-plugin   文件: PsiUtil.java
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();
	}
}
 
源代码6 项目: glsl4idea   文件: GLSLConditionalExpression.java
@Nullable
public GLSLExpression getFalseBranch() {
    PsiElement condition = findChildByType(COLON);
    while (condition != null && !(condition instanceof GLSLExpression)) {
        condition = condition.getNextSibling();
    }
    return (GLSLExpression) condition;
}
 
源代码7 项目: yiistorm   文件: PsiPhpHelper.java
public static PsiElement findNextSiblingOfType(PsiElement psiElement, String[] types) {
    PsiElement siblingElement = psiElement.getNextSibling();
    while (siblingElement != null && isNotElementType(siblingElement, types)) {
        siblingElement = siblingElement.getNextSibling();
    }
    return siblingElement;
}
 
源代码8 项目: intellij-csv-validator   文件: CsvHelper.java
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;
}
 
源代码9 项目: reasonml-idea-plugin   文件: ORUtil.java
@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;
}
 
/**
 * 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;
}
 
源代码11 项目: idea-php-symfony2-plugin   文件: PsiElementUtils.java
@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;
}
 
源代码12 项目: Intellij-Dust   文件: DustTypedHandler.java
/**
 * 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 + "}");
    }
  }
}
 
源代码13 项目: intellij-csv-validator   文件: CsvHelper.java
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;
}
 
源代码14 项目: glsl4idea   文件: GLSLDefineDirective.java
@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;
}
 
源代码15 项目: arma-intellij-plugin   文件: PsiUtil.java
@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;
}
 
/**
 * 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)
    );
}
 
源代码17 项目: needsmoredojo   文件: AMDPsiUtil.java
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;
}
 
源代码18 项目: reasonml-idea-plugin   文件: PsiLetImpl.java
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());
}
 
源代码19 项目: elm-plugin   文件: ElmAddImportHelper.java
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;
}
 
源代码20 项目: consulo   文件: TemplateBuilderImpl.java
/**
 * Adds end variable after the specified element
 */
public void setEndVariableAfter(PsiElement element) {
  element = element.getNextSibling();
  setEndVariableBefore(element);
}