Search in sources :

Example 1 with ResolutionFacade

use of org.jetbrains.kotlin.idea.resolve.ResolutionFacade in project kotlin by JetBrains.

the class KotlinBytecodeToolWindow method compileSingleFile.

@NotNull
public static GenerationState compileSingleFile(@NotNull final KtFile ktFile, @NotNull CompilerConfiguration configuration) {
    ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
    BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
    kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE), bindingContextForFile);
    BindingContext bindingContext = result.getFirst();
    List<KtFile> toProcess = result.getSecond();
    GenerationState.GenerateClassFilter generateClassFilter = new GenerationState.GenerateClassFilter() {

        @Override
        public boolean shouldGeneratePackagePart(@NotNull KtFile file) {
            return file == ktFile;
        }

        @Override
        public boolean shouldAnnotateClass(@NotNull KtClassOrObject processingClassOrObject) {
            return true;
        }

        @Override
        public boolean shouldGenerateClass(@NotNull KtClassOrObject processingClassOrObject) {
            return processingClassOrObject.getContainingKtFile() == ktFile;
        }

        @Override
        public boolean shouldGenerateScript(@NotNull KtScript script) {
            return script.getContainingKtFile() == ktFile;
        }
    };
    GenerationState state = new GenerationState(ktFile.getProject(), ClassBuilderFactories.TEST, resolutionFacade.getModuleDescriptor(), bindingContext, toProcess, configuration, generateClassFilter);
    KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
    return state;
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) KtScript(org.jetbrains.kotlin.psi.KtScript) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) NotNull(org.jetbrains.annotations.NotNull) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ResolutionFacade(org.jetbrains.kotlin.idea.resolve.ResolutionFacade) List(java.util.List) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResolutionFacade

use of org.jetbrains.kotlin.idea.resolve.ResolutionFacade 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)

Aggregations

ResolutionFacade (org.jetbrains.kotlin.idea.resolve.ResolutionFacade)2 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)2 PsiElement (com.intellij.psi.PsiElement)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 KtClassOrObject (org.jetbrains.kotlin.psi.KtClassOrObject)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 KtScript (org.jetbrains.kotlin.psi.KtScript)1 ResolveSession (org.jetbrains.kotlin.resolve.lazy.ResolveSession)1