Ejemplo n.º 1
0
 public static void setBoolean(SNode node, String propertyName, boolean value) {
   if (node != null) {
     SNode conceptProperty = (SNode) findProperty(node, propertyName);
     if (SNodeOperations.isInstanceOf(
             conceptProperty, "jetbrains.mps.lang.structure.structure.BooleanConceptProperty")
         && !(value)) {
       node.removeChild(conceptProperty);
     } else if (conceptProperty == null && value) {
       for (SNode cpd : (List<SNode>) SModelSearchUtil.getConceptPropertyDeclarations(node)) {
         if (SPropertyOperations.getString(cpd, "name").equals(propertyName)) {
           if (SNodeOperations.isInstanceOf(
               cpd, "jetbrains.mps.lang.structure.structure.BooleanConceptPropertyDeclaration")) {
             SNode bcp =
                 SModelOperations.createNewNode(
                     SNodeOperations.getModel(node),
                     null,
                     "jetbrains.mps.lang.structure.structure.BooleanConceptProperty");
             SLinkOperations.setTarget(
                 bcp,
                 "conceptPropertyDeclaration",
                 SNodeOperations.cast(
                     cpd,
                     "jetbrains.mps.lang.structure.structure.BooleanConceptPropertyDeclaration"),
                 false);
             ListSequence.fromList(SLinkOperations.getTargets(node, "conceptProperty", true))
                 .addElement(bcp);
             break;
           }
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
 public static SNode findLinkDeclaration(SReference reference) {
   if (reference == null) {
     return null;
   }
   return ((SNode)
       SModelSearchUtil.findLinkDeclaration(
           jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.getConceptDeclaration(
               ((SNode) reference.getSourceNode())),
           reference.getRole()));
 }
Ejemplo n.º 3
0
 public static SNode findProperty(SNode node, String name) {
   boolean cpt =
       eq_yzaoi3_a0a0a0g(
               node.getConcept().getId(),
               "jetbrains.mps.lang.structure.structure.ConceptDeclaration")
           || eq_yzaoi3_a0a0a0g_0(
               node.getConcept().getId(),
               "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration");
   SNode conceptNode = (cpt ? ((SNode) node) : SNodeOperations.getConceptDeclaration(node));
   return SModelSearchUtil.findConceptProperty(conceptNode, name);
 }
Ejemplo n.º 4
0
 @Override
 public SProperty findProperty(final String name) {
   SNode prop =
       ListSequence.fromList(
               (List<SNode>)
                   SModelSearchUtil.getPropertyDeclarations(
                       getConcept().resolve(MPSModuleRepository.getInstance())))
           .findFirst(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return eq_vein7o_a0a0a0a0a0a0a8(
                       SPropertyOperations.getString(it, "name"), name);
                 }
               });
   return (prop == null ? null : new SPropertyNodeAdapter(prop));
 }
  public List<INodeSubstituteAction> createActions() {
    if (myLinkDeclaration == null) {
      return Collections.emptyList();
    }
    EditorComponent editor =
        (EditorComponent) mySubstituteInfo.getEditorContext().getEditorComponent();
    EditorCell referenceCell =
        editor.findNodeCellWithRole(
            mySourceNode,
            BehaviorReflection.invokeNonVirtual(
                String.class,
                myLinkDeclaration,
                "jetbrains.mps.lang.structure.structure.LinkDeclaration",
                "call_getGenuineRole_1213877254542",
                new Object[] {}));

    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 =
          ((SNode)
              SModelSearchUtil.findLinkDeclaration(
                  SNodeOperations.getConceptDeclaration(parent), role));
      return ModelActions.createChildSubstituteActions(
          parent,
          mySourceNode,
          SLinkOperations.getTarget(roleLink, "target", false),
          new DefaultChildNodeSetter(roleLink),
          mySubstituteInfo.getOperationContext());
    }
    return ModelActions.createReferentSubstituteActions(
        mySourceNode, myCurrentReferent, myLinkDeclaration, mySubstituteInfo.getOperationContext());
  }
Ejemplo n.º 6
0
 public static SNode findLinkDeclaration(String conceptFqName, String linkRole) {
   SNode concept = SModelUtil.findConceptDeclaration(conceptFqName);
   SNode linkDeclaration = SModelSearchUtil.findLinkDeclaration(concept, linkRole);
   return linkDeclaration;
 }
  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;
  }