Esempio n. 1
0
 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;
 }
Esempio n. 2
0
  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);
  }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 private EditableSModel getModel(MPSPsiNodeBase mpsPsiNode) {
   MPSPsiModel containingModel = mpsPsiNode.getContainingModel();
   SModel sModel = containingModel.getSModelReference().resolve(MPSModuleRepository.getInstance());
   return (EditableSModel) sModel;
 }