package org.jetbrains.kotlin.ui.launch;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.jetbrains.kotlin.core.builder.KotlinPsiManager;
import org.jetbrains.kotlin.core.model.KotlinAnalysisProjectCache;
import org.jetbrains.kotlin.idea.MainFunctionDetector;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.BindingContext;

public class KotlinLaunchableTester extends PropertyTester {
    @Override
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
        if (receiver instanceof IAdaptable) {
            IFile file = (IFile) ((IAdaptable) receiver).getAdapter(IFile.class);
            if (file != null) {
                JetFile jetFile = KotlinPsiManager.getKotlinParsedFile(file);
                if (jetFile == null) {
                    return false;
                }
                
                IJavaProject javaProject = JavaCore.create(file.getProject()); 
                BindingContext bindingContext = KotlinAnalysisProjectCache.INSTANCE$.getAnalysisResult(javaProject).getBindingContext();
                return new MainFunctionDetector(bindingContext).hasMain(jetFile.getDeclarations());
            }
        }
        
        return false;
    }
}

@@ -359,31 +359,28 @@
 tlinAnalysis
-Project
+File
 Cache;%0Aimpor
@@ -1183,23 +1183,20 @@
 Analysis
-Project
+File
 Cache.IN
@@ -1221,16 +1221,25 @@
 sResult(
+jetFile, 
 javaProj
@@ -1242,16 +1242,61 @@
 Project)
+%0A                        .getAnalysisResult()
 .getBind

Use file scope cache to detect main function in file