package jetbrains.mps.project.foreign;
/*Generated by MPS */
import jetbrains.mps.util.MacroHelper;
import jetbrains.mps.vfs.IFile;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Matcher;
public class ModuleMacroExpander implements MacroHelper {
private ProjectMacroExpander myProjectMacroExpander;
private IFile myModuleFile;
public ModuleMacroExpander(ProjectMacroExpander pme, IFile moduleFile) {
this.myProjectMacroExpander = pme;
this.myModuleFile = moduleFile;
}
@Override
public String shrinkPath(@Nullable String string) {
throw new UnsupportedOperationException();
}
@Override
public String expandPath(@Nullable String path) {
if (path == null) {
return null;
}
if (myProjectMacroExpander != null) {
path = myProjectMacroExpander.expandPath(path);
}
if (myModuleFile != null) {
String replaceWith = myModuleFile.getParent().getPath();
if (replaceWith.endsWith("/")) {
replaceWith = replaceWith.substring(0, replaceWith.length() - 1);
}
path = path.replaceAll("\\$MODULE_DIR\\$", Matcher.quoteReplacement(replaceWith));
}
return path;
}
}