use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint 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.tree.BLangAnnotationAttachmentPoint in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangStruct structNode) {
BSymbol structSymbol = structNode.symbol;
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
structNode.fields.forEach(field -> analyzeDef(field, structEnv));
structNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
annotationAttachment.accept(this);
});
analyzeDef(structNode.initFunction, structEnv);
structNode.docAttachments.forEach(doc -> analyzeDef(doc, structEnv));
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangEndpoint endpointNode) {
endpointNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
this.analyzeDef(annotationAttachment, env);
});
if (endpointNode.configurationExpr == null) {
return;
}
BType configType = symTable.errType;
if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Init expression.
configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
} else {
// assign Expression.
configType = endpointNode.symbol.type;
}
}
this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangTransformer transformerNode) {
SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
transformerNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.TRANSFORMER);
this.analyzeDef(annotationAttachment, transformerEnv);
});
transformerNode.docAttachments.forEach(doc -> analyzeDef(doc, transformerEnv));
validateTransformerMappingType(transformerNode.source);
validateTransformerMappingType(transformerNode.retParams.get(0));
analyzeStmt(transformerNode.body, transformerEnv);
// TODO: update this accordingly once the unsafe conversion are supported
int returnCount = transformerNode.retParams.size();
if (returnCount == 0) {
dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_MUST_HAVE_OUTPUT);
} else if (returnCount > 1) {
dlog.error(transformerNode.pos, DiagnosticCode.TOO_MANY_OUTPUTS_FOR_TRANSFORMER, 1, returnCount);
}
this.processWorkers(transformerNode, transformerEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangConnector connectorNode) {
BSymbol connectorSymbol = connectorNode.symbol;
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
connectorNode.annAttachments.forEach(a -> {
a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONNECTOR);
this.analyzeDef(a, connectorEnv);
});
connectorNode.docAttachments.forEach(doc -> analyzeDef(doc, connectorEnv));
connectorNode.params.forEach(param -> this.analyzeDef(param, connectorEnv));
connectorNode.varDefs.forEach(varDef -> this.analyzeDef(varDef, connectorEnv));
connectorNode.endpoints.forEach(e -> analyzeDef(e, connectorEnv));
this.analyzeDef(connectorNode.initFunction, connectorEnv);
connectorNode.actions.forEach(action -> this.analyzeDef(action, connectorEnv));
this.analyzeDef(connectorNode.initAction, connectorEnv);
}
Aggregations