Exemplo n.º 1
0
  /**
   * return null if the algorithm should stop (monitor was cancelled) return DOMASTNodeLeafContinue
   * if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null
   * return the DOMASTNodeLeaf added to the DOM AST View's model otherwise
   *
   * @param node
   * @return
   */
  private DOMASTNodeLeaf addRoot(IASTNode node) {
    if (monitor != null && monitor.isCanceled()) return null;
    if (node == null) return new DOMASTNodeLeafContinue(null);

    // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very
    // expensive)
    if (node instanceof ASTNode && ((ASTNode) node).getLength() <= 0)
      return new DOMASTNodeLeafContinue(null);

    DOMASTNodeParent parent = null;

    // if it's a preprocessor statement being merged then do a special search for parent (no search)
    if (node instanceof IASTPreprocessorStatement) {
      parent = root;
    } else {
      IASTNode tempParent = node.getParent();
      if (tempParent instanceof IASTPreprocessorStatement) {
        parent = root.findTreeParentForMergedNode(node);
      } else {
        parent = root.findTreeParentForNode(node);
      }
    }

    if (parent == null) parent = root;

    return createNode(parent, node);
  }