コード例 #1
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());
  }
コード例 #2
0
  @Test
  public void analyzingZeroArgumentLambda() throws Exception {
    class C {
      void m() {
        λ();
      }
    }

    LambdaTreeWeaver weaver = analyze(C.class);
    assertEquals(getType(C.class).getInternalName(), weaver.c.name);
    assertEquals(2, weaver.methods.size());

    MethodAnalyzer constructor = weaver.methods.get(0);
    assertEquals("<init>", constructor.m.name);
    assertTrue(constructor.lambdas.isEmpty());

    MethodAnalyzer method = weaver.methods.get(1);
    assertEquals("m", method.m.name);

    assertEquals(1, method.lambdas.size());
    LambdaAnalyzer lambda = method.lambdas.get(0);

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

    assertTrue(lambda.parameters.isEmpty());
    assertTrue(lambda.newLambdaParameterTypes.isEmpty());

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

    assertEquals("call", lambda.sam.getName());
    assertEquals(0, lambda.sam.getArgumentTypes().length);

    assertEquals(object, lambda.sam.getReturnType());
    assertFalse(lambda.returnNeedsUnboxing());
    assertFalse(lambda.returnNeedsBoxing());
  }
コード例 #3
0
  @Test
  public void analyzingLambdaCreatedFromGenericCastWhichAlsoDefinesMethodFromObject()
      throws Exception {
    class C {
      void m() {
        Comparator<?> c = delegate(o1, o2, 0);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(list("o1", "o2"), list(lambda.parameters.keySet()));
    assertEquals(list(object, object), lambda.newLambdaParameterTypes);
    assertEquals(object, lambda.expressionType);

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

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

    assertEquals(INT_TYPE, lambda.sam.getReturnType());
    assertTrue(lambda.returnNeedsUnboxing());
    assertFalse(lambda.returnNeedsBoxing());
  }