use of com.intellij.psi.PsiElementResolveResult 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()]);
}
use of com.intellij.psi.PsiElementResolveResult in project Perl5-IDEA by Camelcade.
the class PerlSubReferenceSimple method getResolveResults.
@NotNull
public List<ResolveResult> getResolveResults(List<PsiElement> relatedItems) {
List<ResolveResult> result = new ArrayList<>();
resetFlags();
for (PsiElement element : relatedItems) {
if (!isAutoloaded() && element instanceof PerlIdentifierOwner && PerlSubUtil.SUB_AUTOLOAD.equals(((PerlIdentifierOwner) element).getName())) {
setAutoloaded();
}
if (!isConstant() && element instanceof PerlLightConstantDefinitionElement) {
setConstant();
}
if (!isDeclared() && element instanceof PerlSubDeclarationElement) {
setDeclared();
}
if (!isDefined() && element instanceof PerlSubDefinitionElement) {
setDefined();
}
if (!isXSub() && element instanceof PerlSubElement && ((PerlSubElement) element).isXSub()) {
setXSub();
}
if (!isAliased() && element instanceof PerlGlobVariable) {
setAliased();
}
result.add(new PsiElementResolveResult(element));
}
return result;
}
use of com.intellij.psi.PsiElementResolveResult 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()]);
}
use of com.intellij.psi.PsiElementResolveResult in project Perl5-IDEA by Camelcade.
the class PodSubReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement element = getElement();
if (element != null) {
final Project project = element.getProject();
String subName = element.getText();
if (StringUtil.isNotEmpty(subName)) {
final PsiFile containingFile = element.getContainingFile();
String packageName = PodFileUtil.getPackageName(containingFile);
List<ResolveResult> results = new ArrayList<>();
if (StringUtil.isNotEmpty(packageName)) {
String canonicalName = packageName + PerlPackageUtil.PACKAGE_SEPARATOR + subName;
for (PerlSubDefinitionElement target : PerlSubUtil.getSubDefinitions(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
for (PerlSubDeclarationElement target : PerlSubUtil.getSubDeclarations(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
}
if (results.isEmpty()) {
final PsiFile perlFile = containingFile.getViewProvider().getStubBindingRoot();
for (PerlSubElement subBase : PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class)) {
String subBaseName = subBase.getName();
if (subBaseName != null && StringUtil.equals(subBaseName, subName)) {
results.add(new PsiElementResolveResult(subBase));
}
}
}
return results.toArray(new ResolveResult[results.size()]);
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of com.intellij.psi.PsiElementResolveResult in project Perl5-IDEA by Camelcade.
the class TemplateToolkitBlockReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement element = getElement();
if (element == null) {
return ResolveResult.EMPTY_ARRAY;
}
TextRange range = ElementManipulators.getValueTextRange(element);
if (range == null) {
return ResolveResult.EMPTY_ARRAY;
}
final CharSequence targetName = range.subSequence(element.getText());
if (StringUtil.isEmpty(targetName)) {
return ResolveResult.EMPTY_ARRAY;
}
final List<ResolveResult> result = new ArrayList<>();
PsiTreeUtil.processElements(element.getContainingFile(), element1 -> {
if (element1 instanceof TemplateToolkitNamedBlock && StringUtil.equals(((TemplateToolkitNamedBlock) element1).getName(), targetName)) {
result.add(new PsiElementResolveResult(element1));
}
return true;
});
return result.toArray(new ResolveResult[result.size()]);
}
Aggregations