Esempio n. 1
0
 private static String asString(SModuleReference generatorRef) {
   Generator generator = (Generator) ModuleRepositoryFacade.getInstance().getModule(generatorRef);
   if (generator == null) {
     return "unknown(" + generatorRef.toString() + ")";
   }
   return generator.getAlias();
 }
Esempio n. 2
0
  @Override
  public List<String> getWarnings() {
    List<String> warnings = new ArrayList<String>(super.getWarnings());
    Set<String> usedLanguages = new HashSet<String>();
    for (SModel model : myModule.getOwnTemplateModels()) {
      if (SModelStereotype.isGeneratorModel(model)) {
        usedLanguages.addAll(ModelContentUtil.getUsedLanguageNamespacesInTemplateModel(model));
      }
    }
    Set<String> extendedLanguages = new HashSet<String>();
    Language sourceLanguage = myModule.getSourceLanguage();
    usedLanguages.remove(sourceLanguage.getModuleName());

    Set<Language> ext = new LinkedHashSet<Language>();
    sourceLanguage.getDependenciesManager().collectAllExtendedLanguages(ext);

    for (Language language : ext) {
      extendedLanguages.add(language.getModuleName());
    }

    for (String lang : usedLanguages) {
      Language language = ModuleRepositoryFacade.getInstance().getModule(lang, Language.class);
      if (language == null) continue;

      if (!extendedLanguages.contains(lang) && !language.getRuntimeModulesReferences().isEmpty()) {
        warnings.add(sourceLanguage + " should extend " + lang);
      }
    }
    return warnings;
  }
Esempio n. 3
0
 protected void readModules(FileMPSProject.ProjectDescriptor projDesc) {
   myErrors = null;
   //  load solutions
   Set<ModuleReference> existingModules = getModuleReferences();
   for (Path modulePath : projDesc.getModules()) {
     String path = modulePath.getPath();
     IFile descriptorFile = FileSystem.getInstance().getFileByPath(path);
     if (descriptorFile.exists()) {
       ModuleDescriptor descriptor =
           ModulesMiner.getInstance().loadModuleDescriptor(descriptorFile);
       if (descriptor != null) {
         ModulesMiner.ModuleHandle moduleHandle =
             new ModulesMiner.ModuleHandle(descriptorFile, descriptor);
         IModule m = ModuleRepositoryFacade.createModule(moduleHandle, this);
         ModuleReference moduleReference = m.getModuleReference();
         if (!(existingModules.remove(moduleReference))) {
           super.addModule(moduleReference);
         }
       } else {
         error("Can't load module from " + descriptorFile.getPath() + " Unknown file type.");
       }
     } else {
       error("Can't load module from " + descriptorFile.getPath() + " File doesn't exist.");
     }
   }
   for (ModuleReference ref : existingModules) {
     super.removeModule(ref);
   }
 }
Esempio n. 4
0
 @Override
 public QuickFix_Runtime getQuickFix() {
   if (myQuickFixTaken) {
     return myQuickFix;
   }
   try {
     String languageNamespace =
         NameUtil.namespaceFromLongName(NameUtil.namespaceFromLongName(myClassFQName));
     Language language =
         ModuleRepositoryFacade.getInstance().getModule(languageNamespace, Language.class);
     Class aClass = ClassLoaderManager.getInstance().getClass(language, myClassFQName);
     if (aClass == null) {
       LOG.error("class " + myClassFQName + " not found in a module " + languageNamespace);
       myQuickFixTaken = true;
       return null;
     }
     QuickFix_Runtime quickFix = (QuickFix_Runtime) aClass.getConstructor().newInstance();
     for (String s : myMap.keySet()) {
       quickFix.putArgument(s, myMap.get(s));
     }
     myQuickFix = quickFix;
     myQuickFixTaken = true;
     return quickFix;
   } catch (Throwable t) {
     LOG.error(null, t);
     myQuickFixTaken = true;
     return null;
   }
 }
Esempio n. 5
0
 @Override
 protected List<SModuleReference> getAllVisibleElements() {
   final List<SModuleReference> allLanguages = new ArrayList<SModuleReference>();
   for (Language language : ModuleRepositoryFacade.getInstance().getAllModules(Language.class)) {
     allLanguages.add(language.getModuleReference());
   }
   return allLanguages;
 }
Esempio n. 6
0
  @Override
  public List<String> getErrors() {
    List<String> errors = new ArrayList<String>();
    Throwable loadException = myModule.getModuleDescriptor().getLoadException();
    if (loadException != null) {
      errors.add("Couldn't load module: " + loadException.getMessage());
      return errors;
    }

    ModuleDescriptor descriptor = myModule.getModuleDescriptor();
    // null?

    for (Dependency dep : descriptor.getDependencies()) {
      SModuleReference moduleRef = dep.getModuleRef();
      if (MPSModuleRepository.getInstance().getModule(moduleRef) == null) {
        errors.add("Can't find dependency: " + moduleRef.getModuleName());
      }
    }
    for (SModuleReference reference : descriptor.getUsedLanguages()) {
      if (ModuleRepositoryFacade.getInstance().getModule(reference, Language.class) == null) {
        errors.add("Can't find used language: " + reference.getModuleName());
      }
    }
    for (SModuleReference reference : descriptor.getUsedDevkits()) {
      if (MPSModuleRepository.getInstance().getModule(reference) == null) {
        errors.add("Can't find used devkit: " + reference.getModuleName());
      }
    }

    if (descriptor.getSourcePaths() != null && !myModule.isPackaged()) {
      for (String sourcePath : descriptor.getSourcePaths()) {
        IFile file = FileSystem.getInstance().getFileByPath(sourcePath);
        if (file == null || !file.exists()) {
          errors.add("Can't find source path: " + sourcePath);
        }
      }
    }
    if (descriptor.getAdditionalJavaStubPaths() != null) {
      for (String path : descriptor.getAdditionalJavaStubPaths()) {
        IFile file = FileSystem.getInstance().getFileByPath(path);
        if (file == null || !file.exists()) {
          if (new File(path).exists()) {
            errors.add("Idea VFS is not up-to-date. Can't find library: " + path);
          } else {
            errors.add("Can't find library: " + path);
          }
        }
      }
    }

    // todo: =(
    if (!(myModule instanceof Generator)) {
      errors.addAll(validateDependenciesOnGenerators());
    }

    return errors;
  }
Esempio n. 7
0
  private void ensureInitialized(Pair<SModuleReference, String> key) {
    if (myStubModulesCache.containsKey(key)) return;

    IModule module = ModuleRepositoryFacade.getInstance().getModule(key.o1);
    Set<SModel> visibleModels =
        new HashSet<SModel>(IterableUtil.asCollection(module.getModuleScope().getModels()));

    fillCacheWithModels(key, visibleModels);
  }
 protected void removeSolution(String name) {
   ModuleReference ref = new ModuleReference(null, ModuleId.foreign(name));
   MPSModuleRepository repository = MPSModuleRepository.getInstance();
   IModule m = ModuleRepositoryFacade.getInstance().getModule(ref);
   if (m == null) {
     return;
   }
   repository.unregisterModule(m, this);
 }
Esempio n. 9
0
 private TemplateModel getTemplateModel(String modelName) {
   Class<TemplateModel> clazz =
       ClassLoaderManager.getInstance()
           .getClass(ModuleRepositoryFacade.getInstance().getModule(getReference()), modelName);
   try {
     return clazz.getConstructor(TemplateModule.class).newInstance(this);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 10
0
 @Override
 public List<String> getErrors() {
   List<String> errors = new ArrayList<String>(super.getErrors());
   for (SModuleReference gen : myModule.getModuleDescriptor().getDepGenerators()) {
     if (ModuleRepositoryFacade.getInstance().getModule(gen) == null) {
       errors.add("Can't find generator dependency: " + gen.getModuleName());
     }
   }
   return errors;
 }
 protected void removeSolution(String name) {
   SModuleReference ref =
       new jetbrains.mps.project.structure.modules.ModuleReference(null, ModuleId.foreign(name));
   MPSModuleRepository repository = MPSModuleRepository.getInstance();
   SModule m = ModuleRepositoryFacade.getInstance().getModule(ref);
   if (m == null) {
     return;
   }
   repository.unregisterModule(m, this);
 }
Esempio n. 12
0
  private void initialize() {
    Environment env = IdeaEnvironment.getOrCreate(ModuleSymbolicSuite.createConfig());
    env.createProject(new FromProjectPathProjectStrategy());

    SModule mod =
        ModuleRepositoryFacade.getInstance()
            .getModule(PersistenceFacade.getInstance().createModuleReference(myModuleRef));
    for (Runner child : myRunners) {
      ((ModuleSymbolicSuite.DelegatingRunner) child).init(mod, myBuilder);
    }
    this.initialized = true;
  }
Esempio n. 13
0
 @NotNull
 public List<IModule> getModules() {
   // TODO remove after 3.0, this method is a copy of Project.getModules() returning List<IModule>
   List<IModule> result = new ArrayList<IModule>();
   for (SModuleReference ref : myModules) {
     IModule module = ModuleRepositoryFacade.getInstance().getModule(ref);
     if (module != null) {
       result.add(module);
     }
   }
   return result;
 }
Esempio n. 14
0
 private void addNewDevKits() {
   Set<SModuleReference> devKitsInModel =
       new HashSet<SModuleReference>(((SModelInternal) myModelDescriptor).importedDevkits());
   Set<SModuleReference> devKitsInProperties = new HashSet<SModuleReference>(getUsedDevKits());
   devKitsInProperties.removeAll(devKitsInModel);
   for (SModuleReference dk : devKitsInProperties) {
     DevKit devKit = ModuleRepositoryFacade.getInstance().getModule(dk, DevKit.class);
     assert devKit != null;
     SModel model = myModelDescriptor;
     ((SModelInternal) model).addDevKit(dk);
   }
 }
Esempio n. 15
0
 @Override
 public ClassLoader getRootClassLoader() {
   getRepository().getModelAccess().checkReadAccess();
   Set<MPSModuleOwner> moduleOwners = ModuleRepositoryFacade.getInstance().getModuleOwners(this);
   for (MPSModuleOwner owner : moduleOwners) {
     if (owner instanceof SLibrary) {
       ClassLoader classLoader = ((SLibrary) owner).getPluginClassLoader();
       if (classLoader != null) {
         return classLoader;
       }
     }
   }
   return ReloadableModule.class.getClassLoader();
 }
Esempio n. 16
0
 @Override
 public Set<SLanguage> getUsedLanguages() {
   Collection<Language> languages =
       ModuleRepositoryFacade.getInstance().getAllModules(Language.class);
   return SetSequence.fromSetWithValues(
       new HashSet<SLanguage>(),
       CollectionSequence.fromCollection(languages)
           .select(
               new ISelector<Language, SLanguage>() {
                 public SLanguage select(Language it) {
                   return SConceptRepository.getInstance().getLanguage(it.getModuleName());
                 }
               }));
 }
Esempio n. 17
0
 private TemplateModel getTemplateModel(String modelName) {
   Class<TemplateModel> clazz =
       ClassLoaderManager.getInstance()
           .getClass(ModuleRepositoryFacade.getInstance().getModule(getReference()), modelName);
   if (clazz == null) {
     throw new IllegalStateException(
         String.format("Failed to obtain generator runtime class for model %s", modelName));
   }
   try {
     return clazz.getConstructor(TemplateModule.class).newInstance(this);
   } catch (RuntimeException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Esempio n. 18
0
 @Override
 public void update(ProgressMonitor monitor, @NotNull FileSystemEvent event) {
   assertCanChange();
   for (IFile file : event.getRemoved()) {
     if (file.equals(myDescriptorFile)) {
       ModuleRepositoryFacade.getInstance().unregisterModule(this);
       return;
     }
   }
   for (IFile file : event.getChanged()) {
     if (file.equals(myDescriptorFile)) {
       SModuleOperations.reloadFromDisk(this);
       return;
     }
   }
 }
Esempio n. 19
0
  void update(boolean refreshFiles) {
    ModelAccess.assertLegalWrite();

    List<ModuleHandle> moduleHandles =
        Collections.unmodifiableList(ModulesMiner.getInstance().collectModules(file, refreshFiles));
    myHandles.set(moduleHandles);
    List<SModule> loaded = new ArrayList<SModule>();
    for (ModuleHandle moduleHandle : moduleHandles) {
      SModule module = ModuleRepositoryFacade.createModule(moduleHandle, this);
      if (module != null) {
        loaded.add(module);
      }
    }
    for (SModule module : loaded) {
      ((AbstractModule) module).onModuleLoad();
    }
  }
Esempio n. 20
0
  private static void safeDelete(
      final Project project,
      Language sourceLanguage,
      final Generator generator,
      GeneratorDescriptor generatorDescriptor,
      boolean deleteFiles) {
    List<Generator> dependant = new ArrayList<Generator>();
    for (Generator gen :
        (List<Generator>) ModuleRepositoryFacade.getInstance().getAllModules(Generator.class)) {
      if (gen.getReferencedGenerators().contains(generator)) {
        dependant.add(gen);
      }
    }
    if (!dependant.isEmpty()) {
      final StringBuilder report = new StringBuilder();
      report.append("Can't delete generator ").append(generator.getModuleName()).append(".\n");
      report.append("The following generators depend on it:\n\n");
      for (Generator gen : dependant) {
        report.append(gen.getModuleName()).append("\n");
      }

      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              Messages.showErrorDialog(
                  ProjectHelper.toIdeaProject(project), report.toString(), "Deleting Generator");
            }
          });
      return;
    }

    LanguageDescriptor languageDescriptor = sourceLanguage.getModuleDescriptor();
    languageDescriptor.getGenerators().remove(generator.getModuleDescriptor());
    sourceLanguage.setLanguageDescriptor(languageDescriptor, true);
    if (deleteFiles) {
      LOG.error("DELETE GENERATOR FILES - NOT IMPLEMENTED", new Throwable());
      // todo
    }
    sourceLanguage.save();
  }
Esempio n. 21
0
 @Override
 protected Set<Language> getInitialUsedLanguages() {
   HashSet<Language> result = new HashSet<Language>();
   for (SLanguage l : AbstractModule.this.getUsedLanguages()) {
     SModule langModule = l.getSourceModule();
     if (langModule instanceof Language) {
       result.add((Language) langModule);
     }
   }
   if (AbstractModule.this instanceof Language) {
     result.add((Language) AbstractModule.this);
     // XXX why Language(SModule)#getUsedLanguages doesn't care about descriptor language being
     // used?
     result.add(
         ModuleRepositoryFacade.getInstance()
             .getModule(BootstrapLanguages.descriptorLanguageRef(), Language.class));
   }
   if (AbstractModule.this instanceof Generator) {
     result.add(((Generator) AbstractModule.this).getSourceLanguage());
   }
   return result;
 }
Esempio n. 22
0
 private TemplateModel getTemplateModel(String modelName) {
   ReloadableModule module =
       (ReloadableModule) ModuleRepositoryFacade.getInstance().getModule(getReference());
   Class<TemplateModel> clazz = null;
   if (module != null && module.willLoad()) {
     try {
       clazz = (Class<TemplateModel>) module.getClass(modelName);
     } catch (ClassNotFoundException e) {
       throw new IllegalStateException("Class not found for model " + modelName, e);
     }
   }
   if (clazz == null) {
     throw new IllegalStateException(
         String.format("Failed to obtain generator runtime class for model %s", modelName));
   }
   try {
     return clazz.getConstructor(TemplateModule.class).newInstance(this);
   } catch (RuntimeException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Esempio n. 23
0
 private static boolean hasModule(Library library, SModuleReference reference) {
   SModule module = ModuleRepositoryFacade.getInstance().getModule(reference);
   return hasModule(library, module);
 }
Esempio n. 24
0
 @After
 public void afterTest() {
   ModuleRepositoryFacade.getInstance().unregisterModules(OWNER);
   CleanupManager.getInstance().cleanup();
 }
Esempio n. 25
0
 void dispose() {
   FileSystem.getInstance().removeListener(this);
   ModuleRepositoryFacade.getInstance().unregisterModules(this);
 }