Refatoring: rewrite in PsiTreeUtil style

This commit is contained in:
Nikolay Krasko
2014-05-21 18:35:27 +04:00
parent 84fb54fcdb
commit a8642c8636
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2013 JetBrains s.r.o. * Copyright 2010-2014 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.codeInsight.CommentUtilCore; import com.intellij.util.codeInsight.CommentUtilCore;
import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.JetNodeTypes;
@@ -387,22 +388,18 @@ public class JetPsiUtil {
} }
@Nullable @Nullable
@Contract("null, _ -> null")
public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) { public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) {
if (element == null) { PsiElement answer = PsiTreeUtil.getParentOfType(element, parentTypes);
return null;
do {
PsiElement next = PsiTreeUtil.getParentOfType(answer, parentTypes);
if (next == null) break;
answer = next;
} }
while (true);
PsiElement result = null; return answer;
PsiElement parent = element.getParent();
while (parent != null) {
if (PsiTreeUtil.instanceOf(parent, parentTypes)) {
result = parent;
}
parent = parent.getParent();
}
return result;
} }
public static boolean isNullConstant(@NotNull JetExpression expression) { public static boolean isNullConstant(@NotNull JetExpression expression) {