Package com.google.dart.engine.ast

Examples of com.google.dart.engine.ast.AstNode


   */
  private boolean checkForCaseBlockNotTerminated(SwitchCase node) {
    NodeList<Statement> statements = node.getStatements();
    if (statements.isEmpty()) {
      // fall-through without statements at all
      AstNode parent = node.getParent();
      if (parent instanceof SwitchStatement) {
        SwitchStatement switchStatement = (SwitchStatement) parent;
        NodeList<SwitchMember> members = switchStatement.getMembers();
        int index = members.indexOf(node);
        if (index != -1 && index < members.size() - 1) {
View Full Code Here


    for (InterfaceType disallowedType : DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT) {
      if (superType != null && superType.equals(disallowedType)) {
        // if the violating type happens to be 'num', we need to rule out the case where the
        // enclosing class is 'int' or 'double'
        if (superType.equals(typeProvider.getNumType())) {
          AstNode grandParent = typeName.getParent().getParent();
          // Note: this is a corner case that won't happen often, so adding a field currentClass
          // (see currentFunction) to ErrorVerifier isn't worth if for this case, but if the field
          // currentClass is added, then this message should become a todo to not lookup the
          // grandparent node
          if (grandParent instanceof ClassDeclaration) {
View Full Code Here

    Element enclosingElement = element.getEnclosingElement();
    if (!(enclosingElement instanceof ClassElement)) {
      return false;
    }
    // comment
    AstNode parent = node.getParent();
    if (parent instanceof CommentReference) {
      return false;
    }
    // qualified method invocation
    if (parent instanceof MethodInvocation) {
View Full Code Here

   */
  private boolean isUnqualifiedReferenceToNonLocalStaticMemberAllowed(SimpleIdentifier node) {
    if (node.inDeclarationContext()) {
      return true;
    }
    AstNode parent = node.getParent();
    if (parent instanceof ConstructorName || parent instanceof MethodInvocation
        || parent instanceof PropertyAccess || parent instanceof SuperConstructorInvocation) {
      return true;
    }
    if (parent instanceof PrefixedIdentifier
View Full Code Here

    return promoteManager;
  }

  @Override
  public Void visitAnnotation(Annotation node) {
    AstNode parent = node.getParent();
    if (parent == enclosingClassDeclaration || parent == enclosingFunctionTypeAlias) {
      return null;
    }
    return super.visitAnnotation(node);
  }
View Full Code Here

  /**
   * @return {@code true} if given {@link TypeName} is used as a type annotation.
   */
  private static boolean isTypeAnnotation(TypeName node) {
    AstNode parent = node.getParent();
    if (parent instanceof VariableDeclarationList) {
      return ((VariableDeclarationList) parent).getType() == node;
    }
    if (parent instanceof FieldFormalParameter) {
      return ((FieldFormalParameter) parent).getType() == node;
View Full Code Here

      }
      //
      // If not, the look to see whether we might have created the wrong AST structure for a
      // constructor name. If so, fix the AST structure and then proceed.
      //
      AstNode parent = node.getParent();
      if (typeName instanceof PrefixedIdentifier && parent instanceof ConstructorName
          && argumentList == null) {
        ConstructorName name = (ConstructorName) parent;
        if (name.getName() == null) {
          PrefixedIdentifier prefixedIdentifier = (PrefixedIdentifier) typeName;
          SimpleIdentifier prefix = prefixedIdentifier.getPrefix();
          element = getNameScope().lookup(prefix, getDefiningLibrary());
          if (element instanceof PrefixElement) {
            if (parent.getParent() instanceof InstanceCreationExpression
                && ((InstanceCreationExpression) parent.getParent()).isConst()) {
              // If, if this is a const expression, then generate a
              // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
              reportErrorForNode(
                  CompileTimeErrorCode.CONST_WITH_NON_TYPE,
                  prefixedIdentifier.getIdentifier(),
                  prefixedIdentifier.getIdentifier().getName());
            } else {
              // Else, if this expression is a new expression, report a NEW_WITH_NON_TYPE warning.
              reportErrorForNode(
                  StaticWarningCode.NEW_WITH_NON_TYPE,
                  prefixedIdentifier.getIdentifier(),
                  prefixedIdentifier.getIdentifier().getName());
            }
            setElement(prefix, element);
            return null;
          } else if (element != null) {
            //
            // Rewrite the constructor name. The parser, when it sees a constructor named "a.b",
            // cannot tell whether "a" is a prefix and "b" is a class name, or whether "a" is a
            // class name and "b" is a constructor name. It arbitrarily chooses the former, but
            // in this case was wrong.
            //
            name.setName(prefixedIdentifier.getIdentifier());
            name.setPeriod(prefixedIdentifier.getPeriod());
            node.setName(prefix);
            typeName = prefix;
          }
        }
      }
    }
    // check element
    boolean elementValid = !(element instanceof MultiplyDefinedElement);
    if (elementValid && !(element instanceof ClassElement)
        && isTypeNameInInstanceCreationExpression(node)) {
      SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
      InstanceCreationExpression creation = (InstanceCreationExpression) node.getParent().getParent();
      if (creation.isConst()) {
        if (element == null) {
          reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, typeName);
        } else {
          reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, typeName);
        }
        elementValid = false;
      } else {
        if (element != null) {
          reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, typeName);
          elementValid = false;
        }
      }
    }
    if (elementValid && element == null) {
      // We couldn't resolve the type name.
      // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE
      // from the ErrorVerifier, so that we don't have two errors on a built in identifier being
      // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
      SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
      RedirectingConstructorKind redirectingConstructorKind;
      if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
        reportErrorForNode(
            CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE,
            typeName,
            typeName.getName());
      } else if (typeNameSimple.getName().equals("boolean")) {
        reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple);
      } else if (isTypeNameInCatchClause(node)) {
        reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, typeName.getName());
      } else if (isTypeNameInAsExpression(node)) {
        reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, typeName.getName());
      } else if (isTypeNameInIsExpression(node)) {
        reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, typeName.getName());
      } else if ((redirectingConstructorKind = getRedirectingConstructorKind(node)) != null) {
        ErrorCode errorCode = redirectingConstructorKind == RedirectingConstructorKind.CONST
            ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarningCode.REDIRECT_TO_NON_CLASS;
        reportErrorForNode(errorCode, typeName, typeName.getName());
      } else if (isTypeNameInTypeArgumentList(node)) {
        reportErrorForNode(
            StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
            typeName,
            typeName.getName());
      } else {
        reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS, typeName, typeName.getName());
      }
      elementValid = false;
    }
    if (!elementValid) {
      if (element instanceof MultiplyDefinedElement) {
        setElement(typeName, element);
      } else {
        setElement(typeName, dynamicType.getElement());
      }
      typeName.setStaticType(dynamicType);
      node.setType(dynamicType);
      return null;
    }
    Type type = null;
    if (element instanceof ClassElement) {
      setElement(typeName, element);
      type = ((ClassElement) element).getType();
    } else if (element instanceof FunctionTypeAliasElement) {
      setElement(typeName, element);
      type = ((FunctionTypeAliasElement) element).getType();
    } else if (element instanceof TypeParameterElement) {
      setElement(typeName, element);
      type = ((TypeParameterElement) element).getType();
      if (argumentList != null) {
        // Type parameters cannot have type arguments.
        // TODO(brianwilkerson) Report this error.
//      resolver.reportError(ResolverErrorCode.?, keyType);
      }
    } else if (element instanceof MultiplyDefinedElement) {
      Element[] elements = ((MultiplyDefinedElement) element).getConflictingElements();
      type = getTypeWhenMultiplyDefined(elements);
      if (type != null) {
        node.setType(type);
      }
    } else {
      // The name does not represent a type.
      RedirectingConstructorKind redirectingConstructorKind;
      if (isTypeNameInCatchClause(node)) {
        reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, typeName.getName());
      } else if (isTypeNameInAsExpression(node)) {
        reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, typeName.getName());
      } else if (isTypeNameInIsExpression(node)) {
        reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, typeName.getName());
      } else if ((redirectingConstructorKind = getRedirectingConstructorKind(node)) != null) {
        ErrorCode errorCode = redirectingConstructorKind == RedirectingConstructorKind.CONST
            ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarningCode.REDIRECT_TO_NON_CLASS;
        reportErrorForNode(errorCode, typeName, typeName.getName());
      } else if (isTypeNameInTypeArgumentList(node)) {
        reportErrorForNode(
            StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
            typeName,
            typeName.getName());
      } else {
        AstNode parent = typeName.getParent();
        while (parent instanceof TypeName) {
          parent = parent.getParent();
        }
        if (parent instanceof ExtendsClause || parent instanceof ImplementsClause
            || parent instanceof WithClause || parent instanceof ClassTypeAlias) {
          // Ignored. The error will be reported elsewhere.
        } else {
View Full Code Here

   * @param node the type name with the wrong number of type arguments
   * @return the error code that should be used to report that the wrong number of type arguments
   *         were provided
   */
  private ErrorCode getInvalidTypeParametersErrorCode(TypeName node) {
    AstNode parent = node.getParent();
    if (parent instanceof ConstructorName) {
      parent = parent.getParent();
      if (parent instanceof InstanceCreationExpression) {
        if (((InstanceCreationExpression) parent).isConst()) {
          return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS;
        } else {
          return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS;
View Full Code Here

   * @param typeName the type name to analyze
   * @return some {@link RedirectingConstructorKind} if the given type name is used as the type in a
   *         redirected constructor, or {@code null} otherwise
   */
  private RedirectingConstructorKind getRedirectingConstructorKind(TypeName typeName) {
    AstNode parent = typeName.getParent();
    if (parent instanceof ConstructorName) {
      ConstructorName constructorName = (ConstructorName) parent;
      parent = constructorName.getParent();
      if (parent instanceof ConstructorDeclaration) {
        ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) parent;
View Full Code Here

   *
   * @param typeName the type name to analyzer
   * @return {@code true} if the given type name is used as the type in an as expression
   */
  private boolean isTypeNameInAsExpression(TypeName typeName) {
    AstNode parent = typeName.getParent();
    if (parent instanceof AsExpression) {
      AsExpression asExpression = (AsExpression) parent;
      return asExpression.getType() == typeName;
    }
    return false;
View Full Code Here

TOP

Related Classes of com.google.dart.engine.ast.AstNode

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.