diff --git a/platform/lang-api/src/com/intellij/patterns/PsiElementPattern.java b/platform/lang-api/src/com/intellij/patterns/PsiElementPattern.java index c0339cb46e4c..782b91dd9a84 100644 --- a/platform/lang-api/src/com/intellij/patterns/PsiElementPattern.java +++ b/platform/lang-api/src/com/intellij/patterns/PsiElementPattern.java @@ -23,6 +23,7 @@ import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.meta.PsiMetaOwner; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.PairProcessor; import com.intellij.util.ProcessingContext; import com.intellij.util.ReflectionCache; @@ -159,18 +160,10 @@ public abstract class PsiElementPattern=0 || whitespaceText.indexOf((int) '\r') >= 0; } -} \ No newline at end of file +} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/CommentOnLineWithSourcePredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/CommentOnLineWithSourcePredicate.java index 22124a59d6b8..0fad7df789ca 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/CommentOnLineWithSourcePredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/CommentOnLineWithSourcePredicate.java @@ -19,8 +19,8 @@ import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.TreeUtil; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -48,7 +48,7 @@ class CommentOnLineWithSourcePredicate implements PsiElementPredicate{ !JavaTokenType.END_OF_LINE_COMMENT.equals(type)){ return false; // can't move JSP comments } - final PsiElement prevSibling = TreeUtil.getPrevLeaf(element); + final PsiElement prevSibling = PsiTreeUtil.prevLeaf(element); if(!(prevSibling instanceof PsiWhiteSpace)){ return true; } @@ -57,7 +57,7 @@ class CommentOnLineWithSourcePredicate implements PsiElementPredicate{ prevSiblingText.indexOf((int) '\r') < 0){ return true; } - final PsiElement nextSibling = TreeUtil.getNextLeaf(element); + final PsiElement nextSibling = PsiTreeUtil.nextLeaf(element); if(!(nextSibling instanceof PsiWhiteSpace)){ return true; } @@ -75,4 +75,4 @@ class CommentOnLineWithSourcePredicate implements PsiElementPredicate{ }); return containsInjected.get(); } -} \ No newline at end of file +} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java index b0e846377ace..cf042e877f4c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java @@ -17,10 +17,10 @@ package com.siyeh.ipp.comment; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.TreeUtil; import org.jetbrains.annotations.NotNull; public class MoveCommentToSeparateLineIntention extends Intention { @@ -36,7 +36,7 @@ public class MoveCommentToSeparateLineIntention extends Intention { PsiElement elementToCheck = selectedComment; final PsiWhiteSpace whiteSpace; while (true) { - elementToCheck = TreeUtil.getPrevLeaf(elementToCheck); + elementToCheck = PsiTreeUtil.prevLeaf(elementToCheck); if (elementToCheck == null) { return; } @@ -73,4 +73,4 @@ public class MoveCommentToSeparateLineIntention extends Intention { private static boolean containsLineBreak(String text) { return text.indexOf((int)'\n') >= 0 || text.indexOf((int)'\r') >= 0; } -} \ No newline at end of file +} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/TreeUtil.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/TreeUtil.java deleted file mode 100644 index b61e58e98189..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/TreeUtil.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2003-2005 Dave Griffith - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ipp.psiutils; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.Nullable; - -public class TreeUtil{ - - private TreeUtil(){ - super(); - } - - @Nullable - public static PsiElement getNextLeaf(PsiElement element){ - if(element == null){ - return null; - } - final PsiElement sibling = element.getNextSibling(); - if(sibling == null){ - final PsiElement parent = element.getParent(); - return getNextLeaf(parent); - } - return getFirstLeaf(sibling); - } - - private static PsiElement getFirstLeaf(PsiElement element){ - final PsiElement[] children = element.getChildren(); - if(children.length == 0){ - return element; - } - return getFirstLeaf(children[0]); - } - - @Nullable - public static PsiElement getPrevLeaf(PsiElement element){ - if(element == null || element instanceof PsiFile){ - return null; - } - final PsiElement sibling = element.getPrevSibling(); - if(sibling == null){ - final PsiElement parent = element.getParent(); - return getPrevLeaf(parent); - } - return getLastLeaf(sibling); - } - - private static PsiElement getLastLeaf(PsiElement element){ - final PsiElement[] children = element.getChildren(); - if(children.length == 0){ - return element; - } - return getLastLeaf(children[children.length-1]); - } -} \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java index cb5ab4ef3609..a091a6166d25 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java @@ -17,11 +17,10 @@ package org.jetbrains.plugins.groovy.intentions.comments; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; -import org.jetbrains.plugins.groovy.intentions.utils.TreeUtil; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; class CStyleCommentPredicate implements PsiElementPredicate { @@ -38,7 +37,7 @@ class CStyleCommentPredicate implements PsiElementPredicate { if (!GroovyTokenTypes.mML_COMMENT.equals(type)) { return false; } - final PsiElement sibling = TreeUtil.getNextLeaf(comment); + final PsiElement sibling = PsiTreeUtil.nextLeaf(comment); if(sibling == null) { return true; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/utils/TreeUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/utils/TreeUtil.java deleted file mode 100644 index 27a412c88f5b..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/utils/TreeUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.plugins.groovy.intentions.utils; - -import org.jetbrains.annotations.Nullable; -import com.intellij.psi.PsiElement; - -public class TreeUtil { - private TreeUtil() { - super(); - } - - @Nullable - public static PsiElement getNextLeaf(PsiElement element) { - if (element == null) { - return null; - } - final PsiElement sibling = element.getNextSibling(); - if (sibling == null) { - final PsiElement parent = element.getParent(); - return getNextLeaf(parent); - } - return getFirstLeaf(sibling); - } - - private static PsiElement getFirstLeaf(PsiElement element) { - final PsiElement[] children = element.getChildren(); - if (children.length == 0) { - return element; - } - return getFirstLeaf(children[0]); - } - - @Nullable - public static PsiElement getPrevLeaf(PsiElement element) { - if (element == null) { - return null; - } - final PsiElement sibling = element.getPrevSibling(); - if (sibling == null) { - final PsiElement parent = element.getParent(); - return getPrevLeaf(parent); - } - return getLastLeaf(sibling); - } - - private static PsiElement getLastLeaf(PsiElement element) { - final PsiElement[] children = element.getChildren(); - if (children.length == 0) { - return element; - } - return getLastLeaf(children[children.length - 1]); - } -}