From 951868f5906a74c3b0303f1c76c52a0741eb2b75 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 11 Oct 2016 03:40:25 +0300 Subject: [PATCH] Explicitly filter out classes found by DataBindingClassFinder and DataBindingComponentClassFinder for scope without sources (KT-12402) This change is temporary, and it should be reverted when the original problem in DataBinding IDE support is fixed. --- .../jvm/GlobalSearchScopeWithModuleSources.kt | 19 ++++++++++++ .../resolve/jvm/KotlinJavaPsiFacade.java | 30 ++++++++++++++++++- .../idea/caches/resolve/IdeaModuleInfos.kt | 3 +- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/GlobalSearchScopeWithModuleSources.kt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/GlobalSearchScopeWithModuleSources.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/GlobalSearchScopeWithModuleSources.kt new file mode 100644 index 00000000000..5fbdba829fc --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/GlobalSearchScopeWithModuleSources.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-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 org.jetbrains.kotlin.resolve.jvm + +interface GlobalSearchScopeWithModuleSources \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/KotlinJavaPsiFacade.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/KotlinJavaPsiFacade.java index 23316e900cf..1cdcc89d34d 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/KotlinJavaPsiFacade.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/KotlinJavaPsiFacade.java @@ -43,6 +43,7 @@ import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.KotlinLanguage; +import org.jetbrains.kotlin.load.java.JavaClassFinderImpl; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus; import org.jetbrains.kotlin.name.ClassId; @@ -117,7 +118,30 @@ public class KotlinJavaPsiFacade { } else { PsiClass aClass = finder.findClass(qualifiedName, scope); - if (aClass != null) return aClass; + if (aClass != null) { + if (scope instanceof JavaClassFinderImpl.FilterOutKotlinSourceFilesScope) { + GlobalSearchScope baseScope = ((JavaClassFinderImpl.FilterOutKotlinSourceFilesScope) scope).getBase(); + boolean isSourcesScope = baseScope instanceof GlobalSearchScopeWithModuleSources; + + if (!isSourcesScope) { + Object originalFinder = (finder instanceof KotlinPsiElementFinderWrapperImpl) + ? ((KotlinPsiElementFinderWrapperImpl) finder).getOriginal() + : finder; + + // Temporary fix for #KT-12402 + boolean isAndroidDataBindingClassWriter = originalFinder.getClass().getName() + .equals("com.android.tools.idea.databinding.DataBindingClassFinder"); + boolean isAndroidDataBindingComponentClassWriter = originalFinder.getClass().getName() + .equals("com.android.tools.idea.databinding.DataBindingComponentClassFinder"); + + if (isAndroidDataBindingClassWriter || isAndroidDataBindingComponentClassWriter) { + continue; + } + } + } + + return aClass; + } } } @@ -286,6 +310,10 @@ public class KotlinJavaPsiFacade { this.finder = finder; } + public PsiElementFinder getOriginal() { + return finder; + } + @Override public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) { return finder.findClass(qualifiedName, scope); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt index 4cfca1a9b61..e3fb8d90645 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt @@ -31,6 +31,7 @@ import com.intellij.util.SmartList import org.jetbrains.kotlin.analyzer.ModuleInfo import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.jvm.GlobalSearchScopeWithModuleSources import org.jetbrains.kotlin.utils.alwaysNull import org.jetbrains.kotlin.utils.emptyOrSingletonList import java.lang.reflect.Method @@ -169,7 +170,7 @@ internal fun ModuleSourceInfo.isTests() = this is ModuleTestSourceInfo fun Module.productionSourceInfo(): ModuleProductionSourceInfo = ModuleProductionSourceInfo(this) fun Module.testSourceInfo(): ModuleTestSourceInfo = ModuleTestSourceInfo(this) -private abstract class ModuleSourceScope(val module: Module) : GlobalSearchScope(module.project) { +private abstract class ModuleSourceScope(val module: Module) : GlobalSearchScope(module.project), GlobalSearchScopeWithModuleSources { override fun compare(file1: VirtualFile, file2: VirtualFile) = 0 override fun isSearchInModuleContent(aModule: Module) = aModule == module override fun isSearchInLibraries() = false