@Test public void markStatement() { testHelper.getPsiClass( psiClasses -> { assertThat(psiClasses).hasSize(2); PsiClass underTest = psiClasses.get(0); PsiClass component = psiClasses.get(1); Function<PsiMethodCallExpression, PsiClass> resolver = ignored -> component; RequiredPropLineMarkerProvider provider = new RequiredPropLineMarkerProvider(resolver); List<PsiElement> statements = new ArrayList<>(PsiTreeUtil.findChildrenOfAnyType(underTest, PsiStatement.class)); assertThat(provider.getLineMarkerInfo(statements.get(0))).isNotNull(); assertThat(provider.getLineMarkerInfo(statements.get(1))).isNull(); return true; }, "RequiredPropAnnotatorTest.java", "RequiredPropAnnotatorComponent.java"); }
@Nullable @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { final List<PsiReferenceExpression> methodCalls = new ArrayList<>(); final List<Collection<String>> missingPropNames = new ArrayList<>(); RequiredPropAnnotator.annotate( element, (missingRequiredPropNames, createMethodCall) -> { methodCalls.add(createMethodCall); missingPropNames.add(missingRequiredPropNames); }, generatedClassResolver); if (methodCalls.isEmpty()) { return null; } PsiElement leaf = methodCalls.get(0); final Collection<String> missingProps = missingPropNames.get(0); while (leaf.getFirstChild() != null) { leaf = leaf.getFirstChild(); } return new LineMarkerInfo<>( leaf, leaf.getTextRange(), LithoPluginIcons.ERROR_ACTION, 0, ignored -> RequiredPropAnnotator.createErrorMessage(missingProps), null, GutterIconRenderer.Alignment.CENTER); }
RequiredPropLineMarkerProvider implements LineMarkerProvider { @Nullable @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { final List<PsiReferenceExpression> methodCalls = new ArrayList<>(); final List<Collection<String>> missingPropNames = new ArrayList<>(); RequiredPropAnnotator.annotate( element, (missingRequiredPropNames, createMethodCall) -> { methodCalls.add(createMethodCall); missingPropNames.add(missingRequiredPropNames); }, generatedClassResolver); if (methodCalls.isEmpty()) { return null; } PsiElement leaf = methodCalls.get(0); final Collection<String> missingProps = missingPropNames.get(0); while (leaf.getFirstChild() != null) { leaf = leaf.getFirstChild(); } return new LineMarkerInfo<>( leaf, leaf.getTextRange(), LithoPluginIcons.ERROR_ACTION, 0, ignored -> RequiredPropAnnotator.createErrorMessage(missingProps), null, GutterIconRenderer.Alignment.CENTER); } }
RequiredPropLineMarkerProvider implements LineMarkerProvider { @Nullable @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { final List<PsiReferenceExpression> methodCalls = new ArrayList<>(); final List<Collection<String>> missingPropNames = new ArrayList<>(); RequiredPropAnnotator.annotate( element, (missingRequiredPropNames, createMethodCall) -> { methodCalls.add(createMethodCall); missingPropNames.add(missingRequiredPropNames); }, generatedClassResolver); if (methodCalls.isEmpty()) { return null; } PsiElement leaf = methodCalls.get(0); final Collection<String> missingProps = missingPropNames.get(0); while (leaf.getFirstChild() != null) { leaf = leaf.getFirstChild(); } return new LineMarkerInfo<>( leaf, leaf.getTextRange(), LithoPluginIcons.ERROR_ACTION, 0, ignored -> RequiredPropAnnotator.createErrorMessage(missingProps), null, GutterIconRenderer.Alignment.CENTER); } RequiredPropLineMarkerProvider(); @VisibleForTesting  RequiredPropLineMarkerProvider(
      Function<PsiMethodCallExpression, PsiClass> generatedClassResolver); }
RequiredPropLineMarkerProvider implements LineMarkerProvider { @Nullable @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { final List<PsiReferenceExpression> methodCalls = new ArrayList<>(); final List<Collection<String>> missingPropNames = new ArrayList<>(); RequiredPropAnnotator.annotate( element, (missingRequiredPropNames, createMethodCall) -> { methodCalls.add(createMethodCall); missingPropNames.add(missingRequiredPropNames); }, generatedClassResolver); if (methodCalls.isEmpty()) { return null; } PsiElement leaf = methodCalls.get(0); final Collection<String> missingProps = missingPropNames.get(0); while (leaf.getFirstChild() != null) { leaf = leaf.getFirstChild(); } return new LineMarkerInfo<>( leaf, leaf.getTextRange(), LithoPluginIcons.ERROR_ACTION, 0, ignored -> RequiredPropAnnotator.createErrorMessage(missingProps), null, GutterIconRenderer.Alignment.CENTER); } RequiredPropLineMarkerProvider(); @VisibleForTesting  RequiredPropLineMarkerProvider(
      Function<PsiMethodCallExpression, PsiClass> generatedClassResolver); @Nullable @Override LineMarkerInfo getLineMarkerInfo(PsiElement element); @Override void collectSlowLineMarkers(
      List<PsiElement> elements, Collection<LineMarkerInfo> result); }
RequiredPropLineMarkerProvider implements LineMarkerProvider { @Nullable @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { final List<PsiReferenceExpression> methodCalls = new ArrayList<>(); final List<Collection<String>> missingPropNames = new ArrayList<>(); RequiredPropAnnotator.annotate( element, (missingRequiredPropNames, createMethodCall) -> { methodCalls.add(createMethodCall); missingPropNames.add(missingRequiredPropNames); }, generatedClassResolver); if (methodCalls.isEmpty()) { return null; } PsiElement leaf = methodCalls.get(0); final Collection<String> missingProps = missingPropNames.get(0); while (leaf.getFirstChild() != null) { leaf = leaf.getFirstChild(); } return new LineMarkerInfo<>( leaf, leaf.getTextRange(), LithoPluginIcons.ERROR_ACTION, 0, ignored -> RequiredPropAnnotator.createErrorMessage(missingProps), null, GutterIconRenderer.Alignment.CENTER); } RequiredPropLineMarkerProvider(); @VisibleForTesting  RequiredPropLineMarkerProvider(
      Function<PsiMethodCallExpression, PsiClass> generatedClassResolver); @Nullable @Override LineMarkerInfo getLineMarkerInfo(PsiElement element); @Override void collectSlowLineMarkers(
      List<PsiElement> elements, Collection<LineMarkerInfo> result);  }