minor refactoring of CommentParser.java

This commit is contained in:
Marko Klopcic 2013-01-29 08:39:35 +01:00
commit 0d66568ba3
12 changed files with 57 additions and 42 deletions

View file

@ -11,8 +11,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
public class commentParser {
static HashMap<String, String> parsedComments = new HashMap<String, String>();
public class CommentParser {
private static Map<String, String> m_parsedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
@ -24,31 +24,31 @@ public class commentParser {
for (ClassDoc classDoc : root.classes()) {
if (classDoc.getRawCommentText().length() > 0)
parsedComments.put(classDoc.qualifiedName(), classDoc.getRawCommentText());
m_parsedComments.put(classDoc.qualifiedName(), classDoc.getRawCommentText());
for (FieldDoc f : classDoc.enumConstants()) {
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.qualifiedName(), f.getRawCommentText());
m_parsedComments.put(f.qualifiedName(), f.getRawCommentText());
}
for (FieldDoc f : classDoc.fields()) {
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.qualifiedName(), f.getRawCommentText());
m_parsedComments.put(f.qualifiedName(), f.getRawCommentText());
}
for (MethodDoc m : classDoc.methods()) {
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.toString(), m.getRawCommentText());
m_parsedComments.put(m.toString(), m.getRawCommentText());
}
}
return true;
}
public static int check(HashMap<String, String> wantedComments) {
public int check(Map<String, String> wantedComments) {
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
Iterator<Entry<String, String>> it = m_parsedComments.entrySet().iterator();
while (it.hasNext())
{
while (it.hasNext()) {
Entry<String, String> e = (Entry<String, String>) it.next();
String actualStr = e.getValue();
String wantedStr = wantedComments.get(e.getKey());
@ -102,14 +102,14 @@ public class commentParser {
}
}
if (parsedComments.size() != wantedComments.size()) {
if (m_parsedComments.size() != wantedComments.size()) {
System.out.println("Mismatch in the number of comments!\n Expected: " +
wantedComments.size() + "\n Parsed: " +
parsedComments.size());
m_parsedComments.size());
System.out.println("Expected keys: ");
printKeys(wantedComments);
System.out.println("Parsed keys: ");
printKeys(parsedComments);
printKeys(m_parsedComments);
errorCount++;
}
@ -118,7 +118,8 @@ public class commentParser {
}
private static void printKeys(Map map) {
private void printKeys(Map<String, String> map) {
Set<String> keys = map.keySet();
for (String key : keys) {
System.out.println(" " + key);
@ -127,9 +128,11 @@ public class commentParser {
public static void printCommentListForJavaSource() {
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Iterator< Entry<String, String> > it = m_parsedComments.entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> e = (Entry<String, String>) it.next();
String commentText = e.getValue();
commentText = commentText.replace("\\", "\\\\");
@ -143,12 +146,12 @@ public class commentParser {
public static void main(String argv[]) {
if (argv.length<1) {
System.out.format("Usage:\n\tcommentParsing <package to parse>\n");
System.out.format("Usage:\n\tCommentParser <package to parse>\n");
System.exit(1);
}
com.sun.tools.javadoc.Main.execute("The comment parser program",
"commentParser", new String[]{"-quiet", argv[0]});
"CommentParser", new String[]{"-quiet", argv[0]});
// if we are run as standalone app, print the list of found comments as it would appear in java source

View file

@ -19,9 +19,10 @@ public class doxygen_basic_notranslate_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_basic_notranslate runtime test",
"commentParser", new String[]{"-quiet", "doxygen_basic_notranslate"});
"CommentParser",
new String[]{"-quiet", "doxygen_basic_notranslate"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("doxygen_basic_notranslate.doxygen_basic_notranslate.function3(int)",

View file

@ -19,9 +19,10 @@ public class doxygen_basic_translate_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_basic_translate runtime test",
"commentParser", new String[]{"-quiet", "doxygen_basic_translate"});
"CommentParser",
new String[]{"-quiet", "doxygen_basic_translate"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_misc_constructs_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_misc_constructs runtime test",
"commentParser", new String[]{"-quiet", "doxygen_misc_constructs"});
"CommentParser",
new String[]{"-quiet", "doxygen_misc_constructs"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_parsing_enums_proper_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_proper runtime test",
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_proper"});
"CommentParser",
new String[]{"-quiet", "doxygen_parsing_enums_proper"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_parsing_enums_simple_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_simple runtime test",
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_simple"});
"CommentParser",
new String[]{"-quiet", "doxygen_parsing_enums_simple"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_parsing_enums_typesafe_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typesafe runtime test",
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_typesafe"});
"CommentParser",
new String[]{"-quiet", "doxygen_parsing_enums_typesafe"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_parsing_enums_typeunsafe_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typeunsafe runtime test",
"commentParser", new String[]{"-quiet", "doxygen_parsing_enums_typeunsafe"});
"CommentParser",
new String[]{"-quiet", "doxygen_parsing_enums_typeunsafe"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_parsing_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_parsing runtime test",
"commentParser", new String[]{"-quiet", "doxygen_parsing"});
"CommentParser",
new String[]{"-quiet", "doxygen_parsing"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_translate_all_tags_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_translate_all_tags runtime test",
"commentParser", new String[]{"-quiet", "doxygen_translate_all_tags"});
"CommentParser",
new String[]{"-quiet", "doxygen_translate_all_tags"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -19,9 +19,10 @@ public class doxygen_translate_links_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_translate_links runtime test",
"commentParser", new String[]{"-quiet", "doxygen_translate_links"});
"CommentParser",
new String[]{"-quiet", "doxygen_translate_links"});
HashMap<String, String> wantedComments = new HashMap<String, String>();

View file

@ -2,6 +2,7 @@
import doxygen_translate.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map;
public class doxygen_translate_runme {
static {
@ -19,11 +20,12 @@ public class doxygen_translate_runme {
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
commentParser parser = new commentParser();
CommentParser parser = new CommentParser();
com.sun.tools.javadoc.Main.execute("doxygen_translate runtime test",
"commentParser", new String[]{"-quiet", "doxygen_translate"});
"CommentParser",
new String[]{"-quiet", "doxygen_translate"});
HashMap<String, String> wantedComments = new HashMap<String, String>();
Map<String, String> wantedComments = new HashMap<String, String>();
wantedComments.put("doxygen_translate.doxygen_translate.function(int, float)",
" <i>Hello </i>\n" +