Java 类com.intellij.psi.SyntaxTraverser 实例源码

项目:intellij-ce-playground    文件:ParameterInfoUtils.java   
public static <V> int getCurrentParameterIndex(SyntaxTraverser<V> s, int offset, IElementType delimiterType) {
  V root = s.getRoot();
  int curOffset = s.api.rangeOf(root).getStartOffset();
  if (offset < curOffset) return -1;
  int index = 0;

  for (V child : s) {
    curOffset += s.api.rangeOf(child).getLength();
    if (offset < curOffset) break;

    IElementType type = s.api.typeOf(child);
    if (type == delimiterType) index++;
  }

  return index;
}
项目:consulo-java    文件:JavaCodeBlockModificationListener.java   
@Override
protected boolean isOutOfCodeBlock(@NotNull PsiElement element)
{
    for(PsiElement e : SyntaxTraverser.psiApi().parents(element))
    {
        if(e instanceof PsiModifiableCodeBlock)
        {
            // trigger OOCBM for final variables initialized in constructors & class initializers
            if(!((PsiModifiableCodeBlock) e).shouldChangeModificationCount(element))
            {
                return false;
            }
        }
        if(e instanceof PsiClass)
        {
            break;
        }
        if(e instanceof PsiClassOwner)
        {
            break;
        }
    }
    return true;
}
项目:consulo-csharp    文件:CSharpCompletionSorting.java   
@Nullable
@RequiredReadAction
private static LookupElementWeigher recursiveSorter(CompletionParameters completionParameters, CompletionResultSet result)
{
    PsiElement position = completionParameters.getPosition();


    Set<PsiElement> elements = new THashSet<>();

    PsiElement argumentListOwner = PsiTreeUtil.getContextOfType(position, CSharpCallArgumentListOwner.class, DotNetVariable.class);
    if(argumentListOwner instanceof CSharpMethodCallExpressionImpl)
    {
        ContainerUtil.addIfNotNull(elements, ((CSharpMethodCallExpressionImpl) argumentListOwner).resolveToCallable());
    }
    else if(argumentListOwner instanceof DotNetVariable)
    {
        elements.add(argumentListOwner);
    }

    List<CSharpForeachStatementImpl> foreachStatements = SyntaxTraverser.psiApi().parents(position).filter(CSharpForeachStatementImpl.class).addAllTo(new ArrayList<>());
    for(CSharpForeachStatementImpl foreachStatement : foreachStatements)
    {
        DotNetExpression iterableExpression = foreachStatement.getIterableExpression();
        if(iterableExpression instanceof CSharpReferenceExpression)
        {
            ContainerUtil.addIfNotNull(elements, ((CSharpReferenceExpression) iterableExpression).resolve());
        }
    }

    if(!elements.isEmpty())
    {
        return new CSharpRecursiveGuardWeigher(elements);
    }
    return null;
}
项目:intellij-ce-playground    文件:JavaTypeProvider.java   
@NotNull
@Override
public List<PsiExpression> getExpressionsAt(@NotNull PsiElement elementAt) {
  return SyntaxTraverser.psiApi().parents(elementAt).filter(PsiExpression.class).toList();
}
项目:intellij-ce-playground    文件:ParameterInfoUtils.java   
public static int getCurrentParameterIndex(ASTNode argList, int offset, IElementType delimiterType) {
  SyntaxTraverser<ASTNode> s = SyntaxTraverser.astTraverser(argList).expandAndSkip(Conditions.is(argList));
  return getCurrentParameterIndex(s, offset, delimiterType);
}
项目:consulo-java    文件:JavaTypeProvider.java   
@NotNull
@Override
public List<PsiExpression> getExpressionsAt(@NotNull PsiElement elementAt)
{
    return SyntaxTraverser.psiApi().parents(elementAt).filter(PsiExpression.class).toList();
}
项目:consulo-java    文件:JavaCodeBlockModificationListener.java   
private static boolean hasClassesInside(@Nullable PsiElement element)
{
    return !SyntaxTraverser.psiTraverser(element).traverse().filter(Conditions.instanceOf(PsiClass.class, PsiLambdaExpression.class)).isEmpty();
}