コード例 #1
0
  @Test
  public void analyzingLambdaClosingOverEffectivelyFinalArgument() throws Exception {
    class C {
      void m(int i) {
        λ(i);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(1, lambda.locals.size());
    assertTrue(lambda.getMutableLocals().isEmpty());

    assertEquals(list("i"), list(lambda.locals.keySet()));
    assertEquals(INT_TYPE, lambda.getLocalVariableType("i"));
  }
コード例 #2
0
  @Test
  public void analyzingLambdaClosingOverVariableInitialziedInLambda() throws Exception {
    class C {
      void m() {
        int i;
        λ(i = 2);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(1, lambda.locals.size());
    assertEquals(1, lambda.getMutableLocals().size());

    assertEquals(list("i"), list(lambda.getMutableLocals().keySet()));
    assertEquals(INT_TYPE, lambda.getLocalVariableType("i"));
  }
コード例 #3
0
  @Test
  public void analyzingLambdaClosingOverIncreasedVariableOutsideLambda() throws Exception {
    class C {
      void m() {
        int i = 1;
        λ(i++);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(1, lambda.locals.size());
    assertEquals(1, lambda.getMutableLocals().size());

    assertEquals(list("i"), list(lambda.getMutableLocals().keySet()));
    assertEquals(INT_TYPE, lambda.getLocalVariableType("i"));
  }
コード例 #4
0
  @Test
  public void analyzingLambdaClosingOverMutableArgument() throws Exception {
    class C {
      void m(int i) {
        i = 2;
        i = 4;
        λ(i);
      }
    }

    LambdaAnalyzer lambda = lambdaIn(C.class);

    assertEquals(1, lambda.locals.size());
    assertEquals(1, lambda.getMutableLocals().size());

    assertEquals(list("i"), list(lambda.getMutableLocals().keySet()));
    assertEquals(INT_TYPE, lambda.getLocalVariableType("i"));
  }