package org.jetbrains.kotlin.ui.launch;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.MainFunctionDetector;
import org.jetbrains.kotlin.core.builder.KotlinPsiManager;
import org.jetbrains.kotlin.core.resolve.KotlinAnalyzer;

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

@@ -123,24 +123,68 @@
 rces.IFile;%0A
+import org.eclipse.core.runtime.IAdaptable;%0A
 import org.e
@@ -213,16 +213,16 @@
 roject;%0A
-
 import o
@@ -724,18 +724,23 @@
 anceof I
-Fi
+Adaptab
 le) %7B%0A  
@@ -755,24 +755,17 @@
   IFile 
-eclipseF
+f
 ile = (I
@@ -774,18 +774,93 @@
 le) 
-receiver;%0A
+((IAdaptable) receiver).getAdapter(IFile.class);%0A            if (file != null) %7B%0A    
     
@@ -926,22 +926,19 @@
 ile(
-eclipseF
+f
 ile);%0A
+    
     
@@ -976,32 +976,36 @@
                 
+    
 return false;%0A  
@@ -1006,32 +1006,36 @@
 se;%0A            
+    
 %7D%0A            %0A 
@@ -1024,33 +1024,41 @@
   %7D%0A            
+ 
-%0A
+   %0A    
             IJav
@@ -1100,16 +1100,9 @@
 ate(
-eclipseF
+f
 ile.
@@ -1129,16 +1129,20 @@
         
+   
+ 
 BindingC
@@ -1242,24 +1242,28 @@
             
+    
 return new M
@@ -1334,16 +1334,30 @@
 ons());%0A
+            %7D%0A
         

Return ability to launch kotlin from editor