Search in sources :

Example 1 with PerlMooseAugmentStatement

use of com.perl5.lang.perl.parser.moose.psi.PerlMooseAugmentStatement in project Perl5-IDEA by Camelcade.

the class PerlMooseInnerReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    List<ResolveResult> result = new ArrayList<>();
    PsiElement element = getElement();
    String subName = null;
    PerlSubDefinitionElement subDefinitionBase = PsiTreeUtil.getParentOfType(element, PerlSubDefinitionElement.class);
    if (subDefinitionBase != null) {
        subName = subDefinitionBase.getSubName();
    }
    PerlMooseAugmentStatement augmentStatement = PsiTreeUtil.getParentOfType(element, PerlMooseAugmentStatement.class);
    if (augmentStatement != null) {
        subName = augmentStatement.getSubName();
    }
    if (subName != null) {
        PerlNamespaceDefinitionElement namespaceDefinition = PsiTreeUtil.getParentOfType(element, PerlNamespaceDefinitionElement.class);
        Set<PerlNamespaceDefinitionElement> recursionSet = new THashSet<>();
        if (StringUtil.isNotEmpty(subName) && namespaceDefinition != null) {
            collectNamespaceMethodsAugmentations(namespaceDefinition, subName, recursionSet, result);
        }
    }
    return result.toArray(new ResolveResult[result.size()]);
}
Also used : PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) ArrayList(java.util.ArrayList) PerlMooseAugmentStatement(com.perl5.lang.perl.parser.moose.psi.PerlMooseAugmentStatement) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) PsiElement(com.intellij.psi.PsiElement) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlMooseAugmentStatement

use of com.perl5.lang.perl.parser.moose.psi.PerlMooseAugmentStatement in project Perl5-IDEA by Camelcade.

the class PerlMooseInnerReference method collectNamespaceMethodsAugmentations.

protected void collectNamespaceMethodsAugmentations(@NotNull PerlNamespaceDefinitionElement namespaceDefinition, @NotNull String subName, Set<PerlNamespaceDefinitionElement> recursionSet, List<ResolveResult> result) {
    recursionSet.add(namespaceDefinition);
    for (PerlNamespaceDefinitionElement childNamespace : namespaceDefinition.getChildNamespaceDefinitions()) {
        if (!recursionSet.contains(childNamespace)) {
            boolean noSubclasses = false;
            for (PsiElement augmentStatement : getAugmentStatements(childNamespace)) {
                if (subName.equals(((PerlMooseAugmentStatement) augmentStatement).getSubName())) {
                    result.add(new PsiElementResolveResult(augmentStatement));
                    noSubclasses = true;
                }
            }
            if (!noSubclasses) {
                collectNamespaceMethodsAugmentations(childNamespace, subName, recursionSet, result);
            }
        }
    }
}
Also used : PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)2 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)2 ResolveResult (com.intellij.psi.ResolveResult)1 PerlMooseAugmentStatement (com.perl5.lang.perl.parser.moose.psi.PerlMooseAugmentStatement)1 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)1 THashSet (gnu.trove.THashSet)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1