diff --git a/java/java-tests/testData/compiler/compilerReferenceFindUsages/testFindUsagesInInjectedCode/Foo.java b/java/java-tests/testData/compiler/compilerReferenceFindUsages/testFindUsagesInInjectedCode/Foo.java new file mode 100644 index 000000000000..a84aa8c09978 --- /dev/null +++ b/java/java-tests/testData/compiler/compilerReferenceFindUsages/testFindUsagesInInjectedCode/Foo.java @@ -0,0 +1,7 @@ +class A { + + void m() { + String java = "class A { void m() { System.out.println(); }}"; + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesFindUsagesTest.java b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesFindUsagesTest.java new file mode 100644 index 000000000000..30f3e7a58df1 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesFindUsagesTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.compiler; + +import com.intellij.JavaTestUtil; +import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiReference; +import com.intellij.psi.impl.source.tree.injected.MyTestInjector; +import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.testFramework.SkipSlowTestLocally; + +@SkipSlowTestLocally +public class CompilerReferencesFindUsagesTest extends CompilerReferencesTestBase { + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/compiler/compilerReferenceFindUsages/"; + } + + public void testFindUsagesInInjectedCode() { + new MyTestInjector(getPsiManager()).injectAll(getTestRootDisposable()); + myFixture.configureByFile(getName() + "/Foo.java"); + rebuildProject(); + PsiClass classForSearch = myFixture.getJavaFacade().findClass("java.lang.System"); + PsiReference reference = assertOneElement(ReferencesSearch.search(classForSearch).findAll()); + assertTrue(InjectedLanguageManager.getInstance(getProject()).isInjectedFragment(((PsiReferenceExpressionImpl)reference).getContainingFile())); + } +} diff --git a/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTest.java b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTest.java index b174d9e4285b..6b625fd3b942 100644 --- a/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTest.java +++ b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTest.java @@ -36,22 +36,7 @@ import java.util.Set; import java.util.stream.Collectors; @SkipSlowTestLocally -public class CompilerReferencesTest extends AbstractCompilerAwareTest { - private boolean myDefaultEnableState; - - @Override - public void setUp() throws Exception { - myDefaultEnableState = CompilerReferenceService.IS_ENABLED_KEY.asBoolean(); - CompilerReferenceService.IS_ENABLED_KEY.setValue(true); - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - CompilerReferenceService.IS_ENABLED_KEY.setValue(myDefaultEnableState); - super.tearDown(); - } - +public class CompilerReferencesTest extends CompilerReferencesTestBase { protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath() + "/compiler/bytecodeReferences/"; } diff --git a/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTestBase.java b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTestBase.java new file mode 100644 index 000000000000..865da07caae7 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/compiler/CompilerReferencesTestBase.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.compiler; + +import com.intellij.codeInsight.completion.AbstractCompilerAwareTest; + +abstract class CompilerReferencesTestBase extends AbstractCompilerAwareTest { + private boolean myDefaultEnableState; + + @Override + public void setUp() throws Exception { + myDefaultEnableState = CompilerReferenceService.IS_ENABLED_KEY.asBoolean(); + CompilerReferenceService.IS_ENABLED_KEY.setValue(true); + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + CompilerReferenceService.IS_ENABLED_KEY.setValue(myDefaultEnableState); + super.tearDown(); + } +} diff --git a/platform/indexing-api/src/com/intellij/psi/search/SearchRequestCollector.java b/platform/indexing-api/src/com/intellij/psi/search/SearchRequestCollector.java index 8d30590a660c..ea83d1f5e53a 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/SearchRequestCollector.java +++ b/platform/indexing-api/src/com/intellij/psi/search/SearchRequestCollector.java @@ -80,21 +80,17 @@ public class SearchRequestCollector { Collection requests = null; if (searchTarget != null && (searchScope instanceof GlobalSearchScope) && ((searchContext & UsageSearchContext.IN_CODE) != 0 || searchContext == UsageSearchContext.ANY)) { for (ScopeOptimizer optimizer : CODE_USAGE_SCOPE_OPTIMIZER_EP_NAME.getExtensions()) { - //TODO final GlobalSearchScope optimizedCodeUsageSearchScope = optimizer.getScopeToExclude(searchTarget); if (optimizedCodeUsageSearchScope != null) { short exceptCodeSearchContext = searchContext == UsageSearchContext.ANY - ? (short)(searchContext ^ UsageSearchContext.IN_CODE) - : (UsageSearchContext.IN_COMMENTS | - UsageSearchContext.IN_STRINGS | - UsageSearchContext.IN_FOREIGN_LANGUAGES | - UsageSearchContext.IN_PLAIN_TEXT); - final GlobalSearchScope searchWithCodeUsageEffectiveScope = - ((GlobalSearchScope)searchScope).intersectWith(GlobalSearchScope.notScope(optimizedCodeUsageSearchScope)); - final GlobalSearchScope searchWithoutCodeUsageEffectiveScope = - ((GlobalSearchScope)searchScope).intersectWith(GlobalSearchScope.notScope(optimizedCodeUsageSearchScope)); - requests = ContainerUtil.list(new PsiSearchRequest(searchWithCodeUsageEffectiveScope, word, searchContext, caseSensitive, containerName, processor), - new PsiSearchRequest(searchWithoutCodeUsageEffectiveScope, word, exceptCodeSearchContext, caseSensitive, containerName, processor)); + ? (UsageSearchContext.IN_COMMENTS | + UsageSearchContext.IN_STRINGS | + UsageSearchContext.IN_FOREIGN_LANGUAGES | + UsageSearchContext.IN_PLAIN_TEXT) + : (short)(searchContext ^ UsageSearchContext.IN_CODE); + final GlobalSearchScope searchCodeUsageEffectiveScope = ((GlobalSearchScope)searchScope).intersectWith(GlobalSearchScope.notScope(optimizedCodeUsageSearchScope)); + requests = ContainerUtil.list(new PsiSearchRequest(searchCodeUsageEffectiveScope, word, UsageSearchContext.IN_CODE, caseSensitive, containerName, processor), + new PsiSearchRequest(searchScope, word, exceptCodeSearchContext, caseSensitive, containerName, processor)); } } }