Skip to content

Commit 07e6c35

Browse files
committed
Fix by subclassing JavaXrefSimple and sharing via Java.lexh
1 parent 8c43df0 commit 07e6c35

File tree

5 files changed

+106
-48
lines changed

5 files changed

+106
-48
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
26+
27+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?

src/org/opensolaris/opengrok/analysis/java/JavaSymbolTokenizer.lex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.java;
30-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3130

31+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3232
%%
3333
%public
3434
%class JavaSymbolTokenizer
@@ -42,10 +42,10 @@ super(in);
4242
%include CommonTokenizer.lexh
4343
%char
4444

45-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
46-
4745
%state STRING COMMENT SCOMMENT QSTRING
4846

47+
%include Common.lexh
48+
%include Java.lexh
4949
%%
5050

5151
<YYINITIAL> {
@@ -54,18 +54,22 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
5454
setAttribs(id, yychar, yychar + yylength());
5555
return yystate(); }
5656
}
57+
58+
{Number} {}
59+
5760
\" { yybegin(STRING); }
5861
\' { yybegin(QSTRING); }
5962
"/*" { yybegin(COMMENT); }
6063
"//" { yybegin(SCOMMENT); }
6164
}
6265

6366
<STRING> {
67+
\\[\"\\] {}
6468
\" { yybegin(YYINITIAL); }
65-
\\\\ | \\\" {}
6669
}
6770

6871
<QSTRING> {
72+
\\[\'\\] {}
6973
\' { yybegin(YYINITIAL); }
7074
}
7175

@@ -74,10 +78,10 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
7478
}
7579

7680
<SCOMMENT> {
77-
\n { yybegin(YYINITIAL);}
81+
{EOL} { yybegin(YYINITIAL);}
7882
}
7983

8084
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
81-
85+
{WhiteSpace} {}
8286
[^] {}
8387
}

src/org/opensolaris/opengrok/analysis/java/JavaXref.lex

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.java;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
31-
import java.io.IOException;
32-
import java.io.Writer;
33-
import java.io.Reader;
34-
import org.opensolaris.opengrok.web.Util;
3530

31+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
32+
import org.opensolaris.opengrok.web.HtmlConsts;
33+
import org.opensolaris.opengrok.web.Util;
3634
%%
3735
%public
3836
%class JavaXref
39-
%extends JFlexXref
37+
%extends JFlexXrefSimple
4038
%unicode
41-
%ignorecase
4239
%int
4340
%include CommonXref.lexh
4441
%{
@@ -52,11 +49,11 @@ import org.opensolaris.opengrok.web.Util;
5249
protected void setLineNumber(int x) { yyline = x; }
5350
%}
5451

55-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]+
56-
57-
File = [a-zA-Z]{FNameChar}* "." ("java"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"jnlp"|"jad"|"diff"|"patch")
58-
59-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
52+
File = [a-zA-Z]{FNameChar}* "." ([Jj][Aa][Vv][Aa] |
53+
[Pp][Rr][Oo][Pp][Ee][Rr][Tt][Ii][Ee][Ss] | [Pp][Rr][Oo][Pp][Ss] |
54+
[Xx][Mm][Ll] | [Cc][Oo][Nn][Ff] | [Tt][Xx][Tt] | [Hh][Tt][Mm][Ll]? |
55+
[Ii][Nn][Ii] | [Jj][Nn][Ll][Pp] | [Jj][Aa][Dd] | [Dd][Ii][Ff][Ff] |
56+
[Pp][Aa][Tt][Cc][Hh])
6057

6158
JavadocWithClassArg = "@throws" | "@exception"
6259
JavadocWithParamNameArg = "@param"
@@ -69,6 +66,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
6966
%include Common.lexh
7067
%include CommonURI.lexh
7168
%include CommonPath.lexh
69+
%include Java.lexh
7270
%%
7371
<YYINITIAL>{
7472
\{ { incScope(); writeUnicodeChar(yycharat(0)); }
@@ -77,7 +75,12 @@ ParamName = {Identifier} | "<" {Identifier} ">"
7775

7876
{Identifier} {
7977
String id = yytext();
80-
writeSymbol(id, Consts.kwd, yyline);
78+
// For historical reasons, JavaXref does not link identifiers of length=1
79+
if (id.length() > 1) {
80+
writeSymbol(id, Consts.kwd, yyline);
81+
} else {
82+
out.write(id);
83+
}
8184
}
8285

8386
"<" ({File}|{FPath}) ">" {
@@ -96,31 +99,57 @@ ParamName = {Identifier} | "<" {Identifier} ">"
9699
/*{Hier}
97100
{ out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
98101
*/
99-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
100-
101-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
102-
\' { yybegin(QSTRING);out.write("<span class=\"s\">\'");}
103-
"/**" / [^/] { yybegin(JAVADOC);out.write("<span class=\"c\">/**");}
104-
"/*" { yybegin(COMMENT);out.write("<span class=\"c\">/*");}
105-
"//" { yybegin(SCOMMENT);out.write("<span class=\"c\">//");}
102+
{Number} {
103+
disjointSpan(HtmlConsts.NUMBER_CLASS);
104+
out.write(yytext());
105+
disjointSpan(null);
106+
}
107+
108+
\" {
109+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
110+
out.write(htmlize(yytext()));
111+
}
112+
\' {
113+
pushSpan(QSTRING, HtmlConsts.STRING_CLASS);
114+
out.write(htmlize(yytext()));
115+
}
116+
"/**" / [^/] {
117+
pushSpan(JAVADOC, HtmlConsts.COMMENT_CLASS);
118+
out.write(yytext());
119+
}
120+
"/*" {
121+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
122+
out.write(yytext());
123+
}
124+
"//" {
125+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
126+
out.write(yytext());
127+
}
106128
}
107129

108130
<STRING> {
109-
\" {WhiteSpace} \" { out.write(yytext());}
110-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
111-
\\\\ { out.write("\\\\"); }
112-
\\\" { out.write("\\\""); }
131+
\\[\"\\] |
132+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
133+
\" {
134+
out.write(htmlize(yytext()));
135+
yypop();
136+
}
113137
}
114138

115139
<QSTRING> {
116-
"\\\\" { out.write("\\\\"); }
117-
"\\\'" { out.write("\\\'"); }
118-
\' {WhiteSpace} \' { out.write(yytext()); }
119-
\' { yybegin(YYINITIAL); out.write("'</span>"); }
140+
\\[\'\\] |
141+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
142+
\' {
143+
out.write(htmlize(yytext()));
144+
yypop();
145+
}
120146
}
121147

122148
<COMMENT, JAVADOC> {
123-
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
149+
"*/" {
150+
out.write(yytext());
151+
yypop();
152+
}
124153
}
125154

126155
<JAVADOC> {
@@ -140,16 +169,14 @@ ParamName = {Identifier} | "<" {Identifier} ">"
140169

141170
<SCOMMENT> {
142171
{WhspChar}*{EOL} {
143-
yybegin(YYINITIAL); out.write("</span>");
172+
yypop();
144173
startNewLine();
145174
}
146175
}
147176

148177

149178
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, JAVADOC> {
150-
"&" {out.write( "&amp;");}
151-
"<" {out.write( "&lt;");}
152-
">" {out.write( "&gt;");}
179+
[&<>\'\"] { out.write(htmlize(yytext())); }
153180
{WhspChar}*{EOL} { startNewLine(); }
154181
{WhiteSpace} { out.write(yytext()); }
155182
[!-~] { out.write(yycharat(0)); }

test/org/opensolaris/opengrok/analysis/java/sample_xref.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a class="l" name="2" href="#2">2</a><span class='fold-space'>&nbsp;</span> * CDDL HEADER START
1111
<a class="l" name="3" href="#3">3</a><span class='fold-space'>&nbsp;</span> *
1212
<a class="l" name="4" href="#4">4</a><span class='fold-space'>&nbsp;</span> * The contents of this file are subject to the terms of the
13-
<a class="l" name="5" href="#5">5</a><span class='fold-space'>&nbsp;</span> * Common Development and Distribution License (the "License").
13+
<a class="l" name="5" href="#5">5</a><span class='fold-space'>&nbsp;</span> * Common Development and Distribution License (the &quot;License&quot;).
1414
<a class="l" name="6" href="#6">6</a><span class='fold-space'>&nbsp;</span> * You may not use this file except in compliance with the License.
1515
<a class="l" name="7" href="#7">7</a><span class='fold-space'>&nbsp;</span> *
1616
<a class="l" name="8" href="#8">8</a><span class='fold-space'>&nbsp;</span> * See <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a> included in this distribution for the specific
@@ -19,7 +19,7 @@
1919
<a class="l" name="11" href="#11">11</a><span class='fold-space'>&nbsp;</span> * When distributing Covered Code, include this CDDL HEADER in each
2020
<a class="l" name="12" href="#12">12</a><span class='fold-space'>&nbsp;</span> * file and include the License file at <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a>.
2121
<a class="l" name="13" href="#13">13</a><span class='fold-space'>&nbsp;</span> * If applicable, add the following below this CDDL HEADER, with the
22-
<a class="l" name="14" href="#14">14</a><span class='fold-space'>&nbsp;</span> * fields enclosed by brackets "[]" replaced with your own identifying
22+
<a class="l" name="14" href="#14">14</a><span class='fold-space'>&nbsp;</span> * fields enclosed by brackets &quot;[]&quot; replaced with your own identifying
2323
<a class="l" name="15" href="#15">15</a><span class='fold-space'>&nbsp;</span> * information: Portions Copyright [yyyy] [name of copyright owner]
2424
<a class="l" name="16" href="#16">16</a><span class='fold-space'>&nbsp;</span> *
2525
<a class="l" name="17" href="#17">17</a><span class='fold-space'>&nbsp;</span> * CDDL HEADER END
@@ -32,7 +32,7 @@
3232
<a class="l" name="24" href="#24">24</a><span class='fold-space'>&nbsp;</span>
3333
<a class="l" name="25" href="#25">25</a><span class='fold-space'>&nbsp;</span><b>public</b> <b>class</b> <a class="xc" name="Sample"/><a href="/source/s?refs=Sample" class="xc intelliWindow-symbol" data-definition-place="def">Sample</a> &#123;
3434
<a class="l" name="26" href="#26">26</a><span class='fold-space'>&nbsp;</span>
35-
<a class="l" name="27" href="#27">27</a><span class='fold-space'>&nbsp;</span> <b>static</b> <b>private</b> <a href="/source/s?defs=String" class="intelliWindow-symbol" data-definition-place="undefined-in-file">String</a> <a class="xfld" name="MY_MEMBER"/><a href="/source/s?refs=MY_MEMBER" class="xfld intelliWindow-symbol" data-definition-place="def">MY_MEMBER</a> = <span class="s">"value"</span>&#59;
35+
<a class="l" name="27" href="#27">27</a><span class='fold-space'>&nbsp;</span> <b>static</b> <b>private</b> <a href="/source/s?defs=String" class="intelliWindow-symbol" data-definition-place="undefined-in-file">String</a> <a class="xfld" name="MY_MEMBER"/><a href="/source/s?refs=MY_MEMBER" class="xfld intelliWindow-symbol" data-definition-place="def">MY_MEMBER</a> = <span class="s">&quot;value&quot;</span>&#59;
3636
<a class="l" name="28" href="#28">28</a><span class='fold-space'>&nbsp;</span>
3737
<span id='scope_id_332feb92' class='scope-head'><span class='scope-signature'>Sample()</span><a class="l" name="29" href="#29">29</a><a style='cursor:pointer;' onclick='fold(this.parentNode.id)' id='scope_id_332feb92_fold_icon'><span class='fold-icon'>&nbsp;</span></a> <b>public</b> <a class="xmt" name="Sample"/><a href="/source/s?refs=Sample" class="xmt intelliWindow-symbol" data-definition-place="def">Sample</a>() &#123;</span>
3838
<span id='scope_id_332feb92_fold' class='scope-body'><a class="hl" name="30" href="#30">30</a><span class='fold-space'>&nbsp;</span>
@@ -60,9 +60,9 @@
6060
<a class="l" name="52" href="#52">52</a><span class='fold-space'>&nbsp;</span> multi-line comment }{}
6161
<a class="l" name="53" href="#53">53</a><span class='fold-space'>&nbsp;</span> */</span>
6262
<a class="l" name="54" href="#54">54</a><span class='fold-space'>&nbsp;</span>
63-
<a class="l" name="55" href="#55">55</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=print" class="intelliWindow-symbol" data-definition-place="undefined-in-file">print</a>(<span class="s">"I'm so useless"</span>)&#59;
63+
<a class="l" name="55" href="#55">55</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=print" class="intelliWindow-symbol" data-definition-place="undefined-in-file">print</a>(<span class="s">&quot;I&apos;m so useless&quot;</span>)&#59;
6464
<a class="l" name="56" href="#56">56</a><span class='fold-space'>&nbsp;</span>
65-
<a class="l" name="57" href="#57">57</a><span class='fold-space'>&nbsp;</span> <b>return</b> <span class="s">"Why do robots need to drink?"</span>&#59;
65+
<a class="l" name="57" href="#57">57</a><span class='fold-space'>&nbsp;</span> <b>return</b> <span class="s">&quot;Why do robots need to drink?&quot;</span>&#59;
6666
<a class="l" name="58" href="#58">58</a><span class='fold-space'>&nbsp;</span> &#125;
6767
</span><a class="l" name="59" href="#59">59</a><span class='fold-space'>&nbsp;</span>
6868
<a class="hl" name="60" href="#60">60</a><span class='fold-space'>&nbsp;</span> &#125;
@@ -73,12 +73,12 @@
7373
<a class="l" name="65" href="#65">65</a><span class='fold-space'>&nbsp;</span> <span class="c">// Try block to handle code that may cause exception</span>
7474
<a class="l" name="66" href="#66">66</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#num1" data-definition-place="defined-in-file">num1</a> = <span class="n">0</span>&#59;
7575
<a class="l" name="67" href="#67">67</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#num2" data-definition-place="defined-in-file">num2</a> = <span class="n">62</span> * <span class="n">0xFFFF</span> / <a class="d intelliWindow-symbol" href="#num1" data-definition-place="defined-in-file">num1</a>&#59;
76-
<a class="l" name="68" href="#68">68</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">"Try block message"</span>)&#59;
76+
<a class="l" name="68" href="#68">68</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">&quot;Try block message&quot;</span>)&#59;
7777
<a class="l" name="69" href="#69">69</a><span class='fold-space'>&nbsp;</span> &#125; <b>catch</b> (<a href="/source/s?defs=ArithmeticException" class="intelliWindow-symbol" data-definition-place="undefined-in-file">ArithmeticException</a> e) &#123;
7878
<a class="hl" name="70" href="#70">70</a><span class='fold-space'>&nbsp;</span> <span class="c">// This block is to catch divide-by-zero error</span>
79-
<a class="l" name="71" href="#71">71</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">"Error: Don't divide a number by zero"</span>)&#59;
79+
<a class="l" name="71" href="#71">71</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">&quot;Error: Don&apos;t divide a number by zero&quot;</span>)&#59;
8080
<a class="l" name="72" href="#72">72</a><span class='fold-space'>&nbsp;</span> &#125;
81-
<a class="l" name="73" href="#73">73</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">"I'm out of try-catch block in Java."</span>)&#59;
81+
<a class="l" name="73" href="#73">73</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=System" class="intelliWindow-symbol" data-definition-place="undefined-in-file">System</a>.<a href="/source/s?defs=out" class="intelliWindow-symbol" data-definition-place="undefined-in-file">out</a>.<a href="/source/s?defs=println" class="intelliWindow-symbol" data-definition-place="undefined-in-file">println</a>(<span class="s">&quot;I&apos;m out of try-catch block in Java.&quot;</span>)&#59;
8282
<a class="l" name="74" href="#74">74</a><span class='fold-space'>&nbsp;</span> &#125;
8383
</span><a class="l" name="75" href="#75">75</a><span class='fold-space'>&nbsp;</span>
8484
<a class="l" name="76" href="#76">76</a><span class='fold-space'>&nbsp;</span>&#125;

test/org/opensolaris/opengrok/analysis/java/truncated_xref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
class="xref">
66
<head>
77
<title>sampleFile - OpenGrok cross reference for /sampleFile</title></head><body>
8-
<a class="l" name="1" href="#1">1</a><span class='fold-space'>&nbsp;</span> <span class="s">"Oops this string is not ter</span></body>
8+
<a class="l" name="1" href="#1">1</a><span class='fold-space'>&nbsp;</span> <span class="s">&quot;Oops this string is not ter</span></body>
99
</html>

0 commit comments

Comments
 (0)