Package com.google.dart.engine.element

Examples of com.google.dart.engine.element.FieldElement


      }
      // create attribute
      PolymerAttributeElementImpl attribute = new PolymerAttributeElementImpl(name, offset);
      attributes.add(attribute);
      // resolve field
      FieldElement field = classElement.getField(name);
      if (field == null) {
        reportErrorForNameToken(
            nameToken,
            PolymerCode.UNDEFINED_ATTRIBUTE_FIELD,
            name,
View Full Code Here


      FormalParameter parameter = formalParameter;
      if (parameter instanceof DefaultFormalParameter) {
        parameter = ((DefaultFormalParameter) parameter).getParameter();
      }
      if (parameter instanceof FieldFormalParameter) {
        FieldElement fieldElement = ((FieldFormalParameterElementImpl) parameter.getElement()).getField();
        INIT_STATE state = fieldElementsMap.get(fieldElement);
        if (state == INIT_STATE.NOT_INIT) {
          fieldElementsMap.put(fieldElement, INIT_STATE.INIT_IN_FIELD_FORMAL);
        } else if (state == INIT_STATE.INIT_IN_DECLARATION) {
          if (fieldElement.isFinal() || fieldElement.isConst()) {
            errorReporter.reportErrorForNode(
                StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR,
                formalParameter.getIdentifier(),
                fieldElement.getDisplayName());
            foundError = true;
          }
        } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
          if (fieldElement.isFinal() || fieldElement.isConst()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES,
                formalParameter.getIdentifier(),
                fieldElement.getDisplayName());
            foundError = true;
          }
        }
      }
    }

    // Visit all of the initializers
    NodeList<ConstructorInitializer> initializers = node.getInitializers();
    for (ConstructorInitializer constructorInitializer : initializers) {
      if (constructorInitializer instanceof RedirectingConstructorInvocation) {
        return false;
      }
      if (constructorInitializer instanceof ConstructorFieldInitializer) {
        ConstructorFieldInitializer constructorFieldInitializer = (ConstructorFieldInitializer) constructorInitializer;
        SimpleIdentifier fieldName = constructorFieldInitializer.getFieldName();
        Element element = fieldName.getStaticElement();
        if (element instanceof FieldElement) {
          FieldElement fieldElement = (FieldElement) element;
          INIT_STATE state = fieldElementsMap.get(fieldElement);
          if (state == INIT_STATE.NOT_INIT) {
            fieldElementsMap.put(fieldElement, INIT_STATE.INIT_IN_INITIALIZERS);
          } else if (state == INIT_STATE.INIT_IN_DECLARATION) {
            if (fieldElement.isFinal() || fieldElement.isConst()) {
              errorReporter.reportErrorForNode(
                  StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION,
                  fieldName);
              foundError = true;
            }
          } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER,
                fieldName);
            foundError = true;
          } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
                fieldName,
                fieldElement.getDisplayName());
            foundError = true;
          }
        }
      }
    }

    // Visit all of the states in the map to ensure that none were never initialized.
    for (Entry<FieldElement, INIT_STATE> entry : fieldElementsMap.entrySet()) {
      if (entry.getValue() == INIT_STATE.NOT_INIT) {
        FieldElement fieldElement = entry.getKey();
        if (fieldElement.isConst()) {
          errorReporter.reportErrorForNode(
              CompileTimeErrorCode.CONST_NOT_INITIALIZED,
              node.getReturnType(),
              fieldElement.getName());
          foundError = true;
        } else if (fieldElement.isFinal()) {
          errorReporter.reportErrorForNode(
              StaticWarningCode.FINAL_NOT_INITIALIZED,
              node.getReturnType(),
              fieldElement.getName());
          foundError = true;
        }
      }
    }
    return foundError;
View Full Code Here

      return false;
    }
    boolean hasProblems = false;
    VariableDeclarationList fields = node.getFields();
    for (VariableDeclaration field : fields.getVariables()) {
      FieldElement element = (FieldElement) field.getElement();
      if (element == null) {
        continue;
      }
      PropertyAccessorElement getter = element.getGetter();
      PropertyAccessorElement setter = element.getSetter();
      SimpleIdentifier fieldName = field.getName();
      if (getter != null) {
        hasProblems |= checkForAllInvalidOverrideErrorCodesForExecutable(
            getter,
            ParameterElementImpl.EMPTY_ARRAY,
View Full Code Here

      }
    }
    // conflict with class member
    if (constructorName != null && constructorElement != null && !constructorName.isSynthetic()) {
      // fields
      FieldElement field = classElement.getField(name);
      if (field != null) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD,
            node,
            name);
View Full Code Here

      Element staticElement) {
    // prepare field element
    if (!(staticElement instanceof FieldElement)) {
      return false;
    }
    FieldElement fieldElement = (FieldElement) staticElement;
    // prepare field type
    Type fieldType = fieldElement.getType();
    // prepare expression type
    Expression expression = node.getExpression();
    if (expression == null) {
      return false;
    }
View Full Code Here

   *          {@link ConstructorFieldInitializer}
   */
  private void checkForInvalidField(ConstructorFieldInitializer node, SimpleIdentifier fieldName,
      Element staticElement) {
    if (staticElement instanceof FieldElement) {
      FieldElement fieldElement = (FieldElement) staticElement;
      if (fieldElement.isSynthetic()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_FIELD,
            node,
            fieldName);
      } else if (fieldElement.isStatic()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD,
            node,
            fieldName);
      }
View Full Code Here

    }
    ArrayList<String> constantNames = new ArrayList<String>();
    FieldElement[] fields = classElement.getFields();
    int fieldCount = fields.length;
    for (int i = 0; i < fieldCount; i++) {
      FieldElement field = fields[i];
      if (field.isStatic() && !field.isSynthetic()) {
        constantNames.add(field.getName());
      }
    }
    NodeList<SwitchMember> members = statement.getMembers();
    int memberCount = members.size();
    for (int i = 0; i < memberCount; i++) {
View Full Code Here

  }

  private void checkForValidField(FieldFormalParameter node) {
    ParameterElement element = node.getElement();
    if (element instanceof FieldFormalParameterElement) {
      FieldElement fieldElement = ((FieldFormalParameterElement) element).getField();
      if (fieldElement == null || fieldElement.isSynthetic()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTANT_FIELD,
            node,
            node.getIdentifier().getName());
      } else {
        ParameterElement parameterElement = node.getElement();
        if (parameterElement instanceof FieldFormalParameterElementImpl) {
          FieldFormalParameterElementImpl fieldFormal = (FieldFormalParameterElementImpl) parameterElement;
          Type declaredType = fieldFormal.getType();
          Type fieldType = fieldElement.getType();
          if (fieldElement.isSynthetic()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTANT_FIELD,
                node,
                node.getIdentifier().getName());
          } else if (fieldElement.isStatic()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD,
                node,
                node.getIdentifier().getName());
          } else if (declaredType != null && fieldType != null
              && !declaredType.isAssignableTo(fieldType)) {
            errorReporter.reportTypeErrorForNode(
                StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE,
                node,
                declaredType,
                fieldType);
          }
        } else {
          if (fieldElement.isSynthetic()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTANT_FIELD,
                node,
                node.getIdentifier().getName());
          } else if (fieldElement.isStatic()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD,
                node,
                node.getIdentifier().getName());
          }
View Full Code Here

  public Void visitEnumDeclaration(EnumDeclaration node) {
    ClassElement enclosingEnum = findIdentifier(enclosingUnit.getEnums(), node.getName());
    processElement(enclosingEnum);
    FieldElement[] constants = enclosingEnum.getFields();
    for (EnumConstantDeclaration constant : node.getConstants()) {
      FieldElement constantElement = findIdentifier(constants, constant.getName());
      processElement(constantElement);
    }
    return super.visitEnumDeclaration(node);
  }
View Full Code Here

  @Override
  public Void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
    SimpleIdentifier fieldName = node.getFieldName();
    ClassElement enclosingClass = resolver.getEnclosingClass();
    FieldElement fieldElement = enclosingClass.getField(fieldName.getName());
    fieldName.setStaticElement(fieldElement);
    return null;
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.element.FieldElement

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.