private static void assertDeepChildrenEquals(SNode expectedNode, SNode actualNode) { Set<String> roles = new HashSet<String>(); for (SNode child : expectedNode.getChildren()) { roles.add(child.getRoleInParent()); } for (SNode child : actualNode.getChildren()) { roles.add(child.getRoleInParent()); } for (String role : roles) { Iterable<? extends SNode> expectedChildren = expectedNode.getChildren(role); Iterable<? extends SNode> actualChildren = actualNode.getChildren(role); int esize = IterableUtil.asCollection(expectedChildren).size(); int asize = IterableUtil.asCollection(actualChildren).size(); assertEquals( getErrorString("child count in role " + role, expectedNode, actualNode), esize, asize); Iterator<? extends SNode> actualIterator = actualChildren.iterator(); for (SNode expectedChild : expectedChildren) { SNode actualChild = actualIterator.next(); assertEquals( getErrorString("children in role " + role, expectedNode, actualNode), expectedChild.getNodeId(), actualChild.getNodeId()); assertDeepNodeEquals(expectedChild, actualChild); } } }
private static List<INodeSubstituteAction> createPrimaryChildSubstituteActions( SNode parentNode, SNode currentChild, SNode childConcept, IChildNodeSetter childSetter, IOperationContext context) { if (childConcept == null) { return Collections.emptyList(); } final IScope scope = context.getScope(); String childConceptFqName = NameUtil.nodeFQName(childConcept); Set<String> concepts = new HashSet<String>(); for (Language l : SModelOperations.getLanguages(parentNode.getModel(), scope)) { concepts.addAll( LanguageHierarchyCache.getInstance() .getDefaultSubstitutableDescendantsOf(childConceptFqName, l)); } List<INodeSubstituteAction> actions = new ArrayList<INodeSubstituteAction>(); for (String fqName : concepts) { SNode applicableConcept = SModelUtil.findConceptDeclaration(fqName, scope); assert applicableConcept != null : "No concept " + fqName; actions.addAll( createDefaultActions(applicableConcept, parentNode, currentChild, childSetter, context)); } return actions; }
private void fillCacheWithModels(Pair<SModuleReference, String> key, Iterable<SModel> models) { if (!myStubModulesCache.containsKey(key)) { myStubModulesCache.put(key, new HashSet<SModelReference>()); } for (SModel model : models) { if (!model.getReference().getModelName().equals(key.o2)) continue; Set<SModelReference> modelsFromCache = myStubModulesCache.get(key); modelsFromCache.add(model.getReference()); } }
public synchronized Set<SModelReference> resolveModel( SModule module, String name, @Nullable SNodeId nodeId) { Pair<SModuleReference, String> key = new Pair<SModuleReference, String>(module.getModuleReference(), name); ensureInitialized(key); Set<SModelReference> models = myStubModulesCache.get(key); if (nodeId == null) return new HashSet<SModelReference>(models); Set<SModelReference> result = new HashSet<SModelReference>(); for (SModelReference ref : models) { SModel m = SModelRepository.getInstance().getModelDescriptor(ref); if (m.getNode(nodeId) != null) { result.add(ref); } } return result; }
@Override public List<String> getWarnings() { List<String> warnings = new ArrayList<String>(super.getWarnings()); Set<String> usedLanguages = new HashSet<String>(); for (SModel model : myModule.getOwnTemplateModels()) { if (SModelStereotype.isGeneratorModel(model)) { usedLanguages.addAll(ModelContentUtil.getUsedLanguageNamespacesInTemplateModel(model)); } } Set<String> extendedLanguages = new HashSet<String>(); Language sourceLanguage = myModule.getSourceLanguage(); usedLanguages.remove(sourceLanguage.getModuleName()); Set<Language> ext = new LinkedHashSet<Language>(); sourceLanguage.getDependenciesManager().collectAllExtendedLanguages(ext); for (Language language : ext) { extendedLanguages.add(language.getModuleName()); } for (String lang : usedLanguages) { Language language = ModuleRepositoryFacade.getInstance().getModule(lang, Language.class); if (language == null) continue; if (!extendedLanguages.contains(lang) && !language.getRuntimeModulesReferences().isEmpty()) { warnings.add(sourceLanguage + " should extend " + lang); } } return warnings; }
private static void assertReferenceEquals(SNode expectedNode, SNode actualNode) { Set<String> roles = new HashSet<String>(); roles.addAll(jetbrains.mps.util.SNodeOperations.getReferenceRoles(expectedNode)); roles.addAll(jetbrains.mps.util.SNodeOperations.getReferenceRoles(actualNode)); Map<String, Set<SReference>> expRoleToReferenceMap = createRoleToReferenceMap(expectedNode); Map<String, Set<SReference>> actRoleToReferenceMap = createRoleToReferenceMap(actualNode); for (String role : roles) { Assert.assertEquals( getErrorString("different number of referents in role " + role, expectedNode, actualNode), expRoleToReferenceMap.get(role).size(), actRoleToReferenceMap.get(role).size()); SReference expectedReference = expectedNode.getReference(role); SReference actualReference = actualNode.getReference(role); assertReferenceEquals( getErrorString("reference in role " + role, expectedNode, actualNode), expectedReference, actualReference); } }