use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class CodeGenerator method createPackageVarInfo.
// Create info entries
private void createPackageVarInfo(BLangVariable varNode) {
BVarSymbol varSymbol = varNode.symbol;
varSymbol.varIndex = getPVIndex(varSymbol.type.tag);
int varNameCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.name.value);
int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.type.getDesc());
PackageVarInfo pkgVarInfo = new PackageVarInfo(varNameCPIndex, typeSigCPIndex, varSymbol.flags, varSymbol.varIndex.value);
currentPkgInfo.pkgVarInfoMap.put(varSymbol.name.value, pkgVarInfo);
LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
LocalVariableAttributeInfo pkgVarAttrInfo = (LocalVariableAttributeInfo) currentPkgInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
pkgVarAttrInfo.localVars.add(localVarInfo);
// TODO Populate annotation attribute
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class AnnotationDesugar method initAnnotation.
private void initAnnotation(BLangAnnotationAttachment attachment, BLangVariable annotationMapEntryVar, BLangBlockStmt target, BSymbol parentSymbol, int index) {
BLangVariable annotationVar = null;
if (attachment.annotationSymbol.attachedType != null) {
// create: AttachedType annotationVar = { annotation-expression }
annotationVar = ASTBuilderUtil.createVariable(attachment.pos, attachment.annotationName.value, attachment.annotationSymbol.attachedType.type);
annotationVar.expr = attachment.expr;
ASTBuilderUtil.defineVariable(annotationVar, parentSymbol, names);
ASTBuilderUtil.createVariableDefStmt(attachment.pos, target).var = annotationVar;
}
// create: annotationMapEntryVar["name$index"] = annotationVar;
BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
if (annotationVar != null) {
assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationVar.symbol);
} else {
assignmentStmt.expr = ASTBuilderUtil.createLiteral(target.pos, symTable.nullType, null);
}
BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = target.pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, attachment.annotationSymbol.bvmAlias() + "$" + index);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapEntryVar.symbol);
indexAccessNode.type = annotationMapEntryVar.symbol.type;
assignmentStmt.varRefs.add(indexAccessNode);
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangResource resourceNode) {
String resourceName = resourceNode.getName().getValue();
BSymbol resourceSymbol = resourceNode.symbol;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, symbolEnv);
if (isWithinParameterContext(resourceName, NODE_TYPE_RESOURCE)) {
this.populateSymbols(this.resolveAllVisibleSymbols(resourceEnv), resourceEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(resourceNode.getPosition(), resourceNode, this, this.documentServiceContext)) {
// TODO:Handle Annotation attachments
// Visit the endpoints
resourceNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, resourceEnv));
// Cursor position is calculated against the resource parameter scope resolver
cursorPositionResolver = ResourceParamScopeResolver.class;
resourceNode.workers.forEach(w -> this.acceptNode(w, resourceEnv));
this.blockOwnerStack.push(resourceNode);
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
acceptNode(resourceNode.body, resourceEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class Generator method createDocForNode.
/**
* Create documentation for annotations.
* @param annotationNode ballerina annotation node.
* @return documentation for annotation.
*/
public static AnnotationDoc createDocForNode(BLangAnnotation annotationNode) {
String annotationName = annotationNode.getName().getValue();
List<Variable> attributes = new ArrayList<>();
// Iterate through the attributes of the annotation
if (annotationNode.getAttributes().size() > 0) {
for (BLangAnnotAttribute annotAttribute : annotationNode.getAttributes()) {
String dataType = getTypeName(annotAttribute.getTypeNode());
String desc = annotFieldAnnotation(annotationNode, annotAttribute);
Variable variable = new Variable(annotAttribute.getName().value, dataType, desc);
attributes.add(variable);
}
}
return new AnnotationDoc(annotationName, description(annotationNode), new ArrayList<>(), attributes);
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class HtmlDocTest method testPrivateConstructsInPackage.
@Test(description = "Private constructs should not appear at all.")
public void testPrivateConstructsInPackage() {
BLangPackage bLangPackage = createPackage("package x.y; " + "function hello(){}" + "enum Direction { IN,OUT}" + "enum Money { USD,LKR}" + "annotation ParameterInfo;" + "annotation ReturnInfo;" + "int total = 98;" + "string content = \"Name\";" + "struct Message {}" + "struct Response {}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 0);
}
Aggregations