本文整理汇总了Java中com.intellij.psi.impl.source.tree.TreeUtil.findFirstLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java TreeUtil.findFirstLeaf方法的具体用法?Java TreeUtil.findFirstLeaf怎么用?Java TreeUtil.findFirstLeaf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.TreeUtil
的用法示例。
在下文中一共展示了TreeUtil.findFirstLeaf方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _testPerformance1
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public void _testPerformance1() throws Exception {
final String text = loadFile("pallada.xml");
long time = System.currentTimeMillis();
final PsiFile file = createFile("test.xml", text);
transformAllChildren(file.getNode());
System.out.println("Old parsing took " + (System.currentTimeMillis() - time) + "ms");
int index = 0;
while (index++ < 10) {
newParsing(text);
}
LeafElement firstLeaf = TreeUtil.findFirstLeaf(file.getNode());
index = 0;
do {
index++;
}
while ((firstLeaf = TreeUtil.nextLeaf(firstLeaf, null)) != null);
System.out.println("For " + index + " lexems");
}
示例3: _testPerformance2
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public void _testPerformance2() throws Exception {
final String text = loadFile("performance2.xml");
long time = System.currentTimeMillis();
final PsiFile file = createFile("test.xml", text);
transformAllChildren(file.getNode());
System.out.println("Old parsing took " + (System.currentTimeMillis() - time) + "ms");
int index = 0;
while (index++ < 10) {
newParsing(text);
}
LeafElement firstLeaf = TreeUtil.findFirstLeaf(file.getNode());
index = 0;
do {
index++;
}
while ((firstLeaf = TreeUtil.nextLeaf(firstLeaf, null)) != null);
System.out.println("For " + index + " lexems");
}
示例4: 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;
}
示例5: canStickChildrenTogether
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static boolean canStickChildrenTogether(final ASTNode child1, final ASTNode child2)
{
if(child1 == null || child2 == null)
{
return true;
}
if(isWS(child1) || isWS(child2))
{
return true;
}
ASTNode token1 = TreeUtil.findLastLeaf(child1);
ASTNode token2 = TreeUtil.findFirstLeaf(child2);
LOG.assertTrue(token1 != null);
LOG.assertTrue(token2 != null);
return !(token1.getElementType() instanceof IJavaElementType) || !(token2.getElementType() instanceof IJavaElementType) || canStickJavaTokens(token1, token2);
}
示例6: 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);
}
}
示例7: findFirstLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
private static ASTNode findFirstLeaf(ASTNode first, ASTNode last) {
do {
final LeafElement leaf = TreeUtil.findFirstLeaf(first);
if (leaf != null) return leaf;
first = first.getTreeNext();
if (first == null) return null;
}
while (first != last);
return null;
}
示例8: 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);
}
}
示例9: firstLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ASTNode firstLeaf(@NotNull ASTNode startNode) {
return TreeUtil.findFirstLeaf(startNode);
}
示例10: checkFile
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
final ProblemReporter reporter = new ProblemReporter() {
@Override
public void reportProblem(ASTNode node, String message) {
result.add( manager.createProblemDescriptor( node.getPsi(),
message,
(LocalQuickFix)null,
ProblemHighlightType.ERROR,
isOnTheFly));
}
};
FileASTNode node1 = file.getNode();
LeafElement firstLeaf = TreeUtil.findFirstLeaf(node1);
Stack<List<ASTNode>> levels = new Stack<List<ASTNode>>();
List<ASTNode> nodes = new ArrayList<ASTNode>();
// Push the root node, just in case there is no #if to start it off.
levels.push(nodes);
ASTNode leaf = firstLeaf;
while (leaf != null) {
IElementType leafElementType = leaf.getElementType();
if (leafElementType.equals(HaxeTokenTypes.PPIF)) {
nodes = new ArrayList<ASTNode>();
levels.push(nodes);
nodes.add(leaf);
}
else if (leafElementType.equals(HaxeTokenTypes.PPEND)) {
nodes.add(leaf);
// Leave the base level in place, even if there are extra ends.
if (levels.size() > 1) {
validateLevel(nodes, reporter);
levels.pop();
nodes = levels.peek();
}
}
else if (leafElementType.equals(HaxeTokenTypes.PPELSEIF)) {
nodes.add(leaf);
}
else if (leafElementType.equals(HaxeTokenTypes.PPELSE)) {
nodes.add(leaf);
}
leaf = TreeUtil.nextLeaf(leaf);
}
// Any levels that are still left need to be validated.
for (List<ASTNode> level : levels) {
validateLevel(level, reporter);
}
return ArrayUtil.toObjectArray(result, ProblemDescriptor.class);
}