use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class ActionInvocationReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
IdentifierPSINode identifier = getElement();
PsiElement parent = identifier.getParent();
PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(identifier);
PsiElement resolvedElement = null;
if (prevVisibleLeaf != null && ".".equals(prevVisibleLeaf.getText())) {
PsiElement prevSibling = prevVisibleLeaf.getPrevSibling();
if (prevSibling != null) {
PsiReference reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
if (reference == null) {
return new Object[0];
}
resolvedElement = reference.resolve();
} else {
PsiElement variableReference = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
if (variableReference != null) {
PsiReference reference = variableReference.findReferenceAt(variableReference.getTextLength());
if (reference == null) {
return new Object[0];
}
resolvedElement = reference.resolve();
}
}
} else {
ConnectorReferenceNode connectorReferenceNode = PsiTreeUtil.getChildOfType(parent, ConnectorReferenceNode.class);
if (connectorReferenceNode == null) {
return new Object[0];
}
PsiReference reference = connectorReferenceNode.findReferenceAt(connectorReferenceNode.getTextLength());
if (reference == null) {
return new Object[0];
}
resolvedElement = reference.resolve();
}
if (resolvedElement == null) {
return new Object[0];
}
PsiElement connectorNode = resolvedElement.getParent();
if (connectorNode instanceof VariableDefinitionNode || connectorNode instanceof CodeBlockParameterNode) {
connectorNode = BallerinaPsiImplUtil.resolveConnectorFromVariableDefinitionNode(connectorNode);
} else if (connectorNode instanceof EndpointDeclarationNode) {
connectorNode = BallerinaPsiImplUtil.getConnectorDefinition(((EndpointDeclarationNode) connectorNode));
}
if (connectorNode == null) {
return new Object[0];
}
List<IdentifierPSINode> actions = BallerinaPsiImplUtil.getAllActionsFromAConnector(connectorNode);
List<LookupElement> results = BallerinaCompletionUtils.createActionLookupElements(actions);
return results.toArray(new LookupElement[results.size()]);
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class AnnotationAttributeReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
IdentifierPSINode identifier = getElement();
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
if (annotationAttachmentNode == null) {
return new Object[0];
}
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
return new Object[0];
}
int textLength = annotationReferenceNode.getTextLength();
PsiReference reference = annotationReferenceNode.findReferenceAt(textLength);
if (reference == null) {
return new Object[0];
}
PsiElement annotationName = reference.resolve();
if (annotationName == null || !(annotationName instanceof IdentifierPSINode)) {
return new Object[0];
}
PsiElement annotationDefinition = annotationName.getParent();
Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(annotationDefinition, FieldDefinitionNode.class);
List<LookupElement> results = BallerinaCompletionUtils.createFieldLookupElements(fieldDefinitionNodes, (IdentifierPSINode) annotationName, PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP);
return results.toArray(new LookupElement[results.size()]);
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class InvocationReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
IdentifierPSINode identifier = getElement();
PsiElement parent = identifier.getParent();
PsiElement prevSibling = parent.getPrevSibling();
if (prevSibling == null) {
return null;
}
PsiReference 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 || definitionNode instanceof ParameterNode || definitionNode instanceof GlobalVariableDefinitionNode) {
StructDefinitionNode structDefinitionNode = BallerinaPsiImplUtil.resolveStructFromDefinitionNode(definitionNode);
if (structDefinitionNode != null) {
List<IdentifierPSINode> attachedFunctions = BallerinaPsiImplUtil.getAttachedFunctions(structDefinitionNode);
for (IdentifierPSINode attachedFunction : attachedFunctions) {
if (identifier.getText().equals(attachedFunction.getText())) {
return attachedFunction;
}
}
}
}
return super.resolve();
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class InvocationReference method getStructDefinitionNode.
private StructDefinitionNode getStructDefinitionNode() {
IdentifierPSINode identifier = getElement();
PsiElement structReference = identifier.getPrevSibling();
if (".".equals(structReference.getText())) {
structReference = PsiTreeUtil.prevVisibleLeaf(structReference);
}
if (structReference == null) {
return null;
}
PsiReference reference = structReference.findReferenceAt(structReference.getTextLength());
if (reference == null) {
return null;
}
PsiElement resolvedElement = reference.resolve();
if (resolvedElement == null || !(resolvedElement instanceof IdentifierPSINode)) {
return null;
}
return BallerinaPsiImplUtil.findStructDefinition((IdentifierPSINode) resolvedElement);
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class NameReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
IdentifierPSINode identifier = getElement();
PsiElement parent = identifier.getParent();
PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(parent, PackageNameNode.class);
if (packageNameNode == null) {
return resolveInCurrentPackage();
} else {
return resolveInPackage(packageNameNode);
}
}
Aggregations