Search in sources :

Example 1 with ClassResolveResult

use of com.intellij.psi.PsiClassType.ClassResolveResult in project intellij-community by JetBrains.

the class TraitTransformationSupport method process.

private static void process(@NotNull TransformationContext context, @NotNull PairConsumer<PsiClass, PsiSubstitutor> consumer) {
    Deque<Pair<PsiClass, PsiSubstitutor>> stack = new ArrayDeque<>();
    for (PsiClassType superType : context.getSuperTypes()) {
        ClassResolveResult result = superType.resolveGenerics();
        PsiClass superClass = result.getElement();
        if (superClass == null)
            continue;
        stack.push(Pair.create(superClass, result.getSubstitutor()));
    }
    Set<PsiClass> visited = ContainerUtil.newHashSet();
    while (!stack.isEmpty()) {
        Pair<PsiClass, PsiSubstitutor> current = stack.pop();
        PsiClass currentClass = current.first;
        PsiSubstitutor currentSubstitutor = current.second;
        if (!visited.add(currentClass))
            continue;
        if (GrTraitUtil.isTrait(currentClass)) {
            consumer.consume(currentClass, currentSubstitutor);
        }
        for (PsiClass superClass : currentClass.getSupers()) {
            PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, currentClass, currentSubstitutor);
            stack.push(Pair.create(superClass, superSubstitutor));
        }
    }
}
Also used : ClassResolveResult(com.intellij.psi.PsiClassType.ClassResolveResult) ArrayDeque(java.util.ArrayDeque) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 ClassResolveResult (com.intellij.psi.PsiClassType.ClassResolveResult)1 ArrayDeque (java.util.ArrayDeque)1