use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.
the class CompilerPluginRunner method getAnnotationSymbols.
private List<BAnnotationSymbol> getAnnotationSymbols(String annPackage) {
List<BAnnotationSymbol> annotationSymbols = new ArrayList<>();
BLangPackage pkgNode = this.packageCache.get(annPackage);
if (pkgNode == null) {
return annotationSymbols;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
if (pkgEnv != null) {
for (BLangAnnotation annotationNode : pkgEnv.enclPkg.annotations) {
annotationSymbols.add((BAnnotationSymbol) annotationNode.symbol);
}
}
return annotationSymbols;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangAnnotationAttachment annAttachmentNode) {
BSymbol symbol = this.symResolver.resolveAnnotation(annAttachmentNode.pos, env, names.fromString(annAttachmentNode.pkgAlias.getValue()), names.fromString(annAttachmentNode.getAnnotationName().getValue()));
if (symbol == this.symTable.notFoundSymbol) {
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.UNDEFINED_ANNOTATION, annAttachmentNode.getAnnotationName().getValue());
return;
}
// Validate Attachment Point against the Annotation Definition.
BAnnotationSymbol annotationSymbol = (BAnnotationSymbol) symbol;
annAttachmentNode.annotationSymbol = annotationSymbol;
if (annotationSymbol.getAttachmentPoints() != null && annotationSymbol.getAttachmentPoints().size() > 0) {
BLangAnnotationAttachmentPoint[] attachmentPointsArrray = new BLangAnnotationAttachmentPoint[annotationSymbol.getAttachmentPoints().size()];
Optional<BLangAnnotationAttachmentPoint> matchingAttachmentPoint = Arrays.stream(annotationSymbol.getAttachmentPoints().toArray(attachmentPointsArrray)).filter(attachmentPoint -> attachmentPoint.equals(annAttachmentNode.attachmentPoint)).findAny();
if (!matchingAttachmentPoint.isPresent()) {
String msg = annAttachmentNode.attachmentPoint.getAttachmentPoint().getValue();
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.ANNOTATION_NOT_ALLOWED, annotationSymbol, msg);
}
}
// Validate Annotation Attachment data struct against Annotation Definition struct.
validateAnnotationAttachmentExpr(annAttachmentNode, annotationSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
public void visit(BLangAnnotAttribute annotationAttribute) {
BAnnotationAttributeSymbol annotationAttributeSymbol = Symbols.createAnnotationAttributeSymbol(names.fromIdNode(annotationAttribute.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
annotationAttributeSymbol.docTag = DocTag.FIELD;
annotationAttributeSymbol.expr = annotationAttribute.expr;
annotationAttribute.symbol = annotationAttributeSymbol;
((BAnnotationSymbol) env.scope.owner).attributes.add(annotationAttributeSymbol);
defineSymbol(annotationAttribute.pos, annotationAttributeSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
public void visit(BLangAnnotation annotationNode) {
BSymbol annotationSymbol = Symbols.createAnnotationSymbol(Flags.asMask(annotationNode.flagSet), names.fromIdNode(annotationNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
annotationSymbol.type = new BAnnotationType((BAnnotationSymbol) annotationSymbol);
annotationNode.attachmentPoints.forEach(point -> ((BAnnotationSymbol) annotationSymbol).attachmentPoints.add(point));
annotationNode.symbol = annotationSymbol;
defineSymbol(annotationNode.pos, annotationSymbol);
SymbolEnv annotationEnv = SymbolEnv.createAnnotationEnv(annotationNode, annotationSymbol.scope, env);
annotationNode.attributes.forEach(att -> this.defineNode(att, annotationEnv));
if (annotationNode.typeNode != null) {
BType structType = this.symResolver.resolveTypeNode(annotationNode.typeNode, annotationEnv);
((BAnnotationSymbol) annotationSymbol).attachedType = structType.tsymbol;
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.
the class CompilerPluginRunner method handleAnnotationProcesses.
private void handleAnnotationProcesses(CompilerPlugin plugin) {
// Get the list of packages of annotations that this particular compiler plugin is interested in.
SupportedAnnotationPackages supportedAnnotationPackages = plugin.getClass().getAnnotation(SupportedAnnotationPackages.class);
if (supportedAnnotationPackages == null) {
return;
}
String[] annotationPkgs = supportedAnnotationPackages.value();
if (annotationPkgs.length == 0) {
return;
}
for (String annPackage : annotationPkgs) {
// Check whether each annotation type definition is available in the AST.
List<BAnnotationSymbol> annotationSymbols = getAnnotationSymbols(annPackage);
annotationSymbols.forEach(annSymbol -> {
DefinitionID definitionID = new DefinitionID(annSymbol.pkgID.name.value, annSymbol.name.value);
List<CompilerPlugin> processorList = processorMap.computeIfAbsent(definitionID, k -> new ArrayList<>());
processorList.add(plugin);
});
}
}
Aggregations