@Test public void annotate_class_found() throws IOException { final PsiFile file = testHelper.configure("LayoutSpecAnnotatorSpec.java"); ApplicationManager.getApplication() .invokeAndWait( () -> { final PsiClass cls = LithoPluginUtils.getFirstLayoutSpec(file).get(); final TestHolder holder = new TestHolder(); new LayoutSpecAnnotator().annotate(cls, holder); assertThat(holder.errorMessages).hasSize(2); assertThat(holder.errorMessages) .containsExactly( "Methods annotated with interface com.facebook.litho.annotations.OnCreateInitialState must have at least 1 parameters, and they should be of type com.facebook.litho.ComponentContext.", "You need to have a method annotated with either @OnCreateLayout or @OnCreateLayoutWithSizeSpec in your spec. In most cases, @OnCreateLayout is what you want."); }); }
@Override public void annotate(PsiElement element, AnnotationHolder holder) { final PsiClass layoutSpec = getLayoutSpec(element); if (layoutSpec == null) return; try { if (!ComponentGenerateService.getInstance().tryUpdateLayoutComponent(layoutSpec)) { return; } } catch (Exception e) { DEBUG_LOGGER.debug(e); } DEBUG_LOGGER.debug(element + " under analysis"); final List<SpecModelValidationError> errors = Optional.ofNullable(ComponentGenerateService.getInstance().getSpecModel(layoutSpec)) .map(model -> model.validate(RunMode.normal())) .orElse(Collections.emptyList()); if (!errors.isEmpty()) { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "layout_spec"); LOGGER.log(EventLogger.EVENT_ANNOTATOR, data); errors.forEach(error -> AnnotatorUtils.addError(holder, error)); } }
LayoutSpecAnnotator implements Annotator { @Override public void annotate(PsiElement element, AnnotationHolder holder) { final PsiClass layoutSpec = getLayoutSpec(element); if (layoutSpec == null) return; try { if (!ComponentGenerateService.getInstance().tryUpdateLayoutComponent(layoutSpec)) { return; } } catch (Exception e) { DEBUG_LOGGER.debug(e); } DEBUG_LOGGER.debug(element + " under analysis"); final List<SpecModelValidationError> errors = Optional.ofNullable(ComponentGenerateService.getInstance().getSpecModel(layoutSpec)) .map(model -> model.validate(RunMode.normal())) .orElse(Collections.emptyList()); if (!errors.isEmpty()) { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "layout_spec"); LOGGER.log(EventLogger.EVENT_ANNOTATOR, data); errors.forEach(error -> AnnotatorUtils.addError(holder, error)); } } }
LayoutSpecAnnotator implements Annotator { @Override public void annotate(PsiElement element, AnnotationHolder holder) { final PsiClass layoutSpec = getLayoutSpec(element); if (layoutSpec == null) return; try { if (!ComponentGenerateService.getInstance().tryUpdateLayoutComponent(layoutSpec)) { return; } } catch (Exception e) { DEBUG_LOGGER.debug(e); } DEBUG_LOGGER.debug(element + " under analysis"); final List<SpecModelValidationError> errors = Optional.ofNullable(ComponentGenerateService.getInstance().getSpecModel(layoutSpec)) .map(model -> model.validate(RunMode.normal())) .orElse(Collections.emptyList()); if (!errors.isEmpty()) { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "layout_spec"); LOGGER.log(EventLogger.EVENT_ANNOTATOR, data); errors.forEach(error -> AnnotatorUtils.addError(holder, error)); } }  }
LayoutSpecAnnotator implements Annotator { @Override public void annotate(PsiElement element, AnnotationHolder holder) { final PsiClass layoutSpec = getLayoutSpec(element); if (layoutSpec == null) return; try { if (!ComponentGenerateService.getInstance().tryUpdateLayoutComponent(layoutSpec)) { return; } } catch (Exception e) { DEBUG_LOGGER.debug(e); } DEBUG_LOGGER.debug(element + " under analysis"); final List<SpecModelValidationError> errors = Optional.ofNullable(ComponentGenerateService.getInstance().getSpecModel(layoutSpec)) .map(model -> model.validate(RunMode.normal())) .orElse(Collections.emptyList()); if (!errors.isEmpty()) { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "layout_spec"); LOGGER.log(EventLogger.EVENT_ANNOTATOR, data); errors.forEach(error -> AnnotatorUtils.addError(holder, error)); } }  @Override void annotate(PsiElement element, AnnotationHolder holder); }
LayoutSpecAnnotator implements Annotator { @Override public void annotate(PsiElement element, AnnotationHolder holder) { final PsiClass layoutSpec = getLayoutSpec(element); if (layoutSpec == null) return; try { if (!ComponentGenerateService.getInstance().tryUpdateLayoutComponent(layoutSpec)) { return; } } catch (Exception e) { DEBUG_LOGGER.debug(e); } DEBUG_LOGGER.debug(element + " under analysis"); final List<SpecModelValidationError> errors = Optional.ofNullable(ComponentGenerateService.getInstance().getSpecModel(layoutSpec)) .map(model -> model.validate(RunMode.normal())) .orElse(Collections.emptyList()); if (!errors.isEmpty()) { final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "layout_spec"); LOGGER.log(EventLogger.EVENT_ANNOTATOR, data); errors.forEach(error -> AnnotatorUtils.addError(holder, error)); } }  @Override void annotate(PsiElement element, AnnotationHolder holder);  }