use of org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode in project ballerina by ballerina-lang.
the class AnnotationAttributeReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
IdentifierPSINode identifier = getElement();
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
if (annotationAttachmentNode == null) {
return null;
}
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
return null;
}
int textLength = annotationReferenceNode.getTextLength();
PsiReference reference = annotationReferenceNode.findReferenceAt(textLength);
if (reference == null) {
return null;
}
PsiElement annotationName = reference.resolve();
if (annotationName == null || !(annotationName instanceof IdentifierPSINode)) {
return null;
}
PsiElement annotationDefinition = annotationName.getParent();
Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(annotationDefinition, FieldDefinitionNode.class);
return BallerinaPsiImplUtil.resolveReference(fieldDefinitionNodes, identifier);
}
use of org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode in project ballerina by ballerina-lang.
the class BallerinaDocumentationProvider method getAnnotationAttributeNode.
/**
* Extract and return the {@link AnnotationAttributeValueNode} if the provided annotation matches the provided type.
*
* @param annotation annotation element
* @param annotationType annotation type
* @return {@link AnnotationAttributeValueNode} of the given element if the annotation matches the given type.
* {@code null}
* otherwise.
*/
private static AnnotationAttributeValueNode getAnnotationAttributeNode(PsiElement annotation, String annotationType) {
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.findChildOfType(annotation, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
return null;
}
PsiElement nameReferenceNodeIdentifier = annotationReferenceNode.getNameIdentifier();
if (nameReferenceNodeIdentifier == null) {
return null;
}
if (!annotationType.equals(nameReferenceNodeIdentifier.getText())) {
return null;
}
return PsiTreeUtil.findChildOfType(annotation, AnnotationAttributeValueNode.class);
}
use of org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode in project ballerina by ballerina-lang.
the class BallerinaAnnotator method canHighlightParameters.
/**
* Checks whether the query,path parameters can be highlighted in the given element.
*
* @param element element which needs to be checked
* @return {@code true} if parameters can be highlighted, {@code false} otherwise.
*/
private boolean canHighlightParameters(@NotNull PsiElement element) {
AnnotationAttributeNode annotationAttributeNode = PsiTreeUtil.getParentOfType(element, AnnotationAttributeNode.class);
if (annotationAttributeNode == null) {
return false;
}
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(annotationAttributeNode, AnnotationAttachmentNode.class);
if (annotationAttachmentNode == null) {
return false;
}
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
return false;
}
IdentifierPSINode annotationName = PsiTreeUtil.getChildOfType(annotationReferenceNode, IdentifierPSINode.class);
return annotationName != null && "resourceConfig".equals(annotationName.getText());
}
use of org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode in project ballerina by ballerina-lang.
the class BallerinaAnnotator method isMatchingParamAvailable.
private boolean isMatchingParamAvailable(@NotNull AnnotationAttributeNode annotationAttributeNode, @NotNull String value) {
ResourceDefinitionNode resourceDefinitionNode = PsiTreeUtil.getParentOfType(annotationAttributeNode, ResourceDefinitionNode.class);
if (resourceDefinitionNode == null) {
return false;
}
ParameterListNode parameterListNode = PsiTreeUtil.getChildOfType(resourceDefinitionNode, ParameterListNode.class);
if (parameterListNode == null) {
return false;
}
ParameterNode[] parameterNodes = PsiTreeUtil.getChildrenOfType(parameterListNode, ParameterNode.class);
if (parameterNodes == null) {
return false;
}
for (ParameterNode parameterNode : parameterNodes) {
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getChildOfType(parameterNode, AnnotationAttachmentNode.class);
if (annotationAttachmentNode == null) {
continue;
}
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
continue;
}
PsiElement paramType = annotationReferenceNode.getNameIdentifier();
if (paramType == null) {
continue;
}
if (!"PathParam".equals(paramType.getText())) {
continue;
}
Collection<AnnotationAttributeValueNode> annotationAttributeValueNodes = PsiTreeUtil.findChildrenOfType(annotationAttachmentNode, AnnotationAttributeValueNode.class);
for (AnnotationAttributeValueNode annotationAttributeValueNode : annotationAttributeValueNodes) {
SimpleLiteralNode simpleLiteralNode = PsiTreeUtil.getChildOfType(annotationAttributeValueNode, SimpleLiteralNode.class);
if (simpleLiteralNode == null || simpleLiteralNode.getFirstChild() == null) {
continue;
}
PsiElement firstChild = simpleLiteralNode.getFirstChild();
if (!(firstChild instanceof LeafPsiElement)) {
continue;
}
if (((LeafPsiElement) firstChild).getElementType() != BallerinaTypes.QUOTED_STRING) {
continue;
}
String text = firstChild.getText();
text = text.substring(1, text.length() - 1);
if (value.equals(text)) {
return true;
}
}
}
// does not have an annotation attachments.
for (ParameterNode parameterNode : parameterNodes) {
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getChildOfType(parameterNode, AnnotationAttachmentNode.class);
if (annotationAttachmentNode != null) {
continue;
}
PsiElement nameIdentifier = parameterNode.getNameIdentifier();
if (nameIdentifier == null) {
continue;
}
if (value.equals(nameIdentifier.getText())) {
return true;
}
}
return false;
}
use of org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode 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()]);
}
Aggregations