diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java index 971f6e2b0171..44860d211e60 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java @@ -205,11 +205,11 @@ public class LowLevelSearchUtil { if (index > startOffset) { char c = textArray != null ? textArray[index - 1]:text.charAt(index - 1); if (Character.isJavaIdentifierPart(c) && c != '$') { - if (index < 2 || !isNotEscapedBackslash(text, textArray, startOffset, index-2)) { //escape sequence + if (searcher.isHandleEscapeSequences() && (index < 2 || !isNotEscapedBackslash(text, textArray, startOffset, index-2))) { //escape sequence continue; } } - else if (index > 0 && isNotEscapedBackslash(text, textArray, startOffset, index-1)) { + else if (index > 0 && searcher.isHandleEscapeSequences() && isNotEscapedBackslash(text, textArray, startOffset, index-1)) { continue; } } diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 9e91f312ddb8..d751f17573d1 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -126,14 +126,14 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { public AsyncFuture processElementsWithWordAsync(@NotNull final TextOccurenceProcessor processor, @NotNull SearchScope searchScope, @NotNull final String text, - short searchContext, + final short searchContext, final boolean caseSensitively) { if (text.isEmpty()) { return AsyncFutureFactory.wrapException(new IllegalArgumentException("Cannot search for elements with empty text")); } final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (searchScope instanceof GlobalSearchScope) { - StringSearcher searcher = new StringSearcher(text, caseSensitively, true); + StringSearcher searcher = new StringSearcher(text, caseSensitively, true, searchContext == UsageSearchContext.IN_STRINGS); return processElementsWithTextInGlobalScopeAsync(processor, (GlobalSearchScope)searchScope, @@ -154,6 +154,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { text, caseSensitively, ignoreInjectedPsi, + searchContext == UsageSearchContext.IN_STRINGS, progress); } }); @@ -165,11 +166,12 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { final String word, final boolean caseSensitive, final boolean ignoreInjectedPsi, + final boolean handleEscapeSequences, final ProgressIndicator progress) { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { - StringSearcher searcher = new StringSearcher(word, caseSensitive, true); + StringSearcher searcher = new StringSearcher(word, caseSensitive, true, handleEscapeSequences); return LowLevelSearchUtil.processElementsContainingWordInElement(processor, scopeElement, searcher, !ignoreInjectedPsi, progress); } @@ -389,7 +391,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { } }); - final StringSearcher searcher = new StringSearcher(qName, true, true); + final StringSearcher searcher = new StringSearcher(qName, true, true, false); if (progress != null) { progress.pushState(); @@ -615,7 +617,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { final Map searchers = new HashMap(); final Set allWords = new TreeSet(); for (RequestWithProcessor singleRequest : candidateFiles.values()) { - searchers.put(singleRequest, new StringSearcher(singleRequest.request.word, singleRequest.request.caseSensitive, true)); + searchers.put(singleRequest, new StringSearcher(singleRequest.request.word, singleRequest.request.caseSensitive, true, false)); allWords.add(singleRequest.request.word); } diff --git a/platform/platform-tests/testSrc/com/intellij/psi/impl/search/LowLevelSearchUtilTest.java b/platform/platform-tests/testSrc/com/intellij/psi/impl/search/LowLevelSearchUtilTest.java index 49a22d5c69e1..01517b7b96c8 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/impl/search/LowLevelSearchUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/impl/search/LowLevelSearchUtilTest.java @@ -43,7 +43,7 @@ public class LowLevelSearchUtilTest extends TestCase { } private static int doTest(String pattern, String text) { - StringSearcher searcher = new StringSearcher(pattern, true, true); + StringSearcher searcher = new StringSearcher(pattern, true, true, true); return LowLevelSearchUtil.searchWord(text, 0, text.length(), searcher, null); } } diff --git a/platform/util/src/com/intellij/util/text/StringSearcher.java b/platform/util/src/com/intellij/util/text/StringSearcher.java index 69ae27789464..e3a0ab9761c8 100644 --- a/platform/util/src/com/intellij/util/text/StringSearcher.java +++ b/platform/util/src/com/intellij/util/text/StringSearcher.java @@ -32,12 +32,18 @@ public class StringSearcher { private final boolean myCaseSensitive; private final boolean myForwardDirection; private final boolean myJavaIdentifier; + private final boolean myHandleEscapeSequences; public int getPatternLength() { return myPatternLength; } public StringSearcher(@NotNull String pattern, boolean caseSensitive, boolean forwardDirection) { + this(pattern, caseSensitive, forwardDirection, false); + } + + public StringSearcher(@NotNull String pattern, boolean caseSensitive, boolean forwardDirection, boolean handleEscapeSequences) { + myHandleEscapeSequences = handleEscapeSequences; LOG.assertTrue(!pattern.isEmpty()); myPattern = pattern; myCaseSensitive = caseSensitive; @@ -66,6 +72,10 @@ public class StringSearcher { return myForwardDirection; } + public boolean isHandleEscapeSequences() { + return myHandleEscapeSequences; + } + public int scan(@NotNull CharSequence text) { return scan(text,0,text.length()); }