Ejemplo n.º 1
0
 /**
  * has a fallback if the dependency is absent in the module descriptor. if it happens then returns
  * simply the current dep. module version
  *
  * @param check is whether to show error for not found version
  */
 public int getDependencyVersion(@NotNull SModule dependency, boolean check) {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   if (!checkDescriptorNotNull(moduleDescriptor)) {
     return -1;
   }
   Integer res = moduleDescriptor.getDependencyVersions().get(dependency.getModuleReference());
   if (res == null) {
     if (check) {
       LOG.error(
           "#getDependencyVersion can't find a version for module "
               + dependency.getModuleName()
               + " in module "
               + getModuleName()
               + "."
               + " This can either mean that the module is not visible from this module or that "
               + "#validateDependencyVersions() was not called on this module in appropriate moment.",
           new Throwable());
     }
     return ((AbstractModule) dependency).getModuleVersion();
   }
   return res;
 }
Ejemplo n.º 2
0
  public void clean(final Set<? extends SModule> modules, @NotNull final ProgressMonitor monitor) {
    monitor.start("Cleaning...", modules.size());
    try {
      for (SModule module : modules) {
        if (isExcluded(module)) {
          monitor.advance(1);
          continue;
        }
        if (monitor.isCanceled()) break;

        monitor.step(module.getModuleName());
        JavaModuleFacet facet = module.getFacet(JavaModuleFacet.class);
        assert facet != null && facet.getClassesGen() != null;
        String path = facet.getClassesGen().getPath();
        FileUtil.delete(new File(path));
        ClassPathFactory.getInstance().invalidate(Collections.singleton(path));
        monitor.advance(1);
      }
    } finally {
      monitor.done();
    }
  }
Ejemplo n.º 3
0
  @Override
  protected void executeTask(Project project, MpsWorker.ObjectsToProcess go) {
    Set<SModule> toCompile = SetSequence.fromSet(new LinkedHashSet<SModule>());
    SetSequence.fromSet(toCompile).addSequence(SetSequence.fromSet(go.getModules()));
    for (Project p : go.getProjects()) {
      SetSequence.fromSet(toCompile).addSequence(SetSequence.fromSet(go.getModules()));
    }
    for (final SModel modelDescriptor : go.getModels()) {
      SModule owningModule =
          ModelAccess.instance()
              .runReadAction(
                  new Computable<SModule>() {
                    public SModule compute() {
                      return modelDescriptor.getModule();
                    }
                  });
      SetSequence.fromSet(toCompile).addElement(owningModule);
    }
    final Set<SModule> finalToCompile =
        CollectionUtil.filter(
            toCompile,
            new Condition<SModule>() {
              public boolean met(SModule module) {
                boolean compileInMps =
                    !(module instanceof IModule) || ((IModule) module).isCompileInMPS();
                return compileInMps && !(module.isPackaged());
              }
            });
    if (finalToCompile.isEmpty()) {
      return;
    }
    info("Starting compilation:");
    StringBuffer sb = new StringBuffer();
    for (SModule m : finalToCompile) {
      sb.append("    ");
      sb.append(m.getModuleName());
      sb.append("\n");
    }
    info(sb.toString());
    MPSCompilationResult result =
        ModelAccess.instance()
            .runReadAction(
                new Computable<MPSCompilationResult>() {
                  public MPSCompilationResult compute() {
                    return new ModuleMaker()
                        .make(
                            finalToCompile,
                            new EmptyProgressMonitor() {
                              @Override
                              public void step(String text) {
                                info("    " + text);
                              }

                              @Override
                              public void start(String taskName, int work) {
                                info(taskName);
                              }
                            });
                  }
                });
    info(result.toString());
  }
 public void applyRule(
     final SNode buildSolutionRunner,
     final TypeCheckingContext typeCheckingContext,
     IsApplicableStatus status) {
   final String className =
       BehaviorReflection.invokeVirtual(
           String.class,
           buildSolutionRunner,
           "virtual_getClassName_1350734474210951475",
           new Object[] {});
   final String methodName =
       BehaviorReflection.invokeVirtual(
           String.class,
           buildSolutionRunner,
           "virtual_getMethodName_1350734474210955274",
           new Object[] {});
   SModuleReference moduleReference =
       ModuleReference.parseReference(
           BuildMps_AbstractModule_Behavior.call_getModuleReference_4643216374596368935(
               SLinkOperations.getTarget(
                   buildSolutionRunner,
                   MetaAdapterFactory.getReferenceLink(
                       0x427a473d5177432cL,
                       0x9905bcbceb71b996L,
                       0x39ea87a41cc0827eL,
                       0x54b085b5945c6691L,
                       "solution"))));
   SModule module = GlobalScope.getInstance().resolve(moduleReference);
   if (module != null) {
     for (SModel m : module.getModels()) {
       if (SModelOperations.getModelName(m).equals(module.getModuleName())) {
         SNode classToRun =
             ListSequence.fromList(
                     SModelOperations.roots(
                         m,
                         MetaAdapterFactory.getConcept(
                             0xf3061a5392264cc5L,
                             0xa443f952ceaf5816L,
                             0xf8c108ca66L,
                             "jetbrains.mps.baseLanguage.structure.ClassConcept")))
                 .findFirst(
                     new IWhereFilter<SNode>() {
                       public boolean accept(SNode it) {
                         return SPropertyOperations.getString(
                                 it,
                                 MetaAdapterFactory.getProperty(
                                     0xceab519525ea4f22L,
                                     0x9b92103b95ca8c0cL,
                                     0x110396eaaa4L,
                                     0x110396ec041L,
                                     "name"))
                             .equals(className);
                       }
                     });
         if ((classToRun == null)) {
           continue;
         }
         SNode methodToRun =
             Sequence.fromIterable(
                     ClassConcept_Behavior.call_staticMethods_5292274854859435867(classToRun))
                 .findFirst(
                     new IWhereFilter<SNode>() {
                       public boolean accept(SNode it) {
                         return SPropertyOperations.getString(
                                     it,
                                     MetaAdapterFactory.getProperty(
                                         0xceab519525ea4f22L,
                                         0x9b92103b95ca8c0cL,
                                         0x110396eaaa4L,
                                         0x110396ec041L,
                                         "name"))
                                 .equals(methodName)
                             && SNodeOperations.isInstanceOf(
                                 SLinkOperations.getTarget(
                                     it,
                                     MetaAdapterFactory.getContainmentLink(
                                         0xf3061a5392264cc5L,
                                         0xa443f952ceaf5816L,
                                         0x112670d273fL,
                                         0x112670d886aL,
                                         "visibility")),
                                 MetaAdapterFactory.getConcept(
                                     0xf3061a5392264cc5L,
                                     0xa443f952ceaf5816L,
                                     0x10af9581ff1L,
                                     "jetbrains.mps.baseLanguage.structure.PublicVisibility"))
                             && ListSequence.fromList(
                                     SLinkOperations.getChildren(
                                         it,
                                         MetaAdapterFactory.getContainmentLink(
                                             0xf3061a5392264cc5L,
                                             0xa443f952ceaf5816L,
                                             0xf8cc56b1fcL,
                                             0xf8cc56b1feL,
                                             "parameter")))
                                 .isEmpty();
                       }
                     });
         if ((methodToRun != null)) {
           return;
         }
       }
     }
   }
   {
     MessageTarget errorTarget = new NodeMessageTarget();
     errorTarget = new ReferenceMessageTarget("solution");
     IErrorReporter _reporter_2309309498 =
         typeCheckingContext.reportTypeError(
             buildSolutionRunner,
             "Cannot find public static void "
                 + className
                 + "."
                 + methodName
                 + "() in "
                 + SPropertyOperations.getString(
                     SLinkOperations.getTarget(
                         buildSolutionRunner,
                         MetaAdapterFactory.getReferenceLink(
                             0x427a473d5177432cL,
                             0x9905bcbceb71b996L,
                             0x39ea87a41cc0827eL,
                             0x54b085b5945c6691L,
                             "solution")),
                     MetaAdapterFactory.getProperty(
                         0xceab519525ea4f22L,
                         0x9b92103b95ca8c0cL,
                         0x110396eaaa4L,
                         0x110396ec041L,
                         "name")),
             "r:6869e2b7-2b2d-443c-a462-ce5a9004892e(jetbrains.mps.build.mps.runner.typesystem)",
             "7415565752189086936",
             null,
             errorTarget);
   }
 }
 public void applyRule(
     final SNode classifier,
     final TypeCheckingContext typeCheckingContext,
     IsApplicableStatus status) {
   if (SNodeOperations.isInstanceOf(
           classifier,
           MetaAdapterFactory.getConcept(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0x1107e0cb103L,
               "jetbrains.mps.baseLanguage.structure.AnonymousClass"))
       || SNodeOperations.isInstanceOf(
           classifier,
           MetaAdapterFactory.getConcept(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfc367070a5L,
               "jetbrains.mps.baseLanguage.structure.EnumClass"))) {
     return;
   }
   if (SNodeOperations.isInstanceOf(
       SLinkOperations.getTarget(
           classifier,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0x112670d273fL,
               0x112670d886aL,
               "visibility")),
       MetaAdapterFactory.getConcept(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0x10af9586f0cL,
           "jetbrains.mps.baseLanguage.structure.PrivateVisibility"))) {
     return;
   }
   SModule module = classifier.getModel().getModule();
   GlobalModuleDependenciesManager depManager = new GlobalModuleDependenciesManager(module);
   Collection<SModule> deps =
       depManager.getModules(GlobalModuleDependenciesManager.Deptype.COMPILE);
   Collection<SModule> depsReexport = depManager.getOnlyReexportModules();
   for (SNode extendedClassifierType :
       Classifier__BehaviorDescriptor.getExtendedClassifierTypes_id1UeCwxlWKny.invoke(
           classifier)) {
     SNode extendedClassifier =
         SLinkOperations.getTarget(
             extendedClassifierType,
             MetaAdapterFactory.getReferenceLink(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0x101de48bf9eL,
                 0x101de490babL,
                 "classifier"));
     if (extendedClassifier
         == SNodeOperations.getNode(
             "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~Object")) {
       continue;
     }
     SModule classifierModule = extendedClassifier.getModel().getModule();
     assert classifierModule != null;
     if (deps.contains(classifierModule) && !(depsReexport.contains(classifierModule))) {
       {
         MessageTarget errorTarget = new NodeMessageTarget();
         IErrorReporter _reporter_2309309498 =
             typeCheckingContext.reportWarning(
                 classifier,
                 "Usages of this classifier outside of '"
                     + module.getModuleName()
                     + "' module requires setting 'Export' flag for the dependency on '"
                     + classifierModule.getModuleName()
                     + "' module",
                 "r:00000000-0000-4000-0000-011c895902c5(jetbrains.mps.baseLanguage.typesystem)",
                 "9721774220123915",
                 null,
                 errorTarget);
         {
           BaseQuickFixProvider intentionProvider =
               new BaseQuickFixProvider(
                   "jetbrains.mps.baseLanguage.typesystem.PutReexportForExtendedClassifier_QuickFix",
                   false);
           intentionProvider.putArgument("module", ((AbstractModule) module));
           intentionProvider.putArgument("moduleToImport", classifierModule);
           _reporter_2309309498.addIntentionProvider(intentionProvider);
         }
       }
     }
   }
 }
Ejemplo n.º 6
0
  public int getModelKind(SModel model, @Nullable SReference reference) {
    DataSource source = (model != null ? model.getSource() : null);
    IFile modelFile =
        (source instanceof FileDataSource ? ((FileDataSource) source).getFile() : null);
    if (modelFile != null) {
      String filePath = modelFile.getAbsolutePath().replace('\\', '/');
      if (filePath.startsWith(languagesUtilPath)) {
        return OTHER;
      }
    }

    SModule module = model.getModule();
    if (module instanceof Language) {
      LanguageAspect aspect = Language.getModelAspect(model);
      if (aspect != null) {
        switch (aspect) {
          case ACTIONS:
            return EDITOR;
          case BEHAVIOR:
            return CORE;
          case CONSTRAINTS:
            return CORE;
          case DATA_FLOW:
            return CORE;
          case EDITOR:
            return EDITOR;
          case FIND_USAGES:
            return CORE;
          case INTENTIONS:
            return EDITOR;
          case PLUGIN:
            return WORKBENCH;
          case REFACTORINGS:
            return CORE;
          case SCRIPTS:
            return CORE;
          case STRUCTURE:
            return CORE;
          case STUBS:
            return CORE;
          case TEST:
            return EDITOR;
          case TEXT_GEN:
            return CORE;
          case TYPESYSTEM:
            return CORE;
          default:
        }
      }
      return CORE;

    } else if (module instanceof Solution) {

      String moduleFqName = module.getModuleName();
      if (moduleFqName.equals("JDK")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Core")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Editor")) {
        return EDITOR;
      }
      if (moduleFqName.equals("MPS.Workbench")) {
        return WORKBENCH;
      }
      if (moduleFqName.equals("MPS.Classpath")) {
        SNode refTargetRoot = reference.getTargetNode().getContainingRoot();
        if (SNodeOperations.isInstanceOf(
            refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier")) {
          String cName =
              SPropertyOperations.getString(
                  SNodeOperations.cast(
                      refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier"),
                  "name");
          String modelName = model.getModelName();
          if (findInModule(coreModule, modelName, cName)) {
            return CORE;
          }
          if (findInModule(editorModule, modelName, cName)) {
            return EDITOR;
          }
          return WORKBENCH;
        }
        return OTHER;
      }

      Solution sol = (Solution) module;
      switch (sol.getKind()) {
        case NONE:
          return OTHER;
        case PLUGIN_CORE:
          return CORE;
        case PLUGIN_EDITOR:
          return EDITOR;
        case PLUGIN_OTHER:
          return WORKBENCH;
        default:
      }
    }
    return OTHER;
  }
 public String getMatchingText_internal(SModule parameterObject) {
   return parameterObject.getModuleName();
 }
Ejemplo n.º 8
0
  private MPSCompilationResult compile(Set<SModule> modules, JavaCompilerOptions compilerOptions) {
    boolean hasAnythingToCompile = false;
    List<IMessage> messages = new ArrayList<IMessage>();

    for (SModule m : modules) {
      if (isExcluded(m)) continue;

      hasAnythingToCompile = true;
    }

    if (!hasAnythingToCompile) {
      return new MPSCompilationResult(0, 0, false, Collections.<SModule>emptySet());
    }

    JavaCompiler compiler = new JavaCompiler();
    boolean hasJavaToCompile = false;
    boolean hasFilesToCopyOrDelete = false;

    myTracer.push("preparing to compile", false);
    Set<SModule> modulesWithRemovals = new HashSet<SModule>();
    for (SModule m : modules) {
      if (areClassesUpToDate(m)) continue;

      if (!getJavaFacet(m).isCompileInMps()) {
        String text =
            "Module which compiled in IDEA depends on module which has to be compiled in MPS:"
                + m.getModuleName();
        messages.add(createMessage(MessageKind.WARNING, text, m));
        myHandler.handle(createMessage(MessageKind.INFORMATION, text, m));
        continue;
      }

      ModuleSources sources = getModuleSources(m);
      hasFilesToCopyOrDelete |= !sources.isResourcesUpToDate();
      hasJavaToCompile |= !sources.isJavaUpToDate();

      for (File f : sources.getFilesToDelete()) {
        //noinspection ResultOfMethodCallIgnored
        f.delete();
        modulesWithRemovals.add(m);
      }

      for (JavaFile f : sources.getFilesToCompile()) {
        compiler.addSource(f.getClassName(), f.getContents());
        myContainingModules.put(f.getClassName(), m);
      }
    }
    myTracer.pop();

    if (!hasJavaToCompile && !hasFilesToCopyOrDelete) {
      return new MPSCompilationResult(0, 0, false, Collections.<SModule>emptySet(), messages);
    }

    myTracer.push("invalidating classpath", false);
    for (SModule module : modulesWithRemovals) {
      invalidateCompiledClasses(module);
    }
    myTracer.pop();

    Set<SModule> changedModules = new HashSet<SModule>();
    MyCompilationResultAdapter listener = null;
    if (hasJavaToCompile) {
      myTracer.push("compiling java", false);
      IClassPathItem classPathItems = computeDependenciesClassPath(modules);
      listener = new MyCompilationResultAdapter(modules, classPathItems, messages);
      compiler.addCompilationResultListener(listener);
      myTracer.push("eclipse compiler", true);

      if (compilerOptions == null) {
        compiler.compile(classPathItems);
      } else {
        compiler.compile(classPathItems, compilerOptions);
      }
      myTracer.pop();
      changedModules.addAll(listener.myChangedModules);
      compiler.removeCompilationResultListener(listener);
      myTracer.pop();
    }

    myTracer.push("copying resources", false);
    for (SModule module : modules) {
      ModuleSources sources = getModuleSources(module);
      IFile classesGen = getJavaFacet(module).getClassesGen();
      if (classesGen == null) {
        continue;
      }
      for (ResourceFile toCopy : sources.getResourcesToCopy()) {
        String fqName = toCopy.getPath();

        fqName = fqName.substring(0, fqName.length() - toCopy.getFile().getName().length());
        String path = fqName.replace('/', File.separatorChar) + toCopy.getFile().getName();

        if (new File(toCopy.getFile().getAbsolutePath()).exists()) {
          FileUtil.copyFile(
              new File(toCopy.getFile().getAbsolutePath()),
              new File(classesGen.getDescendant(path).getPath()));
        }
      }
    }
    myTracer.pop();

    myTracer.push("updating classpath", false);
    for (SModule module : changedModules) {
      invalidateCompiledClasses(module);
    }
    myTracer.pop();

    for (SModule module : modulesWithRemovals) {
      if (!changedModules.contains(module)) {
        myHandler.handle(
            createMessage(
                MessageKind.WARNING,
                "Module with removals not in changed modules: " + module,
                module));
      }
    }

    // todo: check possibility of this statements
    if (hasJavaToCompile && changedModules.isEmpty()) {
      myHandler.handle(
          createMessage(
              MessageKind.ERROR, "has java to compile but changed modules is empty", null));
    }
    if (!hasJavaToCompile && !changedModules.isEmpty()) {
      myHandler.handle(
          createMessage(
              MessageKind.ERROR, "has not java to compile but changed modules is not empty", null));
    }

    return new MPSCompilationResult(
        listener == null ? 0 : listener.getErrorCount(), 0, false, changedModules, messages);
  }