Package com.google.dart.engine.element

Examples of com.google.dart.engine.element.ParameterElement


    return getBaseElement().isInitializingFormal();
  }

  @Override
  public String toString() {
    ParameterElement baseElement = getBaseElement();
    String left = "";
    String right = "";
    switch (baseElement.getParameterKind()) {
      case NAMED:
        left = "{";
        right = "}";
        break;
      case POSITIONAL:
        left = "[";
        right = "]";
        break;
      case REQUIRED:
        // No need to change the default.
        break;
    }
    StringBuilder builder = new StringBuilder();
    builder.append(left);
    builder.append(getType());
    builder.append(" ");
    builder.append(baseElement.getDisplayName());
    builder.append(right);
    return builder.toString();
  }
View Full Code Here


  private boolean checkForArgumentTypeNotAssignableForArgument(Expression argument) {
    if (argument == null) {
      return false;
    }

    ParameterElement staticParameterElement = argument.getStaticParameterElement();
    Type staticParameterType = staticParameterElement == null ? null
        : staticParameterElement.getType();

    ParameterElement propagatedParameterElement = argument.getPropagatedParameterElement();
    Type propagatedParameterType = propagatedParameterElement == null ? null
        : propagatedParameterElement.getType();

    return checkForArgumentTypeNotAssignableWithExpectedTypes(
        argument,
        staticParameterType,
        propagatedParameterType,
View Full Code Here

    return super.visitExportDirective(node);
  }

  @Override
  public Void visitFormalParameter(FormalParameter node) {
    ParameterElement element = node.getElement();
    enterScope(element);
    try {
      return super.visitFormalParameter(node);
    } finally {
      exitScope();
View Full Code Here

      ConstructorElementImpl constructor = (ConstructorElementImpl) declaration.getElement();
      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);
        }
View Full Code Here

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

   *
   * @return the parameter element representing the parameter to which the value of this expression
   *         will be bound
   */
  public ParameterElement getBestParameterElement() {
    ParameterElement propagatedElement = getPropagatedParameterElement();
    if (propagatedElement != null) {
      return propagatedElement;
    }
    return getStaticParameterElement();
  }
View Full Code Here

        // this could be reached.
        continue;
      }
      if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) {
        // lookup the parameter for the error to select
        ParameterElement parameterToSelect = null;
        AstNode parameterLocationToSelect = null;
        for (int i = 0; i < parameters.length; i++) {
          ParameterElement parameter = parameters[i];
          if (parameter.getParameterKind() == ParameterKind.NAMED
              && overriddenNamedPTEntry.getKey().equals(parameter.getName())) {
            parameterToSelect = parameter;
            parameterLocationToSelect = parameterLocations[i];
            break;
          }
        }
        if (parameterToSelect != null) {
          errorReporter.reportTypeErrorForNode(
              StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE,
              parameterLocationToSelect,
              overridingType,
              overriddenNamedPTEntry.getValue(),
              overriddenExecutable.getEnclosingElement().getDisplayName());
          return true;
        }
      }
    }
    // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES
    //
    // Create three arrays: an array of the optional parameter ASTs (FormalParameters), an array of
    // the optional parameters elements from our method, and finally an array of the optional
    // parameter elements from the method we are overriding.
    //
    boolean foundError = false;
    ArrayList<AstNode> formalParameters = new ArrayList<AstNode>();
    ArrayList<ParameterElementImpl> parameterElts = new ArrayList<ParameterElementImpl>();
    ArrayList<ParameterElementImpl> overriddenParameterElts = new ArrayList<ParameterElementImpl>();
    ParameterElement[] overriddenPEs = overriddenExecutable.getParameters();
    for (int i = 0; i < parameters.length; i++) {
      ParameterElement parameter = parameters[i];
      if (parameter.getParameterKind().isOptional()) {
        formalParameters.add(parameterLocations[i]);
        parameterElts.add((ParameterElementImpl) parameter);
      }
    }
    for (ParameterElement parameterElt : overriddenPEs) {
View Full Code Here

  private boolean checkForArgumentTypeNotAssignableForArgument(Expression argument) {
    if (argument == null) {
      return false;
    }

    ParameterElement staticParameterElement = argument.getStaticParameterElement();
    Type staticParameterType = staticParameterElement == null ? null
        : staticParameterElement.getType();

    return checkForArgumentTypeNotAssignableWithExpectedTypes(
        argument,
        staticParameterType,
        StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE);
View Full Code Here

  private boolean checkForIntNotAssignable(Expression argument) {
    if (argument == null) {
      return false;
    }

    ParameterElement staticParameterElement = argument.getStaticParameterElement();
    Type staticParameterType = staticParameterElement == null ? null
        : staticParameterElement.getType();

    return checkForArgumentTypeNotAssignable(
        argument,
        staticParameterType,
        intType,
View Full Code Here

        name.getName());
    return true;
  }

  private void checkForValidField(FieldFormalParameter node) {
    ParameterElement element = node.getElement();
    if (element instanceof FieldFormalParameterElement) {
      FieldElement fieldElement = ((FieldFormalParameterElement) element).getField();
      if (fieldElement == null || fieldElement.isSynthetic()) {
        errorReporter.reportErrorForNode(
            CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTANT_FIELD,
            node,
            node.getIdentifier().getName());
      } else {
        ParameterElement parameterElement = node.getElement();
        if (parameterElement instanceof FieldFormalParameterElementImpl) {
          FieldFormalParameterElementImpl fieldFormal = (FieldFormalParameterElementImpl) parameterElement;
          Type declaredType = fieldFormal.getType();
          Type fieldType = fieldElement.getType();
          if (fieldElement.isSynthetic()) {
View Full Code Here

TOP

Related Classes of com.google.dart.engine.element.ParameterElement

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.