]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / errors / Locations.java
index d22a69442625708d37b98e13f204574ef0666522..70c258b9bab1fa89ae816c97d1bb02d7290441b6 100644 (file)
@@ -1,43 +1,58 @@
-package org.simantics.scl.compiler.errors;\r
-\r
-public class Locations {\r
-\r
-    public static final long NO_LOCATION = 0x7fffffff80000000L;\r
-    \r
-    public static long location(int begin, int end) {\r
-        return (((long)begin) << 32) | (((long)end) );\r
-    }\r
-    \r
-    public static int beginOf(long location) {\r
-        return (int)(location >>> 32);\r
-    }\r
-    \r
-    public static int endOf(long location) {\r
-        return (int)location;\r
-    }\r
-    \r
-    public static int length(long location) {\r
-        return endOf(location) - beginOf(location);\r
-    }\r
-\r
-    \r
-    public static long combine(long a, long b) {\r
-        return location(Math.min(beginOf(a), beginOf(b)), Math.max(endOf(a), endOf(b)));\r
-    }\r
-    \r
-    public static int compare(long a, long b) {\r
-        if(a < b) \r
-            return -1;\r
-        if(a > b) \r
-            return 1;\r
-        return 0;\r
-    }\r
-\r
-    public static String annotatate(String annotationBegin, String annotationEnd, String formula, long location) {\r
-        if(location == NO_LOCATION)\r
-            return annotationBegin + formula + annotationEnd;\r
-        int begin = beginOf(location);\r
-        int end = endOf(location);\r
-        return formula.substring(0, begin) + annotationBegin + formula.substring(begin, end) + annotationEnd + formula.substring(end);\r
-    }\r
-}\r
+package org.simantics.scl.compiler.errors;
+
+public class Locations {
+
+    public static final long NO_LOCATION = 0x7fffffff80000000L;
+    
+    public static long location(int begin, int end) {
+        return (((long)begin) << 32) | (((long)end) );
+    }
+    
+    public static int beginOf(long location) {
+        return (int)(location >>> 32);
+    }
+    
+    public static int endOf(long location) {
+        return (int)location;
+    }
+    
+    public static int length(long location) {
+        return endOf(location) - beginOf(location);
+    }
+
+    
+    public static long combine(long a, long b) {
+        return location(Math.min(beginOf(a), beginOf(b)), Math.max(endOf(a), endOf(b)));
+    }
+    
+    public static int compare(long a, long b) {
+        if(a < b) 
+            return -1;
+        if(a > b) 
+            return 1;
+        return 0;
+    }
+
+    public static String annotatate(String annotationBegin, String annotationEnd, String formula, long location) {
+        if(location == NO_LOCATION)
+            return annotationBegin + formula + annotationEnd;
+        int begin = beginOf(location);
+        int end = endOf(location);
+        return formula.substring(0, begin) + annotationBegin + formula.substring(begin, end) + annotationEnd + formula.substring(end);
+    }
+    
+    public static long sublocation(long location, int localBegin, int localEnd) {
+        int begin = beginOf(location);
+        int end = endOf(location);
+        if(localEnd > end-begin)
+            localEnd = begin-end;
+        return location(begin+localBegin, begin+localEnd);
+    }
+
+    public static String toString(long location) {
+        if(location == NO_LOCATION)
+            return "NO LOCATION";
+        else
+            return beginOf(location) + "-" + endOf(location);
+    }
+}