public void test_childrenByLinkDeclarationSpecialized() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("2600026384779198859"),
                 "jetbrains.mps.lang.smodelTests.structure.GrandChild")
           }),
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("8758390115029078430"),
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept",
               "specializedGranChild_0_1")));
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("2600026384779198859"),
                 "jetbrains.mps.lang.smodelTests.structure.GrandChild")
           }),
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("8758390115029078430"),
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.Child", "grandChild_0_1")));
 }
 public void execute(final SNode node, final EditorContext editorContext) {
   Iterable<SNode> nodes =
       ListSequence.fromList(SNodeOperations.getChildren(SNodeOperations.getParent(node)))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return SNodeOperations.isInstanceOf(
                       it, "jetbrains.mps.lang.generator.structure.NodeMacro");
                 }
               });
   boolean seen = false;
   for (SNode n : nodes) {
     if (seen) {
       if (SNodeOperations.isInstanceOf(
           n, "jetbrains.mps.lang.generator.structure.CopySrcNodeMacro")) {
         SNodeOperations.deleteNode(n);
         SNodeFactoryOperations.replaceWithNewChild(
             node, "jetbrains.mps.lang.generator.structure.CopySrcListMacro");
       }
       return;
     } else if (n == node) {
       seen = true;
     }
   }
 }
 public void test_childContainingRoles() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new String[] {
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n"),
                 "role"),
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.Root", "childSubConcept_0_n"),
                 "role")
           }),
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("8758390115029078426"),
                       "jetbrains.mps.lang.smodelTests.structure.Root")))
           .select(
               new ISelector<SNode, String>() {
                 public String select(SNode it) {
                   return SNodeOperations.getContainingLinkRole(it);
                 }
               }));
 }
示例#4
0
 public boolean check(
     SNode root, Set<AbstractConstraintsChecker> checkers, SRepository repository) {
   // returns whether state has been changed after check
   if (root == null) {
     return false;
   }
   invalidate();
   if (myCheckedRoot && SetSequence.fromSet(myInvalidNodes).isEmpty()) {
     return false;
   }
   Queue<SNode> nodesToCheck = QueueSequence.fromQueue(new LinkedList<SNode>());
   QueueSequence.fromQueue(nodesToCheck).addLastElement(root);
   while (QueueSequence.fromQueue(nodesToCheck).isNotEmpty()) {
     SNode node = QueueSequence.fromQueue(nodesToCheck).removeFirstElement();
     if (!(myCheckedRoot) || SetSequence.fromSet(myInvalidNodes).contains(node)) {
       try {
         myCurrentNode = node;
         addDependency(node);
         for (AbstractConstraintsChecker checker : checkers) {
           checker.checkNode(node, this, repository);
         }
       } finally {
         myCurrentNode = null;
       }
     }
     QueueSequence.fromQueue(nodesToCheck)
         .addSequence(ListSequence.fromList(SNodeOperations.getChildren(node)));
   }
   // traversed the whole root, should have been removed all invalid nodes
   SetSequence.fromSet(myInvalidNodes).clear();
   myCheckedRoot = true;
   myUpdateInspector = true;
   return true;
 }
 public void test_unspecifiedChildren() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   int initialSize =
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("2166349271756548531"),
                       "jetbrains.mps.lang.smodelTests.structure.Root")))
           .count();
   SNode unspecifiedChild =
       SConceptOperations.createNewNode(
           "jetbrains.mps.lang.smodelTests.structure.GrandChild", null);
   String unspecifiedChildRole =
       this.addUnspecifiedChild(
           SNodeOperations.cast(
               this.getNodeById("2166349271756548531"),
               "jetbrains.mps.lang.smodelTests.structure.Root"),
           unspecifiedChild);
   Assert.assertEquals(
       initialSize + 1,
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("2166349271756548531"),
                       "jetbrains.mps.lang.smodelTests.structure.Root")))
           .count());
   Iterable<SNode> unspecifiedChildren =
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("2166349271756548531"),
                       "jetbrains.mps.lang.smodelTests.structure.Root")))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return (SNodeOperations.getContainingLinkDeclaration(it) == null);
                 }
               });
   Assert.assertEquals(1, Sequence.fromIterable(unspecifiedChildren).count());
   SNode theChild = Sequence.fromIterable(unspecifiedChildren).first();
   Assert.assertEquals(unspecifiedChildRole, SNodeOperations.getContainingLinkRole(theChild));
   Assert.assertEquals(unspecifiedChild, theChild);
 }
 private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
   Iterable<SNode> nodes =
       ListSequence.fromList(SNodeOperations.getChildren(SNodeOperations.getParent(node)))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return SNodeOperations.isInstanceOf(
                       it, "jetbrains.mps.lang.generator.structure.NodeMacro");
                 }
               });
   boolean seen = false;
   for (SNode n : nodes) {
     if (seen) {
       if (SNodeOperations.isInstanceOf(
           n, "jetbrains.mps.lang.generator.structure.CopySrcNodeMacro")) {
         SNode m =
             SLinkOperations.getTarget(
                 SNodeOperations.cast(
                     n, "jetbrains.mps.lang.generator.structure.CopySrcNodeMacro"),
                 "sourceNodeQuery",
                 true);
         if ((m == null)
             || (SLinkOperations.getTarget(m, "body", true) == null)
             || ListSequence.fromList(
                     SLinkOperations.getTargets(
                         SLinkOperations.getTarget(m, "body", true), "statement", true))
                 .isEmpty()
             || ListSequence.fromList(
                         SLinkOperations.getTargets(
                             SLinkOperations.getTarget(m, "body", true), "statement", true))
                     .count()
                 > 1) {
           return false;
         }
         SNode st =
             ListSequence.fromList(
                     SLinkOperations.getTargets(
                         SLinkOperations.getTarget(m, "body", true), "statement", true))
                 .first();
         return SNodeOperations.isInstanceOf(
                 st, "jetbrains.mps.baseLanguage.structure.ExpressionStatement")
             && SNodeOperations.isInstanceOf(
                 SLinkOperations.getTarget(
                     SNodeOperations.cast(
                         st, "jetbrains.mps.baseLanguage.structure.ExpressionStatement"),
                     "expression",
                     true),
                 "jetbrains.mps.lang.generator.structure.TemplateFunctionParameter_sourceNode");
       } else {
         return false;
       }
     } else if (n == node) {
       seen = true;
     }
   }
   return false;
 }
 private void removeAttributes(SNode node) {
   if (SNodeOperations.isAttribute(node)) {
     SNodeOperations.deleteNode(node);
   } else {
     for (SNode child : SNodeOperations.getChildren(node)) {
       removeAttributes(child);
     }
   }
 }
 public boolean isApplicableCustom(SNode subtype, SNode supertype, IsApplicable2Status status) {
   return SConceptOperations.isSubConceptOf(
           SNodeOperations.getConceptDeclaration(subtype),
           NameUtil.nodeFQName(SNodeOperations.getConceptDeclaration(supertype)))
       && !(ListSequence.fromList(SNodeOperations.getChildren(supertype))
           .any(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode ch) {
                   return SNodeOperations.isInstanceOf(
                       ch, "jetbrains.mps.baseLanguage.structure.TypeVariableReference");
                 }
               }))
       && ListSequence.fromList(SNodeOperations.getChildren(subtype))
           .any(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode ch) {
                   return SNodeOperations.isInstanceOf(
                       ch, "jetbrains.mps.baseLanguage.structure.TypeVariableReference");
                 }
               });
 }
  private void _populateLocalVariables(SNode loopStatement, List<SNode> result) {
    for (SNode child : SNodeOperations.getChildren(loopStatement)) {
      if (child.getRoleInParent().equals("body")) {
        continue;
      }
      if (SNodeOperations.isInstanceOf(
          child, "jetbrains.mps.baseLanguage.structure.LocalVariableDeclaration")) {
        result.add(child);
      }

      // <node>
      List<SNode> moreChildren = new ArrayList<SNode>();
      if (SNodeOperations.isInstanceOf(
          loopStatement, "jetbrains.mps.lang.typesystem.structure.MultipleForeachLoop")) {
        ListSequence.fromList(moreChildren)
            .addSequence(
                ListSequence.fromList(
                        SLinkOperations.getTargets(
                            SNodeOperations.cast(
                                loopStatement,
                                "jetbrains.mps.lang.typesystem.structure.MultipleForeachLoop"),
                            "loopVariable",
                            true))
                    .where(
                        new IWhereFilter<SNode>() {
                          public boolean accept(SNode it) {
                            return (SLinkOperations.getTarget(it, "variable", true) != null);
                          }
                        })
                    .select(
                        new ISelector<SNode, SNode>() {
                          public SNode select(SNode it) {
                            return SLinkOperations.getTarget(it, "variable", true);
                          }
                        }));
      }
      for (SNode child_ : moreChildren) {
        result.add(child_);
      }
    }

    SNode containingLoop =
        SNodeOperations.as(
            LocalVariablesScope.findThisOrParent(
                SNodeOperations.getParent(loopStatement),
                SConceptOperations.findConceptDeclaration(
                    "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement")),
            "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement");
    if (containingLoop != null) {
      this._populateLocalVariables(containingLoop, result);
    }
  }
 public static List<SNode> call_getMembers_1213877255431(SNode thisNode) {
   List<SNode> result = new ArrayList<SNode>();
   for (SNode child : SNodeOperations.getChildren(thisNode)) {
     if (SNodeOperations.isInstanceOf(
         child, "jetbrains.mps.baseLanguage.classifiers.structure.IMember")) {
       ListSequence.fromList(result)
           .addElement(
               SNodeOperations.cast(
                   child, "jetbrains.mps.baseLanguage.classifiers.structure.IMember"));
     }
   }
   return result;
 }
 public void test_childrenByLinkDeclarationOnNull() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   SNode nullNode = null;
   Assert.assertTrue(
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   nullNode,
                   SLinkOperations.findLinkDeclaration(
                       "jetbrains.mps.lang.smodelTests.structure.Root", "child_0_n")))
           .isEmpty());
   SNode nullLinkDeclaration = null;
   Assert.assertTrue(
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("8758390115029078426"),
                       "jetbrains.mps.lang.smodelTests.structure.Root"),
                   nullLinkDeclaration))
           .isEmpty());
 }
示例#12
0
 private void removeOrCommentChildInSingleRole() {
   if (!(getContainmentLink().isMultiple())) {
     SNode firstChild =
         ListSequence.fromList(SNodeOperations.getChildren(getParent(), getContainmentLink()))
             .first();
     if ((firstChild != null)) {
       if (firstChild.getConcept().isAbstract()) {
         SNodeOperations.deleteNode(firstChild);
       } else {
         new NodeCommenter(firstChild).commentOut(false);
       }
     }
   }
 }
 public void test_childrenByLinkDeclaration() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   List<SNode> singleChild =
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("8758390115029078426"),
               "jetbrains.mps.lang.smodelTests.structure.Root"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n"));
   Assert.assertEquals(1, ListSequence.fromList(singleChild).count());
   Assert.assertEquals(
       SNodeOperations.cast(
           this.getNodeById("8758390115029078427"),
           "jetbrains.mps.lang.smodelTests.structure.Child"),
       ListSequence.fromList(singleChild).first());
   List<SNode> twins =
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("5815925154349132137"),
               "jetbrains.mps.lang.smodelTests.structure.Root"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n"));
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("5815925154349132142"),
                 "jetbrains.mps.lang.smodelTests.structure.Child"),
             SNodeOperations.cast(
                 this.getNodeById("5815925154349132138"),
                 "jetbrains.mps.lang.smodelTests.structure.Child")
           }),
       twins);
 }
 private void setVariableNames(SNode node, Map<String, Integer> usedNames) {
   if (SNodeOperations.isInstanceOf(
       node, "jetbrains.mps.baseLanguage.structure.VariableDeclaration")) {
     SNode variable =
         SNodeOperations.cast(node, "jetbrains.mps.baseLanguage.structure.VariableDeclaration");
     SNode nodeType = SLinkOperations.getTarget(variable, "type", true);
     if (nodeType != null) {
       String name =
           ListSequence.fromList(
                   BehaviorReflection.invokeVirtual(
                       (Class<List<String>>) ((Class) Object.class),
                       nodeType,
                       "virtual_getVariableSuffixes_1213877337304",
                       new Object[] {}))
               .first();
       if (MapSequence.fromMap(usedNames).containsKey(name)) {
         int i = MapSequence.fromMap(usedNames).get(name);
         i = i + 1;
         MapSequence.fromMap(usedNames).put(name, i);
         name = name + i;
       } else {
         MapSequence.fromMap(usedNames).put(name, 0);
       }
       String prefix =
           BehaviorReflection.invokeVirtual(
               String.class,
               variable,
               "virtual_getPrefix_3012473318495495520",
               new Object[] {myProject});
       String suffix =
           BehaviorReflection.invokeVirtual(
               String.class,
               variable,
               "virtual_getSuffix_3012473318495499856",
               new Object[] {myProject});
       String mainName =
           ((prefix == null || prefix.length() == 0) ? name : NameUtil.capitalize(name));
       SPropertyOperations.set(variable, "name", prefix + mainName + suffix);
     }
   }
   for (SNode child : SNodeOperations.getChildren(node)) {
     setVariableNames(child, usedNames);
   }
 }
示例#15
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());
  }
示例#16
0
  public static void virtual_populateMembers_7405920559687241403(
      SNode thisNode, MembersPopulatingContext context, SNode classifierType) {
    // populate own members
    for (SNode member : SNodeOperations.getChildren(thisNode)) {
      if (SNodeOperations.isInstanceOf(
          member, "jetbrains.mps.baseLanguage.structure.IClassifierMember")) {
        BehaviorReflection.invokeVirtual(
            Void.class,
            SNodeOperations.cast(member, "jetbrains.mps.baseLanguage.structure.IClassifierMember"),
            "virtual_populateMember_7405920559687254644",
            new Object[] {context, classifierType});
      }
    }

    // populate super class members
    SNode superClass =
        BehaviorReflection.invokeVirtual(
            (Class<SNode>) ((Class) Object.class),
            thisNode,
            "virtual_getSuperclass_1240936569950",
            new Object[] {});
    if ((superClass != null)) {
      IClassifierType_Behavior.call_populateMembers_7405920559687241253(
          superClass, context, classifierType);
    }

    // populate implemented interfaces members
    for (SNode implementedInterface :
        ListSequence.fromList(SLinkOperations.getTargets(thisNode, "implementedInterface", true))
            .where(
                new IWhereFilter<SNode>() {
                  public boolean accept(SNode it) {
                    return (it != null);
                  }
                })) {
      IClassifierType_Behavior.call_populateMembers_7405920559687241253(
          implementedInterface, context, classifierType);
    }
  }
示例#17
0
 public void checkNode(
     final SNode node,
     LanguageErrorsComponent component,
     final IOperationContext operationContext,
     IScope scope) {
   if (operationContext == null) {
     return;
   }
   if (SNodeUtil.getMetaLevel(node) != 0) {
     return;
   }
   SNode concept = SNodeOperations.getConceptDeclaration(node);
   for (SReference ref : SNodeOperations.getReferences(node)) {
     SNode target = SLinkOperations.getTargetNode(ref);
     SNode ld = SLinkOperations.findLinkDeclaration(ref);
     // don't check unresolved and broken references, they should already have an error message
     if ((target == null) || ld == null) {
       continue;
     }
     component.addDependency(target);
     component.addDependency(ld);
     component.addDependency(node);
     component.addDependency(SNodeOperations.getParent(node));
     for (SNode c : SNodeOperations.getChildren(node)) {
       component.addDependency(c);
     }
     String linkRole = SModelUtil.getGenuineLinkRole(ld);
     final SNode linkTarget = SLinkOperations.getTarget(ld, "target", false);
     final INodeReferentSearchScopeProvider scopeProvider =
         ModelConstraintsUtil.getSearchScopeProvider(concept, linkRole);
     SearchScopeStatus searchScopeStatus =
         component.runCheckingAction(
             new _FunctionTypes._return_P0_E0<SearchScopeStatus>() {
               public SearchScopeStatus invoke() {
                 return ModelConstraintsUtil.createSearchScope(
                     scopeProvider,
                     SNodeOperations.getModel(node),
                     SNodeOperations.getParent(node),
                     node,
                     linkTarget,
                     operationContext);
               }
             });
     if (searchScopeStatus.isError()) {
       component.addError(
           node,
           searchScopeStatus.getMessage(),
           (SNode) null,
           new ReferenceMessageTarget(SLinkOperations.getRole(ref)));
     } else if (!(searchScopeStatus.isDefault()
         || searchScopeStatus.getSearchScope().isInScope(target))) {
       String name = target.getName();
       component.addError(
           node,
           "reference"
               + ((name == null ? "" : " " + name))
               + " ("
               + SLinkOperations.getRole(ref)
               + ") is out of search scope",
           searchScopeStatus.getReferenceValidatorNode(),
           new ReferenceMessageTarget(SLinkOperations.getRole(ref)));
     }
   }
 }
  private void update(SNode method, SNode baseMethod) {
    if (SModelStereotype.isStubModelStereotype(
        SNodeOperations.getModel(baseMethod).getStereotype())) {
      setVariableNames(method, MapSequence.fromMap(new HashMap<String, Integer>()));
    }
    if (myRemoveAttributes) {
      for (SNode child : SNodeOperations.getChildren(method)) {
        removeAttributes(child);
      }
    }
    boolean isInterfaceMethod =
        SNodeOperations.isInstanceOf(
                SNodeOperations.getParent(baseMethod),
                "jetbrains.mps.baseLanguage.structure.Interface")
            || SPropertyOperations.getBoolean(baseMethod, "isAbstract");
    if (myInsertOverride && !(isInterfaceMethod)) {
      boolean isNeedAddAnnotation = true;
      for (SNode annotation : SLinkOperations.getTargets(method, "annotation", true)) {
        if (SLinkOperations.getTarget(annotation, "annotation", false)
            == SNodeOperations.getNode(
                "f:java_stub#6354ebe7-c22a-4a0f-ac54-50b52ab9b065#java.lang(JDK/java.lang@java_stub)",
                "~Override")) {
          isNeedAddAnnotation = false;
          break;
        }
      }
      if (isNeedAddAnnotation) {
        ListSequence.fromList(SLinkOperations.getTargets(method, "annotation", true))
            .addElement(_quotation_createNode_tfz3o4_a0a0a2a3a8());
      }
    }

    Iterable<SNode> paramList =
        ListSequence.fromList(SLinkOperations.getTargets(method, "parameter", true))
            .select(
                new ISelector<SNode, SNode>() {
                  public SNode select(SNode it) {
                    return _quotation_createNode_tfz3o4_a0a0a0a5a8(it);
                  }
                });
    SNode defaultExpr;
    if (isInterfaceMethod) {
      defaultExpr =
          BehaviorReflection.invokeVirtual(
              (Class<SNode>) ((Class) Object.class),
              SLinkOperations.getTarget(baseMethod, "returnType", true),
              "virtual_createDefaultTypeExpression_3359611512358152580",
              new Object[] {});
    } else {
      defaultExpr =
          _quotation_createNode_tfz3o4_a0a0a7a8(
              baseMethod, Sequence.fromIterable(paramList).toListSequence());
    }

    if (SNodeOperations.isInstanceOf(
        SLinkOperations.getTarget(method, "returnType", true),
        "jetbrains.mps.baseLanguage.structure.VoidType")) {
      if (!(isInterfaceMethod)) {
        ListSequence.fromList(
                SLinkOperations.getTargets(
                    SLinkOperations.getTarget(method, "body", true), "statement", true))
            .addElement(_quotation_createNode_tfz3o4_a0a0a0a9a8(defaultExpr));
      }
    } else {
      ListSequence.fromList(
              SLinkOperations.getTargets(
                  SLinkOperations.getTarget(method, "body", true), "statement", true))
          .addElement(getReturnStatement(defaultExpr));
    }
  }
  public void checkNode(
      final SNode node,
      LanguageErrorsComponent component,
      final IOperationContext operationContext,
      IScope scope) {
    final ConstraintsDescriptor newDescriptor =
        ConceptRegistry.getInstance().getConstraintsDescriptorNew(node.getConceptFqName());

    final CheckingNodeContext checkingNodeContext =
        new jetbrains.mps.smodel.structure.CheckingNodeContext();

    if (SNodeOperations.getParent(node) != null) {
      component.addDependency(SNodeOperations.getParent(node));
    }
    if (SNodeOperations.getParent(node) != null
        && !(jetbrains.mps.smodel.SNodeOperations.isUnknown(SNodeOperations.getParent(node)))) {
      final SNode link = SNodeOperations.getContainingLinkDeclaration(node);
      if (link == null) {
        component.addError(node, "Child in a role with unknown link", null);
        return;
      }
      boolean canBeChild =
          component.runCheckingAction(
              new _FunctionTypes._return_P0_E0<Boolean>() {
                public Boolean invoke() {
                  return ModelConstraintsManager.canBeChild(
                      newDescriptor,
                      node.getConceptFqName(),
                      operationContext,
                      SNodeOperations.getParent(node),
                      link,
                      checkingNodeContext);
                }
              });
      if (!(canBeChild)) {
        SNode rule = getBreakingNodeAndClearContext(checkingNodeContext);
        component.addError(
            node,
            "Node " + node + " cannot be child of node " + SNodeOperations.getParent(node),
            rule);
      }
    }

    if (node.isRoot()) {
      boolean canBeRoot =
          component.runCheckingAction(
              new _FunctionTypes._return_P0_E0<Boolean>() {
                public Boolean invoke() {
                  return ModelConstraintsManager.canBeRoot(
                      newDescriptor,
                      operationContext,
                      node.getConceptFqName(),
                      SNodeOperations.getModel(node),
                      checkingNodeContext);
                }
              });
      if (!(canBeRoot)) {
        SNode rule = getBreakingNodeAndClearContext(checkingNodeContext);
        component.addError(node, "Not rootable concept added as root", rule);
      }
    }

    for (SNode child : SNodeOperations.getChildren(node)) {
      component.addDependency(child);
      final SNode childConcept = SNodeOperations.getConceptDeclaration(child);
      final SNode childLink = SNodeOperations.getContainingLinkDeclaration(child);
      if (childLink == null) {
        continue;
      }
      boolean canBeParent =
          component.runCheckingAction(
              new _FunctionTypes._return_P0_E0<Boolean>() {
                public Boolean invoke() {
                  return ModelConstraintsManager.canBeParent(
                      newDescriptor,
                      node,
                      childConcept,
                      childLink,
                      operationContext,
                      checkingNodeContext);
                }
              });
      if (!(canBeParent)) {
        SNode rule = getBreakingNodeAndClearContext(checkingNodeContext);
        component.addError(node, "Node " + node + " cannot be parent of node " + child, rule);
      }

      // todo: do it right, with runCheckingAction!
      if (!(ModelConstraintsManager.canBeAncestor(
          node, childConcept, operationContext, checkingNodeContext))) {
        SNode rule =
            SNodeOperations.cast(
                getBreakingNodeAndClearContext(checkingNodeContext),
                "jetbrains.mps.lang.constraints.structure.ConstraintFunction_CanBeAnAncestor");
        component.addError(
            child,
            "Concept "
                + SLinkOperations.getTarget(
                    SNodeOperations.as(
                        SNodeOperations.getParent(rule),
                        "jetbrains.mps.lang.constraints.structure.ConceptConstraints"),
                    "concept",
                    false)
                + " cannot be ancestor of node "
                + child,
            rule);
      }
    }

    // Properties validation
    SNode concept = SNodeOperations.getConceptDeclaration(node);
    component.addDependency(concept);
    ConceptAndSuperConceptsScope chs = new ConceptAndSuperConceptsScope(concept);
    for (SNode parentConcept : chs.getConcepts()) {
      component.addDependency(parentConcept);
    }
    List<SNode> props =
        ((List<SNode>)
            chs.getNodes(
                new Condition<SNode>() {
                  public boolean met(SNode n) {
                    return SNodeOperations.isInstanceOf(
                        n, "jetbrains.mps.lang.structure.structure.PropertyDeclaration");
                  }
                }));
    for (SNode p : ListSequence.fromList(props)) {
      final PropertySupport ps = PropertySupport.getPropertySupport(p);
      final String propertyName = SPropertyOperations.getString(p, "name");
      if (propertyName == null) {
        LOG.error(
            "Property declaration has a null name, declaration id: "
                + p.getSNodeId()
                + ", model: "
                + SNodeOperations.getModel(p).getSModelFqName());
        continue;
      }
      final String value = ps.fromInternalValue(node.getProperty(propertyName));
      final PropertyConstraintsDescriptor propertyDescriptor =
          newDescriptor.getProperty(propertyName);
      boolean canSetValue =
          component.runCheckingAction(
              new _FunctionTypes._return_P0_E0<Boolean>() {
                public Boolean invoke() {
                  return ps.canSetValue(
                      propertyDescriptor, node, propertyName, value, operationContext.getScope());
                }
              });
      if (!(canSetValue)) {
        // RE-2426 Ñ disabling the "Property constraint violation for property" error messages

        /*
        // TODO this is a hack for anonymous classes
        if ("name".equals(SPropertyOperations.getString(p, "name")) && ("AnonymousClass".equals(SPropertyOperations.getString(concept, "name")) || "InternalAnonymousClass".equals(SPropertyOperations.getString(concept, "name")))) {
          continue;
        }
        // todo find a rule
        component.addError(node, "Property constraint violation for property \"" + SPropertyOperations.getString(p, "name") + "\"", null, new PropertyMessageTarget(SPropertyOperations.getString(p, "name")));
        */
      }
    }
  }
示例#20
0
  private void cleanDeclaration(final SNode decl) {
    Set<SNode> toRemoveNestedReference = SetSequence.fromSet(new HashSet());
    for (SNode nref : SLinkOperations.getTargets(decl, "nested", true)) {
      for (SNode ref : SLinkOperations.getTargets(decl, "nested", true)) {
        if (eq_ixz87t_a0a0a0b0h(ref, nref)) {
          continue;
        }
        if (eq_ixz87t_a0b0a0b0h(
            SPropertyOperations.getString(
                SLinkOperations.getTarget(ref, "declaration", false), "classname"),
            SPropertyOperations.getString(
                SLinkOperations.getTarget(nref, "declaration", false), "classname"))) {
          SetSequence.fromSet(toRemoveNestedReference).addElement(ref);
        }
      }
    }
    SetSequence.fromSet(toRemoveNestedReference)
        .visitAll(
            new IVisitor<SNode>() {
              public void visit(SNode it) {
                ListSequence.fromList(SNodeOperations.getChildren(decl)).removeElement(it);
                ListSequence.fromList(SLinkOperations.getTargets(it, "role", true))
                    .where(
                        new IWhereFilter<SNode>() {
                          public boolean accept(SNode roleRef) {
                            return SPropertyOperations.getBoolean(
                                SNodeOperations.cast(
                                    SLinkOperations.getTarget(roleRef, "declaration", false),
                                    "jetbrains.mps.build.generictasks.structure.BuiltInTaskDeclaration"),
                                "fake");
                          }
                        })
                    .visitAll(
                        new IVisitor<SNode>() {
                          public void visit(SNode child) {
                            ListSequence.fromList(SNodeOperations.getChildren(decl))
                                .removeElement(
                                    SLinkOperations.getTarget(child, "declaration", false));
                          }
                        });
              }
            });
    ListSequence.fromList(SLinkOperations.getTargets(decl, "fakeDeclaration", true))
        .visitAll(
            new IVisitor<SNode>() {
              public void visit(SNode it) {
                SPropertyOperations.set(it, "fake", "" + (true));
              }
            });

    Set<SNode> toRemoveFakeDeclaration = SetSequence.fromSet(new HashSet());
    SetSequence.fromSet(toRemoveFakeDeclaration)
        .addSequence(
            ListSequence.fromList(SLinkOperations.getTargets(decl, "fakeDeclaration", true)));
    for (SNode nref : SLinkOperations.getTargets(decl, "nested", true)) {
      List<SNode> notRemove =
          ListSequence.fromList(SLinkOperations.getTargets(nref, "role", true))
              .select(
                  new ISelector<SNode, SNode>() {
                    public SNode select(SNode it) {
                      return SNodeOperations.cast(
                          SLinkOperations.getTarget(it, "declaration", false),
                          "jetbrains.mps.build.generictasks.structure.BuiltInTaskDeclaration");
                    }
                  })
              .where(
                  new IWhereFilter<SNode>() {
                    public boolean accept(SNode it) {
                      return SPropertyOperations.getBoolean(it, "fake");
                    }
                  })
              .toListSequence();
      SetSequence.fromSet(toRemoveFakeDeclaration).removeSequence(ListSequence.fromList(notRemove));
    }
    SetSequence.fromSet(toRemoveFakeDeclaration)
        .visitAll(
            new IVisitor<SNode>() {
              public void visit(SNode it) {
                ListSequence.fromList(SNodeOperations.getChildren(decl)).removeElement(it);
              }
            });
    for (final SNode nref : SLinkOperations.getTargets(decl, "nested", true)) {
      SNode node =
          ListSequence.fromList(SLinkOperations.getTargets(nref, "role", true))
              .where(
                  new IWhereFilter<SNode>() {
                    public boolean accept(SNode it) {
                      SNode biDecl =
                          SNodeOperations.cast(
                              SLinkOperations.getTarget(it, "declaration", false),
                              "jetbrains.mps.build.generictasks.structure.BuiltInTaskDeclaration");
                      return SPropertyOperations.getBoolean(biDecl, "fake")
                          && eq_ixz87t_a0a1a0a0a0a0a0a9a7(
                              SPropertyOperations.getString(biDecl, "name"),
                              SPropertyOperations.getString(
                                  SLinkOperations.getTarget(nref, "declaration", false), "name"));
                    }
                  })
              .first();
      ListSequence.fromList(SNodeOperations.getChildren(nref)).removeElement(node);
      ListSequence.fromList(SNodeOperations.getChildren(decl))
          .removeElement(SLinkOperations.getTarget(node, "declaration", false));
    }
  }
示例#21
0
 public static boolean isReference(SNode node) {
   return ListSequence.fromList(SNodeOperations.getChildren(node)).isEmpty()
       && Sequence.fromIterable(SNodeOperations.getReferences(node)).count() == 1;
 }