Package com.google.dart.engine.internal.object

Examples of com.google.dart.engine.internal.object.DartObjectImpl


   *         value
   */
  private ValidResult getConstantBooleanValue(Expression expression) {
    if (expression instanceof BooleanLiteral) {
      if (((BooleanLiteral) expression).getValue()) {
        return new ValidResult(new DartObjectImpl(null, BoolState.from(true)));
      } else {
        return new ValidResult(new DartObjectImpl(null, BoolState.from(false)));
      }
    }
    // Don't consider situations where we could evaluate to a constant boolean expression with the
    // ConstantVisitor
//    else {
View Full Code Here


      constantField.setType(enumType);
      //
      // Create a value for the constant.
      //
      HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjectImpl>();
      fieldMap.put(indexFieldName, new DartObjectImpl(intType, new IntState(BigInteger.valueOf(i))));
      DartObjectImpl value = new DartObjectImpl(enumType, new GenericState(fieldMap));
      constantField.setEvaluationResult(new ValidResult(value));
      fields.add(constantField);
      getters.add(createGetter(constantField));
      constantName.setStaticElement(constantField);
    }
View Full Code Here

   * @param namedArgumentValues Named parameters passed to fromEnvironment()
   * @return A {@link ValidResult} object corresponding to the evaluated result
   */
  private ValidResult computeValueFromEnvironment(DartObject environmentValue,
      DartObjectImpl builtInDefaultValue, HashMap<String, DartObjectImpl> namedArgumentValues) {
    DartObjectImpl value = (DartObjectImpl) environmentValue;
    if (value.isUnknown() || value.isNull()) {
      // The name either doesn't exist in the environment or we couldn't parse the corresponding
      // value.  If the code supplied an explicit default, use it.
      if (namedArgumentValues.containsKey(DEFAULT_VALUE_PARAM)) {
        value = namedArgumentValues.get(DEFAULT_VALUE_PARAM);
      } else if (value.isNull()) {
        // The code didn't supply an explicit default.  The name exists in the environment but
        // we couldn't parse the corresponding value.  So use the built-in default value, because
        // this is what the VM does.
        value = builtInDefaultValue;
      } else {
View Full Code Here

        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);
        }
      } else if (initializer instanceof SuperConstructorInvocation) {
        SuperConstructorInvocation superConstructorInvocation = (SuperConstructorInvocation) initializer;
View Full Code Here

   * @param variableName the name of the variable whose value is to be returned
   */
  public DartObject getBool(TypeProvider typeProvider, String variableName) {
    String value = declaredVariables.get(variableName);
    if (value == null) {
      return new DartObjectImpl(typeProvider.getBoolType(), BoolState.UNKNOWN_VALUE);
    }
    if (value.equals("true")) {
      return new DartObjectImpl(typeProvider.getBoolType(), BoolState.TRUE_STATE);
    } else if (value.equals("false")) {
      return new DartObjectImpl(typeProvider.getBoolType(), BoolState.FALSE_STATE);
    }
    return new DartObjectImpl(typeProvider.getNullType(), NullState.NULL_STATE);
  }
View Full Code Here

   * @param variableName the name of the variable whose value is to be returned
   */
  public DartObject getInt(TypeProvider typeProvider, String variableName) {
    String value = declaredVariables.get(variableName);
    if (value == null) {
      return new DartObjectImpl(typeProvider.getIntType(), IntState.UNKNOWN_VALUE);
    }
    BigInteger bigInteger;
    try {
      bigInteger = new BigInteger(value);
    } catch (NumberFormatException exception) {
      return new DartObjectImpl(typeProvider.getNullType(), NullState.NULL_STATE);
    }
    return new DartObjectImpl(typeProvider.getIntType(), new IntState(bigInteger));
  }
View Full Code Here

   * @param variableName the name of the variable whose value is to be returned
   */
  public DartObject getString(TypeProvider typeProvider, String variableName) {
    String value = declaredVariables.get(variableName);
    if (value == null) {
      return new DartObjectImpl(typeProvider.getIntType(), IntState.UNKNOWN_VALUE);
    }
    return new DartObjectImpl(typeProvider.getStringType(), new StringState(value));
  }
View Full Code Here

   *
   * @return an object representing the value 'null'
   */
  DartObjectImpl getNull() {
    if (nullObject == null) {
      nullObject = new DartObjectImpl(typeProvider.getNullType(), NullState.NULL_STATE);
    }
    return nullObject;
  }
View Full Code Here

    }
    return nullObject;
  }

  ValidResult valid(InterfaceType type, InstanceState state) {
    return new ValidResult(new DartObjectImpl(type, state));
  }
View Full Code Here

      }
    }
  }

  private ValidResult valid(InterfaceType type, InstanceState state) {
    return new ValidResult(new DartObjectImpl(type, state));
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.internal.object.DartObjectImpl

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.