Skip to content

Commit a85855a

Browse files
committedJun 7, 2017
DATAMONGO-1710 - Adopt to changed AnnotationUtils.getValue(…) and OperatorNode.getRightOperand() behavior.
Related ticket: SPR-15540.
1 parent 31390d4 commit a85855a

File tree

4 files changed

+64
-65
lines changed

4 files changed

+64
-65
lines changed
 

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformer.java

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2016 the original author or authors.
2+
* Copyright 2013-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,9 +49,10 @@
4949

5050
/**
5151
* Renders the AST of a SpEL expression as a MongoDB Aggregation Framework projection expression.
52-
*
52+
*
5353
* @author Thomas Darimont
5454
* @author Christoph Strobl
55+
* @author Mark Paluch
5556
*/
5657
class SpelExpressionTransformer implements AggregationExpressionTransformer {
5758

@@ -84,7 +85,7 @@ public SpelExpressionTransformer() {
8485
* {@link AggregationOperationContext} {@code context}.
8586
* <p>
8687
* Exposes the given @{code params} as <code>[0] ... [n]</code>.
87-
*
88+
*
8889
* @param expression must not be {@literal null}
8990
* @param context must not be {@literal null}
9091
* @param params must not be {@literal null}
@@ -114,7 +115,7 @@ public Object transform(AggregationExpressionTransformationContext<ExpressionNod
114115
/**
115116
* Returns an appropriate {@link ExpressionNodeConversion} for the given {@code node}. Throws an
116117
* {@link IllegalArgumentException} if no conversion could be found.
117-
*
118+
*
118119
* @param node
119120
* @return the appropriate {@link ExpressionNodeConversion} for the given {@link ExpressionNode}.
120121
*/
@@ -133,7 +134,7 @@ private ExpressionNodeConversion<ExpressionNode> lookupConversionFor(ExpressionN
133134

134135
/**
135136
* Abstract base class for {@link SpelNode} to (Db)-object conversions.
136-
*
137+
*
137138
* @author Thomas Darimont
138139
* @author Oliver Gierke
139140
*/
@@ -145,7 +146,7 @@ private static abstract class ExpressionNodeConversion<T extends ExpressionNode>
145146

146147
/**
147148
* Creates a new {@link ExpressionNodeConversion}.
148-
*
149+
*
149150
* @param transformer must not be {@literal null}.
150151
*/
151152
@SuppressWarnings("unchecked")
@@ -161,7 +162,7 @@ public ExpressionNodeConversion(AggregationExpressionTransformer transformer) {
161162
/**
162163
* Returns whether the current conversion supports the given {@link ExpressionNode}. By default we will match the
163164
* node type against the genric type the subclass types the type parameter to.
164-
*
165+
*
165166
* @param node will never be {@literal null}.
166167
* @return true if {@literal this} conversion can be applied to the given {@code node}.
167168
*/
@@ -171,7 +172,7 @@ protected boolean supports(ExpressionNode node) {
171172

172173
/**
173174
* Triggers the transformation for the given {@link ExpressionNode} and the given current context.
174-
*
175+
*
175176
* @param node must not be {@literal null}.
176177
* @param context must not be {@literal null}.
177178
* @return
@@ -187,7 +188,7 @@ protected Object transform(ExpressionNode node, AggregationExpressionTransformat
187188
/**
188189
* Triggers the transformation with the given new {@link ExpressionNode}, new parent node, the current operation and
189190
* the previous context.
190-
*
191+
*
191192
* @param node must not be {@literal null}.
192193
* @param parent
193194
* @param operation
@@ -204,7 +205,7 @@ protected Object transform(ExpressionNode node, ExpressionNode parent, Document
204205
context.getAggregationContext()));
205206
}
206207

207-
/*
208+
/*
208209
* (non-Javadoc)
209210
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.NodeConversion#transform(org.springframework.data.mongodb.core.aggregation.AggregationExpressionTransformer.AggregationExpressionTransformationContext)
210211
*/
@@ -215,7 +216,7 @@ public Object transform(AggregationExpressionTransformationContext<ExpressionNod
215216

216217
/**
217218
* Performs the actual conversion from {@link SpelNode} to the corresponding representation for MongoDB.
218-
*
219+
*
219220
* @param context
220221
* @return
221222
*/
@@ -224,7 +225,7 @@ public Object transform(AggregationExpressionTransformationContext<ExpressionNod
224225

225226
/**
226227
* A {@link ExpressionNodeConversion} that converts arithmetic operations.
227-
*
228+
*
228229
* @author Thomas Darimont
229230
*/
230231
private static class OperatorNodeConversion extends ExpressionNodeConversion<OperatorNode> {
@@ -233,7 +234,7 @@ public OperatorNodeConversion(AggregationExpressionTransformer transformer) {
233234
super(transformer);
234235
}
235236

236-
/*
237+
/*
237238
* (non-Javadoc)
238239
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
239240
*/
@@ -258,8 +259,10 @@ protected Object convert(AggregationExpressionTransformationContext<OperatorNode
258259
return convertUnaryMinusOp(context, leftResult);
259260
}
260261

261-
// we deliberately ignore the RHS result
262-
transform(currentNode.getRight(), currentNode, operationObject, context);
262+
if (!currentNode.isUnaryOperator()) {
263+
// we deliberately ignore the RHS result
264+
transform(currentNode.getRight(), currentNode, operationObject, context);
265+
}
263266

264267
return operationObject;
265268
}
@@ -299,7 +302,7 @@ private Object convertUnaryMinusOp(ExpressionTransformationContextSupport<Operat
299302
return result;
300303
}
301304

302-
/*
305+
/*
303306
* (non-Javadoc)
304307
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#supports(java.lang.Class)
305308
*/
@@ -311,7 +314,7 @@ protected boolean supports(ExpressionNode node) {
311314

312315
/**
313316
* A {@link ExpressionNodeConversion} that converts indexed expressions.
314-
*
317+
*
315318
* @author Thomas Darimont
316319
* @author Oliver Gierke
317320
*/
@@ -321,7 +324,7 @@ public IndexerNodeConversion(AggregationExpressionTransformer transformer) {
321324
super(transformer);
322325
}
323326

324-
/*
327+
/*
325328
* (non-Javadoc)
326329
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
327330
*/
@@ -330,7 +333,7 @@ protected Object convert(AggregationExpressionTransformationContext<ExpressionNo
330333
return context.addToPreviousOrReturn(context.getCurrentNode().getValue());
331334
}
332335

333-
/*
336+
/*
334337
* (non-Javadoc)
335338
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.NodeConversion#supports(org.springframework.data.mongodb.core.spel.ExpressionNode)
336339
*/
@@ -342,7 +345,7 @@ protected boolean supports(ExpressionNode node) {
342345

343346
/**
344347
* A {@link ExpressionNodeConversion} that converts in-line list expressions.
345-
*
348+
*
346349
* @author Thomas Darimont
347350
*/
348351
private static class InlineListNodeConversion extends ExpressionNodeConversion<ExpressionNode> {
@@ -351,7 +354,7 @@ public InlineListNodeConversion(AggregationExpressionTransformer transformer) {
351354
super(transformer);
352355
}
353356

354-
/*
357+
/*
355358
* (non-Javadoc)
356359
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
357360
*/
@@ -368,7 +371,7 @@ protected Object convert(AggregationExpressionTransformationContext<ExpressionNo
368371
return transform(currentNode.getChild(0), currentNode, null, context);
369372
}
370373

371-
/*
374+
/*
372375
* (non-Javadoc)
373376
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.NodeConversion#supports(org.springframework.data.mongodb.core.spel.ExpressionNode)
374377
*/
@@ -380,7 +383,7 @@ protected boolean supports(ExpressionNode node) {
380383

381384
/**
382385
* A {@link ExpressionNodeConversion} that converts property or field reference expressions.
383-
*
386+
*
384387
* @author Thomas Darimont
385388
* @author Oliver Gierke
386389
*/
@@ -401,7 +404,7 @@ protected Object convert(AggregationExpressionTransformationContext<ExpressionNo
401404
return context.addToPreviousOrReturn(fieldReference);
402405
}
403406

404-
/*
407+
/*
405408
* (non-Javadoc)
406409
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.NodeConversion#supports(org.springframework.data.mongodb.core.spel.ExpressionNode)
407410
*/
@@ -413,7 +416,7 @@ protected boolean supports(ExpressionNode node) {
413416

414417
/**
415418
* A {@link ExpressionNodeConversion} that converts literal expressions.
416-
*
419+
*
417420
* @author Thomas Darimont
418421
* @author Oliver Gierke
419422
*/
@@ -423,7 +426,7 @@ public LiteralNodeConversion(AggregationExpressionTransformer transformer) {
423426
super(transformer);
424427
}
425428

426-
/*
429+
/*
427430
* (non-Javadoc)
428431
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
429432
*/
@@ -448,7 +451,7 @@ protected Object convert(AggregationExpressionTransformationContext<LiteralNode>
448451
return value;
449452
}
450453

451-
/*
454+
/*
452455
* (non-Javadoc)
453456
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#supports(org.springframework.expression.spel.SpelNode)
454457
*/
@@ -460,7 +463,7 @@ protected boolean supports(ExpressionNode node) {
460463

461464
/**
462465
* A {@link ExpressionNodeConversion} that converts method reference expressions.
463-
*
466+
*
464467
* @author Thomas Darimont
465468
* @author Oliver Gierke
466469
*/
@@ -470,7 +473,7 @@ public MethodReferenceNodeConversion(AggregationExpressionTransformer transforme
470473
super(transformer);
471474
}
472475

473-
/*
476+
/*
474477
* (non-Javadoc)
475478
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
476479
*/
@@ -489,7 +492,7 @@ protected Object convert(AggregationExpressionTransformationContext<MethodRefere
489492
Document dbo = new Document();
490493

491494
int i = 0;
492-
for(ExpressionNode child : node) {
495+
for (ExpressionNode child : node) {
493496
dbo.put(methodReference.getArgumentMap()[i++], transform(child, context));
494497
}
495498
args = dbo;
@@ -510,7 +513,7 @@ protected Object convert(AggregationExpressionTransformationContext<MethodRefere
510513

511514
/**
512515
* A {@link ExpressionNodeConversion} that converts method compound expressions.
513-
*
516+
*
514517
* @author Thomas Darimont
515518
* @author Oliver Gierke
516519
*/
@@ -520,7 +523,7 @@ public CompoundExpressionNodeConversion(AggregationExpressionTransformer transfo
520523
super(transformer);
521524
}
522525

523-
/*
526+
/*
524527
* (non-Javadoc)
525528
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.SpelNodeWrapper#convertSpelNodeToMongoObjectExpression(org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.ExpressionConversionContext)
526529
*/
@@ -537,7 +540,7 @@ protected Object convert(AggregationExpressionTransformationContext<ExpressionNo
537540
return context.addToPreviousOrReturn(currentNode.getValue());
538541
}
539542

540-
/*
543+
/*
541544
* (non-Javadoc)
542545
* @see org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.NodeConversion#supports(org.springframework.data.mongodb.core.spel.ExpressionNode)
543546
*/

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/LiteralNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2016 the original author or authors.
2+
* Copyright 2013-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
*
3535
* @author Oliver Gierke
3636
* @author Christoph Strobl
37+
* @author Mark Paluch
3738
*/
3839
public class LiteralNode extends ExpressionNode {
3940

@@ -56,7 +57,7 @@ public class LiteralNode extends ExpressionNode {
5657

5758
/**
5859
* Creates a new {@link LiteralNode} from the given {@link Literal} and {@link ExpressionState}.
59-
*
60+
*
6061
* @param node must not be {@literal null}.
6162
* @param state must not be {@literal null}.
6263
*/
@@ -67,7 +68,7 @@ public class LiteralNode extends ExpressionNode {
6768

6869
/**
6970
* Returns whether the given {@link ExpressionNode} is a unary minus.
70-
*
71+
*
7172
* @param parent
7273
* @return
7374
*/
@@ -78,7 +79,7 @@ public boolean isUnaryMinus(ExpressionNode parent) {
7879
}
7980

8081
OperatorNode operator = (OperatorNode) parent;
81-
return operator.isUnaryMinus() && operator.getRight() == null;
82+
return operator.isUnaryMinus();
8283
}
8384

8485
/*

0 commit comments

Comments
 (0)
Please sign in to comment.