Package com.google.dart.engine.element

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


    }
    Element expressionElement = expressionType.getElement();
    if (!(expressionElement instanceof ClassElement)) {
      return false;
    }
    ClassElement classElement = (ClassElement) expressionElement;
    if (!classElement.isEnum()) {
      return false;
    }
    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());
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;
      }
    }
    // prepare class name
View Full Code Here

    // prepare super
    InterfaceType superType = enclosingClass.getSupertype();
    if (superType == null) {
      return false;
    }
    ClassElement superElement = superType.getElement();
    // try to find default generative super constructor
    ConstructorElement superUnnamedConstructor = superElement.getUnnamedConstructor();
    if (superUnnamedConstructor != null) {
      if (superUnnamedConstructor.isFactory()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
            node.getName(),
View Full Code Here

    // prepare ClassElement
    Element element = type.getElement();
    if (!(element instanceof ClassElement)) {
      return false;
    }
    ClassElement classElement = (ClassElement) element;
    // prepare type parameters
    Type[] typeParameters = classElement.getType().getTypeArguments();
    TypeParameterElement[] boundingElts = classElement.getTypeParameters();
    // iterate over each bounded type parameter and corresponding argument
    NodeList<TypeName> typeNameArgList = node.getTypeArguments().getArguments();
    Type[] typeArguments = ((InterfaceType) type).getTypeArguments();
    int loopThroughIndex = Math.min(typeNameArgList.size(), boundingElts.length);
    boolean foundError = false;
View Full Code Here

    }
    InterfaceType superType = enclosingClass.getSupertype();
    if (superType == null) {
      return false;
    }
    ClassElement superElement = superType.getElement();
    ConstructorElement superUnnamedConstructor = superElement.getUnnamedConstructor();
    if (superUnnamedConstructor != null) {
      if (superUnnamedConstructor.isFactory()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
            node.getReturnType(),
            superUnnamedConstructor);
        return true;
      }
      if (!superUnnamedConstructor.isDefaultConstructor()) {
        int offset;
        int length;
        {
          Identifier returnType = node.getReturnType();
          SimpleIdentifier name = node.getName();
          offset = returnType.getOffset();
          length = (name != null ? name.getEnd() : returnType.getEnd()) - offset;
        }
        errorReporter.reportErrorForOffset(
            CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT,
            offset,
            length,
            superType.getDisplayName());
      }
      return false;
    }
    errorReporter.reportErrorForNode(
        CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT,
        node.getReturnType(),
        superElement.getName());
    return true;
  }
View Full Code Here

    if (resultMap != null) {
      return resultMap;
    } else {
      resultMap = new MemberMap();
    }
    ClassElement superclassElt = null;
    InterfaceType supertype = classElt.getSupertype();
    if (supertype != null) {
      superclassElt = supertype.getElement();
    } else {
      // classElt is Object
      classLookup.put(classElt, resultMap);
      return resultMap;
    }
    if (superclassElt != null) {
      if (!visitedClasses.contains(superclassElt)) {
        visitedClasses.add(superclassElt);
        try {
          resultMap = new MemberMap(computeClassChainLookupMap(superclassElt, visitedClasses));

          //
          // Substitute the super types down the hierarchy.
          //
          substituteTypeParametersDownHierarchy(supertype, resultMap);

          //
          // Include the members from the superclass in the resultMap.
          //
          recordMapWithClassMembers(resultMap, supertype, false);
        } finally {
          visitedClasses.remove(superclassElt);
        }
      } else {
        // This case happens only when the superclass was previously visited and not in the lookup,
        // meaning this is meant to shorten the compute for recursive cases.
        classLookup.put(superclassElt, resultMap);
        return resultMap;
      }
    }

    //
    // Include the members from the mixins in the resultMap
    //
    InterfaceType[] mixins = classElt.getMixins();
    for (int i = mixins.length - 1; i >= 0; i--) {
      ClassElement mixinElement = mixins[i].getElement();

      if (mixinElement != null) {
        if (!visitedClasses.contains(mixinElement)) {
          visitedClasses.add(mixinElement);
          try {
View Full Code Here

  private void computeInheritancePath(LinkedList<InterfaceType> chain, InterfaceType currentType,
      String memberName) {
    // TODO (jwren) create a public version of this method which doesn't require the initial chain
    // to be provided, then provided tests for this functionality in InheritanceManagerTest
    chain.add(currentType);
    ClassElement classElt = currentType.getElement();
    InterfaceType supertype = classElt.getSupertype();
    // Base case- reached Object
    if (supertype == null) {
      // Looked up the chain all the way to Object, return null.
      // This should never happen.
      return;
    }

    // If we are done, return the chain
    // We are not done if this is the first recursive call on this method.
    if (chain.size() != 1) {
      // We are done however if the member is in this classElt
      if (lookupMemberInClass(classElt, memberName) != null) {
        return;
      }
    }

    // Otherwise, determine the next type (up the inheritance graph) to search for our member, start
    // with the mixins, followed by the superclass, and finally the interfaces:

    // Mixins- note that mixins call lookupMemberInClass, not lookupMember
    InterfaceType[] mixins = classElt.getMixins();
    for (int i = mixins.length - 1; i >= 0; i--) {
      ClassElement mixinElement = mixins[i].getElement();
      if (mixinElement != null) {
        ExecutableElement elt = lookupMemberInClass(mixinElement, memberName);
        if (elt != null) {
          // this is equivalent (but faster than) calling this method recursively
          // (return computeInheritancePath(chain, mixins[i], memberName);)
          chain.add(mixins[i]);
          return;
        }
      }
    }

    // Superclass
    ClassElement superclassElt = supertype.getElement();
    if (lookupMember(superclassElt, memberName) != null) {
      computeInheritancePath(chain, supertype, memberName);
      return;
    }

    // Interfaces
    InterfaceType[] interfaces = classElt.getInterfaces();
    for (InterfaceType interfaceType : interfaces) {
      ClassElement interfaceElement = interfaceType.getElement();
      if (interfaceElement != null && lookupMember(interfaceElement, memberName) != null) {
        computeInheritancePath(chain, interfaceType, memberName);
        return;
      }
    }
View Full Code Here

   *         lookup maps.
   */
  private ArrayList<MemberMap> gatherInterfaceLookupMaps(ClassElement classElt,
      HashSet<ClassElement> visitedInterfaces) {
    InterfaceType supertype = classElt.getSupertype();
    ClassElement superclassElement = supertype != null ? supertype.getElement() : null;
    InterfaceType[] mixins = classElt.getMixins();
    InterfaceType[] interfaces = classElt.getInterfaces();

    // Recursively collect the list of mappings from all of the interface types
    ArrayList<MemberMap> lookupMaps = new ArrayList<MemberMap>(interfaces.length + mixins.length
        + 1);

    //
    // Superclass element
    //
    if (superclassElement != null) {
      if (!visitedInterfaces.contains(superclassElement)) {
        try {
          visitedInterfaces.add(superclassElement);

          //
          // Recursively compute the map for the super type.
          //
          MemberMap map = computeInterfaceLookupMap(superclassElement, visitedInterfaces);
          map = new MemberMap(map);

          //
          // Substitute the super type down the hierarchy.
          //
          substituteTypeParametersDownHierarchy(supertype, map);

          //
          // Add any members from the super type into the map as well.
          //
          recordMapWithClassMembers(map, supertype, true);

          lookupMaps.add(map);
        } finally {
          visitedInterfaces.remove(superclassElement);
        }
      } else {
        return null;
      }
    }

    //
    // Mixin elements
    //
    for (int i = mixins.length - 1; i >= 0; i--) {
      InterfaceType mixinType = mixins[i];
      ClassElement mixinElement = mixinType.getElement();
      if (mixinElement != null) {
        if (!visitedInterfaces.contains(mixinElement)) {
          try {
            visitedInterfaces.add(mixinElement);

            //
            // Recursively compute the map for the mixin.
            //
            MemberMap map = computeInterfaceLookupMap(mixinElement, visitedInterfaces);
            map = new MemberMap(map);

            //
            // Substitute the mixin type down the hierarchy.
            //
            substituteTypeParametersDownHierarchy(mixinType, map);

            //
            // Add any members from the mixin type into the map as well.
            //
            recordMapWithClassMembers(map, mixinType, true);

            lookupMaps.add(map);
          } finally {
            visitedInterfaces.remove(mixinElement);
          }
        } else {
          return null;
        }
      }
    }

    //
    // Interface elements
    //
    for (InterfaceType interfaceType : interfaces) {
      ClassElement interfaceElement = interfaceType.getElement();
      if (interfaceElement != null) {
        if (!visitedInterfaces.contains(interfaceElement)) {
          try {
            visitedInterfaces.add(interfaceElement);

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

        }
      }

      errorCode = checkForInvocationError(target, false, propagatedElement);
      if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) {
        ClassElement classElementContext = null;
        if (target == null) {
          classElementContext = resolver.getEnclosingClass();
        } else {
          Type type = target.getBestType();
          if (type != null) {
            if (type.getElement() instanceof ClassElement) {
              classElementContext = (ClassElement) type.getElement();
            }
          }
        }
        if (classElementContext != null) {
          subtypeManager.ensureLibraryVisited(definingLibrary);
          HashSet<ClassElement> subtypeElements = subtypeManager.computeAllSubtypes(classElementContext);
          for (ClassElement subtypeElement : subtypeElements) {
            if (subtypeElement.getMethod(methodName.getName()) != null) {
              errorCode = null;
            }
          }
        }
      }
      generatedWithTypePropagation = true;
    }
    if (errorCode == null) {
      return null;
    }
    if (errorCode == StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) {
      resolver.reportErrorForNode(
          StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION,
          methodName,
          methodName.getName());
    } else if (errorCode == StaticTypeWarningCode.UNDEFINED_FUNCTION) {
      resolver.reportErrorForNode(
          StaticTypeWarningCode.UNDEFINED_FUNCTION,
          methodName,
          methodName.getName());
    } else if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) {
      String targetTypeName;
      if (target == null) {
        ClassElement enclosingClass = resolver.getEnclosingClass();
        targetTypeName = enclosingClass.getDisplayName();
        ErrorCode proxyErrorCode = generatedWithTypePropagation ? HintCode.UNDEFINED_METHOD
            : StaticTypeWarningCode.UNDEFINED_METHOD;
        if (doesntHaveProxy(resolver.getEnclosingClass())) {
          resolver.reportErrorForNode(
              proxyErrorCode,
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.