01: /*******************************************************************************
02: * Copyright (c) 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.ui.text.java;
11:
12: import java.util.Comparator;
13:
14: import org.eclipse.core.runtime.IConfigurationElement;
15:
16: import org.eclipse.jface.text.contentassist.ICompletionProposal;
17:
18: /**
19: * Abstract base class for sorters contributed to the
20: * <code>org.eclipse.jdt.ui.javaCompletionProposalSorters</code> extension point.
21: * <p>
22: * Subclasses need to implement {@link #compare(ICompletionProposal, ICompletionProposal)} and may
23: * override {@link #beginSorting(ContentAssistInvocationContext) beginSorting} and
24: * {@link #endSorting() endSorting}.
25: * </p>
26: * <p>
27: * The orderings imposed by a subclass need not be consistent with equals.
28: * </p>
29: *
30: * @since 3.2
31: */
32: public abstract class AbstractProposalSorter implements Comparator {
33:
34: /**
35: * Creates a new sorter. Note that subclasses must provide a zero-argument constructor to be
36: * instantiatable via {@link IConfigurationElement#createExecutableExtension(String)}.
37: */
38: protected AbstractProposalSorter() {
39: }
40:
41: /**
42: * Called once before sorting.
43: * <p>
44: * Clients may override, the default implementation does nothing.
45: * </p>
46: *
47: * @param context the context of the content assist invocation
48: */
49: public void beginSorting(ContentAssistInvocationContext context) {
50: }
51:
52: /**
53: * Implements the same contract as {@link Comparator#compare(Object, Object)} but with
54: * completion proposals as parameters. This method will implement the {@link Comparator}
55: * interface if this class is ever converted to extend
56: * <code>Comparator<ICompletionProposal></code>.
57: * <p>
58: * The orderings imposed by an implementation need not be consistent with equals.
59: * </p>
60: *
61: * @param p1 the first proposal to be compared
62: * @param p2 the second proposal to be compared
63: * @return a negative integer, zero, or a positive integer as the first argument is less than,
64: * equal to, or greater than the second.
65: */
66: public abstract int compare(ICompletionProposal p1,
67: ICompletionProposal p2);
68:
69: /**
70: * Called once after sorting.
71: * <p>
72: * Clients may override, the default implementation does nothing.
73: * </p>
74: */
75: public void endSorting() {
76: }
77:
78: /**
79: * This method delegates to {@link #compare(ICompletionProposal, ICompletionProposal)} and may
80: * be removed if the class is ever converted to extend
81: * <code>Comparator<ICompletionProposal></code>.
82: *
83: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
84: */
85: public final int compare(Object o1, Object o2) {
86: ICompletionProposal p1 = (ICompletionProposal) o1;
87: ICompletionProposal p2 = (ICompletionProposal) o2;
88:
89: return compare(p1, p2);
90: }
91: }
|