Beispiel #1
0
    @Override
    public String expandPath(@Nullable String path) {
      if (path == null) {
        return null;
      }

      if (moduleSourceDir != null) {
        for (String macro : MacrosFactory.descriptors) {
          if (path.startsWith(macro)) {
            String relPath = path.substring(path.indexOf('}') + 1);
            return IFileUtils.getCanonicalPath(moduleSourceDir.getDescendant(relPath));
          }
        }
      }
      if (path.startsWith("${")) {
        int index = path.indexOf("}");
        if (index == -1) {
          reporter.report("invalid macro in `" + path + "'", null, null);
          return path;
        }

        String macroName = path.substring(2, index);
        SNode found = null;
        for (SNode macro :
            SLinkOperations.getTargets(
                SNodeOperations.getAncestor(
                    originalModule, "jetbrains.mps.build.structure.BuildProject", false, false),
                "macros",
                true)) {
          if (!(SNodeOperations.isInstanceOf(
              macro, "jetbrains.mps.build.structure.BuildFolderMacro"))) {
            continue;
          }

          if (eq_krgnbt_a0c0f0d0f4(SPropertyOperations.getString(macro, "name"), macroName)) {
            found = SNodeOperations.cast(macro, "jetbrains.mps.build.structure.BuildFolderMacro");
            break;
          }
        }
        if (found == null) {
          reporter.report("macro is not declared in build script: " + path, null, null);
          return path;
        }

        String localPath =
            BehaviorReflection.invokeVirtual(
                String.class,
                SLinkOperations.getTarget(found, "defaultPath", true),
                "virtual_getLocalPath_5481553824944787364",
                new Object[] {
                  (genContext != null
                      ? Context.defaultContext(genContext)
                      : Context.defaultContext())
                });
        if (localPath == null) {
          if (genContext != null) {
            genContext.showWarningMessage(
                found, "cannot resolve local path: " + path + ", macro has no default value");
          }
          return path;
        }

        String relPath = path.substring(index + 1);
        return IFileUtils.getCanonicalPath(
            FileSystem.getInstance().getFileByPath(localPath).getDescendant(relPath));
      }
      return path;
    }