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;
}
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);
}
}
Aggregations