use of org.ballerinalang.plugins.idea.psi.ActionDefinitionNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllActionsFromAConnector.
/**
* Returns all actions/native actions defined in the given ConnectorDefinitionNode.
*
* @param connectorDefinitionNode PsiElement which represent a Connector Definition
* @return List of all actions/native actions defined in the given ConnectorDefinitionNode.
*/
@NotNull
public static List<IdentifierPSINode> getAllActionsFromAConnector(@NotNull PsiElement connectorDefinitionNode) {
List<IdentifierPSINode> results = new ArrayList<>();
Collection<ActionDefinitionNode> actionDefinitionNodes = PsiTreeUtil.findChildrenOfType(connectorDefinitionNode, ActionDefinitionNode.class);
for (ActionDefinitionNode definitionNode : actionDefinitionNodes) {
IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(definitionNode, IdentifierPSINode.class);
results.add(identifier);
}
return results;
}
use of org.ballerinalang.plugins.idea.psi.ActionDefinitionNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAttachmentType.
/**
* Returns the attachment type by checking the nodes.
*
* @param identifier identifier node of the annotation attachment node
* @return attachment type.
*/
@Nullable
public static String getAttachmentType(@NotNull IdentifierPSINode identifier) {
PsiElement parent = identifier.getParent();
PsiElement superParent = parent.getParent();
PsiElement nextSibling = PsiTreeUtil.skipSiblingsForward(superParent, PsiWhiteSpace.class, PsiComment.class, AnnotationAttachmentNode.class);
String type = null;
if (nextSibling == null) {
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
if (annotationAttachmentNode != null) {
PsiElement definitionNode = annotationAttachmentNode.getParent();
type = getAnnotationAttachmentType(definitionNode);
}
} else if (nextSibling instanceof DefinitionNode) {
PsiElement[] children = nextSibling.getChildren();
if (children.length != 0) {
PsiElement definitionNode = children[0];
type = getAnnotationAttachmentType(definitionNode);
}
} else if (nextSibling.getParent() instanceof ResourceDefinitionNode) {
type = "resource";
} else if (nextSibling instanceof ActionDefinitionNode || nextSibling.getParent() instanceof ActionDefinitionNode || parent instanceof ActionDefinitionNode) {
type = "action";
} else if (nextSibling.getParent() instanceof ParameterNode) {
type = "parameter";
}
return type;
}
use of org.ballerinalang.plugins.idea.psi.ActionDefinitionNode 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