system/src/sc/lang/java/Annotation.java
public boolean mergeAnnotation(Object overriddenAnnotation, boolean replace) {
      boolean any = false;

      // Three types of annotations:
      // Marker: no value - nothing to merge
      // SingleElementAnnotation - if replace, we replace the value otherwise do nothing
      // InstInit Annotation - merge the name/values replacing values if replace is true

      if (ModelUtil.isComplexAnnotation(overriddenAnnotation)) {
         if (!(elementValue instanceof List))
            return false;

         List overriddenValues = ModelUtil.getAnnotationComplexValues(overriddenAnnotation);
         List thisElementValues = (List) elementValue;
         for (int i = 0; i < overriddenValues.size(); i++) {
            AnnotationValue av = (AnnotationValue) overriddenValues.get(i);
            AnnotationValue thisAv;
            AnnotationMergeMode mergeMode = LayeredSystem.getAnnotationMergeMode(typeName, av.identifier);
            if ((thisAv = getAnnotationValueWrapper(av.identifier)) == null) {
               thisElementValues.add(av);
               any = true;
            }
            else {
               switch (mergeMode) {
                  case Replace:
                     if (replace) {
                        thisElementValues.remove(thisAv);
                        thisElementValues.add(av);
                     }
                     // else - leave the overriding one in place
                     break;
                  case AppendCommaString:
                     Object thisVal = thisAv.elementValue;
                     Object otherVal = av.elementValue;
                     if (thisVal instanceof StringLiteral && otherVal instanceof StringLiteral) {
                        StringLiteral thisLiteral = (StringLiteral)thisVal;
                        String thisStr = (String) thisLiteral.getLiteralValue();
                        String otherStr = (String) ((StringLiteral)otherVal).getLiteralValue();
                        String merged;
                        if (thisStr.length() == 0)
                           merged = otherStr;
                        else if (otherStr.length() == 0)
                           merged = thisStr;
                        else
                           merged = thisStr + "," + otherStr;
                        thisLiteral.setProperty("value", merged);
                        thisLiteral.stringValue = merged;
                        any = true;
                     }
                     else
                        displayError("Expected string value for annotation: " + av.identifier);
                     break;
                  default:
                     System.err.println("*** Unrecognized merge mode");
                     break;
               }
            }
         }
      }
      else if (replace) {
         Object singleValue = ModelUtil.getAnnotationSingleValue(overriddenAnnotation);
         if (singleValue != null)
            setProperty("elementValue", singleValue);
      }
      return any;
   }
/**
    * As we are inheriting definitions we may find both src/dst types have the same annotation.
    * This method merges the definitions.  When we are merging up to a more specific layer, we only
    * copy definitions not found in the destination layer (replace=false).  When we are merging from
    * a more specific to a more general definition (the modify declaration), we replace conflicting
    * definitions in the dest.
    */
As we are inheriting definitions we may find both src/dst types have the same annotation.
This method merges the definitions.  When we are merging up to a more specific layer, we only
copy definitions not found in the destination layer (replace=false).  When we are merging from
a more specific to a more general definition (the modify declaration), we replace conflicting
definitions in the dest.
As we are inheriting definitions we may find both src / dst types have the same annotation . This method merges the definitions . When we are merging up to a more specific layer we only copy definitions not found in the destination layer ( replace = false ) . When we are merging from a more specific to a more general definition ( the modify declaration ) we replace conflicting definitions in the dest .
public boolean mergeAnnotation(Object overriddenAnnotation, boolean replace) {
      boolean any = false;
      if (ModelUtil.isComplexAnnotation(overriddenAnnotation)) {
         if (!(elementValue instanceof List))
            return false;
         List overriddenValues = ModelUtil.getAnnotationComplexValues(overriddenAnnotation);
         List thisElementValues = (List) elementValue;
         for (int i = 0; i < overriddenValues.size(); i++) {
            AnnotationValue av = (AnnotationValue) overriddenValues.get(i);
            AnnotationValue thisAv;
            AnnotationMergeMode mergeMode = LayeredSystem.getAnnotationMergeMode(typeName, av.identifier);
            if ((thisAv = getAnnotationValueWrapper(av.identifier)) == null) {
               thisElementValues.add(av);
               any = true;
            }
            else {
               switch (mergeMode) {
                  case Replace:
                     if (replace) {
                        thisElementValues.remove(thisAv);
                        thisElementValues.add(av);
                     }
                     break;
                  case AppendCommaString:
                     Object thisVal = thisAv.elementValue;
                     Object otherVal = av.elementValue;
                     if (thisVal instanceof StringLiteral && otherVal instanceof StringLiteral) {
                        StringLiteral thisLiteral = (StringLiteral)thisVal;
                        String thisStr = (String) thisLiteral.getLiteralValue();
                        String otherStr = (String) ((StringLiteral)otherVal).getLiteralValue();
                        String merged;
                        if (thisStr.length() == 0)
                           merged = otherStr;
                        else if (otherStr.length() == 0)
                           merged = thisStr;
                        else
                           merged = thisStr + "," + otherStr;
                        thisLiteral.setProperty("value", merged);
                        thisLiteral.stringValue = merged;
                        any = true;
                     }
                     else
                        displayError("Expected string value for annotation: " + av.identifier);
                     break;
                  default:
                     System.err.println("*** Unrecognized merge mode");
                     break;
               }
            }
         }
      }
      else if (replace) {
         Object singleValue = ModelUtil.getAnnotationSingleValue(overriddenAnnotation);
         if (singleValue != null)
            setProperty("elementValue", singleValue);
      }
      return any;
   }
public boolean mergeAnnotation ( Object overriddenAnnotation , boolean replace ) { boolean any = false ; if ( ModelUtil . isComplexAnnotation ( overriddenAnnotation ) ) { if ( ! ( elementValue instanceof List ) ) return false ; List overriddenValues = ModelUtil . getAnnotationComplexValues ( overriddenAnnotation ) ; List thisElementValues = ( List ) elementValue ; for ( int i = 0 ; i < overriddenValues . size ( ) ; i ++ ) { AnnotationValue av = ( AnnotationValue ) overriddenValues . get ( i ) ; AnnotationValue thisAv ; AnnotationMergeMode mergeMode = LayeredSystem . getAnnotationMergeMode ( typeName , av . identifier ) ; if ( ( thisAv = getAnnotationValueWrapper ( av . identifier ) ) == null ) { thisElementValues . add ( av ) ; any = true ; } else { switch ( mergeMode ) { case Replace : if ( replace ) { thisElementValues . remove ( thisAv ) ; thisElementValues . add ( av ) ; } break ; case AppendCommaString : Object thisVal = thisAv . elementValue ; Object otherVal = av . elementValue ; if ( thisVal instanceof StringLiteral && otherVal instanceof StringLiteral ) { StringLiteral thisLiteral = ( StringLiteral ) thisVal ; String thisStr = ( String ) thisLiteral . getLiteralValue ( ) ; String otherStr = ( String ) ( ( StringLiteral ) otherVal ) . getLiteralValue ( ) ; String merged ; if ( thisStr . length ( ) == 0 ) merged = otherStr ; else if ( otherStr . length ( ) == 0 ) merged = thisStr ; else merged = thisStr + "," + otherStr ; thisLiteral . setProperty ( "value" , merged ) ; thisLiteral . stringValue = merged ; any = true ; } else displayError ( "Expected string value for annotation: " + av . identifier ) ; break ; default : System . err . println ( "*** Unrecognized merge mode" ) ; break ; } } } } else if ( replace ) { Object singleValue = ModelUtil . getAnnotationSingleValue ( overriddenAnnotation ) ; if ( singleValue != null ) setProperty ( "elementValue" , singleValue ) ; } return any ; }
As we are inheriting definitions we may find both src/dst types have the same annotation.
As we are inheriting definitions we may find both src / dst types have the same annotation .
// Three types of annotations: // Marker: no value - nothing to merge // SingleElementAnnotation - if replace, we replace the value otherwise do nothing // InstInit Annotation - merge the name/values replacing values if replace is true // else - leave the overriding one in place