system/src/sc/lang/java/TransformUtil.java
public static void convertArrayInitializerToNewExpression(Statement st) {
      if (st instanceof AssignmentExpression) {
         AssignmentExpression ae = (AssignmentExpression) st;
         if (ae.rhs instanceof ArrayInitializer) {
            ArrayInitializer arrInit = (ArrayInitializer) ae.rhs;
            Object arrayType = ((ITypedObject)ae.fromDefinition).getTypeDeclaration();
            if (!ModelUtil.isArray(arrayType) && ModelUtil.isAssignableFrom(Collection.class, arrayType)) {
               NewExpression newContainerExpr = convertArrayInitializerToNewCollection(st, arrayType, arrInit);
               ae.setProperty("rhs", newContainerExpr);
            }
            else if (ModelUtil.isArray(arrayType)) {
               // Note: ae is not started here but its fromDefinition is so we get the type from that
               String typeName = ModelUtil.getTypeName(arrayType);
               int dimIx = typeName.indexOf("[");
               String arrayDims = null;
               if (dimIx != -1) {
                  arrayDims = typeName.substring(dimIx);
                  typeName = typeName.substring(0,dimIx);
               }
               ae.setProperty("rhs", convertToNewExpression(typeName, (ArrayInitializer) ae.rhs, arrayDims));
            }
         }
         else if (ae.fromDefinition instanceof VariableDefinition) {
            VariableDefinition def = (VariableDefinition) ae.fromDefinition;
            if (def.needsCastOnConvert) {
               ae.setProperty("rhs", CastExpression.create(ModelUtil.getTypeName(def.getTypeDeclaration()), ae.rhs));
            }
         }
         else if (ae.fromDefinition instanceof PropertyAssignment) {
            PropertyAssignment def = (PropertyAssignment) ae.fromDefinition;
            if (def.needsCastOnConvert) {
               // Turn this off so it does not happen twice
               def.needsCastOnConvert = false;
               ae.setProperty("rhs", CastExpression.create(ModelUtil.getTypeName(def.getTypeDeclaration()), ae.rhs));
            }
         }
      }
   }
/** This handles the case where we are converting from a field to a setX or something like that.  It also converts {} into the proper collection creation. */
This handles the case where we are converting from a field to a setX or something like that.  It also converts {} into the proper collection creation.
This handles the case where we are converting from a field to a setX or something like that . It also converts {} into the proper collection creation .
public static void convertArrayInitializerToNewExpression(Statement st) {
      if (st instanceof AssignmentExpression) {
         AssignmentExpression ae = (AssignmentExpression) st;
         if (ae.rhs instanceof ArrayInitializer) {
            ArrayInitializer arrInit = (ArrayInitializer) ae.rhs;
            Object arrayType = ((ITypedObject)ae.fromDefinition).getTypeDeclaration();
            if (!ModelUtil.isArray(arrayType) && ModelUtil.isAssignableFrom(Collection.class, arrayType)) {
               NewExpression newContainerExpr = convertArrayInitializerToNewCollection(st, arrayType, arrInit);
               ae.setProperty("rhs", newContainerExpr);
            }
            else if (ModelUtil.isArray(arrayType)) {
               String typeName = ModelUtil.getTypeName(arrayType);
               int dimIx = typeName.indexOf("[");
               String arrayDims = null;
               if (dimIx != -1) {
                  arrayDims = typeName.substring(dimIx);
                  typeName = typeName.substring(0,dimIx);
               }
               ae.setProperty("rhs", convertToNewExpression(typeName, (ArrayInitializer) ae.rhs, arrayDims));
            }
         }
         else if (ae.fromDefinition instanceof VariableDefinition) {
            VariableDefinition def = (VariableDefinition) ae.fromDefinition;
            if (def.needsCastOnConvert) {
               ae.setProperty("rhs", CastExpression.create(ModelUtil.getTypeName(def.getTypeDeclaration()), ae.rhs));
            }
         }
         else if (ae.fromDefinition instanceof PropertyAssignment) {
            PropertyAssignment def = (PropertyAssignment) ae.fromDefinition;
            if (def.needsCastOnConvert) {
               def.needsCastOnConvert = false;
               ae.setProperty("rhs", CastExpression.create(ModelUtil.getTypeName(def.getTypeDeclaration()), ae.rhs));
            }
         }
      }
   }
public static void convertArrayInitializerToNewExpression ( Statement st ) { if ( st instanceof AssignmentExpression ) { AssignmentExpression ae = ( AssignmentExpression ) st ; if ( ae . rhs instanceof ArrayInitializer ) { ArrayInitializer arrInit = ( ArrayInitializer ) ae . rhs ; Object arrayType = ( ( ITypedObject ) ae . fromDefinition ) . getTypeDeclaration ( ) ; if ( ! ModelUtil . isArray ( arrayType ) && ModelUtil . isAssignableFrom ( Collection . class , arrayType ) ) { NewExpression newContainerExpr = convertArrayInitializerToNewCollection ( st , arrayType , arrInit ) ; ae . setProperty ( "rhs" , newContainerExpr ) ; } else if ( ModelUtil . isArray ( arrayType ) ) { String typeName = ModelUtil . getTypeName ( arrayType ) ; int dimIx = typeName . indexOf ( "[" ) ; String arrayDims = null ; if ( dimIx != - 1 ) { arrayDims = typeName . substring ( dimIx ) ; typeName = typeName . substring ( 0 , dimIx ) ; } ae . setProperty ( "rhs" , convertToNewExpression ( typeName , ( ArrayInitializer ) ae . rhs , arrayDims ) ) ; } } else if ( ae . fromDefinition instanceof VariableDefinition ) { VariableDefinition def = ( VariableDefinition ) ae . fromDefinition ; if ( def . needsCastOnConvert ) { ae . setProperty ( "rhs" , CastExpression . create ( ModelUtil . getTypeName ( def . getTypeDeclaration ( ) ) , ae . rhs ) ) ; } } else if ( ae . fromDefinition instanceof PropertyAssignment ) { PropertyAssignment def = ( PropertyAssignment ) ae . fromDefinition ; if ( def . needsCastOnConvert ) { def . needsCastOnConvert = false ; ae . setProperty ( "rhs" , CastExpression . create ( ModelUtil . getTypeName ( def . getTypeDeclaration ( ) ) , ae . rhs ) ) ; } } } }
This handles the case where we are converting from a field to a setX or something like that.
This handles the case where we are converting from a field to a setX or something like that .
// Note: ae is not started here but its fromDefinition is so we get the type from that // Turn this off so it does not happen twice