Package com.google.dart.engine.type

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


   */
  private boolean checkForReturnOfInvalidType(Expression returnExpression, Type expectedReturnType) {
    if (enclosingFunction == null) {
      return false;
    }
    Type staticReturnType = getStaticType(returnExpression);
    if (expectedReturnType.isVoid()) {
      if (staticReturnType.isVoid() || staticReturnType.isDynamic() || staticReturnType.isBottom()) {
        return false;
      }
      errorReporter.reportTypeErrorForNode(
          StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
          returnExpression,
          staticReturnType,
          expectedReturnType,
          enclosingFunction.getDisplayName());
      return true;
    }
    if (enclosingFunction.isAsynchronous() && !enclosingFunction.isGenerator()) {
      // TODO(brianwilkerson) Figure out how to get the type "Future" so that we can build the type
      // we need to test against.
//      InterfaceType impliedType = "Future<" + flatten(staticReturnType) + ">"
//      if (impliedType.isAssignableTo(expectedReturnType)) {
//        return false;
//      }
//      errorReporter.reportTypeErrorForNode(
//          StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
//          returnExpression,
//          impliedType,
//          expectedReturnType.getDisplayName(),
//          enclosingFunction.getDisplayName());
//      return true;
      return false;
    }
    if (staticReturnType.isAssignableTo(expectedReturnType)) {
      return false;
    }
    errorReporter.reportTypeErrorForNode(
        StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
        returnExpression,
View Full Code Here


   * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE
   */
  private boolean checkForSwitchExpressionNotAssignable(SwitchStatement node) {
    // prepare 'switch' expression type
    Expression expression = node.getExpression();
    Type expressionType = getStaticType(expression);
    if (expressionType == null) {
      return false;
    }
    // compare with type of the first 'case'
    NodeList<SwitchMember> members = node.getMembers();
    for (SwitchMember switchMember : members) {
      if (!(switchMember instanceof SwitchCase)) {
        continue;
      }
      SwitchCase switchCase = (SwitchCase) switchMember;
      // prepare 'case' type
      Expression caseExpression = switchCase.getExpression();
      Type caseType = getStaticType(caseExpression);
      // check types
      if (expressionType.isAssignableTo(caseType)) {
        return false;
      }
      // report problem
View Full Code Here

  private boolean checkForTypeArgumentNotMatchingBounds(TypeName node) {
    if (node.getTypeArguments() == null) {
      return false;
    }
    // prepare Type
    Type type = node.getType();
    if (type == null) {
      return false;
    }
    // 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;
    for (int i = 0; i < loopThroughIndex; i++) {
      TypeName argTypeName = typeNameArgList.get(i);
      Type argType = argTypeName.getType();
      Type boundType = boundingElts[i].getBound();
      if (argType != null && boundType != null) {
        if (typeArguments.length != 0 && typeArguments.length == typeParameters.length) {
          boundType = boundType.substitute(typeArguments, typeParameters);
        }
        if (!argType.isSubtypeOf(boundType)) {
          ErrorCode errorCode;
          if (isInConstInstanceCreation) {
            errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
View Full Code Here

   * @return {@code true} if and only if an error code is generated on the passed node
   * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC
   */
  private boolean checkForTypeParameterReferencedByStatic(TypeName node) {
    if (isInStaticMethod || isInStaticVariableDeclaration) {
      Type type = node.getType();
      if (type instanceof TypeParameterType) {
        errorReporter.reportErrorForNode(
            StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC,
            node);
        return true;
View Full Code Here

   * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
   */
  private boolean checkForTypeParameterSupertypeOfItsBound(TypeParameter node) {
    TypeParameterElement element = node.getElement();
    // prepare bound
    Type bound = element.getBound();
    if (bound == null) {
      return false;
    }
    // OK, type parameter is not supertype of its bound
    if (!bound.isMoreSpecificThan(element.getType())) {
      return false;
    }
    // report problem
    errorReporter.reportErrorForNode(
        StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
View Full Code Here

            node.getIdentifier().getName());
      } else {
        ParameterElement parameterElement = node.getElement();
        if (parameterElement instanceof FieldFormalParameterElementImpl) {
          FieldFormalParameterElementImpl fieldFormal = (FieldFormalParameterElementImpl) parameterElement;
          Type declaredType = fieldFormal.getType();
          Type fieldType = fieldElement.getType();
          if (fieldElement.isSynthetic()) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTANT_FIELD,
                node,
                node.getIdentifier().getName());
View Full Code Here

      ps_out[j] = new ParameterElementImpl(ps_0[j].getName(), 0);
      ps_out[j].setSynthetic(true);
      ps_out[j].setType(ps_0[j].getType());
      ps_out[j].setParameterKind(ps_0[j].getParameterKind());
    }
    Type r_out = e_0.getReturnType();

    for (int i = 1; i < elementArrayToMerge.length; i++) {
      ExecutableElement e_i = elementArrayToMerge[i];
      r_out = UnionTypeImpl.union(r_out, e_i.getReturnType());
View Full Code Here

      operatorType = operatorFromCompoundAssignment(operatorType);
      Expression leftHandSide = node.getLeftHandSide();
      if (leftHandSide != null) {
        String methodName = operatorType.getLexeme();

        Type staticType = getStaticType(leftHandSide);
        MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, methodName);
        node.setStaticElement(staticMethod);

        Type propagatedType = getPropagatedType(leftHandSide);
        MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedType, methodName);
        node.setPropagatedElement(propagatedMethod);

        if (shouldReportMissingMember(staticType, staticMethod)) {
          if (doesntHaveProxy(staticType.getElement())) {
            resolver.reportErrorForToken(
                StaticTypeWarningCode.UNDEFINED_METHOD,
                operator,
                methodName,
                staticType.getDisplayName());
          }
        } else if (enableHints && shouldReportMissingMember(propagatedType, propagatedMethod)
            && !memberFoundInSubclass(propagatedType.getElement(), methodName, true, false)) {
          if (doesntHaveProxy(propagatedType.getElement())) {
            resolver.reportErrorForToken(
                HintCode.UNDEFINED_METHOD,
                operator,
                methodName,
                propagatedType.getDisplayName());
          }
        }
      }
    }
    return null;
View Full Code Here

    if (operator.isUserDefinableOperator()) {
      Expression leftOperand = node.getLeftOperand();
      if (leftOperand != null) {
        String methodName = operator.getLexeme();

        Type staticType = getStaticType(leftOperand);
        MethodElement staticMethod = lookUpMethod(leftOperand, staticType, methodName);
        node.setStaticElement(staticMethod);

        Type propagatedType = getPropagatedType(leftOperand);
        MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedType, methodName);
        node.setPropagatedElement(propagatedMethod);

        if (shouldReportMissingMember(staticType, staticMethod)) {
          if (doesntHaveProxy(staticType.getElement())) {
            resolver.reportErrorForToken(
                StaticTypeWarningCode.UNDEFINED_OPERATOR,
                operator,
                methodName,
                staticType.getDisplayName());
          }
        } else if (enableHints && shouldReportMissingMember(propagatedType, propagatedMethod)
            && !memberFoundInSubclass(propagatedType.getElement(), methodName, true, false)) {
          if (doesntHaveProxy(propagatedType.getElement())) {
            resolver.reportErrorForToken(
                HintCode.UNDEFINED_OPERATOR,
                operator,
                methodName,
                propagatedType.getDisplayName());
          }
        }
      }
    }
    return null;
View Full Code Here

    return null;
  }

  @Override
  public Void visitConstructorName(ConstructorName node) {
    Type type = node.getType().getType();
    if (type != null && type.isDynamic()) {
      return null;
    } else if (!(type instanceof InterfaceType)) {
      // TODO(brianwilkerson) Report these errors.
//      ASTNode parent = node.getParent();
//      if (parent instanceof InstanceCreationExpression) {
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.