Implement stub based package declaration provider for lazy resolve
Implement StubPackageMemberDeclarationProvider Introduce DeclarationProviderFactoryService to provide difference factories in CLI and Plugin When indexing treat top level declarations without name specially so that they can be found in index Implement PluginDeclarationProviderFactoryService which uses file based approach for non indexed files and stub based for others
This commit is contained in:
@@ -108,6 +108,9 @@
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
||||
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.stubindex.resolve.PluginDeclarationProviderFactoryService"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
|
||||
|
||||
private static final JetAllPackagesIndex ourInstance = new JetAllPackagesIndex();
|
||||
|
||||
@NotNull
|
||||
public static JetAllPackagesIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
@@ -48,6 +49,7 @@ public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||
|
||||
@@ -30,6 +30,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
|
||||
|
||||
private static final JetFullClassNameIndex ourInstance = new JetFullClassNameIndex();
|
||||
|
||||
@NotNull
|
||||
public static JetFullClassNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
@@ -42,6 +43,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||
|
||||
@@ -27,11 +27,13 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
|
||||
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||
public static JetSourceFilterScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) {
|
||||
@NotNull
|
||||
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) {
|
||||
return new JetSourceFilterScope(delegate, true);
|
||||
}
|
||||
|
||||
public static JetSourceFilterScope kotlinSources(@NotNull GlobalSearchScope delegate) {
|
||||
@NotNull
|
||||
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate) {
|
||||
return new JetSourceFilterScope(delegate, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class JetTopLevelFunctionsFqnNameIndex extends StringStubIndexExtension<J
|
||||
|
||||
private static final JetTopLevelFunctionsFqnNameIndex INSTANCE = new JetTopLevelFunctionsFqnNameIndex();
|
||||
|
||||
@NotNull
|
||||
public static JetTopLevelFunctionsFqnNameIndex getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
@@ -45,6 +46,7 @@ public class JetTopLevelFunctionsFqnNameIndex extends StringStubIndexExtension<J
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||
|
||||
@@ -30,6 +30,7 @@ public class JetTopLevelPropertiesFqnNameIndex extends StringStubIndexExtension<
|
||||
|
||||
private static final JetTopLevelPropertiesFqnNameIndex INSTANCE = new JetTopLevelPropertiesFqnNameIndex();
|
||||
|
||||
@NotNull
|
||||
public static JetTopLevelPropertiesFqnNameIndex getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
@@ -42,6 +43,7 @@ public class JetTopLevelPropertiesFqnNameIndex extends StringStubIndexExtension<
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||
|
||||
@@ -120,30 +120,29 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
else {
|
||||
sink.occurrence(JetTopLevelExtensionFunctionShortNameIndex.getInstance().getKey(), name);
|
||||
}
|
||||
|
||||
FqName topFQName = stub.getFqName();
|
||||
if (topFQName != null) {
|
||||
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||
}
|
||||
}
|
||||
|
||||
sink.occurrence(JetFunctionShortNameIndex.getInstance().getKey(), name);
|
||||
}
|
||||
// can have special fq name in case of syntactically incorrect function with no name
|
||||
FqName topFQName = stub.getFqName();
|
||||
if (topFQName != null) {
|
||||
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
|
||||
String propertyName = stub.getName();
|
||||
if (propertyName != null) {
|
||||
if (stub.isTopLevel()) {
|
||||
FqName topFQName = stub.getFqName();
|
||||
if (topFQName != null) {
|
||||
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||
}
|
||||
}
|
||||
|
||||
sink.occurrence(JetPropertyShortNameIndex.getInstance().getKey(), propertyName);
|
||||
}
|
||||
// can have special fq name in case of syntactically incorrect function with no name
|
||||
if (stub.isTopLevel()) {
|
||||
FqName topFQName = stub.getFqName();
|
||||
if (topFQName != null) {
|
||||
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.plugin.stubindex.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractStubDeclarationProvider implements DeclarationProvider {
|
||||
@Override
|
||||
public List<JetDeclaration> getAllDeclarations() {
|
||||
// TODO:
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name) {
|
||||
// TODO:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.stubindex.resolve
|
||||
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedPackageMemberDeclarationProvider
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
public class CombinedPackageMemberDeclarationProvider(val providers: Collection<PackageMemberDeclarationProvider>) : PackageMemberDeclarationProvider {
|
||||
override fun getAllDeclaredPackages() = providers.flatMap { it.getAllDeclaredPackages() }
|
||||
|
||||
override fun getPackageDeclarations(fqName: FqName) = providers.flatMap { it.getPackageDeclarations(fqName) }
|
||||
|
||||
override fun getPackageFiles() = providers.flatMap { it.getPackageFiles() }
|
||||
|
||||
override fun getAllDeclarations() = providers.flatMap { it.getAllDeclarations() }
|
||||
|
||||
override fun getFunctionDeclarations(name: Name) = providers.flatMap { it.getFunctionDeclarations(name) }
|
||||
|
||||
override fun getPropertyDeclarations(name: Name) = providers.flatMap { it.getPropertyDeclarations(name) }
|
||||
|
||||
override fun getClassOrObjectDeclarations(name: Name) = providers.flatMap { it.getClassOrObjectDeclarations(name) }
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.stubindex.resolve
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.*
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import java.util.Arrays
|
||||
|
||||
public class PluginDeclarationProviderFactory(
|
||||
private val project: Project,
|
||||
private val indexedFilesScope: GlobalSearchScope,
|
||||
private val storageManager: StorageManager,
|
||||
private val nonIndexedFiles: Collection<JetFile>
|
||||
) : AbstractDeclarationProviderFactory(storageManager) {
|
||||
private val fileBasedDeclarationProviderFactory = FileBasedDeclarationProviderFactory(storageManager, nonIndexedFiles)
|
||||
|
||||
override fun getClassMemberDeclarationProvider(classLikeInfo: JetClassLikeInfo): ClassMemberDeclarationProvider {
|
||||
return PsiBasedClassMemberDeclarationProvider(storageManager, classLikeInfo)
|
||||
}
|
||||
|
||||
override fun createPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||
val fileBasedProvider = fileBasedDeclarationProviderFactory.getPackageMemberDeclarationProvider(name)
|
||||
val stubBasedProvider = getStubBasedPackageMemberDeclarationProvider(name)
|
||||
return when {
|
||||
fileBasedProvider == null && stubBasedProvider == null -> null
|
||||
fileBasedProvider == null -> stubBasedProvider
|
||||
stubBasedProvider == null -> fileBasedProvider
|
||||
else -> CombinedPackageMemberDeclarationProvider(listOf(stubBasedProvider, fileBasedProvider))
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||
//TODO: better check
|
||||
val files = JetAllPackagesIndex.getInstance().get(name.asString(), project, indexedFilesScope)
|
||||
if (files.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return StubBasedPackageMemberDeclarationProvider(name, project, indexedFilesScope)
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.stubindex.resolve
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Condition
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
|
||||
public class PluginDeclarationProviderFactoryService : DeclarationProviderFactoryService() {
|
||||
|
||||
override fun create(project: Project, storageManager: StorageManager, files: Collection<JetFile>): DeclarationProviderFactory {
|
||||
val indexedSourcesScope = JetSourceFilterScope.kotlinSourcesAndLibraries(GlobalSearchScope.allScope(project))
|
||||
val nonIndexedFiles = files.filter {
|
||||
file ->
|
||||
!file.isPhysical() || !indexedSourcesScope.contains(file.getVirtualFile()!!)
|
||||
}
|
||||
val physicalFilesScope = GlobalSearchScope.filesScope(project, files.filter { it.isPhysical() }.map { it.getVirtualFile()!! })
|
||||
val indexedFilesScope = indexedSourcesScope.intersectWith(physicalFilesScope)
|
||||
|
||||
return PluginDeclarationProviderFactory(project, indexedFilesScope, storageManager, nonIndexedFiles)
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.stubindex.resolve
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex
|
||||
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope.kotlinSources
|
||||
import org.jetbrains.jet.lang.resolve.name.numberOfSegments
|
||||
|
||||
public class StubBasedPackageMemberDeclarationProvider(
|
||||
private val fqName: FqName,
|
||||
private val project: Project,
|
||||
private val searchScope: GlobalSearchScope
|
||||
) : PackageMemberDeclarationProvider {
|
||||
|
||||
override fun getAllDeclarations(): List<JetDeclaration> {
|
||||
return TOP_LEVEL_DECLARATION_INDICES.flatMap {
|
||||
index ->
|
||||
val fqNames = index.getAllKeys(project).toSet().map { FqName(it) }.filter { !it.isRoot() && it.parent() == fqName }
|
||||
fqNames.flatMap { index.get(it.asString(), project, searchScope) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassOrObjectDeclarations(name: Name): Collection<JetClassOrObject> {
|
||||
return JetFullClassNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||
}
|
||||
|
||||
override fun getFunctionDeclarations(name: Name): Collection<JetNamedFunction> {
|
||||
return JetTopLevelFunctionsFqnNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||
}
|
||||
|
||||
override fun getPropertyDeclarations(name: Name): Collection<JetProperty> {
|
||||
return JetTopLevelPropertiesFqnNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||
}
|
||||
|
||||
override fun getAllDeclaredPackages(): Collection<FqName> {
|
||||
//TODO: duplication with light class generation support
|
||||
val allPackagesInProject = JetAllPackagesIndex.getInstance().getAllKeys(project)
|
||||
return allPackagesInProject.filter {
|
||||
val otherPackageFqName = FqName(it)
|
||||
!otherPackageFqName.isRoot() && otherPackageFqName.parent() == fqName
|
||||
}.map { FqName(it) }
|
||||
}
|
||||
|
||||
override fun getPackageDeclarations(fqName: FqName): Collection<NavigatablePsiElement> {
|
||||
if (fqName.isRoot()) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
|
||||
val files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope)
|
||||
return files.map {
|
||||
file ->
|
||||
JetPsiUtil.getPackageReference(file, fqName.numberOfSegments() - 1)
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
override fun getPackageFiles(): Collection<JetFile> {
|
||||
//TODO: duplicate with light class generation support
|
||||
val files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, kotlinSources(searchScope))
|
||||
return files.filter {
|
||||
fqName.equals(JetPsiUtil.getFQName(it))
|
||||
}
|
||||
}
|
||||
|
||||
private fun childName(name: Name): String {
|
||||
return fqName.child(name).asString()
|
||||
}
|
||||
}
|
||||
|
||||
private val TOP_LEVEL_DECLARATION_INDICES: List<StringStubIndexExtension<out JetNamedDeclaration>> = listOf(
|
||||
JetFullClassNameIndex.getInstance(),
|
||||
JetTopLevelFunctionsFqnNameIndex.getInstance(),
|
||||
JetTopLevelPropertiesFqnNameIndex.getInstance()
|
||||
)
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.plugin.stubindex.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PsiBasedClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
public class StubDeclarationProviderFactory implements DeclarationProviderFactory {
|
||||
|
||||
private final Project project;
|
||||
private final GlobalSearchScope searchScope;
|
||||
private final StorageManager storageManager;
|
||||
|
||||
public StubDeclarationProviderFactory(@NotNull Project project, @NotNull GlobalSearchScope scope, @NotNull StorageManager manager) {
|
||||
this.project = project;
|
||||
searchScope = scope;
|
||||
storageManager = manager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassMemberDeclarationProvider getClassMemberDeclarationProvider(@NotNull JetClassLikeInfo classLikeInfo) {
|
||||
return new PsiBasedClassMemberDeclarationProvider(storageManager, classLikeInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageMemberDeclarationProvider getPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
||||
return new StubPackageMemberDeclarationProvider(packageFqName, project, searchScope);
|
||||
}
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.stubindex.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.NavigatablePsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class StubPackageMemberDeclarationProvider extends AbstractStubDeclarationProvider implements PackageMemberDeclarationProvider {
|
||||
private final FqName fqName;
|
||||
private final Project project;
|
||||
private final GlobalSearchScope searchScope;
|
||||
|
||||
public StubPackageMemberDeclarationProvider(@NotNull FqName fqName, @NotNull Project project, @NotNull GlobalSearchScope searchScope) {
|
||||
this.fqName = fqName;
|
||||
this.project = project;
|
||||
this.searchScope = searchScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
|
||||
return JetTopLevelFunctionsFqnNameIndex.getInstance().get(fqName.child(name).toString(), project, searchScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetProperty> getPropertyDeclarations(@NotNull Name name) {
|
||||
return JetTopLevelPropertiesFqnNameIndex.getInstance().get(fqName.child(name).toString(), project, searchScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<FqName> getAllDeclaredPackages() {
|
||||
// get all packages in this project
|
||||
Collection<String> allPackagesInProject = JetAllPackagesIndex.getInstance().getAllKeys(project);
|
||||
return ContainerUtil.mapNotNull(allPackagesInProject, new Function<String, FqName>() {
|
||||
@Override
|
||||
public FqName fun(String packageFqName) {
|
||||
// filter by the search scope
|
||||
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(packageFqName, project, searchScope);
|
||||
if (files.isEmpty()) return null;
|
||||
return new FqName(packageFqName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<NavigatablePsiElement> getPackageDeclarations(final FqName fqName) {
|
||||
if (fqName.isRoot()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope);
|
||||
return ContainerUtil.map(files, new Function<JetFile, NavigatablePsiElement>() {
|
||||
@Override
|
||||
public NavigatablePsiElement fun(JetFile file) {
|
||||
return JetPsiUtil.getPackageReference(file, NamePackage.numberOfSegments(fqName) - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> getPackageFiles() {
|
||||
return JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.stubindex.resolve.StubPackageMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.plugin.stubindex.resolve.StubBasedPackageMemberDeclarationProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -37,8 +37,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.configureByText(JetFileType.INSTANCE,
|
||||
"package test.testing\n" +
|
||||
"fun some() {}");
|
||||
StubPackageMemberDeclarationProvider provider =
|
||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
StubBasedPackageMemberDeclarationProvider provider =
|
||||
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
List<JetNamedFunction> some = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("some")));
|
||||
|
||||
@@ -52,8 +52,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
||||
"fun other(v : Int) = 12\n" +
|
||||
"fun other(v : String) {}");
|
||||
|
||||
StubPackageMemberDeclarationProvider provider =
|
||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
StubBasedPackageMemberDeclarationProvider provider =
|
||||
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
List<JetNamedFunction> other = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("other")));
|
||||
Collection<String> functionTexts = Collections2.transform(other, new Function<JetNamedFunction, String>() {
|
||||
@@ -73,8 +73,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
||||
"package test.testing\n" +
|
||||
"val test = 12\n");
|
||||
|
||||
StubPackageMemberDeclarationProvider provider =
|
||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
StubBasedPackageMemberDeclarationProvider provider =
|
||||
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
List<JetProperty> testProperties = Lists.newArrayList(provider.getPropertyDeclarations(Name.identifier("test")));
|
||||
|
||||
@@ -85,7 +85,7 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testGetPackageByIntermediatePartition() {
|
||||
myFixture.configureByText(JetFileType.INSTANCE, "package first.second.third");
|
||||
|
||||
StubPackageMemberDeclarationProvider provider = new StubPackageMemberDeclarationProvider(
|
||||
StubBasedPackageMemberDeclarationProvider provider = new StubBasedPackageMemberDeclarationProvider(
|
||||
new FqName("first.second"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
Collection<NavigatablePsiElement> packageDeclarations = provider.getPackageDeclarations(new FqName("first.second"));
|
||||
|
||||
Reference in New Issue
Block a user