]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add SourceReference.contains()
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 19 Mar 2019 14:58:25 +0000 (15:58 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 11 Apr 2020 13:03:56 +0000 (15:03 +0200)
vala/valasourcereference.vala

index 24aeeda45a02d36b0922d409f0bdd6ca48f7f380..d0680f7058ba345b2ddb013996d3a8b246af1ab9 100644 (file)
@@ -58,6 +58,26 @@ public class Vala.SourceReference {
                using_directives = file.current_using_directives;
        }
 
+       /**
+        * Checks if given source location is part of this source reference.
+        *
+        * @param location     a source location
+        * @return             whether this source location is part of this
+        */
+       public bool contains (SourceLocation location) {
+               if (location.line > begin.line && location.line < end.line) {
+                       return true;
+               } else if (location.line == begin.line && location.line == end.line) {
+                       return location.column >= begin.column && location.column <= end.column;
+               } else if (location.line == begin.line) {
+                       return location.column >= begin.column;
+               } else if (location.line == end.line) {
+                       return location.column <= end.column;
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * Returns a string representation of this source reference.
         *