public static Collection<String> getUsedLanguageNamespaces( SModel model, boolean isTemplateModel) { if (isTemplateModel) { return getUsedLanguageNamespacesInTemplateModel(model); } if (SModelStereotype.isGeneratorModel(model)) { TemplateModelScanner templateModelScanner = new TemplateModelScanner(model); templateModelScanner.scan(); Set<String> namespaces = new HashSet<String>(templateModelScanner.getQueryLanguages()); for (SModuleReference ref : ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) { namespaces.add(ref.getModuleName()); } return namespaces; } Set<String> namespaces = new HashSet<String>(); for (SModuleReference ref : ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) { namespaces.add(ref.getModuleName()); } for (SNode root : model.getRootNodes()) { namespaces.add(NameUtil.namespaceFromConceptFQName(root.getConcept().getId())); for (SNode child : jetbrains.mps.util.SNodeOperations.getDescendants(root, null)) { namespaces.add(NameUtil.namespaceFromConceptFQName(child.getConcept().getId())); } } // empty behavior model should have it's behavior aspect descriptor generated if (model.getModule() instanceof Language && LanguageAspect.BEHAVIOR.is(model)) { namespaces.add(BootstrapLanguages.BEHAVIOR.getModuleName()); } return namespaces; }
@Override public org.jetbrains.mps.openapi.model.SModel resolve( org.jetbrains.mps.openapi.model.SModelReference reference) { if (reference == null) { return null; } SModel model = SModelRepository.getInstance().getModelDescriptor(reference.getModelId()); if (model == null) { return null; } synchronized (LOCK) { initialize(); if (myVisibleModules.contains(model.getModule())) return model; for (Language l : myUsedLanguages) { if (l.getAccessoryModels().contains(model)) return model; } } return null; }
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; }
@NotNull public SModule getModule(SModel model) { if (myGenerationContext != null) { return myGenerationContext.getOriginalInputModel().getModule(); } return model.getModule(); }
@Override protected boolean acceptModel(SModel model) { if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) { return false; } return acceptModule(model.getModule()); }
public RelativePathHelper getRelativePathHelper(@NotNull SModel model) { if (model.getModule() instanceof TransientModelsModule && myGenerationContext != null) { model = myGenerationContext.getOriginalInputModel(); } SModel modelDescriptor = model; if (model.getModule() instanceof TransientModelsModule || modelDescriptor == null) { return null; } SModule module = modelDescriptor.getModule(); if (module == null || ((AbstractModule) module).getDescriptorFile() == null || module.isPackaged()) { return null; } String basePath = ((AbstractModule) module).getDescriptorFile().getParent().getPath(); return new RelativePathHelper(basePath); }
@Override @Nullable public WarningPanel getWarningPanel(@NotNull SNode node, @NotNull Project project) { SModel model = node.getModel(); if (model != null) { SModule module = model.getModule(); if (module != null && module.isReadOnly()) { return new WarningPanel( this, "Warning: the node is in a read-only model. Your changes won't be saved"); } } return null; }
private boolean checkResolvedTarget(AbstractTemplateGenerator generator, SNode outputTargetNode) { Status status = generator .getReferentRoleValidator(myOutputSourceNode, myReferenceRole) .validate(outputTargetNode); if (status != null) { generator .getLogger() .error( myOutputSourceNode.getReference(), status.getMessage(getClass().getSimpleName()), getErrorDescriptions()); return false; } SModel referentNodeModel = outputTargetNode.getModel(); if (referentNodeModel != null && referentNodeModel != myOutputSourceNode.getModel()) { if (SModelStereotype.isGeneratorModel(referentNodeModel)) { // references to template nodes are not acceptable String msg = "bad reference, cannot refer to a generator model: %s for role '%s' in %s"; generator .getLogger() .error( myOutputSourceNode.getReference(), String.format( msg, SNodeUtil.getDebugText(outputTargetNode), myReferenceRole, SNodeUtil.getDebugText(myOutputSourceNode)), getErrorDescriptions()); return false; } if (referentNodeModel.getModule() instanceof TransientModelsModule) { // references to transient nodes in a model outside one being generated are not acceptable String msg = "bad reference, cannot refer to an external transient model: %s for role '%s' in %s"; generator .getLogger() .error( myOutputSourceNode.getReference(), String.format( msg, SNodeUtil.getDebugText(outputTargetNode), myReferenceRole, SNodeUtil.getDebugText(myOutputSourceNode)), getErrorDescriptions()); return false; } } return true; }
protected void addNodeImports(SNode node) { final SModelInternal modelInternal = (SModelInternal) myModel; final AbstractModule module = ((AbstractModule) myModel.getModule()); final Collection<SLanguage> importedLanguages = modelInternal.importedLanguageIds(); for (SNode subNode : ListSequence.fromList( SNodeOperations.getNodeDescendants(node, null, true, new SAbstractConcept[] {}))) { SLanguage usedLanguage = subNode.getConcept().getLanguage(); if (!(importedLanguages.contains(usedLanguage))) { modelInternal.addLanguage(usedLanguage); } for (SReference ref : ListSequence.fromList(SNodeOperations.getReferences(subNode))) { SModel usedModel = SNodeOperations.getModel(SLinkOperations.getTargetNode(ref)); if (usedModel != null && !(modelInternal.importedModels().contains(usedModel))) { modelInternal.addModelImport(usedModel.getReference(), false); module.addDependency( SNodeOperations.getModel(SLinkOperations.getTargetNode(ref)) .getModule() .getModuleReference(), false); } } } }
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)")); }
@Override public void start(@NotNull GeneratorTask task) { final SModel inputModel = task.getModel(); myGenerationHandler.startModule( inputModel.getModule(), Collections.singletonList(inputModel), null); }
private static SModule check_o8sx3d_a0d0a(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; }
public static SNode getModuleStub(SModel model) { final SModule module = model.getModule(); SRepository repo = model.getRepository(); if (repo == null || ProjectStructureModule.getInstance(repo) == null) { return null; } if (module instanceof Generator) { Language lang = ((Generator) module).getSourceLanguage(); SModel m = ProjectStructureModule.getInstance(repo).getModelByModule(lang); if (m == null) { return null; } SNode l = ListSequence.fromList( SModelOperations.roots( m, MetaAdapterFactory.getConcept( 0x86ef829012bb4ca7L, 0x947f093788f263a9L, 0x5869770da61dfe1fL, "jetbrains.mps.lang.project.structure.Language"))) .first(); return (l == null ? null : ListSequence.fromList( SLinkOperations.getChildren( l, MetaAdapterFactory.getContainmentLink( 0x86ef829012bb4ca7L, 0x947f093788f263a9L, 0x5869770da61dfe1fL, 0x5869770da61dfe37L, "generator"))) .findFirst( new IWhereFilter<SNode>() { public boolean accept(SNode it) { return eq_kkj9n5_a0a0a0a0a0a4a3a11( SPropertyOperations.getString( it, MetaAdapterFactory.getProperty( 0x86ef829012bb4ca7L, 0x947f093788f263a9L, 0x5869770da61dfe1eL, 0x5869770da61dfe22L, "uuid")), module.getModuleReference().getModuleId().toString()); } })); } else { SModel m = ProjectStructureModule.getInstance(repo).getModelByModule(module); return (m == null ? null : ListSequence.fromList( SModelOperations.roots( m, MetaAdapterFactory.getConcept( 0x86ef829012bb4ca7L, 0x947f093788f263a9L, 0x5869770da61dfe1eL, "jetbrains.mps.lang.project.structure.Module"))) .first()); } }
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; }
@Override public void done(@NotNull GeneratorTask task, @NotNull GenerationStatus status) { final SModel inputModel = task.getModel(); myGenerationHandler.handleOutput( inputModel.getModule(), inputModel, status, null, new EmptyProgressMonitor()); }
private static SModule check_tq0gdw_a0a0k(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; }
private static SModule check_p8mh91_a0c0a(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; }