Package com.google.dart.engine.type

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


   */
  private static boolean isChangedByTypeSubstitution(PropertyAccessorElement baseAccessor,
      InterfaceType definingType) {
    Type[] argumentTypes = definingType.getTypeArguments();
    if (baseAccessor != null && argumentTypes.length != 0) {
      FunctionType baseType = baseAccessor.getType();
      Type[] parameterTypes = definingType.getElement().getType().getTypeArguments();
      FunctionType substitutedType = baseType.substitute(argumentTypes, parameterTypes);
      if (!baseType.equals(substitutedType)) {
        return true;
      }
      // If this property accessor is based on a field, that field might have a propagated type.
      // In which case we need to check whether the propagated type of the field needs substitution.
View Full Code Here


  @Override
  public String toString() {
    PropertyAccessorElement baseElement = getBaseElement();
    ParameterElement[] parameters = getParameters();
    FunctionType type = getType();
    StringBuilder builder = new StringBuilder();
    if (isGetter()) {
      builder.append("get ");
    } else {
      builder.append("set ");
    }
    builder.append(baseElement.getEnclosingElement().getDisplayName());
    builder.append(".");
    builder.append(baseElement.getDisplayName());
    builder.append("(");
    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      if (i > 0) {
        builder.append(", ");
      }
      builder.append(parameters[i]).toString();
    }
    builder.append(")");
    if (type != null) {
      builder.append(Element.RIGHT_ARROW);
      builder.append(type.getReturnType());
    }
    return builder.toString();
  }
View Full Code Here

  public static ConstructorElement from(ConstructorElement baseConstructor,
      InterfaceType definingType) {
    if (baseConstructor == null || definingType.getTypeArguments().length == 0) {
      return baseConstructor;
    }
    FunctionType baseType = baseConstructor.getType();
    if (baseType == null) {
      // TODO(brianwilkerson) We need to understand when this can happen.
      return baseConstructor;
    }
    Type[] argumentTypes = definingType.getTypeArguments();
    Type[] parameterTypes = definingType.getElement().getType().getTypeArguments();
    FunctionType substitutedType = baseType.substitute(argumentTypes, parameterTypes);
    if (baseType.equals(substitutedType)) {
      return baseConstructor;
    }
    // TODO(brianwilkerson) Consider caching the substituted type in the instance. It would use more
    // memory but speed up some operations. We need to see how often the type is being re-computed.
View Full Code Here

  @Override
  public String toString() {
    ConstructorElement baseElement = getBaseElement();
    ParameterElement[] parameters = getParameters();
    FunctionType type = getType();
    StringBuilder builder = new StringBuilder();
    builder.append(baseElement.getEnclosingElement().getDisplayName());
    String name = getDisplayName();
    if (name != null && !name.isEmpty()) {
      builder.append(".");
      builder.append(name);
    }
    builder.append("(");
    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      if (i > 0) {
        builder.append(", ");
      }
      builder.append(parameters[i]).toString();
    }
    builder.append(")");
    if (type != null) {
      builder.append(Element.RIGHT_ARROW);
      builder.append(type.getReturnType());
    }
    return builder.toString();
  }
View Full Code Here

   */
  public static MethodElement from(MethodElement baseMethod, InterfaceType definingType) {
    if (baseMethod == null || definingType.getTypeArguments().length == 0) {
      return baseMethod;
    }
    FunctionType baseType = baseMethod.getType();
    Type[] argumentTypes = definingType.getTypeArguments();
    Type[] parameterTypes = definingType.getElement().getType().getTypeArguments();
    FunctionType substitutedType = baseType.substitute(argumentTypes, parameterTypes);
    if (baseType.equals(substitutedType)) {
      return baseMethod;
    }
    // TODO(brianwilkerson) Consider caching the substituted type in the instance. It would use more
    // memory but speed up some operations. We need to see how often the type is being re-computed.
View Full Code Here

  @Override
  public String toString() {
    MethodElement baseElement = getBaseElement();
    ParameterElement[] parameters = getParameters();
    FunctionType type = getType();
    StringBuilder builder = new StringBuilder();
    builder.append(baseElement.getEnclosingElement().getDisplayName());
    builder.append(".");
    builder.append(baseElement.getDisplayName());
    builder.append("(");
    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      if (i > 0) {
        builder.append(", ");
      }
      builder.append(parameters[i]).toString();
    }
    builder.append(")");
    if (type != null) {
      builder.append(Element.RIGHT_ARROW);
      builder.append(type.getReturnType());
    }
    return builder.toString();
  }
View Full Code Here

      // doesn't correspond to a "raw"-in-the-Java-sense occurrence of T, which would instead
      // be T<dynamic, dynamic>; on the other hand, it's treated differently by <: and << when
      // occurring on the left hand side.
      ClassElement element = getElement();
      InheritanceManager manager = new InheritanceManager(element.getLibrary());
      FunctionType callType = manager.lookupMemberType(this, "call");
      if (callType != null) {
        // A more literal reading of the spec would give something like
        //
        //  return callType.equals(type)
        //
        // here, but that causes 101 errors in the external tests
        // (tools/test.py --mode release --compiler dartanalyzer --runtime none).
        return callType.isSubtypeOf(type);
      }
      return false;
    } else if (!(type instanceof InterfaceType)) {
      return false;
    } else if (this.equals(type)) {
View Full Code Here

    } else if (!(type instanceof FunctionType)) {
      return false;
    } else if (this.equals(type)) {
      return true;
    }
    FunctionType t = this;
    FunctionType s = (FunctionType) type;

    Type[] tTypes = t.getNormalParameterTypes();
    Type[] tOpTypes = t.getOptionalParameterTypes();
    Type[] sTypes = s.getNormalParameterTypes();
    Type[] sOpTypes = s.getOptionalParameterTypes();

    // If one function has positional and the other has named parameters, return false.
    if ((sOpTypes.length > 0 && t.getNamedParameterTypes().size() > 0)
        || (tOpTypes.length > 0 && s.getNamedParameterTypes().size() > 0)) {
      return false;
    }

    // named parameters case
    if (t.getNamedParameterTypes().size() > 0) {
      // check that the number of required parameters are equal, and check that every t_i is
      // assignable to every s_i
      if (t.getNormalParameterTypes().length != s.getNormalParameterTypes().length) {
        return false;
      } else if (t.getNormalParameterTypes().length > 0) {
        for (int i = 0; i < tTypes.length; i++) {
          if (!((TypeImpl) tTypes[i]).isAssignableTo(sTypes[i], visitedTypePairs)) {
            return false;
          }
        }
      }
      Map<String, Type> namedTypesT = t.getNamedParameterTypes();
      Map<String, Type> namedTypesS = s.getNamedParameterTypes();
      // if k >= m is false, return false: the passed function type has more named parameter types than this
      if (namedTypesT.size() < namedTypesS.size()) {
        return false;
      }
      // Loop through each element in S verifying that T has a matching parameter name and that the
      // corresponding type is assignable to the type in S.
      Iterator<Entry<String, Type>> iteratorS = namedTypesS.entrySet().iterator();
      while (iteratorS.hasNext()) {
        Entry<String, Type> entryS = iteratorS.next();
        Type typeT = namedTypesT.get(entryS.getKey());
        if (typeT == null) {
          return false;
        }
        if (!((TypeImpl) typeT).isAssignableTo(entryS.getValue(), visitedTypePairs)) {
          return false;
        }
      }
    } else if (s.getNamedParameterTypes().size() > 0) {
      return false;
    } else {
      // positional parameter case
      int tArgLength = tTypes.length + tOpTypes.length;
      int sArgLength = sTypes.length + sOpTypes.length;
      // Check that the total number of parameters in t is greater than or equal to the number of
      // parameters in s and that the number of required parameters in s is greater than or equal to
      // the number of required parameters in t.
      if (tArgLength < sArgLength || sTypes.length < tTypes.length) {
        return false;
      }
      if (tOpTypes.length == 0 && sOpTypes.length == 0) {
        // No positional arguments, don't copy contents to new array
        for (int i = 0; i < sTypes.length; i++) {
          if (!((TypeImpl) tTypes[i]).isAssignableTo(sTypes[i], visitedTypePairs)) {
            return false;
          }
        }
      } else {
        // Else, we do have positional parameters, copy required and positional parameter types into
        // arrays to do the compare (for loop below).
        Type[] tAllTypes = new Type[sArgLength];
        for (int i = 0; i < tTypes.length; i++) {
          tAllTypes[i] = tTypes[i];
        }
        for (int i = tTypes.length, j = 0; i < sArgLength; i++, j++) {
          tAllTypes[i] = tOpTypes[j];
        }
        Type[] sAllTypes = new Type[sArgLength];
        for (int i = 0; i < sTypes.length; i++) {
          sAllTypes[i] = sTypes[i];
        }
        for (int i = sTypes.length, j = 0; i < sArgLength; i++, j++) {
          sAllTypes[i] = sOpTypes[j];
        }
        for (int i = 0; i < sAllTypes.length; i++) {
          if (!((TypeImpl) tAllTypes[i]).isAssignableTo(sAllTypes[i], visitedTypePairs)) {
            return false;
          }
        }
      }
    }
    Type tRetType = t.getReturnType();
    Type sRetType = s.getReturnType();
    return sRetType.isVoid() || ((TypeImpl) tRetType).isAssignableTo(sRetType, visitedTypePairs);
  }
View Full Code Here

    } else if (!(type instanceof FunctionType)) {
      return false;
    } else if (this.equals(type)) {
      return true;
    }
    FunctionType t = this;
    FunctionType s = (FunctionType) type;

    Type[] tTypes = t.getNormalParameterTypes();
    Type[] tOpTypes = t.getOptionalParameterTypes();
    Type[] sTypes = s.getNormalParameterTypes();
    Type[] sOpTypes = s.getOptionalParameterTypes();

    // If one function has positional and the other has named parameters, return false.
    if ((sOpTypes.length > 0 && t.getNamedParameterTypes().size() > 0)
        || (tOpTypes.length > 0 && s.getNamedParameterTypes().size() > 0)) {
      return false;
    }

    // named parameters case
    if (t.getNamedParameterTypes().size() > 0) {
      // check that the number of required parameters are equal, and check that every t_i is
      // more specific than every s_i
      if (t.getNormalParameterTypes().length != s.getNormalParameterTypes().length) {
        return false;
      } else if (t.getNormalParameterTypes().length > 0) {
        for (int i = 0; i < tTypes.length; i++) {
          if (!((TypeImpl) tTypes[i]).isMoreSpecificThan(sTypes[i], withDynamic, visitedTypePairs)) {
            return false;
          }
        }
      }
      Map<String, Type> namedTypesT = t.getNamedParameterTypes();
      Map<String, Type> namedTypesS = s.getNamedParameterTypes();
      // if k >= m is false, return false: the passed function type has more named parameter types than this
      if (namedTypesT.size() < namedTypesS.size()) {
        return false;
      }
      // Loop through each element in S verifying that T has a matching parameter name and that the
      // corresponding type is more specific then the type in S.
      Iterator<Entry<String, Type>> iteratorS = namedTypesS.entrySet().iterator();
      while (iteratorS.hasNext()) {
        Entry<String, Type> entryS = iteratorS.next();
        Type typeT = namedTypesT.get(entryS.getKey());
        if (typeT == null) {
          return false;
        }
        if (!((TypeImpl) typeT).isMoreSpecificThan(entryS.getValue(), withDynamic, visitedTypePairs)) {
          return false;
        }
      }
    } else if (s.getNamedParameterTypes().size() > 0) {
      return false;
    } else {
      // positional parameter case
      int tArgLength = tTypes.length + tOpTypes.length;
      int sArgLength = sTypes.length + sOpTypes.length;
      // Check that the total number of parameters in t is greater than or equal to the number of
      // parameters in s and that the number of required parameters in s is greater than or equal to
      // the number of required parameters in t.
      if (tArgLength < sArgLength || sTypes.length < tTypes.length) {
        return false;
      }
      if (tOpTypes.length == 0 && sOpTypes.length == 0) {
        // No positional arguments, don't copy contents to new array
        for (int i = 0; i < sTypes.length; i++) {
          if (!((TypeImpl) tTypes[i]).isMoreSpecificThan(sTypes[i], withDynamic, visitedTypePairs)) {
            return false;
          }
        }
      } else {
        // Else, we do have positional parameters, copy required and positional parameter types into
        // arrays to do the compare (for loop below).
        Type[] tAllTypes = new Type[sArgLength];
        for (int i = 0; i < tTypes.length; i++) {
          tAllTypes[i] = tTypes[i];
        }
        for (int i = tTypes.length, j = 0; i < sArgLength; i++, j++) {
          tAllTypes[i] = tOpTypes[j];
        }
        Type[] sAllTypes = new Type[sArgLength];
        for (int i = 0; i < sTypes.length; i++) {
          sAllTypes[i] = sTypes[i];
        }
        for (int i = sTypes.length, j = 0; i < sArgLength; i++, j++) {
          sAllTypes[i] = sOpTypes[j];
        }
        for (int i = 0; i < sAllTypes.length; i++) {
          if (!((TypeImpl) tAllTypes[i]).isMoreSpecificThan(
              sAllTypes[i],
              withDynamic,
              visitedTypePairs)) {
            return false;
          }
        }
      }
    }
    Type tRetType = t.getReturnType();
    Type sRetType = s.getReturnType();
    return sRetType.isVoid()
        || ((TypeImpl) tRetType).isMoreSpecificThan(sRetType, withDynamic, visitedTypePairs);
  }
View Full Code Here

    boolean wasInAsync = inAsync;
    boolean wasInGenerator = inGenerator;
    try {
      inAsync = node.isAsynchronous();
      inGenerator = node.isGenerator();
      FunctionType functionType = enclosingFunction == null ? null : enclosingFunction.getType();
      Type expectedReturnType = functionType == null ? DynamicTypeImpl.getInstance()
          : functionType.getReturnType();
      checkForReturnOfInvalidType(node.getExpression(), expectedReturnType);
      return super.visitExpressionFunctionBody(node);
    } finally {
      inAsync = wasInAsync;
      inGenerator = wasInGenerator;
View Full Code Here

TOP

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

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.