01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.fix;
11:
12: import java.util.HashMap;
13: import java.util.Iterator;
14: import java.util.Map;
15:
16: import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;
17:
18: import org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup.PositionInformation;
19:
20: public class LinkedProposalModel {
21:
22: private Map/*<String, PositionGroup>*/fPositionGroups;
23: private LinkedProposalPositionGroup.PositionInformation fEndPosition;
24:
25: public void addPositionGroup(
26: LinkedProposalPositionGroup positionGroup) {
27: if (positionGroup == null) {
28: throw new IllegalArgumentException(
29: "positionGroup must not be null"); //$NON-NLS-1$
30: }
31:
32: if (fPositionGroups == null) {
33: fPositionGroups = new HashMap();
34: }
35: fPositionGroups.put(positionGroup.getGroupId(), positionGroup);
36: }
37:
38: public LinkedProposalPositionGroup getPositionGroup(String groupId,
39: boolean createIfNotExisting) {
40: LinkedProposalPositionGroup group = fPositionGroups != null ? (LinkedProposalPositionGroup) fPositionGroups
41: .get(groupId)
42: : null;
43: if (createIfNotExisting && group == null) {
44: group = new LinkedProposalPositionGroup(groupId);
45: addPositionGroup(group);
46: }
47: return group;
48: }
49:
50: public Iterator getPositionGroupIterator() {
51: if (fPositionGroups == null) {
52: return new Iterator() {
53: public boolean hasNext() {
54: return false;
55: }
56:
57: public Object next() {
58: return null;
59: }
60:
61: public void remove() {
62: }
63: };
64: }
65: return fPositionGroups.values().iterator();
66: }
67:
68: /**
69: * Sets the end position of the linked mode to the end of the passed range.
70: * @param position The position that describes the end position of the linked mode.
71: */
72: public void setEndPosition(PositionInformation position) {
73: fEndPosition = position;
74: }
75:
76: public void setEndPosition(ITrackedNodePosition position) {
77: setEndPosition(LinkedProposalPositionGroup
78: .createPositionInformation(position, false));
79: }
80:
81: public PositionInformation getEndPosition() {
82: return fEndPosition;
83: }
84:
85: public boolean hasLinkedPositions() {
86: return fPositionGroups != null && !fPositionGroups.isEmpty();
87: }
88:
89: public void clear() {
90: fPositionGroups = null;
91: fEndPosition = null;
92: }
93:
94: }
|