From 2464dc14f0961815ff8c2aff2ca2776dae51902e Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 25 Nov 2024 22:34:10 +0100 Subject: [PATCH] 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. --- pom.xml | 2 +- .../lang/rascalcore/check/RascalConfig.rsc | 30 ++++++++++++++++++- .../lang/rascalcore/compile/util/Names.rsc | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6ee7c2e5..711e02ad 100644 --- a/pom.xml +++ b/pom.xml @@ -228,7 +228,7 @@ org.rascalmpl typepal - 0.14.8 + 0.14.8-SNAPSHOT io.usethesource diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc index d6a7a841..ffee9ca2 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/RascalConfig.rsc @@ -16,6 +16,7 @@ import lang::rascalcore::check::CheckerCommon; import Location; import util::Reflective; +import lang::rascalcore::compile::util::Names; import IO; import List; @@ -459,6 +460,32 @@ loc rascalCreateLogicalLoc(Define def, str _modelName, PathConfig pcfg){ return def.defined; } +list[str] rascalSimilarNames(Use u, TModel tm){ + w = getOrgId(u); + nw = size(w); + idRoles = u.idRoles; + pcfg = tm.config.typepalPathConfig; + vocabulary = []; + longNames = {}; + if(moduleId() in idRoles){ + for(srcdir <- pcfg.srcs){ + for(loc mloc <- find(srcdir, "rsc")){ + try { + longName = getModuleName(mloc, pcfg); + shortName = asBaseModuleName(longName); + vocabulary += shortName; + longNames += ; + } catch _: ; + } + } + } else { + vocabulary = [ d.orgId | d <- tm.defines, d.idRole in idRoles, isContainedIn(u.occ, d.scope) ]; + } + //println("similarNames: , , "); + similar = similarWords(w, vocabulary, tm.config.cutoffForNameSimilarity)[0..10]; + return [ *(longNames[s]) | s <- similar ]; +} + RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg, str rascalTplVersion = getCurrentRascalTplVersion(), @@ -523,5 +550,6 @@ RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg, preSolver = rascalPreSolver, postSolver = rascalPostSolver, reportUnused = rascalReportUnused, - createLogicalLoc = rascalCreateLogicalLoc + createLogicalLoc = rascalCreateLogicalLoc, + similarNames = rascalSimilarNames ); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/util/Names.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/util/Names.rsc index 2b63661e..50d03e49 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/util/Names.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/util/Names.rsc @@ -103,6 +103,11 @@ str asBaseClassName(str qname){ return n >= 0 ? "$" : "$"; } +str asBaseModuleName(str qname){ + n = findLast(qname, "::"); + return n >= 0 ? qname[n+2 ..] : qname; +} + str asBaseInterfaceName(str qname){ qname = normalizeQName(qname); n = findLast(qname, ".");