KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > fix > LinkedProposalModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.fix;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
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 JavaDoc/*<String, PositionGroup>*/ fPositionGroups;
24     private LinkedProposalPositionGroup.PositionInformation fEndPosition;
25     
26     public void addPositionGroup(LinkedProposalPositionGroup positionGroup) {
27         if (positionGroup == null) {
28             throw new IllegalArgumentException JavaDoc("positionGroup must not be null"); //$NON-NLS-1$
29
}
30         
31         if (fPositionGroups == null) {
32             fPositionGroups= new HashMap JavaDoc();
33         }
34         fPositionGroups.put(positionGroup.getGroupId(), positionGroup);
35     }
36     
37     public LinkedProposalPositionGroup getPositionGroup(String JavaDoc 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 JavaDoc getPositionGroupIterator() {
47         if (fPositionGroups == null) {
48             return new Iterator JavaDoc() {
49                 public boolean hasNext() {return false;}
50                 public Object JavaDoc next() {return null;}
51                 public void remove() {}
52             };
53         }
54         return fPositionGroups.values().iterator();
55     }
56     
57     
58     /**
59      * Sets the end position of the linked mode to the end of the passed range.
60      * @param position The position that describes the end position of the linked mode.
61      */

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