@@ -270,15 +270,15 @@ public void visitStructureStart(final int offsetInCompiledBlock, final JBBPNamed
270270 final String structBaseTypeName = structName .toUpperCase (Locale .ENGLISH );
271271 final String arraySizeIn = nullableArraySize == null ? null : evaluatorToString (NAME_INPUT_STREAM , offsetInCompiledBlock , nullableArraySize , this .flagSet , true );
272272 final String arraySizeOut = nullableArraySize == null ? null : evaluatorToString (NAME_OUTPUT_STREAM , offsetInCompiledBlock , nullableArraySize , this .flagSet , true );
273- final Struct newStruct = new Struct (this .getCurrentStruct (), structBaseTypeName , "public static" );
273+ final Struct newStruct = new Struct (this .getCurrentStruct (), structBaseTypeName , "public" + ( builder . internalClassesNotStatic ? "" : " static") );
274274
275275 final String fieldModifier = makeModifier (nullableNameFieldInfo );
276276
277277 final String toType ;
278278 if (this .builder .generateFields ) {
279279 toType = "" ;
280280 } else {
281- toType = '(' + structBaseTypeName + ')' ;
281+ toType = '(' + structBaseTypeName + ')' ;
282282 }
283283
284284 final String structType ;
@@ -293,8 +293,8 @@ public void visitStructureStart(final int offsetInCompiledBlock, final JBBPNamed
293293
294294 this .getCurrentStruct ().getReadFunc ().indent ()
295295 .printf ("if ( this.%1$s == null) { this.%1$s = new %2$s(%3$s);}" , structName , structType , this .structStack .size () == 1 ? "this" : "this." + NAME_ROOT_STRUCT )
296- .printf (" %s.read(%s);%n" , toType .length () == 0 ? "this." + structName : '(' + toType + "this." + structName + ')' , NAME_INPUT_STREAM );
297- this .getCurrentStruct ().getWriteFunc ().indent ().print (toType .length () == 0 ? structName : '(' +toType + structName + ')' ).println (".write(Out);" );
296+ .printf (" %s.read(%s);%n" , toType .length () == 0 ? "this." + structName : '(' + toType + "this." + structName + ')' , NAME_INPUT_STREAM );
297+ this .getCurrentStruct ().getWriteFunc ().indent ().print (toType .length () == 0 ? structName : '(' + toType + structName + ')' ).println (".write(Out);" );
298298 } else {
299299 structType = structBaseTypeName + " []" ;
300300 if (this .builder .generateFields ) {
@@ -310,7 +310,7 @@ public void visitStructureStart(final int offsetInCompiledBlock, final JBBPNamed
310310 structBaseTypeName ,
311311 (this .structStack .size () == 1 ? "this" : NAME_ROOT_STRUCT ),
312312 NAME_INPUT_STREAM );
313- this .getCurrentStruct ().getWriteFunc ().indent ().printf ("for (int I=0;I<this.%1$s.length;I++){ %2$s.write(%3$s); }%n" , structName , toType .length () == 0 ? "this." + structName + "[I]" : '(' + toType +"this." + structName + "[I])" , NAME_OUTPUT_STREAM );
313+ this .getCurrentStruct ().getWriteFunc ().indent ().printf ("for (int I=0;I<this.%1$s.length;I++){ %2$s.write(%3$s); }%n" , structName , toType .length () == 0 ? "this." + structName + "[I]" : '(' + toType + "this." + structName + "[I])" , NAME_OUTPUT_STREAM );
314314 } else {
315315 this .getCurrentStruct ().getReadFunc ().indent ()
316316 .printf ("if (this.%1$s == null || this.%1$s.length != %2$s){ this.%1$s = new %3$s[%2$s]; for(int I=0;I<%2$s;I++){ this.%1$s[I] = new %3$s(%4$s);}}" , structName , arraySizeIn , structBaseTypeName , (this .structStack .size () == 1 ? "this" : "this." + NAME_ROOT_STRUCT ))
@@ -971,6 +971,11 @@ public static final class Builder {
971971 * Superclasses to be extended by generated subclasses.
972972 */
973973 private final Map <String , String > mapSubClassesSuperclasses = new HashMap <String , String >();
974+
975+ /**
976+ * Imternal classes must not be static.
977+ */
978+ public boolean internalClassesNotStatic ;
974979 /**
975980 * The Package name for the result class.
976981 */
@@ -1129,6 +1134,18 @@ public Builder setMainClassName(final String value) {
11291134 return this ;
11301135 }
11311136
1137+ /**
1138+ * Don't make insternal generated classes as static ones
1139+ *
1140+ * @return the builder instance, must not be null
1141+ * @since 1.4.0
1142+ */
1143+ public Builder doInternalClassesNonStatic () {
1144+ assertNonLocked ();
1145+ this .internalClassesNotStatic = true ;
1146+ return this ;
1147+ }
1148+
11321149 /**
11331150 * Set the superclass for the main generated class. <b>NB! Also it affects read and write methods of the main class, the class will be used as the return type.</b>
11341151 *
0 commit comments