1 11 package org.eclipse.jdt.internal.corext.fix; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition; 18 19 import org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup.PositionInformation; 20 21 public class LinkedProposalModel { 22 23 private Map fPositionGroups; 24 private LinkedProposalPositionGroup.PositionInformation fEndPosition; 25 26 public void addPositionGroup(LinkedProposalPositionGroup positionGroup) { 27 if (positionGroup == null) { 28 throw new IllegalArgumentException ("positionGroup must not be null"); } 30 31 if (fPositionGroups == null) { 32 fPositionGroups= new HashMap (); 33 } 34 fPositionGroups.put(positionGroup.getGroupId(), positionGroup); 35 } 36 37 public LinkedProposalPositionGroup getPositionGroup(String groupId, boolean createIfNotExisting) { 38 LinkedProposalPositionGroup group= fPositionGroups != null ? (LinkedProposalPositionGroup) fPositionGroups.get(groupId) : null; 39 if (createIfNotExisting && group == null) { 40 group= new LinkedProposalPositionGroup(groupId); 41 addPositionGroup(group); 42 } 43 return group; 44 } 45 46 public Iterator getPositionGroupIterator() { 47 if (fPositionGroups == null) { 48 return new Iterator () { 49 public boolean hasNext() {return false;} 50 public Object next() {return null;} 51 public void remove() {} 52 }; 53 } 54 return fPositionGroups.values().iterator(); 55 } 56 57 58 62 public void setEndPosition(PositionInformation position) { 63 fEndPosition= position; 64 } 65 66 public void setEndPosition(ITrackedNodePosition position) { 67 setEndPosition(LinkedProposalPositionGroup.createPositionInformation(position, false)); 68 } 69 70 public PositionInformation getEndPosition() { 71 return fEndPosition; 72 } 73 74 public boolean hasLinkedPositions() { 75 return fPositionGroups != null && !fPositionGroups.isEmpty(); 76 } 77 78 public void clear() { 79 fPositionGroups= null; 80 fEndPosition= null; 81 } 82 83 } 84 | Popular Tags |