use of com.perl5.lang.perl.util.processors.PerlNamespaceEntityProcessor 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.util.processors.PerlNamespaceEntityProcessor in project Perl5-IDEA by Camelcade.
the class PerlUtil method processImportedEntities.
/**
* Processing use statements in the namespace or file and processing all imports found
*
* @param namespace Root element to start searching from
*/
public static void processImportedEntities(@NotNull PerlNamespaceDefinitionElement namespace, @NotNull PerlNamespaceEntityProcessor<PerlExportDescriptor> processor) {
for (PsiElement element : PerlPsiUtil.collectUseStatements(namespace)) {
PerlUseStatement useStatement = (PerlUseStatement) element;
String packageName = useStatement.getPackageName();
if (packageName != null) {
for (PerlExportDescriptor entry : useStatement.getPackageProcessor().getImports(useStatement)) {
ProgressManager.checkCanceled();
processor.process(packageName, entry);
}
}
}
PerlImportsProvider.processProviders(namespace, provider -> {
for (PerlExportDescriptor descriptor : provider.getImports()) {
if (!processor.process(namespace.getPackageName(), descriptor)) {
return false;
}
}
return true;
});
}
Aggregations