Title: [1114] trunk/qdox: Start treating JavaDoc as a special kind of comment

Diff

Modified: trunk/qdox/pom.xml (1113 => 1114)

--- trunk/qdox/pom.xml	2011-03-10 12:51:58 UTC (rev 1113)
+++ trunk/qdox/pom.xml	2011-03-12 21:55:37 UTC (rev 1114)
@@ -220,6 +220,7 @@
           <outputDirectory>${project.build.directory}/generated-sources/parser</outputDirectory>
           <lexDefinitions>
             <lexFile>${basedir}/src/grammar/lexer.flex</lexFile>
+            <lexFile>${basedir}/src/grammar/commentlexer.flex</lexFile>
           </lexDefinitions>
           <skeleton>${basedir}/src/grammar/skeleton.inner</skeleton>
         </configuration>
@@ -230,7 +231,7 @@
         <version>1.2</version>
         <executions>
           <execution>
-            <id>byaccj</id>
+            <id>javasourceparser</id>
             <phase>generate-sources</phase>
             <goals>
               <goal>exec</goal>
@@ -242,6 +243,7 @@
                 <argument>-Jnorun</argument>
                 <argument>-Jnoconstruct</argument>
                 <argument>-Jclass=Parser</argument>
+                <!-- <argument>-Jimplements=CommentHandler</argument> -->
                 <argument>-Jsemantic=Value</argument>
                 <argument>-Jpackage=com.thoughtworks.qdox.parser.impl</argument>
                 <argument>${basedir}/src/grammar/parser.y</argument>
@@ -249,6 +251,25 @@
               <workingDirectory>${project.build.directory}/generated-sources/parser/com/thoughtworks/qdox/parser/impl</workingDirectory>
             </configuration>
           </execution>
+          <execution>
+            <id>javacommentparser</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+            <configuration>
+              <executable>${qdox.byaccj.executable}</executable>
+              <arguments>
+                <argument>-v</argument>
+                <argument>-Jnorun</argument>
+                <argument>-Jnoconstruct</argument>
+                <argument>-Jclass=DefaultJavaCommentParser</argument>
+                <argument>-Jpackage=com.thoughtworks.qdox.parser.impl</argument>
+                <argument>${basedir}/src/grammar/commentparser.y</argument>
+              </arguments>
+              <workingDirectory>${project.build.directory}/generated-sources/parser/com/thoughtworks/qdox/parser/impl</workingDirectory>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
       <plugin>

Added: trunk/qdox/src/grammar/commentlexer.flex (0 => 1114)

--- trunk/qdox/src/grammar/commentlexer.flex	                        (rev 0)
+++ trunk/qdox/src/grammar/commentlexer.flex	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,178 @@
+package com.thoughtworks.qdox.parser.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.thoughtworks.qdox.parser.*;
+%%
+
+// class and lexer definitions
+%class DefaultJavaCommentLexer
+%public
+%implements Lexer
+%byaccj
+%unicode
+%line
+%column
+
+%{
+
+    private int stateDepth = 0;
+    private int[] stateStack = new int[10];
+
+    private StringBuffer codeBody = new StringBuffer(8192);
+    private boolean appendingToCodeBody;
+
+    public int lex() throws java.io.IOException {
+        return yylex();
+    }
+
+    public String text() {
+        return yytext();
+    }
+    
+    public int getLine() {
+        return yyline + 1;
+    }
+
+    public int getColumn() {
+        return yycolumn + 1;
+    }
+    
+    public String getCodeBody(){
+        String s = codeBody.toString();
+        codeBody = new StringBuffer(8192);
+        return s;
+    }
+    
+        private void pushState(int newState) {
+        stateStack[stateDepth++] = zzLexicalState;
+        yybegin(newState);
+    }
+
+    private void popState() {
+        yybegin(stateStack[--stateDepth]);
+    }
+    
+    private int peekState(int relative) {
+      if(relative > stateDepth) {
+        return -1;
+      }
+      else {
+        return stateStack[stateDepth - relative];
+      }
+    }
+%}
+
+Eol                     = \r|\n|\r\n
+JavadocEnd              = "*"+ "/"
+
+%state JAVADOC JAVADOCLINE JAVADOCTAG MULTILINECOMMENT SINGLELINECOMMENT
+
+%%
+
+<YYINITIAL> {
+  "//"   { 
+           codeBody.append( "//" );
+           pushState( SINGLELINECOMMENT ); 
+         }
+  "/**/" { 
+           codeBody.append( "/**/" ); 
+         }
+  "/**"  {
+           pushState( JAVADOC );
+           return DefaultJavaCommentParser.JAVADOCSTART;
+         }
+  "/*"   { 
+           codeBody.append( "/*" );
+           pushState( MULTILINECOMMENT ); 
+         }
+}
+
+<JAVADOC> {
+    "@"               { 
+                        yypushback(1); 
+                        pushState(JAVADOCTAG); 
+                      }
+    [^ \t\r*@]		  { 
+                        yypushback(1); 
+                        pushState(JAVADOCLINE); 
+                      }
+    "*"+ [ \t]* / "@" { 
+                        pushState(JAVADOCTAG); 
+                      }
+    "*"+ [ \t]?       { 
+                        pushState(JAVADOCLINE); 
+                      }
+    {JavadocEnd}      { 
+                        popState(); 
+                        return DefaultJavaCommentParser.JAVADOCEND;
+                      }
+}
+<JAVADOCLINE> {
+  ~{Eol}                           { 
+                                     popState(); 
+                                     return DefaultJavaCommentParser.JAVADOCLINE; 
+                                   }
+  .* [^ \t*] / [ \t]* {JavadocEnd} { 
+                                     popState(); 
+                                     return DefaultJavaCommentParser.JAVADOCLINE;
+                                   }
+  {JavadocEnd}                     { 
+                                     popState();
+                                     popState();
+                                     return DefaultJavaCommentParser.JAVADOCEND;
+                                   }
+}
+
+<JAVADOCTAG> {
+  "@" [^ \t\n\r]+ / {JavadocEnd} { 
+                                   popState();
+                                   return DefaultJavaCommentParser.JAVADOCTAG;
+                                 }
+  "@" [^ \t\n\r]+                { 
+                                   return DefaultJavaCommentParser.JAVADOCTAG;
+                                 }
+  [ \t]+                         { 
+                                   popState();
+                                   pushState(JAVADOCLINE);
+                                 }
+  {Eol}                          { 
+                                   popState();
+                                   return DefaultJavaCommentParser.JAVADOCLINE;
+                                 }
+}
+
+<MULTILINECOMMENT, JAVADOC> {
+    "*/" { 
+           codeBody.append("*/");
+           popState();
+         }
+}
+
+<SINGLELINECOMMENT> {
+    {Eol} { 
+            codeBody.append(yytext());
+            popState();
+          }
+}
+
+.|\r|\n|\r\n { 
+               codeBody.append(yytext());
+             }
\ No newline at end of file

Added: trunk/qdox/src/grammar/commentparser.y (0 => 1114)

--- trunk/qdox/src/grammar/commentparser.y	                        (rev 0)
+++ trunk/qdox/src/grammar/commentparser.y	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,129 @@
+%{
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+
+import com.thoughtworks.qdox.builder.Builder;
+import com.thoughtworks.qdox.parser.Lexer;
+import com.thoughtworks.qdox.parser.ParseException;
+import com.thoughtworks.qdox.parser.structs.TagDef;
+%}
+
+%token JAVADOCSTART JAVADOCEND
+
+// strongly typed tokens/types
+%token <sval> JAVADOCTAG JAVADOCLINE
+%%
+javadoc: JAVADOCSTART javadocdescription_opt javadoctags_opt JAVADOCEND;
+
+javadocdescription_opt:
+                      | javadocdescription;
+
+javadocdescription: javadoctokens 
+                    { 
+                      builder.addJavaDoc(buffer()); 
+                    };
+
+javadoctokens: javadoctoken
+             | javadoctokens javadoctoken;
+
+javadoctoken: JAVADOCLINE 
+              {
+                appendToBuffer($1);
+              }; 
+
+javadoctags_opt: 
+               | javadoctags;
+               
+javadoctags: javadoctag
+           | javadoctags javadoctag;
+
+javadoctag: JAVADOCTAG 
+            { 
+              line = lexer.getLine(); 
+            } 
+            javadoctokens 
+            {
+              builder.addJavaDocTag(new TagDef($1.substring(1), buffer(), line)); 
+            };
+
+%%
+
+private Lexer lexer;
+private Builder builder;
+
+private int line;
+private int column;
+private boolean debugLexer;
+
+private StringBuffer textBuffer = new StringBuffer();
+
+public DefaultJavaCommentParser(Lexer lexer, Builder builder) {
+    this.lexer = lexer;
+    this.builder = builder;
+}
+
+public void setDebugParser(boolean debug) {
+    yydebug = debug;
+}
+
+public void setDebugLexer(boolean debug) {
+    debugLexer = debug;
+}
+
+private void appendToBuffer(String word) {
+    if (textBuffer.length() > 0) {
+        char lastChar = textBuffer.charAt(textBuffer.length() - 1);
+        if (!Character.isWhitespace(lastChar)) {
+            textBuffer.append(' ');
+        }
+    }
+    textBuffer.append(word);
+}
+
+private String buffer() {
+    String result = textBuffer.toString().trim();
+    textBuffer.setLength(0);
+    return result;
+}
+
+public boolean parse() {
+    return yyparse() == 0;
+}
+
+private int yylex() {
+    try {
+        final int result = lexer.lex();
+        yylval = new DefaultJavaCommentParserVal();
+        yylval.sval = lexer.text();
+        if (debugLexer) {
+            System.err.println("Token: " + yyname[result] + " \"" + yylval.sval + "\"");
+        }
+        return result;
+    }
+    catch(IOException e) {
+        return 0;
+    }
+}
+
+private void yyerror(String msg) {
+    throw new ParseException(msg, lexer.getLine(), lexer.getColumn());
+}
+    
\ No newline at end of file

Added: trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentHandler.java (0 => 1114)

--- trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentHandler.java	                        (rev 0)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentHandler.java	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,34 @@
+package com.thoughtworks.qdox.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * JavaDoc is not part of the Java Language Specification, it should be treated as a special type of comment.
+ * This means it can appear almost everywhere, although there are only a few places where JavaDoc has effect.
+ * 
+ * When the parser has finished a comment, it will trigger the commentHandler by calling the onComment-method.     
+ * 
+ * 
+ * @since 2.0
+ */
+public interface CommentHandler
+{
+  public void onComment(String comment);
+}
Property changes on: trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentHandler.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentScanner.java (0 => 1114)

--- trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentScanner.java	                        (rev 0)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentScanner.java	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,30 @@
+package com.thoughtworks.qdox.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Classes implementing this interface can trigger the handler for every time it has parsed a comment. 
+ * 
+ * @since 2.0
+ */
+public interface CommentScanner
+{
+    public void addCommentHandler( CommentHandler handler );
+}
Property changes on: trunk/qdox/src/java/com/thoughtworks/qdox/parser/CommentScanner.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/qdox/src/java/com/thoughtworks/qdox/parser/JavaLexer.java (0 => 1114)

--- trunk/qdox/src/java/com/thoughtworks/qdox/parser/JavaLexer.java	                        (rev 0)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/parser/JavaLexer.java	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,30 @@
+package com.thoughtworks.qdox.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The Lexer-interface for Java sources
+ * 
+ * @since 2.0
+ */
+public interface JavaLexer extends Lexer, CommentScanner
+{
+
+}
Property changes on: trunk/qdox/src/java/com/thoughtworks/qdox/parser/JavaLexer.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/qdox/src/test/com/thoughtworks/qdox/parser/impl/JFlexCommentLexerTest.java (0 => 1114)

--- trunk/qdox/src/test/com/thoughtworks/qdox/parser/impl/JFlexCommentLexerTest.java	                        (rev 0)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/parser/impl/JFlexCommentLexerTest.java	2011-03-12 21:55:37 UTC (rev 1114)
@@ -0,0 +1,245 @@
+package com.thoughtworks.qdox.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.junit.Test;
+
+public class JFlexCommentLexerTest
+{
+    private DefaultJavaCommentLexer lexer;
+    
+    @Test
+    public void testSingleLineComment() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("// this is a single line comment"));
+        lexAssert( 0 );
+        assertEquals( "// this is a single line comment", lexer.getCodeBody() );
+    }
+
+    @Test
+    public void testCompactMultiLineComment() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/**/"));
+        lexAssert( 0 );
+        assertEquals( "/**/", lexer.getCodeBody() );
+    }
+
+    @Test
+    public void testSingleRowMultiLineComment() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/* multiline comment with one row */"));
+        lexAssert( 0 );
+        assertEquals( "/* multiline comment with one row */", lexer.getCodeBody() );
+    }
+    
+    @Test
+    public void testJavaDocComment() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/** multiline comment with one row */"));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "multiline comment with one row");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert( 0 );
+    }
+    
+    @Test
+    public void testSingleTagJavaDoc() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/** @deprecated */"));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@deprecated");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert( 0 );
+    }
+
+    @Test
+    public void testDeprecatedJavaDoc() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/** @author John Doe */"));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@author");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "John Doe");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert( 0 );
+    }
+
+    @Test
+    public void testMultiTagJavaDoc() throws Exception {
+        lexer = new DefaultJavaCommentLexer( new StringReader("/** @deprecated\n" + 
+        		"  * @author John Doe */"));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@deprecated");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@author");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "John Doe");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert( 0 );
+    }
+    
+    public void testDocletTags() throws Exception {
+        String in = ""
+                + "/**\n"
+                + " * @hello world\n"
+                + " * @a b c d\n"
+                + " * @bye\n"
+                + " * @bye:bye\n"
+                + " */";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@hello");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "world\n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@a");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "b c d\n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@bye");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@bye:bye");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert(0);
+    }
+    
+    public void testOneLinerDocComment() throws Exception {
+        String in = "/** @hello world */";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@hello");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "world");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND);
+        lexAssert(0);
+    }
+    
+    public void testCompressedDocComment() throws Exception {
+        String in = "/**@foo bar*/";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@foo");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "bar");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND);
+        lexAssert(0);
+    }
+
+    public void testDeepJavadocTag() throws Exception {
+        String in = "  /** *  *** * @m x \n" +
+                "*/";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "*  *** * @m x \n");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert(0); 
+    }
+
+    public void testDocCommentContainingAtSymbols() throws Exception {
+        String in = ""
+            + "/**\n"
+            + " * [email protected]\n"
+            + " * {@link here}.\n"
+            + " * me @home\n"
+            + " * geeks @ play\n"
+            + " */";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "[email protected]\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "{@link here}.\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "me @home\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "geeks @ play\n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert(0);
+    }
+
+    public void testDocCommentContainingStars() throws Exception {
+        String in = ""
+                + "/**\n"
+                + " * 5 * 4\n"
+                + " * SELECT COUNT(*)\n"
+                + " * **stars**everywhere** \n"
+                + " */";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "5 * 4\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "SELECT COUNT(*)\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "**stars**everywhere** \n");
+
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert(0);
+    }
+    
+    public void testExtraStarsAreIgnoredAtStartAndEnd() throws Exception {
+        String in = ""
+                + "/*****\n"
+                + " * blah\n"
+                + " *****/";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/*****");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "blah\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*****/");
+        lexAssert(0);
+    }
+    
+    public void testExtraStarsCompressed() throws Exception {
+        String in = ""
+                + "/***blah***/";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/***");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "blah");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "**/");
+        lexAssert(0);
+    }
+    
+    public void testIgnoreStarPrefix() throws Exception {
+        String in = ""
+            + "/**\n"
+            + " * simple\n"
+            + "\t    * indented\n"
+            + " *nospace\n"
+            + " *** multistar\n"
+            + " *\n"
+            + " */";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "simple\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "indented\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "nospace\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "multistar\n");
+        lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n");
+        
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");
+        lexAssert(0);
+    }
+    
+    // QDOX-200
+    public void testCompactJavaDocTag() throws Exception {
+        String in = "/** @foo*/";
+        lexer = new DefaultJavaCommentLexer(new StringReader(in));
+        lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**");
+        lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@foo");
+        lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/");      
+        lexAssert(0);
+    }
+
+    private void lexAssert(int lex) throws IOException {
+        lexAssert( lex, "" );
+
+    }
+    private void lexAssert(int lex, String text) throws IOException {
+        assertEquals(lex, lexer.lex());
+        assertEquals(text, lexer.text());
+    }
+    
+}
Property changes on: trunk/qdox/src/test/com/thoughtworks/qdox/parser/impl/JFlexCommentLexerTest.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to