use of org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method resolveConnectorFromVariableDefinitionNode.
@Nullable
public static ConnectorDefinitionNode resolveConnectorFromVariableDefinitionNode(@NotNull PsiElement definitionNode) {
NameReferenceNode nameReferenceNode = PsiTreeUtil.findChildOfType(definitionNode, 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 ConnectorDefinitionNode)) {
return null;
}
return ((ConnectorDefinitionNode) resolvedDefElement.getParent());
}
use of org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode in project ballerina by ballerina-lang.
the class ActionInvocationReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
IdentifierPSINode identifier = getElement();
PsiElement parent = identifier.getParent();
PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(parent);
PsiReference variableReference = null;
if (prevVisibleLeaf != null && ".".equals(prevVisibleLeaf.getText())) {
PsiElement connectorVariable = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
if (connectorVariable != null) {
variableReference = connectorVariable.findReferenceAt(connectorVariable.getTextLength());
}
} else {
PsiElement prevSibling = parent.getPrevSibling();
variableReference = prevSibling.findReferenceAt(prevSibling.getTextLength());
}
if (variableReference == null) {
return null;
}
PsiElement variableDefinition = variableReference.resolve();
if (variableDefinition == null) {
return null;
}
PsiElement variableDefinitionParent = variableDefinition.getParent();
ConnectorDefinitionNode connectorDefinitionNode;
if (variableDefinitionParent instanceof EndpointDeclarationNode) {
connectorDefinitionNode = BallerinaPsiImplUtil.getConnectorDefinition(((EndpointDeclarationNode) variableDefinitionParent));
} else {
connectorDefinitionNode = BallerinaPsiImplUtil.resolveConnectorFromVariableDefinitionNode(variableDefinitionParent);
}
if (connectorDefinitionNode == null) {
return null;
}
Collection<ActionDefinitionNode> actionDefinitionNodes = PsiTreeUtil.findChildrenOfType(connectorDefinitionNode, ActionDefinitionNode.class);
for (ActionDefinitionNode actionDefinitionNode : actionDefinitionNodes) {
IdentifierPSINode actionIdentifier = PsiTreeUtil.getChildOfType(actionDefinitionNode, IdentifierPSINode.class);
if (actionIdentifier == null) {
continue;
}
if (actionIdentifier.getText().equals(identifier.getText())) {
return actionIdentifier;
}
}
return null;
}
Aggregations