@NotNull
  public static Set<SModuleReference> getModules(SRepository repository, final Library library) {
    if (!ModuleLibraryType.isModuleLibrary(library)) {
      return Collections.emptySet();
    }
    final Set<SModuleReference> modules = new HashSet<SModuleReference>();
    final Set<IFile> moduleXmls = new HashSet<IFile>();
    for (VirtualFile file : library.getFiles(ModuleXmlRootDetector.MPS_MODULE_XML)) {
      moduleXmls.add(VirtualFileUtils.toIFile(file));
    }

    repository
        .getModelAccess()
        .runReadAction(
            new Runnable() {
              @Override
              public void run() {
                for (IFile moduleDescriptor : moduleXmls) {
                  SModule moduleByFile =
                      ModuleFileTracker.getInstance().getModuleByFile(moduleDescriptor);
                  if (moduleByFile != null) {
                    modules.add(moduleByFile.getModuleReference());
                  }
                }
              }
            });
    return modules;
  }
  public static SModel doModelParsing(FileContent inputData) {
    SModel model = inputData.getUserData(PARSED_MODEL);

    if (model == null) {
      String ext = FileUtil.getExtension(inputData.getFileName());
      if (MPSFileTypeFactory.MPS_ROOT_FILE_TYPE.equals(inputData.getFile().getFileType())) {
        ext = MPSFileTypeFactory.MPS_HEADER_FILE_TYPE.getDefaultExtension();
      }
      ModelFactory factory = PersistenceFacade.getInstance().getModelFactory(ext);
      if (factory == null) {
        return null;
      }
      if (factory instanceof FolderModelFactory) {
        model =
            PersistenceUtil.loadModel(
                VirtualFileUtils.toIFile(
                    MPSFileTypeFactory.MPS_ROOT_FILE_TYPE.equals(inputData.getFile().getFileType())
                        ? inputData.getFile().getParent().findChild(MPSExtentions.DOT_MODEL_HEADER)
                        : inputData.getFile()));
      } else {
        model =
            factory.isBinary()
                ? PersistenceUtil.loadModel(inputData.getContent(), ext)
                : PersistenceUtil.loadModel(inputData.getContentAsText().toString(), ext);
      }
      if (model == null) {
        return null;
      }
      inputData.putUserData(PARSED_MODEL, model);
    }
    return model;
  }
Exemple #3
0
 @Override
 public void fileStatusChanged(@NotNull VirtualFile file) {
   IFile ifile = VirtualFileUtils.toIFile(file);
   SModel emd = SModelFileTracker.getInstance().findModel(ifile);
   if (emd != null) {
     rehighlightFeatureAndDescendants(new ModelFeature(emd.getReference()));
   }
 }
 private EditableSModel getModel(AbstractTreeNode selectedNode) {
   if (selectedNode instanceof MPSPsiElementTreeNode) {
     MPSPsiNodeBase value = ((MPSPsiElementTreeNode) selectedNode).getValue();
     return getModel(value);
   } else if (selectedNode instanceof MPSPsiModelTreeNode) {
     MPSPsiModel psiModel = ((MPSPsiModelTreeNode) selectedNode).getModel();
     SModel sModel = psiModel.getSModelReference().resolve(MPSModuleRepository.getInstance());
     return (EditableSModel) sModel;
   } else if (selectedNode instanceof PsiDirectoryNode) {
     SModel sModel =
         SModelFileTracker.getInstance()
             .findModel(
                 VirtualFileUtils.toIFile(((PsiDirectoryNode) selectedNode).getVirtualFile()));
     if (sModel instanceof EditableSModel) {
       return (EditableSModel) sModel;
     }
   }
   return null;
 }