use of com.intellij.util.indexing.AdditionalIndexedRootsScope in project intellij-community by JetBrains.
the class IndexedRelevantResource method getResources.
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getResources(ID<K, V> indexId, final K key, @Nullable final Module module, @NotNull Project project, @Nullable final GlobalSearchScope additionalScope) {
if (project.isDefault())
return Collections.emptyList();
final ArrayList<IndexedRelevantResource<K, V>> resources = new ArrayList<>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor<V>() {
@Override
public boolean process(VirtualFile file, V value) {
ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope);
resources.add(new IndexedRelevantResource<>(file, key, value, relevance));
return true;
}
}, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project)));
return resources;
}
use of com.intellij.util.indexing.AdditionalIndexedRootsScope in project intellij-plugins by JetBrains.
the class ActionScriptClassResolver method doFindClassByQName.
protected PsiElement doFindClassByQName(@NotNull String link, final JavaScriptIndex index, GlobalSearchScope searchScope, boolean allowFileLocalSymbols, @NotNull DialectOptionHolder dialect) {
Project project = index.getProject();
boolean clazzShouldBeTakenFromOurLibrary = OBJECT_CLASS_NAME.equals(link) || "Arguments".equals(link);
if (clazzShouldBeTakenFromOurLibrary && !(searchScope instanceof AdditionalIndexedRootsScope)) {
// object from swf do not contain necessary members!
searchScope = new AdditionalIndexedRootsScope(searchScope, JSIndexedRootProvider.class);
}
final Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, link.hashCode(), project, searchScope, JSQualifiedNamedElement.class);
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
JSQualifiedNamedElement resultFromSourceContent = null;
JSQualifiedNamedElement resultFromLibraries = null;
long resultFromLibrariesTimestamp = 0;
for (JSQualifiedNamedElement classCandidate : candidates) {
if (!(classCandidate instanceof JSQualifiedNamedElement))
continue;
if (JSResolveUtil.isConstructorFunction(classCandidate))
continue;
JSQualifiedNamedElement clazz = classCandidate;
if (link.equals(clazz.getQualifiedName())) {
PsiFile file = clazz.getContainingFile();
if (!file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4))
continue;
VirtualFile vFile = file.getVirtualFile();
if (clazzShouldBeTakenFromOurLibrary && // object from swf do not contain necessary members!
!JavaScriptIndex.ECMASCRIPT_JS2.equals(vFile.getName())) {
continue;
}
if (!allowFileLocalSymbols && JSResolveUtil.isFileLocalSymbol(clazz)) {
continue;
}
if (projectFileIndex.isInSourceContent(vFile)) {
// the absolute preference is for classes from sources
resultFromSourceContent = clazz;
continue;
}
// choose the right class in the same way as compiler does: with the latest timestamp in catalog.xml file
if (resultFromLibraries == null) {
resultFromLibraries = clazz;
// do not initialize resultFromLibrariesTimestamp here, it is expensive and may be not required if only 1 candidate
} else if (JSCommonTypeNames.VECTOR_CLASS_NAME.equals(link)) {
if (clazz instanceof JSClass && resultFromLibraries instanceof JSClass && ((JSClass) clazz).getFunctions().length > ((JSClass) resultFromLibraries).getFunctions().length) {
resultFromLibraries = clazz;
}
} else {
if (resultFromLibrariesTimestamp == 0) {
// was not initialized yet
resultFromLibrariesTimestamp = getResolveResultTimestamp(resultFromLibraries);
}
final long classTimestamp = getResolveResultTimestamp(clazz);
if (classTimestamp > resultFromLibrariesTimestamp) {
resultFromLibraries = clazz;
resultFromLibrariesTimestamp = classTimestamp;
}
}
}
}
PsiElement result = resultFromSourceContent != null ? resultFromSourceContent : resultFromLibraries;
if (result == null) {
String className = link.substring(link.lastIndexOf('.') + 1);
if (className.length() > 0 && !isBuiltInClassName(className) && (Character.isLetter(className.charAt(0)) || '_' == className.charAt(0))) {
// TODO optimization, remove when packages will be properly handled
result = findClassByQNameViaHelper(link, project, className, searchScope);
}
}
return result;
}
Aggregations