Java Code Examples for com.intellij.psi.util.PsiTreeUtil#findSiblingBackward()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#findSiblingBackward() . These examples are extracted from open source projects. 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
private static ImmutableList<JSFile> jsFilesFromDtsSymbol(
    ExecutionRootPathResolver pathResolver,
    LocalFileSystem lfs,
    PsiManager psiManager,
    PsiElement dtsElement) {
  while (dtsElement != null && !(dtsElement instanceof PsiFile)) {
    PsiElement comment =
        PsiTreeUtil.findSiblingBackward(dtsElement, JSTokenTypes.END_OF_LINE_COMMENT, null);
    if (comment != null) {
      Matcher matcher = SYMBOL_GENERATED_FROM_JS_COMMENT.matcher(comment.getText());
      if (matcher.find()) {
        JSFile file = pathToJsFile(pathResolver, lfs, psiManager, matcher.group(1));
        return file != null ? ImmutableList.of(file) : ImmutableList.of();
      }
    }
    dtsElement = dtsElement.getParent();
  }
  return ImmutableList.of();
}
 
Example 2
Source Project: idea-php-symfony2-plugin   File: YamlHelper.java    License: MIT License 6 votes vote down vote up
/**
 * key: !my_tag <caret>
 */
public static boolean isElementAfterYamlTag(PsiElement psiElement) {
    if (!(psiElement instanceof LeafPsiElement)) {
        return false;
    }

    // key: !my_tag <caret>\n
    if (((LeafPsiElement) psiElement).getElementType() == YAMLTokenTypes.EOL) {
        PsiElement prevElement = PsiTreeUtil.getDeepestVisibleLast(psiElement);
        if (prevElement instanceof LeafPsiElement) {
            if (((LeafPsiElement) prevElement).getElementType() == YAMLTokenTypes.TAG) {
                return ((LeafPsiElement) prevElement).getText().startsWith("!");
            }
        }
    }

    return PsiTreeUtil.findSiblingBackward(psiElement, YAMLTokenTypes.TAG, null) != null;
}
 
Example 3
private boolean isInsideDefaultInitializer(PsiElement currentElement) {
  AtElementSingle parentAtElement =
      PsiTreeUtil.getParentOfType(currentElement, AtElementSingle.class);
  if (parentAtElement == null) {
    return false;
  }

  if (parentAtElement.getLastChild() != null
      && PsiTreeUtil.findSiblingBackward(
              parentAtElement.getLastChild(),
              currentElement.getNode().getElementType(),
              false,
              null)
          == currentElement) {
    // currentElement is an immediate child of a SoyAt[State|Param]Single that does not have
    // a valid default initializer Expr (due to malformed source code during typing).
    return true;
  }
  SoyExpr atDefaultInitializer = parentAtElement.getDefaultInitializerExpr();
  if (atDefaultInitializer == null) {
    // This is also the case for @inject.
    return false;
  }

  // currentElement is a child of a SoyAt[State|Param]Single's default initializer Expr.
  return PsiTreeUtil.findFirstParent(currentElement, element -> element == atDefaultInitializer)
      != null;
}