From: Reino Ruusu Date: Wed, 20 Mar 2019 10:40:50 +0000 (+0200) Subject: Make SCL compiler accept "." as a valid relative path in imports. X-Git-Tag: v1.43.0~136^2~173^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=098f08657684792709db2cf231bb63956651255e;p=simantics%2Fplatform.git Make SCL compiler accept "." as a valid relative path in imports. gitlab #278 Change-Id: I8f74d26d15545f65400e9ba383fecb34a11be4c5 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java index f5ae62ab8..462358f8d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java @@ -3,28 +3,31 @@ package org.simantics.scl.compiler.module; public class ModuleUtils { public static String resolveAbsolutePath(String moduleName, String relativeModuleName) throws InvalidModulePathException { if (relativeModuleName.startsWith(".")) { - String originalRelativeModuleName = relativeModuleName; - int p = moduleName.lastIndexOf('/'); - String parentPackage = p < 0 ? "" : moduleName.substring(0, p); - while(relativeModuleName.startsWith(".")) { - if(relativeModuleName.startsWith("./")) { - relativeModuleName = relativeModuleName.substring(2); - } - else if(relativeModuleName.startsWith("../")) { - relativeModuleName = relativeModuleName.substring(3); - if(parentPackage.isEmpty()) { - throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + " when the current module name is " + moduleName + "."); - } - p = parentPackage.lastIndexOf('/'); - parentPackage = p < 0 ? "" : parentPackage.substring(0, p); - } - else { - throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + ". It has an invalid syntax."); - } - } - return parentPackage + "/" + relativeModuleName; + String originalRelativeModuleName = relativeModuleName; + int p = moduleName.lastIndexOf('/'); + String parentPackage = p < 0 ? "" : moduleName.substring(0, p); + while(relativeModuleName.startsWith(".")) { + if(relativeModuleName.equals(".")) { + return parentPackage; + } + else if(relativeModuleName.startsWith("./")) { + relativeModuleName = relativeModuleName.substring(2); + } + else if(relativeModuleName.startsWith("../")) { + relativeModuleName = relativeModuleName.substring(3); + if(parentPackage.isEmpty()) { + throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + " when the current module name is " + moduleName + "."); + } + p = parentPackage.lastIndexOf('/'); + parentPackage = p < 0 ? "" : parentPackage.substring(0, p); + } + else { + throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + ". It has an invalid syntax."); + } + } + return parentPackage + "/" + relativeModuleName; } else { - return relativeModuleName; + return relativeModuleName; } } }