Package com.google.dart.engine.ast

Examples of com.google.dart.engine.ast.Expression


  public Void visitPrefixExpression(PrefixExpression node) {
    Token operator = node.getOperator();
    TokenType operatorType = operator.getType();
    if (operatorType.isUserDefinableOperator() || operatorType == TokenType.PLUS_PLUS
        || operatorType == TokenType.MINUS_MINUS) {
      Expression operand = node.getOperand();
      String methodName = getPrefixOperator(node);

      Type staticType = getStaticType(operand);
      MethodElement staticMethod = lookUpMethod(operand, staticType, methodName);
      node.setStaticElement(staticMethod);
View Full Code Here


    return null;
  }

  @Override
  public Void visitPropertyAccess(PropertyAccess node) {
    Expression target = node.getRealTarget();
    if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
      return null;
    }
    SimpleIdentifier propertyName = node.getPropertyName();
    resolvePropertyAccess(target, propertyName);
View Full Code Here

    ParameterElement[] resolvedParameters = new ParameterElement[argumentCount];
    int positionalArgumentCount = 0;
    HashSet<String> usedNames = new HashSet<String>();
    boolean noBlankArguments = true;
    for (int i = 0; i < argumentCount; i++) {
      Expression argument = arguments.get(i);
      if (argument instanceof NamedExpression) {
        SimpleIdentifier nameNode = ((NamedExpression) argument).getName().getLabel();
        String name = nameNode.getName();
        ParameterElement element = namedParameters.get(name);
        if (element == null) {
View Full Code Here

  @Override
  public Void visitDefaultFormalParameter(DefaultFormalParameter node) {
    SimpleIdentifier parameterName = node.getParameter().getIdentifier();
    ParameterElement element = getElementForParameter(node, parameterName);
    Expression defaultValue = node.getDefaultValue();
    if (defaultValue != null) {
      ExecutableElement outerExecutable = enclosingExecutable;
      try {
        if (element == null) {
          // TODO(brianwilkerson) Report this internal error.
        } else {
          enclosingExecutable = element.getInitializer();
        }
        defaultValue.accept(this);
      } finally {
        enclosingExecutable = outerExecutable;
      }
      processElement(enclosingExecutable);
    }
View Full Code Here

      element = findIdentifier(enclosingClass.getFields(), variableName);
    }
    if (element == null && enclosingUnit != null) {
      element = findIdentifier(enclosingUnit.getTopLevelVariables(), variableName);
    }
    Expression initializer = node.getInitializer();
    if (initializer != null) {
      ExecutableElement outerExecutable = enclosingExecutable;
      try {
        if (element == null) {
          // TODO(brianwilkerson) Report this internal error.
View Full Code Here

   */
  @Override
  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;
View Full Code Here

    }

    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");
View Full Code Here

    return null;
  }

  @Override
  public Void visitNamedExpression(NamedExpression node) {
    Expression expression = node.getExpression();
    recordStaticType(node, getStaticType(expression));
    recordPropagatedType(node, expression.getPropagatedType());
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitParenthesizedExpression(ParenthesizedExpression node) {
    Expression expression = node.getExpression();
    recordStaticType(node, getStaticType(expression));
    recordPropagatedType(node, expression.getPropagatedType());
    return null;
  }
View Full Code Here

   * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i){var r = a[i]; a[i]
   * = 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);
    recordPropagatedType(node, operand.getPropagatedType());
    return null;
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.ast.Expression

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.