本文整理汇总了Java中com.intellij.psi.impl.source.tree.TreeUtil.prevLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java TreeUtil.prevLeaf方法的具体用法?Java TreeUtil.prevLeaf怎么用?Java TreeUtil.prevLeaf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.TreeUtil
的用法示例。
在下文中一共展示了TreeUtil.prevLeaf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMatchingLength
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static int getMatchingLength(@NotNull FileElement treeElement, @NotNull CharSequence text, boolean fromStart) {
int patternIndex = fromStart ? 0 : text.length() - 1;
int finalPatternIndex = fromStart ? text.length() - 1 : 0;
int direction = fromStart ? 1 : -1;
ASTNode leaf = fromStart ? TreeUtil.findFirstLeaf(treeElement, false) : TreeUtil.findLastLeaf(treeElement, false);
int result = 0;
while (leaf != null && (fromStart ? patternIndex <= finalPatternIndex : patternIndex >= finalPatternIndex)) {
if (!(leaf instanceof ForeignLeafPsiElement)) {
CharSequence chars = leaf.getChars();
if (chars.length() > 0) {
int matchingLength = getLeafMatchingLength(chars, text, patternIndex, finalPatternIndex, direction);
result += matchingLength;
if (matchingLength != chars.length()) {
break;
}
patternIndex += (fromStart ? matchingLength : -matchingLength);
}
}
leaf = fromStart ? TreeUtil.nextLeaf(leaf, false) : TreeUtil.prevLeaf(leaf, false);
}
return result;
}
示例2: markToReformatBeforeOrInsertWhitespace
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static void markToReformatBeforeOrInsertWhitespace(final ASTNode left, @NotNull final ASTNode right) {
final Language leftLang = left != null ? PsiUtilCore.getNotAnyLanguage(left) : null;
final Language rightLang = PsiUtilCore.getNotAnyLanguage(right);
ASTNode generatedWhitespace = null;
if (leftLang != null && leftLang.isKindOf(rightLang)) {
generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(leftLang).generateWhitespaceBetweenTokens(left, right);
}
else if (rightLang.isKindOf(leftLang)) {
generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(rightLang).generateWhitespaceBetweenTokens(left, right);
}
if (generatedWhitespace != null) {
final TreeUtil.CommonParentState parentState = new TreeUtil.CommonParentState();
TreeUtil.prevLeaf((TreeElement)right, parentState);
parentState.nextLeafBranchStart.getTreeParent().addChild(generatedWhitespace, parentState.nextLeafBranchStart);
}
else {
markToReformatBefore(right, true);
}
}
示例3: calcBaseIndent
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static int calcBaseIndent(ASTNode chameleon) {
final ASTNode prevLeaf = TreeUtil.prevLeaf(chameleon, true);
if (prevLeaf == null) {
return 0;
}
final CharSequence text = prevLeaf.getChars();
int offset = text.length();
int answer = 0;
while (--offset > 0) {
final char c = text.charAt(offset);
if (c == '\n') {
break;
}
if (c != ' ' && c != '\t') {
answer = 0;
break;
}
answer++;
}
return answer;
}
示例4: markToReformatBeforeOrInsertWhitespace
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static void markToReformatBeforeOrInsertWhitespace(final ASTNode left, @Nonnull final ASTNode right) {
final Language leftLang = left != null ? PsiUtilCore.getNotAnyLanguage(left) : null;
final Language rightLang = PsiUtilCore.getNotAnyLanguage(right);
ASTNode generatedWhitespace = null;
if (leftLang != null && leftLang.isKindOf(rightLang)) {
generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(leftLang).generateWhitespaceBetweenTokens(left, right);
}
else if (rightLang.isKindOf(leftLang)) {
generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(rightLang).generateWhitespaceBetweenTokens(left, right);
}
if (generatedWhitespace != null) {
final TreeUtil.CommonParentState parentState = new TreeUtil.CommonParentState();
TreeUtil.prevLeaf((TreeElement)right, parentState);
parentState.nextLeafBranchStart.getTreeParent().addChild(generatedWhitespace, parentState.nextLeafBranchStart);
}
else {
markToReformatBefore(right, true);
}
}
示例5: getMatchingLength
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static int getMatchingLength(@Nonnull FileElement treeElement, @Nonnull CharSequence text, boolean fromStart) {
int patternIndex = fromStart ? 0 : text.length() - 1;
int finalPatternIndex = fromStart ? text.length() - 1 : 0;
int direction = fromStart ? 1 : -1;
ASTNode leaf = fromStart ? TreeUtil.findFirstLeaf(treeElement, false) : TreeUtil.findLastLeaf(treeElement, false);
int result = 0;
while (leaf != null && (fromStart ? patternIndex <= finalPatternIndex : patternIndex >= finalPatternIndex)) {
if (!(leaf instanceof ForeignLeafPsiElement)) {
CharSequence chars = leaf.getChars();
if (chars.length() > 0) {
int matchingLength = getLeafMatchingLength(chars, text, patternIndex, finalPatternIndex, direction);
result += matchingLength;
if (matchingLength != chars.length()) {
break;
}
patternIndex += fromStart ? matchingLength : -matchingLength;
}
}
leaf = fromStart ? TreeUtil.nextLeaf(leaf, false) : TreeUtil.prevLeaf(leaf, false);
}
return result;
}
示例6: replaceWithPsiInLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(TextRange textRange, String whiteSpace, ASTNode leafElement) {
if (!myCanModifyAllWhiteSpaces) {
if (AppleScriptPsiImplUtil.isWhiteSpaceOrNls(leafElement)) return null;
}
IElementType elementTypeToUse = TokenType.WHITE_SPACE;
ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
if (prevNode != null && AppleScriptPsiImplUtil.isWhiteSpaceOrNls(prevNode)) {
elementTypeToUse = prevNode.getElementType();
}
FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, elementTypeToUse, textRange);
return whiteSpace;
}
示例7: addChildren
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static ASTNode addChildren(ASTNode parent, @NotNull ASTNode first, @NotNull ASTNode last, ASTNode anchorBefore) {
ASTNode lastChild = last.getTreeNext();
ASTNode current = first;
while (current != lastChild) {
saveWhitespacesInfo(current);
checkForOuters(current);
current = current.getTreeNext();
}
if (anchorBefore != null && isComment(anchorBefore.getElementType())) {
final ASTNode anchorPrev = anchorBefore.getTreePrev();
if (anchorPrev != null && anchorPrev.getElementType() == TokenType.WHITE_SPACE) {
anchorBefore = anchorPrev;
}
}
parent.addChildren(first, lastChild, anchorBefore);
ASTNode firstAddedLeaf = findFirstLeaf(first, last);
ASTNode prevLeaf = TreeUtil.prevLeaf(first);
ASTNode result = first;
if (firstAddedLeaf != null) {
ASTNode placeHolderEnd = makePlaceHolderBetweenTokens(prevLeaf, firstAddedLeaf, isFormattingRequired(prevLeaf, first), false);
if (placeHolderEnd != prevLeaf && first == firstAddedLeaf) {
result = placeHolderEnd;
}
ASTNode lastAddedLeaf = findLastLeaf(first, last);
placeHolderEnd = makePlaceHolderBetweenTokens(lastAddedLeaf, TreeUtil.nextLeaf(last), true, false);
if (placeHolderEnd != lastAddedLeaf && lastAddedLeaf == first) {
result = placeHolderEnd;
}
}
else {
makePlaceHolderBetweenTokens(prevLeaf, TreeUtil.nextLeaf(last), isFormattingRequired(prevLeaf, first), false);
}
return result;
}
示例8: replaceChild
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static void replaceChild(ASTNode parent, @NotNull ASTNode oldChild, @NotNull ASTNode newChild) {
saveWhitespacesInfo(oldChild);
saveWhitespacesInfo(newChild);
checkForOuters(oldChild);
checkForOuters(newChild);
LeafElement oldFirst = TreeUtil.findFirstLeaf(oldChild);
parent.replaceChild(oldChild, newChild);
final LeafElement firstLeaf = TreeUtil.findFirstLeaf(newChild);
final ASTNode prevToken = TreeUtil.prevLeaf(newChild);
if (firstLeaf != null) {
final ASTNode nextLeaf = TreeUtil.nextLeaf(newChild);
makePlaceHolderBetweenTokens(prevToken, firstLeaf, isFormattingRequired(prevToken, newChild), false);
if (nextLeaf != null && !CharArrayUtil.containLineBreaks(nextLeaf.getText())) {
makePlaceHolderBetweenTokens(TreeUtil.prevLeaf(nextLeaf), nextLeaf, false, false);
}
}
else {
if (oldFirst != null && prevToken == null) {
ASTNode whitespaceNode = newChild.getTreeNext();
if (whitespaceNode != null && whitespaceNode.getElementType() == TokenType.WHITE_SPACE) {
// Replacing non-empty prefix to empty shall remove whitespace
parent.removeChild(whitespaceNode);
}
}
makePlaceHolderBetweenTokens(prevToken, TreeUtil.nextLeaf(newChild), isFormattingRequired(prevToken, newChild), false);
}
}
示例9: searchNonSpaceNonCommentBack
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
public static PsiElement searchNonSpaceNonCommentBack(PsiElement element, final boolean strict) {
if(element == null || element.getNode() == null) return null;
ASTNode leftNeibour = TreeUtil.prevLeaf(element.getNode());
if (!strict) {
while (leftNeibour != null && (leftNeibour.getElementType() == TokenType.WHITE_SPACE || leftNeibour.getPsi() instanceof PsiComment)){
leftNeibour = TreeUtil.prevLeaf(leftNeibour);
}
}
return leftNeibour != null ? leftNeibour.getPsi() : null;
}
示例10: findBeforeCaret
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static PsiElement findBeforeCaret(ASTNode atCaret, Class<? extends PsiElement>... classes) {
while (atCaret != null) {
atCaret = TreeUtil.prevLeaf(atCaret);
if (atCaret != null && atCaret.getElementType() != TokenType.WHITE_SPACE) {
return getNonStrictParentOfType(atCaret.getPsi(), classes);
}
}
return null;
}
示例11: replaceWithPsiInLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(TextRange textRange, String whiteSpace, ASTNode leafElement) {
if (!myCanModifyAllWhiteSpaces) {
if (PsiImplUtil.isWhiteSpaceOrNls(leafElement)) return null;
}
IElementType elementTypeToUse = TokenType.WHITE_SPACE;
ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
if (prevNode != null && PsiImplUtil.isWhiteSpaceOrNls(prevNode)) {
elementTypeToUse = prevNode.getElementType();
}
FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, elementTypeToUse, textRange);
return whiteSpace;
}
示例12: replaceWithPsiInLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(TextRange textRange, String whiteSpace, ASTNode leafElement) {
if (!myCanModifyAllWhiteSpaces) {
if (TokenSets.WHITE_SPACES_SET.contains(leafElement.getElementType())) return null;
}
IElementType elementTypeToUse = TokenType.WHITE_SPACE;
ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
if (prevNode != null && TokenSets.WHITE_SPACES_SET.contains(prevNode.getElementType())) {
elementTypeToUse = prevNode.getElementType();
}
FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, elementTypeToUse, textRange);
return whiteSpace;
}
示例13: addChildren
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static ASTNode addChildren(ASTNode parent, @Nonnull ASTNode first, @Nonnull ASTNode last, ASTNode anchorBefore) {
ASTNode lastChild = last.getTreeNext();
ASTNode current = first;
while (current != lastChild) {
saveWhitespacesInfo(current);
checkForOuters(current);
current = current.getTreeNext();
}
if (anchorBefore != null && CommentUtilCore.isComment(anchorBefore)) {
final ASTNode anchorPrev = anchorBefore.getTreePrev();
if (anchorPrev != null && anchorPrev.getElementType() == TokenType.WHITE_SPACE) {
anchorBefore = anchorPrev;
}
}
parent.addChildren(first, lastChild, anchorBefore);
ASTNode firstAddedLeaf = findFirstLeaf(first, last);
ASTNode prevLeaf = TreeUtil.prevLeaf(first);
ASTNode result = first;
if (firstAddedLeaf != null) {
ASTNode placeHolderEnd = makePlaceHolderBetweenTokens(prevLeaf, firstAddedLeaf, isFormattingRequired(prevLeaf, first), false);
if (placeHolderEnd != prevLeaf && first == firstAddedLeaf) {
result = placeHolderEnd;
}
ASTNode lastAddedLeaf = findLastLeaf(first, last);
placeHolderEnd = makePlaceHolderBetweenTokens(lastAddedLeaf, TreeUtil.nextLeaf(last), true, false);
if (placeHolderEnd != lastAddedLeaf && lastAddedLeaf == first) {
result = placeHolderEnd;
}
}
else {
makePlaceHolderBetweenTokens(prevLeaf, TreeUtil.nextLeaf(last), isFormattingRequired(prevLeaf, first), false);
}
return result;
}
示例14: replaceChild
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static void replaceChild(ASTNode parent, @Nonnull ASTNode oldChild, @Nonnull ASTNode newChild) {
saveWhitespacesInfo(oldChild);
saveWhitespacesInfo(newChild);
checkForOuters(oldChild);
checkForOuters(newChild);
LeafElement oldFirst = TreeUtil.findFirstLeaf(oldChild);
parent.replaceChild(oldChild, newChild);
final LeafElement firstLeaf = TreeUtil.findFirstLeaf(newChild);
final ASTNode prevToken = TreeUtil.prevLeaf(newChild);
if (firstLeaf != null) {
final ASTNode nextLeaf = TreeUtil.nextLeaf(newChild);
makePlaceHolderBetweenTokens(prevToken, firstLeaf, isFormattingRequired(prevToken, newChild), false);
if (nextLeaf != null && !CharArrayUtil.containLineBreaks(nextLeaf.getText())) {
makePlaceHolderBetweenTokens(TreeUtil.prevLeaf(nextLeaf), nextLeaf, false, false);
}
}
else {
if (oldFirst != null && prevToken == null) {
ASTNode whitespaceNode = newChild.getTreeNext();
if (whitespaceNode != null && whitespaceNode.getElementType() == TokenType.WHITE_SPACE) {
// Replacing non-empty prefix to empty shall remove whitespace
parent.removeChild(whitespaceNode);
}
}
makePlaceHolderBetweenTokens(prevToken, TreeUtil.nextLeaf(newChild), isFormattingRequired(prevToken, newChild), false);
}
}
示例15: isFinalKeywordBefore
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static boolean isFinalKeywordBefore(ASTNode node)
{
ASTNode prevLeaf = TreeUtil.prevLeaf(node);
if(prevLeaf != null && prevLeaf.getElementType() == TokenType.WHITE_SPACE)
{
prevLeaf = TreeUtil.prevLeaf(prevLeaf);
}
return prevLeaf != null && prevLeaf.getElementType() == JavaTokenType.FINAL_KEYWORD;
}