Skip to content

Commit

Permalink
Fixes to getModuleLocation and getModuleName
Browse files Browse the repository at this point in the history
- getModuleLocation now also searches libs
- getModuleName filtered on outdated extensions, now only uses .rsc
  • Loading branch information
PaulKlint committed Mar 9, 2024
1 parent 24e3211 commit 53219c8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/org/rascalmpl/library/util/Reflective.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ loc getModuleLocation(str qualifiedModuleName, PathConfig pcfg, str extension =
for(loc dir <- pcfg.srcs){
fileLoc = dir + fileName;
if(exists(fileLoc)){
//println("getModuleLocation <qualifiedModuleName> =\> <fileLoc>");
return fileLoc;
}
}

for(loc dir <- pcfg.libs){
fileLoc = dir + fileName;
if(exists(fileLoc)){
return fileLoc;
}
}
Expand All @@ -131,7 +137,7 @@ tuple[str,str] splitFileExtension(str path){
return <path[0 .. n], path[n+1 .. ]>;
}

str getModuleName(loc moduleLoc, PathConfig pcfg, set[str] extensions = {"tc", "tpl"}){
str getModuleName(loc moduleLoc, PathConfig pcfg){
modulePath = moduleLoc.path;

if(!endsWith(modulePath, "rsc")){
Expand All @@ -150,21 +156,18 @@ str getModuleName(loc moduleLoc, PathConfig pcfg, set[str] extensions = {"tc",
}
}

for(loc dir <- pcfg.libs){
for(loc dir <- pcfg.libs){
if(startsWith(modulePath, dir.path) && moduleLoc.scheme == dir.scheme && moduleLoc.authority == dir.authority){
moduleName = replaceFirst(modulePath, dir.path, "");
<moduleName, ext> = splitFileExtension(moduleName);
if(ext in extensions){
if(moduleName[0] == "/"){
moduleName = moduleName[1..];
}
moduleName = replaceAll(moduleName, "/", "::");
return moduleName;
moduleName = replaceLast(moduleName, ".rsc", "");
if(moduleName[0] == "/"){
moduleName = moduleName[1..];
}
moduleName = replaceAll(moduleName, "/", "::");
return moduleName;
}
}


throw "No module name found for <moduleLoc>;\nsrcs=<pcfg.srcs>;\nlibs=<pcfg.libs>";
}

Expand Down

0 comments on commit 53219c8

Please sign in to comment.