1+ /*
2+ * #%L
3+ * JSQLParser library
4+ * %%
5+ * Copyright (C) 2004 - 2013 JSQLParser
6+ * %%
7+ * This program is free software: you can redistribute it and/or modify
8+ * it under the terms of the GNU Lesser General Public License as
9+ * published by the Free Software Foundation, either version 2.1 of the
10+ * License, or (at your option) any later version.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Lesser Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Lesser Public
18+ * License along with this program. If not, see
19+ * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+ * #L%
21+ */
22+ package net .sf .jsqlparser .expression ;
23+
24+ import java .util .regex .Matcher ;
25+ import java .util .regex .Pattern ;
26+
27+ /**
28+ * Oracle Hint Expression
29+ * @author valdo
30+ */
31+ public class OracleHint implements Expression {
32+
33+ private static final Pattern SINGLE_LINE = Pattern .compile ("--\\ + *([^ ].*[^ ])" );
34+ private static final Pattern MULTI_LINE = Pattern .compile ("\\ /\\ *\\ + *([^ ].*[^ ]) *\\ *+\\ /" , Pattern .MULTILINE | Pattern .DOTALL );
35+
36+ public static boolean isHintMatch (String comment ) {
37+ return SINGLE_LINE .matcher (comment ).find () ||
38+ MULTI_LINE .matcher (comment ).find ();
39+ }
40+
41+ private String value ;
42+ private boolean singleLine = false ;
43+
44+ public final void setComment (String comment ) {
45+ Matcher m ;
46+ {
47+ m = SINGLE_LINE .matcher (comment );
48+ if (m .find ()) {
49+ this .value = m .group (1 );
50+ this .singleLine = true ;
51+ return ;
52+ }
53+ }
54+ {
55+ m = MULTI_LINE .matcher (comment );
56+ if (m .find ()) {
57+ this .value = m .group (1 );
58+ this .singleLine = false ;
59+ }
60+ }
61+ }
62+
63+ public String getValue () {
64+ return value ;
65+ }
66+
67+ public void setValue (String value ) {
68+ this .value = value ;
69+ }
70+
71+ public boolean isSingleLine () {
72+ return singleLine ;
73+ }
74+
75+ public void setSingleLine (boolean singleLine ) {
76+ this .singleLine = singleLine ;
77+ }
78+
79+ @ Override
80+ public void accept (ExpressionVisitor visitor ) {
81+ visitor .visit (this );
82+ }
83+
84+ @ Override
85+ public String toString () {
86+ if (singleLine ) {
87+ return "--+ " + value + "\n " ;
88+ } else {
89+ return "/*+ " + value + " */" ;
90+ }
91+ }
92+
93+ }
0 commit comments