use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class ParserUtils method createNewParameter.
/**
* Create new parameter.
*
* @param name parameter name
* @param type parameter type
* @return {Parameter} parameter
*/
private static Parameter createNewParameter(String name, String type, BLangType typeNode) {
Parameter parameter = new Parameter();
parameter.setType(type);
parameter.setName(name);
BType bType = typeNode.type;
if (bType instanceof BConnectorType) {
parameter.setPkgAlias(((BLangUserDefinedType) typeNode).pkgAlias.toString());
parameter.setConnector(true);
}
return parameter;
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType 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.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class SymbolResolver method visit.
public void visit(BLangUserDefinedType userDefinedTypeNode) {
// 1) Resolve the package scope using the package alias.
// If the package alias is not empty or null, then find the package scope,
// if not use the current package scope.
// 2) lookup the typename in the package scope returned from step 1.
// 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error'
BSymbol pkgSymbol = resolvePkgSymbol(userDefinedTypeNode.pos, this.env, names.fromIdNode(userDefinedTypeNode.pkgAlias));
if (pkgSymbol == symTable.notFoundSymbol) {
resultType = symTable.errType;
return;
}
Name typeName = names.fromIdNode(userDefinedTypeNode.typeName);
BSymbol symbol = symTable.notFoundSymbol;
// Only valued types and ANNOTATION type allowed.
if (env.scope.owner.tag == SymTag.ANNOTATION) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.ANNOTATION);
}
// 3) Lookup the current package scope.
if (symbol == symTable.notFoundSymbol) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
// 4) Lookup the root scope for types such as 'error'
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, symTable.rootScope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
dlog.error(userDefinedTypeNode.pos, diagCode, typeName);
resultType = symTable.errType;
return;
}
if (symbol.kind == SymbolKind.CONNECTOR) {
userDefinedTypeNode.flagSet = EnumSet.of(Flag.CONNECTOR);
}
resultType = symbol.type;
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addEndpointDefinition.
public void addEndpointDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean initExprExist) {
final BLangEndpoint endpointNode = (BLangEndpoint) TreeBuilder.createEndpointNode();
attachAnnotations(endpointNode);
endpointNode.pos = pos;
endpointNode.name = (BLangIdentifier) this.createIdentifier(identifier);
endpointNode.endpointTypeNode = (BLangUserDefinedType) typeNodeStack.pop();
if (initExprExist) {
endpointNode.configurationExpr = (BLangExpression) this.exprNodeStack.pop();
}
endpointNode.addWS(ws);
if (endpointListStack.empty()) {
// Top level node.
lastBuiltEndpoint = endpointNode;
this.compUnit.addTopLevelNode(endpointNode);
} else {
endpointListStack.peek().add(endpointNode);
}
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createUserDefinedType.
private BLangUserDefinedType createUserDefinedType(DiagnosticPos pos, Set<Whitespace> ws, BLangIdentifier pkgAlias, BLangIdentifier name) {
BLangUserDefinedType userDefinedType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
userDefinedType.pos = pos;
userDefinedType.addWS(ws);
userDefinedType.pkgAlias = pkgAlias;
userDefinedType.typeName = name;
return userDefinedType;
}
Aggregations