diff dwtx/jface/text/link/ProposalPosition.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/text/link/ProposalPosition.d	Sat Aug 23 19:10:48 2008 +0200
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwtx.jface.text.link.ProposalPosition;
+
+import dwt.dwthelper.utils;
+
+import java.util.Arrays;
+
+import dwtx.jface.text.IDocument;
+import dwtx.jface.text.contentassist.ICompletionProposal;
+
+/**
+ * LinkedPosition with added completion proposals.
+ * <p>
+ * Clients may instantiate or extend this class.
+ * </p>
+ *
+ * @since 3.0
+ */
+public class ProposalPosition : LinkedPosition {
+
+    /**
+     * The proposals
+     */
+    private ICompletionProposal[] fProposals;
+
+    /**
+     * Creates a new instance.
+     *
+     * @param document the document
+     * @param offset the offset of the position
+     * @param length the length of the position
+     * @param sequence the iteration sequence rank
+     * @param proposals the proposals to be shown when entering this position
+     */
+    public ProposalPosition(IDocument document, int offset, int length, int sequence, ICompletionProposal[] proposals) {
+        super(document, offset, length, sequence);
+        fProposals= copy(proposals);
+    }
+
+    /**
+     * Creates a new instance, with no sequence number.
+     *
+     * @param document the document
+     * @param offset the offset of the position
+     * @param length the length of the position
+     * @param proposals the proposals to be shown when entering this position
+     */
+    public ProposalPosition(IDocument document, int offset, int length, ICompletionProposal[] proposals) {
+        super(document, offset, length, LinkedPositionGroup.NO_STOP);
+        fProposals= copy(proposals);
+    }
+
+    /*
+     * @since 3.1
+     */
+    private ICompletionProposal[] copy(ICompletionProposal[] proposals) {
+        if (proposals !is null) {
+            ICompletionProposal[] copy= new ICompletionProposal[proposals.length];
+            System.arraycopy(proposals, 0, copy, 0, proposals.length);
+            return copy;
+        }
+        return null;
+    }
+
+    /*
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public bool equals(Object o) {
+        if (o instanceof ProposalPosition) {
+            if (super.equals(o)) {
+                return Arrays.equals(fProposals, ((ProposalPosition)o).fProposals);
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the proposals attached to this position. The returned array is owned by
+     * this <code>ProposalPosition</code> and may not be modified by clients.
+     *
+     * @return an array of choices, including the initial one. Callers must not
+     *         modify it.
+     */
+    public ICompletionProposal[] getChoices() {
+        return fProposals;
+    }
+
+    /*
+     * @see dwtx.jdt.internal.ui.text.link.LinkedPosition#hashCode()
+     */
+    public int hashCode() {
+        return super.hashCode() | (fProposals is null ? 0 : fProposals.hashCode());
+    }
+}