Make non-strict behavior of getNextNonCommentSibling more clear by adding corresponding parameter

This commit is contained in:
Mikhail Golubev
2015-07-03 14:37:00 +03:00
parent c47233a435
commit 0b5dd584ea
6 changed files with 23 additions and 21 deletions
@@ -83,15 +83,15 @@ public class PyPsiUtils {
}
/**
* Find first sibling that is neither comment, nor whitespace before given element or this element itself.
* Find first sibling that is neither comment, nor whitespace before given element.
* @param strict prohibit returning element itself
*/
@Nullable
public static PsiElement getFirstNonCommentBefore(@Nullable PsiElement start) {
PsiElement seeker = start;
while (seeker instanceof PsiWhiteSpace || seeker instanceof PsiComment) {
seeker = seeker.getPrevSibling();
public static PsiElement getPrevNonCommentSibling(@Nullable PsiElement start, boolean strict) {
if (!strict && !(start instanceof PsiWhiteSpace || start instanceof PsiComment)) {
return start;
}
return seeker;
return PsiTreeUtil.skipSiblingsBackward(start, PsiWhiteSpace.class, PsiComment.class);
}
/**
@@ -120,13 +120,15 @@ public class PyPsiUtils {
}
/**
* Find first sibling that is neither comment, nor whitespace after given element or this element itself.
* Find first sibling that is neither comment, nor whitespace after given element.
* @param strict prohibit returning element itself
*/
@Nullable
public static PsiElement getFirstNonCommentAfter(@Nullable PsiElement start) {
PsiElement seeker = start;
while (seeker instanceof PsiWhiteSpace || seeker instanceof PsiComment) seeker = seeker.getNextSibling();
return seeker;
public static PsiElement getNextNonCommentSibling(@Nullable PsiElement start, boolean strict) {
if (!strict && !(start instanceof PsiWhiteSpace || start instanceof PsiComment)) {
return start;
}
return PsiTreeUtil.skipSiblingsForward(start, PsiWhiteSpace.class, PsiComment.class);
}
/**