Ejemplo n.º 1
0
  @Override
  public Void visitClassDeclaration(ClassDeclaration node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    SimpleIdentifier className = node.getName();
    ClassElementImpl element = new ClassElementImpl(className);
    MethodElement[] methods = holder.getMethods();
    element.setAbstract(node.getAbstractKeyword() != null);
    element.setAccessors(holder.getAccessors());
    element.setConstructors(holder.getConstructors());
    element.setFields(holder.getFields());
    element.setMethods(methods);
    TypeVariableElement[] typeVariables = holder.getTypeVariables();
    element.setTypeVariables(typeVariables);

    InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
    int typeVariableCount = typeVariables.length;
    Type[] typeArguments = new Type[typeVariableCount];
    for (int i = 0; i < typeVariableCount; i++) {
      TypeVariableElementImpl typeVariable = (TypeVariableElementImpl) typeVariables[i];
      TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable);
      typeVariable.setType(typeArgument);
      typeArguments[i] = typeArgument;
    }
    interfaceType.setTypeArguments(typeArguments);
    element.setType(interfaceType);

    currentHolder.addType(element);
    className.setElement(element);
    return null;
  }
Ejemplo n.º 2
0
  public void test_visitMethodDeclaration_setter() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String methodName = "m";
    MethodDeclaration methodDeclaration =
        methodDeclaration(
            null,
            null,
            Keyword.SET,
            null,
            identifier(methodName),
            formalParameterList(),
            blockFunctionBody());
    methodDeclaration.accept(builder);
    FieldElement[] fields = holder.getFields();
    assertLength(1, fields);

    FieldElement field = fields[0];
    assertNotNull(field);
    assertEquals(methodName, field.getName());
    assertTrue(field.isSynthetic());
    assertNull(field.getGetter());
    PropertyAccessorElement setter = field.getSetter();
    assertNotNull(setter);
    assertTrue(setter.isSetter());
    assertFalse(setter.isSynthetic());
    assertEquals(methodName, setter.getName());
    assertEquals(field, setter.getField());
    assertLength(0, setter.getFunctions());
    assertLength(0, setter.getLabels());
    assertLength(0, setter.getLocalVariables());
    assertLength(0, setter.getParameters());
  }
Ejemplo n.º 3
0
  public void test_visitFieldDeclaration() {
    ElementHolder holder = new ElementHolder();
    ElementBuilder builder = new ElementBuilder(holder);
    String firstFieldName = "x";
    String secondFieldName = "y";
    FieldDeclaration fieldDeclaration =
        fieldDeclaration(
            false, null, variableDeclaration(firstFieldName), variableDeclaration(secondFieldName));
    fieldDeclaration.accept(builder);
    FieldElement[] fields = holder.getFields();
    assertLength(2, fields);

    FieldElement firstField = fields[0];
    assertNotNull(firstField);
    assertEquals(firstFieldName, firstField.getName());
    assertNull(firstField.getInitializer());
    assertFalse(firstField.isConst());
    assertFalse(firstField.isFinal());
    assertFalse(firstField.isSynthetic());

    FieldElement secondField = fields[1];
    assertNotNull(secondField);
    assertEquals(secondFieldName, secondField.getName());
    assertNull(secondField.getInitializer());
    assertFalse(secondField.isConst());
    assertFalse(secondField.isFinal());
    assertFalse(secondField.isSynthetic());
  }
Ejemplo n.º 4
0
  @Override
  public Void visitClassDeclaration(ClassDeclaration node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    TypeElementImpl element = new TypeElementImpl(node.getName());
    MethodElement[] methods = holder.getMethods();
    element.setAbstract(node.getAbstractKeyword() != null || hasAbstractMethod(methods));
    element.setAccessors(holder.getAccessors());
    element.setConstructors(holder.getConstructors());
    element.setFields(holder.getFields());
    element.setMethods(methods);
    element.setTypeVariables(holder.getTypeVariables());
    currentHolder.addType(element);
    return null;
  }
Ejemplo n.º 5
0
  @Override
  public Void visitClassDeclaration(ClassDeclaration node) {
    ElementHolder holder = new ElementHolder();
    isValidMixin = true;
    functionTypesToFix = new ArrayList<FunctionTypeImpl>();
    visitChildren(holder, node);

    SimpleIdentifier className = node.getName();
    ClassElementImpl element = new ClassElementImpl(className);
    TypeParameterElement[] typeParameters = holder.getTypeParameters();

    Type[] typeArguments = createTypeParameterTypes(typeParameters);
    InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
    interfaceType.setTypeArguments(typeArguments);
    element.setType(interfaceType);

    ConstructorElement[] constructors = holder.getConstructors();
    if (constructors.length == 0) {
      //
      // Create the default constructor.
      //
      constructors = createDefaultConstructors(interfaceType);
    }
    element.setAbstract(node.getAbstractKeyword() != null);
    element.setAccessors(holder.getAccessors());
    element.setConstructors(constructors);
    element.setFields(holder.getFields());
    element.setMethods(holder.getMethods());
    element.setTypeParameters(typeParameters);
    element.setValidMixin(isValidMixin);

    int functionTypeCount = functionTypesToFix.size();
    for (int i = 0; i < functionTypeCount; i++) {
      functionTypesToFix.get(i).setTypeArguments(typeArguments);
    }
    functionTypesToFix = null;
    currentHolder.addType(element);
    className.setStaticElement(element);
    holder.validate();
    return null;
  }