Package com.google.dart.engine.type

Examples of com.google.dart.engine.type.Type


  /**
   * Support for <code>$event</code> variable in <code>NgEventDirective</code>.
   */
  private void onNgEventDirective(AngularHtmlUnitResolver resolver) {
    if (element.isClass("NgEventDirective")) {
      Type dynamicType = resolver.getTypeProvider().getDynamicType();
      resolver.defineVariable(resolver.createLocalVariableWithName(dynamicType, "$event"));
    }
  }
View Full Code Here


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

    // TODO(paulberry): to minimize error messages, it would be nice to
    // compare all types with the most popular type rather than the first
    // type.
    NodeList<SwitchMember> switchMembers = node.getMembers();
    boolean foundError = false;
    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,
              CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY);
          DartObject value = ((ValidResult) caseResult).getValue();
          if (firstType == null) {
            firstType = value.getType();
          } else {
            Type nType = value.getType();
            if (!firstType.equals(nType)) {
              errorReporter.reportErrorForNode(
                  CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
                  expression,
                  expression.toSource(),
View Full Code Here

      @Override
      public EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
        Element element = node.getStaticElement();
        for (ParameterElement parameterElement : parameterElements) {
          if (parameterElement == element && parameterElement != null) {
            Type type = parameterElement.getType();
            if (type != null) {
              if (type.isDynamic()) {
                return valid(typeProvider.getObjectType(), DynamicState.DYNAMIC_STATE);
              } else if (type.isSubtypeOf(boolType)) {
                return valid(typeProvider.getBoolType(), BoolState.UNKNOWN_VALUE);
              } else if (type.isSubtypeOf(typeProvider.getDoubleType())) {
                return valid(typeProvider.getDoubleType(), DoubleState.UNKNOWN_VALUE);
              } else if (type.isSubtypeOf(intType)) {
                return valid(typeProvider.getIntType(), IntState.UNKNOWN_VALUE);
              } else if (type.isSubtypeOf(numType)) {
                return valid(typeProvider.getNumType(), NumState.UNKNOWN_VALUE);
              } else if (type.isSubtypeOf(stringType)) {
                return valid(typeProvider.getStringType(), StringState.UNKNOWN_VALUE);
              }
              //
              // We don't test for other types of objects (such as List, Map, Function or Type)
              // because there are no operations allowed on such types other than '==' and '!=',
View Full Code Here

   *
   * @param expression the expression whose type is to be returned
   * @return the static type of the given expression
   */
  public static Type getStaticType(Expression expression) {
    Type type = expression.getStaticType();
    if (type == null) {
      // TODO(brianwilkerson) This should never happen.
      return DynamicTypeImpl.getInstance();
    }
    return type;
View Full Code Here

    boolean wasInGenerator = inGenerator;
    try {
      inAsync = node.isAsynchronous();
      inGenerator = node.isGenerator();
      FunctionType functionType = enclosingFunction == null ? null : enclosingFunction.getType();
      Type expectedReturnType = functionType == null ? DynamicTypeImpl.getInstance()
          : functionType.getReturnType();
      checkForReturnOfInvalidType(node.getExpression(), expectedReturnType);
      return super.visitExpressionFunctionBody(node);
    } finally {
      inAsync = wasInAsync;
View Full Code Here

  }

  @Override
  public Void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
    Expression functionExpression = node.getFunction();
    Type expressionType = functionExpression.getStaticType();
    if (!isFunctionType(expressionType)) {
      errorReporter.reportErrorForNode(
          StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION,
          functionExpression);
    }
View Full Code Here

  public Void visitInstanceCreationExpression(InstanceCreationExpression node) {
    isInConstInstanceCreation = node.isConst();
    try {
      ConstructorName constructorName = node.getConstructorName();
      TypeName typeName = constructorName.getType();
      Type type = typeName.getType();
      if (type instanceof InterfaceType) {
        InterfaceType interfaceType = (InterfaceType) type;
        checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
        checkForConstOrNewWithEnum(node, typeName, interfaceType);
        if (isInConstInstanceCreation) {
View Full Code Here

    if (overridingFT == null || overriddenFT == null) {
      return false;
    }

    Type overridingFTReturnType = overridingFT.getReturnType();
    Type overriddenFTReturnType = overriddenFT.getReturnType();
    Type[] overridingNormalPT = overridingFT.getNormalParameterTypes();
    Type[] overriddenNormalPT = overriddenFT.getNormalParameterTypes();
    Type[] overridingPositionalPT = overridingFT.getOptionalParameterTypes();
    Type[] overriddenPositionalPT = overriddenFT.getOptionalParameterTypes();
    Map<String, Type> overridingNamedPT = overridingFT.getNamedParameterTypes();
    Map<String, Type> overriddenNamedPT = overriddenFT.getNamedParameterTypes();

    // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and CTEC.INVALID_OVERRIDE_NAMED
    if (overridingNormalPT.length > overriddenNormalPT.length) {
      errorReporter.reportErrorForNode(
          StaticWarningCode.INVALID_OVERRIDE_REQUIRED,
          errorNameTarget,
          overriddenNormalPT.length,
          overriddenExecutable.getEnclosingElement().getDisplayName());
      return true;
    }
    if (overridingNormalPT.length + overridingPositionalPT.length < overriddenPositionalPT.length
        + overriddenNormalPT.length) {
      errorReporter.reportErrorForNode(
          StaticWarningCode.INVALID_OVERRIDE_POSITIONAL,
          errorNameTarget,
          overriddenPositionalPT.length + overriddenNormalPT.length,
          overriddenExecutable.getEnclosingElement().getDisplayName());
      return true;
    }
    // For each named parameter in the overridden method, verify that there is the same name in
    // the overriding method, and in the same order.
    Set<String> overridingParameterNameSet = overridingNamedPT.keySet();
    Iterator<String> overriddenParameterNameIterator = overriddenNamedPT.keySet().iterator();
    while (overriddenParameterNameIterator.hasNext()) {
      String overriddenParamName = overriddenParameterNameIterator.next();
      if (!overridingParameterNameSet.contains(overriddenParamName)) {
        // The overridden method expected the overriding method to have overridingParamName,
        // but it does not.
        errorReporter.reportErrorForNode(
            StaticWarningCode.INVALID_OVERRIDE_NAMED,
            errorNameTarget,
            overriddenParamName,
            overriddenExecutable.getEnclosingElement().getDisplayName());
        return true;
      }
    }

    // SWC.INVALID_METHOD_OVERRIDE_*

    // The following (comparing the function types with isSubtypeOf):
    // !overridingFT.isSubtypeOf(overriddenFT)
    // is equivalent to the following checks, we break it is split up for the purposes of
    // providing better error messages.

    // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE
    if (!overriddenFTReturnType.equals(VoidTypeImpl.getInstance())
        && !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) {
      errorReporter.reportTypeErrorForNode(
          !isGetter ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE
              : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
          errorNameTarget,
          overridingFTReturnType,
          overriddenFTReturnType,
          overriddenExecutable.getEnclosingElement().getDisplayName());
      return true;
    }

    // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
    if (parameterLocations == null) {
      return false;
    }
    int parameterIndex = 0;
    for (int i = 0; i < overridingNormalPT.length; i++) {
      if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) {
        errorReporter.reportTypeErrorForNode(
            !isSetter ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
                : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE,
            parameterLocations[parameterIndex],
            overridingNormalPT[i],
            overriddenNormalPT[i],
            overriddenExecutable.getEnclosingElement().getDisplayName());
        return true;
      }
      parameterIndex++;
    }

    // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE
    for (int i = 0; i < overriddenPositionalPT.length; i++) {
      if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i])) {
        errorReporter.reportTypeErrorForNode(
            StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE,
            parameterLocations[parameterIndex],
            overridingPositionalPT[i],
            overriddenPositionalPT[i],
            overriddenExecutable.getEnclosingElement().getDisplayName());
        return true;
      }
      parameterIndex++;
    }

    // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES
    Iterator<Entry<String, Type>> overriddenNamedPTIterator = overriddenNamedPT.entrySet().iterator();
    while (overriddenNamedPTIterator.hasNext()) {
      Entry<String, Type> overriddenNamedPTEntry = overriddenNamedPTIterator.next();
      Type overridingType = overridingNamedPT.get(overriddenNamedPTEntry.getKey());
      if (overridingType == null) {
        // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been created above if
        // this could be reached.
        continue;
      }
View Full Code Here

    if (withClause == null) {
      return false;
    }
    boolean problemReported = false;
    for (TypeName mixinName : withClause.getMixinTypes()) {
      Type mixinType = mixinName.getType();
      if (!(mixinType instanceof InterfaceType)) {
        continue;
      }
      if (checkForExtendsOrImplementsDisallowedClass(
          mixinName,
View Full Code Here

TOP

Related Classes of com.google.dart.engine.type.Type

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.