Commits

Taku Miyakawa  committed a256d5f

Improves usage of StringBuilder

  • Participants
  • Parent commits 0d932da

Comments (0)

Files changed (11)

File src/build/pmd.xml

     </rule>
 
     <rule ref="rulesets/java/strings.xml">
-
         <exclude name="AvoidDuplicateLiterals" />
-
-        <!-- TODO enable it and improve the source code -->
-        <exclude name="ConsecutiveAppendsShouldReuse" />
-
-        <!-- TODO enable it and improve the source code -->
-        <exclude name="AppendCharacterWithChar" />
     </rule>
 
 

File src/main/java/org/kink_lang/common/Signature.java

     @Override
     public String toString() {
         if ( this.stringRepresentation == null ) {
-            StringBuilder builder = new StringBuilder();
-            builder.append( this.name );
-            builder.append( '(' );
+            StringBuilder builder = new StringBuilder()
+                .append( this.name )
+                .append( '(' );
             for ( String descriptor : this.parameterDescriptors ) {
                 builder.append( descriptor );
             }

File src/main/java/org/kink_lang/kink/Trace.java

     public String toString() {
         StringBuilder builder = new StringBuilder( "<trace" );
         if ( this.symbol != null ) {
-            builder.append( ":symbol=" );
-            builder.append( Strings.show( this.symbol ) );
+            builder.append( ":symbol=" )
+                .append( Strings.show( this.symbol ) );
         }
         if ( this.area != null ) {
-            builder.append( ":area=" );
-            builder.append( this.area.toString() );
+            builder.append( ":area=" )
+                .append( this.area.toString() );
         }
-        builder.append( ">" );
+        builder.append( '>' );
         return builder.toString();
     }
 

File src/main/java/org/kink_lang/kink/ValueList.java

         showing.put( this , null );
         try {
             StringBuilder builder = new StringBuilder();
-            builder.append( "[" );
+            builder.append( '[' );
             String delimiter = "";
             for ( Value element : this.getElements() ) {
                 builder.append( delimiter );
                 delimiter = " ";
                 builder.append( element.toString() );
             }
-            builder.append( "]" );
+            builder.append( ']' );
             return builder.toString();
         } finally {
             showing.remove( this );

File src/main/java/org/kink_lang/kink/internal/Messages.java

         StringBuilder builder = new StringBuilder( "(" );
         String prefix = "";
         for ( Value arg : args ) {
-            builder.append( prefix );
-            builder.append( arg );
+            builder.append( prefix )
+                .append( arg );
             prefix = " ";
         }
-        builder.append( ")" );
+        builder.append( ')' );
         String argsRepr = builder.toString();
         return String.format( string( "noMatchingJavaMethod" ) , receiver , symbol , argsRepr );
     }

File src/main/java/org/kink_lang/kink/internal/box/ValueListEnhancer.java

             String head = "";
             int index = 0;
             for ( Value element : list.getElements() ) {
-                builder.append( head );
-                builder.append( element.call( STR ).asString( "#" + index ) );
+                builder.append( head )
+                    .append( element.call( STR ).asString( "#" + index ) );
                 head = separator;
                 ++ index;
             }

File src/main/java/org/kink_lang/kink/internal/jsr223/KinkEngineFactory.java

 
     @Override
     public String getMethodCallSyntax( String obj , String m , String... args ) {
-        StringBuilder builder = new StringBuilder();
-        builder.append( term( obj ) );
-        builder.append( '.' );
-        builder.append( m );
-        builder.append( '(' );
+        StringBuilder builder = new StringBuilder()
+            .append( term( obj ) )
+            .append( '.' )
+            .append( m )
+            .append( '(' );
         for ( String arg : args ) {
-            builder.append( ' ' );
-            builder.append( term( arg ) );
-            builder.append( ' ' );
+            builder.append( ' ' )
+                .append( term( arg ) )
+                .append( ' ' );
         }
         builder.append( ')' );
         return builder.toString();
     public String getProgram( String... statements ) {
         StringBuilder builder = new StringBuilder();
         for ( String statement : statements ) {
-            builder.append( statement );
-            builder.append( '\n' );
+            builder.append( statement )
+                .append( '\n' );
         }
         return builder.toString();
     }

File src/main/java/org/kink_lang/kink/internal/var/Key.java

         }
         Arrays.sort( keys );
         StringBuilder builder = new StringBuilder();
+
+        // TODO should use StringJoiner
         String delimiter = "";
         for ( Key key : keys ) {
-            builder.append( delimiter );
-            builder.append( encodeKey( key ) );
+            builder.append( delimiter )
+                .append( encodeKey( key ) );
             delimiter = " ";
         }
         return builder.toString().intern();
         Objects.requireNonNull( keys , "keys should not be null" );
         StringBuilder builder = new StringBuilder();
         for ( Key key : keys ) {
-            builder.append( '+' );
-            builder.append( encodeKey( key ) );
+            builder.append( '+' )
+                .append( encodeKey( key ) );
         }
         return builder.toString();
     }

File src/test/java/org/kink_lang/kink/FunTest.java

         public Value run( Value receiver , Value ... args ) {
             StringBuilder builder = new StringBuilder( receiver.asString( "" ) );
             for ( Value arg : args ) {
-                builder.append( ' ' );
-                builder.append( arg.asString( "" ) );
+                builder.append( ' ' )
+                    .append( arg.asString( "" ) );
             }
             return Value.value( builder.toString() );
         }

File src/test/java/org/kink_lang/kink/internal/define/MethodFunGeneratorTest.java

         public static Value varJoin( @Receiver Value xValue
                 , Value yValue
                 , Value... varValues ) {
-            StringBuilder builder = new StringBuilder();
-            builder.append( xValue.as( String.class , "x" ) );
-            builder.append( yValue.as( String.class , "y" ) );
+            StringBuilder builder = new StringBuilder()
+                .append( xValue.as( String.class , "x" ) )
+                .append( yValue.as( String.class , "y" ) );
             for ( Value var : varValues ) {
                 builder.append( var.as( String.class , "var" ) );
             }
             .setMandatoryArgumentCount( 2 );
 
         public static Value varJoin( Value xValue , Value yValue , Value... varValues ) {
-            StringBuilder builder = new StringBuilder();
-            builder.append( xValue.as( String.class , "x" ) );
-            builder.append( yValue.as( String.class , "y" ) );
+            StringBuilder builder = new StringBuilder()
+                .append( xValue.as( String.class , "x" ) )
+                .append( yValue.as( String.class , "y" ) );
             for ( Value var : varValues ) {
                 builder.append( var.as( String.class , "var" ) );
             }
             .setMandatoryArgumentCount( 2 );
 
         public static Value join( Value xValue , Value yValue , Value... rest ) {
-            StringBuilder builder = new StringBuilder();
-            builder.append( xValue.as( String.class , "" ) );
-            builder.append( yValue.as( String.class , "" ) );
+            StringBuilder builder = new StringBuilder()
+                .append( xValue.as( String.class , "" ) )
+                .append( yValue.as( String.class , "" ) );
             for ( Value var : rest ) {
                 builder.append( var.as( String.class , "" ) );
             }
 
         public static Value
         optrest( @Optional Value arg0 , @Optional Value arg1 , Value ... rest ) {
-            StringBuilder builder = new StringBuilder();
-            builder.append( arg0 == null ? "" : arg0.asString( "" ) );
-            builder.append( arg1 == null ? "" : arg1.asString( "" ) );
+            StringBuilder builder = new StringBuilder()
+                .append( arg0 == null ? "" : arg0.asString( "" ) )
+                .append( arg1 == null ? "" : arg1.asString( "" ) );
             for ( Value arg : rest ) {
                 builder.append( arg.asString( "" ) );
             }

File src/test/java/org/kink_lang/kink/internal/define/ReflectionMethodFunProxyTest.java

             .setMandatoryArgumentCount( 2 );
 
         public Value mandatoryArguments2( Value arg0 , Value arg1 ) {
-            StringBuilder builder = new StringBuilder( "#" );
-            builder.append( arg0.asString( "" ) );
-            builder.append( arg1.asString( "" ) );
+            StringBuilder builder = new StringBuilder( "#" )
+                .append( arg0.asString( "" ) )
+                .append( arg1.asString( "" ) );
             return Value.value( builder.toString() );
         }
     }
             .setMandatoryArgumentCount( 3 );
 
         public Value mandatoryArguments3( Value arg0 , Value arg1 , Value arg2 ) {
-            StringBuilder builder = new StringBuilder( "#" );
-            builder.append( arg0.asString( "" ) );
-            builder.append( arg1.asString( "" ) );
-            builder.append( arg2.asString( "" ) );
+            StringBuilder builder = new StringBuilder( "#" )
+                .append( arg0.asString( "" ) )
+                .append( arg1.asString( "" ) )
+                .append( arg2.asString( "" ) );
             return Value.value( builder.toString() );
         }
     }
             .setOptionalArgumentCount( 1 );
 
         public Value mandatory1Optional1( Value arg0 , @Optional Value arg1 ) {
-            StringBuilder builder = new StringBuilder( "#" );
-            builder.append( arg0.asString( "" ) );
-            builder.append( arg1 == null ? "" : arg1.asString( "" ) );
+            StringBuilder builder = new StringBuilder( "#" )
+                .append( arg0.asString( "" ) )
+                .append( arg1 == null ? "" : arg1.asString( "" ) );
             return Value.value( builder.toString() );
         }
     }
 
         public Value mandatory1Optional1Rest(
                 Value arg0 , @Optional Value arg1 , Value ... rest ) {
-            StringBuilder builder = new StringBuilder( "#" );
-            builder.append( arg0.asString( "" ) );
-            builder.append( arg1 == null ? "" : arg1.asString( "" ) );
+            StringBuilder builder = new StringBuilder( "#" )
+                .append( arg0.asString( "" ) )
+                .append( arg1 == null ? "" : arg1.asString( "" ) );
             for ( Value arg : rest ) {
                 builder.append( arg.asString( "" ) );
             }