system/src/sc/lang/sc/ModifyDeclaration.java
public void initTypeInfo() {
      if (typeInfoInitialized)
         return;

      try {
         super.initTypeInfo();

         if (modifyTypeDecl != null) {
            if (layer != null) {
               /*
               * If the type we are modifying comes from a super type we need to treat it differently on transform.
               * It's really a shortcut for class foo extends Super.foo
               */
               modifyInherited = !ModelUtil.sameTypes(this, modifyTypeDecl);

               // For CmdScriptModel, a modify type might not have a direct enclosing type since we store them in a list, not a nested tree
               if (modifyInherited && getEnclosingType() == null && !(getJavaModel() instanceof CmdScriptModel))
                  System.out.println("**** ERROR: modifyInherited occurs on top-level type!");

               // For a normal modification, we end up getting the type in a previous layer.  But if we inherited this
               // from another type, we want to get the most specific one, i.e. resolve the replaced type.
               // The example is UCTest(extended) modifies UCtest(model).   UCTest(extended).converters will find UnitConverter.converters
               // to modify it.  But we need to get the most specific one: UnitConverter(extended).converters.
               if (modifyInherited && modifyTypeDecl.replacedByType != null) {
                  BodyTypeDeclaration resolvedDecl = modifyTypeDecl.resolve(true);
                  if (resolvedDecl != this) {
                     modifyTypeDecl = resolvedDecl;
                     checkModify();
                  }
                  else
                     System.err.println("*** Recursive modify in resolve");
               }

               if (modifyInherited && extendsTypes != null && extendsTypes.size() > 0) {
                  TypeDeclaration enclType = getEnclosingType();
                  if (enclType != null)
                     displayError("Modifying inherited type: " + modifyTypeDecl.getFullTypeName() + " from: " + enclType.getFullTypeName() + " cannot extend another type: ");
                  else // This happens during editing in the IDE for some reason
                     displayError("Modifying a type which is not the same: " + modifyTypeDecl.getFullTypeName());
               }

               JavaModel thisModel = getJavaModel();
               // Give the modified type a back pointer - its "find" operations will map back to us so it gets the most
               // specific definition.  It does not matter much for most contracts given type compatibility but the
               // assignment contract requires the most specific definition so we can detect cycles properly.
               if (!inactiveType && !temporaryType && !thisModel.temporary) {
                  BodyTypeDeclaration modReplacedByType = modifyTypeDecl.replacedByType ;
                  if (modReplacedByType != null) {
                     if (modReplacedByType == this) {
                        System.out.println("*** Warning - already modified this type");
                        modifyTypeDecl.replacedByType = null;
                     }
                     else if (modifyTypeDecl.replaced) {
                        System.err.println("**** Error - modifying stale type");
                        modifyTypeDecl.replacedByType = null;
                     }
                     // If we are in the same layer, we are just about to replace the type as part of updateType
                     // Just don't update replacedByType in this case since we'll set that later on anyway.
                     else if (modReplacedByType.getLayer() != getLayer()) {
                        Layer modReplacedByLayer = modReplacedByType.getLayer();
                        if (modReplacedByType.removed || modReplacedByLayer == null || modReplacedByLayer.excluded)
                           modifyTypeDecl.replacedByType = null;
                        else {
                           // For layer components we might get the wrong type here - we use the baseLayers to do teh resolution so we may not find the
                           // layer directly in front of us - instead we find the layer a couple of levels deeper in.
                           if (!isLayerComponent()) {
                              // TODO: we should accumulate all of these layers into an index.  It's quite possible in the IDE context for us to
                              // find the same type modified by different layers... in that case representing the different possible stackings.
                              System.out.println("**** Warning - modify declaration: " + typeName + " in layer: " + getLayer() + " not replacing upstream layer of: " + modifyTypeDecl.getLayer() + " since it's already modified by: " + modifyTypeDecl.replacedByType.getLayer());
                           } else {
                              // This layer should be in front of us -
                              if (getLayer().layerPosition != -1 && getLayer().layerPosition < modReplacedByType.getLayer().layerPosition)
                                 System.out.println("*** Error - improper layer init ordering");
                              else {
                                 while (modifyTypeDecl.replacedByType != null) {
                                    modifyTypeDecl = modifyTypeDecl.replacedByType;
                                    checkModify();
                                 }

                                 modifyTypeDecl.replacedByType = null;
                              }
                           }
                        }
                     }
                  }

                  if (modifyTypeDecl.replacedByType == null && !modifyInherited && !(thisModel instanceof CmdScriptModel)) {
                     modifyTypeDecl.updateReplacedByType(this);
                  }
               }
            }
         }
      }
      catch (RuntimeException exc) {
         typeInfoInitialized = false;
         throw exc;
      }
   }
/** 
    * Here we are updating the 'replacedByType' on the modified type.  Since this is a
    * structural part of the type system, that needs to be resolved during the initialize
    * stage for the html Element convertToObject method, this section was broken out of the
    * start method - so it's done as soon as modifyTypeDecl is updated.
    */
Here we are updating the 'replacedByType' on the modified type.  Since this is a
structural part of the type system, that needs to be resolved during the initialize
stage for the html Element convertToObject method, this section was broken out of the
start method - so it's done as soon as modifyTypeDecl is updated.
Here we are updating the ' replacedByType ' on the modified type . Since this is a structural part of the type system that needs to be resolved during the initialize stage for the html Element convertToObject method this section was broken out of the start method - so it ' s done as soon as modifyTypeDecl is updated .
public void initTypeInfo() {
      if (typeInfoInitialized)
         return;
      try {
         super.initTypeInfo();
         if (modifyTypeDecl != null) {
            if (layer != null) {
               /*
               * If the type we are modifying comes from a super type we need to treat it differently on transform.
               * It's really a shortcut for class foo extends Super.foo
               */
               modifyInherited = !ModelUtil.sameTypes(this, modifyTypeDecl);
               if (modifyInherited && getEnclosingType() == null && !(getJavaModel() instanceof CmdScriptModel))
                  System.out.println("**** ERROR: modifyInherited occurs on top-level type!");
               if (modifyInherited && modifyTypeDecl.replacedByType != null) {
                  BodyTypeDeclaration resolvedDecl = modifyTypeDecl.resolve(true);
                  if (resolvedDecl != this) {
                     modifyTypeDecl = resolvedDecl;
                     checkModify();
                  }
                  else
                     System.err.println("*** Recursive modify in resolve");
               }
               if (modifyInherited && extendsTypes != null && extendsTypes.size() > 0) {
                  TypeDeclaration enclType = getEnclosingType();
                  if (enclType != null)
                     displayError("Modifying inherited type: " + modifyTypeDecl.getFullTypeName() + " from: " + enclType.getFullTypeName() + " cannot extend another type: ");
                  else 
                     displayError("Modifying a type which is not the same: " + modifyTypeDecl.getFullTypeName());
               }
               JavaModel thisModel = getJavaModel();
               if (!inactiveType && !temporaryType && !thisModel.temporary) {
                  BodyTypeDeclaration modReplacedByType = modifyTypeDecl.replacedByType ;
                  if (modReplacedByType != null) {
                     if (modReplacedByType == this) {
                        System.out.println("*** Warning - already modified this type");
                        modifyTypeDecl.replacedByType = null;
                     }
                     else if (modifyTypeDecl.replaced) {
                        System.err.println("**** Error - modifying stale type");
                        modifyTypeDecl.replacedByType = null;
                     }
                     else if (modReplacedByType.getLayer() != getLayer()) {
                        Layer modReplacedByLayer = modReplacedByType.getLayer();
                        if (modReplacedByType.removed || modReplacedByLayer == null || modReplacedByLayer.excluded)
                           modifyTypeDecl.replacedByType = null;
                        else {
                           if (!isLayerComponent()) {
                              System.out.println("**** Warning - modify declaration: " + typeName + " in layer: " + getLayer() + " not replacing upstream layer of: " + modifyTypeDecl.getLayer() + " since it's already modified by: " + modifyTypeDecl.replacedByType.getLayer());
                           } else {
                              if (getLayer().layerPosition != -1 && getLayer().layerPosition < modReplacedByType.getLayer().layerPosition)
                                 System.out.println("*** Error - improper layer init ordering");
                              else {
                                 while (modifyTypeDecl.replacedByType != null) {
                                    modifyTypeDecl = modifyTypeDecl.replacedByType;
                                    checkModify();
                                 }
                                 modifyTypeDecl.replacedByType = null;
                              }
                           }
                        }
                     }
                  }
                  if (modifyTypeDecl.replacedByType == null && !modifyInherited && !(thisModel instanceof CmdScriptModel)) {
                     modifyTypeDecl.updateReplacedByType(this);
                  }
               }
            }
         }
      }
      catch (RuntimeException exc) {
         typeInfoInitialized = false;
         throw exc;
      }
   }
public void initTypeInfo ( ) { if ( typeInfoInitialized ) return ; try { super . initTypeInfo ( ) ; if ( modifyTypeDecl != null ) { if ( layer != null ) { /*
               * If the type we are modifying comes from a super type we need to treat it differently on transform.
               * It's really a shortcut for class foo extends Super.foo
               */ modifyInherited = ! ModelUtil . sameTypes ( this , modifyTypeDecl ) ; if ( modifyInherited && getEnclosingType ( ) == null && ! ( getJavaModel ( ) instanceof CmdScriptModel ) ) System . out . println ( "**** ERROR: modifyInherited occurs on top-level type!" ) ; if ( modifyInherited && modifyTypeDecl . replacedByType != null ) { BodyTypeDeclaration resolvedDecl = modifyTypeDecl . resolve ( true ) ; if ( resolvedDecl != this ) { modifyTypeDecl = resolvedDecl ; checkModify ( ) ; } else System . err . println ( "*** Recursive modify in resolve" ) ; } if ( modifyInherited && extendsTypes != null && extendsTypes . size ( ) > 0 ) { TypeDeclaration enclType = getEnclosingType ( ) ; if ( enclType != null ) displayError ( "Modifying inherited type: " + modifyTypeDecl . getFullTypeName ( ) + " from: " + enclType . getFullTypeName ( ) + " cannot extend another type: " ) ; else displayError ( "Modifying a type which is not the same: " + modifyTypeDecl . getFullTypeName ( ) ) ; } JavaModel thisModel = getJavaModel ( ) ; if ( ! inactiveType && ! temporaryType && ! thisModel . temporary ) { BodyTypeDeclaration modReplacedByType = modifyTypeDecl . replacedByType ; if ( modReplacedByType != null ) { if ( modReplacedByType == this ) { System . out . println ( "*** Warning - already modified this type" ) ; modifyTypeDecl . replacedByType = null ; } else if ( modifyTypeDecl . replaced ) { System . err . println ( "**** Error - modifying stale type" ) ; modifyTypeDecl . replacedByType = null ; } else if ( modReplacedByType . getLayer ( ) != getLayer ( ) ) { Layer modReplacedByLayer = modReplacedByType . getLayer ( ) ; if ( modReplacedByType . removed || modReplacedByLayer == null || modReplacedByLayer . excluded ) modifyTypeDecl . replacedByType = null ; else { if ( ! isLayerComponent ( ) ) { System . out . println ( "**** Warning - modify declaration: " + typeName + " in layer: " + getLayer ( ) + " not replacing upstream layer of: " + modifyTypeDecl . getLayer ( ) + " since it's already modified by: " + modifyTypeDecl . replacedByType . getLayer ( ) ) ; } else { if ( getLayer ( ) . layerPosition != - 1 && getLayer ( ) . layerPosition < modReplacedByType . getLayer ( ) . layerPosition ) System . out . println ( "*** Error - improper layer init ordering" ) ; else { while ( modifyTypeDecl . replacedByType != null ) { modifyTypeDecl = modifyTypeDecl . replacedByType ; checkModify ( ) ; } modifyTypeDecl . replacedByType = null ; } } } } } if ( modifyTypeDecl . replacedByType == null && ! modifyInherited && ! ( thisModel instanceof CmdScriptModel ) ) { modifyTypeDecl . updateReplacedByType ( this ) ; } } } } } catch ( RuntimeException exc ) { typeInfoInitialized = false ; throw exc ; } }
Here we are updating the 'replacedByType' on the modified type.
Here we are updating the ' replacedByType ' on the modified type .
// For CmdScriptModel, a modify type might not have a direct enclosing type since we store them in a list, not a nested tree // For a normal modification, we end up getting the type in a previous layer.  But if we inherited this // from another type, we want to get the most specific one, i.e. resolve the replaced type. // The example is UCTest(extended) modifies UCtest(model).   UCTest(extended).converters will find UnitConverter.converters // to modify it.  But we need to get the most specific one: UnitConverter(extended).converters. // This happens during editing in the IDE for some reason // Give the modified type a back pointer - its "find" operations will map back to us so it gets the most // specific definition.  It does not matter much for most contracts given type compatibility but the // assignment contract requires the most specific definition so we can detect cycles properly. // If we are in the same layer, we are just about to replace the type as part of updateType // Just don't update replacedByType in this case since we'll set that later on anyway. // For layer components we might get the wrong type here - we use the baseLayers to do teh resolution so we may not find the // layer directly in front of us - instead we find the layer a couple of levels deeper in. // TODO: we should accumulate all of these layers into an index.  It's quite possible in the IDE context for us to // find the same type modified by different layers... in that case representing the different possible stackings. // This layer should be in front of us -