コード例 #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();
 }
コード例 #2
0
ファイル: GeneratorValidator.java プロジェクト: brigand/MPS
  @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;
  }
コード例 #3
0
ファイル: BaseQuickFixProvider.java プロジェクト: yan96in/MPS
 @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;
   }
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: BaseModuleValidator.java プロジェクト: sprig/MPS
  @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;
  }
コード例 #6
0
ファイル: StubModelsResolver.java プロジェクト: brigand/MPS
  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);
  }
コード例 #7
0
 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);
 }
コード例 #8
0
 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);
 }
コード例 #9
0
ファイル: GeneratorValidator.java プロジェクト: brigand/MPS
 @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;
 }
コード例 #10
0
ファイル: Generator.java プロジェクト: qyqx/MPS
 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);
   }
 }
コード例 #11
0
ファイル: ModelProperties.java プロジェクト: handong890/MPS
 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);
   }
 }
コード例 #12
0
ファイル: MPSProject.java プロジェクト: wolfhesse/MPS
 @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;
 }
コード例 #13
0
ファイル: ModuleSymbolicSuite.java プロジェクト: yan96in/MPS
  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;
  }
コード例 #14
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());
                 }
               }));
 }
コード例 #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();
 }
コード例 #16
0
ファイル: Generator.java プロジェクト: huangchaoneng/MPS
 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);
   }
 }
コード例 #17
0
ファイル: AbstractModule.java プロジェクト: JetBrains/MPS
 @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;
     }
   }
 }
コード例 #18
0
ファイル: DeleteGeneratorHelper.java プロジェクト: sprig/MPS
  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();
  }
コード例 #19
0
ファイル: AbstractModule.java プロジェクト: JetBrains/MPS
 @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;
 }
コード例 #20
0
ファイル: Generator.java プロジェクト: ramakantmoka/MPS
 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);
   }
 }
コード例 #21
0
 private static boolean hasModule(Library library, SModuleReference reference) {
   SModule module = ModuleRepositoryFacade.getInstance().getModule(reference);
   return hasModule(library, module);
 }
コード例 #22
0
ファイル: SLibrary.java プロジェクト: brigand/MPS
 void dispose() {
   FileSystem.getInstance().removeListener(this);
   ModuleRepositoryFacade.getInstance().unregisterModules(this);
 }
コード例 #23
0
ファイル: DependenciesTests.java プロジェクト: sprig/MPS
 @After
 public void afterTest() {
   ModuleRepositoryFacade.getInstance().unregisterModules(OWNER);
   CleanupManager.getInstance().cleanup();
 }