Search in sources :

Example 6 with PerlSubElement

use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.

the class PerlRenamePolyReferencedElementProcessor method suggestSuperMethod.

@NotNull
private PsiElement suggestSuperMethod(@NotNull PerlSubElement subBase) {
    PerlSubElement topLevelSuperMethod = subBase.getTopmostSuperMethod();
    String canonicalName = topLevelSuperMethod.getCanonicalName();
    if (topLevelSuperMethod == subBase || canonicalName == null) {
        return subBase;
    }
    int dialogResult = Messages.showOkCancelDialog("This method overrides SUPER method: " + canonicalName + ".", "Method Rename", "Rename SUPER method", "Rename this one", PerlIcons.PERL_LANGUAGE_ICON);
    return dialogResult == Messages.OK ? topLevelSuperMethod : subBase;
}
Also used : PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PerlSubElement

use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.

the class PerlSubNameElementCompletionProvider method addCompletions.

public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement element = parameters.getPosition();
    if (element.getParent() instanceof PerlSubElement) {
        PerlSubElement subDefinitionBase = (PerlSubElement) element.getParent();
        PerlSubCompletionUtil.fillWithUnresolvedSubs(subDefinitionBase, resultSet);
        PerlSubCompletionUtil.fillWithNotOverridedSubs(subDefinitionBase, resultSet);
    }
}
Also used : PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PerlSubElement

use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.

the class PodSubReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PsiElement element = getElement();
    if (element != null) {
        final Project project = element.getProject();
        String subName = element.getText();
        if (StringUtil.isNotEmpty(subName)) {
            final PsiFile containingFile = element.getContainingFile();
            String packageName = PodFileUtil.getPackageName(containingFile);
            List<ResolveResult> results = new ArrayList<>();
            if (StringUtil.isNotEmpty(packageName)) {
                String canonicalName = packageName + PerlPackageUtil.PACKAGE_SEPARATOR + subName;
                for (PerlSubDefinitionElement target : PerlSubUtil.getSubDefinitions(project, canonicalName)) {
                    results.add(new PsiElementResolveResult(target));
                }
                for (PerlSubDeclarationElement target : PerlSubUtil.getSubDeclarations(project, canonicalName)) {
                    results.add(new PsiElementResolveResult(target));
                }
            }
            if (results.isEmpty()) {
                final PsiFile perlFile = containingFile.getViewProvider().getStubBindingRoot();
                for (PerlSubElement subBase : PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class)) {
                    String subBaseName = subBase.getName();
                    if (subBaseName != null && StringUtil.equals(subBaseName, subName)) {
                        results.add(new PsiElementResolveResult(subBase));
                    }
                }
            }
            return results.toArray(new ResolveResult[results.size()]);
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : Project(com.intellij.openapi.project.Project) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PerlSubDeclarationElement(com.perl5.lang.perl.psi.PerlSubDeclarationElement) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PerlSubElement

use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.

the class PerlPackageUtil method processNotOverridedMethods.

public static void processNotOverridedMethods(final PerlNamespaceDefinitionElement namespaceDefinition, Processor<PerlSubElement> processor) {
    if (namespaceDefinition != null) {
        PsiFile containingFile = namespaceDefinition.getContainingFile();
        String packageName = namespaceDefinition.getPackageName();
        if (packageName == null) {
            return;
        }
        Set<String> namesSet = new THashSet<>();
        // collecting overrided
        for (PerlSubDefinitionElement subDefinitionBase : PsiTreeUtil.findChildrenOfType(containingFile, PerlSubDefinitionElement.class)) {
            if (subDefinitionBase.isValid() && StringUtil.equals(packageName, subDefinitionBase.getPackageName())) {
                namesSet.add(subDefinitionBase.getSubName());
            }
        }
        processParentClassesSubs(namespaceDefinition, namesSet, new THashSet<>(), processor);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) THashSet(gnu.trove.THashSet)

Example 10 with PerlSubElement

use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.

the class PodTitleCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    final PsiElement element = parameters.getOriginalPosition();
    if (element == null) {
        return;
    }
    PsiElement prevElement = element.getPrevSibling();
    if (prevElement == null || prevElement instanceof PodSectionTitle) {
        if (HEADER1_ELEMENT.accepts(element)) {
            for (String title : DEFAULT_POD_SECTIONS) {
                result.addElement(LookupElementBuilder.create(title));
            }
        }
        final PsiFile elementFile = element.getContainingFile();
        final PsiFile perlFile = PodFileUtil.getTargetPerlFile(elementFile);
        if (perlFile != null) {
            final Collection<PerlSubElement> possibleTargets = PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class);
            element.getContainingFile().accept(new PodRecursiveVisitor() {

                @Override
                public void visitTargetableSection(PodTitledSection o) {
                    PsiElement titleBlock = o.getTitleBlock();
                    if (titleBlock != null) {
                        PsiElement firstChild = titleBlock.getFirstChild();
                        if (firstChild != null) {
                            for (PsiReference reference : firstChild.getReferences()) {
                                if (reference instanceof PodSubReference) {
                                    for (ResolveResult resolveResult : ((PodSubReference) reference).multiResolve(false)) {
                                        PsiElement targetElement = resolveResult.getElement();
                                        if (targetElement instanceof PerlSubElement) {
                                            possibleTargets.remove(targetElement);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    super.visitTargetableSection(o);
                }
            });
            for (PerlSubElement untargetedSub : possibleTargets) {
                result.addElement(LookupElementBuilder.create(StringUtil.notNullize(untargetedSub.getPresentableName())).withIcon(untargetedSub.getIcon(0)));
            }
        }
    }
}
Also used : PodSectionTitle(com.perl5.lang.pod.parser.psi.PodSectionTitle) PodSubReference(com.perl5.lang.pod.parser.psi.references.PodSubReference) PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PodRecursiveVisitor(com.perl5.lang.pod.parser.psi.PodRecursiveVisitor)

Aggregations

PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)9 PsiElement (com.intellij.psi.PsiElement)6 PsiFile (com.intellij.psi.PsiFile)4 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)4 NotNull (org.jetbrains.annotations.NotNull)4 ResolveResult (com.intellij.psi.ResolveResult)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)2 PsiReference (com.intellij.psi.PsiReference)2 PerlGlobVariable (com.perl5.lang.perl.psi.PerlGlobVariable)2 PerlSubDeclarationElement (com.perl5.lang.perl.psi.PerlSubDeclarationElement)2 THashSet (gnu.trove.THashSet)2 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 com.intellij.psi (com.intellij.psi)1 SearchScope (com.intellij.psi.search.SearchScope)1 ReferencesSearch (com.intellij.psi.search.searches.ReferencesSearch)1