private static String concatOverrides ( String annotation , Collection < String > attributeOverrides ) { if ( attributeOverrides == null || attributeOverrides . size ( ) < 1 ) { return annotation ; } if ( annotation == null ) { annotation = "" ; } else { Matcher overrideMatcher ; while ( ( overrideMatcher = PATTERN_ATTR_OVERRIDE . matcher ( annotation ) ) . find ( ) ) { if ( ! ( attributeOverrides instanceof ArrayList ) ) { attributeOverrides = new ArrayList < String > ( attributeOverrides ) ; } ( ( ArrayList ) attributeOverrides ) . add ( 0 , overrideMatcher . group ( 1 ) ) ; annotation = annotation . substring ( 0 , overrideMatcher . start ( ) ) + annotation . substring ( overrideMatcher . end ( ) ) ; } } Matcher overridesMatcher = PATTERN_ATTR_OVERRIDES . matcher ( annotation ) ; if ( ! overridesMatcher . find ( ) ) { annotation = ( annotation . length ( ) < 1 ? "" : annotation + "\n " ) + "@" + AttributeOverrides . class . getName ( ) + "({})" ; } for ( String addOverride : attributeOverrides ) { overridesMatcher = PATTERN_ATTR_OVERRIDES . matcher ( annotation ) ; if ( ! overridesMatcher . find ( ) ) { throw new IllegalStateException ( ) ; } if ( StringUtils . isNotEmpty ( overridesMatcher . group ( 2 ) ) ) { addOverride = ", " + addOverride ; } annotation = annotation . substring ( 0 , overridesMatcher . start ( 3 ) ) + addOverride + annotation . substring ( overridesMatcher . start ( 3 ) ) ; } return annotation ; }
merges given collection of javax . persistence . AttributeOverride elements into an optionally existing javax . persistence . AttributeOverrides annotation with optionally pre - existing javax . persistence . AttributeOverride elements .