@Override public Node transform(Node node) { if (node instanceof RamlDocumentNode) { Node baseUriNode = NodeSelector.selectFrom("baseUri", node); if (baseUriNode != null) { String value = NodeSelector.selectStringValue("value", baseUriNode); List<String> templates = getUriTemplates(value); checkUriParameters("baseUriParameters", node, templates); } } else if (node instanceof ResourceNode) { List<String> templates = getUriTemplates(((ResourceNode) node).getRelativeUri()); checkUriParameters("uriParameters", ((ResourceNode) node).getValue(), templates); } return node; }
@Nullable private Node selectValue(Node node) { for (String expr : selectorExpression) { Node from = NodeSelector.selectFrom(expr, node); if (from != null) { return from; } } return null; }
private void checkUriParameters(String key, Node node, List<String> templates) { Node parametersNode = NodeSelector.selectFrom(key, node); if (parametersNode != null) { for (Node child : parametersNode.getChildren()) { String parameterName = ((SimpleTypeNode) ((KeyValueNode) child).getKey()).getLiteralValue(); if (!templates.contains(parameterName)) { child.annotate( new WarningMessageAnnotation("Unused uri parameter '" + parameterName + "'")); } } } }