Exemplo n.º 1
0
  public static List<SModelDescriptor> getLanguageModels(Language lang) {
    List<SModelDescriptor> inputModels = new ArrayList<SModelDescriptor>();
    for (LanguageAspect aspect : LanguageAspect.values()) {
      SModelDescriptor model = aspect.get(lang);
      if (model != null) {
        inputModels.add(model);
      }
    }

    Set<SModelDescriptor> ownModels = new HashSet<SModelDescriptor>(lang.getOwnModelDescriptors());
    for (SModelDescriptor sm : lang.getAccessoryModels()) {
      if (!SModelStereotype.isUserModel(sm)) continue;
      if (!(sm instanceof EditableSModelDescriptor)) continue;

      if (ownModels.contains(sm)) {
        inputModels.add(((EditableSModelDescriptor) sm));
      }
    }

    inputModels.addAll(lang.getUtilModels());

    // add it from all generators
    List<Generator> list = lang.getGenerators();
    for (Generator generator : list) {
      inputModels.addAll(generator.getGeneratorModels());
    }
    return inputModels;
  }
Exemplo n.º 2
0
 public static void delete(
     Language sourceLanguage, GeneratorDescriptor generatorDescriptor, boolean deleteFiles) {
   LanguageDescriptor languageDescriptor = sourceLanguage.getModuleDescriptor();
   languageDescriptor.getGenerators().remove(generatorDescriptor);
   sourceLanguage.setLanguageDescriptor(languageDescriptor, true);
   sourceLanguage.save();
 }
Exemplo n.º 3
0
  private static SModule getModuleForModel(MPSProject project, SModel model) {
    // language's and solution's own models (+generator models in language)
    SModule owner = model.getModule();
    SModule mainModule =
        owner instanceof Generator ? ((Generator) owner).getSourceLanguage() : owner;
    if (project.isProjectModule(mainModule)) return owner;

    // accessories models in languages
    /*
      //with this enabled, alt-f1 does not work in case node is in non-owned accessory model to a project language
      for (Language l : project.getProjectLanguages()) {
        if (l.isAccessoryModel(model.getSModelReference())) return l;
      }
    */

    // runtime models in languages
    for (Language l : project.getProjectModules(Language.class)) {
      for (SModuleReference depModule : l.getRuntimeModulesReferences()) {
        if (depModule.equals(mainModule.getModuleReference())) return owner;
      }
    }

    // accessories models in devkits

    // runtime models in devkits

    return owner;
  }
Exemplo n.º 4
0
  @Override
  public SearchResults find(SearchQuery query, @NotNull ProgressMonitor monitor) {
    SearchResults<SNode> searchResults = new SearchResults<SNode>();
    Object value = query.getObjectHolder().getObject();
    SModule module = null;
    if (value instanceof SModule) {
      module = ((SModule) value);
    } else if (value instanceof SModuleReference) {
      module = query.getScope().resolve(((SModuleReference) value));
    }
    if (!(module instanceof Language)) {
      return searchResults;
    }
    Language language = (Language) module;
    SModel structureModel = language.getStructureModelDescriptor();
    if (structureModel == null) {
      return searchResults;
    }
    if (!(structureModel.getRootNodes().iterator().hasNext())) {
      return searchResults;
    }
    List<SNode> roots = new LinkedList<SNode>();
    for (SNode root : structureModel.getRootNodes()) {
      roots.add(root);
    }
    searchResults.getSearchedNodes().addAll(roots);

    monitor.start("", IterableUtil.asCollection(structureModel.getRootNodes()).size() + 1);
    try {
      SearchResults<SModel> modelResults =
          FindUtils.getSearchResults(
              monitor.subTask(1),
              new SearchQuery(
                  structureModel.getReference(), GlobalScopeMinusTransient.getInstance()),
              new ModelImportsUsagesFinder());
      List<SModel> models = new ArrayList<SModel>();
      for (SearchResult<SModel> sModelSearchResult : modelResults.getSearchResults()) {
        models.add(sModelSearchResult.getObject());
      }
      SearchScope scope = new ModelsScope(models.toArray(new SModel[models.size()]));
      SearchResults<SNode> results = new SearchResults();
      for (SNode node : roots) {
        if (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();
    }
  }
Exemplo n.º 5
0
 @Override
 protected List<SModuleReference> getAllVisibleElements() {
   final List<SModuleReference> allLanguages = new ArrayList<SModuleReference>();
   for (Language language : ModuleRepositoryFacade.getInstance().getAllModules(Language.class)) {
     allLanguages.add(language.getModuleReference());
   }
   return allLanguages;
 }
Exemplo n.º 6
0
 public static void updateLanguageClasspath(Language l, String classpath) {
   LanguageDescriptor languageDescriptor = l.getModuleDescriptor();
   ClassPathEntry cpEntry = new ClassPathEntry();
   cpEntry.setPath(classpath);
   languageDescriptor
       .getStubModelEntries()
       .add(jetbrains.mps.project.structure.model.ModelRootUtil.fromClassPathEntry(cpEntry));
   l.setLanguageDescriptor(languageDescriptor, false);
 }
Exemplo n.º 7
0
 public static void checkBehaviorAspectPresence(Language lang, List<String> errors) {
   for (Language language : LanguageDependenciesManager.getAllExtendedLanguages(lang)) {
     EditableSModel descriptor = LanguageAspect.BEHAVIOR.get(language);
     if (descriptor == null) {
       if (lang == language) errors.add("Behavior aspect is absent");
       else
         errors.add("Cannot extend language without behavior aspect: " + language.getModuleName());
     }
   }
 }
  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();
    }
  }
Exemplo n.º 9
0
  @Test
  public void testUsedLanguageDependencyNotInScope() {
    Solution s1 = createSolution();

    Solution ld = createSolution();
    Language l1 = createLanguage();
    l1.addDependency(ld.getModuleReference(), true);

    s1.addUsedLanguage(l1.getModuleReference());

    assertFalse(new GlobalModuleDependenciesManager(s1).getModules(Deptype.VISIBLE).contains(ld));
    assertFalse(IterableUtil.asCollection(s1.getScope().getVisibleModules()).contains(ld));
  }
Exemplo n.º 10
0
 private Class<KeyMap> findKeyMapClassByDeclaration(SNode declaration) {
   String fqName =
       BehaviorReflection.invokeVirtual(
           String.class, declaration, "virtual_getFqName_1213877404258", new Object[] {});
   String namespace = NameUtil.namespaceFromLongName(fqName);
   assert namespace.endsWith(".editor");
   String languageNamespace = namespace.substring(0, namespace.length() - ".editor".length());
   Language language =
       (Language) MPSModuleRepository.getInstance().getModuleByFqName(languageNamespace);
   if (language == null) {
     return null;
   }
   return language.getClass(fqName);
 }
Exemplo n.º 11
0
  @Override
  public List<String> getWarnings() {
    List<String> warnings = new ArrayList<String>(super.getWarnings());
    Set<String> usedLanguages = new HashSet<String>();
    for (SModel model : myModule.getOwnTemplateModels()) {
      if (SModelStereotype.isGeneratorModel(model)) {
        usedLanguages.addAll(ModelContentUtil.getUsedLanguageNamespacesInTemplateModel(model));
      }
    }
    Set<String> extendedLanguages = new HashSet<String>();
    Language sourceLanguage = myModule.getSourceLanguage();
    usedLanguages.remove(sourceLanguage.getModuleName());

    Set<Language> ext = new LinkedHashSet<Language>();
    sourceLanguage.getDependenciesManager().collectAllExtendedLanguages(ext);

    for (Language language : ext) {
      extendedLanguages.add(language.getModuleName());
    }

    for (String lang : usedLanguages) {
      Language language = ModuleRepositoryFacade.getInstance().getModule(lang, Language.class);
      if (language == null) continue;

      if (!extendedLanguages.contains(lang) && !language.getRuntimeModulesReferences().isEmpty()) {
        warnings.add(sourceLanguage + " should extend " + lang);
      }
    }
    return warnings;
  }
Exemplo n.º 12
0
  public static Iterable sourceNodesQuery_7923290658387314672(
      final IOperationContext operationContext, final SourceSubstituteMacroNodesContext _context) {
    SModel behaviorModel = _context.getOriginalInputModel();

    Language language = Language.getLanguageForLanguageAspect(behaviorModel);
    SModel structureModel = LanguageAspect.STRUCTURE.get(language);

    return SModelOperations.getNodes(
        structureModel, "jetbrains.mps.lang.structure.structure.AbstractConceptDeclaration");
  }
Exemplo n.º 13
0
  public static boolean checkCyclicInheritance(Language lang) {

    List<Language> frontier = ModuleUtil.refsToLanguages(lang.getExtendedLanguageRefs());
    ArrayList<Language> passed = new ArrayList<Language>();
    while (!frontier.isEmpty()) {
      List<Language> newFrontier = new ArrayList<Language>();
      for (Language extendedLang : frontier) {
        if (extendedLang == lang && lang != BootstrapLanguages.coreLanguage()) {
          return false;
        }
        if (!passed.contains(extendedLang)) {

          newFrontier.addAll(ModuleUtil.refsToLanguages(extendedLang.getExtendedLanguageRefs()));
        }
        passed.add(extendedLang);
      }
      frontier = newFrontier;
    }
    return true;
  }
Exemplo n.º 14
0
  private static void safeDelete(
      final Project project,
      Language sourceLanguage,
      final Generator generator,
      GeneratorDescriptor generatorDescriptor,
      boolean deleteFiles) {
    List<Generator> dependant = new ArrayList<Generator>();
    for (Generator gen :
        (List<Generator>) ModuleRepositoryFacade.getInstance().getAllModules(Generator.class)) {
      if (gen.getReferencedGenerators().contains(generator)) {
        dependant.add(gen);
      }
    }
    if (!dependant.isEmpty()) {
      final StringBuilder report = new StringBuilder();
      report.append("Can't delete generator ").append(generator.getModuleName()).append(".\n");
      report.append("The following generators depend on it:\n\n");
      for (Generator gen : dependant) {
        report.append(gen.getModuleName()).append("\n");
      }

      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              Messages.showErrorDialog(
                  ProjectHelper.toIdeaProject(project), report.toString(), "Deleting Generator");
            }
          });
      return;
    }

    LanguageDescriptor languageDescriptor = sourceLanguage.getModuleDescriptor();
    languageDescriptor.getGenerators().remove(generator.getModuleDescriptor());
    sourceLanguage.setLanguageDescriptor(languageDescriptor, true);
    if (deleteFiles) {
      LOG.error("DELETE GENERATOR FILES - NOT IMPLEMENTED", new Throwable());
      // todo
    }
    sourceLanguage.save();
  }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
 protected void addBuiltInImports() {
   SLanguage base =
       MetaAdapterFactory.getLanguage(
           MetaIdFactory.langId(0xde1ad86d6e504a02L, 0xb306d4d17f64c375L),
           "jetbrains.mps.console.base");
   Collection<SLanguage> baseAndExtensions =
       new SLanguageHierarchy(Collections.singleton(base)).getExtending();
   SModelInternal modelInternal = ((SModelInternal) myModel);
   for (SLanguage l : CollectionSequence.fromCollection(baseAndExtensions)) {
     modelInternal.addLanguage(l);
     Language sourceLangModule = (Language) l.getSourceModule();
     if (sourceLangModule == null) {
       continue;
     }
     modelInternal.addModelImport(
         sourceLangModule.getStructureModelDescriptor().getReference(), false);
     ((AbstractModule) myModel.getModule())
         .addDependency(sourceLangModule.getModuleReference(), false);
   }
   modelInternal.addDevKit(
       PersistenceFacade.getInstance()
           .createModuleReference(
               "fbc25dd2-5da4-483a-8b19-70928e1b62d7(jetbrains.mps.devkit.general-purpose)"));
 }
Exemplo n.º 17
0
  public static Iterable sourceNodesQuery_2056529430201935318(
      final IOperationContext operationContext, final SourceSubstituteMacroNodesContext _context) {
    SModel behaviorModel = _context.getOriginalInputModel();

    Language language = Language.getLanguageForLanguageAspect(behaviorModel);
    SModel structureModel = LanguageAspect.STRUCTURE.get(language);

    return ListSequence.fromList(
            SModelOperations.getNodes(
                structureModel, "jetbrains.mps.lang.structure.structure.ConceptDeclaration"))
        .where(
            new IWhereFilter<SNode>() {
              public boolean accept(SNode it) {
                return !(SPropertyOperations.getBoolean(it, "abstract"));
              }
            });
  }
Exemplo n.º 18
0
  public RenameLanguageDialog(Project project, Language language) throws HeadlessException {
    super(project, language.getModuleFqName(), "language");
    myLanguage = language;
    myProject = project;
    setTitle("Rename Language");

    myRegenerateLanguage
        .getModel()
        .setSelected(
            ModelAccess.instance()
                .runReadAction(
                    new Computable<Boolean>() {
                      @Override
                      public Boolean compute() {
                        return !(myLanguage.isBootstrap());
                      }
                    }));
  }
Exemplo n.º 19
0
  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]);
  }
Exemplo n.º 20
0
  public int getModelKind(SModel model, @Nullable SReference reference) {
    DataSource source = (model != null ? model.getSource() : null);
    IFile modelFile =
        (source instanceof FileDataSource ? ((FileDataSource) source).getFile() : null);
    if (modelFile != null) {
      String filePath = modelFile.getAbsolutePath().replace('\\', '/');
      if (filePath.startsWith(languagesUtilPath)) {
        return OTHER;
      }
    }

    SModule module = model.getModule();
    if (module instanceof Language) {
      LanguageAspect aspect = Language.getModelAspect(model);
      if (aspect != null) {
        switch (aspect) {
          case ACTIONS:
            return EDITOR;
          case BEHAVIOR:
            return CORE;
          case CONSTRAINTS:
            return CORE;
          case DATA_FLOW:
            return CORE;
          case EDITOR:
            return EDITOR;
          case FIND_USAGES:
            return CORE;
          case INTENTIONS:
            return EDITOR;
          case PLUGIN:
            return WORKBENCH;
          case REFACTORINGS:
            return CORE;
          case SCRIPTS:
            return CORE;
          case STRUCTURE:
            return CORE;
          case STUBS:
            return CORE;
          case TEST:
            return EDITOR;
          case TEXT_GEN:
            return CORE;
          case TYPESYSTEM:
            return CORE;
          default:
        }
      }
      return CORE;

    } else if (module instanceof Solution) {

      String moduleFqName = module.getModuleName();
      if (moduleFqName.equals("JDK")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Core")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Editor")) {
        return EDITOR;
      }
      if (moduleFqName.equals("MPS.Workbench")) {
        return WORKBENCH;
      }
      if (moduleFqName.equals("MPS.Classpath")) {
        SNode refTargetRoot = reference.getTargetNode().getContainingRoot();
        if (SNodeOperations.isInstanceOf(
            refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier")) {
          String cName =
              SPropertyOperations.getString(
                  SNodeOperations.cast(
                      refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier"),
                  "name");
          String modelName = model.getModelName();
          if (findInModule(coreModule, modelName, cName)) {
            return CORE;
          }
          if (findInModule(editorModule, modelName, cName)) {
            return EDITOR;
          }
          return WORKBENCH;
        }
        return OTHER;
      }

      Solution sol = (Solution) module;
      switch (sol.getKind()) {
        case NONE:
          return OTHER;
        case PLUGIN_CORE:
          return CORE;
        case PLUGIN_EDITOR:
          return EDITOR;
        case PLUGIN_OTHER:
          return WORKBENCH;
        default:
      }
    }
    return OTHER;
  }
Exemplo n.º 21
0
 public MPSLanguageVirtualFile(@NotNull Language language) {
   myLanguage = language;
   myPath = myLanguage.getModuleFqName();
   myName = myLanguage.getModuleFqName();
 }
Exemplo n.º 22
0
  private List<DepLink> dependencies(DependencyUtil.Role role, SModuleReference moduleRef) {
    List<DepLink> result = ListSequence.fromList(new ArrayList<DepLink>());
    SModule module = moduleRef.resolve(myRepo);
    ModuleDescriptor descr = ((AbstractModule) module).getModuleDescriptor();
    if (descr == null) {
      return result;
    }
    switch (role) {
      case OwnedGenerator:
      case None:
        // first step
        addDeps(
            result,
            descr.getUsedDevkits(),
            DependencyUtil.Role.UsedDevkit,
            DependencyUtil.LinkType.UsesDevkit);
        for (SLanguage lang : module.getUsedLanguages()) {
          SModule langModule = lang.getSourceModule();
          if (langModule != null) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        langModule.getModuleReference(),
                        DependencyUtil.Role.UsedLanguage,
                        DependencyUtil.LinkType.UsesLanguage));
          }
        }
        for (SDependency dep : module.getDeclaredDependencies()) {
          switch (dep.getScope()) {
            case EXTENDS:
              SModule t = dep.getTarget();
              if (t instanceof Language) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsLanguage));
              } else if (t instanceof Generator) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsGenerator));
              } else {
                // just in case module could not be resolved
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.Depends));
              }
              break;
            case DESIGN:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            case RUNTIME:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RuntimeDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            default:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          (dep.isReexport()
                              ? DependencyUtil.LinkType.ReexportsDep
                              : DependencyUtil.LinkType.Depends)));
          }
        }
        if (module instanceof Language) {
          // generators and generators dependencies are now also added to language dependencies
          // (MPS-15883)
          for (Generator g : ((Language) module).getGenerators()) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        g.getModuleReference(),
                        DependencyUtil.Role.OwnedGenerator,
                        DependencyUtil.LinkType.Generator));
          }
        }
        if (module instanceof Generator) {
          Language srcLang = ((Generator) module).getSourceLanguage();
          ListSequence.fromList(result)
              .addElement(
                  new DepLink(
                      srcLang.getModuleReference(),
                      DependencyUtil.Role.SourceLanguage,
                      DependencyUtil.LinkType.GeneratorLanguage));
        }
        break;

      case UsedDevkit:
        // explicit use of devkit
      case DependencyDevkit:
        DevkitDescriptor devkit = as_he47wm_a0a0a3e0g(descr, DevkitDescriptor.class);
        if (devkit == null) {
          break;
        }
        boolean direct = role == DependencyUtil.Role.UsedDevkit;
        addDeps(
            result,
            devkit.getExtendedDevkits(),
            (direct ? DependencyUtil.Role.UsedDevkit : DependencyUtil.Role.DependencyDevkit),
            DependencyUtil.LinkType.ExtendsDevkit);
        addDeps(
            result,
            devkit.getExportedLanguages(),
            (direct ? DependencyUtil.Role.UsedLanguage : DependencyUtil.Role.DependencyLanguage),
            DependencyUtil.LinkType.ExportsLanguage);
        addDeps(
            result,
            devkit.getExportedSolutions(),
            (direct
                ? DependencyUtil.Role.RegularDependency
                : DependencyUtil.Role.RuntimeDependency),
            DependencyUtil.LinkType.ExportsSolution);
        break;

      case UsedLanguage:
        LanguageDescriptor lang = as_he47wm_a0a0a4e0g(descr, LanguageDescriptor.class);
        if (lang == null) {
          break;
        }
        addDeps(
            result,
            lang.getExtendedLanguages(),
            DependencyUtil.Role.UsedLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        if (myNeedRuntime) {
          addDeps(
              result,
              lang.getRuntimeModules(),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ExportsRuntime);
        }
        break;

      case RegularDependency:
        addDeps(
            result,
            getReexportDeps(descr),
            DependencyUtil.Role.RegularDependency,
            DependencyUtil.LinkType.ReexportsDep);
        if (descr instanceof LanguageDescriptor) {
          addDeps(
              result,
              (as_he47wm_a0a1a0a1a5e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
              DependencyUtil.Role.RegularDependency,
              DependencyUtil.LinkType.ExtendsLanguage);
        }
        if (myNeedRuntime) {
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
        }
        break;

      case RuntimeDependency:
        if (myNeedRuntime) {
          addDeps(
              result,
              getReexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ReexportsDep);
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
          if (descr instanceof LanguageDescriptor) {
            addDeps(
                result,
                (as_he47wm_a0a1a0a4a0a6e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.ExtendsLanguage);
          }
          if (descr instanceof GeneratorDescriptor) {
            GeneratorDescriptor gen = (GeneratorDescriptor) descr;
            // generator languages are now also dependencies
            addDeps(
                result,
                gen.getDepGenerators(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.DependsOnGenerator);
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        (as_he47wm_a0a0a0a0a3a5a0a6e0g(module, Generator.class))
                            .getSourceLanguage()
                            .getModuleReference(),
                        DependencyUtil.Role.RuntimeDependency,
                        DependencyUtil.LinkType.GeneratorLanguage));
          }
        }
        break;

      case SourceLanguage:
        // dependency from generator to its source language
        addDeps(
            result,
            check_he47wm_b0b0h4a6(as_he47wm_a0b0b0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.SourceLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0c0h4a6(as_he47wm_a0b0c0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      case DependencyLanguage:
        addDeps(
            result,
            check_he47wm_b0a0i4a6(as_he47wm_a0b0a0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.DependencyLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0b0i4a6(as_he47wm_a0b0b0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      default:
    }
    return result;
  }
Exemplo n.º 23
0
 private static EditableSModel getPluginModel(Language lang) {
   SModel plugin = LanguageAspect.PLUGIN.get(lang);
   LanguageAspect aspectForModel = lang.getAspectForModel(plugin);
   return aspectForModel.getOrCreate(lang);
 }
 public static void copyLanguageJSAccessories(Language language, String targetSourcePath) {
   copyLanguageJSAccessories(language.getBundleHome().getPath(), targetSourcePath);
 }
Exemplo n.º 25
0
  @Override
  public void doUpdate(AnActionEvent event) {
    removeAll();

    SModel modelDescriptor = event.getData(MPSDataKeys.CONTEXT_MODEL);
    if (modelDescriptor == null) {
      setEnabledState(event.getPresentation(), false);
      return;
    }

    if (!(modelDescriptor instanceof EditableSModel)
        || (((EditableSModel) modelDescriptor).isReadOnly())) {
      event.getPresentation().setEnabled(false);
      event.getPresentation().setVisible(false);
      return;
    }

    IScope scope = event.getData(MPSDataKeys.SCOPE);
    IOperationContext context = event.getData(MPSDataKeys.OPERATION_CONTEXT);

    boolean isStubModel =
        SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(modelDescriptor));
    if (scope == null || context == null || isStubModel) {
      setEnabledState(event.getPresentation(), false);
      return;
    }

    boolean inEditor = event.getData(MPSDataKeys.LOGICAL_VIEW_SELECTION_SIZE) == null;

    if (!inEditor) {
      Integer selectedItemsCount = event.getData(MPSDataKeys.LOGICAL_VIEW_SELECTION_SIZE);
      boolean singleItemSelected = selectedItemsCount != null && selectedItemsCount == 1;

      if (!singleItemSelected) {
        setEnabledState(event.getPresentation(), false);
        return;
      }

      TreeNode treeNode = event.getData(MPSDataKeys.LOGICAL_VIEW_NODE);

      if (!(treeNode instanceof PackageNode)) {
        myPackage = null;
      } else {
        final PackageNode node = (PackageNode) treeNode;
        myPackage = node.getPackage();
      }
    } else {
      SNode node = event.getData(MPSDataKeys.NODE);
      myPackage = null;
      if (node != null) {
        SNode root = node.getContainingRoot();
        myPackage =
            SNodeAccessUtil.getProperty(root, SNodeUtil.property_BaseConcept_virtualPackage);
      }
    }

    setEnabledState(event.getPresentation(), true);

    List<Language> modelLanguages = SModelOperations.getLanguages(modelDescriptor, scope);

    LanguageAspect aspect = Language.getModelAspect(modelDescriptor);
    if (aspect != null) {
      SModuleReference ref = aspect.getMainLanguage();
      Language lang = scope.getLanguage(ref);
      if (lang != null) {
        modelLanguages.remove(lang);

        for (SNode conceptDeclaration : lang.getConceptDeclarations()) {
          if (ModelConstraintsManager.canBeRoot(
              context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
            add(
                new NewRootNodeAction(
                    new jetbrains.mps.smodel.SNodePointer(conceptDeclaration), modelDescriptor));
          }
        }

        addSeparator();
      }
    }

    Collections.sort(modelLanguages, new ToStringComparator());

    List<Language> languagesWithRoots = new ArrayList<Language>();
    for (final Language language : modelLanguages) {
      for (SNode conceptDeclaration : language.getConceptDeclarations()) {
        if (ModelConstraintsManager.canBeRoot(
            context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
          languagesWithRoots.add(language);
          break;
        }
      }
    }

    boolean plain = myPlain || (languagesWithRoots.size() == 1 && aspect == null);

    for (final Language language : languagesWithRoots) {
      String name = language.getModuleName();
      Icon icon = IconManager.getIconForNamespace(language.getModuleName());
      BaseGroup langRootsGroup;

      if (!plain) {
        langRootsGroup = new BaseGroup(NameUtil.compactNamespace(name), name, icon);
        langRootsGroup.setPopup(true);
      } else {
        langRootsGroup = this;
      }

      for (SNode conceptDeclaration : language.getConceptDeclarations()) {
        if (ModelConstraintsManager.getInstance()
            .canBeRoot(context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
          langRootsGroup.add(
              new NewRootNodeAction(
                  new jetbrains.mps.smodel.SNodePointer(conceptDeclaration), modelDescriptor));
        }
      }
      if (!plain) {
        this.add(langRootsGroup);
      } else {
        this.addSeparator();
      }
    }

    if (getChildrenCount() == 0) {
      add(
          ActionManager.getInstance()
              .getAction(
                  "jetbrains.mps.ide.editor.actions.AddLanguageImport_Action" /* FIXME AddLanguageImport_Action.class.getName()*/));
    }
  }
Exemplo n.º 26
0
 public static SModelDescriptor getOptional(Language l) {
   SModelReference modelRef =
       SModelReference.fromString(LANGUAGE_NAMESPACE + OPTIONAL_MODEL_SUFFIX);
   return l.getScope().getModelDescriptor(modelRef);
 }
Exemplo n.º 27
0
 public static SModelDescriptor getGenerated(Language l) {
   SModelReference modelRef =
       SModelReference.fromString(LANGUAGE_NAMESPACE + GENERATED_MODEL_SUFFIX);
   return l.getScope().getModelDescriptor(modelRef);
 }