# HG changeset patch # User Pavel Tisnovsky # Date 1326117479 -3600 # Node ID 61f453c6b172f726faf22da053cc64284de5cc11 # Parent 8612fcdfab826c26129d63683f81d0fe4363ecd5 2012-01-09 Pavel Tisnovsky * src/index.html: * src/style.css: * templates/index.html: * templates/style.css: Moved into other directory. * templates/all_classes_template.html: * templates/all_packages_template.html: * templates/package_template.html: Prepared templates for test coverage HTML report. * src/PrintPublicMethods.java: * src/PrintTestCoverage.java: Refactoring and Javadoc. * Makefile: Updated diff -r 8612fcdfab82 -r 61f453c6b172 ChangeLog --- a/ChangeLog Fri Jan 06 12:25:10 2012 +0100 +++ b/ChangeLog Mon Jan 09 14:57:59 2012 +0100 @@ -1,3 +1,20 @@ +2012-01-09 Pavel Tisnovsky + + * src/index.html: + * src/style.css: + * templates/index.html: + * templates/style.css: + Moved into other directory. + * templates/all_classes_template.html: + * templates/all_packages_template.html: + * templates/package_template.html: + Prepared templates for test coverage HTML report. + * src/PrintPublicMethods.java: + * src/PrintTestCoverage.java: + Refactoring and Javadoc. + * Makefile: + Updated + 2012-01-06 Pavel Tisnovsky * src/PrintClassList.java: diff -r 8612fcdfab82 -r 61f453c6b172 Makefile --- a/Makefile Fri Jan 06 12:25:10 2012 +0100 +++ b/Makefile Mon Jan 09 14:57:59 2012 +0100 @@ -40,6 +40,7 @@ CLASSDIR=bin REPORTDIR=reports DOCS=docs +TEMPLATEDIR=templates JAVA=java JAVAC=javac @@ -139,7 +140,7 @@ $(JAVA) -cp $(CLASSDIR) PrintClassList `cat $(PATH_TO_RT_JAR_FILE)` > $(REPORTDIR)/$(ALL_CLASS_LIST) gen_report: $(REPORTDIR) - cp -u $(SOURCEPATH)/index.html $(REPORTDIR) - cp -u $(SOURCEPATH)/style.css $(REPORTDIR) + cp -u $(TEMPLATEDIR)/index.html $(REPORTDIR) + cp -u $(TEMPLATEDIR)/style.css $(REPORTDIR) java -cp $(CLASSDIR) ReportGenerator $(REPORTDIR)/$(ALL_CLASS_LIST) $(CLASS_LIST) $(REPORTDIR) diff -r 8612fcdfab82 -r 61f453c6b172 src/PrintPublicMethods.java --- a/src/PrintPublicMethods.java Fri Jan 06 12:25:10 2012 +0100 +++ b/src/PrintPublicMethods.java Mon Jan 09 14:57:59 2012 +0100 @@ -64,10 +64,13 @@ Class clazz = null; try { clazz = Class.forName(className); + // we need to get a list of public classes only + // (Interfaces and non public classes is not interesting ATM) if (!clazz.isInterface() && Modifier.isPublic(clazz.getModifiers())) { return clazz; } } + // some exceptions could be thrown by Class.forName() catch (ClassNotFoundException e) { return null; } @@ -92,9 +95,12 @@ * @return method name without prefixes */ private static String acquireMethodName(String methodName) { + // please note, that sequence of prefixes is very important final String[] prefixes = new String[] {"public", "final", "native", "synchronized", "static"}; String methodNameString = methodName; + // remove all prefixes for (String prefix : prefixes) { + // remove one prefix methodNameString = removePrefix(methodNameString, prefix); } return removeThrowsFromDeclaration(methodNameString); @@ -143,19 +149,22 @@ } /** - * Print all public method from given class name (if such class exists). + * Get all public methods from given class name (if such class exists). * * @param className * name of a class (including package name) + * @return set of all public methods */ @SuppressWarnings("unchecked") private static Set getAllPublicMethodsForClass(String className) { Set out = new TreeSet(); Class clazz = getClass(className); + // in case of error, empty set is returned (not null) if (clazz == null) { return out; } Method[] methods = clazz.getDeclaredMethods(); + // process all methods select add only public ones for (Method method : methods) { if (Modifier.isPublic(method.getModifiers())) { String methodName = acquireMethodName(method.toString()); @@ -165,14 +174,24 @@ return out; } + /** + * Get all public methods from given class name (if such class exists). + * + * + * @param className + * name of a class (including package name) + * @return set of all public constructors + */ @SuppressWarnings("unchecked") private static Set getAllConstructors(String className) { Set out = new TreeSet(); Class clazz = getClass(className); + // in case of error, empty set is returned (not null) if (clazz == null) { return out; } Constructor[] constructors = clazz.getConstructors(); + // process all constructors select add only public ones for (Constructor constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { String methodName = acquireMethodName(constructor.toString()); @@ -182,12 +201,40 @@ return out; } + /** + * List all public methods and public constructors for given class + * + * @param className + * name of class to list + */ private static void printAllPublicMethodsAndConstructors(String className) { + printAllConstructors(className); + printAllPublicMethods(className); + } + + /** + * List all public constructors for given class + * + * @param className + * name of class to list + */ + private static void printAllConstructors(String className) + { for (String methodSignature : getAllConstructors(className)) { System.out.println(methodSignature); } + } + + /** + * List all public methods for given class + * + * @param className + * name of class to list + */ + private static void printAllPublicMethods(String className) + { for (String methodSignature : getAllPublicMethodsForClass(className)) { System.out.println(methodSignature); @@ -202,6 +249,7 @@ * list. */ public static void main(String[] args) { + // first argument should exists - it should contains path to file with class list if (args.length == 1) { printAllPublicMethodsAndConstructors(args[0].trim()); diff -r 8612fcdfab82 -r 61f453c6b172 src/PrintTestCoverage.java --- a/src/PrintTestCoverage.java Fri Jan 06 12:25:10 2012 +0100 +++ b/src/PrintTestCoverage.java Mon Jan 09 14:57:59 2012 +0100 @@ -860,8 +860,15 @@ } } + /** + * Entry point to this tool. + * + * @param args + * should contain one argument - full name of class to check + */ public static void main(String[] args) { + // full name of class to check should be specified on command line if (args.length == 1) { String className = args[0].trim(); diff -r 8612fcdfab82 -r 61f453c6b172 src/index.html --- a/src/index.html Fri Jan 06 12:25:10 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - - - - Test coverage report - - - - - - - - - <h2>Frame Alert</h2> - <p>This document is designed to be viewed using the frames - feature. If you see this message, you are using a - non-frame-capable web client.</p> - - - - diff -r 8612fcdfab82 -r 61f453c6b172 src/style.css --- a/src/style.css Fri Jan 06 12:25:10 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -body {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; background-color:#ffffff; margin-left: 0px; margin-top: 0px} -h1 {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; text-align:center; padding-left: 1em; margin: 0} -h2 {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; padding-left: 1em; padding-right:1cm} -h3 {font-family: arial, helvetica, sans-serif; color:#000000; background:#a0a080; padding-left: 1em; padding-right:1cm} -h4 {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c0a0; padding-left: 1em; padding-right:1cm; margin-bottom: 5px} -a {font-family: arial, helvetica, sans-serif; color:#0000ff; text-decoration:none} -a:link {color:#0000ff} -a:visited {color:#0000ff} -a:visited {color:#0000ff} -a:hover {color:#ffffff; background:#404040} -p {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; padding-left:1em; padding-right:1em} -li {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify} -pre {} -tr {font-family: arial, helvetica, sans-serif; text-align:left} -td {font-family: arial, helvetica, sans-serif; text-align:left} -td.center {font-family: arial, helvetica, sans-serif; text-align:center} -th.center {font-family: arial, helvetica, sans-serif; text-align:center} - -.forms {background-color: #f0f0dd; vertical-align: top; width: 720px; border-collapse: collapse; border-color:#808080; margin-left:32px} - -.present-method {background-color:#006000} -.absent-method {background-color:#600000} - -.method-return-type {} -.method-name {} -.method-params {} - diff -r 8612fcdfab82 -r 61f453c6b172 templates/all_classes_template.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/all_classes_template.html Mon Jan 09 14:57:59 2012 +0100 @@ -0,0 +1,15 @@ + + + + Class list + + + + + +

Class list

+${PACKAGE_AND_CLASS_LIST} + + + diff -r 8612fcdfab82 -r 61f453c6b172 templates/all_packages_template.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/all_packages_template.html Mon Jan 09 14:57:59 2012 +0100 @@ -0,0 +1,16 @@ + + + + Package list + + + + + +

Package list

+all classes

+${PACKAGE_LIST} + + + diff -r 8612fcdfab82 -r 61f453c6b172 templates/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/index.html Mon Jan 09 14:57:59 2012 +0100 @@ -0,0 +1,20 @@ + + + + Test coverage report + + + + + + + + + <h2>Frame Alert</h2> + <p>This document is designed to be viewed using the frames + feature. If you see this message, you are using a + non-frame-capable web client.</p> + + + + diff -r 8612fcdfab82 -r 61f453c6b172 templates/package_template.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/package_template.html Mon Jan 09 14:57:59 2012 +0100 @@ -0,0 +1,15 @@ + + + + Class list + + + + + +

Class list

+${CLASS_LIST} + + + diff -r 8612fcdfab82 -r 61f453c6b172 templates/style.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/style.css Mon Jan 09 14:57:59 2012 +0100 @@ -0,0 +1,27 @@ +body {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; background-color:#ffffff; margin-left: 0px; margin-top: 0px} +h1 {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; text-align:center; padding-left: 1em; margin: 0} +h2 {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c060; padding-left: 1em; padding-right:1cm} +h3 {font-family: arial, helvetica, sans-serif; color:#000000; background:#a0a080; padding-left: 1em; padding-right:1cm} +h4 {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c0a0; padding-left: 1em; padding-right:1cm; margin-bottom: 5px} +a {font-family: arial, helvetica, sans-serif; color:#0000ff; text-decoration:none} +a:link {color:#0000ff} +a:visited {color:#0000ff} +a:visited {color:#0000ff} +a:hover {color:#ffffff; background:#404040} +p {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; padding-left:1em; padding-right:1em} +li {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify} +pre {} +tr {font-family: arial, helvetica, sans-serif; text-align:left} +td {font-family: arial, helvetica, sans-serif; text-align:left} +td.center {font-family: arial, helvetica, sans-serif; text-align:center} +th.center {font-family: arial, helvetica, sans-serif; text-align:center} + +.forms {background-color: #f0f0dd; vertical-align: top; width: 720px; border-collapse: collapse; border-color:#808080; margin-left:32px} + +.present-method {background-color:#006000} +.absent-method {background-color:#600000} + +.method-return-type {} +.method-name {} +.method-params {} +