use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class CommandExecutor method getDocumentEditForNode.
/**
* Get the document edit attachment info for a given particular node.
* @param node Node given
* @return Doc Attachment Info
*/
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
int replaceFrom;
switch(node.getKind()) {
case FUNCTION:
if (((BLangFunction) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
}
break;
case STRUCT:
if (((BLangStruct) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
}
break;
case ENUM:
if (((BLangEnum) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
}
break;
case TRANSFORMER:
if (((BLangTransformer) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
}
break;
case RESOURCE:
if (((BLangResource) node).docAttachments.isEmpty()) {
BLangResource bLangResource = (BLangResource) node;
replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
}
break;
case SERVICE:
if (((BLangService) node).docAttachments.isEmpty()) {
BLangService bLangService = (BLangService) node;
replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
}
break;
default:
break;
}
return docAttachmentInfo;
}
use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangTransformer transformerNode) {
validateTransformerMappingTypes(transformerNode);
boolean safeConversion = transformerNode.retParams.size() == 1;
Name name = getTransformerSymbolName(transformerNode);
BTransformerSymbol transformerSymbol = Symbols.createTransformerSymbol(Flags.asMask(transformerNode.flagSet), name, env.enclPkg.symbol.pkgID, null, safeConversion, env.scope.owner);
transformerNode.symbol = transformerSymbol;
// If this is a default transformer, check whether this transformer conflicts with a built-in conversion
if (transformerNode.name.value.isEmpty()) {
BType targetType = transformerNode.retParams.get(0).type;
BSymbol symbol = symResolver.resolveConversionOperator(transformerNode.source.type, targetType);
if (symbol != symTable.notFoundSymbol) {
dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_CONFLICTS_WITH_CONVERSION, transformerNode.source.type, targetType);
return;
}
}
// Define the transformer
SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerSymbol.scope, env);
transformerNode.symbol = transformerSymbol;
defineSymbol(transformerNode.pos, transformerSymbol);
transformerEnv.scope = transformerSymbol.scope;
// Define transformer source.
defineNode(transformerNode.source, transformerEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangTransformer transformerNode) {
SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
visitInvokable(transformerNode, transformerEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangTransformer 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.BLangTransformer in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangTransformer transformerNode) {
SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, this.env);
currentCallableUnitInfo = currentPkgInfo.transformerInfoMap.get(transformerNode.symbol.name.value);
visitInvokableNode(transformerNode, currentCallableUnitInfo, transformerEnv);
}
Aggregations