Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 185824
Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/UiTestSuite.java (+2 lines)
Lines 40-45 Link Here
40
import org.eclipse.ui.tests.preferences.PreferencesTestSuite;
40
import org.eclipse.ui.tests.preferences.PreferencesTestSuite;
41
import org.eclipse.ui.tests.presentations.PresentationsTestSuite;
41
import org.eclipse.ui.tests.presentations.PresentationsTestSuite;
42
import org.eclipse.ui.tests.propertysheet.PropertySheetTestSuite;
42
import org.eclipse.ui.tests.propertysheet.PropertySheetTestSuite;
43
import org.eclipse.ui.tests.quickaccess.QuickAccessTestSuite;
43
import org.eclipse.ui.tests.services.ServicesTestSuite;
44
import org.eclipse.ui.tests.services.ServicesTestSuite;
44
import org.eclipse.ui.tests.statushandlers.StatusHandlingTestSuite;
45
import org.eclipse.ui.tests.statushandlers.StatusHandlingTestSuite;
45
import org.eclipse.ui.tests.themes.ThemesTestSuite;
46
import org.eclipse.ui.tests.themes.ThemesTestSuite;
Lines 67-72 Link Here
67
        addTest(new UIAutomatedSuite());
68
        addTest(new UIAutomatedSuite());
68
        addTest(new ApiTestSuite());
69
        addTest(new ApiTestSuite());
69
        addTest(new PropertySheetTestSuite());
70
        addTest(new PropertySheetTestSuite());
71
        addTest(new QuickAccessTestSuite());
70
        addTest(new InternalTestSuite());
72
        addTest(new InternalTestSuite());
71
        addTest(new NavigatorTestSuite());
73
        addTest(new NavigatorTestSuite());
72
        addTest(new DecoratorsTestSuite());
74
        addTest(new DecoratorsTestSuite());
(-)Eclipse (+63 lines)
Added Link Here
1
package org.eclipse.ui.tests.quickaccess;
2
3
import junit.framework.TestCase;
4
5
import org.eclipse.ui.internal.quickaccess.CamelUtil;
6
7
public class CamelUtilTest extends TestCase {
8
9
	public void testIsIgnoredForCamelCase() {
10
		assertEquals(true, CamelUtil.isIgnoredForCamelCase(' '));
11
		assertEquals(true, CamelUtil.isIgnoredForCamelCase('.'));
12
		assertEquals(true, CamelUtil.isIgnoredForCamelCase('-'));
13
		assertEquals(true, CamelUtil.isIgnoredForCamelCase('/'));
14
		assertEquals(true, CamelUtil.isIgnoredForCamelCase('*'));
15
		assertEquals(false, CamelUtil.isIgnoredForCamelCase('a'));
16
		assertEquals(false, CamelUtil.isIgnoredForCamelCase('A'));
17
		assertEquals(false, CamelUtil.isIgnoredForCamelCase('1'));
18
	}
19
20
	public void testGetCamelCase() {
21
		assertEquals("", CamelUtil.getCamelCase(""));
22
		assertEquals("a", CamelUtil.getCamelCase("a"));
23
		assertEquals("ab", CamelUtil.getCamelCase("a b"));
24
		assertEquals("at", CamelUtil.getCamelCase("any thing"));
25
		assertEquals("cc", CamelUtil.getCamelCase("CamelCase"));
26
		assertEquals("csm", CamelUtil.getCamelCase("call Some Method"));
27
		assertEquals("sjree", CamelUtil.getCamelCase("SomeJREExample"));
28
		assertEquals("sjree", CamelUtil.getCamelCase("SomeJRE - Example"));
29
	}
30
31
	public void testGetNextCamelIndex() {
32
		assertEquals(-1, CamelUtil.getNextCamelIndex("", 0));
33
		assertEquals(1, CamelUtil.getNextCamelIndex("aB", 0));
34
		assertEquals(3, CamelUtil.getNextCamelIndex("ab c", 0));
35
		assertEquals(2, CamelUtil.getNextCamelIndex("a b ", 0));
36
		assertEquals(2, CamelUtil.getNextCamelIndex("a b ", 1));
37
	}
38
39
	public void testGetCamelCaseIndices() {
40
		assertArrayEquals(new int[][] {}, CamelUtil.getCamelCaseIndices("some string", 0, 0));
41
		assertArrayEquals(new int[][] {{0,0}}, CamelUtil.getCamelCaseIndices("some string", 0, 1));
42
		assertArrayEquals(new int[][] {{0,0},{5,5}}, CamelUtil.getCamelCaseIndices("some string", 0, 2));
43
		assertArrayEquals(new int[][] {{5,5}}, CamelUtil.getCamelCaseIndices("some string", 1, 1));
44
		assertArrayEquals(new int[][] {{8,8},{12,12},{19,19},{26,26},{31,31}}, CamelUtil.getCamelCaseIndices("Editors ApplAction.java - mail/src", 1, 5));
45
	}
46
47
	/**
48
	 * @param is
49
	 * @param camelCaseIndices
50
	 */
51
	private void assertArrayEquals(int[][] is, int[][] camelCaseIndices) {
52
		assertEquals(is.length, camelCaseIndices.length);
53
		for (int i = 0; i < is.length; i++) {
54
			int[] js = is[i];
55
			assertEquals("i=" + i, js.length, camelCaseIndices[i].length);
56
			for (int j = 0; j < js.length; j++) {
57
				assertEquals("i=" + i + ", j=" + j, js[j],
58
						camelCaseIndices[i][j]);
59
			}
60
		}
61
	}
62
63
}
(-)Eclipse (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
 *******************************************************************************/
11
package org.eclipse.ui.tests.quickaccess;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
/**
17
 * Test areas of the Property Sheet API.
18
 */
19
public class QuickAccessTestSuite extends TestSuite {
20
21
    /**
22
     * Returns the suite.  This is required to
23
     * use the JUnit Launcher.
24
     */
25
    public static Test suite() {
26
        return new QuickAccessTestSuite();
27
    }
28
29
    /**
30
     * Construct the test suite.
31
     */
32
    public QuickAccessTestSuite() {
33
        addTest(new TestSuite(CamelUtilTest.class));
34
    }
35
}
(-)Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessElement.java (-67 / +22 lines)
Lines 11-19 Link Here
11
11
12
package org.eclipse.ui.internal.quickaccess;
12
package org.eclipse.ui.internal.quickaccess;
13
13
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.StringTokenizer;
17
14
18
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.jface.resource.ImageDescriptor;
19
16
Lines 35-54 Link Here
35
	}
32
	}
36
33
37
	/**
34
	/**
38
	 * @return a string containing the first character of every word for camel
39
	 *         case checking.
40
	 */
41
	private static String getCamelCase(String label) {
42
		StringTokenizer tokenizer = new StringTokenizer(label);
43
		StringBuffer camelCase = new StringBuffer();
44
		while (tokenizer.hasMoreTokens()) {
45
			String word = tokenizer.nextToken();
46
			camelCase.append(word.charAt(0));
47
		}
48
		return camelCase.toString().toLowerCase();
49
	}
50
51
	/**
52
	 * Returns the label to be displayed to the user.
35
	 * Returns the label to be displayed to the user.
53
	 * 
36
	 * 
54
	 * @return the label
37
	 * @return the label
Lines 95-109 Link Here
95
	 * @param filter
78
	 * @param filter
96
	 * @return
79
	 * @return
97
	 */
80
	 */
98
	public QuickAccessEntry match(String filter, QuickAccessProvider providerForMatching) {
81
	public QuickAccessEntry match(String filter,
99
		String sortLabel = getSortLabel().toLowerCase();
82
			QuickAccessProvider providerForMatching) {
100
		int index = sortLabel.indexOf(filter);
83
		String sortLabel = getLabel();
84
		int index = sortLabel.toLowerCase().indexOf(filter);
101
		if (index != -1) {
85
		if (index != -1) {
102
			return new QuickAccessEntry(this, providerForMatching, new int[][] { {
86
			return new QuickAccessEntry(this, providerForMatching,
103
					index, index + filter.length() - 1 } }, EMPTY_INDICES);
87
					new int[][] { { index, index + filter.length() - 1 } },
88
					EMPTY_INDICES);
104
		}
89
		}
105
		String combinedLabel = (providerForMatching.getName() + " " + getLabel()).toLowerCase(); //$NON-NLS-1$
90
		String combinedLabel = (providerForMatching.getName() + " " + getLabel()); //$NON-NLS-1$
106
		index = combinedLabel.indexOf(filter);
91
		index = combinedLabel.toLowerCase().indexOf(filter);
107
		if (index != -1) {
92
		if (index != -1) {
108
			int lengthOfElementMatch = index + filter.length()
93
			int lengthOfElementMatch = index + filter.length()
109
					- providerForMatching.getName().length() - 1;
94
					- providerForMatching.getName().length() - 1;
Lines 112-132 Link Here
112
						new int[][] { { 0, lengthOfElementMatch - 1 } },
97
						new int[][] { { 0, lengthOfElementMatch - 1 } },
113
						new int[][] { { index, index + filter.length() - 1 } });
98
						new int[][] { { index, index + filter.length() - 1 } });
114
			}
99
			}
115
			return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES,
100
			return new QuickAccessEntry(this, providerForMatching,
116
					new int[][] { { index, index + filter.length() - 1 } });
101
					EMPTY_INDICES, new int[][] { { index,
102
							index + filter.length() - 1 } });
117
		}
103
		}
118
		String camelCase = getCamelCase(sortLabel);
104
		String camelCase = CamelUtil.getCamelCase(sortLabel);
119
		index = camelCase.indexOf(filter);
105
		index = camelCase.indexOf(filter);
120
		if (index != -1) {
106
		if (index != -1) {
121
			int[][] indices = getCamelCaseIndices(sortLabel, index, filter
107
			int[][] indices = CamelUtil.getCamelCaseIndices(sortLabel, index, filter
122
					.length());
108
					.length());
123
			return new QuickAccessEntry(this, providerForMatching, indices,
109
			return new QuickAccessEntry(this, providerForMatching, indices,
124
					EMPTY_INDICES);
110
					EMPTY_INDICES);
125
		}
111
		}
126
		String combinedCamelCase = getCamelCase(combinedLabel);
112
		String combinedCamelCase = CamelUtil.getCamelCase(combinedLabel);
127
		index = combinedCamelCase.indexOf(filter);
113
		index = combinedCamelCase.indexOf(filter);
128
		if (index != -1) {
114
		if (index != -1) {
129
			String providerCamelCase = getCamelCase(providerForMatching
115
			String providerCamelCase = CamelUtil.getCamelCase(providerForMatching
130
					.getName());
116
					.getName());
131
			int lengthOfElementMatch = index + filter.length()
117
			int lengthOfElementMatch = index + filter.length()
132
					- providerCamelCase.length();
118
					- providerCamelCase.length();
Lines 134-178 Link Here
134
				return new QuickAccessEntry(
120
				return new QuickAccessEntry(
135
						this,
121
						this,
136
						providerForMatching,
122
						providerForMatching,
137
						getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch),
123
						CamelUtil.getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch),
138
						getCamelCaseIndices(providerForMatching.getName(), index, filter
124
						CamelUtil.getCamelCaseIndices(providerForMatching.getName(),
139
								.length()
125
								index, filter.length() - lengthOfElementMatch));
140
								- lengthOfElementMatch));
141
			}
126
			}
142
			return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES,
127
			return new QuickAccessEntry(this, providerForMatching,
143
					getCamelCaseIndices(providerForMatching.getName(), index, filter
128
					EMPTY_INDICES, CamelUtil.getCamelCaseIndices(providerForMatching
144
							.length()));
129
							.getName(), index, filter.length()));
145
		}
130
		}
146
		return null;
131
		return null;
147
	}
132
	}
148
149
	/**
150
	 * @param camelCase
151
	 * @param filter
152
	 * @param index
153
	 * @return
154
	 */
155
	private int[][] getCamelCaseIndices(String original, int start, int length) {
156
		List result = new ArrayList();
157
		int index = 0;
158
		while (start > 0) {
159
			index = original.indexOf(' ', index);
160
			while (original.charAt(index) == ' ') {
161
				index++;
162
			}
163
			start--;
164
		}
165
		while (length > 0) {
166
			result.add(new int[] { index, index });
167
			index = original.indexOf(' ', index);
168
			if (index != -1) {
169
				while (index < original.length()
170
						&& original.charAt(index) == ' ') {
171
					index++;
172
				}
173
			}
174
			length--;
175
		}
176
		return (int[][]) result.toArray(new int[result.size()][]);
177
	}
178
}
133
}
(-)Eclipse (+97 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.quickaccess;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
/**
18
 * @since 3.3
19
 * 
20
 */
21
public class CamelUtil {
22
23
	/**
24
	 * @param s
25
	 * @return a string containing the first character of every word for camel
26
	 *         case checking.
27
	 */
28
	public static String getCamelCase(String s) {
29
		StringBuffer result = new StringBuffer();
30
		if (s.length() > 0) {
31
			int index = 0;
32
			while (index != -1) {
33
				result.append(s.charAt(index));
34
				index = getNextCamelIndex(s, index + 1);
35
			}
36
		}
37
		return result.toString().toLowerCase();
38
	}
39
40
	/**
41
	 * Return an array with start/end indices for the characters used for camel
42
	 * case matching, ignoring the first (start) many camel case characters
43
	 * 
44
	 * @param s
45
	 * @param start
46
	 * @param length
47
	 * @return
48
	 */
49
	public static int[][] getCamelCaseIndices(String s, int start, int length) {
50
		List result = new ArrayList();
51
		int index = 0;
52
		while (start > 0) {
53
			index = getNextCamelIndex(s, index + 1);
54
			start--;
55
		}
56
		while (length > 0) {
57
			result.add(new int[] { index, index });
58
			index = getNextCamelIndex(s, index + 1);
59
			length--;
60
		}
61
		return (int[][]) result.toArray(new int[result.size()][]);
62
	}
63
64
	/**
65
	 * Returns the next index to be used for camel case matching.
66
	 * 
67
	 * @param s
68
	 * @param index
69
	 * @return
70
	 */
71
	public static int getNextCamelIndex(String s, int index) {
72
		char c;
73
		while (index < s.length() && !(isIgnoredForCamelCase(c = s.charAt(index)))
74
				&& Character.isLowerCase(c)) {
75
			index++;
76
		}
77
		while (index < s.length() && isIgnoredForCamelCase(c = s.charAt(index))) {
78
			index++;
79
		}
80
		if (index >= s.length()) {
81
			index = -1;
82
		}
83
		return index;
84
	}
85
86
	/**
87
	 * Returns true if the given character is to be ignored for camel case
88
	 * matching purposes.
89
	 * 
90
	 * @param c
91
	 * @return
92
	 */
93
	public static boolean isIgnoredForCamelCase(char c) {
94
		return !Character.isLetterOrDigit(c);
95
	}
96
97
}

Return to bug 185824