@Override
 protected InequalitySystem getInequalitiesSystem(EditorCell contextCell) {
   HashMap<SNode, SNode> mapping = new HashMap<SNode, SNode>();
   CopyUtil.copy(Arrays.asList(mySourceNode.getContainingRoot()), mapping).get(0);
   SNode nodeToEquatePeer = mySourceNode;
   TypeChecker typeChecker = TypeChecker.getInstance();
   while (nodeToEquatePeer != null && typeChecker.getTypeOf(nodeToEquatePeer) == null) {
     nodeToEquatePeer = nodeToEquatePeer.getParent();
   }
   if (nodeToEquatePeer == null) {
     return null;
   }
   SNode nodeToEquate = mapping.get(nodeToEquatePeer);
   SNode parent = nodeToEquate.getParent();
   if (parent == null) {
     return null;
   }
   SNode hole =
       SModelUtil_new.instantiateConceptDeclaration(
           jetbrains.mps.smodel.SNodeUtil.concept_BaseConcept, null, null, true);
   SNodeUtil.replaceWithAnother(nodeToEquate, hole);
   InequalitySystem inequalitiesForHole =
       TypeChecker.getInstance().getInequalitiesForHole(hole, false);
   return inequalitiesForHole;
 }
Exemplo n.º 2
0
 // todo: this method can be called from inference rules - by calling behavior methods,
 // todo: in which there are no typechecking context(
 public static SNode copyIfNecessary(SNode node) {
   if (node != null
       && (node.getParent() != null || node.getModel() != null && node.getModel().isRoot(node))) {
     // this copies all the atributes, because can be used in migration scripts
     SNode copy = CopyUtil.copy(node, new THashMap<SNode, SNode>(1), true);
     return copy;
   } else {
     return node;
   }
 }
Exemplo n.º 3
0
  public static SNode copyIfNecessary(SNode node, TypeCheckingContext typeCheckingContext) {
    if (node != null
        && (node.getParent() != null || node.getModel() != null && node.getModel().isRoot(node))) {

      // this method is used only when quotations create a type
      // so it should not copy attributes, for instance generator macros of a certain type
      SNode copy = CopyUtil.copy(node, new THashMap<SNode, SNode>(1), false);

      if (typeCheckingContext != null) {
        if (isRuntimeTypeVariable(copy)) {
          typeCheckingContext.registerTypeVariable(copy);
        }
      }
      return copy;
    } else {
      return node;
    }
  }
Exemplo n.º 4
0
  public void processCycles() {
    List<SNode> modules = new ArrayList<SNode>();
    ListSequence.fromList(modules)
        .addSequence(
            ListSequence.fromList(SLinkOperations.getTargets(project, "parts", true))
                .where(
                    new IWhereFilter<SNode>() {
                      public boolean accept(SNode it) {
                        return SNodeOperations.isInstanceOf(
                            it, "jetbrains.mps.build.workflow.structure.BwfJavaModule");
                      }
                    })
                .select(
                    new ISelector<SNode, SNode>() {
                      public SNode select(SNode it) {
                        return SNodeOperations.cast(
                            it, "jetbrains.mps.build.workflow.structure.BwfJavaModule");
                      }
                    }));
    for (SNode m : ListSequence.fromList(modules)) {
      optimizeDependencies(m);
    }
    for (SNode jm : modules) {
      CycleHelper.Module module = new CycleHelper.Module(jm);
      map.put(jm, module);
      if (isEmpty_yc0kju_a0c0d0f(SPropertyOperations.getString(jm, "outputFolder"))) {
        genContext.showErrorMessage(jm, "empty output path");
      } else if (SPropertyOperations.getString(jm, "outputFolder").endsWith("/")
          || SPropertyOperations.getString(jm, "outputFolder").endsWith("\\")) {
        genContext.showErrorMessage(jm, "output path shouldn't end with slash");
      }
    }
    Graph<CycleHelper.Module> graph = new Graph();
    for (CycleHelper.Module module : map.values()) {
      graph.add(module);
    }
    List<List<CycleHelper.Module>> cycles = Graphs.findStronglyConnectedComponents(graph);
    Collections.reverse(cycles);
    List<SNode> cyclesToName = new ArrayList<SNode>();
    for (List<CycleHelper.Module> cycle : cycles) {
      if (cycle.size() < 2) {
        continue;
      }
      final Set<SNode> cycleModules = new HashSet<SNode>();
      for (CycleHelper.Module m : cycle) {
        cycleModules.add(m.getModule());
      }

      Collections.sort(
          cycle,
          new Comparator<CycleHelper.Module>() {
            public int compare(CycleHelper.Module m1, CycleHelper.Module m2) {
              return new Integer(SNodeOperations.getIndexInParent(m1.getModule()))
                  .compareTo(SNodeOperations.getIndexInParent(m2.getModule()));
            }
          });
      SNode first = cycle.get(0).getModule();
      SModel model = SNodeOperations.getModel(first);
      SNode cycleX =
          SModelOperations.createNewNode(
              model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModule");
      cyclesToName.add(cycleX);
      SNodeOperations.insertPrevSiblingChild(first, cycleX);
      SPropertyOperations.set(cycleX, "noWarnings", "" + (true));

      // build cycle sources & dependencies; trying to avoid duplication (which is not critical)
      Set<String> seenSources = new HashSet<String>();
      List<SNode> sources = new ArrayList<SNode>();
      Set<String> seenDependencies = new HashSet<String>();
      List<SNode> deps = new ArrayList<SNode>();
      Set<SNode> seenModules = new LinkedHashSet<SNode>();
      Set<SNode> seenLibraries = new LinkedHashSet<SNode>();
      Set<SNode> taskDependency = new LinkedHashSet<SNode>();

      int heapSize = 0;
      for (CycleHelper.Module m : cycle) {
        SNode module = m.getModule();
        heapSize = Math.max(heapSize, SPropertyOperations.getInteger(module, "heapSize"));
        ListSequence.fromList(SLinkOperations.getTargets(module, "dependencies", true))
            .removeWhere(
                new IWhereFilter<SNode>() {
                  public boolean accept(SNode it) {
                    return SNodeOperations.isInstanceOf(
                            it, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference")
                        && cycleModules.contains(
                            SLinkOperations.getTarget(
                                SNodeOperations.cast(
                                    it,
                                    "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"),
                                "target",
                                false));
                  }
                });
        for (SNode dep : SLinkOperations.getTargets(module, "dependencies", true)) {
          if (SNodeOperations.isInstanceOf(
              dep, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference")) {
            seenModules.add(
                SLinkOperations.getTarget(
                    SNodeOperations.cast(
                        dep, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"),
                    "target",
                    false));
          } else if (SNodeOperations.isInstanceOf(
              dep, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference")) {
            seenLibraries.add(
                SLinkOperations.getTarget(
                    SNodeOperations.cast(
                        dep, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference"),
                    "target",
                    false));
          } else if (SNodeOperations.isInstanceOf(
              dep, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath")) {
            SNode cp =
                SLinkOperations.getTarget(
                    SNodeOperations.cast(
                        dep, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath"),
                    "classpath",
                    true);
            XmlSignature s = new XmlSignature().add(cp);
            String id = (s.hasErrors() ? "dep." + cp.getNodeId().toString() : s.getResult());
            if (seenDependencies.add(id)) {
              deps.add(cp);
            }
          } else {
            genContext.showErrorMessage(dep, "unexpected dependency type");
          }
        }

        for (SNode task :
            ListSequence.fromList(SLinkOperations.getTargets(module, "taskDeps", true))
                .select(
                    new ISelector<SNode, SNode>() {
                      public SNode select(SNode it) {
                        return SLinkOperations.getTarget(it, "target", false);
                      }
                    })) {
          if ((task != null)) {
            taskDependency.add(task);
          }
        }

        SNode mref =
            SModelOperations.createNewNode(
                model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference");
        SLinkOperations.setTarget(mref, "target", cycleX, false);
        ListSequence.fromList(SLinkOperations.getTargets(module, "dependencies", true))
            .addElement(mref);

        for (SNode n :
            ListSequence.fromList(
                SLinkOperations.getTargets(
                    SLinkOperations.getTarget(module, "sources", true), "elements", true))) {
          XmlSignature s = new XmlSignature().add(n);
          String id = (s.hasErrors() ? "path." + n.getNodeId().toString() : s.getResult());
          if (seenSources.add(id)) {
            sources.add(n);
          }
        }
      }
      SPropertyOperations.set(cycleX, "heapSize", "" + (heapSize));
      SLinkOperations.setNewChild(
          cycleX, "sources", "jetbrains.mps.build.workflow.structure.BwfFileSet");
      ListSequence.fromList(
              SLinkOperations.getTargets(
                  SLinkOperations.getTarget(cycleX, "sources", true), "elements", true))
          .addSequence(
              Sequence.fromIterable(((Iterable<SNode>) sources))
                  .select(
                      new ISelector<SNode, SNode>() {
                        public SNode select(SNode it) {
                          return CopyUtil.copy(it);
                        }
                      }));
      for (SNode dep : deps) {
        SNode cp =
            SModelOperations.createNewNode(
                model, null, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath");
        SLinkOperations.setTarget(cp, "classpath", CopyUtil.copy(dep), true);
        ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true))
            .addElement(cp);
      }
      for (SNode jl : seenLibraries) {
        SNode mref =
            SModelOperations.createNewNode(
                model, null, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference");
        SLinkOperations.setTarget(mref, "target", jl, false);
        ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true))
            .addElement(mref);
      }
      for (SNode jm : seenModules) {
        SNode mref =
            SModelOperations.createNewNode(
                model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference");
        SLinkOperations.setTarget(mref, "target", jm, false);
        ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true))
            .addElement(mref);
      }
      for (SNode task : taskDependency) {
        SNode dependency =
            SModelOperations.createNewNode(
                model, null, "jetbrains.mps.build.workflow.structure.BwfTaskDependency");
        SLinkOperations.setTarget(dependency, "target", task, false);
        ListSequence.fromList(SLinkOperations.getTargets(cycleX, "taskDeps", true))
            .addElement(dependency);
      }
    }
    int cycleCounter = 0;
    Collections.sort(
        cyclesToName,
        new Comparator<SNode>() {
          public int compare(SNode n1, SNode n2) {
            return new Integer(SNodeOperations.getIndexInParent(n1))
                .compareTo(SNodeOperations.getIndexInParent(n2));
          }
        });
    for (SNode cycleX : cyclesToName) {
      SPropertyOperations.set(cycleX, "name", "java.modules.cycle." + ++cycleCounter);
      SPropertyOperations.set(
          cycleX,
          "outputFolder",
          SPropertyOperations.getString(project, "temporaryFolder")
              + "/"
              + SPropertyOperations.getString(cycleX, "name"));
    }
  }