use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addTypeInitExpression.
public void addTypeInitExpression(DiagnosticPos pos, Set<Whitespace> ws, String initName, boolean typeAvailable, boolean exprAvailable) {
BLangTypeInit objectInitNode = (BLangTypeInit) TreeBuilder.createObjectInitNode();
objectInitNode.pos = pos;
objectInitNode.addWS(ws);
if (typeAvailable) {
objectInitNode.userDefinedType = (BLangUserDefinedType) typeNodeStack.pop();
}
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
invocationNode.pos = pos;
invocationNode.addWS(ws);
if (exprAvailable) {
List<ExpressionNode> exprNodes = exprNodeListStack.pop();
Set<Whitespace> cws = commaWsStack.pop();
exprNodes.forEach(exprNode -> {
invocationNode.argExprs.add((BLangExpression) exprNode);
objectInitNode.argsExpr.add((BLangExpression) exprNode);
});
invocationNode.addWS(cws);
objectInitNode.addWS(cws);
}
// TODO check whether pkgName can be be empty
IdentifierNode pkgNameNode = TreeBuilder.createIdentifierNode();
IdentifierNode nameNode = createIdentifier(initName);
BLangNameReference nameReference = new BLangNameReference(pos, ws, pkgNameNode, nameNode);
invocationNode.name = (BLangIdentifier) nameReference.name;
invocationNode.addWS(nameReference.ws);
invocationNode.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
objectInitNode.objectInitInvocation = invocationNode;
this.addExpressionNode(objectInitNode);
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class Generator method generatePageForPrimitives.
/**
* Generate the page for primitive types.
* @param balPackage The ballerina.builtin package.
* @param packages List of available packages.
* @return A page model for the primitive types.
*/
public static Page generatePageForPrimitives(BLangPackage balPackage, List<Link> packages) {
ArrayList<Documentable> primitiveTypes = new ArrayList<>();
// Check for functions in the package
if (balPackage.getFunctions().size() > 0) {
for (BLangFunction function : balPackage.getFunctions()) {
if (function.getFlags().contains(Flag.PUBLIC) && function.getReceiver() != null) {
TypeNode langType = function.getReceiver().getTypeNode();
if (!(langType instanceof BLangUserDefinedType)) {
// Check for primitives in ballerina.builtin
Optional<PrimitiveTypeDoc> existingPrimitiveType = primitiveTypes.stream().filter((doc) -> doc instanceof PrimitiveTypeDoc && (((PrimitiveTypeDoc) doc)).name.equals(langType.toString())).map(doc -> (PrimitiveTypeDoc) doc).findFirst();
PrimitiveTypeDoc primitiveTypeDoc;
if (existingPrimitiveType.isPresent()) {
primitiveTypeDoc = existingPrimitiveType.get();
} else {
primitiveTypeDoc = new PrimitiveTypeDoc(langType.toString(), new ArrayList<>());
primitiveTypes.add(primitiveTypeDoc);
}
primitiveTypeDoc.children.add(createDocForNode(function));
}
}
}
}
// Create the links to select which page or package is active
List<Link> links = new ArrayList<>();
for (Link pkgLink : packages) {
if (BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_NAME.equals(pkgLink.caption.value)) {
links.add(new Link(pkgLink.caption, pkgLink.href, true));
} else {
links.add(new Link(pkgLink.caption, pkgLink.href, false));
}
}
StaticCaption primitivesPageHeading = new StaticCaption(BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_NAME);
return new Page(primitivesPageHeading, primitiveTypes, links);
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class Generator method generatePage.
/**
* Generate the page when the bal package is passed.
* @param balPackage The current package that is being viewed.
* @param packages List of available packages.
* @return A page model for the current package.
*/
public static Page generatePage(BLangPackage balPackage, List<Link> packages) {
ArrayList<Documentable> documentables = new ArrayList<>();
String currentPackageName = (balPackage.symbol).pkgID.name.value;
// Check for structs in the package
if (balPackage.getStructs().size() > 0) {
for (BLangStruct struct : balPackage.getStructs()) {
if (struct.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(struct));
}
}
}
// Check for functions in the package
if (balPackage.getFunctions().size() > 0) {
for (BLangFunction function : balPackage.getFunctions()) {
if (function.getFlags().contains(Flag.PUBLIC)) {
if (function.getReceiver() != null) {
if (documentables.size() > 0) {
for (Documentable parentDocumentable : documentables) {
TypeNode langType = function.getReceiver().getTypeNode();
String typeName = (langType instanceof BLangUserDefinedType ? ((BLangUserDefinedType) langType).typeName.value : langType.toString());
if (typeName.equals(parentDocumentable.name)) {
parentDocumentable.children.add(createDocForNode(function));
}
}
}
} else {
// If there's no receiver type i.e. no struct binding to the function
documentables.add(createDocForNode(function));
}
}
}
}
// Check for connectors in the package
for (BLangConnector connector : balPackage.getConnectors()) {
if (connector.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(connector));
}
}
// Check for connectors in the package
for (EnumNode enumNode : balPackage.getEnums()) {
if (enumNode.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(enumNode));
}
}
// Check for annotations
for (BLangAnnotation annotation : balPackage.getAnnotations()) {
if (annotation.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(annotation));
}
}
// Check for global variables
for (BLangVariable var : balPackage.getGlobalVariables()) {
if (var.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(var));
}
}
// Create the links to select which page or package is active
List<Link> links = new ArrayList<>();
PackageName packageNameHeading = null;
for (Link pkgLink : packages) {
if (pkgLink.caption.value.equals(currentPackageName)) {
packageNameHeading = (PackageName) pkgLink.caption;
links.add(new Link(pkgLink.caption, pkgLink.href, true));
} else {
links.add(new Link(pkgLink.caption, pkgLink.href, false));
}
}
return new Page(packageNameHeading, documentables, links);
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class ParameterContextHolder method buildContext.
/**
* Build a readable parameter model from a Ballerina <code>VariableNode</code>.
*
* @param parameter {@code VariableNode} with parameter definition
* @return built Parameter context model
*/
public static ParameterContextHolder buildContext(VariableNode parameter) {
ParameterContextHolder context = new ParameterContextHolder();
TypeNode type = parameter.getTypeNode();
if (type instanceof BLangValueType) {
context.type = ((BLangValueType) parameter.getTypeNode()).getTypeKind().typeName();
} else if (type instanceof BLangUserDefinedType) {
context.type = ((BLangUserDefinedType) parameter.getTypeNode()).getTypeName().getValue();
}
// Ignore Connection and InRequest parameters
if (context.isIgnoredType(context.type)) {
return null;
}
context.name = parameter.getName().toString();
context.defaultValue = context.getDefaultValue(context.type, context.name);
// examples are not yet supported
context.example = "";
return context;
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class PositionTreeVisitor method visit.
@Override
public void visit(BLangUserDefinedType userDefinedType) {
userDefinedType.getPosition().sCol += (previousNode instanceof BLangEndpointTypeNode ? "endpoint<".length() : 0);
CommonUtil.calculateEndColumnOfGivenName(userDefinedType.getPosition(), userDefinedType.typeName.value, userDefinedType.pkgAlias.value);
if (userDefinedType.type instanceof BUnionType && HoverUtil.isMatchingPosition(userDefinedType.getPosition(), this.position)) {
try {
BUnionType bUnionType = (BUnionType) userDefinedType.type;
for (BType type : bUnionType.memberTypes) {
if (type.tsymbol != null && type.tsymbol.getName().getValue().equals(userDefinedType.typeName.getValue())) {
this.context.put(NodeContextKeys.NODE_KEY, userDefinedType);
this.context.put(NodeContextKeys.PREVIOUSLY_VISITED_NODE_KEY, this.previousNode);
this.context.put(NodeContextKeys.NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
this.context.put(NodeContextKeys.PACKAGE_OF_NODE_KEY, type.tsymbol.pkgID);
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_PARENT_KEY, type.tsymbol.kind.name());
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_KEY, type.tsymbol.kind.name());
this.context.put(NodeContextKeys.NODE_OWNER_KEY, type.tsymbol.owner.name.getValue());
this.context.put(NodeContextKeys.NODE_OWNER_PACKAGE_KEY, type.tsymbol.owner.pkgID);
this.context.put(NodeContextKeys.VAR_NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
setTerminateVisitor(true);
break;
}
}
} catch (ClassCastException e) {
// Ignores
}
} else if (userDefinedType.type.tsymbol != null && HoverUtil.isMatchingPosition(userDefinedType.getPosition(), this.position)) {
this.context.put(NodeContextKeys.NODE_KEY, userDefinedType);
this.context.put(NodeContextKeys.PREVIOUSLY_VISITED_NODE_KEY, this.previousNode);
this.context.put(NodeContextKeys.NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
this.context.put(NodeContextKeys.PACKAGE_OF_NODE_KEY, userDefinedType.type.tsymbol.pkgID);
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_PARENT_KEY, userDefinedType.type.tsymbol.kind.name());
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_KEY, userDefinedType.type.tsymbol.kind.name());
this.context.put(NodeContextKeys.NODE_OWNER_KEY, userDefinedType.type.tsymbol.owner.name.getValue());
this.context.put(NodeContextKeys.NODE_OWNER_PACKAGE_KEY, userDefinedType.type.tsymbol.owner.pkgID);
this.context.put(NodeContextKeys.VAR_NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
setTerminateVisitor(true);
}
}
Aggregations