Package com.google.dart.engine.internal.element

Examples of com.google.dart.engine.internal.element.ClassElementImpl


    } finally {
      currentHolder = previousHolder;
    }

    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.isAbstract());
    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);
    }
View Full Code Here


    ElementHolder holder = new ElementHolder();
    functionTypesToFix = new ArrayList<FunctionTypeImpl>();
    visitChildren(holder, node);

    SimpleIdentifier className = node.getName();
    ClassElementImpl element = new ClassElementImpl(className);
    element.setAbstract(node.getAbstractKeyword() != null);
    element.setTypedef(true);
    TypeParameterElement[] typeParameters = holder.getTypeParameters();
    element.setTypeParameters(typeParameters);

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

    // set default constructor
    element.setConstructors(createDefaultConstructors(interfaceType));

    for (FunctionTypeImpl functionType : functionTypesToFix) {
      functionType.setTypeArguments(typeArguments);
    }
    functionTypesToFix = null;
View Full Code Here

  }

  @Override
  public Void visitEnumDeclaration(EnumDeclaration node) {
    SimpleIdentifier enumName = node.getName();
    ClassElementImpl enumElement = new ClassElementImpl(enumName);
    enumElement.setEnum(true);
    InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement);
    enumElement.setType(enumType);
    currentHolder.addEnum(enumElement);
    enumName.setStaticElement(enumElement);
    return super.visitEnumDeclaration(node);
  }
View Full Code Here

  @Override
  public Void visitEnumDeclaration(EnumDeclaration node) {
    //
    // Finish building the enum.
    //
    ClassElementImpl enumElement = (ClassElementImpl) node.getName().getStaticElement();
    InterfaceType enumType = enumElement.getType();
    enumElement.setSupertype(typeProvider.getObjectType());
    //
    // Populate the fields.
    //
    ArrayList<FieldElement> fields = new ArrayList<FieldElement>();
    ArrayList<PropertyAccessorElement> getters = new ArrayList<PropertyAccessorElement>();
    InterfaceType intType = typeProvider.getIntType();

    String indexFieldName = "index";
    FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1);
    indexField.setFinal(true);
    indexField.setSynthetic(true);
    indexField.setType(intType);
    fields.add(indexField);
    getters.add(createGetter(indexField));

    FieldElementImpl valuesField = new FieldElementImpl("values", -1);
    valuesField.setStatic(true);
    valuesField.setConst(true);
    valuesField.setSynthetic(true);
    valuesField.setType(typeProvider.getListType().substitute(new Type[] {enumType}));
    fields.add(valuesField);
    getters.add(createGetter(valuesField));
    //
    // Build the enum constants.
    //
    NodeList<EnumConstantDeclaration> constants = node.getConstants();
    int constantCount = constants.size();
    for (int i = 0; i < constantCount; i++) {
      SimpleIdentifier constantName = constants.get(i).getName();
      FieldElementImpl constantField = new ConstFieldElementImpl(constantName);
      constantField.setStatic(true);
      constantField.setConst(true);
      constantField.setType(enumType);
      //
      // Create a value for the constant.
      //
      HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjectImpl>();
      fieldMap.put(indexFieldName, new DartObjectImpl(intType, new IntState(BigInteger.valueOf(i))));
      DartObjectImpl value = new DartObjectImpl(enumType, new GenericState(fieldMap));
      constantField.setEvaluationResult(new ValidResult(value));
      fields.add(constantField);
      getters.add(createGetter(constantField));
      constantName.setStaticElement(constantField);
    }
    //
    // Finish building the enum.
    //
    enumElement.setFields(fields.toArray(new FieldElement[fields.size()]));
    enumElement.setAccessors(getters.toArray(new PropertyAccessorElement[getters.size()]));
    // Client code isn't allowed to invoke the constructor, so we do not model it.
    return super.visitEnumDeclaration(node);
  }
View Full Code Here

      //
      // If this method invocation is of the form 'C.m' where 'C' is a class, then we don't call
      // resolveInvokedElement(..) which walks up the class hierarchy, instead we just look for the
      // member in the type only.
      //
      ClassElementImpl typeReference = getTypeReference(target);
      if (typeReference != null) {
        staticElement = propagatedElement = resolveElement(typeReference, methodName);
      } else {
        staticElement = resolveInvokedElementWithTarget(target, staticType, methodName);
        propagatedElement = resolveInvokedElementWithTarget(target, propagatedType, methodName);
View Full Code Here

    //
    // If this property access is of the form 'C.m' where 'C' is a class, then we don't call
    // resolveProperty(..) which walks up the class hierarchy, instead we just look for the
    // member in the type only.
    //
    ClassElementImpl typeReference = getTypeReference(target);
    if (typeReference != null) {
      // TODO(brianwilkerson) Why are we setting the propagated element here? It looks wrong.
      staticElement = propagatedElement = resolveElement(typeReference, propertyName);
    } else {
      staticElement = resolveProperty(target, staticType, propertyName);
View Full Code Here

    ImplementsClause implementsClause = node.getImplementsClause();

    hasReferenceToSuper = false;
    super.visitClassDeclaration(node);

    ClassElementImpl classElement = getClassElement(node.getName());
    InterfaceType superclassType = null;
    if (extendsClause != null) {
      ErrorCode errorCode = withClause == null ? CompileTimeErrorCode.EXTENDS_NON_CLASS
          : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
      superclassType = resolveType(
          extendsClause.getSuperclass(),
          errorCode,
          CompileTimeErrorCode.EXTENDS_ENUM,
          errorCode);
      if (superclassType != getTypeProvider().getObjectType()) {
        classElement.setValidMixin(false);
      }
    }
    if (classElement != null) {
      if (superclassType == null) {
        InterfaceType objectType = getTypeProvider().getObjectType();
        if (classElement.getType() != objectType) {
          superclassType = objectType;
        }
      }
      classElement.setSupertype(superclassType);
      classElement.setHasReferenceToSuper(hasReferenceToSuper);
    }
    resolve(classElement, withClause, implementsClause);
    return null;
  }
View Full Code Here

  }

  @Override
  public Void visitClassTypeAlias(ClassTypeAlias node) {
    super.visitClassTypeAlias(node);
    ClassElementImpl classElement = getClassElement(node.getName());
    ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
    InterfaceType superclassType = resolveType(
        node.getSuperclass(),
        errorCode,
        CompileTimeErrorCode.EXTENDS_ENUM,
        errorCode);
    if (superclassType == null) {
      superclassType = getTypeProvider().getObjectType();
    }
    if (classElement != null && superclassType != null) {
      classElement.setSupertype(superclassType);
      ClassElement superclassElement = superclassType.getElement();
      if (superclassElement != null) {
        ConstructorElement[] constructors = superclassElement.getConstructors();
        int count = constructors.length;
        if (count > 0) {
          Type[] parameterTypes = TypeParameterTypeImpl.getTypes(superclassType.getTypeParameters());
          Type[] argumentTypes = getArgumentTypes(
              node.getSuperclass().getTypeArguments(),
              parameterTypes);
          InterfaceType classType = classElement.getType();
          ArrayList<ConstructorElement> implicitConstructors = new ArrayList<ConstructorElement>(
              count);
          for (int i = 0; i < count; i++) {
            ConstructorElement explicitConstructor = constructors[i];
            if (!explicitConstructor.isFactory()) {
              implicitConstructors.add(createImplicitContructor(
                  classType,
                  explicitConstructor,
                  parameterTypes,
                  argumentTypes));
            }
          }
          classElement.setConstructors(implicitConstructors.toArray(new ConstructorElement[implicitConstructors.size()]));
        }
      }
    }
    resolve(classElement, node.getWithClause(), node.getImplementsClause());
    return null;
View Full Code Here

TOP

Related Classes of com.google.dart.engine.internal.element.ClassElementImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.