Search in sources :

Example 1 with PerlMethodMember

use of com.perl5.lang.perl.idea.codeInsight.PerlMethodMember in project Perl5-IDEA by Camelcade.

the class PerlCodeGeneratorImpl method generateOverrideMethod.

@Override
public void generateOverrideMethod(PsiElement anchor, Editor editor) {
    if (anchor != null) {
        final List<PerlMethodMember> subDefinitions = new ArrayList<>();
        PerlPackageUtil.processNotOverridedMethods(PsiTreeUtil.getParentOfType(anchor, PerlNamespaceDefinitionElement.class), subDefinitionBase -> {
            subDefinitions.add(new PerlMethodMember(subDefinitionBase));
            return true;
        });
        final MemberChooser<PerlMethodMember> chooser = new MemberChooser<PerlMethodMember>(subDefinitions.toArray(new PerlMethodMember[subDefinitions.size()]), false, true, anchor.getProject()) {

            @Override
            protected SpeedSearchComparator getSpeedSearchComparator() {
                return new SpeedSearchComparator(false) {

                    @Nullable
                    @Override
                    public Iterable<TextRange> matchingFragments(@NotNull String pattern, @NotNull String text) {
                        return super.matchingFragments(PerlMethodMember.trimUnderscores(pattern), text);
                    }
                };
            }

            @Override
            protected ShowContainersAction getShowContainersAction() {
                return new ShowContainersAction(IdeBundle.message("action.show.classes"), PerlIcons.PACKAGE_GUTTER_ICON);
            }
        };
        chooser.setTitle("Override/Implement Method");
        chooser.setCopyJavadocVisible(false);
        chooser.show();
        if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
            return;
        }
        StringBuilder generatedCode = new StringBuilder("");
        if (chooser.getSelectedElements() != null) {
            for (PerlMethodMember methodMember : chooser.getSelectedElements()) {
                String code = getOverrideCodeText(methodMember.getPsiElement());
                if (StringUtil.isNotEmpty(code)) {
                    generatedCode.append(code);
                    generatedCode.append("\n\n");
                }
            }
            insertCodeAfterElement(anchor, generatedCode.toString(), editor);
        }
    }
}
Also used : PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator) PerlMethodMember(com.perl5.lang.perl.idea.codeInsight.PerlMethodMember) MemberChooser(com.intellij.ide.util.MemberChooser) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlMethodMember

use of com.perl5.lang.perl.idea.codeInsight.PerlMethodMember in project Perl5-IDEA by Camelcade.

the class PerlMethodMember method getParentNodeDelegate.

@Override
public MemberChooserObject getParentNodeDelegate() {
    final PsiElement subDefinitionBase = getPsiElement();
    final PerlNamespaceDefinitionElement parent = (PerlNamespaceDefinitionElement) PerlPsiUtil.getParentElementOrStub(subDefinitionBase, PerlNamespaceDefinitionStub.class, PerlNamespaceDefinitionElement.class);
    assert (parent != null);
    return new PerlMethodMember(parent);
}
Also used : PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PerlNamespaceDefinitionStub(com.perl5.lang.perl.psi.stubs.namespaces.PerlNamespaceDefinitionStub) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)2 MemberChooser (com.intellij.ide.util.MemberChooser)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 SpeedSearchComparator (com.intellij.ui.SpeedSearchComparator)1 PerlMethodMember (com.perl5.lang.perl.idea.codeInsight.PerlMethodMember)1 PerlNamespaceDefinitionStub (com.perl5.lang.perl.psi.stubs.namespaces.PerlNamespaceDefinitionStub)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1