use of com.intellij.util.containers.JBTreeTraverser in project intellij-community by JetBrains.
the class PsiViewerDialog method initMap.
private void initMap(BlockTreeNode rootBlockNode, PsiElement psiEl) {
JBTreeTraverser<BlockTreeNode> traverser = new JBTreeTraverser<>(o -> JBIterable.of(o.getChildren()));
for (BlockTreeNode block : traverser.withRoot(rootBlockNode)) {
PsiElement currentElem = null;
if (block.getBlock() instanceof ASTBlock) {
ASTNode node = ((ASTBlock) block.getBlock()).getNode();
if (node != null) {
currentElem = node.getPsi();
}
}
if (currentElem == null) {
currentElem = InjectedLanguageUtil.findElementAtNoCommit(psiEl.getContainingFile(), block.getBlock().getTextRange().getStartOffset());
}
myPsiToBlockMap.put(currentElem, block);
//nested PSI elements with same ranges will be mapped to one blockNode
// assert currentElem != null; //for Scala-language plugin etc it can be null, because formatterBlocks is not instance of ASTBlock
TextRange curTextRange = currentElem.getTextRange();
PsiElement parentElem = currentElem.getParent();
while (parentElem != null && parentElem.getTextRange().equals(curTextRange)) {
myPsiToBlockMap.put(parentElem, block);
parentElem = parentElem.getParent();
}
}
}
use of com.intellij.util.containers.JBTreeTraverser in project intellij-community by JetBrains.
the class CodeInsightUtil method processSubTypes.
public static void processSubTypes(PsiType psiType, final PsiElement context, boolean getRawSubtypes, @NotNull final PrefixMatcher matcher, Consumer<PsiType> consumer) {
int arrayDim = psiType.getArrayDimensions();
psiType = psiType.getDeepComponentType();
if (!(psiType instanceof PsiClassType))
return;
PsiClassType baseType = JavaCompletionUtil.originalize((PsiClassType) psiType);
PsiClassType.ClassResolveResult baseResult = baseType.resolveGenerics();
PsiClass baseClass = baseResult.getElement();
PsiSubstitutor baseSubstitutor = baseResult.getSubstitutor();
if (baseClass == null)
return;
GlobalSearchScope scope = context.getResolveScope();
Processor<PsiClass> inheritorsProcessor = createInheritorsProcessor(context, baseType, arrayDim, getRawSubtypes, consumer, baseClass, baseSubstitutor);
addContextTypeArguments(context, baseType, inheritorsProcessor);
if (baseClass.hasModifierProperty(PsiModifier.FINAL))
return;
if (matcher.getPrefix().length() > 2) {
JBTreeTraverser<PsiClass> traverser = new JBTreeTraverser<>(c -> Arrays.asList(c.getInnerClasses()));
AllClassesGetter.processJavaClasses(matcher, context.getProject(), scope, psiClass -> {
Iterable<PsiClass> inheritors = traverser.withRoot(psiClass).filter(c -> c.isInheritor(baseClass, true));
return ContainerUtil.process(inheritors, inheritorsProcessor);
});
} else {
Query<PsiClass> baseQuery = ClassInheritorsSearch.search(baseClass, scope, true, true, false);
Query<PsiClass> query = new FilteredQuery<>(baseQuery, psiClass -> !(psiClass instanceof PsiTypeParameter) && ContainerUtil.exists(JavaCompletionUtil.getAllLookupStrings(psiClass), matcher::prefixMatches));
query.forEach(inheritorsProcessor);
}
}
Aggregations