Example #1
0
  public List<INodeSubstituteAction> createActions() {
    if (myLinkDeclaration == null) {
      return Collections.emptyList();
    }
    EditorComponent editor = mySubstituteInfo.getEditorContext().getNodeEditorComponent();
    EditorCell referenceCell =
        editor.findNodeCellWithRole(
            mySourceNode,
            ((String)
                BehaviorManager.getInstance()
                    .invoke(
                        Object.class,
                        SNodeOperations.cast(
                            myLinkDeclaration,
                            "jetbrains.mps.lang.structure.structure.LinkDeclaration"),
                        "call_getGenuineRole_1213877254542",
                        new Class[] {SNode.class})));

    if (referenceCell != null
        && referenceCell.getContainingBigCell().getFirstLeaf() == referenceCell
        && ReferenceConceptUtil.getCharacteristicReference(
                SNodeOperations.getConceptDeclaration(mySourceNode))
            == myLinkDeclaration
        && SNodeOperations.getParent(mySourceNode) != null
        && ListSequence.fromList(SNodeOperations.getChildren(mySourceNode)).isEmpty()) {
      SNode parent = SNodeOperations.getParent(mySourceNode);
      String role = SNodeOperations.getContainingLinkRole(mySourceNode);
      SNode roleLink =
          SNodeOperations.cast(
              parent.getLinkDeclaration(role),
              "jetbrains.mps.lang.structure.structure.LinkDeclaration");
      return ModelActions.createChildSubstituteActions(
          parent,
          mySourceNode,
          SLinkOperations.getTarget(roleLink, "target", false),
          new DefaultChildNodeSetter(roleLink),
          mySubstituteInfo.getOperationContext());
    }
    return ModelActions.createReferentSubstituteActions(
        mySourceNode, myCurrentReferent, myLinkDeclaration, mySubstituteInfo.getOperationContext());
  }
  public static List<INodeSubstituteAction> createDefaultActions(
      @NotNull SNode applicableConcept,
      SNode parentNode,
      SNode currentChild,
      IChildNodeSetter setter,
      IOperationContext operationContext) {

    String conceptFqName = NameUtil.nodeFQName(applicableConcept);
    SNode link = null;
    if (setter instanceof DefaultChildNodeSetter) {
      DefaultChildNodeSetter defaultSetter = (DefaultChildNodeSetter) setter;
      link = defaultSetter.getLinkDeclaration();
    }

    IScope scope = operationContext.getScope();

    if (!ModelConstraintsManager.canBeChild(conceptFqName, operationContext, parentNode, link)) {
      return new ArrayList<INodeSubstituteAction>();
    }

    SNode smartRef = ReferenceConceptUtil.getCharacteristicReference(applicableConcept);
    if (smartRef != null) {
      List<INodeSubstituteAction> smartActions =
          createSmartReferenceActions(
              applicableConcept, smartRef, parentNode, currentChild, setter, operationContext);
      if (smartActions != null) {
        return smartActions;
      } else {
        return Collections.emptyList();
      }
    } else {
      return Arrays.asList(
          (INodeSubstituteAction)
              new DefaultChildNodeSubstituteAction(
                  applicableConcept, parentNode, currentChild, setter, scope));
    }
  }