Use special index to record files corresponding to static facade classes.
This commit is contained in:
committed by
Michael Bogdanov
parent
ab8b5d05ed
commit
83336553df
+3
-2
@@ -214,8 +214,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<PsiClass> getFacadeClasses(@NotNull FqName facadeFqName, @NotNull GlobalSearchScope scope) {
|
||||
Collection<JetFile> filesInPackage = findFilesForPackage(facadeFqName.parent(), scope);
|
||||
List<JetFile> filesForFacade = PackagePartClassUtils.getFilesForFacade(facadeFqName, filesInPackage);
|
||||
Collection<JetFile> filesForFacade = findFilesForFacade(facadeFqName, scope);
|
||||
if (filesForFacade.isEmpty()) return Collections.emptyList();
|
||||
|
||||
//noinspection RedundantTypeArguments
|
||||
@@ -226,6 +225,8 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> findFilesForFacade(@NotNull FqName facadeFqName, @NotNull GlobalSearchScope scope) {
|
||||
// TODO We need a way to plug some platform-dependent stuff into LazyTopDownAnalyzer.
|
||||
// It already performs some ad hoc stuff for packages->files mapping, anyway.
|
||||
Collection<JetFile> filesInPackage = findFilesForPackage(facadeFqName.parent(), scope);
|
||||
return PackagePartClassUtils.getFilesForFacade(facadeFqName, filesInPackage);
|
||||
}
|
||||
|
||||
+9
-3
@@ -77,8 +77,14 @@ public class PackagePartClassUtils {
|
||||
|
||||
@NotNull
|
||||
public static FqName getPackagePartFqName(@NotNull FqName facadeFqName, @NotNull VirtualFile file, @Nullable JetFile jetFile) {
|
||||
String fileName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(file.getName()));
|
||||
return facadeFqName.parent().child(Name.identifier(getSanitizedClassNameBase(fileName) + FACADE_CLASS_NAME_SUFFIX));
|
||||
String fileName = file.getName();
|
||||
return getStaticFacadeClassFqNameForFile(facadeFqName.parent(), fileName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static FqName getStaticFacadeClassFqNameForFile(@NotNull FqName packageFqName, String fileName) {
|
||||
String nameWithoutExtension = FileUtil.getNameWithoutExtension(PathUtil.getFileName(fileName));
|
||||
return packageFqName.child(Name.identifier(getSanitizedClassNameBase(nameWithoutExtension) + FACADE_CLASS_NAME_SUFFIX));
|
||||
}
|
||||
|
||||
public static boolean isFacadeClassFqName(@NotNull FqName classFqName) {
|
||||
@@ -98,7 +104,7 @@ public class PackagePartClassUtils {
|
||||
|
||||
@NotNull
|
||||
public static FqName getPackagePartFqName(@NotNull JetFile file) {
|
||||
return getPackagePartFqName(getPackageClassFqName(file.getPackageFqName()), file.getVirtualFile(), file);
|
||||
return getStaticFacadeClassFqNameForFile(file.getPackageFqName(), file.getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-6
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade;
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetFullClassNameIndex;
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelClassByPackageIndex;
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil;
|
||||
import org.jetbrains.kotlin.idea.stubindex.StaticFacadeIndexUtil;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
@@ -350,16 +351,12 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> findFilesForFacade(@NotNull FqName facadeFqName, @NotNull GlobalSearchScope scope) {
|
||||
// TODO naive version. Production variant should use an equivalent of JetExactPackageIndex.
|
||||
Collection<JetFile> packageFiles = findFilesForPackage(facadeFqName.parent(), scope);
|
||||
return PackagePartClassUtils.getFilesForFacade(facadeFqName, packageFiles);
|
||||
return StaticFacadeIndexUtil.findFilesForStaticFacade(facadeFqName, kotlinSourceAndClassFiles(scope, project), project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<KotlinLightFacadeClassInfo> findFacadeClassesInfos(FqName facadeFqName, GlobalSearchScope scope) {
|
||||
// TODO naive version. Production variant should use an equivalent of JetExactPackageIndex.
|
||||
Collection<JetFile> packageFiles = findFilesForPackage(facadeFqName.parent(), scope);
|
||||
List<JetFile> facadeFiles = PackagePartClassUtils.getFilesForFacade(facadeFqName, packageFiles);
|
||||
Collection<JetFile> facadeFiles = findFilesForFacade(facadeFqName, scope);
|
||||
Map<IdeaModuleInfo, List<JetFile>> filesByInfo = groupByModuleInfo(facadeFiles);
|
||||
List<KotlinLightFacadeClassInfo> result = new ArrayList<KotlinLightFacadeClassInfo>();
|
||||
for (Map.Entry<IdeaModuleInfo, List<JetFile>> entry : filesByInfo.entrySet()) {
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.idea.stubindex
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import com.intellij.psi.stubs.StubIndexKey
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
|
||||
public class JetStaticFacadeClassIndex private constructor() : StringStubIndexExtension<JetFile>() {
|
||||
override fun getKey(): StubIndexKey<String, JetFile> = KEY
|
||||
|
||||
override fun get(key: String, project: Project, scope: GlobalSearchScope) =
|
||||
super.get(key, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project))
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(javaClass<JetStaticFacadeClassIndex>())
|
||||
|
||||
public val INSTANCE: JetStaticFacadeClassIndex = JetStaticFacadeClassIndex()
|
||||
|
||||
public fun getInstance(): JetStaticFacadeClassIndex = INSTANCE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.idea.stubindex
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object StaticFacadeIndexUtil {
|
||||
|
||||
platformStatic public fun findFilesForStaticFacade(
|
||||
facadeFqName: FqName,
|
||||
searchScope: GlobalSearchScope,
|
||||
project: Project
|
||||
) : Collection<JetFile> =
|
||||
JetStaticFacadeClassIndex.INSTANCE.get(facadeFqName.asString(), project, searchScope)
|
||||
|
||||
}
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.kotlin.idea.stubindex;
|
||||
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.stubs.*;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.StubIndexService;
|
||||
import org.jetbrains.kotlin.util.UtilPackage;
|
||||
@@ -33,6 +35,12 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
FqName packageFqName = stub.getPackageFqName();
|
||||
|
||||
sink.occurrence(JetExactPackagesIndex.getInstance().getKey(), packageFqName.asString());
|
||||
|
||||
JetFile psi = stub.getPsi();
|
||||
if (psi != null) {
|
||||
FqName staticFacadeFqName = PackagePartClassUtils.getPackagePartFqName(psi);
|
||||
sink.occurrence(JetStaticFacadeClassIndex.INSTANCE.getKey(), staticFacadeFqName.asString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -497,6 +497,7 @@
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.JetAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.JetProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.JetProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.JetStaticFacadeClassIndex"/>
|
||||
|
||||
<psi.classFileDecompiler implementation="org.jetbrains.kotlin.idea.decompiler.JetClassFileDecompiler"/>
|
||||
<psi.classFileDecompiler implementation="org.jetbrains.kotlin.idea.decompiler.KotlinJavaScriptMetaFileDecompiler"/>
|
||||
|
||||
Reference in New Issue
Block a user