use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = objectNode.symbol;
SymbolEnv objectEnv = SymbolEnv.createPkgLevelSymbolEnv(objectNode, objectSymbol.scope, symbolEnv);
blockOwnerStack.push(objectNode);
this.cursorPositionResolver = ObjectTypeScopeResolver.class;
objectNode.fields.forEach(field -> acceptNode(field, objectEnv));
// TODO: visit annotation and doc attachments
objectNode.functions.forEach(f -> acceptNode(f, objectEnv));
blockOwnerStack.pop();
this.cursorPositionResolver = TopLevelNodeScopeResolver.class;
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangAction actionNode) {
String actionName = actionNode.getName().getValue();
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
if (this.isWithinParameterContext(actionName, NODE_TYPE_ACTION)) {
this.populateSymbols(this.resolveAllVisibleSymbols(actionEnv), actionEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(actionNode.getPosition(), actionNode, this, this.documentServiceContext)) {
// TODO: Handle Annotation attachments
// Visit the endpoints
actionNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, actionEnv));
// Cursor position is calculated against the resource parameter scope resolver since both are similar
cursorPositionResolver = ResourceParamScopeResolver.class;
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class HoverUtil method getDocumentationContent.
/**
* Get documentation content.
*
* @param docAnnotation list of doc annotation
* @return {@link Hover} hover object.
*/
private static Hover getDocumentationContent(List<BLangDocumentation> docAnnotation) {
Hover hover = new Hover();
StringBuilder content = new StringBuilder();
BLangDocumentation bLangDocumentation = docAnnotation.get(0);
Map<String, List<BLangDocumentationAttribute>> filterAttributes = filterDocumentationAttributes(docAnnotation.get(0));
if (!bLangDocumentation.documentationText.isEmpty()) {
content.append(getFormattedHoverDocContent(ContextConstants.DESCRIPTION, bLangDocumentation.documentationText));
}
if (filterAttributes.get(ContextConstants.DOC_RECEIVER) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RECEIVER, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RECEIVER))));
}
if (filterAttributes.get(ContextConstants.DOC_PARAM) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_PARAM, getDocAttributes(filterAttributes.get(ContextConstants.DOC_PARAM))));
}
if (filterAttributes.get(ContextConstants.DOC_FIELD) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_FIELD, getDocAttributes(filterAttributes.get(ContextConstants.DOC_FIELD))));
}
if (filterAttributes.get(ContextConstants.DOC_RETURN) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RETURN, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RETURN))));
}
if (filterAttributes.get(ContextConstants.DOC_VARIABLE) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_VARIABLE, getDocAttributes(filterAttributes.get(ContextConstants.DOC_VARIABLE))));
}
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(content.toString()));
hover.setContents(contents);
return hover;
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class Generator method fieldAnnotation.
/**
* Get description annotation of the field.
* @param node parent node.
* @param param field.
* @return description of the field.
*/
private static String fieldAnnotation(BLangNode node, BLangNode param) {
String subName = "";
if (param instanceof BLangVariable) {
BLangVariable paramVariable = (BLangVariable) param;
subName = (paramVariable.getName() == null) ? paramVariable.type.tsymbol.name.value : paramVariable.getName().getValue();
} else if (param instanceof BLangEnum.Enumerator) {
BLangEnum.Enumerator paramEnumVal = (BLangEnum.Enumerator) param;
subName = paramEnumVal.getName().getValue();
}
for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
continue;
}
BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
String attribVal = bLangLiteral.toString();
if (annotation.getAnnotationName().getValue().equals("Field") && attribVal.startsWith(subName + ":")) {
return attribVal.split(subName + ":")[1].trim();
}
}
// annotation's value
for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
continue;
}
if (annotation.getAnnotationName().getValue().equals("Field")) {
BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
return bLangLiteral.toString();
}
}
return "";
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class Generator method paramAnnotation.
/**
* Get description annotation of the parameter.
* @param node parent node.
* @param param parameter.
* @return description of the parameter.
*/
private static String paramAnnotation(BLangNode node, BLangVariable param) {
String subName = param.getName() == null ? param.type.tsymbol.name.value : param.getName().getValue();
for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
continue;
}
BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
String attribVal = bLangLiteral.toString();
if ((annotation.getAnnotationName().getValue().equals("Param")) && attribVal.startsWith(subName + ":")) {
return attribVal.split(subName + ":")[1].trim();
}
}
return "";
}
Aggregations