system/src/sc/lang/java/ModelUtil.java
public static Object mergeAnnotations(Object mainAnnot, Object overAnnot, boolean replace) {
      boolean any = false;

      Annotation newAnnotation = null;

      // 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(overAnnot)) {
         if (!ModelUtil.isComplexAnnotation(mainAnnot))
            return replace ? overAnnot : mainAnnot; // Weird case - an @Foo(a=1,b=2) overriding @Foo(3) or @Foo - use the more specific one or do we need a way to clear the

         List<AnnotationValue> overriddenValues = ModelUtil.getAnnotationComplexValues(overAnnot);
         List<AnnotationValue> thisElementValues = ModelUtil.getAnnotationComplexValues(mainAnnot);
         int thisSz = thisElementValues.size();
         for (int i = 0; i < overriddenValues.size(); i++) {
            AnnotationValue av = overriddenValues.get(i);

            int tix;
            AnnotationValue tv = null;
            for (tix = 0; tix < thisSz; tix++) {
               tv = thisElementValues.get(tix);
               if (tv.identifier.equals(av.identifier)) {
                  break;
               }
            }
            if (tix != thisSz) {
               if (replace) {
                  if (tv != null)
                     thisElementValues.remove(tv);
                  thisElementValues.add(av);
               }
               // else - use mainAnnot version
            }
            // Overridden value not found in main - first time clone the element, then add the overridden guys to this new list only if their' not in main
            else {
               if (newAnnotation == null) {
                  newAnnotation = Annotation.createFromAnnotation(mainAnnot);
               }
               List<Object> newValues = (List<Object>) newAnnotation.elementValue;
               newValues.add(av.deepCopy(ISemanticNode.CopyNormal, null));
            }
         }
         if (newAnnotation != null)
            return newAnnotation;
      }
      else if (replace) {
         Object overrideSV = ModelUtil.getAnnotationSingleValue(overAnnot);
         if (overrideSV != null)
            return overrideSV;
      }
      return mainAnnot;
   }
/**
    * 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 static Object mergeAnnotations(Object mainAnnot, Object overAnnot, boolean replace) {
      boolean any = false;
      Annotation newAnnotation = null;
      if (ModelUtil.isComplexAnnotation(overAnnot)) {
         if (!ModelUtil.isComplexAnnotation(mainAnnot))
            return replace ? overAnnot : mainAnnot; 
         List<AnnotationValue> overriddenValues = ModelUtil.getAnnotationComplexValues(overAnnot);
         List<AnnotationValue> thisElementValues = ModelUtil.getAnnotationComplexValues(mainAnnot);
         int thisSz = thisElementValues.size();
         for (int i = 0; i < overriddenValues.size(); i++) {
            AnnotationValue av = overriddenValues.get(i);
            int tix;
            AnnotationValue tv = null;
            for (tix = 0; tix < thisSz; tix++) {
               tv = thisElementValues.get(tix);
               if (tv.identifier.equals(av.identifier)) {
                  break;
               }
            }
            if (tix != thisSz) {
               if (replace) {
                  if (tv != null)
                     thisElementValues.remove(tv);
                  thisElementValues.add(av);
               }
            }
            else {
               if (newAnnotation == null) {
                  newAnnotation = Annotation.createFromAnnotation(mainAnnot);
               }
               List<Object> newValues = (List<Object>) newAnnotation.elementValue;
               newValues.add(av.deepCopy(ISemanticNode.CopyNormal, null));
            }
         }
         if (newAnnotation != null)
            return newAnnotation;
      }
      else if (replace) {
         Object overrideSV = ModelUtil.getAnnotationSingleValue(overAnnot);
         if (overrideSV != null)
            return overrideSV;
      }
      return mainAnnot;
   }
public static Object mergeAnnotations ( Object mainAnnot , Object overAnnot , boolean replace ) { boolean any = false ; Annotation newAnnotation = null ; if ( ModelUtil . isComplexAnnotation ( overAnnot ) ) { if ( ! ModelUtil . isComplexAnnotation ( mainAnnot ) ) return replace ? overAnnot : mainAnnot ; List < AnnotationValue > overriddenValues = ModelUtil . getAnnotationComplexValues ( overAnnot ) ; List < AnnotationValue > thisElementValues = ModelUtil . getAnnotationComplexValues ( mainAnnot ) ; int thisSz = thisElementValues . size ( ) ; for ( int i = 0 ; i < overriddenValues . size ( ) ; i ++ ) { AnnotationValue av = overriddenValues . get ( i ) ; int tix ; AnnotationValue tv = null ; for ( tix = 0 ; tix < thisSz ; tix ++ ) { tv = thisElementValues . get ( tix ) ; if ( tv . identifier . equals ( av . identifier ) ) { break ; } } if ( tix != thisSz ) { if ( replace ) { if ( tv != null ) thisElementValues . remove ( tv ) ; thisElementValues . add ( av ) ; } } else { if ( newAnnotation == null ) { newAnnotation = Annotation . createFromAnnotation ( mainAnnot ) ; } List < Object > newValues = ( List < Object > ) newAnnotation . elementValue ; newValues . add ( av . deepCopy ( ISemanticNode . CopyNormal , null ) ) ; } } if ( newAnnotation != null ) return newAnnotation ; } else if ( replace ) { Object overrideSV = ModelUtil . getAnnotationSingleValue ( overAnnot ) ; if ( overrideSV != null ) return overrideSV ; } return mainAnnot ; }
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 // Weird case - an @Foo(a=1,b=2) overriding @Foo(3) or @Foo - use the more specific one or do we need a way to clear the // else - use mainAnnot version // Overridden value not found in main - first time clone the element, then add the overridden guys to this new list only if their' not in main