Ejemplo n.º 1
0
  public void test_visitClassDeclaration_parameterized() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String className = "C";
    String firstVariableName = "E";
    String secondVariableName = "F";
    ClassDeclaration classDeclaration =
        classDeclaration(
            null,
            className,
            typeParameterList(firstVariableName, secondVariableName),
            null,
            null,
            null);
    classDeclaration.accept(builder);
    ClassElement[] types = holder.getTypes();
    assertLength(1, types);

    ClassElement type = types[0];
    assertNotNull(type);
    assertEquals(className, type.getName());
    TypeVariableElement[] typeVariables = type.getTypeVariables();
    assertLength(2, typeVariables);
    assertEquals(firstVariableName, typeVariables[0].getName());
    assertEquals(secondVariableName, typeVariables[1].getName());
    assertFalse(type.isAbstract());
    assertFalse(type.isSynthetic());
  }
Ejemplo n.º 2
0
  public void test_visitClassDeclaration_withMembers() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String className = "C";
    String typeVariableName = "E";
    String fieldName = "f";
    String methodName = "m";
    ClassDeclaration classDeclaration =
        classDeclaration(
            null,
            className,
            typeParameterList(typeVariableName),
            null,
            null,
            null,
            fieldDeclaration(false, null, variableDeclaration(fieldName)),
            methodDeclaration(
                null,
                null,
                null,
                null,
                identifier(methodName),
                formalParameterList(),
                blockFunctionBody()));
    classDeclaration.accept(builder);
    ClassElement[] types = holder.getTypes();
    assertLength(1, types);

    ClassElement type = types[0];
    assertNotNull(type);
    assertEquals(className, type.getName());
    assertFalse(type.isAbstract());
    assertFalse(type.isSynthetic());

    TypeVariableElement[] typeVariables = type.getTypeVariables();
    assertLength(1, typeVariables);
    TypeVariableElement typeVariable = typeVariables[0];
    assertNotNull(typeVariable);
    assertEquals(typeVariableName, typeVariable.getName());

    FieldElement[] fields = type.getFields();
    assertLength(1, fields);
    FieldElement field = fields[0];
    assertNotNull(field);
    assertEquals(fieldName, field.getName());

    MethodElement[] methods = type.getMethods();
    assertLength(1, methods);
    MethodElement method = methods[0];
    assertNotNull(method);
    assertEquals(methodName, method.getName());
  }
Ejemplo n.º 3
0
  public void test_visitClassDeclaration_minimal() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String className = "C";
    ClassDeclaration classDeclaration = classDeclaration(null, className, null, null, null, null);
    classDeclaration.accept(builder);
    ClassElement[] types = holder.getTypes();
    assertLength(1, types);

    ClassElement type = types[0];
    assertNotNull(type);
    assertEquals(className, type.getName());
    TypeVariableElement[] typeVariables = type.getTypeVariables();
    assertLength(0, typeVariables);
    assertFalse(type.isAbstract());
    assertFalse(type.isSynthetic());
  }