Example #1
0
  public void test_visitCatchClause() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String exceptionParameterName = "e";
    String stackParameterName = "s";
    CatchClause clause = catchClause(exceptionParameterName, stackParameterName);
    clause.accept(builder);
    VariableElement[] variables = holder.getVariables();
    assertLength(2, variables);

    VariableElement exceptionVariable = variables[0];
    assertNotNull(exceptionVariable);
    assertEquals(exceptionParameterName, exceptionVariable.getName());
    assertFalse(exceptionVariable.isSynthetic());
    assertFalse(exceptionVariable.isConst());
    assertFalse(exceptionVariable.isFinal());
    assertNull(exceptionVariable.getInitializer());

    VariableElement stackVariable = variables[1];
    assertNotNull(stackVariable);
    assertEquals(stackParameterName, stackVariable.getName());
    assertFalse(stackVariable.isSynthetic());
    assertFalse(stackVariable.isConst());
    assertFalse(stackVariable.isFinal());
    assertNull(stackVariable.getInitializer());
  }
Example #2
0
  public void test_visitVariableDeclaration_noInitializer() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String variableName = "v";
    VariableDeclaration variableDeclaration = variableDeclaration(variableName, null);
    variableDeclarationList(null, variableDeclaration);
    variableDeclaration.accept(builder);
    VariableElement[] variables = holder.getVariables();
    assertLength(1, variables);

    VariableElement variable = variables[0];
    assertNotNull(variable);
    assertNull(variable.getInitializer());
    assertEquals(variableName, variable.getName());
    assertFalse(variable.isConst());
    assertFalse(variable.isFinal());
    assertFalse(variable.isSynthetic());
  }