1 Reply Latest reply on Nov 16, 2015 10:33 AM by mbarkley

    @CodeDecorator and 4.0.0-SNAPSHOT

    treblereel

      Hi Everyone,

       

      As I understand, there are some changes in errai-ioc 4.0.0-SNAPSHOT comparing to 3.2.1, i mean how decorators work. I have some and it works perfect but after I switched to 4.0.0 it stopped. Could you please give me a piece of advice how to fix it, because i really have no idea. I 've checked that this decorator is registered as a CodeDecorator for Check annotation.

      Thanks for any help.


      <code>

      @Target(ElementType.TYPE)

      @Retention(RetentionPolicy.RUNTIME)

      public @interface Check {

       

      }

       

      @CodeDecorator

      public class CheckCodeDecorator extends IOCDecoratorExtension<Check> {

       

        public CheckCodeDecorator(Class<Check> decoratesWith) {

          super(decoratesWith);

        }

       

        @Override

        public void generateDecorator(final Decorable decorable, final FactoryController controller) {

          final List<Statement> statements = new ArrayList<Statement>();

           /// some code which never called

        }

      </code>


      UPDATE: added maven test project with @Check annotation and decorator

       

      Сообщение отредактировано: Dmitrii Tikhomirov

        • 1. Re: @CodeDecorator and 4.0.0-SNAPSHOT
          mbarkley

          Hi Dmitrii,

           

          I was able to get the decorator working in your sample project by adding an explicit scope to the CheckClient class. What was happening is that Errai was ignoring your CheckClient class because it was not injected in any other types and had no explicit scope. Errai considers types like these to be unreachable and does not generate code to wire them to avoid generating code for types you are not injecting. Since no wiring code was generated for this class, the decorator for its Check annotation did not run.

           

          If you verify that this is the problem you're having in your actual project, there are a couple ways of fixing it.

          1. You can manually add @Dependent to all your unscoped, decorated types.
          2. You can make an extension that defines your annotation as an alias for @Dependent (like we do here for @Templated).

           

          Cheers.