@Test public void findFirstParent() { testHelper.getPsiClass( psiClasses -> { Assert.assertNotNull(psiClasses); Assert.assertEquals(2, psiClasses.size()); PsiMethod layoutSpecMethod = psiClasses.get(0).getMethods()[0]; Optional<PsiClass> layoutSpec = CompletionUtils.findFirstParent(layoutSpecMethod, LithoPluginUtils::isLayoutSpec); Assert.assertTrue(layoutSpec.isPresent()); Optional<PsiClass> componentCls = CompletionUtils.findFirstParent(layoutSpecMethod, LithoPluginUtils::isComponentClass); Assert.assertFalse(componentCls.isPresent()); PsiMethod sectionSpecMethod = psiClasses.get(1).getMethods()[0]; Optional<PsiClass> layoutSpecInSection = CompletionUtils.findFirstParent(sectionSpecMethod, LithoPluginUtils::isLayoutSpec); Assert.assertFalse(layoutSpecInSection.isPresent()); Optional<PsiClass> lithoSpec = CompletionUtils.findFirstParent(sectionSpecMethod, LithoPluginUtils::isLithoSpec); Assert.assertTrue(lithoSpec.isPresent()); return true; }, "LayoutSpec.java", "SectionSpec.java"); }
static Optional<PsiClass> findFirstParent(PsiElement element, Predicate<PsiClass> condition) { return Optional.ofNullable(PsiTreeUtil.findFirstParent(element, PsiClass.class::isInstance)) .map(PsiClass.class::cast) .filter(condition); }
CompletionUtils { static Optional<PsiClass> findFirstParent(PsiElement element, Predicate<PsiClass> condition) { return Optional.ofNullable(PsiTreeUtil.findFirstParent(element, PsiClass.class::isInstance)) .map(PsiClass.class::cast) .filter(condition); } }
CompletionUtils { static Optional<PsiClass> findFirstParent(PsiElement element, Predicate<PsiClass> condition) { return Optional.ofNullable(PsiTreeUtil.findFirstParent(element, PsiClass.class::isInstance)) .map(PsiClass.class::cast) .filter(condition); }  }
CompletionUtils { static Optional<PsiClass> findFirstParent(PsiElement element, Predicate<PsiClass> condition) { return Optional.ofNullable(PsiTreeUtil.findFirstParent(element, PsiClass.class::isInstance)) .map(PsiClass.class::cast) .filter(condition); }   }
CompletionUtils { static Optional<PsiClass> findFirstParent(PsiElement element, Predicate<PsiClass> condition) { return Optional.ofNullable(PsiTreeUtil.findFirstParent(element, PsiClass.class::isInstance)) .map(PsiClass.class::cast) .filter(condition); }    }