<s> package org . eclipse . jdt . core . dom . rewrite ; import java . util . Collections ; import java . util . List ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . Block ; import org . eclipse . jdt . core . dom . ChildListPropertyDescriptor ; import org . eclipse . jdt . core . dom . FieldDeclaration ; import org . eclipse . jdt . core . dom . Statement ; import org . eclipse . jdt . core . dom . StructuralPropertyDescriptor ; import org . eclipse . jdt . internal . core . dom . rewrite . ListRewriteEvent ; import org . eclipse . jdt . internal . core . dom . rewrite . NodeInfoStore ; import org . eclipse . jdt . internal . core . dom . rewrite . RewriteEvent ; import org . eclipse . jdt . internal . core . dom . rewrite . RewriteEventStore ; import org . eclipse . jdt . internal . core . dom . rewrite . RewriteEventStore . CopySourceInfo ; import org . eclipse . text . edits . TextEditGroup ; public final class ListRewrite { private ASTNode parent ; private StructuralPropertyDescriptor childProperty ; private ASTRewrite rewriter ; ListRewrite ( ASTRewrite rewriter , ASTNode parent , StructuralPropertyDescriptor childProperty ) { this . rewriter = rewriter ; this . parent = parent ; this . childProperty = childProperty ; } private RewriteEventStore getRewriteStore ( ) { return this . rewriter . getRewriteEventStore ( ) ; } private ListRewriteEvent getEvent ( ) { return getRewriteStore ( ) . getListEvent ( this . parent , this . childProperty , true ) ; } public ASTNode getParent ( ) { return this . parent ; } public StructuralPropertyDescriptor getLocationInParent ( ) { return this . childProperty ; } public void remove ( ASTNode node , TextEditGroup editGroup ) { if ( node == null ) { throw new IllegalArgumentException ( ) ; } RewriteEvent event = getEvent ( ) . removeEntry ( node ) ; if ( editGroup != null ) { getRewriteStore ( ) . setEventEditGroup ( event , editGroup ) ; } } public ASTRewrite getASTRewrite ( ) { return this . rewriter ; } public void replace ( ASTNode node , ASTNode replacement , TextEditGroup editGroup ) { if ( node == null ) { throw new IllegalArgumentException ( ) ; } RewriteEvent event = getEvent ( ) . replaceEntry ( node , replacement ) ; if ( editGroup != null ) { getRewriteStore ( ) . setEventEditGroup ( event , editGroup ) ; } } public void insertAfter ( ASTNode node , ASTNode element , TextEditGroup editGroup ) { if ( node == null || element == null ) { throw new IllegalArgumentException ( ) ; } int index = getEvent ( ) . getIndex ( element , ListRewriteEvent . BOTH ) ; if ( index == - 1 ) { throw new IllegalArgumentException ( "" ) ; } internalInsertAt ( node , index + 1 , true , editGroup ) ; } public void insertBefore ( ASTNode node , ASTNode element , TextEditGroup editGroup ) { if ( node == null || element == null ) { throw new IllegalArgumentException ( ) ; } int index = getEvent ( ) . getIndex ( element , ListRewriteEvent . BOTH ) ; if ( index == - 1 ) { throw new IllegalArgumentException ( "" ) ; } internalInsertAt ( node , index , false , editGroup ) ; } public void insertFirst ( ASTNode node , TextEditGroup editGroup ) { if ( node == null ) { throw new IllegalArgumentException ( ) ; } internalInsertAt ( node , 0 , false , editGroup ) ; } public void insertLast ( ASTNode node , TextEditGroup editGroup ) { if ( node == null ) { throw new IllegalArgumentException ( ) ; } internalInsertAt ( node , - 1 , true , editGroup ) ; } public void insertAt ( ASTNode node , int index , TextEditGroup editGroup ) { if ( node == null ) { throw new IllegalArgumentException ( ) ; } internalInsertAt ( node , index , isInsertBoundToPreviousByDefault ( node ) , editGroup ) ; } private void internalInsertAt ( ASTNode node , int index , boolean boundToPrevious , TextEditGroup editGroup ) { RewriteEvent event = getEvent ( ) . insert ( node , index ) ; if ( boundToPrevious ) { getRewriteStore ( ) . setInsertBoundToPrevious ( node ) ; } if ( editGroup != null ) { getRewriteStore ( ) . setEventEditGroup ( event , editGroup ) ; } } private ASTNode createTargetNode ( ASTNode first , ASTNode last , boolean isMove , ASTNode replacingNode , TextEditGroup editGroup ) { if ( first == null || last == null ) { throw new IllegalArgumentException ( ) ; } NodeInfoStore nodeStore = this . rewriter . getNodeStore ( ) ; ASTNode placeholder = nodeStore . newPlaceholderNode ( first . getNodeType ( ) ) ; if ( placeholder == null ) { throw new IllegalArgumentException ( "" + first . getClass ( ) . getName ( ) ) ; } Block internalPlaceHolder = nodeStore . createCollapsePlaceholder ( ) ; CopySourceInfo info = getRewriteStore ( ) . createRangeCopy ( this . parent , this . childProperty , first , last , isMove , internalPlaceHolder , replacingNode , editGroup ) ; nodeStore . markAsCopyTarget ( placeholder , info ) ; return placeholder ; } public final ASTNode createCopyTarget ( ASTNode first , ASTNode last ) { if ( first == last ) { return this . rewriter . createCopyTarget ( first ) ; } else { return createTargetNode ( first , last , false , null , null ) ; } } public final ASTNode createMoveTarget ( ASTNode first , ASTNode last ) { return createMoveTarget ( first , last , null , null ) ; } public final ASTNode createMoveTarget ( ASTNode first , ASTNode last , ASTNode replacingNode , TextEditGroup editGroup ) { if ( first == last ) { replace ( first , replacingNode , editGroup ) ; return this . rewriter . createMoveTarget ( first ) ; } else { return createTargetNode ( first , last , true , replacingNode , editGroup ) ; } } private boolean isInsertBoundToPreviousByDefault ( ASTNode node ) { return ( node instanceof Statement || node instanceof FieldDeclaration ) ; } public List getOriginalList ( ) { List list = ( List ) getEvent ( ) . getOriginalValue ( ) ; return Collections . unmodifiableList ( list ) ; } public List getRewrittenList ( ) { List list = ( List ) getEvent ( ) . getNewValue ( ) ; return Collections . unmodifiableList ( list ) ; } } </s>