protected Solution addSolution(String name, VirtualFile[] roots) { SolutionDescriptor sd = new SolutionDescriptor(); sd.setNamespace(name); sd.setId(ModuleId.foreign(name)); addModelRoots(sd, roots); return StubSolution.newInstance(sd, this); }
@Nullable public static IModule call_getModule_4040588429969043137(SNode thisNode) { if (SPropertyOperations.getString(thisNode, "moduleId") == null) { return null; } return MPSModuleRepository.getInstance() .getModuleById(ModuleId.fromString(SPropertyOperations.getString(thisNode, "moduleId"))); }
public TempModule(Set<ModelRootDescriptor> modelRoots) { SModuleId id = ModuleId.regular(); SModuleReference reference = new ModuleReference("TempModule" + id, id); setModuleReference(reference); myDescriptor = new ModuleDescriptor(); myDescriptor.getModelRootDescriptors().addAll(modelRoots); setModuleDescriptor(myDescriptor, false); }
protected void removeSolution(String name) { ModuleReference ref = new ModuleReference(null, ModuleId.foreign(name)); MPSModuleRepository repository = MPSModuleRepository.getInstance(); IModule m = ModuleRepositoryFacade.getInstance().getModule(ref); if (m == null) { return; } repository.unregisterModule(m, this); }
protected void removeSolution(String name) { SModuleReference ref = new jetbrains.mps.project.structure.modules.ModuleReference(null, ModuleId.foreign(name)); MPSModuleRepository repository = MPSModuleRepository.getInstance(); SModule m = ModuleRepositoryFacade.getInstance().getModule(ref); if (m == null) { return; } repository.unregisterModule(m, this); }
/** * Create a model with a tree of nodes. * * <p>It's an instance method as I envision model to be owned by this class, which would keep * extra info about created model (e.g. number of initial nodes to get rid of constants like * (3*5*2 + 3*5 + 3) from the tests code * * @param nodesAtLevel number of child elements for each parent (i.e. of previous level) element. * Each node at level i has nodesAtLevel[i] children */ public SModel createModel(@Nullable int... nodesAtLevel) { final SNode top = createNode(nodesAtLevel); final jetbrains.mps.smodel.SModel modelData = new jetbrains.mps.smodel.SModel( new SModelReference( new ModuleReference("M", ModuleId.regular()), SModelId.generate(), "m")); for (SNode c : top.getChildren(ourRole)) { modelData.addRootNode(c); } assert myNeedEditableModel; return myModel = new TestModelBase(modelData); }
/** * This temporary code suites the purpose to homogenize java_stub model references, that used to * be kept in two different formats (one is "module id/model id including module id/(module * name/model name)" and another "model id including module id(module name/model name)". If * there's module id anyway, why would anyone keep it to model id then, and common patter for * model reference (with module id coming first) shall be used. * * <p>Once all model references to java stub are updated, this code shall cease to exist. */ @ToRemove(version = 3.3) @Nullable @Hack private static SModuleId extractModuleIdFromModelIdIfJavaStub(SModelId modelId) { if (SModelRepository.isVerboseJavaStubModelId(modelId)) { String idValue = ((ForeignSModelId) modelId).getId(); String stereo = SModelStereotype.getStubStereotypeForId(LanguageID.JAVA); if (idValue.length() > stereo.length() + 2 && idValue.startsWith(stereo) && idValue.charAt(stereo.length()) == '#') { // two forms of legacy stub model id: // f:java_stub#module id#package name // f:java_stub#package name int secondHashIndex = idValue.indexOf('#', stereo.length() + 1); // there are two hash chars and non-empty package name if (secondHashIndex != -1 && idValue.length() > secondHashIndex) { return ModuleId.fromString(idValue.substring(stereo.length() + 1, secondHashIndex)); } } } return null; }
@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; }
/** * @deprecated This code shall move to private method of PersistenceRegistry, which would dispatch * to proper registered factories. Use {@link PersistenceFacade#createModelReference(String)} * instead. Format: <code>[ moduleID / ] modelID [ ([moduleName /] modelName ) ]</code> */ @Deprecated @ToRemove(version = 3.3) public static SModelReference parseReference(String s) { if (s == null) return null; s = s.trim(); int lParen = s.indexOf('('); int rParen = s.lastIndexOf(')'); String presentationPart = null; if (lParen > 0 && rParen == s.length() - 1) { presentationPart = s.substring(lParen + 1, rParen); s = s.substring(0, lParen); lParen = s.indexOf('('); rParen = s.lastIndexOf(')'); } if (lParen != -1 || rParen != -1) { throw new IllegalArgumentException("parentheses do not match in: `" + s + "'"); } SModuleId moduleId = null; int slash = s.indexOf('/'); if (slash >= 0) { // FIXME I wonder why there's no SModuleIdFactory and corresponding methods in // PersistenceFacade moduleId = ModuleId.fromString(StringUtil.unescapeRefChars(s.substring(0, slash))); s = s.substring(slash + 1); } String modelIDString = StringUtil.unescapeRefChars(s); SModelId modelId; if (modelIDString.indexOf(':') >= 0) { PersistenceFacade facade = PersistenceFacade.getInstance(); // temporary: SModelReference can be created without active PersistenceFacade if (facade == null) { // FIXME get rid of facade == null case, if any // Besides, shall move the code to PersistenceRegistry, as it's responsible for prefixes and // factory pick LOG.warn( "Please report stacktrace, which would help us to find out improper MPS initialization sequence", new Throwable()); } modelId = facade != null ? facade.createModelId(modelIDString) : jetbrains.mps.smodel.SModelId.fromString(modelIDString); } else { // dead code? I suspect ModelNameSModelId, if any, would start with "m:" prefix and we'd never // get into else clause // OTOH, there seems to be a special hack in toString(), that persists ModelNameSModelId // without the prefix modelId = new ModelNameSModelId(modelIDString); } String moduleName = null; String modelName = null; if (presentationPart != null) { slash = presentationPart.indexOf('/'); if (slash >= 0) { moduleName = StringUtil.unescapeRefChars(presentationPart.substring(0, slash)); modelName = StringUtil.unescapeRefChars(presentationPart.substring(slash + 1)); } else { modelName = StringUtil.unescapeRefChars(presentationPart); } } if (modelName == null || modelName.isEmpty()) { modelName = modelId.getModelName(); if (modelName == null) { throw new IllegalArgumentException( "incomplete model reference, presentation part is absent"); } } if (moduleId == null) { moduleId = extractModuleIdFromModelIdIfJavaStub(modelId); } if (SModelRepository.isLegacyJavaStubModelId(modelId)) { modelId = SModelRepository.newJavaPackageStubFromLegacy(modelId); } SModuleReference moduleRef = moduleId != null || moduleName != null ? new jetbrains.mps.project.structure.modules.ModuleReference(moduleName, moduleId) : null; return new SModelReference(moduleRef, modelId, modelName); }
public TestModule(String namespace, String moduleId, SModule peer) { myPeer = peer; SModuleReference reference = new ModuleReference(namespace, ModuleId.fromString(moduleId)); setModuleReference(reference); }
public EvaluationModule() { SModuleReference reference = new ModuleReference("Evaluation Container Module", ModuleId.regular()); setModuleReference(reference); myDescriptor = new ModuleDescriptor(); }