private static void addRootsToTrack( final String[] urls, final Collection<String> recursive, final Collection<String> flat) { for (String url : urls) { if (url != null) { final String protocol = VirtualFileManager.extractProtocol(url); if (protocol == null || LocalFileSystem.PROTOCOL.equals(protocol)) { recursive.add(extractLocalPath(url)); } else if (JarFileSystem.PROTOCOL.equals(protocol)) { flat.add(extractLocalPath(url)); } else if (StandardFileSystems.JRT_PROTOCOL.equals(protocol)) { recursive.add(extractLocalPath(url)); } } } }
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; } } } }