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 static List<INodeSubstituteAction> createActions_internal( SNode parentNode, SNode currentChild, SNode childConcept, IChildNodeSetter childSetter, IOperationContext context) { List<INodeSubstituteAction> resultActions = new ArrayList<INodeSubstituteAction>(); if (childConcept == null) { return resultActions; } // special case if (childConcept == SModelUtil.getBaseConcept()) { if ((currentChild == null || currentChild.getConcept().getId().equals(SNodeUtil.concept_BaseConcept))) { resultActions = new ArrayList<INodeSubstituteAction>(); ISearchScope conceptsSearchScope = SModelSearchUtil.createConceptsFromModelLanguagesScope( parentNode.getModel(), true, context.getScope()); List<SNode> allVisibleConcepts = conceptsSearchScope.getNodes(); for (final SNode visibleConcept : allVisibleConcepts) { resultActions.add( new DefaultChildNodeSubstituteAction( visibleConcept, parentNode, currentChild, childSetter, context.getScope()) { public String getMatchingText(String pattern) { return getMatchingText(pattern, true, true); } public String getVisibleMatchingText(String pattern) { return getMatchingText(pattern); } public String getDescriptionText(String pattern) { String fqName = NameUtil.nodeFQName(visibleConcept); return "lang: " + NameUtil.compactNamespace(NameUtil.namespaceFromConceptFQName(fqName)); } public Icon getIconFor(String pattern) { return getIconFor(pattern, true); } }); } return resultActions; } // pretend we are going to substitute more concrete concept childConcept = ChildSubstituteActionsUtil.getRefinedChildConcept(currentChild); } Language primaryLanguage = SModelUtil.getDeclaringLanguage(childConcept); if (primaryLanguage == null) { LOG.error( "Couldn't build actions : couldn't get declaring language for concept " + org.jetbrains.mps.openapi.model.SNodeUtil.getDebugText(childConcept)); return resultActions; } List<SNode> allBuilders = ChildSubstituteActionsUtil.getActionsBuilders( parentNode, currentChild, childConcept, childSetter, context); if (!ChildSubstituteActionsUtil.containsRemoveDefaults(allBuilders)) { resultActions.addAll( createPrimaryChildSubstituteActions( parentNode, currentChild, childConcept, childSetter, context)); } for (SNode builder : allBuilders) { List<INodeSubstituteAction> addActions = ChildSubstituteActionsUtil.invokeActionFactory( builder, parentNode, currentChild, childConcept, childSetter, context); resultActions.addAll(addActions); } for (SNode builder : allBuilders) { resultActions = ChildSubstituteActionsUtil.applyActionFilter( builder, resultActions, parentNode, currentChild, childConcept, context); } if (childSetter instanceof DefaultChildNodeSetter || childSetter instanceof AbstractCellMenuPart_ReplaceNode_CustomNodeConcept && currentChild != null) { SNode linkDeclaration; if (childSetter instanceof DefaultChildNodeSetter) { linkDeclaration = ((DefaultChildNodeSetter) childSetter).myLinkDeclaration; } else { linkDeclaration = currentChild.getRoleLink(); } Iterator<INodeSubstituteAction> it = resultActions.iterator(); while (it.hasNext()) { INodeSubstituteAction action = it.next(); SNode conceptNode = action.getOutputConcept(); if (conceptNode == null) { continue; } if (!ModelConstraintsManager.canBeParent(parentNode, conceptNode, linkDeclaration, context) || !ModelConstraintsManager.canBeAncestor(parentNode, conceptNode, context)) { it.remove(); } } } return resultActions; }