use of org.ballerinalang.plugins.idea.psi.AliasNode in project ballerina by ballerina-lang.
the class PackageNameReference method multiResolve.
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
IdentifierPSINode identifier = getElement();
if (identifier == null) {
return new ResolveResult[0];
}
AliasNode aliasNode = PsiTreeUtil.getParentOfType(identifier, AliasNode.class);
if (aliasNode != null) {
return new ResolveResult[0];
}
List<ResolveResult> results = new ArrayList<>();
ImportDeclarationNode importDeclarationNode = PsiTreeUtil.getParentOfType(identifier, ImportDeclarationNode.class);
if (importDeclarationNode != null) {
List<PsiDirectory> directories = BallerinaPsiImplUtil.resolveDirectory(identifier);
for (PsiDirectory directory : directories) {
results.add(new PsiElementResolveResult(directory));
}
// Return the results.
return results.toArray(new ResolveResult[results.size()]);
}
PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.getParentOfType(identifier, PackageDeclarationNode.class);
if (packageDeclarationNode != null) {
// If this is a package declaration, resolve the directory.
List<PsiDirectory> directories = BallerinaPsiImplUtil.resolveDirectory(identifier);
for (PsiDirectory directory : directories) {
results.add(new PsiElementResolveResult(directory));
}
// Return the results.
return results.toArray(new ResolveResult[results.size()]);
}
PsiFile containingFile = identifier.getContainingFile();
if (containingFile == null) {
return new ResolveResult[0];
}
List<PsiElement> importedPackages = BallerinaPsiImplUtil.getImportedPackagesInCurrentFile(containingFile);
for (PsiElement importedPackage : importedPackages) {
String packageName = importedPackage.getText();
if (packageName == null || packageName.isEmpty()) {
continue;
}
if (packageName.equals(identifier.getText())) {
PsiReference reference = importedPackage.findReferenceAt(0);
if (reference != null) {
PsiElement resolvedElement = reference.resolve();
if (resolvedElement != null) {
results.add(new PsiElementResolveResult(resolvedElement));
}
}
}
}
importedPackages = BallerinaPsiImplUtil.getPackagesImportedAsAliasInCurrentFile(containingFile);
for (PsiElement importedPackage : importedPackages) {
String packageName = importedPackage.getText();
if (packageName == null || packageName.isEmpty()) {
continue;
}
if (packageName.equals(identifier.getText())) {
IdentifierPSINode nameNode = PsiTreeUtil.findChildOfType(importedPackage, IdentifierPSINode.class);
if (nameNode != null) {
results.add(new PsiElementResolveResult(nameNode));
}
}
}
return results.toArray(new ResolveResult[results.size()]);
}
Aggregations