Search in sources :

Example 16 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class Desugar method rewriteObjectToStruct.

private BLangStruct rewriteObjectToStruct(BLangObject objectNode, SymbolEnv env) {
    BLangStruct bLangStruct = (BLangStruct) TreeBuilder.createStructNode();
    bLangStruct.name = objectNode.name;
    bLangStruct.fields = objectNode.fields;
    // bLangStruct.functions = rewrite(objectNode.functions, env);
    bLangStruct.initFunction = objectNode.initFunction;
    bLangStruct.annAttachments = rewrite(objectNode.annAttachments, env);
    bLangStruct.docAttachments = rewrite(objectNode.docAttachments, env);
    bLangStruct.deprecatedAttachments = rewrite(objectNode.deprecatedAttachments, env);
    bLangStruct.isAnonymous = objectNode.isAnonymous;
    bLangStruct.symbol = objectNode.symbol;
    return bLangStruct;
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct)

Example 17 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addAnonObjectType.

public void addAnonObjectType(DiagnosticPos pos, Set<Whitespace> ws) {
    // Generate a name for the anonymous struct
    String genName = anonymousModelHelper.getNextAnonymousStructKey(pos.src.pkgID);
    IdentifierNode anonStructGenName = createIdentifier(genName);
    // Create an anonymous struct and add it to the list of structs in the current package.
    BLangStruct structNode = populateStructNode(pos, ws, anonStructGenName, true);
    this.compUnit.addTopLevelNode(structNode);
    addType(createUserDefinedType(pos, ws, (BLangIdentifier) TreeBuilder.createIdentifierNode(), structNode.name));
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 18 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class BLangPackageBuilder method endStructDef.

public void endStructDef(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicStruct) {
    BLangStruct structNode = populateStructNode(pos, ws, createIdentifier(identifier), false);
    structNode.setName(this.createIdentifier(identifier));
    if (publicStruct) {
        structNode.flagSet.add(Flag.PUBLIC);
    }
    this.compUnit.addTopLevelNode(structNode);
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct)

Example 19 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addVarToStruct.

public void addVarToStruct(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
    Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
    BLangStruct structNode = (BLangStruct) this.structStack.peek();
    structNode.addWS(wsForSemiColon);
    BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
    if (!isPrivate) {
        field.flagSet.add(Flag.PUBLIC);
    }
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 20 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class TreeVisitor method visit.

public void visit(BLangStruct structNode) {
    if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(structNode.getPosition(), structNode, this, this.documentServiceContext)) {
        BSymbol structSymbol = structNode.symbol;
        SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, symbolEnv);
        if (structNode.fields.isEmpty() && isCursorWithinBlock(structNode.getPosition(), structEnv)) {
            symbolEnv = structEnv;
            Map<Name, Scope.ScopeEntry> visibleSymbolEntries = this.resolveAllVisibleSymbols(symbolEnv);
            this.populateSymbols(visibleSymbolEntries, null);
            this.setTerminateVisitor(true);
        } else if (!structNode.fields.isEmpty()) {
            // Since the struct definition do not have a block statement within, we push null
            this.blockStmtStack.push(null);
            this.blockOwnerStack.push(structNode);
            // Cursor position is calculated against the Block statement scope resolver
            this.cursorPositionResolver = BlockStatementScopeResolver.class;
            structNode.fields.forEach(field -> acceptNode(field, structEnv));
            this.blockStmtStack.pop();
            this.blockOwnerStack.pop();
        }
    }
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) Arrays(java.util.Arrays) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) TokenStream(org.antlr.v4.runtime.TokenStream) Token(org.antlr.v4.runtime.Token) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) LSNodeVisitor(org.ballerinalang.langserver.common.LSNodeVisitor) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) Map(java.util.Map) ServiceScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ServiceScopeResolver) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) SymbolResolver(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) Names(org.wso2.ballerinalang.compiler.util.Names) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) ConnectorScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ConnectorScopeResolver) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) ScopeResolverConstants(org.ballerinalang.langserver.completions.util.ScopeResolverConstants) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ObjectTypeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ObjectTypeScopeResolver) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) List(java.util.List) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) ResourceParamScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ResourceParamScopeResolver) BlockStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.BlockStatementScopeResolver) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangBind(org.wso2.ballerinalang.compiler.tree.statements.BLangBind) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) PackageNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.PackageNodeScopeResolver) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) HashMap(java.util.HashMap) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) Position(org.eclipse.lsp4j.Position) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode) MatchStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.MatchStatementScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) TopLevelNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.TopLevelNodeScopeResolver) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) Node(org.ballerinalang.model.tree.Node) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BlockStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.BlockStatementScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)11 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)10 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)7 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 List (java.util.List)6 CompileResult (org.ballerinalang.launcher.util.CompileResult)6 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)6 PackageNode (org.ballerinalang.model.tree.PackageNode)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5