Exemple #1
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;
 }
  private IFile getModelFile(AbstractTreeNode treeNode) {
    if (treeNode instanceof MPSPsiModelTreeNode) {
      MPSPsiModelTreeNode fileNode = (MPSPsiModelTreeNode) treeNode;
      VirtualFile virtualFile = fileNode.getVirtualFile();
      if (virtualFile == null
          || virtualFile.getFileType() != MPSFileTypeFactory.MPS_FILE_TYPE
              && virtualFile.getFileType() != MPSFileTypeFactory.MPS_HEADER_FILE_TYPE) {
        return null;
      }
      return FileSystem.getInstance().getFileByPath(virtualFile.getPath());

    } else if (treeNode instanceof PsiDirectoryNode) {
      VirtualFile virtualFile = ((PsiDirectoryNode) treeNode).getVirtualFile();
      if (virtualFile == null) {
        return null;
      }
      IFile ifile = FileSystem.getInstance().getFileByPath(virtualFile.getPath());
      SModel model = SModelFileTracker.getInstance().findModel(ifile);
      if (model != null) return ifile;
    }
    return null;
  }
Exemple #4
0
  private void updateFields(AnActionEvent e) {
    // cleaning all local fields
    myOperationContext = null;
    myModelDescriptor = null;
    myConceptFqNameToNodePointerMap.clear();
    myProject = e.getData(PlatformDataKeys.PROJECT);

    if (myProject == null) {
      return;
    }
    jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(myProject);
    if (mpsProject == null) {
      return;
    }

    Module module = e.getData(LangDataKeys.MODULE);
    VirtualFile[] vFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
    if (module == null || vFiles == null || vFiles.length != 1) {
      return;
    }

    MPSFacet mpsFacet = FacetManager.getInstance(module).getFacetByType(MPSFacetType.ID);
    if (mpsFacet == null || !mpsFacet.wasInitialized()) {
      return;
    }

    String url = vFiles[0].getUrl();
    if (!LocalFileSystem.PROTOCOL.equals(VirtualFileManager.extractProtocol(url))) {
      return;
    }
    String path = VirtualFileManager.extractPath(url);
    for (ModelRoot root : mpsFacet.getSolution().getModelRoots()) {
      if (!(root instanceof DefaultModelRoot)) continue;
      DefaultModelRoot modelRoot = (DefaultModelRoot) root;
      for (String sourceRoot : modelRoot.getFiles(DefaultModelRoot.SOURCE_ROOTS)) {
        if (path.startsWith(sourceRoot)) {
          Solution solution = mpsFacet.getSolution();
          myOperationContext = new ModuleContext(solution, mpsProject);
          myModelDescriptor =
              (EditableSModel)
                  SModelFileTracker.getInstance()
                      .findModel(FileSystem.getInstance().getFileByPath(vFiles[0].getPath()));
          if (myModelDescriptor != null) {
            mpsProject
                .getModelAccess()
                .runReadAction(
                    new Runnable() {
                      @Override
                      public void run() {
                        SModel model = myModelDescriptor;
                        List<Language> modelLanguages = SModelOperations.getLanguages(model);
                        for (Language language : modelLanguages) {
                          for (SNode concept : language.getConceptDeclarations()) {
                            String conceptFqName = NameUtil.nodeFQName(concept);
                            if (ModelConstraints.canBeRoot(conceptFqName, model, null)) {
                              myConceptFqNameToNodePointerMap.put(
                                  conceptFqName, new jetbrains.mps.smodel.SNodePointer(concept));
                            }
                          }
                        }
                      }
                    });
          } else {
            myNewModel = true;
          }
          return;
        }
      }
    }
  }