コード例 #1
0
 public void showItemInHierarchy(SNode node) {
   myHierarchyTree.setHierarchyNode(node);
   final jetbrains.mps.project.Project mpsProject = getMPSProject();
   mpsProject
       .getModelAccess()
       .runReadInEDT(
           new Runnable() {
             @Override
             public void run() {
               Project project = getProject();
               if (project == null || project.isDisposed()) {
                 return;
               }
               myHierarchyTree.rebuildNow();
               if (myHierarchyTree.getActiveTreeNode() != null) {
                 myHierarchyTree.setRootNodeText(
                     "<html>Hierarchy for <font color=\"#400090\"><b>"
                         + StringUtil.escapeXml(
                             myHierarchyTree.getActiveTreeNode().calculateNodeIdentifier())
                         + "</b></font>",
                     getIcon());
                 myHierarchyTree.selectNode(myHierarchyTree.getActiveTreeNode());
               }
               if (!(isTreeInfinite())) {
                 myHierarchyTree.expandAll();
               }
             }
           });
 }
コード例 #2
0
ファイル: TypeSystemStateTree.java プロジェクト: yan96in/MPS
 @Override
 protected ActionGroup createPopupActionGroup(final MPSTreeNode treeNode) {
   final TypeSystemStateTreeNode stateNode = (TypeSystemStateTreeNode) treeNode;
   final DefaultActionGroup group = ActionUtils.groupFromActions();
   myProject
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               NodeMaps maps = myState.getNodeMaps();
               List<SNode> vars = stateNode.getVariables();
               if (null == vars) {
                 return;
               }
               for (SNode var : vars) {
                 SNode node = check_x8yvv7_a0a0d0a0a0a0d0u(maps, var);
                 if (node != null && node.getModel() != null) {
                   final SNodeReference pointer = new jetbrains.mps.smodel.SNodePointer(node);
                   group.add(
                       new BaseAction("Go to node with type " + var) {
                         @Override
                         public void doExecute(AnActionEvent e, Map<String, Object> _params) {
                           new EditorNavigator(myProject)
                               .shallFocus(true)
                               .shallSelect(true)
                               .open(pointer);
                         }
                       });
                 }
               }
             }
           });
   return group;
 }
コード例 #3
0
ファイル: TypeSystemStateTree.java プロジェクト: yan96in/MPS
 private void highlightNodesWithTypes(final Collection<? extends MPSTreeNode> treeNodes) {
   clearHighlighting();
   myProject
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               NodeMaps maps = myState.getNodeMaps();
               List<EditorMessage> messages = new ArrayList<EditorMessage>();
               for (MPSTreeNode treeNode : treeNodes) {
                 TypeSystemStateTreeNode stateNode = (TypeSystemStateTreeNode) treeNode;
                 List<SNode> vars = stateNode.getVariables();
                 if (null == vars) {
                   continue;
                 }
                 for (SNode var : vars) {
                   SNode node = check_x8yvv7_a0a0d0c0a0a0a0b0t(maps, var);
                   if (node != null && node.getModel() != null) {
                     EditorCell nodeCell = myEditorComponent.findNodeCell(node);
                     if (nodeCell != null) {
                       messages.add(
                           new TypeSystemStateTree.TypeEditorMessage(
                               nodeCell, String.valueOf(var)));
                     }
                   }
                 }
                 if (messages.size() > 0) {
                   myHighlightManager.mark(messages);
                 }
               }
             }
           });
 }
コード例 #4
0
ファイル: TreeNodeUpdater.java プロジェクト: yan96in/MPS
 final void process() {
   if (!myGuard.tryAcquire()) {
     return;
   }
   try {
     do {
       int batchProcessMax =
           20; // do not process more than X at once, not to block any write actions nor UI thread
       // for too long
       final ArrayList<Pair<MPSTreeNode, NodeUpdate>> updates =
           new ArrayList<Pair<MPSTreeNode, NodeUpdate>>(batchProcessMax);
       Pair<MPSTreeNode, NodeUpdate> u;
       while ((u = myUpdates.poll()) != null && batchProcessMax > 0) {
         if (u.o1.getTree() == null) {
           // no reason to update element which is not in the tree
           continue;
         }
         updates.add(u);
         batchProcessMax--;
       }
       if (updates.isEmpty()) {
         break;
       }
       myProject
           .getModelAccess()
           .runReadInEDT(
               new Runnable() {
                 @Override
                 public void run() {
                   final HashSet<MPSTreeNode> toRefresh = new HashSet<MPSTreeNode>();
                   for (Pair<MPSTreeNode, NodeUpdate> next : updates) {
                     MPSTreeNode node = next.o1;
                     if (node.getTree() == null) {
                       // once again, no reason to update element which is not in the tree
                       continue;
                     }
                     next.o2.update(node);
                     toRefresh.add(node);
                   }
                   for (MPSTreeNode node : toRefresh) {
                     node.updateNodePresentationInTree();
                   }
                 }
               });
     } while (!myUpdates.isEmpty());
     myTimer.suspend();
   } finally {
     myGuard.release();
   }
 }
コード例 #5
0
ファイル: MpsTestsSuite.java プロジェクト: JetBrains/MPS
 private List<Runner> createChildRunners(Project project, final RunnerBuilder builder) {
   final List<Runner> result = new ArrayList<Runner>();
   project
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             public void run() {
               for (SModule module : ListSequence.fromList(myContextProject.getProjectModules())) {
                 for (SModel model : Sequence.fromIterable(module.getModels())) {
                   for (SNode testCase :
                       ListSequence.fromList(
                           SModelOperations.roots(
                               ((SModel) model),
                               MetaAdapterFactory.getInterfaceConcept(
                                   0xf61473f9130f42f6L,
                                   0xb98d6c438812c2f6L,
                                   0x11b2709bd56L,
                                   "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")))) {
                     String testClassName =
                         ((String)
                             BHReflection.invoke(
                                 testCase,
                                 SMethodTrimmedId.create("getClassName", null, "hGBnqtL")));
                     try {
                       Class<?> testClass = myClassLoader.loadClass(testClassName);
                       result.add(new DelegatingRunner(builder, testClass));
                     } catch (ClassNotFoundException e) {
                       if (LOG.isEnabledFor(Level.WARN)) {
                         LOG.warn(
                             "Cannot find the test class "
                                 + testClassName
                                 + "; will skip this test class");
                       }
                     }
                   }
                 }
               }
             }
           });
   return result;
 }
  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);
                }
              });
    }
  }
コード例 #7
0
ファイル: NewRootAction.java プロジェクト: sasundaresan/MPS
  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;
        }
      }
    }
  }