@NotNull private String[] getInitialEditorHints(EditorContext editorContext) { if (myInitialEditorHints != null) { return myInitialEditorHints; } Project project = ProjectHelper.toIdeaProject(ProjectHelper.getProject(editorContext.getRepository())); if (project == null) { return EMPTY_HINTS_ARRAY; } HintsState state = ConceptEditorHintSettingsComponent.getInstance(project).getState(); return state.getEnabledHints().toArray(EMPTY_HINTS_ARRAY); }
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { try { MPSPropertiesConfigurable configurable = new ModulePropertiesConfigurable( ((SModule) MapSequence.fromMap(_params).get("module")), ((IOperationContext) MapSequence.fromMap(_params).get("context")).getProject()); final SingleConfigurableEditor configurableEditor = new SingleConfigurableEditor( ProjectHelper.toIdeaProject( ((IOperationContext) MapSequence.fromMap(_params).get("context")).getProject()), configurable, "#MPSPropertiesConfigurable"); configurable.setParentForCallBack(configurableEditor); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { configurableEditor.show(); } }); } catch (Throwable t) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("User's action execute method failed. Action:" + "ModuleProperties", t); } } }
@Override protected Set<BreakpointWithHighlighter> getBreakpointsForComponent( @NotNull final EditorComponent component) { final Set<BreakpointWithHighlighter> result = new HashSet<BreakpointWithHighlighter>(); final List<Breakpoint> breakpoints = myDebuggerManager .getBreakpointManager() .getBreakpoints(); // XDebuggerManager.getInstance(myProject).getBreakpointManager() ProjectHelper.getModelAccess(myProject) .runReadAction( new Runnable() { @Override public void run() { for (Breakpoint breakpoint : breakpoints) { if (breakpoint instanceof BreakpointWithHighlighter) { BreakpointWithHighlighter breakpointWithHighlighter = (BreakpointWithHighlighter) breakpoint; SNode node = BreakpointPainter.getNodeForBreakpoint(breakpointWithHighlighter); if (node != null && EditorComponentUtil.isNodeShownInTheComponent(component, node)) { result.add(breakpointWithHighlighter); } } } } }); return result; }
@Override public void selectInTree( @NotNull IOperationContext context, @NotNull SModel model, boolean focus) { ProjectPane projectPane = ProjectPane.getInstance(ProjectHelper.toIdeaProject(context.getProject())); projectPane.selectModel(model, focus); }
@NotNull protected final Project getProject() { Project mpsProject = ProjectHelper.toMPSProject(this.getConsoleTool().getProject()); if (mpsProject == null) { throw new IllegalStateException("Cannot convert idea project to the mps project"); } return mpsProject; }
@Override public void selectInTree( @NotNull IOperationContext context, @NotNull SModule module, boolean focus) { ProjectPane projectPane = ProjectPane.getInstance(ProjectHelper.toIdeaProject(context.getProject())); // TODO IModule cast projectPane.selectModule((IModule) module, focus); }
public static IOperationContext getOperationContext( com.intellij.openapi.project.Project project, SModel model) { SModelDescriptor md = model.getModelDescriptor(); assert md != null; IModule module = md.getModule(); if (module instanceof DiffTemporaryModule) { return ((DiffTemporaryModule) module).createContext(); } else { return new ModuleContext(module, ProjectHelper.toMPSProject(project)); } }
public NewSolutionDialog(Project project, @Nullable String virtualFolder) { super(ProjectHelper.toIdeaProject(project)); setTitle("New Solution"); setOKButtonText("&OK"); setCancelButtonText("Ca&ncel"); myProject = project; myVirtualFolder = virtualFolder; init(); }
private void execute_internal( final KeyEvent keyEvent, final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) { IOperationContext operationContext = editorContext.getOperationContext(); Project project = operationContext.getProject(); ProjectPane.getInstance(ProjectHelper.toIdeaProject(project)) .selectModule(Module_Behavior.call_getModule_1213877515148(node), false); }
public void init(Project project) { super.init(project); ModuleRepository_Tool.this.myComponent = new ModuleRepositoryComponent(ProjectHelper.toMPSProject(project)); ModuleRepository_Tool.this.myPanel = new JPanel(new BorderLayout()); ModuleRepository_Tool.this.myPanel.add( ModuleRepository_Tool.this.myComponent.getComponent(), BorderLayout.CENTER); DefaultActionGroup group = new DefaultActionGroup(); group.add(new CloseAction(ModuleRepository_Tool.this)); JComponent toolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.UNKNOWN, group, false) .getComponent(); ModuleRepository_Tool.this.myPanel.add(toolbar, BorderLayout.WEST); }
@Override @NotNull protected List<EditorComponent> getComponentsForBreakpoint( @NotNull final BreakpointWithHighlighter breakpoint) { return new ModelAccessHelper(ProjectHelper.getModelAccess(myProject)) .runReadAction( new Computable<List<EditorComponent>>() { public List<EditorComponent> compute() { SNode node = BreakpointPainter.getNodeForBreakpoint(breakpoint); if (node != null) { return EditorComponentUtil.findComponentForNode(node, myFileEditorManager); } return Collections.emptyList(); } }); }
private static void execute_id7oNS25df64x(@NotNull SNode __thisNode__, Project project) { SNode targetNode = SLinkOperations.getTarget( __thisNode__, MetaAdapterFactory.getReferenceLink( 0xde1ad86d6e504a02L, 0xb306d4d17f64c375L, 0x36ac6f29ae8c1fb5L, 0x4904fd89e74fc6fL, "target")); jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project); if (mpsProject == null) { return; } NavigationSupport.getInstance() .openNode(mpsProject, targetNode, true, !(SNodeOperations.isRoot(targetNode))); }
@NotNull protected IOperationContext createOperationContext() { if (myContext != null) { return myContext; } assert isValid() : "createOperationContext() was called for MPSFileNodeEditor with invalid file: " + myFile; SModelDescriptor sm = myFile.getNode().getModel().getModelDescriptor(); assert sm != null : "Model descriptor is null for model: " + myFile.getNode().getModel(); IOperationContext result = new ModuleContext(sm.getModule(), ProjectHelper.toMPSProject(myProject)); assert result.getModule() == sm.getModule() : "Different modules: " + result.getModule() + "/" + sm.getModule(); return result; }
private <T> T getModelProvider( AbstractTreeNode treeNode, ModelProviderFactory<T> createProvider) { if (!(treeNode instanceof MPSPsiModelTreeNode)) return null; // only model MPSPsiModel psiModel = ((MPSPsiModelTreeNode) treeNode).getModel(); if (psiModel == null || !psiModel.isValid()) return null; Project project = treeNode.getProject(); EditableSModel modelDescriptor = getModel(treeNode); jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project); if (mpsProject == null || modelDescriptor == null) return null; SModel sModel = modelDescriptor; if (sModel == null) return null; return createProvider.create(modelDescriptor, sModel, mpsProject); }
@Override public void doubleClick() { Project project = getProject(); final SRepository r = ProjectHelper.getProjectRepository(project); SModule m = (r == null ? null : new ModelAccessHelper(r) .runReadAction( new Computable<SModule>() { public SModule compute() { return myModule.resolve(r); } })); if (m == null) { return; } ProjectPane.getInstance(project).selectModule(m, false); }
public RenameLanguageDialog(com.intellij.openapi.project.Project project, Language language) throws HeadlessException { super(project, language.getModuleName(), "language"); myLanguage = language; myProject = ProjectHelper.toMPSProject(project); setTitle("Rename Language"); final boolean[] regenerateHolder = new boolean[] {false}; myProject .getRepository() .getModelAccess() .runReadAction( new Runnable() { public void run() { regenerateHolder[0] = !(myLanguage.isBootstrap()); } }); myRegenerateLanguage.getModel().setSelected(regenerateHolder[0]); }
protected IOperationContext createOperationContext() { if (myContext != null) { return myContext; } assert isValid() : "createOperationContext() was called for MPSFileNodeEditor with invalid file: " + myFile; SNode node = myFile.getNode(); if (node == null || node.getModel() == null || node.getModel().getModelDescriptor() == null) { myIsValid = false; return null; } SModelDescriptor sm = node.getModel().getModelDescriptor(); IOperationContext result = new ModuleContext(sm.getModule(), ProjectHelper.toMPSProject(myProject)); assert result.getModule() == sm.getModule() : "Different modules: " + result.getModule() + "/" + sm.getModule(); return result; }
public UnitTestViewComponent( Project project, ConsoleView console, TestRunState testRunState, _FunctionTypes._void_P0_E0 closeListener) { myProject = project; myTestState = testRunState; StatisticsTableModel statisticsModel = new StatisticsTableModel(myTestState); myTreeComponent = new TestTree(myTestState, ProjectHelper.toMPSProject(project), this); myTestNavigator = new FailedTestOccurrenceNavigator(myTreeComponent); myActionToolComponent = new TestToolbarPanel(myTreeComponent, myTestNavigator); JComponent leftPanel = createTreeComponent(myActionToolComponent, myTreeComponent); myProgressLineComponent = new ProgressLine(myTestState); myProgressLineComponent.setMinimumSize( new Dimension(0, myProgressLineComponent.getMinimumSize().height)); myOutputComponent = new TestOutputComponent(myProject, this, console, myTestState); myTreeComponent.addTreeSelectionListener( new TestTreeSelectionListener(myTreeComponent, statisticsModel, myOutputComponent)); myTreeComponent.addMouseListener( new TestTreeRootMouseListener(myTreeComponent, statisticsModel, myOutputComponent)); JPanel rightPanel = createOutputComponent( console, myProgressLineComponent, myOutputComponent.getComponent(), statisticsModel); Splitter splitter = new Splitter(false); initSplitterProportion(splitter, 0.2f, "tree"); splitter.setFirstComponent(leftPanel); splitter.setSecondComponent(rightPanel); setLayout(new BorderLayout()); add(splitter, BorderLayout.CENTER); myTestState.addView(myTreeComponent); myTestState.addView(myProgressLineComponent); myTestState.addView(myOutputComponent); addCloseListener(closeListener); }
private SNode getNode(AbstractTreeNode treeNode) { if (!(treeNode instanceof MPSPsiElementTreeNode)) { return null; } MPSPsiNodeBase psiNode = ((MPSPsiElementTreeNode) treeNode).getValue(); if (!(psiNode instanceof MPSPsiRealNode)) { return null; } final SNodeReference nodeRef = ((MPSPsiRealNode) psiNode).getSNodeReference(); final SRepository repository = ProjectHelper.getProjectRepository(treeNode.getProject()); // TODO remove read action from here once SModelFileTracker stops doing the same (creating read // action if not already in one) return new ModelComputeRunnable<SNode>( new Computable<SNode>() { @Override public SNode compute() { return nodeRef.resolve(repository); } }) .runRead(repository.getModelAccess()); }
protected void createEditor() { this.myEditor = new UIEditorComponent( check_6q36mf_a0a0a0a82(ProjectHelper.toMPSProject(myTool.getProject())), null) { @Nullable @Override public Object getData(@NonNls String key) { if (PlatformDataKeys.FILE_EDITOR.is(key)) { return myFileEditor; } if (PlatformDataKeys.PASTE_PROVIDER.is(key)) { PasteProvider parentPasteProvider = as_6q36mf_a0a0a1a0a0a0a0cb(super.getData(key), PasteProvider.class); return (myTool.getPasteAsRef() ? new BaseConsoleTab.MyPasteProvider(parentPasteProvider) : parentPasteProvider); } return super.getData(key); } }; myEditor.editNode(myRoot); }
@Nullable public JComponent createCenterPanel() { if (mySolutionSettings == null) { mySolutionSettings = new NewSolutionSettings( (myProject != null ? ((((ProjectEx) ProjectHelper.toIdeaProject(myProject)) .getStateStore() .getStorageScheme() != StorageScheme.DIRECTORY_BASED ? myProject.getProjectFile().getParentFile().getAbsolutePath() : myProject.getProjectFile().getAbsolutePath())) : null)); mySolutionSettings.setListener( new NewSolutionSettings.SolutionSettingsChangedListener() { @Override public void changed() { NewSolutionDialog.this.check(); } }); } return mySolutionSettings; }
private <T> T getProvider( Collection<AbstractTreeNode> selected, ProviderFactory<T> createProvider) { if (selected.size() == 0) return null; List<SNodeReference> selectedNodePointers = new ArrayList<SNodeReference>(); Project project = null; EditableSModel modelDescriptor = null; for (AbstractTreeNode treeNode : selected) { if (!(treeNode instanceof MPSPsiElementTreeNode)) return null; // only root nodes please MPSPsiRootNode mpsPsiNode = ((MPSPsiElementTreeNode) treeNode).getValue(); if (!mpsPsiNode.isValid()) return null; selectedNodePointers.add(mpsPsiNode.getSNodeReference()); if (project == null) { project = treeNode.getProject(); } else if (project != treeNode.getProject()) { return null; // only same project } if (modelDescriptor == null) { modelDescriptor = getModel(mpsPsiNode); } else if (modelDescriptor != getModel(mpsPsiNode)) { return null; // only same model } } jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project); if (mpsProject == null || modelDescriptor == null) return null; SModel sModel = modelDescriptor; if (sModel == null) return null; return createProvider.create(selectedNodePointers, modelDescriptor, sModel, mpsProject); }
@Override protected void doRefactoringAction() { final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected(); final String fqName = getCurrentValue(); if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) { setErrorText("Duplicate language name"); return; } if (!((SourceVersion.isName(fqName)))) { setErrorText("Language namespace should be valid Java package"); return; } final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName); ModelAccess.instance() .runWriteActionInCommand( new Runnable() { public void run() { renamer.rename(needToRegenerate); renamer.update(); } }); if (needToRegenerate) { final Set<Language> langs = new LinkedHashSet<Language>(); ModelAccess.instance() .runReadAction( new Runnable() { @Override public void run() { langs.add(myLanguage); langs.addAll( ModuleRepositoryFacade.getInstance().getAllExtendingLanguages(myLanguage)); } }); for (final Language l : langs) { GenParameters params = ModelAccess.instance() .runReadAction( new Computable<GenParameters>() { @Override public GenParameters compute() { ModuleTestConfiguration languageConfig = new ModuleTestConfiguration(); languageConfig.setModuleRef(l.getModuleReference()); languageConfig.setName("tmp"); try { return languageConfig.getGenParams( myProject.getComponent(MPSProject.class), true); } catch (IllegalGeneratorConfigurationException e) { return null; } } }); if (params == null) { setErrorText("Rebuild configuration is invalid"); return; } ModuleContext context = new ModuleContext(myLanguage, ProjectHelper.toMPSProject(myProject)); MakeSession sess = new MakeSession(context); if (IMakeService.INSTANCE.get().openNewSession(sess)) { IMakeService.INSTANCE .get() .make( sess, new ModelsToResources( context, ListSequence.fromListWithValues( new ArrayList<SModel>(), (Iterable<SModel>) params.getModelDescriptors())) .resources(false)); } // GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage, // myProject), params.getModelDescriptors(), // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false); } } super.doRefactoringAction(); }
public MPSFileNodeEditor(IOperationContext context, final MPSNodeVirtualFile file) { this(ProjectHelper.toIdeaProject(context.getProject()), file, context); }
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; }
@Override public Collection<AbstractTreeNode> modify( final AbstractTreeNode treeNode, final Collection<AbstractTreeNode> children, final ViewSettings settings) { final Ref<Collection<AbstractTreeNode>> result = new Ref<Collection<AbstractTreeNode>>(children); // we're actually in EDT here, but we work with SModels, and various routines assert that we can // read, thus read action ProjectHelper.getProjectRepository(treeNode.getProject()) .getModelAccess() .runReadAction( new Runnable() { @Override public void run() { List<AbstractTreeNode> updatedChildren = null; final MPSPsiProvider mpsPsiProvider = MPSPsiProvider.getInstance(treeNode.getProject()); // if current dir is data source from some model FolderDataSource currentDirectoryDataSource = null; if (treeNode instanceof PsiDirectoryNode) { // let's see if we have a model built from this dir, e.g. in per-root persistence SModel sModel = SModelFileTracker.getInstance() .findModel( VirtualFileUtils.toIFile( ((PsiDirectoryNode) treeNode).getVirtualFile())); if (sModel != null) { // adding root nodes (removing their corresponding files' nodes from the tree is // further below) List<MPSPsiElementTreeNode> rootsTreeNodes = new ArrayList<MPSPsiElementTreeNode>(); for (SNode root : sModel.getRootNodes()) { rootsTreeNodes.add( new MPSPsiElementTreeNode( treeNode.getProject(), (MPSPsiRootNode) mpsPsiProvider.getPsi(root).getContainingFile(), settings)); } if (!rootsTreeNodes.isEmpty() && updatedChildren == null) { updatedChildren = new ArrayList<AbstractTreeNode>(children); updatedChildren.addAll(rootsTreeNodes); } DataSource dataSource = sModel.getSource(); if (dataSource instanceof FolderDataSource) { // could be assert as currently SModelFileTracker only tracks FileDataSource // and FolderDataSource currentDirectoryDataSource = (FolderDataSource) dataSource; } } } else if (treeNode instanceof MPSPsiModelTreeNode) { MPSPsiModel psiModel = ((MPSPsiModelTreeNode) treeNode).extractPsiFromValue(); updatedChildren = new ArrayList<AbstractTreeNode>(); for (PsiElement psiElement : psiModel.getChildren()) { updatedChildren.add( new MPSPsiElementTreeNode( treeNode.getProject(), (MPSPsiRootNode) psiElement, settings)); } } for (final AbstractTreeNode child : children) { if (child instanceof PsiFileNode) { VirtualFile vFile = ((PsiFileNode) child).getVirtualFile(); if (vFile == null) { continue; } // check if it's a single file model final SModel sModel = SModelFileTracker.getInstance().findModel(VirtualFileUtils.toIFile(vFile)); if (sModel != null) { if (updatedChildren == null) updatedChildren = new ArrayList<AbstractTreeNode>(children); int idx = updatedChildren.indexOf(child); updatedChildren.remove(idx); updatedChildren.add( idx, new MPSPsiModelTreeNode( treeNode.getProject(), mpsPsiProvider.getPsi(sModel), settings)); continue; } if (currentDirectoryDataSource != null && currentDirectoryDataSource.isIncluded(VirtualFileUtils.toIFile(vFile))) { // it's a file that constitutes a FolderDataSource-backed model, remove it // from the tree (root nodes are shown instead) if (updatedChildren == null) updatedChildren = new ArrayList<AbstractTreeNode>(children); int idx = updatedChildren.indexOf(child); updatedChildren.remove(idx); } } else if (child instanceof PsiDirectoryNode) { // below code only attaches our action to the directory and makes it show added // children - our root nodes final SModel perRootModel = SModelFileTracker.getInstance() .findModel( VirtualFileUtils.toIFile( ((PsiDirectoryNode) child).getVirtualFile())); if (perRootModel != null) { if (updatedChildren == null) updatedChildren = new ArrayList<AbstractTreeNode>(children); int idx = updatedChildren.indexOf(child); updatedChildren.remove(idx); updatedChildren.add( idx, new PsiDirectoryNode( treeNode.getProject(), ((PsiDirectoryNode) child).getValue(), settings) { @Override public boolean canNavigate() { return true; } @Override public String getNavigateActionText(boolean focusEditor) { return MPSBundle.message("open.model.properties.action"); } @Override public void navigate(boolean requestFocus) { MPSPropertiesConfigurable configurable = new ModelPropertiesConfigurable( perRootModel, ProjectHelper.toMPSProject(myProject), true); final SingleConfigurableEditor dialog = new SingleConfigurableEditor(myProject, configurable); configurable.setParentForCallBack(dialog); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { dialog.show(); } }); } }); } } } if (updatedChildren != null) { result.set(updatedChildren); } } }); return result.get(); }
public void run() { ModelAccessHelper mah = new ModelAccessHelper(myProject.getModelAccess()); final SNode contextEnumConstant = mah.runReadAction( new Computable<SNode>() { public SNode compute() { return SNodeOperations.getAncestor( mySelectedNode, "jetbrains.mps.baseLanguage.structure.EnumConstantDeclaration", true, false); } }); final SNode contextMember = mah.runReadAction( new Computable<SNode>() { public SNode compute() { return SNodeOperations.getAncestor( mySelectedNode, "jetbrains.mps.baseLanguage.structure.ClassifierMember", true, false); } }); final SNodeReference[] methods = mah.runReadAction( new Computable<SNodeReference[]>() { @Override public SNodeReference[] compute() { List<SNode> methodsToOverride = (myIsOverride ? BehaviorReflection.invokeVirtual( (Class<List<SNode>>) ((Class) Object.class), contextEnumConstant, "virtual_getMethodsToOverride_5418393554803767537", new Object[] {}) : BehaviorReflection.invokeVirtual( (Class<List<SNode>>) ((Class) Object.class), contextEnumConstant, "virtual_getMethodsToImplement_5418393554803775106", new Object[] {})); List<SNode> allSuperClassifiers = BehaviorReflection.invokeNonVirtual( (Class<List<SNode>>) ((Class) Object.class), SNodeOperations.cast( SNodeOperations.getParent(contextEnumConstant), "jetbrains.mps.baseLanguage.structure.EnumClass"), "jetbrains.mps.baseLanguage.structure.ClassConcept", "call_getAllSuperClassifiers_4892662966716545618", new Object[] {}); ListSequence.fromList(allSuperClassifiers) .addElement( SNodeOperations.cast( SNodeOperations.getParent(contextEnumConstant), "jetbrains.mps.baseLanguage.structure.Classifier")); return OverrideImplementMethodsDialog.toNodePointers( OverrideImplementMethodsDialog.sortMethods( allSuperClassifiers, methodsToOverride)); } }); final OverrideImplementMethodsDialog dialog = new OverrideImplementMethodsDialog(methods, ProjectHelper.toIdeaProject(myProject)) { @Override protected boolean showInsertOverride() { return myIsOverride; } }; dialog.setTitle((myIsOverride ? "Select Methods to Override" : "Select Methods to Implement")); dialog.show(); if (dialog.isOK()) { final Iterable<SNodeReference> selectedElements = (Iterable<SNodeReference>) dialog.getSelectedElements(); myProject .getModelAccess() .executeCommandInEDT( new Runnable() { @Override public void run() { List<SNode> selection = Sequence.fromIterable(selectedElements) .select( new ISelector<SNodeReference, SNode>() { public SNode select(SNodeReference it) { return SNodeOperations.cast( ((SNodePointer) it) .resolve(MPSModuleRepository.getInstance()), "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration"); } }) .toListSequence(); OverrideImplementMethodsHelper helper = new OverrideImplementMethodsInEnumHelper( myProject, SNodeOperations.cast( SNodeOperations.getParent(contextEnumConstant), "jetbrains.mps.baseLanguage.structure.EnumClass"), contextEnumConstant, contextMember, dialog.isRemoveAttributes(), dialog.isInsertOverrideAnnotation(), dialog.isAddReturn()); List<SNode> insertedMethods = helper.insertMethods(selection); if (insertedMethods.isEmpty()) { return; } SNode firstMethod = ListSequence.fromList(insertedMethods).first(); SNode nodeToSelect; if (ListSequence.fromList( SLinkOperations.getTargets( SLinkOperations.getTarget(firstMethod, "body", true), "statement", true)) .isNotEmpty()) { nodeToSelect = ListSequence.fromList( SLinkOperations.getTargets( SLinkOperations.getTarget(firstMethod, "body", true), "statement", true)) .first(); } else { nodeToSelect = firstMethod; } myEditorContext.flushEvents(); myEditorContext.getSelectionManager().setSelection(nodeToSelect); } }); } }
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; } } } }
@Override public void processQuery( @NotNull SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) { if (!(queryParameters.getEffectiveSearchScope() instanceof GlobalSearchScope)) { return; } final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getEffectiveSearchScope(); final PsiElement target = queryParameters.getElementToSearch(); // Only class names can be prefixes in foreign ids of other nodes if (!(target instanceof PsiClass)) return; final SRepository repository = ProjectHelper.getProjectRepository(scope.getProject()); if (repository == null) { return; } repository .getModelAccess() .runReadAction( new Runnable() { @Override public void run() { final NodePtr nodePtr = JavaForeignIdBuilder.computeNodePtr(target); if (nodePtr == null) return; final SNodeReference mpsTarget = new SNodePointer(nodePtr.getSModelReference(), nodePtr.getNodeId()); // do we have this node? if (mpsTarget.resolve(MPSModuleRepository.getInstance()) == null) return; String prefix = nodePtr.getNodeId().toString(); final String prefixToSearch = (prefix.startsWith(Foreign.ID_PREFIX) ? prefix.substring(1) : prefix); final String prefixToSearchWithDot = prefixToSearch + "."; final Project project = target.getProject(); // first look into changed models SearchScope mpsSearchScope = new IdeaSearchScope(scope, true); CollectConsumer<VirtualFile> processedFilesConsumer = new CollectConsumer<VirtualFile>(); for (SModel model : mpsSearchScope.getModels()) { boolean changed = model instanceof EditableSModel && ((EditableSModel) model).isChanged(); if (!changed) continue; findInModel( model, prefixToSearch, processedFilesConsumer, new Consumer<SReference>() { @Override public void consume(SReference ref) { String role = ref.getRole(); SNode source = ref.getSourceNode(); PsiElement psiNode = MPSPsiProvider.getInstance(project).getPsi(source.getReference()); assert psiNode instanceof MPSPsiNode; consumer.process(new IdPrefixReference(mpsTarget, role, psiNode)); } }); } // now index final Collection<VirtualFile> filesOfChangedModels = processedFilesConsumer.getResult(); GlobalSearchScope truncatedScope = new DelegatingGlobalSearchScope(scope) { @Override public boolean contains(VirtualFile file) { if (filesOfChangedModels.contains(file)) return false; return super.contains(file); } }; ValueProcessor<Collection<Pair<SNodeDescriptor, String>>> sReferenceProcessor = new ValueProcessor<Collection<Pair<SNodeDescriptor, String>>>() { @Override public boolean process( VirtualFile file, Collection<Pair<SNodeDescriptor, String>> refs) { for (Pair<SNodeDescriptor, String> ref : refs) { SNodeReference nodeRef = ref.o1.getNodeReference(); String role = ref.o2; // index got out-of-date on this // unfortunately our indices are not always up-to-date, as we don't index // yet-unsaved changes if (nodeRef.resolve(repository) == null) continue; PsiElement psiNode = MPSPsiProvider.getInstance(project).getPsi(nodeRef); // original node came from MPS index, it must be converted to our PSI // element assert psiNode instanceof MPSPsiNode; consumer.process(new IdPrefixReference(mpsTarget, role, psiNode)); } return true; } }; FileBasedIndex.getInstance() .processValues( ForeignIdReferenceIndex.ID, prefixToSearchWithDot, null, sReferenceProcessor, truncatedScope); } }); }
private boolean createPerRootModel(AnActionEvent e) { final PsiElement psiElement = e.getData(LangDataKeys.PSI_ELEMENT); if (psiElement == null || !(psiElement instanceof PsiJavaDirectoryImpl)) { // Can be used only on package return true; } final VirtualFile targetDir = ((PsiDirectory) psiElement).getVirtualFile(); myModelDescriptor = new ModelAccessHelper(ProjectHelper.getModelAccess(myProject)) .executeCommand( new Computable<EditableSModel>() { @Override public EditableSModel compute() { ModelRoot useModelRoot = null; String useSourceRoot = null; for (ModelRoot root : myOperationContext.getModule().getModelRoots()) { if (!(root instanceof DefaultModelRoot)) continue; DefaultModelRoot modelRoot = (DefaultModelRoot) root; for (String sourceRoot : modelRoot.getFiles(DefaultModelRoot.SOURCE_ROOTS)) { if (FileUtil.isSubPath(sourceRoot, targetDir.getPath())) { useModelRoot = root; useSourceRoot = targetDir.getPath(); break; } } } if (useModelRoot == null) return null; final String modelName = ((PsiJavaDirectoryImpl) psiElement).getPresentation().getLocationString(); EditableSModel model = null; try { model = (EditableSModel) ((DefaultModelRoot) useModelRoot) .createModel( modelName, useSourceRoot, PersistenceRegistry.getInstance() .getFolderModelFactory("file-per-root")); } catch (IOException ioException) { LOG.error( "Can't create per-root model " + modelName + " under " + useSourceRoot, ioException); } model.setChanged(true); model.load(); model.save(); // TODO: This methods are from SModuleOperations.createModelWithAdjustments. // Need to check them really needed. ModelsAutoImportsManager.doAutoImport(useModelRoot.getModule(), model); new MissingDependenciesFixer(model).fixModuleDependencies(); return model; } }); return false; }