package jetbrains.mps.build.mps.util; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import org.jetbrains.annotations.Nullable; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; /** * Produces BuildRelativePath and BuildCompositePath, knows factory for these nodes. */ public final class PathBuilder { private final SModel myNodeFactory; public PathBuilder(SModel nodeFactory) { myNodeFactory = nodeFactory; } /** * Gives project-relative path. */ @NotNull public SNode buildRelative(String path) { SNode relPath = SModelOperations.createNewNode(myNodeFactory, null, MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x4c12642949048fb2L, "jetbrains.mps.build.structure.BuildSourceProjectRelativePath")); SLinkOperations.setTarget(relPath, MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x65997a657729f6fbL, 0x65997a65772aebcbL, "compositePart"), buildComposite(path)); return relPath; } @NotNull public SNode buildRelative(SNode macro, String path) { SNode relPath = SModelOperations.createNewNode(myNodeFactory, null, MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafae121dL, "jetbrains.mps.build.structure.BuildSourceMacroRelativePath")); SLinkOperations.setTarget(relPath, MetaAdapterFactory.getReferenceLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafae121dL, 0x668c6cfbafae122aL, "macro"), macro); SLinkOperations.setTarget(relPath, MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x65997a657729f6fbL, 0x65997a65772aebcbL, "compositePart"), buildComposite(path)); return relPath; } @Nullable public SNode buildComposite(String path) { SNode head = null; SNode tail = null; for (String fname : path.split("/")) { if ((fname == null || fname.length() == 0)) { continue; } SNode npath = SModelOperations.createNewNode(myNodeFactory, null, MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x779c6e65c01467f1L, "jetbrains.mps.build.structure.BuildCompositePath")); SPropertyOperations.set(npath, MetaAdapterFactory.getProperty(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x779c6e65c01467f1L, 0x779c6e65c01467f3L, "head"), fname); if (head == null) { head = tail = npath; } else { SLinkOperations.setTarget(tail, MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x779c6e65c01467f1L, 0x779c6e65c01467f2L, "tail"), npath); tail = npath; } } return head; } }