@@ -203,8 +203,8 @@ CodeBlock build() {
203
203
Object actualReturnType = isProjecting ? context .getActualReturnType ().getType () : domainType ;
204
204
205
205
builder .add ("\n " );
206
- builder .addStatement ("$T<$T > $L = $L .remove($T .class)" , ExecutableRemove .class , domainType ,
207
- context .localVariable ("remover" ), mongoOpsRef , domainType );
206
+ builder .addStatement ("$1T<$2T > $3L = $4L .remove($2T .class)" , ExecutableRemove .class , domainType ,
207
+ context .localVariable ("remover" ), mongoOpsRef );
208
208
209
209
DeleteExecution .Type type = DeleteExecution .Type .FIND_AND_REMOVE_ALL ;
210
210
if (!queryMethod .isCollectionQuery ()) {
@@ -270,8 +270,8 @@ CodeBlock build() {
270
270
271
271
String updateReference = updateVariableName ;
272
272
Class <?> domainType = context .getRepositoryInformation ().getDomainType ();
273
- builder .addStatement ("$T<$T > $L = $L .update($T .class)" , ExecutableUpdate .class , domainType ,
274
- context .localVariable ("updater" ), mongoOpsRef , domainType );
273
+ builder .addStatement ("$1T<$2T > $3L = $4L .update($2T .class)" , ExecutableUpdate .class , domainType ,
274
+ context .localVariable ("updater" ), mongoOpsRef );
275
275
276
276
Class <?> returnType = ClassUtils .resolvePrimitiveIfNecessary (queryMethod .getReturnedObjectType ());
277
277
if (ReflectionUtils .isVoid (returnType )) {
@@ -344,16 +344,17 @@ CodeBlock build() {
344
344
builder .addStatement ("$T<$T> $L = $L.aggregateStream($L, $T.class)" , Stream .class , Document .class ,
345
345
context .localVariable ("results" ), mongoOpsRef , aggregationVariableName , outputType );
346
346
347
- builder .addStatement ("return $L .map(it -> ($T ) convertSimpleRawResult($T .class, it))" ,
348
- context .localVariable ("results" ), returnType , returnType );
347
+ builder .addStatement ("return $1L .map(it -> ($2T ) convertSimpleRawResult($2T .class, it))" ,
348
+ context .localVariable ("results" ), returnType );
349
349
} else {
350
350
351
351
builder .addStatement ("$T $L = $L.aggregate($L, $T.class)" , AggregationResults .class ,
352
352
context .localVariable ("results" ), mongoOpsRef , aggregationVariableName , outputType );
353
353
354
354
if (!queryMethod .isCollectionQuery ()) {
355
- builder .addStatement ("return $T.<$T>firstElement(convertSimpleRawResults($T.class, $L.getMappedResults()))" ,
356
- CollectionUtils .class , returnType , returnType , context .localVariable ("results" ));
355
+ builder .addStatement (
356
+ "return $1T.<$2T>firstElement(convertSimpleRawResults($2T.class, $3L.getMappedResults()))" ,
357
+ CollectionUtils .class , returnType , context .localVariable ("results" ));
357
358
} else {
358
359
builder .addStatement ("return convertSimpleRawResults($T.class, $L.getMappedResults())" , returnType ,
359
360
context .localVariable ("results" ));
@@ -366,10 +367,9 @@ CodeBlock build() {
366
367
builder .addStatement ("boolean $L = $L.getMappedResults().size() > $L.getPageSize()" ,
367
368
context .localVariable ("hasNext" ), context .localVariable ("results" ), context .getPageableParameterName ());
368
369
builder .addStatement (
369
- "return new $T <>($L ? $L .getMappedResults().subList(0, $L .getPageSize()) : $L .getMappedResults(), $L , $L )" ,
370
+ "return new $1T <>($2L ? $3L .getMappedResults().subList(0, $4L .getPageSize()) : $3L .getMappedResults(), $4L , $2L )" ,
370
371
SliceImpl .class , context .localVariable ("hasNext" ), context .localVariable ("results" ),
371
- context .getPageableParameterName (), context .localVariable ("results" ), context .getPageableParameterName (),
372
- context .localVariable ("hasNext" ));
372
+ context .getPageableParameterName ());
373
373
} else {
374
374
375
375
if (queryMethod .isStreamQuery ()) {
@@ -584,9 +584,9 @@ CodeBlock build() {
584
584
585
585
if (!pipelineOnly ) {
586
586
587
- builder .addStatement ("$T<$T > $L = $T .newAggregation($T .class, $L .getOperations())" , TypedAggregation . class ,
588
- context .getRepositoryInformation ().getDomainType (), aggregationVariableName , Aggregation . class ,
589
- context . getRepositoryInformation (). getDomainType () , pipelineName );
587
+ builder .addStatement ("$1T<$2T > $3L = $4T .newAggregation($2T .class, $5L .getOperations())" ,
588
+ TypedAggregation . class , context .getRepositoryInformation ().getDomainType (), aggregationVariableName ,
589
+ Aggregation . class , pipelineName );
590
590
591
591
builder .add (aggregationOptions (aggregationVariableName ));
592
592
}
@@ -662,8 +662,8 @@ private CodeBlock aggregationOptions(String aggregationVariableName) {
662
662
if (!options .isEmpty ()) {
663
663
664
664
Builder optionsBuilder = CodeBlock .builder ();
665
- optionsBuilder .add ("$T $L = $T .builder()\n " , AggregationOptions .class ,
666
- context .localVariable ("aggregationOptions" ), AggregationOptions . class );
665
+ optionsBuilder .add ("$1T $2L = $1T .builder()\n " , AggregationOptions .class ,
666
+ context .localVariable ("aggregationOptions" ));
667
667
optionsBuilder .indent ();
668
668
for (CodeBlock optionBlock : options ) {
669
669
optionsBuilder .add (optionBlock );
@@ -673,7 +673,7 @@ private CodeBlock aggregationOptions(String aggregationVariableName) {
673
673
optionsBuilder .unindent ();
674
674
builder .add (optionsBuilder .build ());
675
675
676
- builder .addStatement ("$L = $L .withOptions($L)" , aggregationVariableName , aggregationVariableName ,
676
+ builder .addStatement ("$1L = $1L .withOptions($2L)" , aggregationVariableName ,
677
677
context .localVariable ("aggregationOptions" ));
678
678
}
679
679
return builder .build ();
@@ -701,10 +701,10 @@ private CodeBlock sortingStage(String sortProvider) {
701
701
Builder builder = CodeBlock .builder ();
702
702
703
703
builder .beginControlFlow ("if ($L.isSorted())" , sortProvider );
704
- builder .addStatement ("$T $L = new $T ()" , Document .class , context .localVariable ("sortDocument" ), Document . class );
704
+ builder .addStatement ("$1T $2L = new $1T ()" , Document .class , context .localVariable ("sortDocument" ));
705
705
builder .beginControlFlow ("for ($T $L : $L)" , Order .class , context .localVariable ("order" ), sortProvider );
706
- builder .addStatement ("$L .append($L .getProperty(), $L .isAscending() ? 1 : -1);" ,
707
- context .localVariable ("sortDocument" ), context .localVariable ("order" ), context . localVariable ( "order" ) );
706
+ builder .addStatement ("$1L .append($2L .getProperty(), $2L .isAscending() ? 1 : -1);" ,
707
+ context .localVariable ("sortDocument" ), context .localVariable ("order" ));
708
708
builder .endControlFlow ();
709
709
builder .addStatement ("stages.add(new $T($S, $L))" , Document .class , "$sort" ,
710
710
context .localVariable ("sortDocument" ));
@@ -768,28 +768,26 @@ static class QueryCodeBlockBuilder {
768
768
for (MongoParameter parameter : queryMethod .getParameters ().getBindableParameters ()) {
769
769
String parameterName = context .getParameterName (parameter .getIndex ());
770
770
if (ClassUtils .isAssignable (Circle .class , parameter .getType ())) {
771
- arguments .add (CodeBlock .builder ()
772
- .add ("$T.of($T.of($L.getCenter().getX(), $L.getCenter().getY()), $L.getRadius().getNormalizedValue())" ,
773
- List .class , List .class , parameterName , parameterName , parameterName )
774
- .build ());
771
+ arguments .add (CodeBlock .builder ().add (
772
+ "$1T.of($1T.of($2L.getCenter().getX(), $2L.getCenter().getY()), $2L.getRadius().getNormalizedValue())" ,
773
+ List .class , parameterName ).build ());
775
774
} else if (ClassUtils .isAssignable (Box .class , parameter .getType ())) {
776
775
777
776
// { $geoWithin: { $box: [ [ <x1>, <y1> ], [ <x2>, <y2> ] ] }
778
777
arguments .add (CodeBlock .builder ().add (
779
- "$T .of($T .of($L .getFirst().getX(), $L .getFirst().getY()), $T .of($L .getSecond().getX(), $L .getSecond().getY()))" ,
780
- List .class , List . class , parameterName , parameterName , List . class , parameterName , parameterName ).build ());
778
+ "$1T .of($1T .of($2L .getFirst().getX(), $2L .getFirst().getY()), $1T .of($2L .getSecond().getX(), $2L .getSecond().getY()))" ,
779
+ List .class , parameterName ).build ());
781
780
} else if (ClassUtils .isAssignable (Sphere .class , parameter .getType ())) {
782
781
// { $centerSphere: [ [ <x>, <y> ], <radius> ] }
783
- arguments .add (CodeBlock .builder ()
784
- .add ("$T.of($T.of($L.getCenter().getX(), $L.getCenter().getY()), $L.getRadius().getNormalizedValue())" ,
785
- List .class , List .class , parameterName , parameterName , parameterName )
786
- .build ());
782
+ arguments .add (CodeBlock .builder ().add (
783
+ "$1T.of($1T.of($2L.getCenter().getX(), $2L.getCenter().getY()), $2L.getRadius().getNormalizedValue())" ,
784
+ List .class , parameterName ).build ());
787
785
} else if (ClassUtils .isAssignable (Polygon .class , parameter .getType ())) {
788
786
// $polygon: [ [ <x1> , <y1> ], [ <x2> , <y2> ], [ <x3> , <y3> ], ... ]
789
787
String localVar = context .localVariable ("_p" );
790
- arguments
791
- . add ( CodeBlock .builder ().add ("$L .getPoints().stream().map($L -> $T .of($L .getX(), $L .getY())).toList()" ,
792
- parameterName , localVar , List .class , localVar , localVar ).build ());
788
+ arguments . add (
789
+ CodeBlock .builder ().add ("$1L .getPoints().stream().map($2L -> $3T .of($2L .getX(), $2L .getY())).toList()" ,
790
+ parameterName , localVar , List .class ).build ());
793
791
}
794
792
795
793
else {
@@ -890,11 +888,10 @@ private CodeBlock renderExpressionToQuery(@Nullable String source, String variab
890
888
Builder builder = CodeBlock .builder ();
891
889
if (!StringUtils .hasText (source )) {
892
890
893
- builder .addStatement ("$T $L = new $T(new $T())" , BasicQuery .class , variableName , BasicQuery .class ,
894
- Document .class );
891
+ builder .addStatement ("$1T $2L = new $1T(new $3T())" , BasicQuery .class , variableName , Document .class );
895
892
} else if (!containsPlaceholder (source )) {
896
- builder .addStatement ("$T $L = new $T($T .parse($S ))" , BasicQuery .class , variableName , BasicQuery .class ,
897
- Document . class , source );
893
+ builder .addStatement ("$1T $2L = new $1T($3T .parse($4S ))" , BasicQuery .class , variableName , Document .class ,
894
+ source );
898
895
} else {
899
896
builder .add ("$T $L = createQuery($S, new $T[]{ " , BasicQuery .class , variableName , source , Object .class );
900
897
Iterator <CodeBlock > iterator = arguments .iterator ();
@@ -939,8 +936,7 @@ CodeBlock build() {
939
936
builder .add ("\n " );
940
937
String tmpVariableName = updateVariableName + "Document" ;
941
938
builder .add (renderExpressionToDocument (source .getUpdate ().getUpdateString (), tmpVariableName , arguments ));
942
- builder .addStatement ("$T $L = new $T($L)" , BasicUpdate .class , updateVariableName , BasicUpdate .class ,
943
- tmpVariableName );
939
+ builder .addStatement ("$1T $2L = new $1T($3L)" , BasicUpdate .class , updateVariableName , tmpVariableName );
944
940
945
941
return builder .build ();
946
942
}
@@ -951,9 +947,9 @@ private static CodeBlock renderExpressionToDocument(@Nullable String source, Str
951
947
952
948
Builder builder = CodeBlock .builder ();
953
949
if (!StringUtils .hasText (source )) {
954
- builder .addStatement ("$T $L = new $T ()" , Document .class , variableName , Document . class );
950
+ builder .addStatement ("$1T $2L = new $1T ()" , Document .class , variableName );
955
951
} else if (!containsPlaceholder (source )) {
956
- builder .addStatement ("$T $L = $T .parse($S )" , Document .class , variableName , Document . class , source );
952
+ builder .addStatement ("$1T $2L = $1T .parse($3S )" , Document .class , variableName , source );
957
953
} else {
958
954
959
955
builder .add ("$T $L = bindParameters($S, new $T[]{ " , Document .class , variableName , source , Object .class );
@@ -965,8 +961,6 @@ private static CodeBlock renderExpressionToDocument(@Nullable String source, Str
965
961
}
966
962
}
967
963
builder .add ("});\n " );
968
- // builder.addStatement("$T $L = bindParameters($S, new $T[]{ $L })", Document.class, variableName, source,
969
- // Object.class, StringUtils.collectionToDelimitedString(arguments, ", "));
970
964
}
971
965
return builder .build ();
972
966
}
0 commit comments