private void addExactInstances(SNode current, SNode concept, Set<SNode> result, IScope scope) {
   if (current.getConceptFqName().equals(NameUtil.nodeFQName(concept))) {
     result.add(current);
   }
   for (SNode child : current.getChildren()) {
     addExactInstances(child, concept, result, scope);
   }
 }
 private void addUsages(SNode current, Set<SNode> nodes, Set<SReference> result) {
   for (SReference ref : current.getReferences()) {
     if (nodes.contains(ref.getTargetNode())) {
       result.add(ref);
     }
   }
   for (SNode child : current.getChildren()) {
     addUsages(child, nodes, result);
   }
 }
  private void addDescendants(SNode current, SNode node, Set<SNode> result) {
    if (SNodeUtil.isInstanceOfConceptDeclaration(current)) {
      for (SNode interfaceConcept : SNodeUtil.getConceptDeclaration_Implements(current)) {
        if (interfaceConcept != null && interfaceConcept == node) {
          result.add(current);
          break;
        }
      }
      if (SNodeUtil.getConceptDeclaration_Extends(current) == node) {
        result.add(current);
      }
    } else if (SNodeUtil.isInstanceOfInterfaceConceptDeclaration(current)) {
      for (SNode interfaceConcept : SNodeUtil.getInterfaceConceptDeclaration_Extends(current)) {
        if (interfaceConcept != null && interfaceConcept == node) {
          result.add(interfaceConcept);
          break;
        }
      }
    }

    for (SNode child : current.getChildren()) { // are there any "inner" concepts?
      addDescendants(child, node, result);
    }
  }
 private void addInstances(SNode current, SNode concept, Set<SNode> result, IScope scope) {
   if (current.isInstanceOfConcept(NameUtil.nodeFQName(concept))) result.add(current);
   for (SNode child : current.getChildren()) {
     addInstances(child, concept, result, scope);
   }
 }
  private static List<INodeSubstituteAction> createSmartReferenceActions(
      final SNode smartConcept,
      final SNode smartReference,
      final SNode parentNode,
      final SNode currentChild,
      final IChildNodeSetter childSetter,
      final IOperationContext context) {

    if (parentNode == null) {
      return null;
    }

    // try to create referent-search-scope
    SNode linkDeclaration = null;
    int index = 0;
    if (currentChild != null) {
      linkDeclaration = currentChild.getRoleLink();
      index = parentNode.getChildren(currentChild.getRoleInParent()).indexOf(currentChild);
    }
    //    TODO generate wrapping setter to have access to original link
    //    if(childSetter instanceof WrappingSetter) {
    //      childSetter = ((WrappingSetter)childSetter).unwrap();
    //    }
    if (linkDeclaration == null && childSetter instanceof DefaultChildNodeSetter) {
      linkDeclaration = ((DefaultChildNodeSetter) childSetter).getLinkDeclaration();
    }

    //    TODO restore (when wrapping setter is created)
    //    if (linkDeclaration == null) {
    //      return null;
    //    }

    ReferenceDescriptor refDescriptor =
        ModelConstraintsUtil.getSmartReferenceDescriptor(
            parentNode,
            linkDeclaration == null ? null : SModelUtil.getLinkDeclarationRole(linkDeclaration),
            index,
            smartConcept);
    if (refDescriptor == null) return null;

    Scope searchScope = refDescriptor.getScope();
    if (searchScope == null) return null;

    // create smart actions
    final String targetConcept =
        NameUtil.nodeFQName(SModelUtil.getLinkDeclarationTarget(smartReference));
    List<INodeSubstituteAction> actions = new ArrayList<INodeSubstituteAction>();
    IReferencePresentation presentation = refDescriptor.getReferencePresentation();
    Iterable<SNode> referentNodes = searchScope.getAvailableElements(null);
    for (SNode referentNode : referentNodes) {
      if (referentNode == null
          || !referentNode
              .getConcept()
              .isSubConceptOf(SConceptRepository.getInstance().getConcept(targetConcept))) continue;
      actions.add(
          new SmartRefChildNodeSubstituteAction(
              referentNode,
              parentNode,
              currentChild,
              childSetter,
              context.getScope(),
              smartConcept,
              smartReference,
              presentation));
    }

    return actions;
  }