Search in sources :

Example 16 with PerlNamespaceDefinitionElement

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

the class PerlVariableNameCompletionProvider method fillWithImportedVariables.

private void fillWithImportedVariables(@NotNull PsiElement variableNameElement, @NotNull CompletionResultSet resultSet) {
    PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(variableNameElement);
    if (namespaceContainer == null) {
        return;
    }
    String packageName = namespaceContainer.getPackageName();
    if (// incomplete package definition
    StringUtil.isEmpty(packageName)) {
        return;
    }
    PerlNamespaceEntityProcessor<PerlExportDescriptor> processor = null;
    PsiElement perlVariable = variableNameElement.getParent();
    if (perlVariable instanceof PsiPerlScalarVariable) {
        processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {

            @Override
            public boolean process(String namespaceName, PerlExportDescriptor entity) {
                LookupElementBuilder lookupElement = null;
                if (entity.isScalar()) {
                    lookupElement = PerlVariableCompletionUtil.getScalarLookupElement(entity.getImportedName());
                } else if (entity.isArray()) {
                    lookupElement = PerlVariableCompletionUtil.getArrayElementLookupElement(entity.getImportedName());
                } else if (entity.isHash()) {
                    lookupElement = PerlVariableCompletionUtil.getHashElementLookupElement(entity.getImportedName());
                }
                if (lookupElement != null) {
                    resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
                }
                return true;
            }
        };
    } else if (perlVariable instanceof PsiPerlArrayVariable || perlVariable instanceof PsiPerlArrayIndexVariable) {
        processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {

            @Override
            public boolean process(String namespaceName, PerlExportDescriptor entity) {
                LookupElementBuilder lookupElement = null;
                if (entity.isArray()) {
                    lookupElement = PerlVariableCompletionUtil.getArrayLookupElement(entity.getImportedName());
                } else if (entity.isHash()) {
                    lookupElement = PerlVariableCompletionUtil.getHashSliceLookupElement(entity.getImportedName());
                }
                if (lookupElement != null) {
                    resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
                }
                return true;
            }
        };
    } else if (perlVariable instanceof PsiPerlHashVariable) {
        processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {

            @Override
            public boolean process(String namespaceName, PerlExportDescriptor entity) {
                LookupElementBuilder lookupElement = null;
                if (entity.isHash()) {
                    lookupElement = PerlVariableCompletionUtil.getHashLookupElement(entity.getImportedName());
                }
                if (lookupElement != null) {
                    resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
                }
                return true;
            }
        };
    }
    if (processor != null) {
        PerlUtil.processImportedEntities(namespaceContainer, processor);
    }
}
Also used : PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PerlNamespaceEntityProcessor(com.perl5.lang.perl.util.processors.PerlNamespaceEntityProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 17 with PerlNamespaceDefinitionElement

use of com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement 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)

Example 18 with PerlNamespaceDefinitionElement

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

the class PerlImportedSubsCompletionProvider method fillWithNamespaceImports.

protected static void fillWithNamespaceImports(@NotNull PerlNamespaceDefinitionElement namespaceContainer, @NotNull final CompletionResultSet resultSet) {
    for (PerlExportDescriptor importedDescriptor : namespaceContainer.getImportedSubsDescriptors()) {
        Ref<Boolean> flag = Ref.create(false);
        PerlSubUtil.processRelatedItems(importedDescriptor.getTargetCanonicalName(), namespaceContainer.getProject(), element -> {
            resultSet.addElement(PerlSubCompletionUtil.getImportedEntityLookupElement(element, importedDescriptor));
            flag.set(true);
            return true;
        });
        if (!flag.get()) {
            resultSet.addElement(importedDescriptor.getLookupElement());
        }
    }
}
Also used : PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)

Example 19 with PerlNamespaceDefinitionElement

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

the class PerlImportedSubsCompletionProvider method addCompletions.

public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet resultSet) {
    PsiElement position = parameters.getPosition();
    PsiPerlMethod method = (PsiPerlMethod) position.getParent();
    if (method.isObjectMethod()) {
        return;
    }
    Project project = method.getProject();
    if (!method.hasExplicitNamespace()) {
        PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(position);
        if (namespaceContainer != null) {
            fillWithNamespaceImports(namespaceContainer, resultSet);
        }
    } else {
        // not an object method, but has explicit namespace
        PerlNamespaceElement namespaceElement = method.getNamespaceElement();
        if (namespaceElement != null) {
            String targetPackageName = namespaceElement.getCanonicalName();
            if (targetPackageName != null) {
                for (PerlNamespaceDefinitionElement namespaceDefinition : PerlPackageUtil.getNamespaceDefinitions(project, targetPackageName)) {
                    fillWithNamespaceImports(namespaceDefinition, resultSet);
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PsiElement(com.intellij.psi.PsiElement)

Example 20 with PerlNamespaceDefinitionElement

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

the class PerlNamespaceElementImpl method getNamespaceDefinitions.

@Override
public List<PerlNamespaceDefinitionElement> getNamespaceDefinitions() {
    List<PerlNamespaceDefinitionElement> namespaceDefinitions = new ArrayList<>();
    PsiReference[] references = getReferences();
    for (PsiReference reference : references) {
        if (reference instanceof PerlNamespaceReference) {
            ResolveResult[] results = ((PerlNamespaceReference) reference).multiResolve(false);
            for (ResolveResult result : results) {
                PsiElement targetElement = result.getElement();
                assert targetElement != null;
                assert targetElement instanceof PerlNamespaceDefinitionElement;
                namespaceDefinitions.add((PerlNamespaceDefinitionElement) targetElement);
            }
        }
    }
    return namespaceDefinitions;
}
Also used : PerlNamespaceReference(com.perl5.lang.perl.psi.references.PerlNamespaceReference) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)17 PsiElement (com.intellij.psi.PsiElement)12 NotNull (org.jetbrains.annotations.NotNull)10 Project (com.intellij.openapi.project.Project)8 ArrayList (java.util.ArrayList)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 PsiFile (com.intellij.psi.PsiFile)6 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)6 ResolveResult (com.intellij.psi.ResolveResult)4 PerlImportsCollector (com.perl5.lang.perl.util.processors.PerlImportsCollector)4 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 MasonSettings (com.perl5.lang.mason2.idea.configuration.MasonSettings)2 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)2 PerlUseStatement (com.perl5.lang.perl.psi.PerlUseStatement)2 PerlFileImpl (com.perl5.lang.perl.psi.impl.PerlFileImpl)2 PerlNamespaceDefinitionStub (com.perl5.lang.perl.psi.stubs.namespaces.PerlNamespaceDefinitionStub)2 THashSet (gnu.trove.THashSet)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1