Search in sources :

Example 1 with ResolveSession

use of org.jetbrains.kotlin.resolve.lazy.ResolveSession in project kotlin by JetBrains.

the class AbstractOutOfBlockModificationTest method checkOOBWithDescriptorsResolve.

private void checkOOBWithDescriptorsResolve(boolean expectedOutOfBlock) {
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            ((PsiModificationTrackerImpl) PsiManager.getInstance(myFixture.getProject()).getModificationTracker()).incOutOfCodeBlockModificationCounter();
        }
    });
    PsiElement updateElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset() - 1);
    KtExpression ktExpression = PsiTreeUtil.getParentOfType(updateElement, KtExpression.class, false);
    KtDeclaration ktDeclaration = PsiTreeUtil.getParentOfType(updateElement, KtDeclaration.class, false);
    KtElement ktElement = ktExpression != null ? ktExpression : ktDeclaration;
    if (ktElement == null)
        return;
    ResolutionFacade facade = ResolutionUtils.getResolutionFacade(ktElement.getContainingKtFile());
    ResolveSession session = facade.getFrontendService(ResolveSession.class);
    session.forceResolveAll();
    BindingContext context = session.getBindingContext();
    if (ktExpression != null && ktExpression != ktDeclaration) {
        @SuppressWarnings("ConstantConditions") boolean expressionProcessed = context.get(BindingContext.PROCESSED, ktExpression instanceof KtFunctionLiteral ? (KtLambdaExpression) ktExpression.getParent() : ktExpression) == Boolean.TRUE;
        assertEquals("Expected out-of-block should result expression analyzed and vise versa", expectedOutOfBlock, expressionProcessed);
    } else {
        boolean declarationProcessed = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, ktDeclaration) != null;
        assertEquals("Expected out-of-block should result declaration analyzed and vise versa", expectedOutOfBlock, declarationProcessed);
    }
}
Also used : ResolutionFacade(org.jetbrains.kotlin.idea.resolve.ResolutionFacade) ResolveSession(org.jetbrains.kotlin.resolve.lazy.ResolveSession) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ResolveSession

use of org.jetbrains.kotlin.resolve.lazy.ResolveSession in project kotlin by JetBrains.

the class SourceNavigationHelper method createAnalyzer.

@NotNull
private static KotlinCodeAnalyzer createAnalyzer(@NotNull Collection<KtNamedDeclaration> candidates, @NotNull Project project) {
    MutableModuleContext context = ContextKt.ContextForNewModule(ContextKt.ProjectContext(project), Name.special("<library module>"), DefaultBuiltIns.getInstance(), null);
    context.setDependencies(context.getModule(), context.getModule().getBuiltIns().getBuiltInsModule());
    ResolveSession resolveSession = InjectionKt.createLazyResolveSession(context, getContainingFiles(candidates));
    context.initializeModuleContents(resolveSession.getPackageFragmentProvider());
    return resolveSession;
}
Also used : ResolveSession(org.jetbrains.kotlin.resolve.lazy.ResolveSession) MutableModuleContext(org.jetbrains.kotlin.context.MutableModuleContext) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResolveSession (org.jetbrains.kotlin.resolve.lazy.ResolveSession)2 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1 MutableModuleContext (org.jetbrains.kotlin.context.MutableModuleContext)1 ResolutionFacade (org.jetbrains.kotlin.idea.resolve.ResolutionFacade)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1