Search in sources :

Example 16 with DeclarationDescriptor

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

the class KtInvokeFunctionReference method getTargetDescriptors.

@Override
@NotNull
protected Collection<DeclarationDescriptor> getTargetDescriptors(@NotNull BindingContext context) {
    Call call = CallUtilKt.getCall(getElement(), context);
    ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(call, context);
    if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
        return Collections.<DeclarationDescriptor>singleton(((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor());
    }
    if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) {
        return Collections.<DeclarationDescriptor>singleton(resolvedCall.getCandidateDescriptor());
    }
    return Collections.emptyList();
}
Also used : VariableAsFunctionResolvedCall(org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall) ResolvedCall(org.jetbrains.kotlin.resolve.calls.model.ResolvedCall) VariableAsFunctionResolvedCall(org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with DeclarationDescriptor

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

the class JetTestFunctionDetector method getTestFunctions.

@NotNull
private static List<FunctionDescriptor> getTestFunctions(@NotNull BindingContext bindingContext, @NotNull List<KtDeclaration> declarations) {
    List<FunctionDescriptor> answer = Lists.newArrayList();
    for (KtDeclaration declaration : declarations) {
        MemberScope scope = null;
        if (declaration instanceof KtClass) {
            KtClass klass = (KtClass) declaration;
            ClassDescriptor classDescriptor = BindingUtils.getClassDescriptor(bindingContext, klass);
            if (classDescriptor.getModality() != Modality.ABSTRACT) {
                scope = classDescriptor.getDefaultType().getMemberScope();
            }
        }
        if (scope != null) {
            Collection<DeclarationDescriptor> allDescriptors = DescriptorUtils.getAllDescriptors(scope);
            List<FunctionDescriptor> testFunctions = ContainerUtil.mapNotNull(allDescriptors, new Function<DeclarationDescriptor, FunctionDescriptor>() {

                @Override
                public FunctionDescriptor fun(DeclarationDescriptor descriptor) {
                    if (descriptor instanceof FunctionDescriptor) {
                        FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
                        if (isTest(functionDescriptor))
                            return functionDescriptor;
                    }
                    return null;
                }
            });
            answer.addAll(testFunctions);
        }
    }
    return answer;
}
Also used : KtDeclaration(org.jetbrains.kotlin.psi.KtDeclaration) ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) KtClass(org.jetbrains.kotlin.psi.KtClass) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor 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)

Aggregations

DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)18 NotNull (org.jetbrains.annotations.NotNull)5 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)3 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 CallableDescriptor (org.jetbrains.kotlin.descriptors.CallableDescriptor)2 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)2 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)2 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 ResolvedCall (org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)2 VariableAsFunctionResolvedCall (org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 Trinity (com.intellij.openapi.util.Trinity)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 IElementType (com.intellij.psi.tree.IElementType)1 File (java.io.File)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 JarFile (java.util.jar.JarFile)1