Search in sources :

Example 1 with Shape

use of com.structurizr.view.Shape in project dsl by structurizr.

the class ElementStyleParser method parseShape.

void parseShape(ElementStyleDslContext context, Tokens tokens) {
    Map<String, Shape> shapes = new HashMap<>();
    String shapesAsString = "";
    for (Shape shape : Shape.values()) {
        shapes.put(shape.toString().toLowerCase(), shape);
        shapesAsString += shape;
        shapesAsString += "|";
    }
    shapesAsString = shapesAsString.substring(0, shapesAsString.length() - 1);
    ElementStyle style = context.getStyle();
    if (tokens.hasMoreThan(FIRST_PROPERTY_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: shape <" + shapesAsString + ">");
    }
    if (tokens.includes(FIRST_PROPERTY_INDEX)) {
        String shape = tokens.get(1).toLowerCase();
        if (shapes.containsKey(shape)) {
            style.setShape(shapes.get(shape));
        } else {
            throw new RuntimeException("The shape \"" + shape + "\" is not valid");
        }
    } else {
        throw new RuntimeException("Expected: shape <" + shapesAsString + ">");
    }
}
Also used : Shape(com.structurizr.view.Shape) HashMap(java.util.HashMap) ElementStyle(com.structurizr.view.ElementStyle)

Aggregations

ElementStyle (com.structurizr.view.ElementStyle)1 Shape (com.structurizr.view.Shape)1 HashMap (java.util.HashMap)1