Supplier<Collection<PsiElement>> () { return () -> { Set<PsiElement> result = new HashSet<>(); List<PsiElement> startPoints = new ArrayList<>(); JavaRecursiveElementVisitor fileVisitor = new JavaRecursiveElementVisitor() { @Override public void visitClassInitializer(@NotNull PsiClassInitializer initializer) { if (myMetaInfo.callType == MetaInfoCallType.STATIC_INIT) { startPoints.add(initializer); } } @Override public void visitField(@NotNull PsiField field) { if (myMetaInfo.callType == MetaInfoCallType.STATIC_INIT && field.hasModifierProperty(PsiModifier.STATIC)) { startPoints.add(field); } if (myMetaInfo.callType == MetaInfoCallType.NON_STATIC_INIT && !field.hasModifier(JvmModifier.STATIC)) { startPoints.add(field); } } @Override public void visitMethod(@NotNull PsiMethod method) { ProgressManager.checkCanceled(); if (myMetaInfo.callType != MetaInfoCallType.LAMBDA && placeMatch(method, myMetaInfo)) { startPoints.add(method); } if (myMetaInfo.callType == MetaInfoCallType.LAMBDA) { super.visitMethod(method); } } @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { ProgressManager.checkCanceled(); if (myMetaInfo.callType == MetaInfoCallType.LAMBDA) { PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class); if (method != null && placeMatch(method, myMetaInfo)) { startPoints.add(expression); } } } }; myPsiFile.acceptChildren(fileVisitor); for (PsiElement startPoint : startPoints) { PsiTreeUtil.processElements(startPoint, new PsiElementProcessor<>() { @Override public boolean execute(@NotNull PsiElement element) { ProgressManager.checkCanceled(); ExceptionLineRefiner.RefinerMatchResult matchedElement = myRefiner.matchElement(element); if (matchedElement != null && matchedElement.target() instanceof Navigatable) { PsiElement target = matchedElement.target(); PsiMethod matchedElementMethod = PsiTreeUtil.getParentOfType(target, PsiMethod.class); if (matchedElementMethod != null && placeMatch(matchedElementMethod, myMetaInfo)) { result.add(target); } if (matchedElementMethod == null && (myMetaInfo.callType == MetaInfoCallType.NON_STATIC_INIT || myMetaInfo.callType == MetaInfoCallType.STATIC_INIT)) { result.add(target); } } return true; } }); } if (result.isEmpty()) { result.addAll(startPoints); } return result.stream().sorted(Comparator.comparing(element -> element.getTextOffset())).collect(Collectors.toList()); }; }