Package com.google.dart.engine.type

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


      }
      // If this property accessor is based on a field, that field might have a propagated type.
      // In which case we need to check whether the propagated type of the field needs substitution.
      PropertyInducingElement field = baseAccessor.getVariable();
      if (!field.isSynthetic()) {
        Type baseFieldType = field.getPropagatedType();
        if (baseFieldType != null) {
          Type substitutedFieldType = baseFieldType.substitute(argumentTypes, parameterTypes);
          if (!baseFieldType.equals(substitutedFieldType)) {
            return true;
          }
        }
      }
View Full Code Here


      if (catchClause.getOnKeyword() != null) {
        // on-catch clause found, verify that the exception type is not a subtype of a previous
        // on-catch exception type
        TypeName typeName = catchClause.getExceptionType();
        if (typeName != null && typeName.getType() != null) {
          Type currentType = typeName.getType();
          if (currentType.isObject()) {
            // Found catch clause clause that has Object as an exception type, this is equivalent to
            // having a catch clause that doesn't have an exception type, visit the block, but
            // generate an error on any following catch clauses (and don't visit them).
            safelyVisit(catchClause);
            if (i + 1 != numOfCatchClauses) {
              // this catch clause is not the last in the try statement
              CatchClause nextCatchClause = catchClauses.get(i + 1);
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = nextCatchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
                  offset,
                  length);
              return null;
            }
          }
          for (Type type : visitedTypes) {
            if (currentType.isSubtypeOf(type)) {
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = catchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_ON_CATCH_SUBTYPE,
                  offset,
                  length,
                  currentType.getDisplayName(),
                  type.getDisplayName());
              return null;
            }
          }
          visitedTypes.add(currentType);
View Full Code Here

    }
    // Check if parameter type depends on defining type type arguments.
    // It is possible that we did not resolve field formal parameter yet, so skip this check for it.
    boolean isFieldFormal = baseParameter instanceof FieldFormalParameterElement;
    if (!isFieldFormal) {
      Type baseType = baseParameter.getType();
      Type[] argumentTypes = definingType.getTypeArguments();
      Type[] parameterTypes = TypeParameterTypeImpl.getTypes(definingType.getTypeParameters());
      Type substitutedType = baseType.substitute(argumentTypes, parameterTypes);
      if (baseType.equals(substitutedType)) {
        return baseParameter;
      }
    }
    // TODO(brianwilkerson) Consider caching the substituted type in the instance. It would use more
View Full Code Here

   */
  private static boolean isChangedByTypeSubstitution(FieldElement baseField,
      InterfaceType definingType) {
    Type[] argumentTypes = definingType.getTypeArguments();
    if (baseField != null && argumentTypes.length != 0) {
      Type baseType = baseField.getType();
      Type[] parameterTypes = definingType.getElement().getType().getTypeArguments();
      if (baseType != null) {
        Type substitutedType = baseType.substitute(argumentTypes, parameterTypes);
        if (!baseType.equals(substitutedType)) {
          return true;
        }
      }
      // If the field has a propagated type, then we need to check whether the propagated type
      // needs substitution.
      Type basePropagatedType = baseField.getPropagatedType();
      if (basePropagatedType != null) {
        Type substitutedPropagatedType = basePropagatedType.substitute(
            argumentTypes,
            parameterTypes);
        if (!basePropagatedType.equals(substitutedPropagatedType)) {
          return true;
        }
View Full Code Here

        return false;
      }

      private boolean isScope(Expression target) {
        if (target != null) {
          Type type = target.getBestType();
          if (type instanceof InterfaceType) {
            InterfaceType interfaceType = (InterfaceType) type;
            return interfaceType.getName().equals("Scope");
          }
        }
View Full Code Here

        if (target instanceof SimpleIdentifier) {
          SimpleIdentifier identifier = (SimpleIdentifier) target;
          Element element = identifier.getStaticElement();
          if (element instanceof VariableElement) {
            VariableElement variable = (VariableElement) element;
            Type type = variable.getType();
            if (type instanceof InterfaceType) {
              InterfaceType interfaceType = (InterfaceType) type;
              return interfaceType.getName().equals("ViewFactory");
            }
          }
View Full Code Here

   * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE
   */
  private boolean checkAllTypeChecks(IsExpression node) {
    Expression expression = node.getExpression();
    TypeName typeName = node.getType();
    Type lhsType = expression.getStaticType();
    Type rhsType = typeName.getType();
    if (lhsType == null || rhsType == null) {
      return false;
    }
    String rhsNameStr = typeName.getName().getName();
    // if x is dynamic
    if ((rhsType.isDynamic() && rhsNameStr.equals(Keyword.DYNAMIC.getSyntax()))) {
      if (node.getNotOperator() == null) {
        // the is case
        errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
      } else {
        // the is not case
        errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node);
      }
      return true;
    }
    Element rhsElement = rhsType.getElement();
    LibraryElement libraryElement = rhsElement != null ? rhsElement.getLibrary() : null;
    if (libraryElement != null && libraryElement.isDartCore()) {
      // if x is Object or null is Null
      if (rhsType.isObject()
          || (expression instanceof NullLiteral && rhsNameStr.equals(NULL_TYPE_NAME))) {
        if (node.getNotOperator() == null) {
          // the is case
          errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
        } else {
View Full Code Here

    }
    //
    // Hint case: test propagated type information
    //
    // Compute the best types to use.
    Type expectedBestType = expectedPropagatedType != null ? expectedPropagatedType
        : expectedStaticType;
    Type actualBestType = actualPropagatedType != null ? actualPropagatedType : actualStaticType;

    if (actualBestType != null && expectedBestType != null) {
      if (!actualBestType.isAssignableTo(expectedBestType)) {
        errorReporter.reportTypeErrorForNode(hintCode, expression, actualBestType, expectedBestType);
        return true;
      }
    }
    return false;
View Full Code Here

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

  private boolean checkForInvalidAssignment(Expression lhs, Expression rhs) {
    if (lhs == null || rhs == null) {
      return false;
    }
    VariableElement leftVariableElement = ErrorVerifier.getVariableElement(lhs);
    Type leftType = (leftVariableElement == null) ? ErrorVerifier.getStaticType(lhs)
        : leftVariableElement.getType();
    Type staticRightType = ErrorVerifier.getStaticType(rhs);
    if (!staticRightType.isAssignableTo(leftType)) {
      // The warning was generated on this rhs
      return false;
    }
    // Test for, and then generate the hint
    Type bestRightType = rhs.getBestType();
    if (leftType != null && bestRightType != null) {
      if (!bestRightType.isAssignableTo(leftType)) {
        errorReporter.reportTypeErrorForNode(
            HintCode.INVALID_ASSIGNMENT,
            rhs,
            bestRightType,
            leftType);
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.