@Override
  public void findTargets(
      TargetKind kind,
      Collection<SModel> scope,
      Consumer<NavigationTarget> consumer,
      Consumer<SModel> processedConsumer) {
    final ID<Integer, List<SNodeDescriptor>> indexName = RootNodeNameIndex.NAME;
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

    for (SModel sm : scope) {
      if (sm instanceof EditableSModel && ((EditableSModel) sm).isChanged()) {
        continue;
      }

      DataSource source = sm.getSource();
      if (!(source instanceof FileDataSource)) {
        continue;
      }

      IFile modelFile = ((FileDataSource) source).getFile();
      String ext = FileUtil.getExtension(modelFile.getName());
      if (ext == null
          || modelFile.isDirectory()
          || !(supportedExtensions.contains(ext.toLowerCase()))) {
        continue;
      }

      VirtualFile vf = VirtualFileUtils.getVirtualFile(modelFile);
      if (vf == null) continue; // e.g. model was deleted

      int fileId = FileBasedIndex.getFileId(vf);
      ConcreteFilesGlobalSearchScope fileScope =
          new ConcreteFilesGlobalSearchScope(Collections.singleton(vf));
      List<List<SNodeDescriptor>> descriptors =
          fileBasedIndex.getValues(indexName, fileId, fileScope);
      if (descriptors.isEmpty()) continue;

      boolean needToLoad = false;
      for (NavigationTarget snd : descriptors.get(0)) {
        PropertyConstraintsDescriptor descriptor =
            ConceptRegistry.getInstance()
                .getConstraintsDescriptor(snd.getConcept().getQualifiedName())
                .getProperty(SNodeUtil.property_INamedConcept_name);
        if (descriptor instanceof BasePropertyConstraintsDescriptor
            && !((BasePropertyConstraintsDescriptor) descriptor).isGetterDefault()) {
          needToLoad = true;
          break;
        }
      }

      if (!needToLoad) {
        for (SNodeDescriptor desc : descriptors.get(0)) {
          consumer.consume(desc);
        }
        processedConsumer.consume(sm);
      }
    }
  }
  private VirtualFile[] getSelectedFiles() {
    List<VirtualFile> selectedFilesList = new LinkedList<VirtualFile>();

    // add selected model files
    List<SModelDescriptor> descriptors = getSelectedModels();
    if (descriptors != null) {
      for (SModelDescriptor descriptor : descriptors) {
        selectedFilesList.addAll(ModelUtil.getVFilesByModelDescriptor(descriptor));
      }
    }

    // add selected modules files
    List<SModule> modules = getSelectedModules();
    if (modules != null) {
      for (SModule m : modules) {
        if (!(m instanceof AbstractModule)) continue;
        AbstractModule module = (AbstractModule) m;
        IFile home = module.getBundleHome();
        if (home != null) {
          VirtualFile vfile = VirtualFileUtils.getVirtualFile(home);
          if (vfile != null) {
            selectedFilesList.add(vfile);
          }
        }
        IFile ifile = module.getDescriptorFile();
        if (ifile != null) {
          VirtualFile vfile = VirtualFileUtils.getVirtualFile(ifile);
          if (vfile != null) {
            selectedFilesList.add(vfile);
          }
        }
      }
    }

    if (selectedFilesList.size() == 0) {
      return null;
    }

    return selectedFilesList.toArray(new VirtualFile[selectedFilesList.size()]);
  }
Exemple #3
0
 @Nullable
 private static FileStatus getModelFileStatus(
     @NotNull EditableSModel ed, @NotNull Project project) {
   DataSource ds = ed.getSource();
   IFile file = null;
   if (ds instanceof FileDataSource) {
     file = ((FileDataSource) ds).getFile();
   } else if (ds instanceof FilePerRootDataSource) {
     file = ((FilePerRootDataSource) ds).getFile(FilePerRootDataSource.HEADER_FILE);
   }
   VirtualFile vf = VirtualFileUtils.getVirtualFile(file);
   return (vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf));
 }
  private void update(boolean force) {
    final Wrappers._boolean _force = new Wrappers._boolean(force);
    myQueue.assertSoftlyIsCommandThread();
    if (!(myDifference.isEnabled())) {
      return;
    }

    IFile modelFile = myModelDescriptor.getSource().getFile();
    if (!(modelFile.exists())) {
      return;
    }
    VirtualFile modelVFile = VirtualFileUtils.getVirtualFile(modelFile);
    if (modelVFile == null
        || ProjectLevelVcsManager.getInstance(myProject).getVcsFor(modelVFile) == null) {
      return;
    }
    FileStatus status = FileStatusManager.getInstance(myProject).getStatus(modelVFile);
    if (ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) {
      status = FileStatus.MERGED_WITH_CONFLICTS;
    }

    if (myDifference.getChangeSet() != null) {
      ModelAccess.instance()
          .runReadAction(
              new Runnable() {
                public void run() {
                  if (myDifference.getChangeSet().getNewModel() != myModelDescriptor.getSModel()) {
                    _force.value = true;
                  }
                }
              });
    }

    if (myStatusOnLastUpdate == status && !(_force.value)) {
      return;
    }
    myDifference.removeChangeSet();
    myStatusOnLastUpdate = status;
    if (FileStatus.NOT_CHANGED == status && !(_force.value)) {
      return;
    }
    final Wrappers._T<SModel> baseVersionModel = new Wrappers._T<SModel>(null);
    if (BaseVersionUtil.isAddedFileStatus(status)
        || ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) {
      baseVersionModel.value =
          new jetbrains.mps.smodel.SModel(myModelDescriptor.getSModelReference());
    } else {
      String content = BaseVersionUtil.getBaseVersionContent(modelVFile, myProject);
      if (content == null && status != FileStatus.NOT_CHANGED) {
        LOG.error("Base version content is null while file status is " + status);
      }
      if (content == null) {
        return;
      }
      try {
        baseVersionModel.value = ModelPersistence.readModel(content, false);
      } catch (ModelReadException e) {
        LOG.warning("", e);
        return;
      }
    }
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                synchronized (ChangesTracking.this) {
                  if (!(myDisposed)) {
                    ChangeSet changeSet =
                        ChangeSetBuilder.buildChangeSet(
                            baseVersionModel.value, myModelDescriptor.getSModel(), true);
                    myDifference.setChangeSet((ChangeSetImpl) changeSet);
                    buildCaches();
                  }
                }
              }
            });
  }
Exemple #5
0
  private static boolean annotate(@NotNull final EditorComponent editorComponent, boolean dryRun) {
    final LeftEditorHighlighter leftEditorHighlighter = editorComponent.getLeftEditorHighlighter();
    if (findAnnotationColumn(editorComponent) != null) {
      if (!(dryRun)) {
        leftEditorHighlighter.removeLeftColumn(findAnnotationColumn(editorComponent));
      }
      return true;
    }
    final SNode root = editorComponent.getEditedNode();
    SModel model = check_19hp0u_a0d0b(root);
    SModelDescriptor modelDescriptor = check_19hp0u_a0e0b(model);
    if (!((modelDescriptor instanceof EditableSModelDescriptor))) {
      return false;
    }
    IFile modelFile = ((EditableSModelDescriptor) modelDescriptor).getModelFile();
    if (modelFile == null) {
      return false;
    }
    final VirtualFile file = VirtualFileUtils.getVirtualFile(modelFile);
    final Project project =
        ProjectHelper.toIdeaProject(editorComponent.getOperationContext().getProject());
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
    if (vcs == null) {
      return false;
    }

    _FunctionTypes._return_P1_E0<? extends Boolean, ? super FileStatus> checkFileStatus =
        new _FunctionTypes._return_P1_E0<Boolean, FileStatus>() {
          public Boolean invoke(FileStatus fs) {
            return fs == FileStatus.UNKNOWN || fs == FileStatus.ADDED || fs == FileStatus.IGNORED;
          }
        };
    if (checkFileStatus.invoke(FileStatusManager.getInstance(project).getStatus(file))) {
      return false;
    }

    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    if (annotationProvider == null) {
      return false;
    }

    if (dryRun) {
      return true;
    }
    Task.Backgroundable annotateTask =
        new Task.Backgroundable(
            project, "Retrieving annotations", true, BackgroundFromStartOption.getInstance()) {
          private FileAnnotation myFileAnnotation;
          private VcsException myException;

          public void run(@NotNull ProgressIndicator indicator) {
            try {
              myFileAnnotation = annotationProvider.annotate(file);
            } catch (VcsException e) {
              myException = e;
            }
          }

          @Override
          public void onCancel() {
            onSuccess();
          }

          @Override
          public void onSuccess() {
            if (myException != null) {
              AbstractVcsHelper.getInstance(project)
                  .showErrors(Arrays.asList(myException), "Exception on retrieving annotation");
            }

            if (myFileAnnotation != null) {
              ModelAccess.instance()
                  .runReadAction(
                      new Runnable() {
                        public void run() {
                          AnnotationColumn annotationColumn =
                              new AnnotationColumn(
                                  leftEditorHighlighter, root, myFileAnnotation, vcs, file);
                          leftEditorHighlighter.addLeftColumn(annotationColumn);
                        }
                      });
            }
          }
        };
    ProgressManager.getInstance().run(annotateTask);
    return true;
  }