129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.link.ProposalPosition;
|
|
14
|
131
|
15 import dwtx.jface.text.link.LinkedModeModel; // packageimport
|
|
16 import dwtx.jface.text.link.LinkedPosition; // packageimport
|
|
17 import dwtx.jface.text.link.ILinkedModeListener; // packageimport
|
|
18 import dwtx.jface.text.link.TabStopIterator; // packageimport
|
|
19 import dwtx.jface.text.link.LinkedModeUI; // packageimport
|
|
20 import dwtx.jface.text.link.InclusivePositionUpdater; // packageimport
|
|
21 import dwtx.jface.text.link.LinkedPositionGroup; // packageimport
|
|
22 import dwtx.jface.text.link.LinkedModeManager; // packageimport
|
|
23 import dwtx.jface.text.link.LinkedPositionAnnotations; // packageimport
|
|
24
|
|
25
|
129
|
26 import dwt.dwthelper.utils;
|
|
27
|
|
28 import java.util.Arrays;
|
|
29
|
|
30 import dwtx.jface.text.IDocument;
|
|
31 import dwtx.jface.text.contentassist.ICompletionProposal;
|
|
32
|
|
33 /**
|
|
34 * LinkedPosition with added completion proposals.
|
|
35 * <p>
|
|
36 * Clients may instantiate or extend this class.
|
|
37 * </p>
|
|
38 *
|
|
39 * @since 3.0
|
|
40 */
|
|
41 public class ProposalPosition : LinkedPosition {
|
|
42
|
|
43 /**
|
|
44 * The proposals
|
|
45 */
|
|
46 private ICompletionProposal[] fProposals;
|
|
47
|
|
48 /**
|
|
49 * Creates a new instance.
|
|
50 *
|
|
51 * @param document the document
|
|
52 * @param offset the offset of the position
|
|
53 * @param length the length of the position
|
|
54 * @param sequence the iteration sequence rank
|
|
55 * @param proposals the proposals to be shown when entering this position
|
|
56 */
|
|
57 public ProposalPosition(IDocument document, int offset, int length, int sequence, ICompletionProposal[] proposals) {
|
|
58 super(document, offset, length, sequence);
|
|
59 fProposals= copy(proposals);
|
|
60 }
|
|
61
|
|
62 /**
|
|
63 * Creates a new instance, with no sequence number.
|
|
64 *
|
|
65 * @param document the document
|
|
66 * @param offset the offset of the position
|
|
67 * @param length the length of the position
|
|
68 * @param proposals the proposals to be shown when entering this position
|
|
69 */
|
|
70 public ProposalPosition(IDocument document, int offset, int length, ICompletionProposal[] proposals) {
|
|
71 super(document, offset, length, LinkedPositionGroup.NO_STOP);
|
|
72 fProposals= copy(proposals);
|
|
73 }
|
|
74
|
|
75 /*
|
|
76 * @since 3.1
|
|
77 */
|
|
78 private ICompletionProposal[] copy(ICompletionProposal[] proposals) {
|
|
79 if (proposals !is null) {
|
|
80 ICompletionProposal[] copy= new ICompletionProposal[proposals.length];
|
|
81 System.arraycopy(proposals, 0, copy, 0, proposals.length);
|
|
82 return copy;
|
|
83 }
|
|
84 return null;
|
|
85 }
|
|
86
|
|
87 /*
|
|
88 * @see java.lang.Object#equals(java.lang.Object)
|
|
89 */
|
|
90 public bool equals(Object o) {
|
|
91 if (o instanceof ProposalPosition) {
|
|
92 if (super.equals(o)) {
|
|
93 return Arrays.equals(fProposals, ((ProposalPosition)o).fProposals);
|
|
94 }
|
|
95 }
|
|
96 return false;
|
|
97 }
|
|
98
|
|
99 /**
|
|
100 * Returns the proposals attached to this position. The returned array is owned by
|
|
101 * this <code>ProposalPosition</code> and may not be modified by clients.
|
|
102 *
|
|
103 * @return an array of choices, including the initial one. Callers must not
|
|
104 * modify it.
|
|
105 */
|
|
106 public ICompletionProposal[] getChoices() {
|
|
107 return fProposals;
|
|
108 }
|
|
109
|
|
110 /*
|
|
111 * @see dwtx.jdt.internal.ui.text.link.LinkedPosition#hashCode()
|
|
112 */
|
|
113 public int hashCode() {
|
|
114 return super.hashCode() | (fProposals is null ? 0 : fProposals.hashCode());
|
|
115 }
|
|
116 }
|