use of com.structurizr.model.ModelItem in project dsl by structurizr.
the class RefParser method parse.
ModelItem parse(DslContext context, Tokens tokens) {
if (tokens.hasMoreThan(IDENTIFIER_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
String s = tokens.get(IDENTIFIER_INDEX);
ModelItem modelItem;
if (s.contains("://")) {
modelItem = context.getWorkspace().getModel().getElementWithCanonicalName(s);
} else {
modelItem = context.getElement(s);
if (modelItem == null) {
modelItem = context.getRelationship(s);
}
}
if (modelItem == null) {
throw new RuntimeException("An element/relationship referenced by \"" + s + "\" could not be found");
}
return modelItem;
}
use of com.structurizr.model.ModelItem in project dsl by structurizr.
the class RefParserTests method test_parse_FindsAnElementByCanonicalName.
@Test
void test_parse_FindsAnElementByCanonicalName() {
Person user = workspace.getModel().addPerson("User");
ModelItem element = parser.parse(context(), tokens("ref", "Person://User"));
assertSame(user, element);
}
use of com.structurizr.model.ModelItem in project dsl by structurizr.
the class RefParserTests method test_parse_FindsARelationshipByIdentifier.
@Test
void test_parse_FindsARelationshipByIdentifier() {
Person user = workspace.getModel().addPerson("User");
Relationship relationship = user.interactsWith(user, "Description");
ModelDslContext context = context();
IdentifiersRegister register = new IdentifiersRegister();
register.register("rel", relationship);
context.setIdentifierRegister(register);
ModelItem modelItem = parser.parse(context, tokens("ref", "rel"));
assertSame(modelItem, relationship);
}
use of com.structurizr.model.ModelItem in project dsl by structurizr.
the class AbstractExpressionParser method parseIdentifier.
protected Set<ModelItem> parseIdentifier(String identifier, DslContext context) {
Set<ModelItem> modelItems = new LinkedHashSet<>();
Element element = context.getElement(identifier);
if (element != null) {
modelItems.addAll(getElements(identifier, context));
}
Relationship relationship = context.getRelationship(identifier);
if (relationship != null) {
modelItems.add(relationship);
}
if (modelItems.isEmpty()) {
throw new RuntimeException("The element/relationship \"" + identifier + "\" does not exist");
} else {
return modelItems;
}
}
use of com.structurizr.model.ModelItem in project dsl by structurizr.
the class RefParserTests method test_parse_FindsAnElementByIdentifier.
@Test
void test_parse_FindsAnElementByIdentifier() {
Person user = workspace.getModel().addPerson("User");
ModelDslContext context = context();
IdentifiersRegister register = new IdentifiersRegister();
register.register("user", user);
context.setIdentifierRegister(register);
ModelItem modelItem = parser.parse(context, tokens("ref", "user"));
assertSame(modelItem, user);
}
Aggregations