Package com.google.dart.engine.type

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


   * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i>
   * and the static type of <i>e<sub>3</sub></i>.</blockquote>
   */
  @Override
  public Void visitConditionalExpression(ConditionalExpression node) {
    Type staticThenType = getStaticType(node.getThenExpression());
    Type staticElseType = getStaticType(node.getElseExpression());
    if (staticThenType == null) {
      // TODO(brianwilkerson) Determine whether this can still happen.
      staticThenType = dynamicType;
    }
    if (staticElseType == null) {
      // TODO(brianwilkerson) Determine whether this can still happen.
      staticElseType = dynamicType;
    }
    Type staticType = staticThenType.getLeastUpperBound(staticElseType);
    if (staticType == null) {
      staticType = dynamicType;
    }
    recordStaticType(node, staticType);

    Type propagatedThenType = node.getThenExpression().getPropagatedType();
    Type propagatedElseType = node.getElseExpression().getPropagatedType();
    if (propagatedThenType != null || propagatedElseType != null) {
      if (propagatedThenType == null) {
        propagatedThenType = staticThenType;
      }
      if (propagatedElseType == null) {
        propagatedElseType = staticElseType;
      }
      Type propagatedType = propagatedThenType.getLeastUpperBound(propagatedElseType);
      if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
        recordPropagatedType(node, propagatedType);
      }
    }
    return null;
  }
View Full Code Here


  @Override
  public Void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
    ExecutableElement staticMethodElement = node.getStaticElement();

    // Record static return type of the static element.
    Type staticStaticType = computeStaticReturnType(staticMethodElement);
    recordStaticType(node, staticStaticType);

    // Record propagated return type of the static element.
    Type staticPropagatedType = computePropagatedReturnType(staticMethodElement);
    if (staticPropagatedType != null
        && (staticStaticType == null || staticPropagatedType.isMoreSpecificThan(staticStaticType))) {
      recordPropagatedType(node, staticPropagatedType);
    }

    ExecutableElement propagatedMethodElement = node.getPropagatedElement();
    if (propagatedMethodElement != staticMethodElement) {
      // Record static return type of the propagated element.
      Type propagatedStaticType = computeStaticReturnType(propagatedMethodElement);
      if (propagatedStaticType != null
          && (staticStaticType == null || propagatedStaticType.isMoreSpecificThan(staticStaticType))
          && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
        recordPropagatedType(node, propagatedStaticType);
      }
      // Record propagated return type of the propagated element.
      Type propagatedPropagatedType = computePropagatedReturnType(propagatedMethodElement);
      if (propagatedPropagatedType != null
          && (staticStaticType == null || propagatedPropagatedType.isMoreSpecificThan(staticStaticType))
          && (staticPropagatedType == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType))
          && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan(propagatedStaticType))) {
        recordPropagatedType(node, propagatedPropagatedType);
      }
    }

    return null;
View Full Code Here

   */
  @Override
  public Void visitIndexExpression(IndexExpression node) {
    if (node.inSetterContext()) {
      ExecutableElement staticMethodElement = node.getStaticElement();
      Type staticType = computeArgumentType(staticMethodElement);
      recordStaticType(node, staticType);

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

    if (element != null && "Element".equals(element.getEnclosingElement().getName())) {
      LibraryElement library = element.getLibrary();
      if (isHtmlLibrary(library)) {
        String constructorName = element.getName();
        if ("tag".equals(constructorName)) {
          Type returnType = getFirstArgumentAsTypeWithMap(
              library,
              node.getArgumentList(),
              HTML_ELEMENT_TO_CLASS_MAP);
          if (returnType != null) {
            recordPropagatedType(node, returnType);
          }
        } else {
          Type returnType = getElementNameAsType(
              library,
              constructorName,
              HTML_ELEMENT_TO_CLASS_MAP);
          if (returnType != null) {
            recordPropagatedType(node, returnType);
View Full Code Here

   * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt;dynamic&gt;}
   * .</blockquote>
   */
  @Override
  public Void visitListLiteral(ListLiteral node) {
    Type staticType = dynamicType;
    TypeArgumentList typeArguments = node.getTypeArguments();
    if (typeArguments != null) {
      NodeList<TypeName> arguments = typeArguments.getArguments();
      if (arguments != null && arguments.size() == 1) {
        TypeName argumentTypeName = arguments.get(0);
        Type argumentType = getType(argumentTypeName);
        if (argumentType != null) {
          staticType = argumentType;
        }
      }
    }
View Full Code Here

   * It is a compile-time error if the first type argument to a map literal is not
   * <i>String</i>.</blockquote>
   */
  @Override
  public Void visitMapLiteral(MapLiteral node) {
    Type staticKeyType = dynamicType;
    Type staticValueType = dynamicType;
    TypeArgumentList typeArguments = node.getTypeArguments();
    if (typeArguments != null) {
      NodeList<TypeName> arguments = typeArguments.getArguments();
      if (arguments != null && arguments.size() == 2) {
        TypeName entryKeyTypeName = arguments.get(0);
        Type entryKeyType = getType(entryKeyTypeName);
        if (entryKeyType != null) {
          staticKeyType = entryKeyType;
        }
        TypeName entryValueTypeName = arguments.get(1);
        Type entryValueType = getType(entryValueTypeName);
        if (entryValueType != null) {
          staticValueType = entryValueType;
        }
      }
    }
View Full Code Here

    Element staticMethodElement = methodNameNode.getStaticElement();

    // Record types of the local variable invoked as a function.
    if (staticMethodElement instanceof LocalVariableElement) {
      LocalVariableElement variable = (LocalVariableElement) staticMethodElement;
      Type staticType = variable.getType();
      recordStaticType(methodNameNode, staticType);
      Type propagatedType = overrideManager.getType(variable);
      if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
        recordPropagatedType(methodNameNode, propagatedType);
      }
    }

    // Record static return type of the static element.
    Type staticStaticType = computeStaticReturnType(staticMethodElement);
    recordStaticType(node, staticStaticType);

    // Record propagated return type of the static element.
    Type staticPropagatedType = computePropagatedReturnType(staticMethodElement);
    if (staticPropagatedType != null
        && (staticStaticType == null || staticPropagatedType.isMoreSpecificThan(staticStaticType))) {
      recordPropagatedType(node, staticPropagatedType);
    }

    boolean needPropagatedType = true;
    String methodName = methodNameNode.getName();
    if (methodName.equals("then")) {
      Expression target = node.getRealTarget();
      if (target != null) {
        Type targetType = target.getBestType();
        if (isAsyncFutureType(targetType)) {
          // Future.then(closure) return type is:
          // 1) the returned Future type, if the closure returns a Future;
          // 2) Future<valueType>, if the closure returns a value.
          NodeList<Expression> arguments = node.getArgumentList().getArguments();
          if (arguments.size() == 1) {
            // TODO(brianwilkerson) Handle the case where both arguments are provided.
            Expression closureArg = arguments.get(0);
            if (closureArg instanceof FunctionExpression) {
              FunctionExpression closureExpr = (FunctionExpression) closureArg;
              Type returnType = computePropagatedReturnType(closureExpr.getElement());
              if (returnType != null) {
                // 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;
                return null;
              }
            }
          }
        }
      }
    } else if (methodName.equals("$dom_createEvent")) {
      Expression target = node.getRealTarget();
      if (target != null) {
        Type targetType = target.getBestType();
        if (targetType instanceof InterfaceType
            && (targetType.getName().equals("HtmlDocument") || targetType.getName().equals(
                "Document"))) {
          LibraryElement library = targetType.getElement().getLibrary();
          if (isHtmlLibrary(library)) {
            Type returnType = getFirstArgumentAsType(library, node.getArgumentList());
            if (returnType != null) {
              recordPropagatedType(node, returnType);
              needPropagatedType = false;
            }
          }
        }
      }
    } else if (methodName.equals("query")) {
      Expression target = node.getRealTarget();
      if (target == null) {
        Element methodElement = methodNameNode.getBestElement();
        if (methodElement != null) {
          LibraryElement library = methodElement.getLibrary();
          if (isHtmlLibrary(library)) {
            Type returnType = getFirstArgumentAsQuery(library, node.getArgumentList());
            if (returnType != null) {
              recordPropagatedType(node, returnType);
              needPropagatedType = false;
            }
          }
        }
      } else {
        Type targetType = target.getBestType();
        if (targetType instanceof InterfaceType
            && (targetType.getName().equals("HtmlDocument") || targetType.getName().equals(
                "Document"))) {
          LibraryElement library = targetType.getElement().getLibrary();
          if (isHtmlLibrary(library)) {
            Type returnType = getFirstArgumentAsQuery(library, node.getArgumentList());
            if (returnType != null) {
              recordPropagatedType(node, returnType);
              needPropagatedType = false;
            }
          }
        }
      }
    } else if (methodName.equals("$dom_createElement")) {
      Expression target = node.getRealTarget();
      if (target != null) {
        Type targetType = target.getBestType();
        if (targetType instanceof InterfaceType
            && (targetType.getName().equals("HtmlDocument") || targetType.getName().equals(
                "Document"))) {
          LibraryElement library = targetType.getElement().getLibrary();
          if (isHtmlLibrary(library)) {
            Type returnType = getFirstArgumentAsQuery(library, node.getArgumentList());
            if (returnType != null) {
              recordPropagatedType(node, returnType);
              needPropagatedType = false;
            }
          }
        }
      }
    } else if (methodName.equals("JS")) {
      Type returnType = getFirstArgumentAsType(
          typeProvider.getObjectType().getElement().getLibrary(),
          node.getArgumentList());
      if (returnType != null) {
        recordPropagatedType(node, returnType);
        needPropagatedType = false;
      }
    } else if (methodName.equals("getContext")) {
      Expression target = node.getRealTarget();
      if (target != null) {
        Type targetType = target.getBestType();
        if (targetType instanceof InterfaceType && (targetType.getName().equals("CanvasElement"))) {
          NodeList<Expression> arguments = node.getArgumentList().getArguments();
          if (arguments.size() == 1) {
            Expression argument = arguments.get(0);
            if (argument instanceof StringLiteral) {
              String value = ((StringLiteral) argument).getStringValue();
              if ("2d".equals(value)) {
                PropertyAccessorElement getter = ((InterfaceType) targetType).getElement().getGetter(
                    "context2D");
                if (getter != null) {
                  Type returnType = getter.getReturnType();
                  if (returnType != null) {
                    recordPropagatedType(node, returnType);
                    needPropagatedType = false;
                  }
                }
              }
            }
          }
        }
      }
    }
    if (needPropagatedType) {
      Element propagatedElement = methodNameNode.getPropagatedElement();
      // HACK: special case for object methods ([toString]) on dynamic expressions.
      // More special cases in [visitPrefixedIdentfier].
      if (propagatedElement == null) {
        propagatedElement = typeProvider.getObjectType().getMethod(methodNameNode.getName());
      }

      if (propagatedElement != staticMethodElement) {
        // Record static return type of the propagated element.
        Type propagatedStaticType = computeStaticReturnType(propagatedElement);
        if (propagatedStaticType != null
            && (staticStaticType == null || propagatedStaticType.isMoreSpecificThan(staticStaticType))
            && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
          recordPropagatedType(node, propagatedStaticType);
        }
        // Record propagated return type of the propagated element.
        Type propagatedPropagatedType = computePropagatedReturnType(propagatedElement);
        if (propagatedPropagatedType != null
            && (staticStaticType == null || propagatedPropagatedType.isMoreSpecificThan(staticStaticType))
            && (staticPropagatedType == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType))
            && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan(propagatedStaticType))) {
          recordPropagatedType(node, propagatedPropagatedType);
        }
      }
    }
    return null;
View Full Code Here

   * = r - 1; return r}(e1, e2)</i></blockquote>
   */
  @Override
  public Void visitPostfixExpression(PostfixExpression node) {
    Expression operand = node.getOperand();
    Type staticType = getStaticType(operand);
    TokenType operator = node.getOperator().getType();
    if (operator == TokenType.MINUS_MINUS || operator == TokenType.PLUS_PLUS) {
      Type intType = typeProvider.getIntType();
      if (getStaticType(node.getOperand()) == intType) {
        staticType = intType;
      }
    }
    recordStaticType(node, staticType);
View Full Code Here

   */
  @Override
  public Void visitPrefixedIdentifier(PrefixedIdentifier node) {
    SimpleIdentifier prefixedIdentifier = node.getIdentifier();
    Element staticElement = prefixedIdentifier.getStaticElement();
    Type staticType = dynamicType;
    Type propagatedType = null;
    if (staticElement instanceof ClassElement) {
      if (isNotTypeLiteral(node)) {
        staticType = ((ClassElement) staticElement).getType();
      } else {
        staticType = typeProvider.getTypeType();
      }
    } else if (staticElement instanceof FunctionTypeAliasElement) {
      if (isNotTypeLiteral(node)) {
        staticType = ((FunctionTypeAliasElement) staticElement).getType();
      } else {
        staticType = typeProvider.getTypeType();
      }
    } else if (staticElement instanceof MethodElement) {
      staticType = ((MethodElement) staticElement).getType();
    } else if (staticElement instanceof PropertyAccessorElement) {
      staticType = getTypeOfProperty(
          (PropertyAccessorElement) staticElement,
          node.getPrefix().getStaticType());
      propagatedType = getPropertyPropagatedType(staticElement, propagatedType);
    } else if (staticElement instanceof ExecutableElement) {
      staticType = ((ExecutableElement) staticElement).getType();
    } else if (staticElement instanceof TypeParameterElement) {
      staticType = ((TypeParameterElement) staticElement).getType();
    } else if (staticElement instanceof VariableElement) {
      staticType = ((VariableElement) staticElement).getType();
    }
    recordStaticType(prefixedIdentifier, staticType);
    recordStaticType(node, staticType);

    Element propagatedElement = prefixedIdentifier.getPropagatedElement();
    // HACK: special case for object getters ([hashCode] and [runtimeType]) on dynamic expressions.
    // More special cases in [visitMethodInvocation].
    if (propagatedElement == null) {
      propagatedElement = typeProvider.getObjectType().getGetter(prefixedIdentifier.getName());
    }

    if (propagatedElement instanceof ClassElement) {
      if (isNotTypeLiteral(node)) {
        propagatedType = ((ClassElement) propagatedElement).getType();
      } else {
        propagatedType = typeProvider.getTypeType();
      }
    } else if (propagatedElement instanceof FunctionTypeAliasElement) {
      propagatedType = ((FunctionTypeAliasElement) propagatedElement).getType();
    } else if (propagatedElement instanceof MethodElement) {
      propagatedType = ((MethodElement) propagatedElement).getType();
    } else if (propagatedElement instanceof PropertyAccessorElement) {
      propagatedType = getTypeOfProperty(
          (PropertyAccessorElement) propagatedElement,
          node.getPrefix().getStaticType());
      propagatedType = getPropertyPropagatedType(propagatedElement, propagatedType);
    } else if (propagatedElement instanceof ExecutableElement) {
      propagatedType = ((ExecutableElement) propagatedElement).getType();
    } else if (propagatedElement instanceof TypeParameterElement) {
      propagatedType = ((TypeParameterElement) propagatedElement).getType();
    } else if (propagatedElement instanceof VariableElement) {
      propagatedType = ((VariableElement) propagatedElement).getType();
    }
    Type overriddenType = overrideManager.getType(propagatedElement);
    if (propagatedType == null
        || (overriddenType != null && overriddenType.isMoreSpecificThan(propagatedType))) {
      propagatedType = overriddenType;
    }
    if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
      recordPropagatedType(prefixedIdentifier, propagatedType);
      recordPropagatedType(node, propagatedType);
View Full Code Here

    if (operator == TokenType.BANG) {
      recordStaticType(node, typeProvider.getBoolType());
    } else {
      // The other cases are equivalent to invoking a method.
      ExecutableElement staticMethodElement = node.getStaticElement();
      Type staticType = computeStaticReturnType(staticMethodElement);
      if (operator == TokenType.MINUS_MINUS || operator == TokenType.PLUS_PLUS) {
        Type intType = typeProvider.getIntType();
        if (getStaticType(node.getOperand()) == intType) {
          staticType = intType;
        }
      }
      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.