use of org.jetbrains.jps.backwardRefs.LightRef in project intellij-community by JetBrains.
the class CompilerReferenceReader method getDirectInheritors.
/**
* @return two maps of classes grouped per file
*
* 1st map: inheritors. Can be used without explicit inheritance verification
* 2nd map: candidates. One need to check that these classes are really direct inheritors
*/
@NotNull
Map<VirtualFile, Object[]> getDirectInheritors(@NotNull LightRef searchElement, @NotNull GlobalSearchScope searchScope, @NotNull GlobalSearchScope dirtyScope, @NotNull FileType fileType, @NotNull CompilerHierarchySearchType searchType) throws StorageException {
GlobalSearchScope effectiveSearchScope = GlobalSearchScope.notScope(dirtyScope).intersectWith(searchScope);
LanguageLightRefAdapter adapter = CompilerReferenceServiceImpl.findAdapterForFileType(fileType);
LOG.assertTrue(adapter != null, "adapter is null for file type: " + fileType);
Class<? extends LightRef> requiredLightRefClass = searchType.getRequiredClass(adapter);
Map<VirtualFile, Object[]> candidatesPerFile = new HashMap<>();
myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(searchElement).forEach((fileId, defs) -> {
final List<LightRef> requiredCandidates = defs.stream().filter(requiredLightRefClass::isInstance).collect(toList());
if (requiredCandidates.isEmpty())
return true;
final VirtualFile file = findFile(fileId);
if (file != null && effectiveSearchScope.contains(file)) {
candidatesPerFile.put(file, searchType.convertToIds(requiredCandidates, myIndex.getByteSeqEum()));
}
return true;
});
return candidatesPerFile.isEmpty() ? Collections.emptyMap() : candidatesPerFile;
}
use of org.jetbrains.jps.backwardRefs.LightRef in project intellij-community by JetBrains.
the class CompilerReferenceReader method findReferentFileIds.
@Nullable
TIntHashSet findReferentFileIds(@NotNull LightRef ref, boolean checkBaseClassAmbiguity) throws StorageException {
LightRef.LightClassHierarchyElementDef hierarchyElement = ref instanceof LightRef.LightClassHierarchyElementDef ? (LightRef.LightClassHierarchyElementDef) ref : ((LightRef.LightMember) ref).getOwner();
TIntHashSet set = new TIntHashSet();
final LightRef.NamedLightRef[] hierarchy = getWholeHierarchy(hierarchyElement, checkBaseClassAmbiguity);
if (hierarchy == null)
return null;
for (LightRef.NamedLightRef aClass : hierarchy) {
final LightRef overriderUsage = ref.override(aClass.getName());
addUsages(overriderUsage, set);
}
return set;
}
use of org.jetbrains.jps.backwardRefs.LightRef in project intellij-community by JetBrains.
the class CompilerReferenceReader method getWholeHierarchy.
@Nullable("return null if the class hierarchy contains ambiguous qualified names")
private LightRef.NamedLightRef[] getWholeHierarchy(LightRef.LightClassHierarchyElementDef hierarchyElement, boolean checkBaseClassAmbiguity) throws StorageException {
Set<LightRef.NamedLightRef> result = new THashSet<>();
Queue<LightRef.NamedLightRef> q = new Queue<>(10);
q.addLast(hierarchyElement);
while (!q.isEmpty()) {
LightRef.NamedLightRef curClass = q.pullFirst();
if (result.add(curClass)) {
if (checkBaseClassAmbiguity || curClass != hierarchyElement) {
DefCount count = getDefinitionCount(curClass);
if (count == DefCount.NONE) {
//diagnostic
String baseHierarchyElement = getNameEnumerator().getName(hierarchyElement.getName());
String curHierarchyElement = getNameEnumerator().getName(curClass.getName());
LOG.error("Can't get definition files for: " + curHierarchyElement + " base class: " + baseHierarchyElement);
}
if (count != DefCount.ONE) {
return null;
}
}
myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(curClass).forEach((id, children) -> {
for (LightRef child : children) {
if (child instanceof LightRef.LightClassHierarchyElementDef) {
q.addLast((LightRef.LightClassHierarchyElementDef) child);
}
}
return true;
});
}
}
return result.toArray(new LightRef.NamedLightRef[result.size()]);
}
use of org.jetbrains.jps.backwardRefs.LightRef in project intellij-community by JetBrains.
the class CompilerReferenceServiceImpl method getReferentFileIds.
@Nullable
private TIntHashSet getReferentFileIds(@NotNull PsiElement element) {
final CompilerElementInfo compilerElementInfo = asCompilerElements(element, true);
if (compilerElementInfo == null)
return null;
myReadDataLock.lock();
try {
if (myReader == null)
return null;
TIntHashSet referentFileIds = new TIntHashSet();
for (LightRef ref : compilerElementInfo.searchElements) {
try {
final TIntHashSet referents = myReader.findReferentFileIds(ref, compilerElementInfo.place == ElementPlace.SRC);
if (referents == null)
return null;
referentFileIds.addAll(referents.toArray());
} catch (StorageException e) {
throw new RuntimeException(e);
}
}
return referentFileIds;
} finally {
myReadDataLock.unlock();
}
}
use of org.jetbrains.jps.backwardRefs.LightRef in project intellij-community by JetBrains.
the class CompilerReferenceServiceImpl method asCompilerElements.
@Nullable
private CompilerElementInfo asCompilerElements(@NotNull PsiElement psiElement, boolean buildHierarchyForLibraryElements) {
myReadDataLock.lock();
try {
if (myReader == null)
return null;
VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);
if (file == null)
return null;
ElementPlace place = ElementPlace.get(file, myProjectFileIndex);
if (place == null || (place == ElementPlace.SRC && myDirtyScopeHolder.contains(file))) {
return null;
}
final LanguageLightRefAdapter adapter = findAdapterForFileType(file.getFileType());
if (adapter == null)
return null;
final LightRef ref = adapter.asLightUsage(psiElement, myReader.getNameEnumerator());
if (ref == null)
return null;
if (place == ElementPlace.LIB && buildHierarchyForLibraryElements) {
final List<LightRef> elements = adapter.getHierarchyRestrictedToLibraryScope(ref, psiElement, myReader.getNameEnumerator(), LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope());
final LightRef[] fullHierarchy = new LightRef[elements.size() + 1];
fullHierarchy[0] = ref;
int i = 1;
for (LightRef element : elements) {
fullHierarchy[i++] = element;
}
return new CompilerElementInfo(place, fullHierarchy);
} else {
return new CompilerElementInfo(place, ref);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
myReadDataLock.unlock();
}
}
Aggregations