use of org.ballerinalang.plugins.idea.psi.ParameterNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getParameters.
/**
* Returns parameter for provided definition node.
*
* @param definitionNode
* @return
*/
@NotNull
public static List<IdentifierPSINode> getParameters(@NotNull PsiElement definitionNode) {
List<IdentifierPSINode> parameters = new LinkedList<>();
ParameterListNode parameterListNode = PsiTreeUtil.getChildOfType(definitionNode, ParameterListNode.class);
if (parameterListNode == null) {
return parameters;
}
// Get parameter nodes.
Collection<ParameterNode> parameterNodes = PsiTreeUtil.getChildrenOfTypeAsList(parameterListNode, ParameterNode.class);
for (ParameterNode parameterNode : parameterNodes) {
IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(parameterNode, IdentifierPSINode.class);
if (identifier == null) {
continue;
}
parameters.add(identifier);
}
return parameters;
}
use of org.ballerinalang.plugins.idea.psi.ParameterNode 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.ParameterNode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAnonymousStruct.
@Nullable
public static PsiElement getAnonymousStruct(@NotNull Object element, @NotNull List<PsiElement> parameterListNodes, int offset) {
int index = BallerinaParameterInfoHandler.getCurrentParameterIndex(element, offset);
PsiElement parameterListNode = parameterListNodes.get(0);
if (parameterListNode instanceof ParameterListNode) {
List<ParameterNode> parameterNodes = PsiTreeUtil.getChildrenOfTypeAsList(parameterListNode, ParameterNode.class);
if (index < 0 || index >= parameterNodes.size()) {
return null;
}
ParameterNode parameterNode = parameterNodes.get(index);
TypeNameNode typeNameNode = PsiTreeUtil.findChildOfType(parameterNode, TypeNameNode.class);
if (typeNameNode == null) {
return null;
}
PsiReference reference = typeNameNode.findReferenceAt(typeNameNode.getTextLength());
if (reference == null) {
AnonStructTypeNameNode anonStructNode = PsiTreeUtil.findChildOfType(typeNameNode, AnonStructTypeNameNode.class);
if (anonStructNode == null) {
return null;
}
return anonStructNode;
}
PsiElement resolvedElement = reference.resolve();
if (resolvedElement == null || !(resolvedElement.getParent() instanceof StructDefinitionNode)) {
return null;
}
return resolvedElement.getParent();
}
return null;
}
use of org.ballerinalang.plugins.idea.psi.ParameterNode 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.ParameterNode in project ballerina by ballerina-lang.
the class RecordKeyReference method resolve.
private PsiElement resolve(@NotNull AssignmentStatementNode assignmentStatementNode) {
IdentifierPSINode identifier = getElement();
VariableReferenceListNode variableReferenceListNode = PsiTreeUtil.getChildOfType(assignmentStatementNode, VariableReferenceListNode.class);
if (variableReferenceListNode == null) {
return null;
}
PsiElement variableReferenceNode = variableReferenceListNode.getFirstChild();
if (variableReferenceNode == null) {
return null;
}
PsiReference reference = variableReferenceNode.findReferenceAt(0);
if (reference == null) {
return null;
}
PsiElement resolvedElement = reference.resolve();
if (resolvedElement == null) {
return null;
}
PsiElement parent = resolvedElement.getParent();
if (parent instanceof VariableDefinitionNode || parent instanceof ParameterNode) {
return resolve(parent);
} else if (parent instanceof NameReferenceNode) {
StructDefinitionNode structDefinitionNode = resolveStructDefinition(identifier);
if (structDefinitionNode == null) {
return null;
}
Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(structDefinitionNode, FieldDefinitionNode.class);
for (FieldDefinitionNode fieldDefinitionNode : fieldDefinitionNodes) {
IdentifierPSINode fieldName = PsiTreeUtil.getChildOfType(fieldDefinitionNode, IdentifierPSINode.class);
if (fieldName != null && identifier.getText().equals(fieldName.getText())) {
return fieldName;
}
}
}
return null;
}
Aggregations