mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 408870 - Do not require a whitespace after 'operator' when searching
for an overloaded operator in the Search or Open Element dialogs Change-Id: Idd0363cd2cb3d44a822fb2ebc34582feb2238022 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
4e90a96767
commit
7ece374afd
5 changed files with 48 additions and 2 deletions
|
@ -379,4 +379,14 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
query= makeProjectQuery("f");
|
||||
assertOccurrences(query, 6);
|
||||
}
|
||||
|
||||
// struct S {
|
||||
// bool operator<(const S&, const S&);
|
||||
// };
|
||||
|
||||
// // empty
|
||||
public void testOverloadedOperatorNoSpace_408870() throws Exception {
|
||||
CSearchQuery query = makeProjectQuery("operator<");
|
||||
assertOccurrences(query, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
|
|||
import org.eclipse.cdt.internal.core.browser.IndexModelUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
|
||||
/**
|
||||
* A dialog to select an element from a filterable list of elements.
|
||||
|
@ -349,6 +350,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
|||
}
|
||||
|
||||
protected void scheduleUpdate(String filterText) {
|
||||
filterText= CSearchUtil.adjustSearchStringForOperators(filterText);
|
||||
char[] newPrefix= toPrefix(filterText);
|
||||
final char[] currentPrefix= fUpdateJob.getCurrentPrefix();
|
||||
final boolean equivalentPrefix= isEquivalentPrefix(currentPrefix, newPrefix);
|
||||
|
|
|
@ -439,7 +439,7 @@ public class CSearchPage extends DialogPage implements ISearchPage {
|
|||
final String text = patternCombo.getText();
|
||||
final char[] newChars= event.text.toCharArray();
|
||||
final StringBuilder result= new StringBuilder(newChars.length);
|
||||
boolean relax= prefix(text, event.start, result).contains(Keywords.OPERATOR + " "); //$NON-NLS-1$
|
||||
boolean relax= prefix(text, event.start, result).contains(Keywords.OPERATOR);
|
||||
for (final char c : newChars) {
|
||||
switch (c) {
|
||||
case '_':
|
||||
|
@ -459,7 +459,6 @@ public class CSearchPage extends DialogPage implements ISearchPage {
|
|||
case '%': case '^': case '(': case ')':
|
||||
case '[': case ']':
|
||||
if (prefix(text, event.start, result).endsWith(Keywords.OPERATOR)) {
|
||||
result.append(' ');
|
||||
relax= true;
|
||||
}
|
||||
if (relax)
|
||||
|
|
|
@ -74,6 +74,9 @@ public class CSearchPatternQuery extends CSearchQuery {
|
|||
int flags) throws PatternSyntaxException {
|
||||
super(scope, flags);
|
||||
this.scopeDesc = scopeDesc;
|
||||
|
||||
// adjust the pattern string to accomodate searches for operators
|
||||
patternStr = CSearchUtil.adjustSearchStringForOperators(patternStr);
|
||||
|
||||
// remove spurious whitespace, which will make the search fail 100% of the time
|
||||
this.patternStr = patternStr.trim();
|
||||
|
|
|
@ -66,4 +66,36 @@ public class CSearchUtil {
|
|||
}
|
||||
return isWrite;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true whether 'ch' could the first character of an overloadable C++ operator.
|
||||
*/
|
||||
private static boolean isOperatorChar(char ch) {
|
||||
switch (ch) {
|
||||
case '&': case '|': case '+': case '-':
|
||||
case '!': case '=': case '>': case '<':
|
||||
case '%': case '^': case '(': case ')':
|
||||
case '[': case '~':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If 'searchStr' contains the name of an overloadable operator with no
|
||||
* space between 'operator' and the operator (e.g. 'operator<'), insert
|
||||
* a space (yielding e.g. 'operator <'). This is necessary because the
|
||||
* binding names for overloaded operators in the index contain such a
|
||||
* space, and the search wouldn't find them otherwise.
|
||||
*/
|
||||
public static String adjustSearchStringForOperators(String searchStr) {
|
||||
int operatorIndex = searchStr.indexOf("operator"); //$NON-NLS-1$
|
||||
int operatorCharIndex = operatorIndex + 8; // "operator" is 8 characters
|
||||
if (operatorCharIndex < searchStr.length() && isOperatorChar(searchStr.charAt(operatorCharIndex))) {
|
||||
searchStr = searchStr.substring(0, operatorCharIndex) + ' ' + searchStr.substring(operatorCharIndex);
|
||||
}
|
||||
return searchStr;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue