Search in sources :

Example 1 with KtProperty

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

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

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

the class AddFieldBreakpointDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            updateUI();
        }
    });
    myClassChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title"));
            if (currentClass != null) {
                PsiFile containingFile = currentClass.getContainingFile();
                if (containingFile != null) {
                    PsiDirectory containingDirectory = containingFile.getContainingDirectory();
                    if (containingDirectory != null) {
                        chooser.selectDirectory(containingDirectory);
                    }
                }
            }
            chooser.showDialog();
            PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                myClassChooser.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myFieldChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            PsiClass selectedClass = getSelectedClass();
            DescriptorMemberChooserObject[] properties = FieldBreakpointDialogUtilKt.collectProperties(selectedClass);
            MemberChooser<DescriptorMemberChooserObject> chooser = new MemberChooser<DescriptorMemberChooserObject>(properties, false, false, myProject);
            chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", properties.length));
            chooser.setCopyJavadocVisible(false);
            chooser.show();
            List<DescriptorMemberChooserObject> selectedElements = chooser.getSelectedElements();
            if (selectedElements != null && selectedElements.size() == 1) {
                KtProperty field = (KtProperty) selectedElements.get(0).getElement();
                myFieldChooser.setText(field.getName());
            }
        }
    });
    myFieldChooser.setEnabled(false);
    return myPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) MemberChooser(com.intellij.ide.util.MemberChooser) KtProperty(org.jetbrains.kotlin.psi.KtProperty) DescriptorMemberChooserObject(org.jetbrains.kotlin.idea.core.util.DescriptorMemberChooserObject) ActionListener(java.awt.event.ActionListener) List(java.util.List)

Aggregations

KtProperty (org.jetbrains.kotlin.psi.KtProperty)3 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 MemberChooser (com.intellij.ide.util.MemberChooser)1 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 PsiMethod (com.intellij.psi.PsiMethod)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 List (java.util.List)1 Map (java.util.Map)1 DocumentEvent (javax.swing.event.DocumentEvent)1 CallableMemberDescriptor (org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 DescriptorMemberChooserObject (org.jetbrains.kotlin.idea.core.util.DescriptorMemberChooserObject)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1 InlineAnalyzerExtension (org.jetbrains.kotlin.resolve.inline.InlineAnalyzerExtension)1