Package org.aspectj.org.eclipse.jdt.core.dom

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


    this.source = removeIndentAndNewLines(this.source, document, cu);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(this.source.toCharArray());
    parser.setProject(getCompilationUnit().getJavaProject());
    parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
    ASTNode node = parser.createAST(this.progressMonitor);
    String createdNodeSource;
    if (node.getNodeType() != ASTNode.TYPE_DECLARATION) {
      createdNodeSource = generateSyntaxIncorrectAST();
      if (this.createdNode == null)
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
    } else {
      TypeDeclaration typeDeclaration = (TypeDeclaration) node;
View Full Code Here


*/
public CreateFieldOperation(IType parentElement, String source, boolean force) {
  super(parentElement, source, force);
}
protected ASTNode generateElementAST(ASTRewrite rewriter, IDocument document, ICompilationUnit cu) throws JavaModelException {
  ASTNode node = super.generateElementAST(rewriter, document, cu);
  if (node.getNodeType() != ASTNode.FIELD_DECLARATION)
    throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
  return node;
}
View Full Code Here

          }
        }
      }
    }
    if (value instanceof ASTNode) {
      ASTNode node= (ASTNode) value;
      return new PropertyLocation(node.getParent(), node.getLocationInParent());
    }
    return null;
  }
View Full Code Here

  }
 
  private void revertListWithRanges(RewriteEvent[] childEvents, Set placeholders, List revertedChildren) {
    for (int i= 0; i < childEvents.length; i++) {
      RewriteEvent event= childEvents[i];
      ASTNode node= (ASTNode) event.getOriginalValue();
      if (placeholders.contains(node)) {
        RewriteEvent[] placeholderChildren= getListEvent(node, Block.STATEMENTS_PROPERTY, false).getChildren();
        revertListWithRanges(placeholderChildren, placeholders, revertedChildren);
      } else {
        revertedChildren.add(event);
View Full Code Here

    Iterator rangeInfoIterator= rangeInfos.iterator();
    NodeRangeInfo nextInfo= (NodeRangeInfo) rangeInfoIterator.next();
   
    for (int k= 0; k < childEvents.length; k++) {
      RewriteEvent event= childEvents[k];
      ASTNode node= (ASTNode) event.getOriginalValue();
      // check for ranges and add a placeholder for them
      while (nextInfo != null && node == nextInfo.getStartNode()) { // is this child the beginning of a range?
        nextInfo.updatePlaceholderSourceRanges(sourceRangeComputer);
       
        Block internalPlaceholder= nextInfo.getInternalPlaceholder();
View Full Code Here

   * being rewritten
   * @return the exact source range in the compilation unit being rewritten
   * that should be replaced (or deleted)
   */
  public SourceRange computeSourceRange(ASTNode node) {
    ASTNode root= node.getRoot();
    if (root instanceof CompilationUnit) {
      CompilationUnit cu= (CompilationUnit) root;
      return new SourceRange(cu.getExtendedStartPosition(node), cu.getExtendedLength(node));
    }
    return new SourceRange(node.getStartPosition(), node.getLength());
View Full Code Here

    if (first == null || last == null) {
      throw new IllegalArgumentException();
    }

    NodeInfoStore nodeStore= this.rewriter.getNodeStore();
    ASTNode placeholder= nodeStore.newPlaceholderNode(first.getNodeType()); // revisit: could use list type
    if (placeholder == null) {
      throw new IllegalArgumentException("Creating a target node is not supported for nodes of type" + first.getClass().getName()); //$NON-NLS-1$
    }
   
    Block internalPlaceHolder= nodeStore.createCollapsePlaceholder();
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;
    return internalRewriteAST(content, lineInfo, lineDelim, commentNodes, options, rootNode);
  }
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.aspectj.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.