Package com.google.dart.engine.type

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


    if (!(body instanceof BlockFunctionBody)) {
      return false;
    }

    // Check that the type is resolvable, and is not "void"
    Type returnTypeType = returnType.getType();
    if (returnTypeType == null || returnTypeType.isVoid()) {
      return false;
    }

    // Check the block for a return statement, if not, create the hint
    BlockFunctionBody blockFunctionBody = (BlockFunctionBody) body;
    if (!blockFunctionBody.accept(new ExitDetector())) {
      errorReporter.reportErrorForNode(
          HintCode.MISSING_RETURN,
          returnType,
          returnTypeType.getDisplayName());
      return true;
    }
    return false;
  }
View Full Code Here


   * @see HintCode#UNNECESSARY_CAST
   */
  private boolean checkForUnnecessaryCast(AsExpression node) {
    Expression expression = node.getExpression();
    TypeName typeName = node.getType();
    Type lhsType = expression.getStaticType();
    Type rhsType = typeName.getType();
    // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to remove the
    // !(x instanceof TypeParameterType) checks.
    if (lhsType != null && rhsType != null && !lhsType.isDynamic() && !rhsType.isDynamic()
        && !(lhsType instanceof TypeParameterType) && !(rhsType instanceof TypeParameterType)
        && lhsType.isMoreSpecificThan(rhsType)) {
      errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node);
      return true;
    }
View Full Code Here

      // Function types have an empty name when they are defined implicitly by either a closure or
      // as part of a parameter declaration.
      Type[] normalParameterTypes = getNormalParameterTypes();
      Type[] optionalParameterTypes = getOptionalParameterTypes();
      Map<String, Type> namedParameterTypes = getNamedParameterTypes();
      Type returnType = getReturnType();
      StringBuilder builder = new StringBuilder();
      builder.append("(");
      boolean needsComma = false;
      if (normalParameterTypes.length > 0) {
        for (Type type : normalParameterTypes) {
          if (needsComma) {
            builder.append(", ");
          } else {
            needsComma = true;
          }
          builder.append(type.getDisplayName());
        }
      }
      if (optionalParameterTypes.length > 0) {
        if (needsComma) {
          builder.append(", ");
          needsComma = false;
        }
        builder.append("[");
        for (Type type : optionalParameterTypes) {
          if (needsComma) {
            builder.append(", ");
          } else {
            needsComma = true;
          }
          builder.append(type.getDisplayName());
        }
        builder.append("]");
        needsComma = true;
      }
      if (namedParameterTypes.size() > 0) {
        if (needsComma) {
          builder.append(", ");
          needsComma = false;
        }
        builder.append("{");
        for (Map.Entry<String, Type> entry : namedParameterTypes.entrySet()) {
          if (needsComma) {
            builder.append(", ");
          } else {
            needsComma = true;
          }
          builder.append(entry.getKey());
          builder.append(": ");
          builder.append(entry.getValue().getDisplayName());
        }
        builder.append("}");
        needsComma = true;
      }
      builder.append(")");
      builder.append(Element.RIGHT_ARROW);
      if (returnType == null) {
        builder.append("null");
      } else {
        builder.append(returnType.getDisplayName());
      }
      name = builder.toString();
    }
    return name;
  }
View Full Code Here

      return namedParameterTypes;
    }
    Type[] typeParameters = TypeParameterTypeImpl.getTypes(getTypeParameters());
    for (ParameterElement parameter : parameters) {
      if (parameter.getParameterKind() == ParameterKind.NAMED) {
        Type type = parameter.getType();
        if (typeArguments.length != 0 && typeArguments.length == typeParameters.length) {
          type = type.substitute(typeArguments, typeParameters);
        }
        namedParameterTypes.put(parameter.getName(), type);
      }
    }
    return namedParameterTypes;
View Full Code Here

    }
    Type[] typeParameters = TypeParameterTypeImpl.getTypes(getTypeParameters());
    ArrayList<Type> types = new ArrayList<Type>();
    for (ParameterElement parameter : parameters) {
      if (parameter.getParameterKind() == ParameterKind.REQUIRED) {
        Type type = parameter.getType();
        if (typeArguments.length != 0 && typeArguments.length == typeParameters.length) {
          type = type.substitute(typeArguments, typeParameters);
        }
        types.add(type);
      }
    }
    return types.toArray(new Type[types.size()]);
View Full Code Here

    }
    Type[] typeParameters = TypeParameterTypeImpl.getTypes(getTypeParameters());
    ArrayList<Type> types = new ArrayList<Type>();
    for (ParameterElement parameter : parameters) {
      if (parameter.getParameterKind() == ParameterKind.POSITIONAL) {
        Type type = parameter.getType();
        if (typeArguments.length != 0 && typeArguments.length == typeParameters.length) {
          type = type.substitute(typeArguments, typeParameters);
        }
        types.add(type);
      }
    }
    return types.toArray(new Type[types.size()]);
View Full Code Here

    return specializedParameters;
  }

  @Override
  public Type getReturnType() {
    Type baseReturnType = getBaseReturnType();
    if (baseReturnType == null) {
      // TODO(brianwilkerson) This is a patch. The return type should never be null and we need to
      // understand why it is and fix it.
      return DynamicTypeImpl.getInstance();
    }
    // If there are no arguments to substitute, or if the arguments size doesn't match the parameter
    // size, return the base return type.
    if (typeArguments.length == 0 || typeArguments.length != getTypeParameters().length) {
      return baseReturnType;
    }
    return baseReturnType.substitute(
        typeArguments,
        TypeParameterTypeImpl.getTypes(getTypeParameters()));
  }
View Full Code Here

      // 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

  @Override
  protected void appendTo(StringBuilder builder) {
    Type[] normalParameterTypes = getNormalParameterTypes();
    Type[] optionalParameterTypes = getOptionalParameterTypes();
    Map<String, Type> namedParameterTypes = getNamedParameterTypes();
    Type returnType = getReturnType();
    builder.append("(");
    boolean needsComma = false;
    if (normalParameterTypes.length > 0) {
      for (Type type : normalParameterTypes) {
        if (needsComma) {
View Full Code Here

      // 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

TOP

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

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.