private static void checkModelNodes(@NotNull SModel model, @NotNull final List<String> result) { for (final SNode node : SNodeUtil.getDescendants(model)) { final SConcept concept = node.getConcept(); if (concept == null) { result.add("unknown concept of node: " + SNodeUtil.getDebugText(node)); continue; } for (String name : node.getPropertyNames()) { if (concept.getProperty(name) == null) { result.add("unknown property: `" + name + "' in node " + SNodeUtil.getDebugText(node)); } } for (SReference ref : node.getReferences()) { SAbstractLink link = concept.getLink(ref.getRole()); if (link == null || !(link.isReference())) { result.add( "unknown link role: `" + ref.getRole() + "' in node " + SNodeUtil.getDebugText(node)); } } for (SNode child : node.getChildren()) { String role = child.getRoleInParent(); SAbstractLink link = concept.getLink(role); if (link == null || link.isReference()) { result.add("unknown child role: `" + role + "' in node " + SNodeUtil.getDebugText(node)); } } } }
private static Map<String, Set<SReference>> createRoleToReferenceMap(SNode expectedNode) { Map<String, Set<SReference>> expRoleToReferenceMap = new HashMap<String, Set<SReference>>(); for (SReference ref : expectedNode.getReferences()) { if (expRoleToReferenceMap.get(ref.getRole()) == null) { expRoleToReferenceMap.put(ref.getRole(), new HashSet<SReference>()); } expRoleToReferenceMap.get(ref.getRole()).add(ref); } return expRoleToReferenceMap; }
private void findPrefixReferences(String prefix, SNode node, Consumer<SReference> consumer) { LinkedList<SNode> queue = new LinkedList<SNode>(); queue.add(node); while (!queue.isEmpty()) { SNode n = queue.pop(); for (SReference ref : n.getReferences()) { processReference(prefix, ref, consumer); } for (SNode child : n.getChildren()) { queue.add(child); } } }
private static StringBuilder checkModel(final SModel sm) { StringBuilder errorMessages = new StringBuilder(); List<String> validationResult = ModelAccess.instance() .runReadAction( new Computable<List<String>>() { public List<String> compute() { return new ModelValidator(sm).validate(); } }); if (!(validationResult.isEmpty())) { errorMessages.append("errors in model: ").append(sm.getReference().toString()).append("\n"); for (String item : validationResult) { errorMessages.append("\t"); errorMessages.append(item); errorMessages.append("\n"); } } for (SNode node : SNodeUtil.getDescendants(sm)) { // Testbench.LOG.debug("Checking node " + node); if (SModelUtil.findConceptDeclaration(node.getConcept().getQualifiedName()) == null) { errorMessages.append("Unknown concept "); errorMessages.append(node.getConcept().getQualifiedName()); errorMessages.append("\n"); } } for (SNode node : SNodeUtil.getDescendants(sm)) { for (SReference ref : node.getReferences()) { if (jetbrains.mps.smodel.SNodeUtil.hasReferenceMacro(node, ref.getRole())) { continue; } if (SNodeOperations.getTargetNodeSilently(ref) == null) { errorMessages .append("Broken reference in model {") .append(SNodeOperations.getModelLongName(node.getModel())) .append("}") .append(" node ") .append(node.getNodeId().toString()) .append("(") .append(node) .append(")\n"); } } } return errorMessages; }