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

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#skipSiblingsForward() . 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: SimpleDuplicatesFinder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SimpleDuplicatesFinder(@Nonnull final PsiElement statement1,
                              @Nonnull final PsiElement statement2,
                              Collection<String> variables,
                              AbstractVariableData[] variableData) {
  myOutputVariables = variables;
  myParameters = new HashSet<>();
  for (AbstractVariableData data : variableData) {
    myParameters.add(data.getOriginalName());
  }
  myPattern = new ArrayList<>();
  PsiElement sibling = statement1;

  do {
    myPattern.add(sibling);
    if (sibling == statement2) break;
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  } while (sibling != null);
}
 
Example 2
Source File: SimpleDuplicatesFinder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected SimpleMatch isDuplicateFragment(@Nonnull final PsiElement candidate) {
  if (!canReplace(myReplacement, candidate)) return null;
  for (PsiElement pattern : myPattern) {
    if (PsiTreeUtil.isAncestor(pattern, candidate, false)) return null;
  }
  PsiElement sibling = candidate;
  final ArrayList<PsiElement> candidates = new ArrayList<>();
  for (int i = 0; i != myPattern.size(); ++i) {
    if (sibling == null) return null;

    candidates.add(sibling);
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  }
  if (myPattern.size() != candidates.size()) return null;
  if (candidates.size() <= 0) return null;
  final SimpleMatch match = new SimpleMatch(candidates.get(0), candidates.get(candidates.size() - 1));
  for (int i = 0; i < myPattern.size(); i++) {
    if (!matchPattern(myPattern.get(i), candidates.get(i), match)) return null;
  }
  return match;
}
 
Example 3
Source File: RemoveUnusedAtFixBase.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
static void deleteElement(PsiElement element, Document document) {
  ASTNode atParamNode = element.getNode();
  PsiElement nextMeaningfulNode = PsiTreeUtil
      .skipSiblingsForward(element, PsiWhiteSpace.class);
  nextMeaningfulNode = nextMeaningfulNode == null ? null
      : WhitespaceUtils.getFirstNonWhitespaceChild(nextMeaningfulNode);
  TextRange rangeToDelete = computeRangeToDelete(element, atParamNode, nextMeaningfulNode);
  document.deleteString(rangeToDelete.getStartOffset(), rangeToDelete.getEndOffset());
}
 
Example 4
Source File: ElmAddImportHelper.java    From elm-plugin with MIT License 5 votes vote down vote up
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 5
Source File: PsiEquivalenceUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addRangeDuplicates(final PsiElement scope,
                                       final PsiElement first,
                                       final PsiElement last,
                                       final PairConsumer<PsiElement, PsiElement> result) {
  final PsiElement[] children = getFilteredChildren(scope, null, true);
  NextChild:
  for (int i = 0; i < children.length;) {
    PsiElement child = children[i];
    if (child != first) {
      int j = i;
      PsiElement next = first;
      do {
        if (!areElementsEquivalent(children[j], next)) break;
        j++;
        if (next == last) {
          result.consume(child, children[j - 1]);
          i = j + 1;
          continue NextChild;
        }
        next = PsiTreeUtil.skipSiblingsForward(next, PsiWhiteSpace.class);
      }
      while (true);

      if (i == j) {
        addRangeDuplicates(child, first, last, result);
      }
    }

    i++;
  }
}
 
Example 6
Source File: WhitespaceUtils.java    From bamboo-soy with Apache License 2.0 4 votes vote down vote up
@Nullable
public static PsiElement getNextNonWhitespaceSibling(PsiElement element) {
  return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class);
}
 
Example 7
Source File: WhitespaceUtils.java    From bamboo-soy with Apache License 2.0 4 votes vote down vote up
@Nullable
public static PsiElement getNextMeaningSibling(PsiElement element) {
  return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class, PsiComment.class);
}