Search in sources :

Example 1 with KtNamedFunction

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

the class AnalyzerExtensions method process.

public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
    for (Map.Entry<KtNamedFunction, SimpleFunctionDescriptor> entry : bodiesResolveContext.getFunctions().entrySet()) {
        KtNamedFunction function = entry.getKey();
        SimpleFunctionDescriptor functionDescriptor = entry.getValue();
        for (AnalyzerExtension extension : getFunctionExtensions(functionDescriptor)) {
            extension.process(functionDescriptor, function, trace);
        }
    }
    for (Map.Entry<KtProperty, PropertyDescriptor> entry : bodiesResolveContext.getProperties().entrySet()) {
        KtProperty function = entry.getKey();
        PropertyDescriptor propertyDescriptor = entry.getValue();
        for (AnalyzerExtension extension : getPropertyExtensions(propertyDescriptor)) {
            extension.process(propertyDescriptor, function, trace);
        }
    }
}
Also used : KtProperty(org.jetbrains.kotlin.psi.KtProperty) InlineAnalyzerExtension(org.jetbrains.kotlin.resolve.inline.InlineAnalyzerExtension) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) Map(java.util.Map)

Example 2 with KtNamedFunction

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

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

the class KotlinOverridingDialog method formatElement.

private static String formatElement(PsiElement element) {
    element = KtPsiUtil.ascendIfPropertyAccessor(element);
    if (element instanceof KtNamedFunction || element instanceof KtProperty) {
        BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
        DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
        if (declarationDescriptor instanceof CallableMemberDescriptor) {
            DeclarationDescriptor containingDescriptor = declarationDescriptor.getContainingDeclaration();
            if (containingDescriptor instanceof ClassDescriptor) {
                return KotlinBundle.message("x.in.y", DescriptorRenderer.COMPACT.render(declarationDescriptor), IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor));
            }
        }
    }
    assert element instanceof PsiMethod : "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found";
    return RenderingUtilsKt.formatPsiMethod((PsiMethod) element, true, false);
}
Also used : KtProperty(org.jetbrains.kotlin.psi.KtProperty) ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) PsiMethod(com.intellij.psi.PsiMethod) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) CallableMemberDescriptor(org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)

Example 4 with KtNamedFunction

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

the class KotlinOverloadTest 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)

Example 5 with KtNamedFunction

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

the class KtFunctionPsiElementCellRenderer method getElementText.

@Override
public String getElementText(PsiElement element) {
    if (element instanceof KtNamedFunction) {
        KtNamedFunction function = (KtNamedFunction) element;
        DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(function, BodyResolveMode.PARTIAL);
        return DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor);
    }
    return super.getElementText(element);
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) 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