Search in sources :

Example 1 with MainFunctionDetector

use of org.jetbrains.kotlin.idea.MainFunctionDetector in project kotlin by JetBrains.

the class JetRunConfiguration method findMainFun.

@Nullable
private static KtNamedFunction findMainFun(@NotNull PsiClass psiClass) {
    for (KtNamedFunction function : getMainFunCandidates(psiClass)) {
        BindingContext bindingContext = ResolutionUtils.analyze(function, BodyResolveMode.FULL);
        MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(bindingContext);
        if (mainFunctionDetector.isMain(function))
            return function;
    }
    return null;
}
Also used : MainFunctionDetector(org.jetbrains.kotlin.idea.MainFunctionDetector) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MainFunctionDetector

use of org.jetbrains.kotlin.idea.MainFunctionDetector in project kotlin by JetBrains.

the class Translation method generateCallToMain.

//TODO: determine whether should throw exception
@Nullable
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull Collection<KtFile> files, @NotNull List<String> arguments) {
    MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(context.bindingContext());
    KtNamedFunction mainFunction = mainFunctionDetector.getMainFunction(files);
    if (mainFunction == null) {
        return null;
    }
    FunctionDescriptor functionDescriptor = getFunctionDescriptor(context.bindingContext(), mainFunction);
    JsArrayLiteral argument = new JsArrayLiteral(toStringLiteralList(arguments, context.program()));
    return CallTranslator.INSTANCE.buildCall(context, functionDescriptor, Collections.singletonList(argument), null).makeStmt();
}
Also used : MainFunctionDetector(org.jetbrains.kotlin.idea.MainFunctionDetector) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) BindingUtils.getFunctionDescriptor(org.jetbrains.kotlin.js.translate.utils.BindingUtils.getFunctionDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)2 MainFunctionDetector (org.jetbrains.kotlin.idea.MainFunctionDetector)2 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 BindingUtils.getFunctionDescriptor (org.jetbrains.kotlin.js.translate.utils.BindingUtils.getFunctionDescriptor)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1