Пример #1
0
  @Test
  public void analyzingTwoArgumentsLambda() throws Exception {
    class C {
      void m() {
        λ(s, n, null);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertTrue(lambda.locals.isEmpty());
    assertTrue(lambda.getMutableLocals().isEmpty());

    assertEquals(list("s", "n"), list(lambda.parameters.keySet()));
    assertEquals(list(getType(String.class), INT_TYPE), lambda.getParameterTypes());

    assertEquals(list(object, object), lambda.newLambdaParameterTypes);

    assertEquals(object, lambda.expressionType);
    assertEquals(getType(Fn2.class), lambda.lambdaType);

    assertEquals("call", lambda.sam.getName());
    assertEquals(list(object, object), list(lambda.sam.getArgumentTypes()));
    assertEquals(object, lambda.sam.getReturnType());

    assertFalse(lambda.parameterNeedsUnboxing("s"));
    assertTrue(lambda.parameterNeedsUnboxing("n"));
  }
Пример #2
0
  @Test
  public void analyzingLambdaCreatedFromPrimitiveLambdaThatNeedsNarrowConversionFromLongToInt()
      throws Exception {
    class C {
      void m() {
        LambdaPrimitives.λ(l, idx, 0);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(getType(Fn2LLtoL.class), lambda.lambdaType);

    assertEquals(list(LONG_TYPE, LONG_TYPE), list(lambda.sam.getArgumentTypes()));
    assertEquals(list(LONG_TYPE, INT_TYPE), lambda.getParameterTypes());

    assertFalse(lambda.parameterNeedsUnboxing("l"));
    assertFalse(lambda.parameterNeedsBoxing("l"));
    assertFalse(lambda.parameterNeedsNarrowConversionFromActualArgument("l"));
    assertEquals(-1, lambda.parameterNarrowConversionOpcode("l"));

    assertFalse(lambda.parameterNeedsUnboxing("idx"));
    assertFalse(lambda.parameterNeedsBoxing("idx"));
    assertTrue(lambda.parameterNeedsNarrowConversionFromActualArgument("idx"));
    assertEquals(L2I, lambda.parameterNarrowConversionOpcode("idx"));

    assertEquals(LONG_TYPE, lambda.expressionType);
    assertEquals(LONG_TYPE, lambda.sam.getReturnType());
  }
Пример #3
0
  @Test
  public void analyzingLambdaCreatedFromGenericCastWithTypesThatNeedConversion() throws Exception {
    class C {
      void m() {
        I i = delegate(n, o1, dbl, 0);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(getType(I.class), lambda.lambdaType);
    assertEquals("invoke", lambda.sam.getName());

    assertEquals(list("n", "o1", "dbl"), list(lambda.parameters.keySet()));

    assertEquals(list(INT_TYPE, object, DOUBLE_TYPE), list(lambda.sam.getArgumentTypes()));
    assertEquals(list(INT_TYPE, object, getType(Double.class)), lambda.getParameterTypes());

    assertFalse(lambda.parameterNeedsUnboxing("n"));
    assertFalse(lambda.parameterNeedsBoxing("n"));

    assertFalse(lambda.parameterNeedsUnboxing("o1"));
    assertFalse(lambda.parameterNeedsBoxing("o1"));

    assertFalse(lambda.parameterNeedsUnboxing("dbl"));
    assertTrue(lambda.parameterNeedsBoxing("dbl"));

    assertEquals(object, lambda.expressionType);
    assertEquals(LONG_TYPE, lambda.sam.getReturnType());

    assertTrue(lambda.returnNeedsUnboxing());
    assertFalse(lambda.returnNeedsBoxing());
  }
Пример #4
0
  @Test
  public void analyzingLambdaCreatedFromPrimitiveLambdaThatNeedsNarrowConversionFromDoubleToFloat()
      throws Exception {
    class C {
      void m() {
        LambdaPrimitives.λ(d, fl, 0);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(getType(Fn2DDtoD.class), lambda.lambdaType);
    assertEquals(list(DOUBLE_TYPE, DOUBLE_TYPE), list(lambda.sam.getArgumentTypes()));
    assertEquals(list(DOUBLE_TYPE, FLOAT_TYPE), lambda.getParameterTypes());

    assertFalse(lambda.parameterNeedsUnboxing("fl"));
    assertFalse(lambda.parameterNeedsBoxing("fl"));
    assertTrue(lambda.parameterNeedsNarrowConversionFromActualArgument("fl"));
    assertEquals(D2F, lambda.parameterNarrowConversionOpcode("fl"));
  }