Search in sources :

Example 6 with PerlExportDescriptor

use of com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor 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 7 with PerlExportDescriptor

use of com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor 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 8 with PerlExportDescriptor

use of com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor in project Perl5-IDEA by Camelcade.

the class PerlLightTestCase method appendDescriptors.

private void appendDescriptors(@NotNull String sectionLabel, @NotNull StringBuilder sb, @NotNull List<PerlExportDescriptor> exportDescriptors) {
    if (exportDescriptors.isEmpty()) {
        return;
    }
    sb.append(sectionLabel).append(":\n");
    for (PerlExportDescriptor descriptor : exportDescriptors) {
        sb.append("    ").append(descriptor.getImportedName()).append(" => ").append(descriptor.getTargetCanonicalName()).append("\n");
    }
    sb.append("\n");
}
Also used : PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)

Example 9 with PerlExportDescriptor

use of com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor in project Perl5-IDEA by Camelcade.

the class PerlScalarUtil method getImportedScalarsDescritptors.

/**
 * Returns a map of imported scalars names
 *
 * @param namespaceDefinitionElement element to start looking from
 * @return result map
 */
@NotNull
public static List<PerlExportDescriptor> getImportedScalarsDescritptors(@NotNull PerlNamespaceDefinitionElement namespaceDefinitionElement) {
    PerlImportsCollector collector = new PerlScalarImportsCollector();
    PerlUtil.processImportedEntities(namespaceDefinitionElement, collector);
    return collector.getResult();
}
Also used : PerlImportsCollector(com.perl5.lang.perl.util.processors.PerlImportsCollector) PerlScalarImportsCollector(com.perl5.lang.perl.util.processors.PerlScalarImportsCollector) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PerlExportDescriptor

use of com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor in project Perl5-IDEA by Camelcade.

the class PerlSubUtil method getImportedSubsDescriptors.

/**
 * Returns a list of imported descriptors
 *
 * @param namespaceDefinitionElement element to start looking from
 * @return result map
 */
@NotNull
public static List<PerlExportDescriptor> getImportedSubsDescriptors(@NotNull PerlNamespaceDefinitionElement namespaceDefinitionElement) {
    PerlImportsCollector collector = new PerlSubImportsCollector();
    PerlUtil.processImportedEntities(namespaceDefinitionElement, collector);
    return collector.getResult();
}
Also used : PerlSubImportsCollector(com.perl5.lang.perl.util.processors.PerlSubImportsCollector) PerlImportsCollector(com.perl5.lang.perl.util.processors.PerlImportsCollector) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)9 NotNull (org.jetbrains.annotations.NotNull)9 PsiElement (com.intellij.psi.PsiElement)5 PerlImportsCollector (com.perl5.lang.perl.util.processors.PerlImportsCollector)4 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)2 ResolveResult (com.intellij.psi.ResolveResult)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ArrayList (java.util.ArrayList)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 SortableTreeElement (com.intellij.ide.util.treeView.smartTree.SortableTreeElement)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 Language (com.intellij.lang.Language)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 PerlLanguage (com.perl5.lang.perl.PerlLanguage)1 PerlItemPresentationBase (com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase)1