Skip to content

Commit

Permalink
Merge pull request #268 from AntoineGautier/issue267_lookup
Browse files Browse the repository at this point in the history
Fix class name lookup for single file mapping
  • Loading branch information
JayHuLBL authored Feb 12, 2025
2 parents fb7edd1 + 1be0333 commit e6363a5
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/expressionEvaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,13 @@ function getClassDefinition (fullClassName, jsons, classObject) {
* otherwise undefined.
*/
function convertPathToClassName (moFilePath) {
for (const p of utilM2j.getMODELICAPATH()) {
if (moFilePath.includes(p)) {
return moFilePath
.replace(new RegExp(p + '/*|\\.mo$' + '', 'g'), '')
const moFilePathNorm = path.normalize(moFilePath)
for (const p of utilM2j.getMODELICAPATH().map(
(el) => path.normalize(el))
) {
if (moFilePathNorm.includes(p)) {
return path.relative(p, moFilePath)
.replace(/\.mo$/, '')
.replace(new RegExp(path.sep, 'g'), '.')
}
}
Expand All @@ -341,10 +344,21 @@ function lookupClassName (typeSpecifier, within, moFilePath) {
within,
moFilePath)[0]
if (path == null) {
// Simple class names not found are short class definitions: these are returned unchanged
// Simple class names not found by 'searchPath' are short class definitions: these are returned unchanged
if (!/\./.test(typeSpecifier)) return typeSpecifier
else logger.debug(`Path not found for ${typeSpecifier} used in ${moFilePath}`)
} else { return convertPathToClassName(path) }
} else {
const className = convertPathToClassName(path)
// When mapping a package to a file, 'searchPath' returns the package path for any class in the package.
// We then need to append the simple class name to the package path.
const simpleClassNameToFind = typeSpecifier.split('.').slice(-1)[0]
const simpleClassNameFound = className.split('.').slice(-1)[0]
if (simpleClassNameFound !== simpleClassNameToFind) {
return `${className}.${simpleClassNameToFind}`
} else {
return className
}
}
}

/**
Expand Down

0 comments on commit e6363a5

Please sign in to comment.