Search in sources :

Example 11 with FunctionDescriptor

use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.

the class JSTestGenerator method doGenerateTestCalls.

private static void doGenerateTestCalls(@NotNull List<FunctionDescriptor> functionDescriptors, @NotNull TranslationContext context, @NotNull JSTester jsTester) {
    for (FunctionDescriptor functionDescriptor : functionDescriptors) {
        ClassDescriptor classDescriptor = DescriptorUtils.getContainingClass(functionDescriptor);
        if (classDescriptor == null) {
            return;
        }
        generateCodeForTestMethod(context, functionDescriptor, classDescriptor, jsTester);
    }
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor)

Example 12 with FunctionDescriptor

use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.

the class FunctionBodyTranslator method translateFunctionBody.

@NotNull
public static JsBlock translateFunctionBody(@NotNull FunctionDescriptor descriptor, @NotNull KtDeclarationWithBody declarationWithBody, @NotNull TranslationContext functionBodyContext) {
    Map<DeclarationDescriptor, JsExpression> aliases = new HashMap<DeclarationDescriptor, JsExpression>();
    LocalFunctionCollector functionCollector = new LocalFunctionCollector(functionBodyContext.bindingContext());
    declarationWithBody.acceptChildren(functionCollector, null);
    for (FunctionDescriptor localFunction : functionCollector.getFunctions()) {
        String localIdent = localFunction.getName().isSpecial() ? "lambda" : localFunction.getName().asString();
        JsName localName = functionBodyContext.scope().getParent().declareTemporaryName(NameSuggestion.sanitizeName(localIdent));
        MetadataProperties.setDescriptor(localName, localFunction);
        JsExpression alias = JsAstUtils.pureFqn(localName, null);
        aliases.put(localFunction, alias);
    }
    if (!aliases.isEmpty()) {
        functionBodyContext = functionBodyContext.innerContextWithDescriptorsAliased(aliases);
    }
    return (new FunctionBodyTranslator(descriptor, declarationWithBody, functionBodyContext)).translate();
}
Also used : LocalFunctionCollector(org.jetbrains.kotlin.js.translate.expression.LocalFunctionCollector) HashMap(java.util.HashMap) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with FunctionDescriptor

use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.

the class BoundsSubstitutorTest method doTest.

//public void testWithWhereTwoBoundsLoop() throws Exception {
//    doTest("fun <T, R> f(l: List<R>): R where T : R, R : T",
//           "");
//}
private void doTest(String text, String expected) {
    KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
    ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor();
    Collection<SimpleFunctionDescriptor> functions = module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
    FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(CollectionsKt.single(functions));
    String actual = DescriptorRenderer.COMPACT.render(substituted);
    assertEquals(expected, actual);
}
Also used : ModuleDescriptor(org.jetbrains.kotlin.descriptors.ModuleDescriptor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)

Example 14 with FunctionDescriptor

use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.

the class KotlinOverridingTest method assertOverridabilityRelation.

private void assertOverridabilityRelation(String superFun, String subFun, boolean expectedIsError) {
    FunctionDescriptor a = makeFunction(superFun);
    FunctionDescriptor b = makeFunction(subFun);
    OverridingUtil.OverrideCompatibilityInfo overridableWith = OverridingUtil.DEFAULT.isOverridableBy(a, b, null);
    assertEquals(overridableWith.getDebugMessage(), expectedIsError, overridableWith.getResult() != OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE);
}
Also used : FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) OverridingUtil(org.jetbrains.kotlin.resolve.OverridingUtil)

Aggregations

FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)14 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)2 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)2 KtExpression (org.jetbrains.kotlin.psi.KtExpression)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CallableDescriptor (org.jetbrains.kotlin.descriptors.CallableDescriptor)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 SimpleFunctionDescriptor (org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)1 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)1 MainFunctionDetector (org.jetbrains.kotlin.idea.MainFunctionDetector)1 JsExpression (org.jetbrains.kotlin.js.backend.ast.JsExpression)1 JsName (org.jetbrains.kotlin.js.backend.ast.JsName)1 JsNameRef (org.jetbrains.kotlin.js.backend.ast.JsNameRef)1 JsVars (org.jetbrains.kotlin.js.backend.ast.JsVars)1 TranslationContext (org.jetbrains.kotlin.js.translate.context.TranslationContext)1 LocalFunctionCollector (org.jetbrains.kotlin.js.translate.expression.LocalFunctionCollector)1