Package com.google.dart.engine.type

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


      boolean allowPrecisionLoss) {
    if (potentialType == null || potentialType.isBottom()) {
      return;
    }

    Type currentType = getBestType(element);
    // If we aren't allowing precision loss then the third and fourth conditions check that we
    // aren't losing precision.
    //
    // Let [C] be the current type and [P] be the potential type.  When we aren't allowing
    // precision loss -- which is the case for is-checks -- we check that [! (C << P)] or  [P << C].
    // The second check, that [P << C], is analogous to part of the Dart Language Spec rule
    // for type promotion under is-checks (in the analogy [T] is [P] and [S] is [C]):
    //
    //   An is-expression of the form [v is T] shows that [v] has type [T] iff [T] is more
    //   specific than the type [S] of the expression [v] and both [T != dynamic] and
    //   [S != dynamic].
    //
    // It also covers an important case that is not applicable in the spec: for union types, we
    // want an is-check to promote from an union type to (a subtype of) any of its members.
    //
    // The first check, that [! (C << P)], covers the case where [P] and [C] are unrelated types;
    // This case is not addressed in the spec for static types.
    if (currentType == null || allowPrecisionLoss || !currentType.isMoreSpecificThan(potentialType)
        || potentialType.isMoreSpecificThan(currentType)) {
      if (element instanceof PropertyInducingElement) {
        PropertyInducingElement variable = (PropertyInducingElement) element;
        if (!variable.isConst() && !variable.isFinal()) {
          return;
View Full Code Here


      overrideManager.enterScope();
      try {
        if (loopVariable != null && iterator != null) {
          LocalVariableElement loopElement = loopVariable.getElement();
          if (loopElement != null) {
            Type iteratorElementType = getIteratorElementType(iterator);
            overrideVariable(loopElement, iteratorElementType, true);
            recordPropagatedType(loopVariable.getIdentifier(), iteratorElementType);
          }
        } else if (identifier != null && iterator != null) {
          Element identifierElement = identifier.getStaticElement();
          if (identifierElement instanceof VariableElement) {
            Type iteratorElementType = getIteratorElementType(iterator);
            overrideVariable((VariableElement) identifierElement, iteratorElementType, true);
            recordPropagatedType(identifier, iteratorElementType);
          }
        }
        visitStatementInScope(body);
View Full Code Here

   *
   * @param element the element for which type information is to be returned
   * @return the best type information available for the given element
   */
  private Type getBestType(Element element) {
    Type bestType = overrideManager.getType(element);
    if (bestType == null) {
      if (element instanceof LocalVariableElement) {
        bestType = ((LocalVariableElement) element).getType();
      } else if (element instanceof ParameterElement) {
        bestType = ((ParameterElement) element).getType();
View Full Code Here

   *
   * @param iterator the iterator for a for-each statement
   * @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");
View Full Code Here

      return;
    }
    FunctionType expectedClosureType = (FunctionType) mayByFunctionType;

    // If the expectedClosureType is not more specific than the static type, return.
    Type staticClosureType = closure.getElement() != null ? closure.getElement().getType() : null;
    if (staticClosureType != null && !expectedClosureType.isMoreSpecificThan(staticClosureType)) {
      return;
    }

    // set propagated type for the closure
    closure.setPropagatedType(expectedClosureType);
    // set inferred types for parameters
    NodeList<FormalParameter> parameters = closure.getParameters().getParameters();
    ParameterElement[] expectedParameters = expectedClosureType.getParameters();
    for (int i = 0; i < parameters.size() && i < expectedParameters.length; i++) {
      FormalParameter parameter = parameters.get(i);
      ParameterElement element = parameter.getElement();
      Type currentType = getBestType(element);
      // may be override the type
      Type expectedType = expectedParameters[i].getType();
      if (currentType == null || expectedType.isMoreSpecificThan(currentType)) {
        overrideManager.setType(element, expectedType);
      }
    }
  }
View Full Code Here

      // may be mutated somewhere in closure
      if (((VariableElementImpl) element).isPotentiallyMutatedInClosure()) {
        return;
      }
      // prepare current variable type
      Type type = promoteManager.getType(element);
      if (type == null) {
        type = expression.getStaticType();
      }
      // Declared type should not be "dynamic".
      if (type == null || type.isDynamic()) {
        return;
      }
      // Promoted type should not be "dynamic".
      if (potentialType == null || potentialType.isDynamic()) {
        return;
View Full Code Here

   * Returns static type of the given variable - declared or promoted.
   *
   * @return the static type of the given variable - declared or promoted
   */
  public Type getStaticType(VariableElement variable) {
    Type staticType = getType(variable);
    if (staticType == null) {
      staticType = variable.getType();
    }
    return staticType;
  }
View Full Code Here

     *
     * @param element the element whose type might have been promoted
     * @return the promoted type of the given element
     */
    public Type getType(Element element) {
      Type type = promotedTypes.get(element);
      if (type == null && element instanceof PropertyAccessorElement) {
        type = promotedTypes.get(((PropertyAccessorElement) element).getVariable());
      }
      if (type != null) {
        return type;
View Full Code Here

  public Void visitAssignmentExpression(AssignmentExpression node) {
    TokenType operator = node.getOperator().getType();
    if (operator == TokenType.EQ) {
      Expression rightHandSide = node.getRightHandSide();

      Type staticType = getStaticType(rightHandSide);
      recordStaticType(node, staticType);
      Type overrideType = staticType;

      Type propagatedType = rightHandSide.getPropagatedType();
      if (propagatedType != null) {
        if (propagatedType.isMoreSpecificThan(staticType)) {
          recordPropagatedType(node, propagatedType);
        }
        overrideType = propagatedType;
      }
      resolver.overrideExpression(node.getLeftHandSide(), overrideType, true);
    } else {
      ExecutableElement staticMethodElement = node.getStaticElement();
      Type staticType = computeStaticReturnType(staticMethodElement);
      recordStaticType(node, staticType);

      MethodElement propagatedMethodElement = node.getPropagatedElement();
      if (propagatedMethodElement != staticMethodElement) {
        Type propagatedType = computeStaticReturnType(propagatedMethodElement);
        if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
          recordPropagatedType(node, propagatedType);
        }
      }
    }
    return null;
View Full Code Here

   * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
   */
  @Override
  public Void visitBinaryExpression(BinaryExpression node) {
    ExecutableElement staticMethodElement = node.getStaticElement();
    Type staticType = computeStaticReturnType(staticMethodElement);
    staticType = refineBinaryExpressionType(node, staticType);
    recordStaticType(node, staticType);

    MethodElement propagatedMethodElement = node.getPropagatedElement();
    if (propagatedMethodElement != staticMethodElement) {
      Type propagatedType = computeStaticReturnType(propagatedMethodElement);
      if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
        recordPropagatedType(node, propagatedType);
      }
    }
    return null;
  }
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.