system/src/sc/lang/java/TransformUtil.java
public static void convertFieldToGetSetMethods(VariableDefinition variableDefinition, boolean bindable, boolean toInterface, ILanguageModel.RuntimeType runtime) {
      String convertedPropName = variableDefinition.getRealVariableName();
      String origPropName = variableDefinition.variableName;

      PropertyDefinitionParameters params = PropertyDefinitionParameters.create(convertedPropName);
      Definition enclDef = variableDefinition.getDefinition();
      FieldDefinition field = (FieldDefinition) enclDef;
      TypeDeclaration typeDeclaration = field.getEnclosingType();


      LayeredSystem sys = typeDeclaration.getLayeredSystem();

      initImportTypeNames(sys, params, typeDeclaration);

      // Skipping interfaces here.  We want to only find implementation methods that we have to rename or contend with if we are converting a field and there are already get/set methods in the same type.
      // This is like the "makeBindable" case but we use declares not defines cause we only want to modify get/set methods if they are defined in this same type.  In the makeBindable case we are really
      // remapping the existing property.   For the field case, the code is declaring a new property that should hide the base classes property based on Java's rules.  If however they define a field and get/set methods
      // in the same type, we need to remap them.  This layers on binding on top of the existing get/set methods.
      // TODO: as an optimization we should recognize trivial get/set methods and just insert the sendEvent call instead of adding all of that code.
      params.getMethod = typeDeclaration.declaresMember(origPropName, JavaSemanticNode.MemberType.GetMethodSet, null, null);
      params.setMethod = typeDeclaration.declaresMember(origPropName, JavaSemanticNode.MemberType.SetMethodSet, null, null);

      params.arrayDimensions = field.type.arrayDimensions;

      if (typeDeclaration.propertiesToMakeBindable != null && typeDeclaration.propertiesToMakeBindable.get(origPropName) != null) {
         Object getMethod = typeDeclaration.definesMember(origPropName, JavaSemanticNode.MemberType.GetMethodSet, null, null);
         Object setMethod = typeDeclaration.definesMember(origPropName, JavaSemanticNode.MemberType.SetMethodSet, null, null);
         // If we are overriding an abstract implementation, continue to convert the field to a getX/setX to implement the interface or abstract methods
         if ((getMethod == null || !ModelUtil.isAbstractMethod(getMethod)) && (setMethod == null || !ModelUtil.isAbstractMethod(setMethod))) {
            return;
         }
      }

      // TODO: Right now we cannot do static bindable properties on interfaces.  Not sure how that will work
      if (toInterface && params.isStatic) {
         System.err.println("*** can't make static interface properties bindable");
         return;
      }

      params.sendEvent = !ModelUtil.isManualBindable(variableDefinition);
      setPropertyMappingName(params, typeDeclaration);

      int ix = typeDeclaration.body.indexOf(field);

      params.propertyTypeName = field.type.getGenericTypeName(typeDeclaration, false);
      params.overrideField = false;
      params.omitField = false; // Always generate the field here since we replace this one with the generated get/set call

      if (params.sendEvent) {
         Object sameValueCheckObj = ModelUtil.getAnnotationValue(field, BINDABLE_ANNOTATION, "sameValueCheck");
         if (sameValueCheckObj != null)
            params.sameValueCheck = (Boolean) sameValueCheckObj;
         else
            params.sameValueCheck = false;
      }
      /*
      Object lazyObj = ModelUtil.getAnnotationValue(field, BINDABLE_ANNOTATION, "lazy");
      if (lazyObj != null)
         params.lazy = (Boolean) lazyObj;
      else
         params.lazy = false;
      */

      if (variableDefinition.initializer == null)
         params.initializer = "";
      else {
         Expression varInit;
         if (variableDefinition.initializer instanceof ArrayInitializer) {
            if (params.arrayDimensions != null)
               varInit = convertToNewExpression(field.type.getFullBaseTypeName(), (ArrayInitializer)variableDefinition.initializer, params.arrayDimensions);
            else {
               Object fieldVarType = field.type.getTypeDeclaration();
               if (ModelUtil.isAssignableFrom(Collection.class, fieldVarType)) {
                  varInit = convertArrayInitializerToNewCollection(typeDeclaration, fieldVarType, (ArrayInitializer) variableDefinition.initializer);
               }
               else {
                  typeDeclaration.displayError("Invalid use of array initializer: ");
                  varInit = variableDefinition.initializer;
               }
            }
         }
         // For short x = 3, we need setX((short) 3)
         else if (variableDefinition.needsCastOnConvert)
            varInit = CastExpression.create(field.type.getFullTypeName(), variableDefinition.initializer);
         else
            varInit = variableDefinition.initializer;
         params.initializer = ParseUtil.toLanguageString(SCLanguage.INSTANCE.variableInitializer, varInit);
      }

      makePropertyBindableInType(field, typeDeclaration, convertedPropName, params, true, bindable);

      Object enclType = ModelUtil.getEnclosingType(variableDefinition);
      params.initForProperty(sys, enclType, variableDefinition);

      int vix = -1;
      if (field.variableDefinitions.size() == 1)
         field.parentNode.removeChild(field);
      else {
         vix = field.variableDefinitions.removeChild(variableDefinition);
         if (field.variableDefinitions.size() <= vix)
            vix = -1;
      }

      applyPropertyTemplate(typeDeclaration, ix, params, typeDeclaration, ModelUtil.isInterface(typeDeclaration), variableDefinition);

      // Need to transform the next guy in the list if there is one since the parent call won't anymore
      if (vix != -1)
         field.variableDefinitions.get(vix).transform(runtime);
   }
/**
    * The main method to transform a VariableDefinition into getX/setX methods.
    *
    * See makePropertyBindable for a variant of this method that works for when there's an existing property in the base
    * class that needs a wrapping setX/getX definitions.
    */
The main method to transform a VariableDefinition into getX/setX methods.
See makePropertyBindable for a variant of this method that works for when there's an existing property in the base
class that needs a wrapping setX/getX definitions.
The main method to transform a VariableDefinition into getX / setX methods . See makePropertyBindable for a variant of this method that works for when there ' s an existing property in the base class that needs a wrapping setX / getX definitions .
public static void convertFieldToGetSetMethods(VariableDefinition variableDefinition, boolean bindable, boolean toInterface, ILanguageModel.RuntimeType runtime) {
      String convertedPropName = variableDefinition.getRealVariableName();
      String origPropName = variableDefinition.variableName;
      PropertyDefinitionParameters params = PropertyDefinitionParameters.create(convertedPropName);
      Definition enclDef = variableDefinition.getDefinition();
      FieldDefinition field = (FieldDefinition) enclDef;
      TypeDeclaration typeDeclaration = field.getEnclosingType();
      LayeredSystem sys = typeDeclaration.getLayeredSystem();
      initImportTypeNames(sys, params, typeDeclaration);
      params.getMethod = typeDeclaration.declaresMember(origPropName, JavaSemanticNode.MemberType.GetMethodSet, null, null);
      params.setMethod = typeDeclaration.declaresMember(origPropName, JavaSemanticNode.MemberType.SetMethodSet, null, null);
      params.arrayDimensions = field.type.arrayDimensions;
      if (typeDeclaration.propertiesToMakeBindable != null && typeDeclaration.propertiesToMakeBindable.get(origPropName) != null) {
         Object getMethod = typeDeclaration.definesMember(origPropName, JavaSemanticNode.MemberType.GetMethodSet, null, null);
         Object setMethod = typeDeclaration.definesMember(origPropName, JavaSemanticNode.MemberType.SetMethodSet, null, null);
         if ((getMethod == null || !ModelUtil.isAbstractMethod(getMethod)) && (setMethod == null || !ModelUtil.isAbstractMethod(setMethod))) {
            return;
         }
      }
      if (toInterface && params.isStatic) {
         System.err.println("*** can't make static interface properties bindable");
         return;
      }
      params.sendEvent = !ModelUtil.isManualBindable(variableDefinition);
      setPropertyMappingName(params, typeDeclaration);
      int ix = typeDeclaration.body.indexOf(field);
      params.propertyTypeName = field.type.getGenericTypeName(typeDeclaration, false);
      params.overrideField = false;
      params.omitField = false; 
      if (params.sendEvent) {
         Object sameValueCheckObj = ModelUtil.getAnnotationValue(field, BINDABLE_ANNOTATION, "sameValueCheck");
         if (sameValueCheckObj != null)
            params.sameValueCheck = (Boolean) sameValueCheckObj;
         else
            params.sameValueCheck = false;
      }
      /*
      Object lazyObj = ModelUtil.getAnnotationValue(field, BINDABLE_ANNOTATION, "lazy");
      if (lazyObj != null)
         params.lazy = (Boolean) lazyObj;
      else
         params.lazy = false;
      */
      if (variableDefinition.initializer == null)
         params.initializer = "";
      else {
         Expression varInit;
         if (variableDefinition.initializer instanceof ArrayInitializer) {
            if (params.arrayDimensions != null)
               varInit = convertToNewExpression(field.type.getFullBaseTypeName(), (ArrayInitializer)variableDefinition.initializer, params.arrayDimensions);
            else {
               Object fieldVarType = field.type.getTypeDeclaration();
               if (ModelUtil.isAssignableFrom(Collection.class, fieldVarType)) {
                  varInit = convertArrayInitializerToNewCollection(typeDeclaration, fieldVarType, (ArrayInitializer) variableDefinition.initializer);
               }
               else {
                  typeDeclaration.displayError("Invalid use of array initializer: ");
                  varInit = variableDefinition.initializer;
               }
            }
         }
         else if (variableDefinition.needsCastOnConvert)
            varInit = CastExpression.create(field.type.getFullTypeName(), variableDefinition.initializer);
         else
            varInit = variableDefinition.initializer;
         params.initializer = ParseUtil.toLanguageString(SCLanguage.INSTANCE.variableInitializer, varInit);
      }
      makePropertyBindableInType(field, typeDeclaration, convertedPropName, params, true, bindable);
      Object enclType = ModelUtil.getEnclosingType(variableDefinition);
      params.initForProperty(sys, enclType, variableDefinition);
      int vix = -1;
      if (field.variableDefinitions.size() == 1)
         field.parentNode.removeChild(field);
      else {
         vix = field.variableDefinitions.removeChild(variableDefinition);
         if (field.variableDefinitions.size() <= vix)
            vix = -1;
      }
      applyPropertyTemplate(typeDeclaration, ix, params, typeDeclaration, ModelUtil.isInterface(typeDeclaration), variableDefinition);
      if (vix != -1)
         field.variableDefinitions.get(vix).transform(runtime);
   }
public static void convertFieldToGetSetMethods ( VariableDefinition variableDefinition , boolean bindable , boolean toInterface , ILanguageModel . RuntimeType runtime ) { String convertedPropName = variableDefinition . getRealVariableName ( ) ; String origPropName = variableDefinition . variableName ; PropertyDefinitionParameters params = PropertyDefinitionParameters . create ( convertedPropName ) ; Definition enclDef = variableDefinition . getDefinition ( ) ; FieldDefinition field = ( FieldDefinition ) enclDef ; TypeDeclaration typeDeclaration = field . getEnclosingType ( ) ; LayeredSystem sys = typeDeclaration . getLayeredSystem ( ) ; initImportTypeNames ( sys , params , typeDeclaration ) ; params . getMethod = typeDeclaration . declaresMember ( origPropName , JavaSemanticNode . MemberType . GetMethodSet , null , null ) ; params . setMethod = typeDeclaration . declaresMember ( origPropName , JavaSemanticNode . MemberType . SetMethodSet , null , null ) ; params . arrayDimensions = field . type . arrayDimensions ; if ( typeDeclaration . propertiesToMakeBindable != null && typeDeclaration . propertiesToMakeBindable . get ( origPropName ) != null ) { Object getMethod = typeDeclaration . definesMember ( origPropName , JavaSemanticNode . MemberType . GetMethodSet , null , null ) ; Object setMethod = typeDeclaration . definesMember ( origPropName , JavaSemanticNode . MemberType . SetMethodSet , null , null ) ; if ( ( getMethod == null || ! ModelUtil . isAbstractMethod ( getMethod ) ) && ( setMethod == null || ! ModelUtil . isAbstractMethod ( setMethod ) ) ) { return ; } } if ( toInterface && params . isStatic ) { System . err . println ( "*** can't make static interface properties bindable" ) ; return ; } params . sendEvent = ! ModelUtil . isManualBindable ( variableDefinition ) ; setPropertyMappingName ( params , typeDeclaration ) ; int ix = typeDeclaration . body . indexOf ( field ) ; params . propertyTypeName = field . type . getGenericTypeName ( typeDeclaration , false ) ; params . overrideField = false ; params . omitField = false ; if ( params . sendEvent ) { Object sameValueCheckObj = ModelUtil . getAnnotationValue ( field , BINDABLE_ANNOTATION , "sameValueCheck" ) ; if ( sameValueCheckObj != null ) params . sameValueCheck = ( Boolean ) sameValueCheckObj ; else params . sameValueCheck = false ; } /*
      Object lazyObj = ModelUtil.getAnnotationValue(field, BINDABLE_ANNOTATION, "lazy");
      if (lazyObj != null)
         params.lazy = (Boolean) lazyObj;
      else
         params.lazy = false;
      */ if ( variableDefinition . initializer == null ) params . initializer = "" ; else { Expression varInit ; if ( variableDefinition . initializer instanceof ArrayInitializer ) { if ( params . arrayDimensions != null ) varInit = convertToNewExpression ( field . type . getFullBaseTypeName ( ) , ( ArrayInitializer ) variableDefinition . initializer , params . arrayDimensions ) ; else { Object fieldVarType = field . type . getTypeDeclaration ( ) ; if ( ModelUtil . isAssignableFrom ( Collection . class , fieldVarType ) ) { varInit = convertArrayInitializerToNewCollection ( typeDeclaration , fieldVarType , ( ArrayInitializer ) variableDefinition . initializer ) ; } else { typeDeclaration . displayError ( "Invalid use of array initializer: " ) ; varInit = variableDefinition . initializer ; } } } else if ( variableDefinition . needsCastOnConvert ) varInit = CastExpression . create ( field . type . getFullTypeName ( ) , variableDefinition . initializer ) ; else varInit = variableDefinition . initializer ; params . initializer = ParseUtil . toLanguageString ( SCLanguage . INSTANCE . variableInitializer , varInit ) ; } makePropertyBindableInType ( field , typeDeclaration , convertedPropName , params , true , bindable ) ; Object enclType = ModelUtil . getEnclosingType ( variableDefinition ) ; params . initForProperty ( sys , enclType , variableDefinition ) ; int vix = - 1 ; if ( field . variableDefinitions . size ( ) == 1 ) field . parentNode . removeChild ( field ) ; else { vix = field . variableDefinitions . removeChild ( variableDefinition ) ; if ( field . variableDefinitions . size ( ) <= vix ) vix = - 1 ; } applyPropertyTemplate ( typeDeclaration , ix , params , typeDeclaration , ModelUtil . isInterface ( typeDeclaration ) , variableDefinition ) ; if ( vix != - 1 ) field . variableDefinitions . get ( vix ) . transform ( runtime ) ; }
The main method to transform a VariableDefinition into getX/setX methods.
The main method to transform a VariableDefinition into getX / setX methods .
// Skipping interfaces here.  We want to only find implementation methods that we have to rename or contend with if we are converting a field and there are already get/set methods in the same type. // This is like the "makeBindable" case but we use declares not defines cause we only want to modify get/set methods if they are defined in this same type.  In the makeBindable case we are really // remapping the existing property.   For the field case, the code is declaring a new property that should hide the base classes property based on Java's rules.  If however they define a field and get/set methods // in the same type, we need to remap them.  This layers on binding on top of the existing get/set methods. // TODO: as an optimization we should recognize trivial get/set methods and just insert the sendEvent call instead of adding all of that code. // If we are overriding an abstract implementation, continue to convert the field to a getX/setX to implement the interface or abstract methods // TODO: Right now we cannot do static bindable properties on interfaces.  Not sure how that will work // Always generate the field here since we replace this one with the generated get/set call // For short x = 3, we need setX((short) 3) // Need to transform the next guy in the list if there is one since the parent call won't anymore