Package com.google.dart.engine.ast

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


      }
      for (FormalParameter parameter : declaration.getParameters().getParameters()) {
        referenceGraph.addNode(parameter);
        referenceGraph.addEdge(declaration, parameter);
        if (parameter instanceof DefaultFormalParameter) {
          Expression defaultValue = ((DefaultFormalParameter) parameter).getDefaultValue();
          if (defaultValue != null) {
            ReferenceFinder parameterReferenceFinder = new ReferenceFinder(
                parameter,
                referenceGraph,
                variableDeclarationMap,
                constructorDeclarationMap);
            defaultValue.accept(parameterReferenceFinder);
          }
        }
      }
    }
    for (InstanceCreationExpression expression : constructorInvocations) {
View Full Code Here


      constructor.setConstantInitializers(new InitializerCloner().cloneNodeList(initializers));
    } else if (constNode instanceof FormalParameter) {
      if (constNode instanceof DefaultFormalParameter) {
        DefaultFormalParameter parameter = ((DefaultFormalParameter) constNode);
        ParameterElement element = parameter.getElement();
        Expression defaultValue = parameter.getDefaultValue();
        if (defaultValue != null) {
          EvaluationResultImpl result = defaultValue.accept(createConstantVisitor());
          ((ParameterElementImpl) element).setEvaluationResult(result);
        }
      }
    } else {
      // Should not happen.
View Full Code Here

      ConstantVisitor constantVisitor) {
    int argumentCount = arguments.size();
    DartObjectImpl[] argumentValues = new DartObjectImpl[argumentCount];
    HashMap<String, DartObjectImpl> namedArgumentValues = new HashMap<String, DartObjectImpl>();
    for (int i = 0; i < argumentCount; i++) {
      Expression argument = arguments.get(i);
      if (argument instanceof NamedExpression) {
        NamedExpression namedExpression = (NamedExpression) argument;
        String name = namedExpression.getName().getLabel().getName();
        namedArgumentValues.put(name, constantVisitor.valueOf(namedExpression.getExpression()));
        argumentValues[i] = constantVisitor.getNull();
      } else {
        argumentValues[i] = constantVisitor.valueOf(argument);
      }
    }
    constructor = followConstantRedirectionChain(constructor);
    InterfaceType definingClass = (InterfaceType) constructor.getReturnType();
    if (constructor.isFactory()) {
      // We couldn't find a non-factory constructor.  See if it's because we reached an external
      // const factory constructor that we can emulate.
      if (constructor.getName().equals("fromEnvironment")) {
        if (!checkFromEnvironmentArguments(
            arguments,
            argumentValues,
            namedArgumentValues,
            definingClass)) {
          return new ErrorResult(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
        }
        String variableName = argumentCount < 1 ? null : argumentValues[0].getStringValue();
        if (definingClass == typeProvider.getBoolType()) {
          DartObject valueFromEnvironment;
          valueFromEnvironment = declaredVariables.getBool(typeProvider, variableName);
          return computeValueFromEnvironment(
              valueFromEnvironment,
              new DartObjectImpl(typeProvider.getBoolType(), BoolState.FALSE_STATE),
              namedArgumentValues);
        } else if (definingClass == typeProvider.getIntType()) {
          DartObject valueFromEnvironment;
          valueFromEnvironment = declaredVariables.getInt(typeProvider, variableName);
          return computeValueFromEnvironment(
              valueFromEnvironment,
              new DartObjectImpl(typeProvider.getNullType(), NullState.NULL_STATE),
              namedArgumentValues);
        } else if (definingClass == typeProvider.getStringType()) {
          DartObject valueFromEnvironment;
          valueFromEnvironment = declaredVariables.getString(typeProvider, variableName);
          return computeValueFromEnvironment(
              valueFromEnvironment,
              new DartObjectImpl(typeProvider.getNullType(), NullState.NULL_STATE),
              namedArgumentValues);
        }
      } else if (constructor.getName().equals("") && definingClass == typeProvider.getSymbolType()
          && argumentCount == 1) {
        if (!checkSymbolArguments(arguments, argumentValues, namedArgumentValues)) {
          return new ErrorResult(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
        }
        String argumentValue = argumentValues[0].getStringValue();
        return constantVisitor.valid(definingClass, new SymbolState(argumentValue));
      }

      // Either it's an external const factory constructor that we can't emulate, or an error
      // occurred (a cycle, or a const constructor trying to delegate to a non-const constructor).
      // In the former case, the best we can do is consider it an unknown value.  In the latter
      // case, the error has already been reported, so considering it an unknown value will
      // suppress further errors.
      return constantVisitor.validWithUnknownValue(definingClass);
    }
    beforeGetConstantInitializers(constructor);
    ConstructorElementImpl constructorBase = (ConstructorElementImpl) getConstructorBase(constructor);
    List<ConstructorInitializer> initializers = constructorBase.getConstantInitializers();
    if (initializers == null) {
      // This can happen in some cases where there are compile errors in the code being analyzed
      // (for example if the code is trying to create a const instance using a non-const
      // constructor, or the node we're visiting is involved in a cycle).  The error has already
      // been reported, so consider it an unknown value to suppress further errors.
      return constantVisitor.validWithUnknownValue(definingClass);
    }
    HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjectImpl>();
    HashMap<String, DartObjectImpl> parameterMap = new HashMap<String, DartObjectImpl>();
    ParameterElement[] parameters = constructorBase.getParameters();
    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      ParameterElement parameter = parameters[i];
      while (parameter instanceof ParameterMember) {
        parameter = ((ParameterMember) parameter).getBaseElement();
      }
      DartObjectImpl argumentValue = null;
      if (parameter.getParameterKind() == ParameterKind.NAMED) {
        argumentValue = namedArgumentValues.get(parameter.getName());
      } else if (i < argumentCount) {
        argumentValue = argumentValues[i];
      }
      if (argumentValue == null && parameter instanceof ParameterElementImpl) {
        // The parameter is an optional positional parameter for which no value was provided, so
        // use the default value.
        beforeGetParameterDefault(parameter);
        EvaluationResultImpl evaluationResult = ((ParameterElementImpl) parameter).getEvaluationResult();
        if (evaluationResult instanceof ValidResult) {
          argumentValue = ((ValidResult) evaluationResult).getValue();
        } else if (evaluationResult == null) {
          // No default was provided, so the default value is null.
          argumentValue = constantVisitor.getNull();
        }
      }
      if (argumentValue != null) {
        if (parameter.isInitializingFormal()) {
          FieldElement field = ((FieldFormalParameterElement) parameter).getField();
          if (field != null) {
            String fieldName = field.getName();
            fieldMap.put(fieldName, argumentValue);
          }
        } else {
          String name = parameter.getName();
          parameterMap.put(name, argumentValue);
        }
      }
    }
    ConstantVisitor initializerVisitor = new ConstantVisitor(typeProvider, parameterMap);
    String superName = null;
    NodeList<Expression> superArguments = null;
    for (ConstructorInitializer initializer : initializers) {
      if (initializer instanceof ConstructorFieldInitializer) {
        ConstructorFieldInitializer constructorFieldInitializer = (ConstructorFieldInitializer) initializer;
        Expression initializerExpression = constructorFieldInitializer.getExpression();
        EvaluationResultImpl evaluationResult = initializerExpression.accept(initializerVisitor);
        if (evaluationResult instanceof ValidResult) {
          DartObjectImpl value = ((ValidResult) evaluationResult).getValue();
          String fieldName = constructorFieldInitializer.getFieldName().getName();
          fieldMap.put(fieldName, value);
        }
View Full Code Here

    }

    @Override
    public Void visitMapLiteralEntry(MapLiteralEntry node) {
      String libraryName = null;
      Expression key = node.getKey();
      if (key instanceof SimpleStringLiteral) {
        libraryName = LIBRARY_PREFIX + ((SimpleStringLiteral) key).getValue();
      }
      Expression value = node.getValue();
      if (value instanceof InstanceCreationExpression) {
        SdkLibraryImpl library = new SdkLibraryImpl(libraryName);
        List<Expression> arguments = ((InstanceCreationExpression) value).getArgumentList().getArguments();
        for (Expression argument : arguments) {
          if (argument instanceof SimpleStringLiteral) {
            library.setPath(((SimpleStringLiteral) argument).getValue());
          } else if (argument instanceof NamedExpression) {
            String name = ((NamedExpression) argument).getName().getLabel().getName();
            Expression expression = ((NamedExpression) argument).getExpression();
            if (name.equals(CATEGORY)) {
              library.setCategory(((SimpleStringLiteral) expression).getValue());
            } else if (name.equals(IMPLEMENTATION)) {
              library.setImplementation(((BooleanLiteral) expression).getValue());
            } else if (name.equals(DOCUMENTED)) {
View Full Code Here

  /**
   * Returns the {@link Element} of the {@link Expression} in the given {@link HtmlUnit}, enclosing
   * the given offset.
   */
  public static Element getElementAtOffset(HtmlUnit htmlUnit, int offset) {
    Expression expression = getExpression(htmlUnit, offset);
    return getElement(expression);
  }
View Full Code Here

    try {
      // TODO(scheglov) this code is very Angular specific
      htmlUnit.accept(new ExpressionVisitor() {
        @Override
        public void visitExpression(Expression expression) {
          Expression at = getExpressionAt(expression, offset);
          if (at != null) {
            result[0] = at;
            throw new FoundExpressionError();
          }
        }
View Full Code Here

    return valid(typeProvider.getBoolType(), BoolState.from(node.getValue()));
  }

  @Override
  public EvaluationResultImpl visitConditionalExpression(ConditionalExpression node) {
    Expression condition = node.getCondition();
    EvaluationResultImpl conditionResult = condition.accept(this);
    EvaluationResultImpl thenResult = node.getThenExpression().accept(this);
    EvaluationResultImpl elseResult = node.getElseExpression().accept(this);
    if (conditionResult instanceof ErrorResult) {
      return union(union((ErrorResult) conditionResult, thenResult), elseResult);
    } else if (!((ValidResult) conditionResult).isBool()) {
View Full Code Here

          lhsOffset,
          lhsSpec.length());
      return;
    }
    // parse item name
    Expression varExpression = resolver.parseDartExpression(lhsSpec, 0, lhsSpec.length(), lhsOffset);
    SimpleIdentifier varName = (SimpleIdentifier) varExpression;
    // parse iterable
    AngularExpression iterableExpr = resolver.parseAngularExpression(
        iterableSpec,
        0,
View Full Code Here

  /**
   * Resolves an argument for "filter" formatter.
   */
  private void resolveFormatterArgument_filter(AngularHtmlUnitResolver resolver, Type itemType,
      AngularFormatterArgument argument, int argIndex) {
    Expression arg = argument.getExpression();
    // only first argument is special for "filter"
    if (argIndex != 0) {
      resolver.resolveNode(arg);
      return;
    }
    // Map
    if (arg instanceof MapLiteral) {
      List<Expression> expressions = Lists.newArrayList();
      List<MapLiteralEntry> entries = ((MapLiteral) arg).getEntries();
      for (MapLiteralEntry mapEntry : entries) {
        Expression keyExpr = mapEntry.getKey();
        if (keyExpr instanceof SimpleIdentifier) {
          SimpleIdentifier propertyNode = (SimpleIdentifier) keyExpr;
          resolvePropertyNode(resolver, expressions, itemType, propertyNode);
        }
      }
View Full Code Here

  /**
   * Resolves an argument for "orderBy" formatter.
   */
  private void resolveFormatterArgument_orderByWithFilter(AngularHtmlUnitResolver resolver,
      Type itemType, AngularFormatterArgument argument, int argIndex) {
    Expression arg = argument.getExpression();
    // only first argument is special for "orderBy"
    if (argIndex != 0) {
      resolver.resolveNode(arg);
      return;
    }
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.