Пример #1
0
  public void stopListening() {
    if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) {
      ModelGenerationStatusManager.getInstance().removeGenerationStatusListener(myStatusListener);
    }

    myModel.removeModelListener(mySimpleModelListener);
    SModelEventsDispatcher.getInstance().unregisterListener(myEventsListener);
  }
Пример #2
0
  public void startListening() {
    visitNode(myTreeNode);

    SModelEventsDispatcher.getInstance().registerListener(myEventsListener);
    myModel.addModelListener(mySimpleModelListener);

    if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) {
      ModelGenerationStatusManager.getInstance().addGenerationStatusListener(myStatusListener);
    }
  }
  public SearchResults find(SearchQuery query, ProgressMonitor monitor) {
    SearchResults<SNode> searchResults = new SearchResults<SNode>();
    IHolder holder = query.getObjectHolder();
    assert holder instanceof ModuleHolder;
    IModule module = ((ModuleHolder) holder).getObject();
    assert module instanceof Language;
    Language language = (Language) module;
    SModelDescriptor structureModel = language.getStructureModelDescriptor();
    if (structureModel == null) {
      return searchResults;
    }
    SModel sModel = structureModel.getSModel();
    if (sModel == null) {
      return searchResults;
    }
    if (sModel.rootsCount() == 0) {
      return searchResults;
    }
    List<SNode> roots = new LinkedList<SNode>();
    for (SNode root : sModel.roots()) {
      roots.add(root);
    }
    searchResults.getSearchedNodes().addAll(roots);

    monitor.start("", sModel.rootsCount() + 1);
    try {
      SearchResults<SModel> modelResults =
          FindUtils.getSearchResults(
              monitor.subTask(1),
              new SearchQuery(sModel, GlobalScopeMinusTransient.getInstance()),
              new ModelUsagesFinder());
      List<SModelDescriptor> models = new ArrayList<SModelDescriptor>();
      for (SearchResult<SModel> sModelSearchResult : modelResults.getSearchResults()) {
        models.add(sModelSearchResult.getObject().getModelDescriptor());
      }
      IScope scope = new ModelsOnlyScope(models.toArray(new SModelDescriptor[models.size()]));
      SearchResults results = new SearchResults();
      for (SNode node : roots) {
        if (monitor != null && monitor.isCanceled()) {
          break;
        }
        results.addAll(
            FindUtils.getSearchResults(
                monitor.subTask(1),
                node,
                scope,
                "jetbrains.mps.lang.structure.findUsages.NodeUsages_Finder"));
        results.removeDuplicates();
      }
      searchResults.getSearchResults().addAll(results.getSearchResults());
      return searchResults;
    } finally {
      monitor.done();
    }
  }
Пример #4
0
 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));
   }
 }
Пример #5
0
  @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;
  }
Пример #6
0
  public static void createModuleForModel(
      SModel model, String version, Project project, boolean mergeResultModel) {
    if (model.getModelDescriptor() != null) {
      return;
    }
    IModule module = null;
    if (mergeResultModel) {
      SModelDescriptor mdInRepo =
          SModelRepository.getInstance().getModelDescriptor(model.getSModelReference());
      if (mdInRepo != null) {
        module = mdInRepo.getModule();
      }
    }

    if (module == null) {
      module = new DiffTemporaryModule(model, version, project);
    }
    model.setModelDescriptor(
        new DiffTemporaryModule.DiffSModelDescriptor(module, model, mergeResultModel));
  }
Пример #7
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;
  }
Пример #8
0
 public static Iterable sourceNodesQuery_1220369573364040170(
     final IOperationContext operationContext, final SourceSubstituteMacroNodesContext _context) {
   List<SNode> result = new ArrayList<SNode>();
   List<Language> langs =
       SModelOperations.getLanguages(
           SNodeOperations.getModel(_context.getNode()), GlobalScope.getInstance());
   for (Language lang : langs) {
     for (ModuleReference mr : lang.getRuntimeModulesReferences()) {
       for (SModelDescriptor smd :
           MPSModuleRepository.getInstance().getModule(mr).getOwnModelDescriptors()) {
         SModel rtModel = smd.getSModel();
         for (SNode gwtmod :
             jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations.getRoots(
                 rtModel, "jetbrains.mps.gwt.client.structure.GWTModule")) {
           ListSequence.fromList(result).addElement(gwtmod);
         }
       }
     }
   }
   return result;
 }
Пример #9
0
  public boolean generationRequired(SModelDescriptor sm, IOperationContext operationContext) {
    if (!sm.isGeneratable()) return false;
    if (sm instanceof EditableSModelDescriptor && ((EditableSModelDescriptor) sm).isChanged())
      return true;

    String currentHash = ModelDigestHelper.getInstance().getModelHashFast(sm, operationContext);
    if (currentHash == null) return true;

    String generatedHash = getGenerationHash(sm);
    if (generatedHash == null) return true;

    return !generatedHash.equals(currentHash);
  }
  private IFile fileForContent(String name, boolean isCache) {
    // RE-3090
    // RE-3635
    if (name.endsWith(TraceInfoCache.TRACE_FILE_NAME)) {
      // RE-3103
      if (myOriginalOutputDir instanceof IdeaFile) {
        IdeaFile originalOutputDirIdeaFile = (IdeaFile) myOriginalOutputDir;
        if (!originalOutputDirIdeaFile.isPackaged()) {
          return FileGenerationUtil.getDefaultOutputDir(myModelDescriptor, myOriginalOutputDir)
              .getDescendant(name);
        }
      }
    }

    IFile outputRootDir = isCache ? myCachesOutputDir : myOutputDir;

    CodeOrchestraGenerateManager codeOrchestraGenerateManager =
        myProcessor.getProject().getComponent(CodeOrchestraGenerateManager.class);
    CodeOrchestraGenerationContext currentContext =
        codeOrchestraGenerateManager.getCurrentContext();
    if (currentContext != null) {
      String fqName =
          NameUtil.longNameFromNamespaceAndShortName(
              myModelDescriptor.getLongName(), getRootNameFromFileName(name));
      if (fqName != null) {
        FileOverrideWrapper customMapping = currentContext.getCustomFileFqNameMapping(fqName);
        if (customMapping != null) {
          return FileGenerationUtil.getDefaultOutputDir(
                  NameUtil.namespaceFromLongName(customMapping.getTargetFqName()), outputRootDir)
              .getDescendant(
                  NameUtil.shortNameFromLongName(customMapping.getTargetFqName())
                      + customMapping.getExtension());
        }
      }
    }

    return FileGenerationUtil.getDefaultOutputDir(myModelDescriptor, outputRootDir)
        .getDescendant(name);
  }
Пример #11
0
  @Override
  public SModel loadSModel(IModule module, SModelDescriptor descriptor) {
    SModel model = new SModel(descriptor.getSModelReference(), new ForeignNodeIdMap());
    ModuleReference lang =
        MPSModuleRepository.getInstance()
            .getModuleById(ModuleId.fromString("32d0a39c-772f-4490-8142-e50f9a9f19d4"))
            .getModuleReference();
    model.addLanguage(lang);

    String pkg = model.getSModelFqName().getLongName();
    List<Tuples._4<String, String, SNode, PathItem>> doclst =
        ListSequence.fromList(new ArrayList<Tuples._4<String, String, SNode, PathItem>>());
    SNode sample =
        SConceptOperations.createNewNode(
            "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument", null);
    for (String path : roots) {
      PathItem pi = ConfPathItem.getPathItem(path);
      for (String docres : ListSequence.fromList(pi.resources(pkg))) {
        SNodeId id = ConfReader.createForeignId(pi.baseName(docres));
        SNode doc = (SNode) model.getNodeById(id);
        if ((doc == null)) {
          doc =
              SConceptOperations.createNewNode(
                  NameUtil.nodeFQName(
                      SConceptOperations.findConceptDeclaration(
                          "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument")),
                  sample);
          ((jetbrains.mps.smodel.SNode) doc).setId(id);
          SPropertyOperations.set(doc, "name", pi.baseName(docres));
          SModelOperations.addRootNode(((SModel) model), doc);
          ListSequence.fromList(doclst)
              .addElement(MultiTuple.<String, String, SNode, PathItem>from(pkg, docres, doc, pi));
        }
      }
    }
    final StubModelDescriptors descs =
        new StubModelDescriptors(SModelStereotype.getStubStereotypeForId("conf"), roots, module) {
          @Override
          public StubModelDataSource createStubsSource(String path) {
            return new ConfStubSource(path);
          }
        };
    ConfReader reader =
        new ConfReader(
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.javaStubRef(pk);
              }
            },
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.smodelRefWithId(pk);
              }
            });
    for (Tuples._4<String, String, SNode, PathItem> doctuple : ListSequence.fromList(doclst)) {
      InputStream is = null;
      try {
        is = doctuple._3().openResource(doctuple._0(), doctuple._1());
        reader.read(doctuple._2(), new SAXBuilder().build(is));
      } catch (IOException e) {
        e.printStackTrace();
      } catch (JDOMException e) {
        e.printStackTrace();
      }
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
    }
    SNodeOperations.deleteNode(sample);
    return model;
  }
 private static IModule check_gidzrl_a0e0a0e(SModelDescriptor checkedDotOperand) {
   if (null != checkedDotOperand) {
     return checkedDotOperand.getModule();
   }
   return null;
 }
Пример #13
0
 public void onCreate(SModelDescriptor model) {
   if (!model.getModule().getUsedLanguagesReferences().contains(BootstrapLanguages.UNITTEST)) {
     model.getModule().addUsedLanguage(BootstrapLanguages.UNITTEST);
   }
   model.getSModel().addLanguage(BootstrapLanguages.UNITTEST);
 }
Пример #14
0
 public SNode findRuleNode() {
   SModelDescriptor modelDescriptor =
       SModelRepository.getInstance().getModelDescriptor(SModelReference.fromString(myRuleModel));
   if (modelDescriptor == null) return null;
   return modelDescriptor.getSModel().getNodeById(myRuleId);
 }
Пример #15
0
 public void modelRepositoryChanged(SModelDescriptor modelDescriptor) {
   if (!SModelStereotype.INTERNAL.equals(modelDescriptor.getStereotype())) {
     myNeedRebuild = true;
   }
 }