@@ -82,64 +82,15 @@ public final class JBBPToJavaConverter extends CompiledBlockVisitor {
8282 private static final String NAME_OUTPUT_STREAM = "Out" ;
8383
8484 static {
85- final Set <String > reserved = new HashSet <>();
86-
87- reserved .add ("abstract" );
88- reserved .add ("assert" );
89- reserved .add ("boolean" );
90- reserved .add ("break" );
91- reserved .add ("byte" );
92- reserved .add ("case" );
93- reserved .add ("catch" );
94- reserved .add ("char" );
95- reserved .add ("class" );
96- reserved .add ("continue" );
97- reserved .add ("default" );
98- reserved .add ("do" );
99- reserved .add ("double" );
100- reserved .add ("else" );
101- reserved .add ("enum" );
102- reserved .add ("extends" );
103- reserved .add ("final" );
104- reserved .add ("finally" );
105- reserved .add ("float" );
106- reserved .add ("for" );
107- reserved .add ("if" );
108- reserved .add ("implements" );
109- reserved .add ("import" );
110- reserved .add ("instanceof" );
111- reserved .add ("int" );
112- reserved .add ("interface" );
113- reserved .add ("long" );
114- reserved .add ("native" );
115- reserved .add ("new" );
116- reserved .add ("package" );
117- reserved .add ("private" );
118- reserved .add ("protected" );
119- reserved .add ("public" );
120- reserved .add ("return" );
121- reserved .add ("short" );
122- reserved .add ("static" );
123- reserved .add ("strictfp" );
124- reserved .add ("super" );
125- reserved .add ("switch" );
126- reserved .add ("synchronized" );
127- reserved .add ("this" );
128- reserved .add ("throw" );
129- reserved .add ("throws" );
130- reserved .add ("transient" );
131- reserved .add ("try" );
132- reserved .add ("void" );
133- reserved .add ("volatile" );
134- reserved .add ("while" );
135- reserved .add ("true" );
136- reserved .add ("null" );
137- reserved .add ("false" );
138- reserved .add ("var" );
139- reserved .add ("const" );
140- reserved .add ("goto" );
141-
142- RESERVED_JAVA_KEYWORDS = Collections .unmodifiableSet (reserved );
85+
86+ RESERVED_JAVA_KEYWORDS =
87+ Set .of ("abstract" , "assert" , "boolean" , "break" , "byte" , "case" , "catch" , "char" , "class" ,
88+ "continue" , "default" , "do" , "double" , "else" , "enum" , "extends" , "final" , "finally" ,
89+ "float" , "for" , "if" , "implements" , "import" , "instanceof" , "int" , "interface" , "long" ,
90+ "native" , "new" , "package" , "private" , "protected" , "public" , "return" , "short" ,
91+ "static" , "strictfp" , "super" , "switch" , "synchronized" , "this" , "throw" , "throws" ,
92+ "transient" , "try" , "void" , "volatile" , "while" , "true" , "null" , "false" , "var" ,
93+ "const" , "goto" );
14394 }
14495
14596 /**
@@ -258,7 +209,7 @@ public void visitEnd() {
258209 buffer .printCommentMultiLinesWithIndent (this .builder .headComment );
259210 }
260211
261- if (this .builder .mainClassPackage != null && this .builder .mainClassPackage .length () != 0 ) {
212+ if (this .builder .mainClassPackage != null && ! this .builder .mainClassPackage .isEmpty () ) {
262213 buffer .print ("package " ).print (this .builder .mainClassPackage ).println (";" );
263214 }
264215
@@ -377,7 +328,7 @@ public void visitEnd() {
377328 this .builder .mapSubClassesInterfaces ,
378329 this .builder .mapSubClassesSuperclasses ,
379330 this .specialSection .toString (),
380- specialMethodsText .length () == 0 ? null : specialMethodsText ,
331+ specialMethodsText .isEmpty () ? null : specialMethodsText ,
381332 this .builder .mainClassCustomText ,
382333 true
383334 );
@@ -429,10 +380,10 @@ public void visitStructureStart(final int offsetInCompiledBlock,
429380 this .getCurrentStruct ().getReadFunc ().indent ()
430381 .printf ("if ( this.%1$s == null) { this.%1$s = new %2$s(%3$s);}" , structName , structType ,
431382 pathToRootObject )
432- .printf (" %s.read(%s);%n" , toType .length () == 0 ? "this." + structName :
383+ .printf (" %s.read(%s);%n" , toType .isEmpty () ? "this." + structName :
433384 '(' + toType + "this." + structName + ')' , NAME_INPUT_STREAM );
434385 this .getCurrentStruct ().getWriteFunc ().indent ()
435- .print (toType .length () == 0 ? structName : '(' + toType + structName + ')' )
386+ .print (toType .isEmpty () ? structName : '(' + toType + structName + ')' )
436387 .println (".write(Out);" );
437388 } else {
438389 structType = structBaseTypeName + " []" ;
@@ -453,7 +404,7 @@ public void visitStructureStart(final int offsetInCompiledBlock,
453404 NAME_INPUT_STREAM );
454405 this .getCurrentStruct ().getWriteFunc ().indent ()
455406 .printf ("for (int I=0;I<this.%1$s.length;I++){ %2$s.write(%3$s); }%n" , structName ,
456- toType .length () == 0 ? "this." + structName + "[I]" :
407+ toType .isEmpty () ? "this." + structName + "[I]" :
457408 '(' + toType + "this." + structName + "[I])" , NAME_OUTPUT_STREAM );
458409 } else {
459410 this .getCurrentStruct ().getReadFunc ().indent ()
@@ -1129,7 +1080,7 @@ private String arg2str(final Object obj) {
11291080 }
11301081 } else if (obj instanceof String ) {
11311082 return String .format ("%s.getNamedValue(this, \" %s\" )" ,
1132- (getCurrentStruct ().isRoot () ? "this" : "this." + NAME_ROOT_STRUCT ), obj . toString () );
1083+ (getCurrentStruct ().isRoot () ? "this" : "this." + NAME_ROOT_STRUCT ), obj );
11331084 } else if (obj instanceof JBBPNamedFieldInfo ) {
11341085 final NamedFieldInfo namedFieldInfo = foundNamedFields .get (obj );
11351086 final String fieldPath = namedFieldInfo .makeSrcPath (getCurrentStruct ());
@@ -1186,7 +1137,7 @@ public ExpressionEvaluatorVisitor visitEnd() {
11861137
11871138 final Object result = this .stack .remove (0 );
11881139 if (result instanceof ExprTreeItem ) {
1189- buffer .append ('(' ).append (result . toString () ).append (')' );
1140+ buffer .append ('(' ).append (result ).append (')' );
11901141 } else {
11911142 buffer .append (arg2str (result ));
11921143 }
@@ -1778,7 +1729,7 @@ private static class Struct {
17781729 private final String path ;
17791730
17801731 private Struct (final Struct parent , final String className , final String classModifiers ) {
1781- this .path = parent == null ? "" : parent .path + (parent .path .length () == 0 ? "" : "." ) +
1732+ this .path = parent == null ? "" : parent .path + (parent .path .isEmpty () ? "" : "." ) +
17821733 className .toLowerCase (Locale .ENGLISH );
17831734 this .classModifiers = classModifiers ;
17841735 this .className = className ;
@@ -1909,7 +1860,7 @@ void write(
19091860 buffer .println ();
19101861 }
19111862
1912- if (customText != null && customText .length () != 0 ) {
1863+ if (customText != null && ! customText .isEmpty () ) {
19131864 buffer .printCommentLinesWithIndent ("------ Custom section START" );
19141865 buffer .printLinesWithIndent (customText );
19151866 buffer .printCommentLinesWithIndent ("------ Custom section END" );
0 commit comments