summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Walther2013-03-12 11:56:04 (EDT)
committer Dani Megert2013-03-12 11:57:40 (EDT)
commit04c4ef15a4f0dc527eb24db5f114794e397fe7b5 (patch)
tree49091dd3a372cfffa889dd88521297d2803135ac
parent0926366d519d68d9dd547f1e873c1bd5ff461370 (diff)
downloadeclipse.platform.text-04c4ef15a4f0dc527eb24db5f114794e397fe7b5.zip
eclipse.platform.text-04c4ef15a4f0dc527eb24db5f114794e397fe7b5.tar.gz
eclipse.platform.text-04c4ef15a4f0dc527eb24db5f114794e397fe7b5.tar.bz2
Fixed bug 402009: Whole word API and UI should not allow to be true if regex is true
-rw-r--r--org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java9
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/core/text/PatternConstructor.java11
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java9
3 files changed, 12 insertions, 17 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java
index bf7dbdc..8d59a01 100644
--- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java
+++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
+ * Christian Walther (Indel AG) - Bug 399094, 402009: Add whole word option to file search
*******************************************************************************/
package org.eclipse.search.tests.filesearch;
@@ -248,13 +248,6 @@ public class FileSearchTests extends TestCase {
engine.search(scope, collector, searchPattern, null);
assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
}
- {
- // regexp, whole word = true: match only nothing and non-word chars before and after
- Pattern searchPattern= PatternConstructor.createPattern("h[eio]ll", true, true, false, true);
- TestResultCollector collector= new TestResultCollector();
- engine.search(scope, collector, searchPattern, null);
- assertEquals("Number of whole-word results", 10, collector.getNumberOfResults());
- }
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/PatternConstructor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/PatternConstructor.java
index 7e94ade..2aa184e 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/PatternConstructor.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/PatternConstructor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -7,12 +7,15 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Christian Walther (Indel AG) - Bug 402009: Disallow "whole word" together with regex
*******************************************************************************/
package org.eclipse.search.internal.core.text;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import org.eclipse.core.runtime.Assert;
+
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.search.internal.ui.SearchMessages;
@@ -47,11 +50,7 @@ public class PatternConstructor {
public static Pattern createPattern(String pattern, boolean isRegex, boolean isStringMatcher, boolean isCaseSensitive, boolean isWholeWord) throws PatternSyntaxException {
if (isRegex) {
pattern= substituteLinebreak(pattern);
- if (isWholeWord) {
- StringBuffer buffer= new StringBuffer(pattern.length() + 10);
- buffer.append("\\b(?:").append(pattern).append(")\\b"); //$NON-NLS-1$ //$NON-NLS-2$
- pattern= buffer.toString();
- }
+ Assert.isTrue(!isWholeWord, "isWholeWord unsupported together with isRegex"); //$NON-NLS-1$
} else {
int len= pattern.length();
StringBuffer buffer= new StringBuffer(len + 10);
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
index 89f28e6..2ad0bf2 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
@@ -10,7 +10,7 @@
* Juerg Billeter, juergbi@ethz.ch - 47136 Search view should show match objects
* Ulrich Etter, etteru@ethz.ch - 47136 Search view should show match objects
* Roman Fuchs, fuchsro@ethz.ch - 47136 Search view should show match objects
- * Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
+ * Christian Walther (Indel AG) - Bug 399094, 402009: Add whole word option to file search
*******************************************************************************/
package org.eclipse.search.internal.ui.text;
@@ -250,7 +250,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
private ISearchQuery newQuery() throws CoreException {
SearchPatternData data= getPatternData();
- TextSearchPageInput input= new TextSearchPageInput(data.textPattern, data.isCaseSensitive, data.isRegExSearch, data.isWholeWord, createTextSearchScope());
+ TextSearchPageInput input= new TextSearchPageInput(data.textPattern, data.isCaseSensitive, data.isRegExSearch, data.isWholeWord && !data.isRegExSearch, createTextSearchScope());
return TextSearchQueryProvider.getPreferred().createQuery(input);
}
@@ -495,7 +495,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
private boolean validateRegex() {
if (fIsRegExCheckbox.getSelection()) {
try {
- PatternConstructor.createPattern(fPattern.getText(), true, true, fIsCaseSensitive, fIsWholeWord);
+ PatternConstructor.createPattern(fPattern.getText(), fIsCaseSensitive, true);
} catch (PatternSyntaxException e) {
String locMessage= e.getLocalizedMessage();
int i= 0;
@@ -576,6 +576,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
writeConfiguration();
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
+ fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
}
});
fIsRegExCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 2));
@@ -592,6 +593,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
fIsWholeWordCheckbox= new Button(group, SWT.CHECK);
fIsWholeWordCheckbox.setText(SearchMessages.SearchPage_wholeWord);
fIsWholeWordCheckbox.setSelection(fIsWholeWord);
+ fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
fIsWholeWordCheckbox.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fIsWholeWord= fIsWholeWordCheckbox.getSelection();
@@ -614,6 +616,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
fIsRegExCheckbox.setSelection(fIsRegExSearch);
fIsWholeWord= patternData.isWholeWord;
fIsWholeWordCheckbox.setSelection(fIsWholeWord);
+ fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
fPattern.setText(patternData.textPattern);
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
fFileTypeEditor.setFileTypes(patternData.fileNamePatterns);