コード例 #1
0
 @Override
 public SNodeReference getReferenceRoleId(SReference reference) {
   return MapSequence.fromMap(myReferenceRolesToPointers)
       .get(
           MultiTuple.<String, String>from(
               reference.getSourceNode().getConcept().getConceptId(), reference.getRole()));
 }
コード例 #2
0
  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));
  }
コード例 #3
0
ファイル: ConceptIconHelper.java プロジェクト: JetBrains/MPS
  public static Tuples._2<String, String> createColors() {
    // make it not less than 80 in each color
    int mainColor = new Random().nextInt(0x1000000) | 0x808080;
    int borderColor = new Color(mainColor).darker().getRGB() & 0xFFFFFF;

    return MultiTuple.<String, String>from(toColor(mainColor), toColor(borderColor));
  }
コード例 #4
0
 @Override
 public void propertyNameRead(SNode node, String propertyName, SNodeReference propertyPointer) {
   storeAndCheckConsistency(
       myPropertyNamesToPointers,
       MultiTuple.<String, String>from(node.getConcept().getConceptId(), propertyName),
       propertyPointer);
 }
コード例 #5
0
 private <K, C extends ModelChange> Tuples._2<Map<K, C>, Map<K, C>> arrangeChanges(
     _FunctionTypes._return_P1_E0<? extends K, ? super C> changeToKey, Class<C> changeClass) {
   return MultiTuple.<Map<K, C>, Map<K, C>>from(
       MergeConflictsBuilder.<K, C>arrangeChanges(myMineChangeSet, changeToKey, changeClass),
       MergeConflictsBuilder.<K, C>arrangeChanges(
           myRepositoryChangeSet, changeToKey, changeClass));
 }
コード例 #6
0
ファイル: FacetRegistry.java プロジェクト: sprig/MPS
 public void register(String languageNamespace, IFacet facet) {
   if (MapSequence.fromMap(facetMap).containsKey(facet.getName())) {
     throw new IllegalArgumentException("already registered");
   }
   MapSequence.fromMap(facetMap).put(facet.getName(), facet);
   SetSequence.fromSet(facetsForLanguages)
       .addElement(MultiTuple.<String, IFacet>from(languageNamespace, facet));
 }
コード例 #7
0
 @Override
 public void referenceRoleRead(SReference reference, SNodeReference linkPointer) {
   storeAndCheckConsistency(
       myReferenceRolesToPointers,
       MultiTuple.<String, String>from(
           reference.getSourceNode().getConcept().getConceptId(), reference.getRole()),
       linkPointer);
 }
コード例 #8
0
 @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);
 }
コード例 #9
0
  private void collectGroupChangesWithOthersConflicts(
      Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangedChanges,
      ChangeSet thisChangeSet,
      ChangeSet otherChangeSet) {
    Map<SNodeId, DeleteRootChange> deleteRootChanges =
        MergeConflictsBuilder.<SNodeId, DeleteRootChange>arrangeChanges(
            thisChangeSet,
            new _FunctionTypes._return_P1_E0<SNodeId, DeleteRootChange>() {
              public SNodeId invoke(DeleteRootChange drc) {
                return drc.getRootId();
              }
            },
            DeleteRootChange.class);
    for (ModelChange change : ListSequence.fromList(otherChangeSet.getModelChanges())) {
      if (MapSequence.fromMap(myConflictingChanges).containsKey(change)) {
        continue;
      }

      SNodeId nodeId = null;
      if (change instanceof NodeChange) {
        nodeId = ((NodeChange) change).getAffectedNodeId();
      } else if (change instanceof NodeGroupChange) {
        nodeId = ((NodeGroupChange) change).getParentNodeId();
      }
      if (nodeId == null) {
        continue;
      }
      SNode node = myBaseModel.getNode(nodeId);
      while (node != null) {
        if (SNodeOperations.getParent(node) == null) {
          DeleteRootChange conflicting =
              MapSequence.fromMap(deleteRootChanges).get(node.getNodeId());
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
          }
        } else {
          Tuples._2<SNodeId, String> nodeRole =
              MultiTuple.<SNodeId, String>from(
                  SNodeOperations.getParent(node).getNodeId(),
                  SNodeOperations.getContainingLinkRole(node));
          final int index = SNodeOperations.getIndexInParent(node);
          NodeGroupChange conflicting =
              ListSequence.fromList(MapSequence.fromMap(arrangedChanges).get(nodeRole))
                  .findFirst(
                      new IWhereFilter<NodeGroupChange>() {
                        public boolean accept(NodeGroupChange ch) {
                          return ch.getBegin() <= index && index < ch.getEnd();
                        }
                      });
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
            break;
          }
        }
        node = SNodeOperations.getParent(node);
      }
    }
  }
コード例 #10
0
 @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));
 }
コード例 #11
0
 @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();
 }
コード例 #12
0
  public void doUpdate(AnActionEvent event) {
    try {
      SurroundWithIntentions_ActionGroup.this.removeAll();

      IntentionsManager.QueryDescriptor query = new IntentionsManager.QueryDescriptor();
      query.setIntentionClass(SurroundWithIntention.class);
      query.setInstantiate(true);
      query.setCurrentNodeOnly(true);

      List<Tuples._2<Intention, SNode>> groupItems =
          ListSequence.fromList(new ArrayList<Tuples._2<Intention, SNode>>());
      SNode node = event.getData(MPSDataKeys.NODE);
      final EditorContext context = event.getData(MPSDataKeys.EDITOR_CONTEXT);

      Collection<Pair<Intention, SNode>> intentions =
          IntentionsManager.getInstance().getAvailableIntentions(query, node, context);
      for (Pair<Intention, SNode> pair : Sequence.fromIterable(intentions)) {
        ListSequence.fromList(groupItems)
            .addElement(MultiTuple.<Intention, SNode>from(pair.getFirst(), pair.getSecond()));
      }
      if (ListSequence.fromList(groupItems).isEmpty()) {
        return;
      }

      ListSequence.fromList(groupItems)
          .sort(
              new Comparator<Tuples._2<Intention, SNode>>() {
                public int compare(Tuples._2<Intention, SNode> a, Tuples._2<Intention, SNode> b) {
                  return a._0()
                      .getDescription(a._1(), context)
                      .compareTo(b._0().getDescription(b._1(), context));
                }
              },
              true)
          .visitAll(
              new IVisitor<Tuples._2<Intention, SNode>>() {
                public void visit(Tuples._2<Intention, SNode> it) {
                  SurroundWithIntentions_ActionGroup.this.addParameterizedAction(
                      new SurroundIntentionAction_Action((SurroundWithIntention) it._0(), it._1()),
                      PluginId.getId("jetbrains.mps.lang.intentions"),
                      (SurroundWithIntention) it._0(),
                      it._1());
                }
              });
    } catch (Throwable t) {
      LOG.error("User group error", t);
    }
    for (Pair<ActionPlace, Condition<BaseAction>> p : this.myPlaces) {
      this.addPlace(p.first, p.second);
    }
  }
コード例 #13
0
 private static Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangeNodeGroupChanges(
     ChangeSet changeSet) {
   Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> nodeRoleToGroupChanges =
       MapSequence.fromMap(new HashMap<Tuples._2<SNodeId, String>, List<NodeGroupChange>>());
   for (NodeGroupChange change :
       Sequence.fromIterable(changeSet.getModelChanges(NodeGroupChange.class))) {
     Tuples._2<SNodeId, String> nodeRole =
         MultiTuple.<SNodeId, String>from(change.getParentNodeId(), change.getRole());
     if (!(MapSequence.fromMap(nodeRoleToGroupChanges).containsKey(nodeRole))) {
       MapSequence.fromMap(nodeRoleToGroupChanges)
           .put(nodeRole, ListSequence.fromList(new ArrayList<NodeGroupChange>()));
     }
     ListSequence.fromList(MapSequence.fromMap(nodeRoleToGroupChanges).get(nodeRole))
         .addElement(change);
   }
   return nodeRoleToGroupChanges;
 }
コード例 #14
0
ファイル: Junit_Command.java プロジェクト: wolfhesse/MPS
 private static Tuples._2<List<ITestNodeWrapper>, Tuples._3<String, List<String>, List<String>>>
     getTestsToRunWithParameters(@NotNull List<ITestNodeWrapper> tests) throws ExecutionException {
   final Wrappers._T<List<ITestNodeWrapper>> _tests =
       new Wrappers._T<List<ITestNodeWrapper>>(tests);
   final Wrappers._T<Tuples._3<String, List<String>, List<String>>> runParams =
       new Wrappers._T<Tuples._3<String, List<String>, List<String>>>();
   final Wrappers._T<List<ITestNodeWrapper>> testsToRun =
       new Wrappers._T<List<ITestNodeWrapper>>();
   final Wrappers._T<String> skipped = new Wrappers._T<String>();
   _tests.value =
       ListSequence.fromList(_tests.value)
           .where(
               new IWhereFilter<ITestNodeWrapper>() {
                 public boolean accept(ITestNodeWrapper it) {
                   return it != null;
                 }
               })
           .toListSequence();
   if (ListSequence.fromList(_tests.value).isEmpty()) {
     final Wrappers._T<Tuples._3<String, List<String>, List<String>>> defaultRunParameters =
         new Wrappers._T<Tuples._3<String, List<String>, List<String>>>();
     ModelAccess.instance()
         .runReadAction(
             new Runnable() {
               public void run() {
                 defaultRunParameters.value = AbstractTestWrapper.getDefaultRunParameters();
               }
             });
     return MultiTuple.<List<ITestNodeWrapper>, Tuples._3<String, List<String>, List<String>>>from(
         ListSequence.fromList(new ArrayList<ITestNodeWrapper>()), defaultRunParameters.value);
   }
   ModelAccess.instance()
       .runReadAction(
           new Runnable() {
             public void run() {
               runParams.value =
                   ListSequence.fromList(_tests.value).first().getTestRunParameters();
               testsToRun.value =
                   ListSequence.fromList(_tests.value)
                       .where(
                           new IWhereFilter<ITestNodeWrapper>() {
                             public boolean accept(ITestNodeWrapper it) {
                               return eq_yo2c7x_a0a0a0a0a0a0b0a0a0a0g0c(
                                   it.getTestRunParameters(), runParams.value);
                             }
                           })
                       .toListSequence();
               skipped.value =
                   IterableUtils.join(
                       ListSequence.fromList(_tests.value)
                           .where(
                               new IWhereFilter<ITestNodeWrapper>() {
                                 public boolean accept(ITestNodeWrapper it) {
                                   return neq_yo2c7x_a0a0a0a0a0a0a2a0a0a0a6a2(
                                       it.getTestRunParameters(), runParams.value);
                                 }
                               })
                           .select(
                               new ISelector<ITestNodeWrapper, String>() {
                                 public String select(ITestNodeWrapper it) {
                                   return it.getName();
                                 }
                               }),
                       " ");
             }
           });
   if (isNotEmpty_yo2c7x_a0h0c(skipped.value)) {
     LOG.warning("All tests could not be executed together. Skipped " + skipped.value);
   }
   return MultiTuple.<List<ITestNodeWrapper>, Tuples._3<String, List<String>, List<String>>>from(
       testsToRun.value, runParams.value);
 }
コード例 #15
0
ファイル: ConfStubSource.java プロジェクト: lilongthinker/MPS
  @Override
  public SModel loadSModel(IModule module, SModelDescriptor descriptor) {
    SModel model = new SModel(descriptor.getSModelReference(), new ForeignNodeIdMap());
    ModuleReference lang =
        MPSModuleRepository.getInstance()
            .getModuleById(ModuleId.fromString("32d0a39c-772f-4490-8142-e50f9a9f19d4"))
            .getModuleReference();
    model.addLanguage(lang);

    String pkg = model.getSModelFqName().getLongName();
    List<Tuples._4<String, String, SNode, PathItem>> doclst =
        ListSequence.fromList(new ArrayList<Tuples._4<String, String, SNode, PathItem>>());
    SNode sample =
        SConceptOperations.createNewNode(
            "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument", null);
    for (String path : roots) {
      PathItem pi = ConfPathItem.getPathItem(path);
      for (String docres : ListSequence.fromList(pi.resources(pkg))) {
        SNodeId id = ConfReader.createForeignId(pi.baseName(docres));
        SNode doc = (SNode) model.getNodeById(id);
        if ((doc == null)) {
          doc =
              SConceptOperations.createNewNode(
                  NameUtil.nodeFQName(
                      SConceptOperations.findConceptDeclaration(
                          "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument")),
                  sample);
          ((jetbrains.mps.smodel.SNode) doc).setId(id);
          SPropertyOperations.set(doc, "name", pi.baseName(docres));
          SModelOperations.addRootNode(((SModel) model), doc);
          ListSequence.fromList(doclst)
              .addElement(MultiTuple.<String, String, SNode, PathItem>from(pkg, docres, doc, pi));
        }
      }
    }
    final StubModelDescriptors descs =
        new StubModelDescriptors(SModelStereotype.getStubStereotypeForId("conf"), roots, module) {
          @Override
          public StubModelDataSource createStubsSource(String path) {
            return new ConfStubSource(path);
          }
        };
    ConfReader reader =
        new ConfReader(
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.javaStubRef(pk);
              }
            },
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.smodelRefWithId(pk);
              }
            });
    for (Tuples._4<String, String, SNode, PathItem> doctuple : ListSequence.fromList(doclst)) {
      InputStream is = null;
      try {
        is = doctuple._3().openResource(doctuple._0(), doctuple._1());
        reader.read(doctuple._2(), new SAXBuilder().build(is));
      } catch (IOException e) {
        e.printStackTrace();
      } catch (JDOMException e) {
        e.printStackTrace();
      }
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
    }
    SNodeOperations.deleteNode(sample);
    return model;
  }
コード例 #16
0
 @Override
 public SNodeReference getPropertyId(SNode node, String propertyName) {
   return MapSequence.fromMap(myPropertyNamesToPointers)
       .get(MultiTuple.<String, String>from(node.getConcept().getConceptId(), propertyName));
 }
コード例 #17
0
 public void synchronize() {
   myInputPort.set(
       MultiTuple.<SNode>from(SLinkOperations.getTarget(getSNode(), "inputPort", false)));
   myOutputPort.set(
       MultiTuple.<SNode>from(SLinkOperations.getTarget(getSNode(), "outputPort", false)));
 }