Example #1
0
 @Override
 public void MetaFunction(metadslx.core.MetaFunction _this) {
   super.MetaFunction(_this);
   MetaFunctionType type = MetaFactory.instance().createMetaFunctionType();
   ((ModelObject) type).mUnSet(MetaDescriptor.MetaFunctionType.ParameterTypesProperty);
   ((ModelObject) type)
       .mLazySet(
           MetaDescriptor.MetaFunctionType.ParameterTypesProperty,
           Lazy.create(
               () ->
                   new ModelMultiList<>(
                       (ModelObject) _this,
                       MetaDescriptor.MetaFunctionType.ParameterTypesProperty,
                       _this
                           .getParameters()
                           .stream()
                           .map(p -> p.getType())
                           .collect(java.util.stream.Collectors.toList())),
               true));
   ((ModelObject) type)
       .mLazySet(
           MetaDescriptor.MetaFunctionType.ReturnTypeProperty,
           Lazy.create(() -> _this.getReturnType(), true));
   ((ModelObject) _this).mSet(MetaDescriptor.MetaFunction.TypeProperty, type);
 }
Example #2
0
 @Override
 public void MetaBinaryExpression(metadslx.core.MetaBinaryExpression _this) {
   super.MetaBinaryExpression(_this);
   ((ModelObject) _this)
       .mLazyAdd(
           MetaDescriptor.MetaBoundExpression.ArgumentsProperty,
           Lazy.create(() -> _this.getLeft(), true));
   ((ModelObject) _this)
       .mLazyAdd(
           MetaDescriptor.MetaBoundExpression.ArgumentsProperty,
           Lazy.create(() -> _this.getRight(), true));
 }
Example #3
0
 @Override
 public void MetaNewCollectionExpression(metadslx.core.MetaNewCollectionExpression _this) {
   super.MetaNewCollectionExpression(_this);
   ((ModelObject) _this)
       .mLazySetChild(
           MetaDescriptor.MetaNewCollectionExpression.ValuesProperty,
           MetaDescriptor.MetaExpression.ExpectedTypeProperty,
           Lazy.create(() -> _this.getTypeReference().getInnerType(), true));
 }
 protected boolean isLazy(DependencyDescriptor descriptor) {
   for (Annotation ann : descriptor.getAnnotations()) {
     Lazy lazy = AnnotationUtils.getAnnotation(ann, Lazy.class);
     if (lazy != null && lazy.value()) {
       return true;
     }
   }
   MethodParameter methodParam = descriptor.getMethodParameter();
   if (methodParam != null) {
     Method method = methodParam.getMethod();
     if (method == null || void.class == method.getReturnType()) {
       Lazy lazy = AnnotationUtils.getAnnotation(methodParam.getAnnotatedElement(), Lazy.class);
       if (lazy != null && lazy.value()) {
         return true;
       }
     }
   }
   return false;
 }
Example #5
0
  @Test
  public void providerOfLazyOfSomething() {
    final AtomicInteger counter = new AtomicInteger();
    class TestEntryPoint {
      @Inject Provider<Lazy<Integer>> providerOfLazyInteger;
    }

    @Module(entryPoints = TestEntryPoint.class)
    class TestModule {
      @Provides
      Integer provideInteger() {
        return counter.incrementAndGet();
      }
    }

    TestEntryPoint ep = injectWithModule(new TestEntryPoint(), new TestModule());
    assertEquals(0, counter.get());
    Lazy<Integer> i = ep.providerOfLazyInteger.get();
    assertEquals(1, i.get().intValue());
    assertEquals(1, counter.get());
    assertEquals(1, i.get().intValue());
    Lazy<Integer> j = ep.providerOfLazyInteger.get();
    assertEquals(2, j.get().intValue());
    assertEquals(2, counter.get());
    assertEquals(1, i.get().intValue());
  }
Example #6
0
 @Override
 default Function1<T1, R> memoized() {
   if (isMemoized()) {
     return this;
   } else {
     final Lazy<R> forNull = Lazy.of(() -> apply(null));
     final Object lock = new Object();
     final Map<T1, R> cache = new HashMap<>();
     return (Function1<T1, R> & Memoized)
         t1 -> {
           if (t1 == null) {
             return forNull.get();
           } else {
             final R result;
             synchronized (lock) {
               result = cache.computeIfAbsent(t1, this::apply);
             }
             return result;
           }
         };
   }
 }
Example #7
0
    private static void doTest() {
      if (loadLazy) {
        // anewarray
        Lazy[] array = new Lazy[1];

        // new and invokespecial
        Object lazy = new Lazy();

        // checkcast
        array[0] = (Lazy) lazy;

        // instanceof
        expect(lazy instanceof Lazy);

        // invokeinterface
        expect(array[0].interfaceMethod() == 42);

        // invokestatic
        expect(Lazy.staticMethod() == 43);

        // invokevirtual
        expect(array[0].virtualMethod() == 44);

        // ldc
        expect(Lazy.class == lazy.getClass());

        // multianewarray
        Lazy[][] multiarray = new Lazy[5][6];
        multiarray[2][3] = array[0];
        expect(multiarray[2][3] == array[0]);

        // getfield
        expect(array[0].intField == 45);

        // getstatic
        expect(Lazy.intStaticField == 46);

        // putfield int
        array[0].intField = 47;
        expect(array[0].intField == 47);

        // putfield long
        array[0].longField = 48;
        expect(array[0].longField == 48);

        // putfield object
        Object x = new Object();
        array[0].objectField = x;
        expect(array[0].objectField == x);

        // putstatic int
        array[0].intStaticField = 49;
        expect(array[0].intStaticField == 49);

        // putstatic long
        array[0].longStaticField = 50;
        expect(array[0].longStaticField == 50);

        // putstatic object
        Object y = new Object();
        array[0].objectStaticField = y;
        expect(array[0].objectStaticField == y);
      }
    }
Example #8
0
 public final Lazy<FV> eval(Lazy<FV> p) {
   return ((Prod4) p._e()).mem4;
 }
Example #9
0
 public static final Lazy<FV> get4(Lazy<FV> p) {
   return ((Prod4) p._e()).mem4;
 }
Example #10
0
 public final Lazy<FV> eval(Lazy<FV> p) {
   return ((Prod25) p._e()).mem3;
 }
Example #11
0
 public static final Lazy<FV> get3(Lazy<FV> p) {
   return ((Prod25) p._e()).mem3;
 }