Skip to content

Commit a9c5b1e

Browse files
authored
Merge pull request #1930 from idodeclare/feature/java_tests
Feature/java tests
2 parents bb8ee6a + ee290b5 commit a9c5b1e

File tree

11 files changed

+397
-44
lines changed

11 files changed

+397
-44
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
144144
<exclude>*.java</exclude>
145145
</excludes>
146146
</testResource>
147+
<testResource>
148+
<targetPath>org/opensolaris/opengrok/analysis/java/</targetPath>
149+
<directory>../test/org/opensolaris/opengrok/analysis/java/</directory>
150+
<excludes>
151+
<exclude>*.java</exclude>
152+
</excludes>
153+
</testResource>
147154
<testResource>
148155
<targetPath>org/opensolaris/opengrok/analysis/perl/</targetPath>
149156
<directory>../test/org/opensolaris/opengrok/analysis/perl/</directory>
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/JavaAnalyzerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class JavaAnalyzerFactory extends FileAnalyzerFactory {
3434
private static final String[] SUFFIXES = {
3535
"JAVA",
3636
"AIDL",
37+
"JAV" // This just supports OpenGrok's own .jav test files
3738
};
3839

3940
public JavaAnalyzerFactory() {

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: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@
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.util.StringUtils;
33+
import org.opensolaris.opengrok.web.HtmlConsts;
34+
import org.opensolaris.opengrok.web.Util;
3635
%%
3736
%public
3837
%class JavaXref
39-
%extends JFlexXref
38+
%extends JFlexXrefSimple
4039
%unicode
41-
%ignorecase
4240
%int
4341
%include CommonXref.lexh
4442
%{
@@ -52,11 +50,11 @@ import org.opensolaris.opengrok.web.Util;
5250
protected void setLineNumber(int x) { yyline = x; }
5351
%}
5452

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]*)?
53+
File = [a-zA-Z]{FNameChar}* "." ([Jj][Aa][Vv][Aa] |
54+
[Pp][Rr][Oo][Pp][Ee][Rr][Tt][Ii][Ee][Ss] | [Pp][Rr][Oo][Pp][Ss] |
55+
[Xx][Mm][Ll] | [Cc][Oo][Nn][Ff] | [Tt][Xx][Tt] | [Hh][Tt][Mm][Ll]? |
56+
[Ii][Nn][Ii] | [Jj][Nn][Ll][Pp] | [Jj][Aa][Dd] | [Dd][Ii][Ff][Ff] |
57+
[Pp][Aa][Tt][Cc][Hh])
6058

6159
JavadocWithClassArg = "@throws" | "@exception"
6260
JavadocWithParamNameArg = "@param"
@@ -69,6 +67,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
6967
%include Common.lexh
7068
%include CommonURI.lexh
7169
%include CommonPath.lexh
70+
%include Java.lexh
7271
%%
7372
<YYINITIAL>{
7473
\{ { incScope(); writeUnicodeChar(yycharat(0)); }
@@ -96,31 +95,57 @@ ParamName = {Identifier} | "<" {Identifier} ">"
9695
/*{Hier}
9796
{ out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
9897
*/
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\">//");}
98+
{Number} {
99+
disjointSpan(HtmlConsts.NUMBER_CLASS);
100+
out.write(yytext());
101+
disjointSpan(null);
102+
}
103+
104+
\" {
105+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
106+
out.write(htmlize(yytext()));
107+
}
108+
\' {
109+
pushSpan(QSTRING, HtmlConsts.STRING_CLASS);
110+
out.write(htmlize(yytext()));
111+
}
112+
"/**" / [^/] {
113+
pushSpan(JAVADOC, HtmlConsts.COMMENT_CLASS);
114+
out.write(yytext());
115+
}
116+
"/*" {
117+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
118+
out.write(yytext());
119+
}
120+
"//" {
121+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
122+
out.write(yytext());
123+
}
106124
}
107125

108126
<STRING> {
109-
\" {WhiteSpace} \" { out.write(yytext());}
110-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
111-
\\\\ { out.write("\\\\"); }
112-
\\\" { out.write("\\\""); }
127+
\\[\"\\] |
128+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
129+
\" {
130+
out.write(htmlize(yytext()));
131+
yypop();
132+
}
113133
}
114134

115135
<QSTRING> {
116-
"\\\\" { out.write("\\\\"); }
117-
"\\\'" { out.write("\\\'"); }
118-
\' {WhiteSpace} \' { out.write(yytext()); }
119-
\' { yybegin(YYINITIAL); out.write("'</span>"); }
136+
\\[\'\\] |
137+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
138+
\' {
139+
out.write(htmlize(yytext()));
140+
yypop();
141+
}
120142
}
121143

122144
<COMMENT, JAVADOC> {
123-
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
145+
"*/" {
146+
out.write(yytext());
147+
yypop();
148+
}
124149
}
125150

126151
<JAVADOC> {
@@ -140,23 +165,21 @@ ParamName = {Identifier} | "<" {Identifier} ">"
140165

141166
<SCOMMENT> {
142167
{WhspChar}*{EOL} {
143-
yybegin(YYINITIAL); out.write("</span>");
168+
yypop();
144169
startNewLine();
145170
}
146171
}
147172

148173

149174
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, JAVADOC> {
150-
"&" {out.write( "&amp;");}
151-
"<" {out.write( "&lt;");}
152-
">" {out.write( "&gt;");}
175+
[&<>\'\"] { out.write(htmlize(yytext())); }
153176
{WhspChar}*{EOL} { startNewLine(); }
154177
{WhiteSpace} { out.write(yytext()); }
155178
[!-~] { out.write(yycharat(0)); }
156179
[^\n] { writeUnicodeChar(yycharat(0)); }
157180
}
158181

159-
<STRING, COMMENT, SCOMMENT, STRING, QSTRING, JAVADOC> {
182+
<STRING, COMMENT, SCOMMENT, QSTRING, JAVADOC> {
160183
{FPath}
161184
{ out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
162185

@@ -170,12 +193,26 @@ ParamName = {Identifier} | "<" {Identifier} ">"
170193
out.write(path);
171194
out.write("</a>");}
172195

173-
{BrowseableURI} {
174-
appendLink(yytext(), true);
175-
}
176-
177196
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
178197
{
179198
writeEMailAddress(yytext());
180199
}
181200
}
201+
202+
<STRING, SCOMMENT> {
203+
{BrowseableURI} {
204+
appendLink(yytext(), true);
205+
}
206+
}
207+
208+
<COMMENT, JAVADOC> {
209+
{BrowseableURI} {
210+
appendLink(yytext(), true, StringUtils.END_C_COMMENT);
211+
}
212+
}
213+
214+
<QSTRING> {
215+
{BrowseableURI} {
216+
appendLink(yytext(), true, StringUtils.APOS_NO_BSESC);
217+
}
218+
}

0 commit comments

Comments
 (0)