]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Make SCL compiler accept "." as a valid relative path in imports."
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 20 Mar 2019 10:52:12 +0000 (10:52 +0000)
committerGerrit Code Review <gerrit2@simantics>
Wed, 20 Mar 2019 10:52:12 +0000 (10:52 +0000)
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java

index f5ae62ab86f3c53461a1a73da49cf1c67494e8d3..462358f8de8ab08086740922ec432397688aaf47 100644 (file)
@@ -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;
         }
     }
 }