@Test public void getGotoDeclarationTargets_findProps_found() { ApplicationManager.getApplication() .invokeAndWait( () -> { final PsiFile file = testHelper .getFixture() .configureByFile("ComponentsMethodDeclarationHandlerTest.java"); PsiClass testSpecClass = findClass("TestSpec", file); final PsiIdentifier componentMethodCall = findIdentifier(testSpecClass.findMethodsByName("test2", false)[0], "prop"); final PsiElement[] specElements = new ComponentsMethodDeclarationHandler() .getGotoDeclarationTargets( componentMethodCall, 0, testHelper.getFixture().getEditor()); assertThat(specElements.length).isOne(); PsiParameter targetProp = (PsiParameter) specElements[0]; assertThat(targetProp.getName()).isEqualTo("prop"); }); }
@Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (sourceElement == null || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) { return PsiElement.EMPTY_ARRAY; } final Project project = sourceElement.getProject(); return BaseLithoComponentsDeclarationHandler.resolve(sourceElement) .filter(PsiMethod.class::isInstance) .map(PsiMethod.class::cast) .map(method -> findSpecElements(method, project)) .filter(result -> result.length > 0) .findFirst() .map( result -> { final Map<String, String> data = new HashMap<>(); data.put( EventLogger.KEY_TARGET, result[0] instanceof PsiMethod ? EventLogger.VALUE_NAVIGATION_TARGET_METHOD : EventLogger.VALUE_NAVIGATION_TARGET_PARAMETER); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO); LOGGER.log(EventLogger.EVENT_NAVIGATION, data); return result; }) .orElse(PsiElement.EMPTY_ARRAY); }
ComponentsMethodDeclarationHandler extends GotoDeclarationHandlerBase { @Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (sourceElement == null || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) { return PsiElement.EMPTY_ARRAY; } final Project project = sourceElement.getProject(); return BaseLithoComponentsDeclarationHandler.resolve(sourceElement) .filter(PsiMethod.class::isInstance) .map(PsiMethod.class::cast) .map(method -> findSpecElements(method, project)) .filter(result -> result.length > 0) .findFirst() .map( result -> { final Map<String, String> data = new HashMap<>(); data.put( EventLogger.KEY_TARGET, result[0] instanceof PsiMethod ? EventLogger.VALUE_NAVIGATION_TARGET_METHOD : EventLogger.VALUE_NAVIGATION_TARGET_PARAMETER); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO); LOGGER.log(EventLogger.EVENT_NAVIGATION, data); return result; }) .orElse(PsiElement.EMPTY_ARRAY); } }
ComponentsMethodDeclarationHandler extends GotoDeclarationHandlerBase { @Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (sourceElement == null || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) { return PsiElement.EMPTY_ARRAY; } final Project project = sourceElement.getProject(); return BaseLithoComponentsDeclarationHandler.resolve(sourceElement) .filter(PsiMethod.class::isInstance) .map(PsiMethod.class::cast) .map(method -> findSpecElements(method, project)) .filter(result -> result.length > 0) .findFirst() .map( result -> { final Map<String, String> data = new HashMap<>(); data.put( EventLogger.KEY_TARGET, result[0] instanceof PsiMethod ? EventLogger.VALUE_NAVIGATION_TARGET_METHOD : EventLogger.VALUE_NAVIGATION_TARGET_PARAMETER); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO); LOGGER.log(EventLogger.EVENT_NAVIGATION, data); return result; }) .orElse(PsiElement.EMPTY_ARRAY); }  }
ComponentsMethodDeclarationHandler extends GotoDeclarationHandlerBase { @Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (sourceElement == null || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) { return PsiElement.EMPTY_ARRAY; } final Project project = sourceElement.getProject(); return BaseLithoComponentsDeclarationHandler.resolve(sourceElement) .filter(PsiMethod.class::isInstance) .map(PsiMethod.class::cast) .map(method -> findSpecElements(method, project)) .filter(result -> result.length > 0) .findFirst() .map( result -> { final Map<String, String> data = new HashMap<>(); data.put( EventLogger.KEY_TARGET, result[0] instanceof PsiMethod ? EventLogger.VALUE_NAVIGATION_TARGET_METHOD : EventLogger.VALUE_NAVIGATION_TARGET_PARAMETER); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO); LOGGER.log(EventLogger.EVENT_NAVIGATION, data); return result; }) .orElse(PsiElement.EMPTY_ARRAY); }  @Nullable @Override PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor); @Override PsiElement[] getGotoDeclarationTargets(
      @Nullable PsiElement sourceElement, int offset, Editor editor); }
ComponentsMethodDeclarationHandler extends GotoDeclarationHandlerBase { @Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (sourceElement == null || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) { return PsiElement.EMPTY_ARRAY; } final Project project = sourceElement.getProject(); return BaseLithoComponentsDeclarationHandler.resolve(sourceElement) .filter(PsiMethod.class::isInstance) .map(PsiMethod.class::cast) .map(method -> findSpecElements(method, project)) .filter(result -> result.length > 0) .findFirst() .map( result -> { final Map<String, String> data = new HashMap<>(); data.put( EventLogger.KEY_TARGET, result[0] instanceof PsiMethod ? EventLogger.VALUE_NAVIGATION_TARGET_METHOD : EventLogger.VALUE_NAVIGATION_TARGET_PARAMETER); data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO); LOGGER.log(EventLogger.EVENT_NAVIGATION, data); return result; }) .orElse(PsiElement.EMPTY_ARRAY); }  @Nullable @Override PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor); @Override PsiElement[] getGotoDeclarationTargets(
      @Nullable PsiElement sourceElement, int offset, Editor editor);  }