Minor: Convert PackageIndexUtil to Kotlin
This commit is contained in:
@@ -10,7 +10,10 @@
|
|||||||
name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Psi> get(Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope) 2'>
|
name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Psi> get(Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope) 2'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item name='com.intellij.psi.stubs.StubIndex com.intellij.psi.stubs.StubIndex getInstance()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
name='com.intellij.psi.stubs.StubIndex java.util.Collection<Psi> get(com.intellij.psi.stubs.StubIndexKey<Key,Psi>, Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope)'>
|
name='com.intellij.psi.stubs.StubIndex java.util.Collection<Psi> get(com.intellij.psi.stubs.StubIndexKey<Key,Psi>, Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope)'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -1,80 +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;
|
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.Ref;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
|
||||||
import com.intellij.psi.stubs.StubIndex;
|
|
||||||
import com.intellij.psi.stubs.StubIndexKey;
|
|
||||||
import com.intellij.util.Processor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public final class PackageIndexUtil {
|
|
||||||
@NotNull
|
|
||||||
public static Collection<FqName> getSubPackageFqNames(
|
|
||||||
@NotNull FqName packageFqName,
|
|
||||||
@NotNull GlobalSearchScope scope,
|
|
||||||
@NotNull Project project
|
|
||||||
) {
|
|
||||||
return SubpackagesIndexService.OBJECT$.getInstance(project).getSubpackages(packageFqName, scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Collection<JetFile> findFilesWithExactPackage(
|
|
||||||
@NotNull FqName packageFqName,
|
|
||||||
@NotNull GlobalSearchScope searchScope,
|
|
||||||
@NotNull Project project
|
|
||||||
) {
|
|
||||||
return JetExactPackagesIndex.getInstance().get(packageFqName.asString(), project, searchScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean packageExists(
|
|
||||||
@NotNull FqName packageFqName,
|
|
||||||
@NotNull GlobalSearchScope searchScope,
|
|
||||||
@NotNull Project project
|
|
||||||
) {
|
|
||||||
return containsAny(packageFqName, searchScope, project, JetExactPackagesIndex.getInstance().getKey())
|
|
||||||
|| SubpackagesIndexService.OBJECT$.getInstance(project).hasSubpackages(packageFqName, searchScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean containsAny(
|
|
||||||
@NotNull FqName packageFqName,
|
|
||||||
@NotNull GlobalSearchScope searchScope,
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull StubIndexKey<String, JetFile> key
|
|
||||||
) {
|
|
||||||
final Ref<Boolean> result = new Ref<Boolean>(false);
|
|
||||||
StubIndex.getInstance().processElements(
|
|
||||||
key, packageFqName.asString(), project, searchScope, JetFile.class,
|
|
||||||
new Processor<JetFile>() {
|
|
||||||
@Override
|
|
||||||
public boolean process(JetFile file) {
|
|
||||||
result.set(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PackageIndexUtil() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Ref
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.psi.stubs.StubIndex
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey
|
||||||
|
import com.intellij.util.Processor
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import kotlin.platform.platformStatic
|
||||||
|
|
||||||
|
public object PackageIndexUtil {
|
||||||
|
platformStatic public fun getSubPackageFqNames(
|
||||||
|
packageFqName: FqName,
|
||||||
|
scope: GlobalSearchScope,
|
||||||
|
project: Project
|
||||||
|
): Collection<FqName> {
|
||||||
|
return SubpackagesIndexService.getInstance(project).getSubpackages(packageFqName, scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
platformStatic public fun findFilesWithExactPackage(
|
||||||
|
packageFqName: FqName,
|
||||||
|
searchScope: GlobalSearchScope,
|
||||||
|
project: Project
|
||||||
|
): Collection<JetFile> {
|
||||||
|
return JetExactPackagesIndex.getInstance().get(packageFqName.asString(), project, searchScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
platformStatic public fun packageExists(
|
||||||
|
packageFqName: FqName,
|
||||||
|
searchScope: GlobalSearchScope,
|
||||||
|
project: Project
|
||||||
|
): Boolean {
|
||||||
|
return containsAny(packageFqName, searchScope, project, JetExactPackagesIndex.getInstance().getKey()) ||
|
||||||
|
SubpackagesIndexService.getInstance(project).hasSubpackages(packageFqName, searchScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
platformStatic public fun containsAny(
|
||||||
|
packageFqName: FqName,
|
||||||
|
searchScope: GlobalSearchScope,
|
||||||
|
project: Project,
|
||||||
|
key: StubIndexKey<String, JetFile>
|
||||||
|
): Boolean {
|
||||||
|
var result = false
|
||||||
|
StubIndex.getInstance().processElements<String, JetFile>(key, packageFqName.asString(), project, searchScope, javaClass<JetFile>()) {
|
||||||
|
result = true
|
||||||
|
false
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user