use of org.ballerinalang.plugins.idea.psi.references.InvocationReference in project ballerina by ballerina-lang.
the class IdentifierPSINode method suggestReferenceTypeForInvocation.
@Nullable
private PsiReference suggestReferenceTypeForInvocation() {
PsiElement parent = getParent();
PsiElement prevSibling = parent.getPrevSibling();
if (prevSibling == null) {
return null;
}
PsiReference reference = null;
if (parent instanceof AnyIdentifierNameNode) {
InvocationNode invocationNode = PsiTreeUtil.getParentOfType(parent, InvocationNode.class);
if (invocationNode != null) {
PsiElement invocationNodePrevSibling = invocationNode.getPrevSibling();
if (invocationNodePrevSibling != null) {
if (invocationNodePrevSibling instanceof VariableReferenceNode) {
InvocationNode node = PsiTreeUtil.getChildOfType(invocationNodePrevSibling, InvocationNode.class);
if (node != null) {
IdentifierPSINode identifier = PsiTreeUtil.findChildOfType(node, IdentifierPSINode.class);
if (identifier != null) {
reference = identifier.findReferenceAt(identifier.getTextLength());
}
} else {
NameReferenceNode nameReferenceNode = PsiTreeUtil.getChildOfType(invocationNodePrevSibling, NameReferenceNode.class);
if (nameReferenceNode != null) {
IdentifierPSINode identifier = PsiTreeUtil.findChildOfType(nameReferenceNode, IdentifierPSINode.class);
if (identifier != null) {
reference = identifier.findReferenceAt(identifier.getTextLength());
}
}
}
} else {
reference = invocationNodePrevSibling.findReferenceAt(invocationNodePrevSibling.getTextLength());
}
}
}
} else if (prevSibling instanceof VariableReferenceNode) {
InvocationNode invocationNode = PsiTreeUtil.getChildOfType(prevSibling, InvocationNode.class);
if (invocationNode != null) {
IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(invocationNode, IdentifierPSINode.class);
if (identifier == null) {
return null;
}
reference = identifier.findReferenceAt(identifier.getTextLength());
}
FieldNode fieldNode = PsiTreeUtil.getChildOfType(prevSibling, FieldNode.class);
if (fieldNode != null) {
IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(fieldNode, IdentifierPSINode.class);
if (identifier == null) {
return null;
}
reference = identifier.findReferenceAt(identifier.getTextLength());
}
FunctionInvocationNode functionInvocationNode = PsiTreeUtil.getChildOfType(prevSibling, FunctionInvocationNode.class);
if (functionInvocationNode != null) {
FunctionReferenceNode functionReferenceNode = PsiTreeUtil.getChildOfType(functionInvocationNode, FunctionReferenceNode.class);
if (functionReferenceNode != null) {
return new NameReference(this);
}
}
if (reference == null) {
reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
}
} else {
reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
}
if (reference == null) {
return null;
}
PsiElement resolvedElement = reference.resolve();
if (resolvedElement == null) {
return null;
}
PsiElement definitionNode = resolvedElement.getParent();
if (definitionNode instanceof VariableDefinitionNode) {
ConnectorDefinitionNode connectorDefinitionNode = BallerinaPsiImplUtil.resolveConnectorFromVariableDefinitionNode((definitionNode));
if (connectorDefinitionNode != null) {
return new ActionInvocationReference(this);
}
} else if (definitionNode instanceof EndpointDeclarationNode) {
ConnectorReferenceNode connectorReferenceNode = PsiTreeUtil.getChildOfType(definitionNode, ConnectorReferenceNode.class);
if (connectorReferenceNode != null) {
return new ActionInvocationReference(this);
}
} else if (definitionNode instanceof FunctionDefinitionNode) {
return new NameReference(this);
}
reference = checkAndSuggestReferenceAfterDot();
if (reference != null) {
return reference;
}
return new InvocationReference(this);
}
Aggregations