01: package net.sourceforge.squirrel_sql.plugins.hibernate.completion;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
04: import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
05:
06: import java.util.ArrayList;
07:
08: public class HqlSyntaxHighlightTokenMatcher implements
09: ISyntaxHighlightTokenMatcher {
10: private HQLCompletionInfoCollection _hqlCompletionInfoCollection;
11: private ArrayList<SQLTokenListener> _listeners = new ArrayList<SQLTokenListener>();
12:
13: public HqlSyntaxHighlightTokenMatcher(
14: HQLCompletionInfoCollection hqlCompletionInfoCollection) {
15: _hqlCompletionInfoCollection = hqlCompletionInfoCollection;
16: }
17:
18: public boolean isTable(char[] buffer, int offset, int len) {
19: String classNameCandidate = getString(buffer, offset, len);
20: boolean ret = _hqlCompletionInfoCollection
21: .isMappeadClass(classNameCandidate);
22:
23: if (ret) {
24: fireClassFound(classNameCandidate);
25: }
26:
27: return ret;
28: }
29:
30: public boolean isFunction(char[] buffer, int offset, int len) {
31: return _hqlCompletionInfoCollection.isFunction(getString(
32: buffer, offset, len));
33: }
34:
35: public boolean isDataType(char[] buffer, int offset, int len) {
36: return false;
37: }
38:
39: public boolean isStatementSeparator(char[] buffer, int offset,
40: int len) {
41: return false;
42: }
43:
44: public boolean isColumn(char[] buffer, int offset, int len) {
45: return _hqlCompletionInfoCollection
46: .isMappedAttribute(getString(buffer, offset, len));
47: }
48:
49: public boolean isKeyword(char[] buffer, int offset, int len) {
50: return _hqlCompletionInfoCollection.isKeyword(getString(buffer,
51: offset, len));
52: }
53:
54: public void addSQLTokenListener(SQLTokenListener tl) {
55: _listeners.add(tl);
56: }
57:
58: public void removeSQLTokenListener(SQLTokenListener tl) {
59: _listeners.remove(tl);
60: }
61:
62: private String getString(char[] buffer, int offset, int len) {
63: return new String(buffer, offset, len);
64: }
65:
66: private void fireClassFound(String className) {
67: for (SQLTokenListener listener : _listeners) {
68: listener.tableOrViewFound(className);
69: }
70: }
71: }
|