public <T> T createParameters(Class<T> cls, T copyFrom) { T t = createParameters(cls); if (t != null) { ((Tuples._4) t).assign((Tuples._4) copyFrom); } return t; }
@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; }