Package com.google.dart.engine.internal.constant

Examples of com.google.dart.engine.internal.constant.EvaluationResultImpl


    this.source = source;
    this.typeProvider = typeProvider;
  }

  public EvaluationResult evaluate(Expression expression) {
    EvaluationResultImpl result = expression.accept(new ConstantVisitor(typeProvider));
    if (result instanceof ValidResult) {
      return EvaluationResult.forValue(((ValidResult) result).getValue());
    }
    ArrayList<AnalysisError> errors = new ArrayList<AnalysisError>();
    for (ErrorResult.ErrorData data : ((ErrorResult) result).getErrorData()) {
View Full Code Here


  @Override
  public Void visitListLiteral(ListLiteral node) {
    super.visitListLiteral(node);
    if (node.getConstKeyword() != null) {
      EvaluationResultImpl result;
      for (Expression element : node.getElements()) {
        result = validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
        if (result instanceof ValidResult) {
          reportErrorIfFromDeferredLibrary(
              element,
View Full Code Here

    HashSet<DartObject> keys = new HashSet<DartObject>();
    ArrayList<Expression> invalidKeys = new ArrayList<Expression>();
    for (MapLiteralEntry entry : node.getEntries()) {
      Expression key = entry.getKey();
      if (isConst) {
        EvaluationResultImpl keyResult = validate(key, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY);
        Expression valueExpression = entry.getValue();
        EvaluationResultImpl valueResult = validate(
            valueExpression,
            CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
        if (valueResult instanceof ValidResult) {
          reportErrorIfFromDeferredLibrary(
              valueExpression,
              CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY);
        }
        if (keyResult instanceof ValidResult) {
          reportErrorIfFromDeferredLibrary(
              key,
              CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY);
          DartObject value = ((ValidResult) keyResult).getValue();
          if (keys.contains(value)) {
            invalidKeys.add(key);
          } else {
            keys.add(value);
          }
          Type type = value.getType();
          if (implementsEqualsWhenNotAllowed(type)) {
            errorReporter.reportErrorForNode(
                CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS,
                key,
                type.getDisplayName());
          }
        }
      } else {
        EvaluationResultImpl result = key.accept(new ConstantVisitor(typeProvider));
        if (result instanceof ValidResult) {
          DartObject value = ((ValidResult) result).getValue();
          if (keys.contains(value)) {
            invalidKeys.add(key);
          } else {
View Full Code Here

    Type firstType = null;
    for (SwitchMember switchMember : switchMembers) {
      if (switchMember instanceof SwitchCase) {
        SwitchCase switchCase = (SwitchCase) switchMember;
        Expression expression = switchCase.getExpression();
        EvaluationResultImpl caseResult = validate(
            expression,
            CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION);
        if (caseResult instanceof ValidResult) {
          reportErrorIfFromDeferredLibrary(
              expression,
View Full Code Here

  public Void visitVariableDeclaration(VariableDeclaration node) {
    super.visitVariableDeclaration(node);
    Expression initializer = node.getInitializer();
    if (initializer != null && node.isConst()) {
      VariableElementImpl element = (VariableElementImpl) node.getElement();
      EvaluationResultImpl result = element.getEvaluationResult();
      if (result == null) {
        //
        // Normally we don't need to visit const variable declarations because we have already
        // computed their values. But if we missed it for some reason, this gives us a second
        // chance.
View Full Code Here

   * @param expression the expression to be validated
   * @param errorCode the error code to be used if the expression is not a compile time constant
   * @return the value of the compile time constant
   */
  private EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) {
    EvaluationResultImpl result = expression.accept(new ConstantVisitor(typeProvider));
    reportErrors(result, errorCode);
    return result;
  }
View Full Code Here

    for (FormalParameter parameter : parameters.getParameters()) {
      if (parameter instanceof DefaultFormalParameter) {
        DefaultFormalParameter defaultParameter = (DefaultFormalParameter) parameter;
        Expression defaultValue = defaultParameter.getDefaultValue();
        if (defaultValue != null) {
          EvaluationResultImpl result = validate(
              defaultValue,
              CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE);
          VariableElementImpl element = (VariableElementImpl) parameter.getElement();
          element.setEvaluationResult(result);
          if (result instanceof ValidResult) {
View Full Code Here

        FieldDeclaration fieldDeclaration = (FieldDeclaration) member;
        if (!fieldDeclaration.isStatic()) {
          for (VariableDeclaration variableDeclaration : fieldDeclaration.getFields().getVariables()) {
            Expression initializer = variableDeclaration.getInitializer();
            if (initializer != null) {
              EvaluationResultImpl result = initializer.accept(new ConstantVisitor(typeProvider));
              if (!(result instanceof ValidResult)) {
                errorReporter.reportErrorForNode(
                    CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST,
                    errorSite,
                    variableDeclaration.getName().getName());
View Full Code Here

   *          considered as a valid potentially constant expressions
   * @param expression the expression to validate
   */
  private void validateInitializerExpression(final ParameterElement[] parameterElements,
      Expression expression) {
    EvaluationResultImpl result = expression.accept(new ConstantVisitor(typeProvider) {
      @Override
      public EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
        Element element = node.getStaticElement();
        for (ParameterElement parameterElement : parameterElements) {
          if (parameterElement == element && parameterElement != null) {
View Full Code Here

    if (parameterElts.size() > 0) {
      if (parameterElts.get(0).getParameterKind() == ParameterKind.NAMED) {
        // Named parameters, consider the names when matching the parameterElts to the overriddenParameterElts
        for (int i = 0; i < parameterElts.size(); i++) {
          ParameterElementImpl parameterElt = parameterElts.get(i);
          EvaluationResultImpl result = parameterElt.getEvaluationResult();
          // TODO (jwren) Ignore Object types, see Dart bug 11287
          if (isUserDefinedObject(result)) {
            continue;
          }
          String parameterName = parameterElt.getName();
          for (int j = 0; j < overriddenParameterElts.size(); j++) {
            ParameterElementImpl overriddenParameterElt = overriddenParameterElts.get(j);
            String overriddenParameterName = overriddenParameterElt.getName();
            if (parameterName != null && parameterName.equals(overriddenParameterName)) {
              EvaluationResultImpl overriddenResult = overriddenParameterElt.getEvaluationResult();
              if (isUserDefinedObject(overriddenResult)) {
                break;
              }
              if (!result.equalValues(typeProvider, overriddenResult)) {
                errorReporter.reportErrorForNode(
                    StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED,
                    formalParameters.get(i),
                    overriddenExecutable.getEnclosingElement().getDisplayName(),
                    overriddenExecutable.getDisplayName(),
                    parameterName);
                foundError = true;
              }
            }
          }
        }
      } else {
        // Positional parameters, consider the positions when matching the parameterElts to the overriddenParameterElts
        for (int i = 0; i < parameterElts.size() && i < overriddenParameterElts.size(); i++) {
          ParameterElementImpl parameterElt = parameterElts.get(i);
          EvaluationResultImpl result = parameterElt.getEvaluationResult();
          // TODO (jwren) Ignore Object types, see Dart bug 11287
          if (isUserDefinedObject(result)) {
            continue;
          }
          ParameterElementImpl overriddenParameterElt = overriddenParameterElts.get(i);
          EvaluationResultImpl overriddenResult = overriddenParameterElt.getEvaluationResult();
          if (isUserDefinedObject(overriddenResult)) {
            continue;
          }
          if (!result.equalValues(typeProvider, overriddenResult)) {
            errorReporter.reportErrorForNode(
View Full Code Here

TOP

Related Classes of com.google.dart.engine.internal.constant.EvaluationResultImpl

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.