]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/completions/PrefixUtil.java
New SCL completion implementation
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / completions / PrefixUtil.java
1 package org.simantics.scl.compiler.completions;
2
3 public class PrefixUtil {
4     public static String findPrefix(String sourceText, int end) {
5         int position;
6         for(position=end-1;position >= 0 && isPrefixChar(sourceText.charAt(position));--position);
7         ++position;
8         while(position < end && !isPrefixStart(sourceText.charAt(position)))
9             ++position;
10         return sourceText.substring(position, end);
11     }
12
13     private static boolean isPrefixStart(char c) {
14         return Character.isJavaIdentifierStart(c);
15     }
16
17     private static boolean isPrefixChar(char c) {
18         return Character.isJavaIdentifierPart(c) || c=='.';
19     }
20     
21     public static String[] splitPrefix(String prefix) {
22         int partCount = 1;
23         for(int i=0;i<prefix.length();++i)
24             if(prefix.charAt(i) == '.')
25                 ++partCount;
26         String[] result = new String[partCount];
27         int partId = 0;
28         int begin = 0;
29         for(int i=0;i<prefix.length();++i)
30             if(prefix.charAt(i) == '.') {
31                 result[partId++] = prefix.substring(begin, i);
32                 begin = i+1;
33             }
34         result[partId] = prefix.substring(begin);
35         return result;
36     }
37 }