use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class SwitchCodegenUtil method buildAppropriateSwitchCodegenIfPossible.
@Nullable
public static SwitchCodegen buildAppropriateSwitchCodegenIfPossible(@NotNull KtWhenExpression expression, boolean isStatement, boolean isExhaustive, @NotNull ExpressionCodegen codegen) {
BindingContext bindingContext = codegen.getBindingContext();
boolean shouldInlineConstVals = codegen.getState().getShouldInlineConstVals();
if (!isThereConstantEntriesButNulls(expression, bindingContext, shouldInlineConstVals)) {
return null;
}
Type subjectType = codegen.expressionType(expression.getSubjectExpression());
WhenByEnumsMapping mapping = codegen.getBindingContext().get(CodegenBinding.MAPPING_FOR_WHEN_BY_ENUM, expression);
if (mapping != null) {
return new EnumSwitchCodegen(expression, isStatement, isExhaustive, codegen, mapping);
}
if (isIntegralConstantsSwitch(expression, subjectType, bindingContext, shouldInlineConstVals)) {
return new IntegralConstantsSwitchCodegen(expression, isStatement, isExhaustive, codegen);
}
if (isStringConstantsSwitch(expression, subjectType, bindingContext, shouldInlineConstVals)) {
return new StringSwitchCodegen(expression, isStatement, isExhaustive, codegen);
}
return null;
}
use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class ScriptCodegen method createScriptCodegen.
public static ScriptCodegen createScriptCodegen(@NotNull KtScript declaration, @NotNull GenerationState state, @NotNull CodegenContext parentContext) {
BindingContext bindingContext = state.getBindingContext();
ScriptDescriptor scriptDescriptor = bindingContext.get(BindingContext.SCRIPT, declaration);
assert scriptDescriptor != null;
Type classType = state.getTypeMapper().mapType(scriptDescriptor);
ClassBuilder builder = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(declaration, scriptDescriptor), classType, declaration.getContainingFile());
List<ScriptDescriptor> earlierScripts = state.getReplSpecific().getEarlierScriptsForReplInterpreter();
ScriptContext scriptContext = parentContext.intoScript(scriptDescriptor, earlierScripts == null ? Collections.<ScriptDescriptor>emptyList() : earlierScripts, scriptDescriptor, state.getTypeMapper());
return new ScriptCodegen(declaration, state, scriptContext, builder);
}
use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class AbstractLoadJavaTest method doTestSourceJava.
protected void doTestSourceJava(@NotNull String javaFileName) throws Exception {
File originalJavaFile = new File(javaFileName);
File expectedFile = getTxtFile(javaFileName);
File testPackageDir = new File(tmpdir, "test");
assertTrue(testPackageDir.mkdir());
FileUtil.copy(originalJavaFile, new File(testPackageDir, originalJavaFile.getName()));
Pair<PackageViewDescriptor, BindingContext> javaPackageAndContext = loadTestPackageAndBindingContextFromJavaRoot(tmpdir, getTestRootDisposable(), getJdkKind(), ConfigurationKind.JDK_ONLY, false);
checkJavaPackage(expectedFile, javaPackageAndContext.first, javaPackageAndContext.second, COMPARATOR_CONFIGURATION.withValidationStrategy(errorTypesAllowed()));
}
use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class AbstractLoadJavaTest method doTestCompiledJavaAndKotlin.
// Java-Kotlin dependencies are not supported in this method for simplicity
protected void doTestCompiledJavaAndKotlin(@NotNull String expectedFileName) throws Exception {
File expectedFile = new File(expectedFileName);
File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", ""));
List<File> kotlinSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.kt"), sourcesDir);
KotlinCoreEnvironment environment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_ONLY);
compileKotlinToDirAndGetModule(kotlinSources, tmpdir, environment);
List<File> javaSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.java"), sourcesDir);
Pair<PackageViewDescriptor, BindingContext> binaryPackageAndContext = compileJavaAndLoadTestPackageAndBindingContextFromBinary(javaSources, tmpdir, ConfigurationKind.JDK_ONLY);
checkJavaPackage(expectedFile, binaryPackageAndContext.first, binaryPackageAndContext.second, COMPARATOR_CONFIGURATION);
}
use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class AbstractPseudocodeTest method doTest.
protected void doTest(String fileName) throws Exception {
File file = new File(fileName);
KtFile jetFile = KotlinTestUtils.loadJetFile(getProject(), file);
SetMultimap<KtElement, Pseudocode> data = LinkedHashMultimap.create();
AnalysisResult analysisResult = KotlinTestUtils.analyzeFile(jetFile, getEnvironment());
List<KtDeclaration> declarations = jetFile.getDeclarations();
BindingContext bindingContext = analysisResult.getBindingContext();
for (KtDeclaration declaration : declarations) {
addDeclaration(data, bindingContext, declaration);
if (declaration instanceof KtDeclarationContainer) {
for (KtDeclaration member : ((KtDeclarationContainer) declaration).getDeclarations()) {
// Properties and initializers are processed elsewhere
if (member instanceof KtNamedFunction || member instanceof KtSecondaryConstructor) {
addDeclaration(data, bindingContext, member);
}
}
}
}
try {
processCFData(file, data, bindingContext);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if ("true".equals(System.getProperty("kotlin.control.flow.test.dump.graphs"))) {
CFGraphToDotFilePrinter.dumpDot(file, data.values());
}
}
}
Aggregations