Search in sources :

Example 6 with BindingContext

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()));
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Example 7 with BindingContext

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);
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ScriptContext(org.jetbrains.kotlin.codegen.context.ScriptContext) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) ScriptDescriptor(org.jetbrains.kotlin.descriptors.ScriptDescriptor)

Example 8 with BindingContext

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()));
}
Also used : BindingContext(org.jetbrains.kotlin.resolve.BindingContext) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 9 with BindingContext

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);
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 10 with BindingContext

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

BindingContext (org.jetbrains.kotlin.resolve.BindingContext)20 KtFile (org.jetbrains.kotlin.psi.KtFile)6 File (java.io.File)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)3 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)3 IOException (java.io.IOException)2 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)2 ResolutionFacade (org.jetbrains.kotlin.idea.resolve.ResolutionFacade)2 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 Type (org.jetbrains.org.objectweb.asm.Type)2 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)1 Editor (com.intellij.openapi.editor.Editor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 SearchScope (com.intellij.psi.search.SearchScope)1 HashMap (com.intellij.util.containers.HashMap)1