@Test public void getPrimaryElements() { PsiClass mockedElement = mock(PsiClass.class); PsiClass mockedResult = mock(PsiClass.class); Function<PsiClass, PsiClass> findGeneratedComponent = psiClass -> mockedResult; GeneratedClassFindUsagesHandler handler = new GeneratedClassFindUsagesHandler(mockedElement, findGeneratedComponent); PsiElement[] primaryElements = handler.getPrimaryElements(); assertThat(primaryElements.length).isEqualTo(2); assertThat(primaryElements[0]).isSameAs(mockedResult); assertThat(primaryElements[1]).isSameAs(mockedElement); }
@Override public PsiElement[] getPrimaryElements() { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_RESULT, "fail"); final PsiElement[] results = Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .map( psiClass -> { data.put(EventLogger.KEY_RESULT, "success"); return ArrayUtil.insert(super.getPrimaryElements(), 0, psiClass); }) .orElseGet(super::getPrimaryElements); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_NAVIGATION_TARGET_CLASS); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_FIND_USAGES); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_NAVIGATION, data); return results; }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public PsiElement[] getPrimaryElements() { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_RESULT, "fail"); final PsiElement[] results = Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .map( psiClass -> { data.put(EventLogger.KEY_RESULT, "success"); return ArrayUtil.insert(super.getPrimaryElements(), 0, psiClass); }) .orElseGet(super::getPrimaryElements); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_NAVIGATION_TARGET_CLASS); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_FIND_USAGES); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_NAVIGATION, data); return results; } }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public PsiElement[] getPrimaryElements() { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_RESULT, "fail"); final PsiElement[] results = Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .map( psiClass -> { data.put(EventLogger.KEY_RESULT, "success"); return ArrayUtil.insert(super.getPrimaryElements(), 0, psiClass); }) .orElseGet(super::getPrimaryElements); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_NAVIGATION_TARGET_CLASS); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_FIND_USAGES); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_NAVIGATION, data); return results; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public PsiElement[] getPrimaryElements() { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_RESULT, "fail"); final PsiElement[] results = Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .map( psiClass -> { data.put(EventLogger.KEY_RESULT, "success"); return ArrayUtil.insert(super.getPrimaryElements(), 0, psiClass); }) .orElseGet(super::getPrimaryElements); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_NAVIGATION_TARGET_CLASS); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_FIND_USAGES); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_NAVIGATION, data); return results; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); @Override PsiElement[] getPrimaryElements(); @Override FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext); }
GeneratedClassFindUsagesHandler extends FindUsagesHandler { @Override public PsiElement[] getPrimaryElements() { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_RESULT, "fail"); final PsiElement[] results = Optional.of(getPsiElement()) .filter(PsiClass.class::isInstance) .map(PsiClass.class::cast) .map(findGeneratedClass) .map( psiClass -> { data.put(EventLogger.KEY_RESULT, "success"); return ArrayUtil.insert(super.getPrimaryElements(), 0, psiClass); }) .orElseGet(super::getPrimaryElements); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_NAVIGATION_TARGET_CLASS); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_FIND_USAGES); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_NAVIGATION, data); return results; } GeneratedClassFindUsagesHandler(
      PsiElement psiElement, Function<PsiClass, PsiClass> findGeneratedClass); @Override PsiElement[] getPrimaryElements(); @Override FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext);  }