Package com.google.dart.engine.element

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


      if (checkForExtendsOrImplementsDisallowedClass(
          mixinName,
          CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS)) {
        problemReported = true;
      } else {
        ClassElement mixinElement = ((InterfaceType) mixinType).getElement();
        problemReported |= checkForExtendsOrImplementsDeferredClass(
            mixinName,
            CompileTimeErrorCode.MIXIN_DEFERRED_CLASS);
        problemReported |= checkForMixinDeclaresConstructor(mixinName, mixinElement);
        problemReported |= checkForMixinInheritsNotFromObject(mixinName, mixinElement);
View Full Code Here


   */
  private boolean checkForConflictingConstructorNameAndMember(ConstructorDeclaration node,
      ConstructorElement constructorElement) {
    SimpleIdentifier constructorName = node.getName();
    String name = constructorElement.getName();
    ClassElement classElement = constructorElement.getEnclosingElement();
    // constructors
    ConstructorElement[] constructors = classElement.getConstructors();
    for (ConstructorElement otherConstructor : constructors) {
      if (otherConstructor == constructorElement) {
        continue;
      }
      if (ObjectUtilities.equals(name, otherConstructor.getName())) {
        if (name == null || name.length() == 0) {
          errorReporter.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, node);
        } else {
          errorReporter.reportErrorForNode(
              CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME,
              node,
              name);
        }
        return true;
      }
    }
    // 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);
        return true;
      }
      // methods
      MethodElement method = classElement.getMethod(name);
      if (method != null) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD,
            node,
            name);
View Full Code Here

      // OK, not static
      if (!superElement.isStatic()) {
        continue;
      }
      // prepare "super" type to report its name
      ClassElement superElementClass = (ClassElement) superElement.getEnclosingElement();
      InterfaceType superElementType = superElementClass.getType();
      // report problem
      hasProblem = true;
      if (getter) {
        errorReporter.reportErrorForElement(
            StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER,
View Full Code Here

    // OK, also static
    if (setter.isStatic()) {
      return false;
    }
    // prepare "setter" type to report its name
    ClassElement setterClass = (ClassElement) setter.getEnclosingElement();
    InterfaceType setterType = setterClass.getType();
    // report problem
    errorReporter.reportErrorForNode(
        StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER,
        nameNode,
        setterType.getDisplayName());
View Full Code Here

    // OK, also static
    if (member.isStatic()) {
      return false;
    }
    // prepare "member" type to report its name
    ClassElement memberClass = (ClassElement) member.getEnclosingElement();
    InterfaceType memberType = memberClass.getType();
    // report problem
    errorReporter.reportErrorForNode(
        StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER,
        nameNode,
        memberType.getDisplayName());
View Full Code Here

      ConstructorElement constructorElement) {
    if (!isEnclosingConstructorConst) {
      return false;
    }
    // check if there is non-final field
    ClassElement classElement = constructorElement.getEnclosingElement();
    if (!classElement.hasNonFinalField()) {
      return false;
    }
    // report problem
    errorReporter.reportErrorForNode(
        CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD,
View Full Code Here

    if (node.getStaticElement() != null) {
      return false;
    }
    Type type = typeName.getType();
    if (type instanceof InterfaceType) {
      ClassElement element = ((InterfaceType) type).getElement();
      if (element != null && element.isEnum()) {
        // We have already reported the error.
        return false;
      }
    }
    Identifier className = typeName.getName();
View Full Code Here

          // Note: this is a corner case that won't happen often, so adding a field currentClass
          // (see currentFunction) to ErrorVerifier isn't worth if for this case, but if the field
          // currentClass is added, then this message should become a todo to not lookup the
          // grandparent node
          if (grandParent instanceof ClassDeclaration) {
            ClassElement classElement = ((ClassDeclaration) grandParent).getElement();
            Type classType = classElement.getType();
            if (classType != null
                && (classType.equals(intType) || classType.equals(typeProvider.getDoubleType()))) {
              return false;
            }
          }
View Full Code Here

      ExecutableElement executableElement, SimpleIdentifier errorNameTarget) {
    String executableElementName = executableElement.getName();
    if (!(executableElement instanceof PropertyAccessorElement) && !executableElement.isOperator()) {
      HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>();
      InterfaceType superclassType = enclosingClass.getSupertype();
      ClassElement superclassElement = superclassType == null ? null : superclassType.getElement();
      boolean executableElementPrivate = Identifier.isPrivateName(executableElementName);
      while (superclassElement != null && !visitedClasses.contains(superclassElement)) {
        visitedClasses.add(superclassElement);
        LibraryElement superclassLibrary = superclassElement.getLibrary();
        // Check fields.
        FieldElement[] fieldElts = superclassElement.getFields();
        for (FieldElement fieldElt : fieldElts) {
          // We need the same name.
          if (!fieldElt.getName().equals(executableElementName)) {
            continue;
          }
          // Ignore if private in a different library - cannot collide.
          if (executableElementPrivate && !currentLibrary.equals(superclassLibrary)) {
            continue;
          }
          // instance vs. static
          if (fieldElt.isStatic()) {
            errorReporter.reportErrorForNode(
                StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC,
                errorNameTarget,
                executableElementName,
                fieldElt.getEnclosingElement().getDisplayName());
            return true;
          }
        }
        // Check methods.
        MethodElement[] methodElements = superclassElement.getMethods();
        for (MethodElement methodElement : methodElements) {
          // We need the same name.
          if (!methodElement.getName().equals(executableElementName)) {
            continue;
          }
          // Ignore if private in a different library - cannot collide.
          if (executableElementPrivate && !currentLibrary.equals(superclassLibrary)) {
            continue;
          }
          // instance vs. static
          if (methodElement.isStatic()) {
            errorReporter.reportErrorForNode(
                StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC,
                errorNameTarget,
                executableElementName,
                methodElement.getEnclosingElement().getDisplayName());
            return true;
          }
        }
        superclassType = superclassElement.getSupertype();
        superclassElement = superclassType == null ? null : superclassType.getElement();
      }
    }
    return false;
  }
View Full Code Here

    if (!(accessorElement instanceof PropertyAccessorElement)) {
      return false;
    }
    PropertyAccessorElement propertyAccessorElement = (PropertyAccessorElement) accessorElement;
    PropertyAccessorElement counterpartAccessor = null;
    ClassElement enclosingClassForCounterpart = null;
    if (propertyAccessorElement.isGetter()) {
      counterpartAccessor = propertyAccessorElement.getCorrespondingSetter();
    } else {
      counterpartAccessor = propertyAccessorElement.getCorrespondingGetter();
      // If the setter and getter are in the same enclosing element, return, this prevents having
      // MISMATCHED_GETTER_AND_SETTER_TYPES reported twice.
      if (counterpartAccessor != null
          && counterpartAccessor.getEnclosingElement() == propertyAccessorElement.getEnclosingElement()) {
        return false;
      }
    }
    if (counterpartAccessor == null) {
      // If the accessor is declared in a class, check the superclasses.
      if (enclosingClass != null) {
        // Figure out the correct identifier to lookup in the inheritance graph, if 'x', then 'x=',
        // or if 'x=', then 'x'.
        String lookupIdentifier = propertyAccessorElement.getName();
        if (StringUtilities.endsWithChar(lookupIdentifier, '=')) {
          lookupIdentifier = lookupIdentifier.substring(0, lookupIdentifier.length() - 1);
        } else {
          lookupIdentifier += "=";
        }
        // lookup with the identifier.
        ExecutableElement elementFromInheritance = inheritanceManager.lookupInheritance(
            enclosingClass,
            lookupIdentifier);
        // Verify that we found something, and that it is an accessor
        if (elementFromInheritance != null
            && elementFromInheritance instanceof PropertyAccessorElement) {
          enclosingClassForCounterpart = (ClassElement) elementFromInheritance.getEnclosingElement();
          counterpartAccessor = (PropertyAccessorElement) elementFromInheritance;
        }
      }
      if (counterpartAccessor == null) {
        return false;
      }
    }

    // Default of null == no accessor or no type (dynamic)
    Type getterType = null;
    Type setterType = null;

    // Get an existing counterpart accessor if any.
    if (propertyAccessorElement.isGetter()) {
      getterType = getGetterType(propertyAccessorElement);
      setterType = getSetterType(counterpartAccessor);
    } else if (propertyAccessorElement.isSetter()) {
      setterType = getSetterType(propertyAccessorElement);
      getterType = getGetterType(counterpartAccessor);
    }

    // If either types are not assignable to each other, report an error (if the getter is null,
    // it is dynamic which is assignable to everything).
    if (setterType != null && getterType != null && !getterType.isAssignableTo(setterType)) {
      if (enclosingClassForCounterpart == null) {
        errorReporter.reportTypeErrorForNode(
            StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES,
            accessorDeclaration,
            accessorTextName,
            setterType,
            getterType);
        return true;
      } else {
        errorReporter.reportTypeErrorForNode(
            StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE,
            accessorDeclaration,
            accessorTextName,
            setterType,
            getterType,
            enclosingClassForCounterpart.getDisplayName());
      }
    }
    return false;
  }
View Full Code Here

TOP

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

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.