|
From: SVN by r. <sv...@ca...> - 2008-01-10 20:06:22
|
Author: roy
Date: 2008-01-10 20:20:50 +0100 (Thu, 10 Jan 2008)
New Revision: 207
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added another test
(no spaces required around '=' operator for code completion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 16:11:26 UTC (rev 206)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-10 19:20:50 UTC (rev 207)
@@ -235,12 +235,20 @@
String upperCommandString = tmpCommand.toUpperCase();
String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
//String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
- String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"))))*))))";
+ String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))))";
if (upperCommandString.matches(regExp)) {
- String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+/* String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
if (end.indexOf(".") > 0) {
end = end.substring(end.indexOf(".")+1);
}
+*/
+ int lastIndex = tmpCommand.lastIndexOf(' ');
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ String end = tmpCommand.substring(lastIndex+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
@@ -249,7 +257,12 @@
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
} else {
- end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+ int lastIndex = tmpCommand.lastIndexOf(' ');
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ end = tmpCommand.substring(lastIndex+1);
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}), end);
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 16:11:26 UTC (rev 206)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-10 19:20:50 UTC (rev 207)
@@ -299,7 +299,6 @@
assertTrue(matches.contains("ORDER BY"));
assertEquals("", info.getStart());
-
sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -308,6 +307,14 @@
matches = info.getPossibleMatches();
assertEquals("pl", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child=pl"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals("pl", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' A"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
|