Package com.google.dart.engine.ast

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


      return node.getElement();
    }

    @Override
    public Element visitIdentifier(Identifier node) {
      AstNode parent = node.getParent();
      // Type name in Annotation
      if (parent instanceof Annotation) {
        Annotation annotation = (Annotation) parent;
        if (annotation.getName() == node && annotation.getConstructorName() == null) {
          return annotation.getElement();
        }
      }
      // Extra work to map Constructor Declarations to their associated Constructor Elements
      if (parent instanceof ConstructorDeclaration) {
        ConstructorDeclaration decl = (ConstructorDeclaration) parent;
        Identifier returnType = decl.getReturnType();
        if (returnType == node) {
          SimpleIdentifier name = decl.getName();
          if (name != null) {
            return name.getBestElement();
          }
          Element element = node.getBestElement();
          if (element instanceof ClassElement) {
            return ((ClassElement) element).getUnnamedConstructor();
          }
        }
      }
      if (parent instanceof LibraryIdentifier) {
        AstNode grandParent = ((LibraryIdentifier) parent).getParent();
        if (grandParent instanceof PartOfDirective) {
          Element element = ((PartOfDirective) grandParent).getElement();
          if (element instanceof LibraryElement) {
            return ((LibraryElement) element).getDefiningCompilationUnit();
          }
View Full Code Here


      return node.getBestElement();
    }

    @Override
    public Element visitStringLiteral(StringLiteral node) {
      AstNode parent = node.getParent();
      if (parent instanceof UriBasedDirective) {
        return ((UriBasedDirective) parent).getUriElement();
      }
      return null;
    }
View Full Code Here

   * @param root the root of the AST structure to be visited
   */
  public void visitAllNodes(AstNode root) {
    queue.add(root);
    while (!queue.isEmpty()) {
      AstNode next = queue.removeFirst();
      next.accept(this);
    }
  }
View Full Code Here

    CompilationUnit unit = getUnit();
    if (unit == null) {
      return null;
    }
    int offset = getNameOffset();
    AstNode node = new NodeLocator(offset).searchWithin(unit);
    if (node == null) {
      return null;
    }
    return node.getAncestor(clazz);
  }
View Full Code Here

   */
  private boolean checkForDeprecatedMemberUseAtIdentifier(SimpleIdentifier identifier) {
    if (identifier.inDeclarationContext()) {
      return false;
    }
    AstNode parent = identifier.getParent();
    if ((parent instanceof ConstructorName && identifier == ((ConstructorName) parent).getName())
        || (parent instanceof SuperConstructorInvocation && identifier == ((SuperConstructorInvocation) parent).getConstructorName())
        || parent instanceof HideCombinator) {
      return false;
    }
View Full Code Here

    CompilationUnit unit = parseCompilationUnit(source);
    if (unit == null) {
      return null;
    }
    NodeLocator locator = new NodeLocator(element.getNameOffset());
    AstNode nameNode = locator.searchWithin(unit);
    while (nameNode != null) {
      if (nameNode instanceof AnnotatedNode) {
        Comment comment = ((AnnotatedNode) nameNode).getDocumentationComment();
        if (comment == null) {
          return null;
        }
        StringBuilder builder = new StringBuilder();
        Token[] tokens = comment.getTokens();
        for (int i = 0; i < tokens.length; i++) {
          if (i > 0) {
            builder.append("\n");
          }
          builder.append(tokens[i].getLexeme());
        }
        return builder.toString();
      }
      nameNode = nameNode.getParent();
    }
    return null;
  }
View Full Code Here

      throw new AnalysisException("Cannot create scope: node is null");
    } else if (node instanceof CompilationUnit) {
      ScopeBuilder builder = new ScopeBuilder(errorListener);
      return builder.scopeForAstNode(node);
    }
    AstNode parent = node.getParent();
    if (parent == null) {
      throw new AnalysisException("Cannot create scope: node is not part of a CompilationUnit");
    }
    ScopeBuilder builder = new ScopeBuilder(errorListener);
    return builder.scopeForAstNode(parent);
View Full Code Here

   */
  private Scope scopeForAstNode(AstNode node) throws AnalysisException {
    if (node instanceof CompilationUnit) {
      return scopeForCompilationUnit((CompilationUnit) node);
    }
    AstNode parent = node.getParent();
    if (parent == null) {
      throw new AnalysisException("Cannot create scope: node is not part of a CompilationUnit");
    }
    Scope scope = scopeForAstNode(parent);
    if (node instanceof ClassDeclaration) {
View Full Code Here

   *
   * @param node the parameter contained in the function whose body is to be returned
   * @return the body of the function that contains the given parameter
   */
  private FunctionBody getFunctionBody(FormalParameter node) {
    AstNode parent = node.getParent();
    while (parent != null) {
      if (parent instanceof ConstructorDeclaration) {
        return ((ConstructorDeclaration) parent).getBody();
      } else if (parent instanceof FunctionExpression) {
        return ((FunctionExpression) parent).getBody();
      } else if (parent instanceof MethodDeclaration) {
        return ((MethodDeclaration) parent).getBody();
      }
      parent = parent.getParent();
    }
    return null;
  }
View Full Code Here

  /**
   * If the given {@link AstNode} has an {@link Element} at the given offset, then returns
   * {@link Reference} with this {@link Element}.
   */
  private Reference getReferenceAtNode(AstNode root, int offset) {
    AstNode node = new NodeLocator(offset).searchWithin(root);
    if (node != null) {
      Element element = ElementLocator.locate(node);
      return new Reference(element, node.getOffset(), node.getLength());
    }
    return null;
  }
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.