/**
   * Adds the necessary field and methods to support resource locating.
   *
   * @param declaringClass the class to which we add the support field and methods
   */
  public static void apply(@Nonnull ClassNode declaringClass, @Nullable String beanName) {
    injectInterface(declaringClass, EVENT_PUBLISHER_CNODE);

    FieldNode epField =
        injectField(
            declaringClass, EVENT_ROUTER_FIELD_NAME, PRIVATE, EVENT_PUBLISHER_FIELD_CNODE, null);

    Parameter erParam = param(EVENT_ROUTER_CNODE, EVENT_ROUTER_PROPERTY);
    if (!isBlank(beanName)) {
      AnnotationNode namedAnnotation = new AnnotationNode(NAMED_TYPE);
      namedAnnotation.addMember("value", new ConstantExpression(beanName));
      erParam.addAnnotation(namedAnnotation);
    }

    MethodNode setter =
        new MethodNode(
            METHOD_SET_EVENT_ROUTER,
            PRIVATE,
            VOID_TYPE,
            params(erParam),
            NO_EXCEPTIONS,
            stmnt(call(field(epField), METHOD_SET_EVENT_ROUTER, args(var(EVENT_ROUTER_PROPERTY)))));
    setter.addAnnotation(new AnnotationNode(INJECT_TYPE));
    injectMethod(declaringClass, setter);

    addDelegateMethods(declaringClass, EVENT_PUBLISHER_CNODE, field(epField));
  }
 /**
  * Convenience method to see if an annotated node is {@code @EventPublisher}.
  *
  * @param node the node to check
  * @return true if the node is an event publisher
  */
 public static boolean hasEventPublisherAnnotation(AnnotatedNode node) {
   for (AnnotationNode annotation : node.getAnnotations()) {
     if (EVENT_PUBLISHER_ANODE.equals(annotation.getClassNode())) {
       return true;
     }
   }
   return false;
 }
 public static void addEventPublisherIfNeeded(
     SourceUnit source, AnnotationNode annotationNode, ClassNode classNode) {
   if (needsDelegate(classNode, source, METHODS, "EventPublisher", EVENT_PUBLISHER_TYPE)) {
     LOG.debug("Injecting {} into {}", EVENT_PUBLISHER_TYPE, classNode.getName());
     ConstantExpression value = (ConstantExpression) annotationNode.getMember("value");
     String beanName = value != null ? value.getText() : null;
     beanName = isBlank(beanName) ? null : beanName;
     apply(classNode, beanName);
   }
 }