Skip to content

Commit 0d063dc

Browse files
committed
Add data-shape-only visitor class
1 parent 367c4a5 commit 0d063dc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeVisitor.java

+26
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,30 @@ public R timestampShape(TimestampShape shape) {
199199
return getDefault(shape);
200200
}
201201
}
202+
203+
/**
204+
* Creates {@link ShapeVisitor} that only requires implementation of
205+
* all data shape branches, but does not support service shapes.
206+
*
207+
* @param <R> Return type.
208+
*/
209+
abstract class DataShapeVisitor<R> implements ShapeVisitor<R> {
210+
@Override
211+
public R operationShape(OperationShape shape) {
212+
throw new IllegalArgumentException("DataShapeVisitor cannot be use to visit "
213+
+ "Operation Shapes. Attempted to visit: " + shape);
214+
}
215+
216+
@Override
217+
public R resourceShape(ResourceShape shape) {
218+
throw new IllegalArgumentException("DataShapeVisitor cannot be use to visit "
219+
+ "Resource Shapes. Attempted to visit: " + shape);
220+
}
221+
222+
@Override
223+
public R serviceShape(ServiceShape shape) {
224+
throw new IllegalArgumentException("DataShapeVisitor cannot be use to visit "
225+
+ "Service Shapes. Attempted to visit: " + shape);
226+
}
227+
}
202228
}

0 commit comments

Comments
 (0)