Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ASTNode


        "}");
    // check captured position
    {
      assertTrue(openSourcePosition.hasCaptured());
      assertTrue(openSourcePosition.getValue() != 0);
      ASTNode enclosingNode = m_lastEditor.getEnclosingNode(openSourcePosition.getValue());
      assertEquals("new MyCommand()", m_lastEditor.getSource(enclosingNode));
    }
  }
View Full Code Here


      assertTrue(creationSupport.canReparent());
      assertTrue(creationSupport.canDelete());
    }
    // assert that "image" is bound to AST
    {
      ASTNode node = getNode("image = ");
      assertTrue(newImage.isRepresentedBy(node));
    }
  }
View Full Code Here

            }
          }
        }
      }

      ASTNode a = ASTNode.copySubtree(ast, dropTypeDec);
      @SuppressWarnings("unchecked")
      List<TypeDeclaration> types = astRoot.types();
      ArrayList<TypeDeclaration> newTypes = new ArrayList<TypeDeclaration>();
      newTypes.add((TypeDeclaration) a);
      if (types.addAll(newTypes)) {
View Full Code Here

   * @param ext the list of modifier and annotation nodes
   * (element type: <code>IExtendedModifiers</code>)
   */
  void printModifiers(List ext) {
    for (Iterator it = ext.iterator(); it.hasNext(); ) {
      ASTNode p = (ASTNode) it.next();
      p.accept(this);
      this.buffer.append(" ");//$NON-NLS-1$
    }
  }
View Full Code Here

   */
  public boolean visit(Javadoc node) {
    printIndent();
    this.buffer.append("/** ");//$NON-NLS-1$
    for (Iterator it = node.tags().iterator(); it.hasNext(); ) {
      ASTNode e = (ASTNode) it.next();
      e.accept(this);
    }
    this.buffer.append("\n */\n");//$NON-NLS-1$
    return false;
  }
View Full Code Here

   * @param nodeType Type of the node to create. Use the type constants in {@link NodeInfoStore}.
   * @return Returns a place holder node.
   */
  public final ASTNode newPlaceholderNode(int nodeType) {
      try {
        ASTNode node= this.ast.createInstance(nodeType);
        switch (node.getNodeType()) {
        case ASTNode.FIELD_DECLARATION:
            ((FieldDeclaration) node).fragments().add(this.ast.newVariableDeclarationFragment());
            break;
        case ASTNode.MODIFIER:
            ((Modifier) node).setKeyword(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
View Full Code Here

      this.buffer.append(node.getTagName());
      previousRequiresWhiteSpace = true;
    }
    boolean previousRequiresNewLine = false;
    for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
      ASTNode e = (ASTNode) it.next();
      // assume text elements include necessary leading and trailing whitespace
      // but Name, MemberRef, MethodRef, and nested TagElement do not include white space
      boolean currentIncludesWhiteSpace = (e instanceof TextElement);
      if (previousRequiresNewLine && currentIncludesWhiteSpace) {
        this.buffer.append("\n * ");//$NON-NLS-1$
      }
      previousRequiresNewLine = currentIncludesWhiteSpace;
      // add space if required to separate
      if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
        this.buffer.append(" "); //$NON-NLS-1$
      }
      e.accept(this);
      previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
    }
    if (node.isNested()) {
      this.buffer.append("}");//$NON-NLS-1$
    }
View Full Code Here

  public TextEdit rewriteAST(IDocument document, Map options) throws IllegalArgumentException {
    if (document == null) {
      throw new IllegalArgumentException();
    }

    ASTNode rootNode= getRootNode();
    if (rootNode == null) {
      return new MultiTextEdit(); // no changes
    }

    char[] content= document.get().toCharArray();
    LineInformation lineInfo= LineInformation.create(document);
    String lineDelim= TextUtilities.getDefaultLineDelimiter(document);

    ASTNode astRoot= rootNode.getRoot();
    List commentNodes= astRoot instanceof CompilationUnit ? ((CompilationUnit) astRoot).getCommentList() : null;
    Map currentOptions = options == null ? JavaCore.getOptions() : options;
    return internalRewriteAST(content, lineInfo, lineDelim, commentNodes, currentOptions, rootNode, (RecoveryScannerData)((CompilationUnit) astRoot).getStatementsRecoveryData());
  }
View Full Code Here

   * is thrown if the document passed does not correspond to the AST that is rewritten.
   *
   * @since 3.2
   */
  public TextEdit rewriteAST() throws JavaModelException, IllegalArgumentException {
    ASTNode rootNode= getRootNode();
    if (rootNode == null) {
      return new MultiTextEdit(); // no changes
    }

    ASTNode root= rootNode.getRoot();
    if (!(root instanceof CompilationUnit)) {
      throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
    }
    CompilationUnit astRoot= (CompilationUnit) root;
    ITypeRoot typeRoot = astRoot.getTypeRoot();
View Full Code Here

    this.eventStore.revertMovedNodes();
    return result;
  }

  private ASTNode getRootNode() {
    ASTNode node= null;
    int start= -1;
    int end= -1;

    for (Iterator iter= getRewriteEventStore().getChangeRootIterator(); iter.hasNext();) {
      ASTNode curr= (ASTNode) iter.next();
      if (!RewriteEventStore.isNewNode(curr)) {
        int currStart= curr.getStartPosition();
        int currEnd= currStart + curr.getLength();
        if (node == null || currStart < start && currEnd > end) {
          start= currStart;
          end= currEnd;
          node= curr;
        } else if (currStart < start) {
          start= currStart;
        } else if (currEnd > end) {
          end= currEnd;
        }
      }
    }
    if (node != null) {
      int currStart= node.getStartPosition();
      int currEnd= currStart + node.getLength();
      while (start < currStart || end > currEnd) { // go up until a node covers all
        node= node.getParent();
        currStart= node.getStartPosition();
        currEnd= currStart + node.getLength();
      }
      ASTNode parent= node.getParent(); // go up until a parent has different range
      while (parent != null && parent.getStartPosition() == node.getStartPosition() && parent.getLength() == node.getLength()) {
        node= parent;
        parent= node.getParent();
      }
    }
    return node;
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.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.