Package com.google.dart.engine.type

Examples of com.google.dart.engine.type.InterfaceType


      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;
    }
View Full Code Here


   *         are no classes above this one in the class hierarchy. Otherwise, a list of interface
   *         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);

View Full Code Here

      return null;
    }
    // look up ConstructorElement
    ConstructorElement constructor;
    SimpleIdentifier name = node.getName();
    InterfaceType interfaceType = (InterfaceType) type;
    if (name == null) {
      constructor = interfaceType.lookUpConstructor(null, definingLibrary);
    } else {
      constructor = interfaceType.lookUpConstructor(name.getName(), definingLibrary);
      name.setStaticElement(constructor);
    }
    node.setStaticElement(constructor);
    return null;
  }
View Full Code Here

      }
    }

    node.setStaticElement(element);
    if (node.inSetterContext() && node.inGetterContext() && enclosingClass != null) {
      InterfaceType enclosingType = enclosingClass.getType();
      AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(
          null,
          enclosingType,
          node.getName()), null);
      node.setAuxiliaryElements(auxiliaryElements);
View Full Code Here

    ClassElement enclosingClass = resolver.getEnclosingClass();
    if (enclosingClass == null) {
      // TODO(brianwilkerson) Report this error.
      return null;
    }
    InterfaceType superType = enclosingClass.getSupertype();
    if (superType == null) {
      // TODO(brianwilkerson) Report this error.
      return null;
    }
    SimpleIdentifier name = node.getConstructorName();
    String superName = name != null ? name.getName() : null;
    ConstructorElement element = superType.lookUpConstructor(superName, definingLibrary);
    if (element == null) {
      if (name != null) {
        resolver.reportErrorForNode(
            CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER,
            node,
            superType.getDisplayName(),
            name);
      } else {
        resolver.reportErrorForNode(
            CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT,
            node,
            superType.getDisplayName());
      }
      return null;
    } else {
      if (element.isFactory()) {
        resolver.reportErrorForNode(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, element);
View Full Code Here

   * @return the element representing the getter that was found
   */
  private PropertyAccessorElement lookUpGetter(Expression target, Type type, String getterName) {
    type = resolveTypeParameter(type);
    if (type instanceof InterfaceType) {
      InterfaceType interfaceType = (InterfaceType) type;
      PropertyAccessorElement accessor;
      if (target instanceof SuperExpression) {
        accessor = interfaceType.lookUpGetterInSuperclass(getterName, definingLibrary);
      } else {
        accessor = interfaceType.lookUpGetter(getterName, definingLibrary);
      }
      if (accessor != null) {
        return accessor;
      }
      return lookUpGetterInInterfaces(interfaceType, false, getterName, new HashSet<ClassElement>());
View Full Code Here

   * @return the type of objects that will be assigned to the loop variable
   */
  private Type getIteratorElementType(Expression iteratorExpression) {
    Type expressionType = iteratorExpression.getBestType();
    if (expressionType instanceof InterfaceType) {
      InterfaceType interfaceType = (InterfaceType) expressionType;
      FunctionType iteratorFunction = inheritanceManager.lookupMemberType(interfaceType, "iterator");
      if (iteratorFunction == null) {
        // TODO(brianwilkerson) Should we report this error?
        return null;
      }
      Type iteratorType = iteratorFunction.getReturnType();
      if (iteratorType instanceof InterfaceType) {
        InterfaceType iteratorInterfaceType = (InterfaceType) iteratorType;
        FunctionType currentFunction = inheritanceManager.lookupMemberType(
            iteratorInterfaceType,
            "current");
        if (currentFunction == null) {
          // TODO(brianwilkerson) Should we report this error?
View Full Code Here

   * all of its supertypes to the {@link #subtypeMap} map.
   *
   * @param classElement the class element
   */
  private void computeSubtypesInClass(ClassElement classElement) {
    InterfaceType supertypeType = classElement.getSupertype();
    if (supertypeType != null) {
      ClassElement supertypeElement = supertypeType.getElement();
      if (supertypeElement != null) {
        putInSubtypeMap(supertypeElement, classElement);
      }
    }
    InterfaceType[] interfaceTypes = classElement.getInterfaces();
View Full Code Here

                // prepare the type of the returned Future
                InterfaceTypeImpl newFutureType;
                if (isAsyncFutureType(returnType)) {
                  newFutureType = (InterfaceTypeImpl) returnType;
                } else {
                  InterfaceType futureType = (InterfaceType) targetType;
                  newFutureType = new InterfaceTypeImpl(futureType.getElement());
                  newFutureType.setTypeArguments(new Type[] {returnType});
                }
                // set the 'then' invocation type
                recordPropagatedType(node, newFutureType);
                needPropagatedType = false;
View Full Code Here

    }
    Type returnType = functionType.getReturnType();
    if (returnType instanceof TypeParameterType && context instanceof InterfaceType) {
      // if the return type is a TypeParameter, we try to use the context [that the function is being
      // called on] to get a more accurate returnType type
      InterfaceType interfaceTypeContext = ((InterfaceType) context);
//      Type[] argumentTypes = interfaceTypeContext.getTypeArguments();
      TypeParameterElement[] typeParameterElements = interfaceTypeContext.getElement() != null
          ? interfaceTypeContext.getElement().getTypeParameters() : null;
      if (typeParameterElements != null) {
        for (int i = 0; i < typeParameterElements.length; i++) {
          TypeParameterElement typeParameterElement = typeParameterElements[i];
          if (returnType.getName().equals(typeParameterElement.getName())) {
            return interfaceTypeContext.getTypeArguments()[i];
          }
        }
        // TODO(jwren) troubleshoot why call to substitute doesn't work
//        Type[] parameterTypes = TypeParameterTypeImpl.getTypes(parameterElements);
//        return returnType.substitute(argumentTypes, parameterTypes);
View Full Code Here

TOP

Related Classes of com.google.dart.engine.type.InterfaceType

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.