Skip to content

Commit

Permalink
Merge pull request ballerina-platform#41849 from nipunayf/display-worker
Browse files Browse the repository at this point in the history
[Worker Change] Add display annotation support for worker
  • Loading branch information
lochana-chathura authored Dec 11, 2023
2 parents 176f977 + ab50a0d commit 8240b05
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ public const annotation record {
"text"|"password"|"file" kind?;
} display on source type, source class,
source function, source return, source parameter, source field, source listener,
source var, source const, source annotation, source service;
source var, source const, source annotation, source service, source worker;
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@
"sortText": "P",
"insertText": "typedesc",
"insertTextFormat": "Snippet"
},
{
"label": "display",
"kind": "Property",
"detail": "Annotation",
"sortText": "B",
"insertText": "display {\n\tlabel: ${1:\"\"}\n}",
"insertTextFormat": "Snippet",
"additionalTextEdits": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@
"sortText": "P",
"insertText": "typedesc",
"insertTextFormat": "Snippet"
},
{
"label": "display",
"kind": "Property",
"detail": "Annotation",
"sortText": "B",
"insertText": "display {\n\tlabel: ${1:\"\"}\n}",
"insertTextFormat": "Snippet",
"additionalTextEdits": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@
"sortText": "P",
"insertText": "typedesc",
"insertTextFormat": "Snippet"
},
{
"label": "display",
"kind": "Property",
"detail": "Annotation",
"sortText": "B",
"insertText": "display {\n\tlabel: ${1:\"\"}\n}",
"insertTextFormat": "Snippet",
"additionalTextEdits": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@
"sortText": "P",
"insertText": "typedesc",
"insertTextFormat": "Snippet"
},
{
"label": "display",
"kind": "Property",
"detail": "Annotation",
"sortText": "B",
"insertText": "display {\n\tlabel: ${1:\"\"}\n}",
"insertTextFormat": "Snippet",
"additionalTextEdits": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.ballerinalang.model.tree.AnnotationAttachmentNode;
import org.ballerinalang.model.tree.ClassDefinition;
import org.ballerinalang.model.tree.FunctionNode;
import org.ballerinalang.model.tree.NodeKind;
import org.ballerinalang.model.tree.SimpleVariableNode;
import org.ballerinalang.model.tree.TypeDefinition;
Expand All @@ -30,13 +31,17 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment;
import org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody;
import org.wso2.ballerinalang.compiler.tree.BLangClassDefinition;
import org.wso2.ballerinalang.compiler.tree.BLangFunction;
import org.wso2.ballerinalang.compiler.tree.BLangPackage;
import org.wso2.ballerinalang.compiler.tree.BLangService;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr;
import org.wso2.ballerinalang.compiler.tree.statements.BLangSimpleVariableDef;
import org.wso2.ballerinalang.compiler.tree.statements.BLangStatement;

import java.util.List;

Expand Down Expand Up @@ -91,7 +96,7 @@ public void testDisplayAnnotOnObjectAndMemberFunction() {

@Test
public void testDisplayAnnotOnRecord() {
TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(13);
TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(14);
List<? extends AnnotationAttachmentNode> annot = typeDefinition.getAnnotationAttachments();
Assert.assertEquals(annot.size(), 1);
Assert.assertEquals(annot.get(0).getExpression().toString(),
Expand All @@ -104,6 +109,20 @@ public void testDisplayAnnotOnRecord() {
"clientSecret field,kind: <\"text\"|\"password\"|\"file\"?> password}");
}

@Test
public void testDisplayAnnotOnWorker() {
BLangBlockFunctionBody bLangBlockFunctionBody =
((BLangBlockFunctionBody) result.getAST().getFunctions().get(2).getBody());
BLangStatement bLangStatement = bLangBlockFunctionBody.getStatements().get(1);
FunctionNode workerExpression =
((BLangLambdaFunction) ((BLangSimpleVariableDef) bLangStatement).getVariable()
.getInitialExpression()).getFunctionNode();
BLangAnnotationAttachment annot =
(BLangAnnotationAttachment) workerExpression.getAnnotationAttachments().get(0);
Assert.assertEquals(getActualExpressionFromAnnotationAttachmentExpr(annot.expr).toString(),
" {label: worker annotation,type: <anydata> named,id: <anydata> hash}");
}

@Test void testDisplayAnnotationNegative() {
BAssertUtil.validateError(negative, 0, "cannot specify more than one annotation value " +
"for annotation 'ballerina/lang.annotations:0.0.0:display'", 17, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ public type RefreshTokenGrantConfig record {|
@display {iconPath: "Field.icon", label: "clientSecret field", kind: "password"}
string clientSecret;
|};

function annotationOnWorker() {
@display {
label: "worker annotation",
'type: "named",
id: "hash"
}
worker testWorker {

}
}

0 comments on commit 8240b05

Please sign in to comment.