use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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.BLangStruct in project ballerina by ballerina-lang.
the class CommandUtil method getStructDocumentationByPosition.
/**
* Get the Documentation attachment for the struct definition.
* @param bLangPackage BLangPackage built
* @param line Start line of the struct in the source
* @return {@link String} Documentation attachment for the struct
*/
static DocAttachmentInfo getStructDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangStruct) {
BLangStruct structNode = (BLangStruct) topLevelNode;
DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(structNode.getPosition());
int structStart = structPos.getStartLine();
if (structStart == line) {
return getStructNodeDocumentation(structNode, line);
}
}
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.
the class CommandUtil method getStructNodeDocumentation.
static DocAttachmentInfo getStructNodeDocumentation(BLangStruct bLangStruct, int replaceFrom) {
List<String> attributes = new ArrayList<>();
DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(bLangStruct.getPosition());
int offset = structPos.getStartColumn();
bLangStruct.getFields().forEach(bLangVariable -> attributes.add(getDocAttributeFromBLangVariable(bLangVariable, offset)));
return new DocAttachmentInfo(getDocumentationAttachment(attributes, structPos.getStartColumn()), replaceFrom);
}
use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.
the class SymbolEnter method createReceiver.
private BLangVariable createReceiver(BLangStruct struct) {
BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
receiver.pos = struct.pos;
IdentifierNode name = createIdentifier(Names.SELF.getValue());
receiver.setName(name);
receiver.docTag = DocTag.RECEIVER;
BLangUserDefinedType structTypeNode = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
structTypeNode.pkgAlias = new BLangIdentifier();
structTypeNode.typeName = struct.name;
receiver.setTypeNode(structTypeNode);
return receiver;
}
use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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));
}
Aggregations