Beispiel #1
0
 public static Object insertMacro_varValue_3961775458390375615(
     final TemplateQueryContext _context) {
   StringBuilder res = new StringBuilder();
   Set<String> used = new HashSet<String>();
   Iterable<SNode> dependencies =
       SLinkOperations.getTargets(_context.getNode(), "dependencies", true);
   for (SNode part : ((List<SNode>) _context.getVariable("var:taskParts"))) {
     dependencies =
         Sequence.fromIterable(dependencies)
             .concat(
                 ListSequence.fromList(
                     SLinkOperations.getTargets(part, "additionalDependencies", true)));
   }
   for (SNode dep : dependencies) {
     String d =
         SPropertyOperations.getString(SLinkOperations.getTarget(dep, "target", false), "name");
     if (used.add(d)) {
       if (res.length() > 0) {
         res.append(", ");
       }
       res.append(d);
     }
   }
   return res.toString();
 }
Beispiel #2
0
 @NotNull
 public SModule getModule(SModel model) {
   if (myGenerationContext != null) {
     return myGenerationContext.getOriginalInputModel().getModule();
   }
   return model.getModule();
 }
Beispiel #3
0
 public static Object insertMacro_varValue_3961775458390373890(
     final TemplateQueryContext _context) {
   List<SNode> parts = new ArrayList<SNode>();
   for (SNode sibl : SNodeOperations.getAllSiblings(_context.getNode(), false)) {
     if (SNodeOperations.isInstanceOf(sibl, "jetbrains.mps.build.workflow.structure.BwfTaskPart")
         && _context.getNode()
             == SLinkOperations.getTarget(
                 SNodeOperations.cast(sibl, "jetbrains.mps.build.workflow.structure.BwfTaskPart"),
                 "task",
                 false)) {
       ListSequence.fromList(parts)
           .addElement(
               SNodeOperations.cast(sibl, "jetbrains.mps.build.workflow.structure.BwfTaskPart"));
     }
   }
   return parts;
 }
Beispiel #4
0
 public static SNode getContextForInnerClass(
     TemplateQueryContext genContext, SNode node, boolean topmost) {
   SNode usage =
       genContext.getOutputNodeByInputNodeAndMappingLabel(
           SLinkOperations.getTarget(node, "inner", true), "classUsageExpr");
   if ((usage != null)) {
     if (SPropertyOperations.getBoolean(node, "nonStatic")) {
       return SNodeOperations.getAncestor(
           usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false);
     }
     if (topmost) {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false))
           .last();
     } else {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   usage, "jetbrains.mps.baseLanguage.structure.ClassConcept", false))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return BehaviorReflection.invokeVirtual(
                       Boolean.TYPE, it, "virtual_isStatic_7405920559687241224", new Object[] {});
                 }
               })
           .first();
     }
   } else {
     SNode outclass =
         genContext.getCopiedOutputNodeForInputNode(
             SNodeOperations.getAncestor(
                 node, "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false));
     if ((outclass != null)) {
       return ListSequence.fromList(
               SNodeOperations.getAncestors(
                   outclass, "jetbrains.mps.baseLanguage.structure.ClassConcept", true))
           .last();
     }
   }
   return null;
 }
Beispiel #5
0
 public static Object insertMacro_varValue_2379134940430813886(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return ListSequence.fromList(
           SLinkOperations.getTargets(
               SNodeOperations.cast(
                   SNodeOperations.getParent(_context.getNode()),
                   "jetbrains.mps.baseLanguage.structure.MethodDeclaration"),
               "parameter",
               true))
       .first();
 }
Beispiel #6
0
 public static SNode findFormattersFieldDeclaration(SNode node, TemplateQueryContext genctx) {
   SNode clazz = findEnclosingTableClass2(node, genctx);
   SNode result = null;
   for (SNode sfd : SLinkOperations.getTargets(clazz, "staticField", true)) {
     if (SPropertyOperations.hasValue(sfd, "name", "formatters")) {
       result = sfd;
       break;
     }
   }
   if (result == null) {
     genctx.showErrorMessage(node, "Can't find formatters field declaration");
   }
   return result;
 }
Beispiel #7
0
 public RelativePathHelper getRelativePathHelper(@NotNull SModel model) {
   if (model.getModule() instanceof TransientModelsModule && myGenerationContext != null) {
     model = myGenerationContext.getOriginalInputModel();
   }
   SModel modelDescriptor = model;
   if (model.getModule() instanceof TransientModelsModule || modelDescriptor == null) {
     return null;
   }
   SModule module = modelDescriptor.getModule();
   if (module == null
       || ((AbstractModule) module).getDescriptorFile() == null
       || module.isPackaged()) {
     return null;
   }
   String basePath = ((AbstractModule) module).getDescriptorFile().getParent().getPath();
   return new RelativePathHelper(basePath);
 }
Beispiel #8
0
 public static SNode findEnclosingTableClass2(SNode node, TemplateQueryContext genctx) {
   SNode table =
       SNodeOperations.getAncestor(
           node, "jetbrains.mps.baseLanguage.dates.structure.DateFormatsTable", true, false);
   return genctx.getOutputNodeByInputNodeAndMappingLabel(table, "FormatTableClass");
 }
Beispiel #9
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"));
    }
  }
Beispiel #10
0
 public static Object insertMacro_varValue_2379134940433430092(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return SNodeOperations.cast(
       SNodeOperations.getParent(_context.getNode()),
       "jetbrains.mps.baseLanguage.structure.MethodDeclaration");
 }
Beispiel #11
0
 public static Object insertMacro_varValue_2379134940431021756(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return DispatchGenUtil.getMatchingMethods(((SNode) _context.getVariable("var:methodDecl")));
 }
Beispiel #12
0
 public static Object templateArgumentQuery_2323553266849259847(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return _context.getNode();
 }
Beispiel #13
0
 public static Object templateArgumentQuery_2323553266849248475(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return ((SNode) _context.getVariable("var:methodDecl"));
 }
Beispiel #14
0
 public static Object templateArgumentQuery_2323553266848938515(
     final IOperationContext operationContext, final TemplateQueryContext _context) {
   return Sequence.fromIterable(((Iterable<SNode>) _context.getVariable("var:methods"))).first();
 }
Beispiel #15
0
    @Override
    public String expandPath(@Nullable String path) {
      if (path == null) {
        return null;
      }

      if (moduleSourceDir != null) {
        for (String macro : MacrosFactory.descriptors) {
          if (path.startsWith(macro)) {
            String relPath = path.substring(path.indexOf('}') + 1);
            return IFileUtils.getCanonicalPath(moduleSourceDir.getDescendant(relPath));
          }
        }
      }
      if (path.startsWith("${")) {
        int index = path.indexOf("}");
        if (index == -1) {
          reporter.report("invalid macro in `" + path + "'", null, null);
          return path;
        }

        String macroName = path.substring(2, index);
        SNode found = null;
        for (SNode macro :
            SLinkOperations.getTargets(
                SNodeOperations.getAncestor(
                    originalModule, "jetbrains.mps.build.structure.BuildProject", false, false),
                "macros",
                true)) {
          if (!(SNodeOperations.isInstanceOf(
              macro, "jetbrains.mps.build.structure.BuildFolderMacro"))) {
            continue;
          }

          if (eq_krgnbt_a0c0f0d0f4(SPropertyOperations.getString(macro, "name"), macroName)) {
            found = SNodeOperations.cast(macro, "jetbrains.mps.build.structure.BuildFolderMacro");
            break;
          }
        }
        if (found == null) {
          reporter.report("macro is not declared in build script: " + path, null, null);
          return path;
        }

        String localPath =
            BehaviorReflection.invokeVirtual(
                String.class,
                SLinkOperations.getTarget(found, "defaultPath", true),
                "virtual_getLocalPath_5481553824944787364",
                new Object[] {
                  (genContext != null
                      ? Context.defaultContext(genContext)
                      : Context.defaultContext())
                });
        if (localPath == null) {
          if (genContext != null) {
            genContext.showWarningMessage(
                found, "cannot resolve local path: " + path + ", macro has no default value");
          }
          return path;
        }

        String relPath = path.substring(index + 1);
        return IFileUtils.getCanonicalPath(
            FileSystem.getInstance().getFileByPath(localPath).getDescendant(relPath));
      }
      return path;
    }