Search in sources :

Example 6 with KtNamedFunction

use of org.jetbrains.kotlin.psi.KtNamedFunction 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)

Example 7 with KtNamedFunction

use of org.jetbrains.kotlin.psi.KtNamedFunction in project kotlin by JetBrains.

the class KotlinOverridingTest method makeFunction.

private FunctionDescriptor makeFunction(String funDecl) {
    KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
    LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
    return functionDescriptorResolver.resolveFunctionDescriptor(module, scope, function, KotlinTestUtils.DUMMY_TRACE, DataFlowInfoFactory.EMPTY);
}
Also used : LexicalScope(org.jetbrains.kotlin.resolve.scopes.LexicalScope) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction)

Aggregations

KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)7 Nullable (org.jetbrains.annotations.Nullable)2 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)2 MainFunctionDetector (org.jetbrains.kotlin.idea.MainFunctionDetector)2 KtProperty (org.jetbrains.kotlin.psi.KtProperty)2 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)2 LexicalScope (org.jetbrains.kotlin.resolve.scopes.LexicalScope)2 PsiMethod (com.intellij.psi.PsiMethod)1 Map (java.util.Map)1 CallableMemberDescriptor (org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 BindingUtils.getFunctionDescriptor (org.jetbrains.kotlin.js.translate.utils.BindingUtils.getFunctionDescriptor)1 InlineAnalyzerExtension (org.jetbrains.kotlin.resolve.inline.InlineAnalyzerExtension)1