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