use of org.jetbrains.kotlin.resolve.BindingContext in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method testNoWarningsOnJavaKotlinInheritance.
public void testNoWarningsOnJavaKotlinInheritance() throws Exception {
// This test checks that there are no PARAMETER_NAME_CHANGED_ON_OVERRIDE or DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES
// warnings when subclassing in Kotlin from Java binaries (in case when no parameter names are available for Java classes)
KotlinTestUtils.compileJavaFiles(Collections.singletonList(getTestDataFileWithExtension("java")), Arrays.asList("-d", tmpdir.getPath()));
KotlinCoreEnvironment environment = createEnvironment(Collections.singletonList(tmpdir));
AnalysisResult result = JvmResolveUtil.analyze(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
result.throwIfError();
BindingContext bindingContext = result.getBindingContext();
AnalyzerWithCompilerReport.Companion.reportDiagnostics(bindingContext.getDiagnostics(), new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false));
assertEquals("There should be no diagnostics", 0, Iterables.size(bindingContext.getDiagnostics()));
}
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 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