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