Exemple #1
0
  private static void assertDeepChildrenEquals(SNode expectedNode, SNode actualNode) {
    Set<String> roles = new HashSet<String>();
    for (SNode child : expectedNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }
    for (SNode child : actualNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }

    for (String role : roles) {
      Iterable<? extends SNode> expectedChildren = expectedNode.getChildren(role);
      Iterable<? extends SNode> actualChildren = actualNode.getChildren(role);

      int esize = IterableUtil.asCollection(expectedChildren).size();
      int asize = IterableUtil.asCollection(actualChildren).size();
      assertEquals(
          getErrorString("child count in role " + role, expectedNode, actualNode), esize, asize);

      Iterator<? extends SNode> actualIterator = actualChildren.iterator();
      for (SNode expectedChild : expectedChildren) {
        SNode actualChild = actualIterator.next();
        assertEquals(
            getErrorString("children in role " + role, expectedNode, actualNode),
            expectedChild.getNodeId(),
            actualChild.getNodeId());
        assertDeepNodeEquals(expectedChild, actualChild);
      }
    }
  }
Exemple #2
0
 private static void checkModelNodes(@NotNull SModel model, @NotNull final List<String> result) {
   for (final SNode node : SNodeUtil.getDescendants(model)) {
     final SConcept concept = node.getConcept();
     if (concept == null) {
       result.add("unknown concept of node: " + SNodeUtil.getDebugText(node));
       continue;
     }
     for (String name : node.getPropertyNames()) {
       if (concept.getProperty(name) == null) {
         result.add("unknown property: `" + name + "' in node " + SNodeUtil.getDebugText(node));
       }
     }
     for (SReference ref : node.getReferences()) {
       SAbstractLink link = concept.getLink(ref.getRole());
       if (link == null || !(link.isReference())) {
         result.add(
             "unknown link role: `" + ref.getRole() + "' in node " + SNodeUtil.getDebugText(node));
       }
     }
     for (SNode child : node.getChildren()) {
       String role = child.getRoleInParent();
       SAbstractLink link = concept.getLink(role);
       if (link == null || link.isReference()) {
         result.add("unknown child role: `" + role + "' in node " + SNodeUtil.getDebugText(node));
       }
     }
   }
 }
  public Map<String, String> getContextClassifiers(SNode contextNode) {
    // only AnonymousClass has Classifier as reference
    // todo: make it clearer
    if (SNodeOperations.isInstanceOf(
        contextNode, "jetbrains.mps.baseLanguage.structure.IAnonymousClass")) {
      contextNode = SNodeOperations.getParent(contextNode);
    }
    if (SNodeOperations.isInstanceOf(
        contextNode, "jetbrains.mps.baseLanguage.structure.Classifier")) {
      if (LOG.isEnabledFor(Level.WARN)) {
        LOG.warn("contextNode is classifier in getContextClassifiers: " + contextNode);
      }
      return Collections.emptyMap();
    }

    // find first classifier in path
    String sourceChildRole = null;
    while ((contextNode != null)
        && !(SNodeOperations.isInstanceOf(
            contextNode, "jetbrains.mps.baseLanguage.structure.Classifier"))) {
      sourceChildRole = contextNode.getRoleInParent();
      contextNode = SNodeOperations.getParent(contextNode);
    }

    if ((contextNode == null)) {
      // todo: impossible?
      return Collections.emptyMap();
    }

    return contextClassifiersCache.get(
        MultiTuple.<SNode, String>from(
            SNodeOperations.cast(contextNode, "jetbrains.mps.baseLanguage.structure.Classifier"),
            sourceChildRole));
  }
 @Override
 public void nodeRoleRead(SNode node, SNodeReference linkPointer, boolean unorderedRole) {
   Tuples._2<String, String> key =
       MultiTuple.<String, String>from(
           node.getParent().getConcept().getConceptId(), node.getRoleInParent());
   storeAndCheckConsistency(myNodeRolesToPointers, key, linkPointer);
   storeAndCheckConsistency(myChildLinkToUnordered, key, unorderedRole);
 }
 @Override
 public SNodeReference getNodeRoleId(SNode node) {
   String roleInParent = node.getRoleInParent();
   if (roleInParent == null) {
     return null;
   }
   return MapSequence.fromMap(myNodeRolesToPointers)
       .get(
           MultiTuple.<String, String>from(
               node.getParent().getConcept().getConceptId(), roleInParent));
 }
  private Map<String, String> getContextClassifiers(SNode contextNode, String sourceChildRole) {
    Map<String, String> bindings = new HashMap<String, String>();

    SNode current = contextNode;
    while ((current != null)) {
      if (SNodeOperations.isInstanceOf(
          current, "jetbrains.mps.baseLanguage.structure.Classifier")) {
        boolean processNestedClassifiers = false;
        if (SNodeOperations.isInstanceOf(
                current, "jetbrains.mps.baseLanguage.structure.AnonymousClass")
            || SNodeOperations.isInstanceOf(
                current, "jetbrains.mps.baseLanguage.structure.EnumClass")) {
          processNestedClassifiers = true;
        } else if (SNodeOperations.isInstanceOf(
            current, "jetbrains.mps.baseLanguage.structure.Interface")) {
          processNestedClassifiers = !("extendedInterface".equals(sourceChildRole));
        } else if (SNodeOperations.isInstanceOf(
            current, "jetbrains.mps.baseLanguage.structure.ClassConcept")) {
          processNestedClassifiers =
              !("superclass".equals(sourceChildRole)
                  || "implementedInterface".equals(sourceChildRole));
        } else {
          if (LOG.isEnabledFor(Level.WARN)) {
            LOG.warn("Illegal classifier node in bl textgen: " + current);
          }
        }

        // todo: is it true? had a bug with it. Look like nested classifier has more priority then
        // class with same name
        addClassifierToBindingMap(
            bindings,
            SNodeOperations.cast(current, "jetbrains.mps.baseLanguage.structure.Classifier"));
        if (processNestedClassifiers) {
          for (Map.Entry<String, String> simpleToFqName :
              nestedClassifiersCache
                  .get(
                      SNodeOperations.cast(
                          current, "jetbrains.mps.baseLanguage.structure.Classifier"))
                  .entrySet()) {
            if (!(bindings.containsKey(simpleToFqName.getKey()))) {
              bindings.put(simpleToFqName.getKey(), simpleToFqName.getValue());
            }
          }
        }
      }

      // todo: specialized links?
      // should not be a problem: superclass/extendedInterface/implementedInterface not specialized
      sourceChildRole = current.getRoleInParent();
      current = SNodeOperations.getParent(current);
    }

    return bindings;
  }
  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);
    }
  }
 @Override
 public boolean isInUnorderedRole(SNode node) {
   SNode parent = node.getParent();
   if (parent == null) {
     return false;
   }
   Boolean b =
       MapSequence.fromMap(myChildLinkToUnordered)
           .get(
               MultiTuple.<String, String>from(
                   parent.getConcept().getQualifiedName(), node.getRoleInParent()));
   return b != null && b.booleanValue();
 }
 private static Scope getScope_id3fifI_xCJOQ(
     @NotNull SNode __thisNode__, SNode kind, SNode child) {
   if (child != null && child.getRoleInParent().equals("actualArgument")) {
     Scope argumentsScope =
         XMLSAXChildRule_BehaviorDescriptor.getArgumentsScope_id460OzqriLdX.invoke(
             __thisNode__, kind);
     if (argumentsScope != null) {
       return argumentsScope;
     }
   }
   if (child
       == SLinkOperations.getTarget(
           __thisNode__,
           MetaAdapterFactory.getContainmentLink(
               0xdcb5a83a19a844ffL,
               0xa4cbfc7d324ecc63L,
               0x1f6c736337b5e2d8L,
               0x4180d2369beda765L,
               "condition"))) {
     {
       SAbstractConcept cncpt = SNodeOperations.asSConcept((kind));
       if (SConceptOperations.isSubConceptOf(
           SNodeOperations.asSConcept(cncpt),
           MetaAdapterFactory.getConcept(
               0xdcb5a83a19a844ffL,
               0xa4cbfc7d324ecc63L,
               0x1f6c736337b5e2cbL,
               "jetbrains.mps.core.xml.sax.structure.XMLSAXAttributeRule"))) {
         return SimpleRoleScope.forNamedElements(
             SLinkOperations.getTarget(
                 __thisNode__,
                 MetaAdapterFactory.getReferenceLink(
                     0xdcb5a83a19a844ffL,
                     0xa4cbfc7d324ecc63L,
                     0x1f6c736337b5e2d8L,
                     0x1f6c736337b5e2dcL,
                     "rule")),
             MetaAdapterFactory.getContainmentLink(
                 0xdcb5a83a19a844ffL,
                 0xa4cbfc7d324ecc63L,
                 0x1f6c736337b5e2f2L,
                 0x1f6c736337b5e2f4L,
                 "attrs"));
       }
     }
   }
   return ScopeProvider_BehaviorDescriptor.getScope_id3fifI_xCJOQ.invokeSpecial(
       __thisNode__, kind, child);
 }
Exemple #10
0
  private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) {
    if (!APICellAdapter.isFirstPositionInBigCell(selectedCell)) return false;
    SNode anchor = selectedCell.getSNode();
    if (anchor.getParent() == null) return false;

    NodeAndRole nodeAndRole =
        new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent(), false);
    if (nodeAndRole == null) return false;

    EditorCell targetCell = selectedCell.getEditorComponent().findNodeCell(nodeAndRole.myNode);
    return targetCell != null
        && ((jetbrains.mps.nodeEditor.cells.EditorCell) targetCell)
                .getFirstLeaf(CellConditions.SELECTABLE)
            == selectedCell
        && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode);
  }