@@ -119,45 +119,12 @@ private void generateBuildSchemeCode(ClassGen cg) {
119119 private void generateFieldCode (ClassGen cg , Map <String , RecordField > fields , String recordNameReference ,
120120 boolean isRegional )
121121 {
122- String conditionalProperty = null ;
123- boolean isPhantom = false ;
124122 for (Map .Entry <String , RecordField > fieldEntry : fields .entrySet ()) {
125123 String fieldName = fieldEntry .getKey ();
126124 RecordField f = fieldEntry .getValue ();
127125 if (isRegional && f .isCompositeOnly )
128126 continue ;
129- if (conditionalProperty != null &&
130- (!conditionalProperty .equals (f .conditionalProperty ) || isPhantom != f .isPhantom ))
131- {
132- cg .unindent ();
133- cg .code ("}" );
134- conditionalProperty = null ;
135- }
136- if (f .conditionalProperty != null && !f .conditionalProperty .equals (conditionalProperty )) {
137- cg .addImport (new ClassName (SystemProperties .class ));
138- cg .code ("if (SystemProperties.getBooleanProperty(\" " + f .conditionalProperty + "\" , false)) {" );
139- cg .indent ();
140- conditionalProperty = f .conditionalProperty ;
141- isPhantom = f .isPhantom ;
142- }
143- if (f .onlySuffixesDefault != null || f .exceptSuffixes != null ) {
144- cg .code ("if (" +
145- (f .onlySuffixesDefault != null ?
146- ("suffix.matches(" +
147- (f .onlySuffixesProperty != null ?
148- "SystemProperties.getProperty(\" " + f .onlySuffixesProperty + "\" , \" " +
149- f .onlySuffixesDefault + "\" )" :
150- "\" " + f .onlySuffixesDefault + "\" "
151- ) +
152- ")"
153- ) :
154- ""
155- ) +
156- (f .onlySuffixesDefault != null && f .exceptSuffixes != null ? " && " : "" ) +
157- (f .exceptSuffixes != null ? "!suffix.matches(\" " + f .exceptSuffixes + "\" )" : "" ) +
158- ")" );
159- cg .indent ();
160- }
127+
161128 cg .addImport (new ClassName (SerialFieldType .class ));
162129 for (FieldType .Field field : f .fieldType .fields ) {
163130 String typeExpr = "SerialFieldType." + field .serialType ;
@@ -179,17 +146,43 @@ private void generateFieldCode(ClassGen cg, Map<String, RecordField> fields, Str
179146 } else {
180147 cg .code ("builder.addOptionalField(" +
181148 recordNameReference + ", \" " + field .getFullName (fieldName ) + "\" , " + typeExpr +
182- ", \" " + f .eventName + "\" , \" " + f .propertyName + "\" , " + f . enabled +
149+ ", \" " + f .eventName + "\" , \" " + f .propertyName + "\" , " + generateEnabledCondition ( cg , f ) +
183150 (f .time == SchemeFieldTime .COMMON_FIELD ? "" : ", SchemeFieldTime." + f .time ) + ");" );
184151 }
185152 }
186- if (f .onlySuffixesDefault != null || f .exceptSuffixes != null )
187- cg .unindent ();
188153 }
189- if (conditionalProperty != null ) {
190- cg .unindent ();
191- cg .code ("}" );
154+ }
155+
156+ private String generateEnabledCondition (ClassGen cg , RecordField f ) {
157+ if (f .enabled ) {
158+ // Field is unconditionally enabled
159+ return "true" ;
160+ }
161+
162+ String enabledCondition = "" ;
163+ if (f .conditionalProperty != null ) {
164+ // Field is enabled if system property is set
165+ cg .addImport (new ClassName (SystemProperties .class ));
166+ enabledCondition += "SystemProperties.getBooleanProperty(\" " + f .conditionalProperty + "\" , false)" ;
167+ }
168+ if (f .onlySuffixesDefault != null ) {
169+ if (!enabledCondition .isEmpty ()) {
170+ enabledCondition += " && " ;
171+ }
172+ // Field is enabled if suffix matches pattern
173+ enabledCondition += "suffix.matches(" + (f .onlySuffixesProperty != null ?
174+ "SystemProperties.getProperty(\" " + f .onlySuffixesProperty + "\" , \" " + f .onlySuffixesDefault + "\" )" :
175+ "\" " + f .onlySuffixesDefault + "\" " ) + ")" ;
176+
177+ }
178+ if (f .exceptSuffixes != null ) {
179+ if (!enabledCondition .isEmpty ()) {
180+ enabledCondition += " && " ;
181+ }
182+ // Field is enabled if not suffix matches pattern
183+ enabledCondition += "!suffix.matches(\" " + f .exceptSuffixes + "\" )" ;
192184 }
185+ return (enabledCondition .isEmpty ()) ? "false" : enabledCondition ;
193186 }
194187
195188 private void generateCreateDelegatesCode (ClassGen cg , boolean streamOnly ) {
0 commit comments