]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ModuleUtils.java
Merge "Workaround for missing selection highlights on SVG diagrams"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / ModuleUtils.java
1 package org.simantics.scl.compiler.module;
2
3 public class ModuleUtils {
4     public static String resolveAbsolutePath(String moduleName, String relativeModuleName) throws InvalidModulePathException {
5         if (relativeModuleName.startsWith(".")) {
6                 String originalRelativeModuleName = relativeModuleName;
7                 int p = moduleName.lastIndexOf('/');
8                 String parentPackage = p < 0 ? "" : moduleName.substring(0, p);
9                 while(relativeModuleName.startsWith(".")) {
10                     if(relativeModuleName.startsWith("./")) {
11                         relativeModuleName = relativeModuleName.substring(2);
12                     }
13                     else if(relativeModuleName.startsWith("../")) {
14                         relativeModuleName = relativeModuleName.substring(3);
15                         if(parentPackage.isEmpty()) {
16                             throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + " when the current module name is " + moduleName + ".");
17                         }
18                         p = parentPackage.lastIndexOf('/');
19                         parentPackage = p < 0 ? "" : parentPackage.substring(0, p);
20                     }
21                     else {
22                         throw new InvalidModulePathException("Couldn't resolve the relative module name " + originalRelativeModuleName + ". It has an invalid syntax.");
23                     }
24                 }
25                 return parentPackage + "/" + relativeModuleName;
26         } else {
27                 return relativeModuleName;
28         }
29     }
30 }