@Test public void getFindUsagesOptions() { testHelper.getPsiClass( psiClasses -> { PsiClass layoutSpec = psiClasses.get(0); PsiClass mockedGeneratedComponentCls = mock(PsiClass.class); PsiFile mockedGeneratedComponentFile = mock(PsiFile.class); when(mockedGeneratedComponentCls.getContainingFile()) .thenReturn(mockedGeneratedComponentFile); VirtualFile generatedComponentVirtualFile = createPresentInScopeVirtualFile(); when(mockedGeneratedComponentFile.getVirtualFile()) .thenReturn(generatedComponentVirtualFile); VirtualFile presentInScopeVirtualFile = createPresentInScopeVirtualFile(); Function<PsiClass, PsiClass> findGeneratedComponent = psiClass -> mockedGeneratedComponentCls; GeneratedClassFindUsagesHandler handler = new GeneratedClassFindUsagesHandler(layoutSpec, findGeneratedComponent); SearchScope searchScope = handler.getFindUsagesOptions(null).searchScope; assertThat(searchScope.contains(presentInScopeVirtualFile)).isTrue(); assertThat(searchScope.contains(generatedComponentVirtualFile)).isFalse(); return true; }, "LayoutSpec.java"); }
@Override public FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) { FindUsagesOptions findUsagesOptions = super.getFindUsagesOptions(dataContext); Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .ifPresent( generatedCls -> { findUsagesOptions.searchScope = new ExcludingScope( findUsagesOptions.searchScope, ComponentScope.getVirtualFile(generatedCls.getContainingFile())); }); return findUsagesOptions; }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) { FindUsagesOptions findUsagesOptions = super.getFindUsagesOptions(dataContext); Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .ifPresent( generatedCls -> { findUsagesOptions.searchScope = new ExcludingScope( findUsagesOptions.searchScope, ComponentScope.getVirtualFile(generatedCls.getContainingFile())); }); return findUsagesOptions; } }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) { FindUsagesOptions findUsagesOptions = super.getFindUsagesOptions(dataContext); Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .ifPresent( generatedCls -> { findUsagesOptions.searchScope = new ExcludingScope( findUsagesOptions.searchScope, ComponentScope.getVirtualFile(generatedCls.getContainingFile())); }); return findUsagesOptions; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) { FindUsagesOptions findUsagesOptions = super.getFindUsagesOptions(dataContext); Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .ifPresent( generatedCls -> { findUsagesOptions.searchScope = new ExcludingScope( findUsagesOptions.searchScope, ComponentScope.getVirtualFile(generatedCls.getContainingFile())); }); return findUsagesOptions; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); @Override PsiElement[] getPrimaryElements(); @Override FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext); }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) { FindUsagesOptions findUsagesOptions = super.getFindUsagesOptions(dataContext); Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .ifPresent( generatedCls -> { findUsagesOptions.searchScope = new ExcludingScope( findUsagesOptions.searchScope, ComponentScope.getVirtualFile(generatedCls.getContainingFile())); }); return findUsagesOptions; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); @Override PsiElement[] getPrimaryElements(); @Override FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext);  }