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; }
@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; }
@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; }
@NotNull @Override public List<PsiExpression> getExpressionsAt(@NotNull PsiElement elementAt) { return SyntaxTraverser.psiApi().parents(elementAt).filter(PsiExpression.class).toList(); }
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); }
private static boolean hasClassesInside(@Nullable PsiElement element) { return !SyntaxTraverser.psiTraverser(element).traverse().filter(Conditions.instanceOf(PsiClass.class, PsiLambdaExpression.class)).isEmpty(); }