예제 #1
0
 private static boolean hasModule(Library library, SModule module) {
   if (!isSuitableModule(module) || !ModuleLibraryType.isModuleLibrary(library)) {
     return false;
   }
   Solution solution = (Solution) module;
   return Arrays.asList(library.getFiles(ModuleXmlRootDetector.MPS_MODULE_XML))
       .contains(VirtualFileUtils.getOrCreateVirtualFile(solution.getDescriptorFile()));
 }
예제 #2
0
 public static Library getOrCreateAutoLibrary(
     AbstractModule usedModule, Project project, LibrariesContainer container) {
   Library library = getAutoLibrary(usedModule.getModuleReference(), project);
   if (library != null) {
     return library;
   }
   Set<VirtualFile> stubFiles = ModuleLibraryType.getModuleJars(usedModule);
   IFile descriptorFile = usedModule.getDescriptorFile();
   VirtualFile descriptorVirtualFile = null;
   if (descriptorFile != null) {
     descriptorVirtualFile = VirtualFileUtils.getOrCreateVirtualFile(descriptorFile);
   }
   return createAutoLibrary(
       usedModule.getModuleName(), stubFiles, descriptorVirtualFile, container);
 }
예제 #3
0
  private <T> MultiMap<SModel, T> findCandidates(
      Collection<SModel> models,
      Set<T> elems,
      Consumer<SModel> processedModels,
      Function<T, UsageEntry> id) {
    // get all files in scope
    final ManyToManyMap<SModel, VirtualFile> scopeFiles = new ManyToManyMap<SModel, VirtualFile>();
    for (final SModel sm : models) {
      if (sm instanceof EditableSModel && ((EditableSModel) sm).isChanged()) {
        continue;
      }

      DataSource source = sm.getSource();
      // these are data sources this participant knows about
      if (!(source instanceof FileDataSource || source instanceof FilePerRootDataSource)) {
        continue;
      }

      /*
      This is a tmp fix for MPS-24151. See the issue to learn about the correct fix
       */
      if (!(sm instanceof DefaultSModelDescriptor)) {
        continue;
      }

      Collection<IFile> modelFiles = getDataSourceFiles(source);
      for (IFile modelFile : modelFiles) {
        String ext = FileUtil.getExtension(modelFile.getName());
        if (ext == null || modelFile.isDirectory()) {
          continue;
        }

        VirtualFile vf = VirtualFileUtils.getOrCreateVirtualFile(modelFile);
        if (vf == null) {
          LogManager.getLogger(MPSModelsFastFindSupport.class)
              .warn(
                  String.format(
                      "Model %s: virtual file not found for model file. Model file: %s",
                      sm.getName(), modelFile.getPath()));
          continue;
        }
        processedModels.consume(sm);
        scopeFiles.addLink(sm, vf);
      }
    }

    // filter files with usages
    ConcreteFilesGlobalSearchScope allFiles =
        new ConcreteFilesGlobalSearchScope(scopeFiles.getSecond());
    // process indexes
    MultiMap<SModel, T> result = new SetBasedMultiMap<SModel, T>();
    for (T elem : elems) {
      UsageEntry entry = id.apply(elem);

      Collection<VirtualFile> matchingFiles;

      try {
        matchingFiles = MPSModelsIndexer.getContainingFiles(entry, allFiles);
      } catch (ProcessCanceledException ce) {
        matchingFiles = Collections.emptyList();
      }

      // back-transform
      for (VirtualFile file : matchingFiles) {
        for (SModel m : scopeFiles.getBySecond(file)) {
          result.putValue(m, elem);
        }
      }
    }
    return result;
  }