use of org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllEndpointsInResolvableScope.
@NotNull
public static List<IdentifierPSINode> getAllEndpointsInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
List<IdentifierPSINode> results = new LinkedList<>();
if (scope instanceof VariableContainer || scope instanceof CodeBlockScope || scope instanceof TopLevelDefinition || scope instanceof LowerLevelDefinition) {
results.addAll(getAllEndpointsInScope(scope, caretOffset));
ScopeNode context = scope.getContext();
if (context != null) {
results.addAll(getAllEndpointsInResolvableScope(context, caretOffset));
}
}
return results;
}
use of org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllXmlNamespacesInResolvableScope.
@NotNull
public static List<PsiElement> getAllXmlNamespacesInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
List<PsiElement> results = new LinkedList<>();
if (scope instanceof VariableContainer || scope instanceof CodeBlockScope || scope instanceof BallerinaFile) {
results.addAll(getAllXmlNamespacesInScope(scope, caretOffset));
ScopeNode context = scope.getContext();
if (context != null) {
results.addAll(getAllXmlNamespacesInResolvableScope(context, caretOffset));
}
} else if (scope instanceof ParameterContainer || scope instanceof TopLevelDefinition || scope instanceof LowerLevelDefinition) {
ScopeNode context = scope.getContext();
if (context != null) {
results.addAll(getAllXmlNamespacesInResolvableScope(context, caretOffset));
}
}
if (scope instanceof BallerinaFile) {
PsiFile originalFile = ((BallerinaFile) scope).getOriginalFile();
PsiDirectory containingPackage = originalFile.getParent();
if (containingPackage == null) {
return results;
}
PsiFile[] files = containingPackage.getFiles();
for (PsiFile file : files) {
// Do't check the current file again.
if (file.equals(originalFile)) {
continue;
}
Collection<NamespaceDeclarationNode> namespaceDeclarationNodes = PsiTreeUtil.findChildrenOfType(file, NamespaceDeclarationNode.class);
for (NamespaceDeclarationNode namespaceDeclarationNode : namespaceDeclarationNodes) {
PsiElement identifier = namespaceDeclarationNode.getNameIdentifier();
if (identifier != null) {
results.add(identifier);
}
}
}
}
return results;
}
use of org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllLocalVariablesInResolvableScope.
/**
* Returns all local variables in provided scope and all parent contexts.
*
* @param scope
* @param caretOffset
* @return
*/
@NotNull
public static List<IdentifierPSINode> getAllLocalVariablesInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
List<IdentifierPSINode> results = new LinkedList<>();
if (scope instanceof VariableContainer || scope instanceof CodeBlockScope) {
results.addAll(getAllLocalVariablesInScope(scope, caretOffset));
ScopeNode context = scope.getContext();
if (context != null && !(scope instanceof RestrictedScope)) {
results.addAll(getAllLocalVariablesInResolvableScope(context, caretOffset));
}
} else if (scope instanceof ParameterContainer || scope instanceof LowerLevelDefinition) {
ScopeNode context = scope.getContext();
if (context != null) {
results.addAll(getAllLocalVariablesInResolvableScope(context, caretOffset));
}
}
return results;
}
Aggregations