modules/ballerina-core/src/main/java/org/ballerinalang/model/builder/BLangModelBuilder.java
public void addFieldDefinition(NodeLocation location, SimpleTypeName typeName, String fieldName, 
            boolean defaultValueAvailable) {
        SymbolName symbolName = new SymbolName(fieldName);

        // Check whether this constant is already defined.
        StructuredUnit structScope = (StructuredUnit) currentScope;
        BLangSymbol fieldSymbol = structScope.resolveMembers(symbolName);
        if (fieldSymbol != null) {
            String errMsg = BLangExceptionHelper
                    .constructSemanticError(location, SemanticErrors.REDECLARED_SYMBOL, fieldName);
            errorMsgs.add(errMsg);
        }

        Expression defaultValExpr = null;
        if (defaultValueAvailable) {
            defaultValExpr = exprStack.pop();
        }
        
        if (currentScope instanceof StructDef) {
            VariableDef fieldDef = new VariableDef(location, fieldName, typeName, symbolName, currentScope);
            VariableRefExpr fieldRefExpr = new VariableRefExpr(location, fieldName);
            fieldRefExpr.setVariableDef(fieldDef);
            VariableDefStmt fieldDefStmt = new VariableDefStmt(location, fieldDef, fieldRefExpr, defaultValExpr);
            currentStructBuilder.addField(fieldDefStmt);
        } else if (currentScope instanceof AnnotationDef) {
            AnnotationAttributeDef annotationField = new AnnotationAttributeDef(location, fieldName, typeName, 
                (BasicLiteral) defaultValExpr, symbolName, currentScope, currentPackagePath);
            currentScope.define(symbolName, annotationField);
            annotationDefBuilder.addAttributeDef(annotationField);
        }
    }
/**
     * Add a field definition. Field definition can be a child of {@code StructDef} or {@code AnnotationDef}.
     *
     * @param location  Location of the field in the source file
     * @param fieldName Name of the field in the {@link StructDef}
     */
Add a field definition. Field definition can be a child of  StructDef or  AnnotationDef.
@param location  Location of the field in the source file
@param fieldName Name of the field in the  StructDef
Add a field definition . Field definition can be a child of StructDef or AnnotationDef . @param location Location of the field in the source file @param fieldName Name of the field in the StructDef
public void addFieldDefinition(NodeLocation location, SimpleTypeName typeName, String fieldName, 
            boolean defaultValueAvailable) {
        SymbolName symbolName = new SymbolName(fieldName);
        StructuredUnit structScope = (StructuredUnit) currentScope;
        BLangSymbol fieldSymbol = structScope.resolveMembers(symbolName);
        if (fieldSymbol != null) {
            String errMsg = BLangExceptionHelper
                    .constructSemanticError(location, SemanticErrors.REDECLARED_SYMBOL, fieldName);
            errorMsgs.add(errMsg);
        }
        Expression defaultValExpr = null;
        if (defaultValueAvailable) {
            defaultValExpr = exprStack.pop();
        }
        if (currentScope instanceof StructDef) {
            VariableDef fieldDef = new VariableDef(location, fieldName, typeName, symbolName, currentScope);
            VariableRefExpr fieldRefExpr = new VariableRefExpr(location, fieldName);
            fieldRefExpr.setVariableDef(fieldDef);
            VariableDefStmt fieldDefStmt = new VariableDefStmt(location, fieldDef, fieldRefExpr, defaultValExpr);
            currentStructBuilder.addField(fieldDefStmt);
        } else if (currentScope instanceof AnnotationDef) {
            AnnotationAttributeDef annotationField = new AnnotationAttributeDef(location, fieldName, typeName, 
                (BasicLiteral) defaultValExpr, symbolName, currentScope, currentPackagePath);
            currentScope.define(symbolName, annotationField);
            annotationDefBuilder.addAttributeDef(annotationField);
        }
    }
public void addFieldDefinition ( NodeLocation location , SimpleTypeName typeName , String fieldName , boolean defaultValueAvailable ) { SymbolName symbolName = new SymbolName ( fieldName ) ; StructuredUnit structScope = ( StructuredUnit ) currentScope ; BLangSymbol fieldSymbol = structScope . resolveMembers ( symbolName ) ; if ( fieldSymbol != null ) { String errMsg = BLangExceptionHelper . constructSemanticError ( location , SemanticErrors . REDECLARED_SYMBOL , fieldName ) ; errorMsgs . add ( errMsg ) ; } Expression defaultValExpr = null ; if ( defaultValueAvailable ) { defaultValExpr = exprStack . pop ( ) ; } if ( currentScope instanceof StructDef ) { VariableDef fieldDef = new VariableDef ( location , fieldName , typeName , symbolName , currentScope ) ; VariableRefExpr fieldRefExpr = new VariableRefExpr ( location , fieldName ) ; fieldRefExpr . setVariableDef ( fieldDef ) ; VariableDefStmt fieldDefStmt = new VariableDefStmt ( location , fieldDef , fieldRefExpr , defaultValExpr ) ; currentStructBuilder . addField ( fieldDefStmt ) ; } else if ( currentScope instanceof AnnotationDef ) { AnnotationAttributeDef annotationField = new AnnotationAttributeDef ( location , fieldName , typeName , ( BasicLiteral ) defaultValExpr , symbolName , currentScope , currentPackagePath ) ; currentScope . define ( symbolName , annotationField ) ; annotationDefBuilder . addAttributeDef ( annotationField ) ; } }
Add a field definition.
Add a field definition .
// Check whether this constant is already defined.