コード例 #1
0
 public static SNode virtual_getExpectedReturnType_1213877374441(SNode thisNode) {
   SNode referenceMacro =
       SNodeOperations.getAncestor(
           thisNode, "jetbrains.mps.lang.generator.structure.ReferenceMacro", false, false);
   SNode attributedNode = SNodeOperations.getParent(referenceMacro);
   String linkRole = AttributeOperations.getLinkRole(referenceMacro);
   ConceptAndSuperConceptsScope linkSearchScope =
       new ConceptAndSuperConceptsScope(SNodeOperations.getConceptDeclaration(attributedNode));
   SNode link =
       SNodeOperations.cast(
           linkSearchScope.getMostSpecificLinkDeclarationByRole(linkRole),
           "jetbrains.mps.lang.structure.structure.LinkDeclaration");
   SNode targetConcept = SLinkOperations.getTarget(link, "target", false);
   SNode expectedNodeType = _quotation_createNode_mxwyp3_a0g0a(targetConcept);
   // reference may be resolved dynamically?
   if (SConceptOperations.isSubConceptOf(
       targetConcept, "jetbrains.mps.lang.core.structure.IResolveInfo")) {
     return _quotation_createNode_mxwyp3_a0a8a0(targetConcept);
   }
   return expectedNodeType;
 }
コード例 #2
0
  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")));
        */
      }
    }
  }