private EditableSModel getContextModel(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; } return null; }
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); }
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 EditableSModel getModel(MPSPsiNodeBase mpsPsiNode) { MPSPsiModel containingModel = mpsPsiNode.getContainingModel(); SModel sModel = containingModel.getSModelReference().resolve(MPSModuleRepository.getInstance()); return (EditableSModel) sModel; }