Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 66181 Details for
Bug 185824
[QuickAccess] CamelCase algorithm needs to be better
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch, with tests for camel case helper methods
patch-185824.txt (text/plain), 14.35 KB, created by
Boris Bokowski
on 2007-05-07 14:27:50 EDT
(
hide
)
Description:
patch, with tests for camel case helper methods
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2007-05-07 14:27:50 EDT
Size:
14.35 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/UiTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/UiTestSuite.java,v >retrieving revision 1.53 >diff -u -r1.53 UiTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/UiTestSuite.java 18 Apr 2007 12:02:52 -0000 1.53 >+++ Eclipse UI Tests/org/eclipse/ui/tests/UiTestSuite.java 7 May 2007 18:27:21 -0000 >@@ -40,6 +40,7 @@ > import org.eclipse.ui.tests.preferences.PreferencesTestSuite; > import org.eclipse.ui.tests.presentations.PresentationsTestSuite; > import org.eclipse.ui.tests.propertysheet.PropertySheetTestSuite; >+import org.eclipse.ui.tests.quickaccess.QuickAccessTestSuite; > import org.eclipse.ui.tests.services.ServicesTestSuite; > import org.eclipse.ui.tests.statushandlers.StatusHandlingTestSuite; > import org.eclipse.ui.tests.themes.ThemesTestSuite; >@@ -67,6 +68,7 @@ > addTest(new UIAutomatedSuite()); > addTest(new ApiTestSuite()); > addTest(new PropertySheetTestSuite()); >+ addTest(new QuickAccessTestSuite()); > addTest(new InternalTestSuite()); > addTest(new NavigatorTestSuite()); > addTest(new DecoratorsTestSuite()); >Index: Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/CamelUtilTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/CamelUtilTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/CamelUtilTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/CamelUtilTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,63 @@ >+package org.eclipse.ui.tests.quickaccess; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.ui.internal.quickaccess.CamelUtil; >+ >+public class CamelUtilTest extends TestCase { >+ >+ public void testIsIgnoredForCamelCase() { >+ assertEquals(true, CamelUtil.isIgnoredForCamelCase(' ')); >+ assertEquals(true, CamelUtil.isIgnoredForCamelCase('.')); >+ assertEquals(true, CamelUtil.isIgnoredForCamelCase('-')); >+ assertEquals(true, CamelUtil.isIgnoredForCamelCase('/')); >+ assertEquals(true, CamelUtil.isIgnoredForCamelCase('*')); >+ assertEquals(false, CamelUtil.isIgnoredForCamelCase('a')); >+ assertEquals(false, CamelUtil.isIgnoredForCamelCase('A')); >+ assertEquals(false, CamelUtil.isIgnoredForCamelCase('1')); >+ } >+ >+ public void testGetCamelCase() { >+ assertEquals("", CamelUtil.getCamelCase("")); >+ assertEquals("a", CamelUtil.getCamelCase("a")); >+ assertEquals("ab", CamelUtil.getCamelCase("a b")); >+ assertEquals("at", CamelUtil.getCamelCase("any thing")); >+ assertEquals("cc", CamelUtil.getCamelCase("CamelCase")); >+ assertEquals("csm", CamelUtil.getCamelCase("call Some Method")); >+ assertEquals("sjree", CamelUtil.getCamelCase("SomeJREExample")); >+ assertEquals("sjree", CamelUtil.getCamelCase("SomeJRE - Example")); >+ } >+ >+ public void testGetNextCamelIndex() { >+ assertEquals(-1, CamelUtil.getNextCamelIndex("", 0)); >+ assertEquals(1, CamelUtil.getNextCamelIndex("aB", 0)); >+ assertEquals(3, CamelUtil.getNextCamelIndex("ab c", 0)); >+ assertEquals(2, CamelUtil.getNextCamelIndex("a b ", 0)); >+ assertEquals(2, CamelUtil.getNextCamelIndex("a b ", 1)); >+ } >+ >+ public void testGetCamelCaseIndices() { >+ assertArrayEquals(new int[][] {}, CamelUtil.getCamelCaseIndices("some string", 0, 0)); >+ assertArrayEquals(new int[][] {{0,0}}, CamelUtil.getCamelCaseIndices("some string", 0, 1)); >+ assertArrayEquals(new int[][] {{0,0},{5,5}}, CamelUtil.getCamelCaseIndices("some string", 0, 2)); >+ assertArrayEquals(new int[][] {{5,5}}, CamelUtil.getCamelCaseIndices("some string", 1, 1)); >+ assertArrayEquals(new int[][] {{8,8},{12,12},{19,19},{26,26},{31,31}}, CamelUtil.getCamelCaseIndices("Editors ApplAction.java - mail/src", 1, 5)); >+ } >+ >+ /** >+ * @param is >+ * @param camelCaseIndices >+ */ >+ private void assertArrayEquals(int[][] is, int[][] camelCaseIndices) { >+ assertEquals(is.length, camelCaseIndices.length); >+ for (int i = 0; i < is.length; i++) { >+ int[] js = is[i]; >+ assertEquals("i=" + i, js.length, camelCaseIndices[i].length); >+ for (int j = 0; j < js.length; j++) { >+ assertEquals("i=" + i + ", j=" + j, js[j], >+ camelCaseIndices[i][j]); >+ } >+ } >+ } >+ >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessTestSuite.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessTestSuite.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessTestSuite.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessTestSuite.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,35 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 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 >+ *******************************************************************************/ >+package org.eclipse.ui.tests.quickaccess; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+/** >+ * Test areas of the Property Sheet API. >+ */ >+public class QuickAccessTestSuite extends TestSuite { >+ >+ /** >+ * Returns the suite. This is required to >+ * use the JUnit Launcher. >+ */ >+ public static Test suite() { >+ return new QuickAccessTestSuite(); >+ } >+ >+ /** >+ * Construct the test suite. >+ */ >+ public QuickAccessTestSuite() { >+ addTest(new TestSuite(CamelUtilTest.class)); >+ } >+} >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessElement.java,v >retrieving revision 1.1 >diff -u -r1.1 QuickAccessElement.java >--- Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessElement.java 27 Apr 2007 05:54:08 -0000 1.1 >+++ Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessElement.java 7 May 2007 18:27:21 -0000 >@@ -11,9 +11,6 @@ > > package org.eclipse.ui.internal.quickaccess; > >-import java.util.ArrayList; >-import java.util.List; >-import java.util.StringTokenizer; > > import org.eclipse.jface.resource.ImageDescriptor; > >@@ -35,20 +32,6 @@ > } > > /** >- * @return a string containing the first character of every word for camel >- * case checking. >- */ >- private static String getCamelCase(String label) { >- StringTokenizer tokenizer = new StringTokenizer(label); >- StringBuffer camelCase = new StringBuffer(); >- while (tokenizer.hasMoreTokens()) { >- String word = tokenizer.nextToken(); >- camelCase.append(word.charAt(0)); >- } >- return camelCase.toString().toLowerCase(); >- } >- >- /** > * Returns the label to be displayed to the user. > * > * @return the label >@@ -95,15 +78,17 @@ > * @param filter > * @return > */ >- public QuickAccessEntry match(String filter, QuickAccessProvider providerForMatching) { >- String sortLabel = getSortLabel().toLowerCase(); >- int index = sortLabel.indexOf(filter); >+ public QuickAccessEntry match(String filter, >+ QuickAccessProvider providerForMatching) { >+ String sortLabel = getLabel(); >+ int index = sortLabel.toLowerCase().indexOf(filter); > if (index != -1) { >- return new QuickAccessEntry(this, providerForMatching, new int[][] { { >- index, index + filter.length() - 1 } }, EMPTY_INDICES); >+ return new QuickAccessEntry(this, providerForMatching, >+ new int[][] { { index, index + filter.length() - 1 } }, >+ EMPTY_INDICES); > } >- String combinedLabel = (providerForMatching.getName() + " " + getLabel()).toLowerCase(); //$NON-NLS-1$ >- index = combinedLabel.indexOf(filter); >+ String combinedLabel = (providerForMatching.getName() + " " + getLabel()); //$NON-NLS-1$ >+ index = combinedLabel.toLowerCase().indexOf(filter); > if (index != -1) { > int lengthOfElementMatch = index + filter.length() > - providerForMatching.getName().length() - 1; >@@ -112,21 +97,22 @@ > new int[][] { { 0, lengthOfElementMatch - 1 } }, > new int[][] { { index, index + filter.length() - 1 } }); > } >- return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES, >- new int[][] { { index, index + filter.length() - 1 } }); >+ return new QuickAccessEntry(this, providerForMatching, >+ EMPTY_INDICES, new int[][] { { index, >+ index + filter.length() - 1 } }); > } >- String camelCase = getCamelCase(sortLabel); >+ String camelCase = CamelUtil.getCamelCase(sortLabel); > index = camelCase.indexOf(filter); > if (index != -1) { >- int[][] indices = getCamelCaseIndices(sortLabel, index, filter >+ int[][] indices = CamelUtil.getCamelCaseIndices(sortLabel, index, filter > .length()); > return new QuickAccessEntry(this, providerForMatching, indices, > EMPTY_INDICES); > } >- String combinedCamelCase = getCamelCase(combinedLabel); >+ String combinedCamelCase = CamelUtil.getCamelCase(combinedLabel); > index = combinedCamelCase.indexOf(filter); > if (index != -1) { >- String providerCamelCase = getCamelCase(providerForMatching >+ String providerCamelCase = CamelUtil.getCamelCase(providerForMatching > .getName()); > int lengthOfElementMatch = index + filter.length() > - providerCamelCase.length(); >@@ -134,45 +120,14 @@ > return new QuickAccessEntry( > this, > providerForMatching, >- getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch), >- getCamelCaseIndices(providerForMatching.getName(), index, filter >- .length() >- - lengthOfElementMatch)); >+ CamelUtil.getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch), >+ CamelUtil.getCamelCaseIndices(providerForMatching.getName(), >+ index, filter.length() - lengthOfElementMatch)); > } >- return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES, >- getCamelCaseIndices(providerForMatching.getName(), index, filter >- .length())); >+ return new QuickAccessEntry(this, providerForMatching, >+ EMPTY_INDICES, CamelUtil.getCamelCaseIndices(providerForMatching >+ .getName(), index, filter.length())); > } > return null; > } >- >- /** >- * @param camelCase >- * @param filter >- * @param index >- * @return >- */ >- private int[][] getCamelCaseIndices(String original, int start, int length) { >- List result = new ArrayList(); >- int index = 0; >- while (start > 0) { >- index = original.indexOf(' ', index); >- while (original.charAt(index) == ' ') { >- index++; >- } >- start--; >- } >- while (length > 0) { >- result.add(new int[] { index, index }); >- index = original.indexOf(' ', index); >- if (index != -1) { >- while (index < original.length() >- && original.charAt(index) == ' ') { >- index++; >- } >- } >- length--; >- } >- return (int[][]) result.toArray(new int[result.size()][]); >- } > } >Index: Eclipse UI/org/eclipse/ui/internal/quickaccess/CamelUtil.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/quickaccess/CamelUtil.java >diff -N Eclipse UI/org/eclipse/ui/internal/quickaccess/CamelUtil.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/quickaccess/CamelUtil.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,97 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 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 >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.quickaccess; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CamelUtil { >+ >+ /** >+ * @param s >+ * @return a string containing the first character of every word for camel >+ * case checking. >+ */ >+ public static String getCamelCase(String s) { >+ StringBuffer result = new StringBuffer(); >+ if (s.length() > 0) { >+ int index = 0; >+ while (index != -1) { >+ result.append(s.charAt(index)); >+ index = getNextCamelIndex(s, index + 1); >+ } >+ } >+ return result.toString().toLowerCase(); >+ } >+ >+ /** >+ * Return an array with start/end indices for the characters used for camel >+ * case matching, ignoring the first (start) many camel case characters >+ * >+ * @param s >+ * @param start >+ * @param length >+ * @return >+ */ >+ public static int[][] getCamelCaseIndices(String s, int start, int length) { >+ List result = new ArrayList(); >+ int index = 0; >+ while (start > 0) { >+ index = getNextCamelIndex(s, index + 1); >+ start--; >+ } >+ while (length > 0) { >+ result.add(new int[] { index, index }); >+ index = getNextCamelIndex(s, index + 1); >+ length--; >+ } >+ return (int[][]) result.toArray(new int[result.size()][]); >+ } >+ >+ /** >+ * Returns the next index to be used for camel case matching. >+ * >+ * @param s >+ * @param index >+ * @return >+ */ >+ public static int getNextCamelIndex(String s, int index) { >+ char c; >+ while (index < s.length() && !(isIgnoredForCamelCase(c = s.charAt(index))) >+ && Character.isLowerCase(c)) { >+ index++; >+ } >+ while (index < s.length() && isIgnoredForCamelCase(c = s.charAt(index))) { >+ index++; >+ } >+ if (index >= s.length()) { >+ index = -1; >+ } >+ return index; >+ } >+ >+ /** >+ * Returns true if the given character is to be ignored for camel case >+ * matching purposes. >+ * >+ * @param c >+ * @return >+ */ >+ public static boolean isIgnoredForCamelCase(char c) { >+ return !Character.isLetterOrDigit(c); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 185824
: 66181