use of org.ballerinalang.plugins.idea.psi.references.EnumFieldReference in project ballerina by ballerina-lang.
the class IdentifierPSINode method checkAndSuggestReferenceAfterDot.
@Nullable
private PsiReference checkAndSuggestReferenceAfterDot() {
PsiReference reference = null;
PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(getParent());
if (prevVisibleLeaf != null) {
if (".".equals(prevVisibleLeaf.getText())) {
PsiElement prevSibling = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
if (prevSibling != null) {
reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
}
} else {
reference = prevVisibleLeaf.findReferenceAt(prevVisibleLeaf.getTextLength());
}
}
if (reference == null) {
PsiElement prevSibling = getParent().getPrevSibling();
if (prevSibling == null) {
return null;
}
InvocationNode invocationNode = PsiTreeUtil.getChildOfType(prevSibling, InvocationNode.class);
if (invocationNode == null) {
return null;
}
AnyIdentifierNameNode anyIdentifierNameNode = PsiTreeUtil.getChildOfType(invocationNode, AnyIdentifierNameNode.class);
if (anyIdentifierNameNode == null) {
return null;
}
IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(anyIdentifierNameNode, IdentifierPSINode.class);
if (identifier == null) {
return null;
}
reference = identifier.findReferenceAt(identifier.getTextLength());
}
if (reference == null) {
return null;
}
PsiElement resolvedElement = reference.resolve();
if (resolvedElement == null) {
return null;
}
// Get the return type of the function definition.
PsiElement parent = resolvedElement.getParent();
if (parent instanceof FunctionDefinitionNode) {
List<TypeNameNode> returnTypes = BallerinaPsiImplUtil.getReturnTypes(parent);
if (returnTypes.size() == 1) {
return new TypeReference(this, returnTypes.get(0));
}
}
if (resolvedElement.getParent() instanceof EndpointDeclarationNode) {
return new ActionInvocationReference(this);
}
if (resolvedElement.getParent() instanceof EnumDefinitionNode) {
return new EnumFieldReference(this);
}
PsiElement type = BallerinaPsiImplUtil.getType(((IdentifierPSINode) resolvedElement));
if (type == null || (!(type instanceof BuiltInReferenceTypeNameNode) && !(type instanceof ReferenceTypeNameNode) && !(type instanceof ValueTypeNameNode))) {
return null;
}
return new TypeReference(this, type);
}
Aggregations