use of com.perl5.lang.perl.psi.utils.PerlVariableType in project Perl5-IDEA by Camelcade.
the class PerlVariableReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement elementParent = myElement.getParent();
assert elementParent instanceof PerlVariable;
PerlVariable perlVariable = (PerlVariable) elementParent;
List<ResolveResult> result = new ArrayList<>();
PerlVariableDeclarationElement lexicalDeclaration = PerlResolveUtil.getLexicalDeclaration(perlVariable);
if (lexicalDeclaration == null || lexicalDeclaration.isGlobalDeclaration() && !(lexicalDeclaration instanceof PerlImplicitVariableDeclaration)) {
// not found explicit lexically visible declarations
// imports
PerlVariableType actualType = perlVariable.getActualType();
Project project = perlVariable.getProject();
PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(perlVariable);
if (// not true if LPE in TemplateToolkit
namespaceContainer != null) {
String variableName = perlVariable.getName();
if (actualType == PerlVariableType.SCALAR) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedScalarDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlScalarUtil.getGlobalScalarDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
} else if (actualType == PerlVariableType.ARRAY) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedArrayDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlArrayUtil.getGlobalArrayDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
} else if (actualType == PerlVariableType.HASH) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedHashDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlHashUtil.getGlobalHashDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
}
}
// our variable declaration
for (PerlGlobVariable glob : perlVariable.getRelatedGlobs()) {
result.add(new PsiElementResolveResult(glob));
}
// globs
for (PerlVariableDeclarationElement globalDeclaration : perlVariable.getGlobalDeclarations()) {
result.add(new PsiElementResolveResult(globalDeclaration));
}
} else {
result.add(new PsiElementResolveResult(lexicalDeclaration));
}
return result.toArray(new ResolveResult[result.size()]);
}
Aggregations