@@ -44,12 +44,6 @@ public abstract class Expression extends Selectable {
44
44
/** Returns whether this expression requires an input value. */
45
45
public boolean requiresInput () { return true ; }
46
46
47
- /**
48
- * Returns whether this expression outputs a different value than what it gets as input.
49
- * Annotating a string value does not count as modifying it.
50
- */
51
- public boolean isMutating () { return true ; }
52
-
53
47
/**
54
48
* Returns an expression where the children of this has been converted using the given converter.
55
49
* This default implementation returns this as it has no children.
@@ -158,38 +152,50 @@ public final void verify(DocumentType type) {
158
152
verify (new DocumentTypeAdapter (type ));
159
153
}
160
154
161
- public final void verify (Document doc ) {
162
- verify (new SimpleAdapterFactory (), doc );
155
+ public final Document verify (Document doc ) {
156
+ return verify (new SimpleAdapterFactory (), doc );
163
157
}
164
158
165
- public final void verify (AdapterFactory factory , Document doc ) {
166
- verify (factory .newDocumentAdapter (doc ));
159
+ public final Document verify (AdapterFactory factory , Document doc ) {
160
+ return verify (factory .newDocumentAdapter (doc ));
167
161
}
168
162
169
- public final void verify (DocumentAdapter adapter ) {
163
+ public final Document verify (DocumentAdapter adapter ) {
170
164
verify ((FieldTypeAdapter )adapter );
171
- adapter .getFullOutput ();
165
+ return adapter .getFullOutput ();
172
166
}
173
167
174
- public final void verify (DocumentUpdate upd ) {
175
- verify (new SimpleAdapterFactory (), upd );
168
+ public final DocumentUpdate verify (DocumentUpdate upd ) {
169
+ return verify (new SimpleAdapterFactory (), upd );
176
170
}
177
171
178
- public final void verify (AdapterFactory factory , DocumentUpdate upd ) {
179
- for (UpdateAdapter adapter : factory .newUpdateAdapterList (upd ))
180
- verify (adapter );
172
+ public final DocumentUpdate verify (AdapterFactory factory , DocumentUpdate upd ) {
173
+ DocumentUpdate ret = null ;
174
+ for (UpdateAdapter adapter : factory .newUpdateAdapterList (upd )) {
175
+ DocumentUpdate output = verify (adapter );
176
+ if (output == null ) {
177
+ // ignore
178
+ } else if (ret != null ) {
179
+ ret .addAll (output );
180
+ } else {
181
+ ret = output ;
182
+ }
183
+ }
184
+ return ret ;
181
185
}
182
186
183
- public final void verify (UpdateAdapter adapter ) {
187
+ public final DocumentUpdate verify (UpdateAdapter adapter ) {
184
188
verify ((FieldTypeAdapter )adapter );
189
+ return adapter .getOutput ();
185
190
}
186
191
187
- public final void verify (FieldTypeAdapter adapter ) {
188
- verify (new VerificationContext (adapter ));
192
+ public final DataType verify (FieldTypeAdapter adapter ) {
193
+ return verify (new VerificationContext (adapter ));
189
194
}
190
195
191
- public final void verify (VerificationContext context ) {
196
+ public final DataType verify (VerificationContext context ) {
192
197
doVerify (context );
198
+ return context .getCurrentType ();
193
199
}
194
200
195
201
protected void doVerify (VerificationContext context ) {}
@@ -240,6 +246,14 @@ public final FieldValue execute(ExecutionContext context) {
240
246
if (input == null ) return null ;
241
247
}
242
248
doExecute (context );
249
+ DataType outputType = createdOutputType ();
250
+ if (outputType != null ) {
251
+ FieldValue output = context .getCurrentValue ();
252
+ if (output != null && !outputType .isValueCompatible (output )) {
253
+ throw new IllegalStateException ("Expression '" + this + "' expected " + outputType .getName () +
254
+ " output, got " + output .getDataType ().getName ());
255
+ }
256
+ }
243
257
return context .getCurrentValue ();
244
258
}
245
259
@@ -262,6 +276,17 @@ public static Expression newInstance(ScriptParserContext context) throws ParseEx
262
276
return ScriptParser .parseExpression (context );
263
277
}
264
278
279
+ protected static boolean equals (Object lhs , Object rhs ) {
280
+ if (lhs == null ) {
281
+ return rhs == null ;
282
+ } else {
283
+ if (rhs == null ) {
284
+ return false ;
285
+ }
286
+ return lhs .equals (rhs );
287
+ }
288
+ }
289
+
265
290
// Convenience For testing
266
291
public static Document execute (Expression expression , Document doc ) {
267
292
expression .verify (doc );
0 commit comments