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);
}
}
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());
}
}
}
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");
}
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();
}
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();
}
Aggregations