use of org.ballerinalang.plugins.idea.psi.ConnectorDeclarationStatementNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method resolveStructFromDefinitionNode.
@Nullable
public static StructDefinitionNode resolveStructFromDefinitionNode(@NotNull PsiElement definitionNode) {
if (definitionNode instanceof ConnectorDeclarationStatementNode) {
NameReferenceNode nameReferenceNode = PsiTreeUtil.getChildOfType(definitionNode, NameReferenceNode.class);
if (nameReferenceNode != null) {
PsiReference reference = nameReferenceNode.findReferenceAt(nameReferenceNode.getTextLength());
if (reference != null) {
PsiElement resolvedElement = reference.resolve();
if (resolvedElement != null && resolvedElement.getParent() instanceof StructDefinitionNode) {
return ((StructDefinitionNode) resolvedElement.getParent());
}
}
}
}
TypeNameNode typeNameNode = PsiTreeUtil.findChildOfType(definitionNode, TypeNameNode.class);
if (typeNameNode == null) {
return null;
}
NameReferenceNode nameReferenceNode = PsiTreeUtil.findChildOfType(typeNameNode, NameReferenceNode.class);
if (nameReferenceNode == null) {
return null;
}
PsiElement nameIdentifier = nameReferenceNode.getNameIdentifier();
if (nameIdentifier == null) {
return null;
}
PsiReference typeNameNodeReference = nameIdentifier.getReference();
if (typeNameNodeReference == null) {
return null;
}
PsiElement resolvedDefElement = typeNameNodeReference.resolve();
if (resolvedDefElement == null) {
return null;
}
if (!(resolvedDefElement.getParent() instanceof StructDefinitionNode)) {
return null;
}
return ((StructDefinitionNode) resolvedDefElement.getParent());
}
Aggregations