Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 2464dc1

Browse files
committed
Written first version of rascalSimilarNames
rascalSimilarNames computes fixes for undefined names: - unknown moduleId are inferred from the modules in srcs. - other names are inferred by the default mechanism of TypePal. Many extensions and refinements are possible here.
1 parent 5841965 commit 2464dc1

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
<dependency>
229229
<groupId>org.rascalmpl</groupId>
230230
<artifactId>typepal</artifactId>
231-
<version>0.14.8</version>
231+
<version>0.14.8-SNAPSHOT</version>
232232
</dependency>
233233
<dependency>
234234
<groupId>io.usethesource</groupId>

src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import lang::rascalcore::check::CheckerCommon;
1616

1717
import Location;
1818
import util::Reflective;
19+
import lang::rascalcore::compile::util::Names;
1920

2021
import IO;
2122
import List;
@@ -459,6 +460,32 @@ loc rascalCreateLogicalLoc(Define def, str _modelName, PathConfig pcfg){
459460
return def.defined;
460461
}
461462
463+
list[str] rascalSimilarNames(Use u, TModel tm){
464+
w = getOrgId(u);
465+
nw = size(w);
466+
idRoles = u.idRoles;
467+
pcfg = tm.config.typepalPathConfig;
468+
vocabulary = [];
469+
longNames = {};
470+
if(moduleId() in idRoles){
471+
for(srcdir <- pcfg.srcs){
472+
for(loc mloc <- find(srcdir, "rsc")){
473+
try {
474+
longName = getModuleName(mloc, pcfg);
475+
shortName = asBaseModuleName(longName);
476+
vocabulary += shortName;
477+
longNames += <shortName, longName>;
478+
} catch _: ;
479+
}
480+
}
481+
} else {
482+
vocabulary = [ d.orgId | d <- tm.defines, d.idRole in idRoles, isContainedIn(u.occ, d.scope) ];
483+
}
484+
//println("similarNames: <u>, <idRoles>, <vocabulary>");
485+
similar = similarWords(w, vocabulary, tm.config.cutoffForNameSimilarity)[0..10];
486+
return [ *(longNames[s]) | s <- similar ];
487+
}
488+
462489
RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg,
463490
464491
str rascalTplVersion = getCurrentRascalTplVersion(),
@@ -523,5 +550,6 @@ RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg,
523550
preSolver = rascalPreSolver,
524551
postSolver = rascalPostSolver,
525552
reportUnused = rascalReportUnused,
526-
createLogicalLoc = rascalCreateLogicalLoc
553+
createLogicalLoc = rascalCreateLogicalLoc,
554+
similarNames = rascalSimilarNames
527555
);

src/org/rascalmpl/core/library/lang/rascalcore/compile/util/Names.rsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ str asBaseClassName(str qname){
103103
return n >= 0 ? "$<qname[n+1 ..]>" : "$<qname>";
104104
}
105105

106+
str asBaseModuleName(str qname){
107+
n = findLast(qname, "::");
108+
return n >= 0 ? qname[n+2 ..] : qname;
109+
}
110+
106111
str asBaseInterfaceName(str qname){
107112
qname = normalizeQName(qname);
108113
n = findLast(qname, ".");

0 commit comments

Comments
 (0)