cvs commit: spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant ClassAbbreviator.java ClassAbbreviatorImpl.java JavadocFormatter.java JavadocFormatterImpl.java LineIndenter.java LineIndenterImpl.java NotAClassException.java NotPublicException.java ComponentMetadataTask.java DirectoryDoesNotExistBuildException.java NoInterfacesSpecifiedBuildException.java NoJavadocBuildException.java NoSuchJavaSourceFileBuildException.java NotADirectoryBuildException.java ParameterNotSpecifiedBuildException.java
Mike Hogan <[email protected]> Sun, 09 Nov 2003 06:00:47 -0800
| Newsgroups | gmane.comp.java.spice.cvs |
|---|---|
| Message-ID | <[email protected]> |
hogie 03/11/09 06:00:47
Modified: sandbox/repository/componenthaus/src/java/org/componenthaus/ant
ComponentMetadataTask.java
DirectoryDoesNotExistBuildException.java
NoInterfacesSpecifiedBuildException.java
NoJavadocBuildException.java
NoSuchJavaSourceFileBuildException.java
NotADirectoryBuildException.java
ParameterNotSpecifiedBuildException.java
Added: sandbox/repository/componenthaus/src/java/org/componenthaus/ant
ClassAbbreviator.java ClassAbbreviatorImpl.java
JavadocFormatter.java JavadocFormatterImpl.java
LineIndenter.java LineIndenterImpl.java
NotAClassException.java NotPublicException.java
Log:
If components are classes, show as little of the class as necessary to show service offering
Revision Changes Path
1.4 +3 -2 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ComponentMetadataTask.java
Index: ComponentMetadataTask.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ComponentMetadataTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ComponentMetadataTask.java 5 Nov 2003 19:35:50 -0000 1.3
+++ ComponentMetadataTask.java 9 Nov 2003 14:00:46 -0000 1.4
@@ -119,7 +119,7 @@
if (interfaceAsClass == null) {
throw new NoSuchJavaSourceFileBuildException(interfaceName);
}
- final String javadoc = interfaceAsClass.getComment();
+ String javadoc = interfaceAsClass.getComment();
if (javadoc == null || "".equals(javadoc)) {
throw new NoJavadocBuildException(interfaceName);
}
@@ -137,7 +137,8 @@
interfaceAsClass.getPackage(),
interfaceAsClass.getName(),
interfaceAsClass.getComment(),
- source);
+ source,
+ !interfaceAsClass.isInterface());
return interfaceMetadata;
}
1.2 +1 -0 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/DirectoryDoesNotExistBuildException.java
Index: DirectoryDoesNotExistBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/DirectoryDoesNotExistBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DirectoryDoesNotExistBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ DirectoryDoesNotExistBuildException.java 9 Nov 2003 14:00:46 -0000 1.2
@@ -6,6 +6,7 @@
private String directoryName;
public DirectoryDoesNotExistBuildException(String directoryName) {
+ super("The directory '" + directoryName + "' does not exist");
this.directoryName = directoryName;
}
1.2 +3 -0 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoInterfacesSpecifiedBuildException.java
Index: NoInterfacesSpecifiedBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoInterfacesSpecifiedBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NoInterfacesSpecifiedBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ NoInterfacesSpecifiedBuildException.java 9 Nov 2003 14:00:47 -0000 1.2
@@ -3,4 +3,7 @@
import org.apache.tools.ant.BuildException;
public class NoInterfacesSpecifiedBuildException extends BuildException {
+ public NoInterfacesSpecifiedBuildException() {
+ super("No interfaces specified to ant task");
+ }
}
1.2 +1 -0 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoJavadocBuildException.java
Index: NoJavadocBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoJavadocBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NoJavadocBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ NoJavadocBuildException.java 9 Nov 2003 14:00:47 -0000 1.2
@@ -6,6 +6,7 @@
private String interfaceName;
public NoJavadocBuildException(String interfaceName) {
+ super("There is no javadoc for the source file " + interfaceName);
this.interfaceName = interfaceName;
}
1.2 +1 -0 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoSuchJavaSourceFileBuildException.java
Index: NoSuchJavaSourceFileBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NoSuchJavaSourceFileBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NoSuchJavaSourceFileBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ NoSuchJavaSourceFileBuildException.java 9 Nov 2003 14:00:47 -0000 1.2
@@ -6,6 +6,7 @@
private String interfaceName;
public NoSuchJavaSourceFileBuildException(String interfaceName) {
+ super("No java source file with name " + interfaceName);
this.interfaceName = interfaceName;
}
1.2 +1 -0 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NotADirectoryBuildException.java
Index: NotADirectoryBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NotADirectoryBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NotADirectoryBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ NotADirectoryBuildException.java 9 Nov 2003 14:00:47 -0000 1.2
@@ -6,6 +6,7 @@
private String directoryName;
public NotADirectoryBuildException(String directoryName) {
+ super(directoryName + " is not a directory");
this.directoryName = directoryName;
}
1.2 +3 -2 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ParameterNotSpecifiedBuildException.java
Index: ParameterNotSpecifiedBuildException.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ParameterNotSpecifiedBuildException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ParameterNotSpecifiedBuildException.java 26 Oct 2003 13:46:41 -0000 1.1
+++ ParameterNotSpecifiedBuildException.java 9 Nov 2003 14:00:47 -0000 1.2
@@ -5,8 +5,9 @@
public class ParameterNotSpecifiedBuildException extends BuildException {
private final String directoryName;
- public ParameterNotSpecifiedBuildException(String directoryName) {
- this.directoryName = directoryName;
+ public ParameterNotSpecifiedBuildException(String parameterName) {
+ super("Required parameter '" + parameterName + "' is not specified");
+ this.directoryName = parameterName;
}
public String getParameterName() {
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ClassAbbreviator.java
Index: ClassAbbreviator.java
===================================================================
package org.componenthaus.ant;
import com.thoughtworks.qdox.model.JavaClass;
/**
* Given a QDox JavaClass representing a class (not an interface), provide
* a string representation of the source code for that class, but containing
* only the public method signatures. All non-public members are removed, as are
* all method bodies.
*/
public interface ClassAbbreviator {
/**
* Given a QDox JavaClass representing a class (not an interface), provide
* a string representation of the source code for that class, but containing
* only the public method signatures. All non-public members are removed,
* as are all method bodies.
*
* @param aClass the class to abbreviate
* @param collector will contain the public methods as a formatted block
* @return the number of public members in the result
*/
int abbreviate(JavaClass aClass, StringBuffer collector);
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/ClassAbbreviatorImpl.java
Index: ClassAbbreviatorImpl.java
===================================================================
package org.componenthaus.ant;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.AbstractJavaEntity;
import com.thoughtworks.qdox.model.JavaParameter;
import com.thoughtworks.qdox.model.Type;
import com.thoughtworks.qdox.model.DocletTag;
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
import java.util.Iterator;
public class ClassAbbreviatorImpl implements ClassAbbreviator {
private static final String JAVA_LANG_PACKAGE = "java.lang.";
private static final String DOT = ".";
private final JavadocFormatter javadocFormatter;
private final LineIndenter indenter;
public ClassAbbreviatorImpl(JavadocFormatter javadocFormatter, LineIndenter indenter) {
this.javadocFormatter = javadocFormatter;
this.indenter = indenter;
}
public int abbreviate(JavaClass aClass, StringBuffer collector) {
if (aClass.isInterface()) {
throw new NotAClassException(aClass.getFullyQualifiedName());
}
if (!aClass.isPublic()) {
throw new NotPublicException(aClass.getFullyQualifiedName());
}
Set importsCollector = new HashSet();
StringBuffer bodyCollector = new StringBuffer();
int publicMethodCount = 0;
JavaMethod[] methods = aClass.getMethods();
for (int i = 0; i < methods.length; i++) {
JavaMethod method = methods[i];
if (method.isPublic()) {
if (publicMethodCount > 0) {
bodyCollector.append("\n");
}
System.out.println("About to call method text on method " + method.getName());
bodyCollector.append(createMethodText(method, importsCollector));
publicMethodCount++;
}
}
System.out.println("About to do package text");
collector.append(createPackageText(aClass));
System.out.println("About to do imports text");
collector.append(createImportsText(importsCollector));
System.out.println("About to do class begnnning text");
collector.append(createClassBeginningText(aClass));
System.out.println("About to do body text");
collector.append(bodyCollector);
collector.append("}");
return publicMethodCount;
}
private String createPackageText(JavaClass aClass) {
return "package " + aClass.getPackage() + ";\n\n";
}
private String createImportsText(Collection imports) {
StringBuffer result = new StringBuffer();
for (Iterator i = imports.iterator(); i.hasNext();) {
result.append("import ").append(i.next()).append(";\n");
}
result.append("\n");
return result.toString();
}
private String createMethodText(JavaMethod method, Collection importsCollector) {
final StringBuffer result = new StringBuffer();
String unformattedJavadoc = "";
if (method.getComment() != null) {
unformattedJavadoc = method.getComment() + "\n";
}
if (method.getTags().length != 0) {
unformattedJavadoc += createJavadocTagsText(method.getTags());
}
if (unformattedJavadoc.length() > 0) {
final String javadoc = javadocFormatter.format(unformattedJavadoc);
result.append(indenter.indent(javadoc, 1)).append("\n");
}
result.append("\t");
appendModifiers(method, result);
result.append(getType(method.getReturns(), importsCollector)).append(" ");
result.append(method.getName()).append("(");
result.append(createParameterListText(method, importsCollector));
result.append(")");
if (method.getExceptions().length > 0) {
result.append(" throws ");
result.append(createExceptionDeclarationText(method, importsCollector));
}
result.append(";\n");
return result.toString();
}
private String createJavadocTagsText(DocletTag[] tags) {
System.out.println("Entering createjavadoctagstext");
StringBuffer result = new StringBuffer();
for (int i = 0; i < tags.length; i++) {
DocletTag tag = tags[i];
System.out.println("Working on tag " + tag.getName());
result.append("@").append(tag.getName());
System.out.println("Appended name");
final String[] params = tag.getParameters();
System.out.println("Num params " + params.length);
for (int j = 0; j < params.length; j++) {
System.out.println("Working on param " + params[j]);
//TODO remove this check for * when QDox is fixed - it includes the * here for some reason
if (!"*".equals(params[j])) {
result.append(" ");
result.append(params[j]);
}
}
System.out.println("Finished with params");
//result.append(" ").append(tag.getValue()).append("\n");
result.append("\n");
}
System.out.println("Leaving createjavadoctagstext");
return result.toString();
}
private String createExceptionDeclarationText(JavaMethod method, Collection importsCollector) {
StringBuffer result = new StringBuffer();
Type[] exceptions = method.getExceptions();
for (int i = 0; i < exceptions.length; i++) {
Type exception = exceptions[i];
if (i > 0) {
result.append(", ");
}
result.append(getType(exception, importsCollector));
}
return result.toString();
}
private String getType(Type type, Collection importsCollector) {
final String fullTypeName = type.getValue();
String result = fullTypeName;
if (!fullTypeName.startsWith(JAVA_LANG_PACKAGE)) {
importsCollector.add(fullTypeName);
}
int indexOfLastDot = fullTypeName.lastIndexOf(DOT);
if (indexOfLastDot != -1) {
result = fullTypeName.substring(indexOfLastDot + 1);
}
return result;
}
private String createParameterListText(JavaMethod method, Collection importsCollector) {
JavaParameter[] parameters = method.getParameters();
StringBuffer result = new StringBuffer();
for (int i = 0; i < parameters.length; i++) {
JavaParameter parameter = parameters[i];
if (i > 0) {
result.append(", ");
}
result.append(getType(parameter.getType(), importsCollector)).append(" ").append(parameter.getName());
}
return result.toString();
}
private String createClassBeginningText(JavaClass aClass) {
final StringBuffer result = new StringBuffer();
if ( aClass.getComment() != null) {
result.append(javadocFormatter.format(aClass.getComment())).append("\n");
}
appendModifiers(aClass, result);
result.append("class ");
result.append(aClass.getName()).append(" {\n");
return result.toString();
}
private void appendModifiers(AbstractJavaEntity entity, final StringBuffer result) {
final String[] modifiers = entity.getModifiers();
for (int i = 0; i < modifiers.length; i++) {
result.append(modifiers[i]).append(" ");
}
}
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/JavadocFormatter.java
Index: JavadocFormatter.java
===================================================================
package org.componenthaus.ant;
public interface JavadocFormatter {
String format(String javadoc);
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/JavadocFormatterImpl.java
Index: JavadocFormatterImpl.java
===================================================================
package org.componenthaus.ant;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
public class JavadocFormatterImpl implements JavadocFormatter {
private static final int LENGTH_OF_A_SPACE_CHARACTER = 1;
private static final Collection wordsRequiringNewline = new ArrayList();
private final int maxLineLength;
static {
wordsRequiringNewline.add("@param");
wordsRequiringNewline.add("@return");
wordsRequiringNewline.add("@throws");
wordsRequiringNewline.add("@version");
wordsRequiringNewline.add("@author");
}
public JavadocFormatterImpl(int maxLineLength) {
this.maxLineLength = maxLineLength;
}
public String format(String javadoc) {
String result = javadoc;
if ( javadoc != null && javadoc.length() != 0) {
result = formatJavadoc(javadoc);
}
return result;
}
private String formatJavadoc(String javadoc) {
final StringBuffer result = new StringBuffer("/**\n");
final List words = new ArrayList(Arrays.asList(javadoc.split("\\s")));
final String commentPrefix = " * ";
final int commentTextLength = maxLineLength - commentPrefix.length();
boolean firstNewLineWord = true;
while ( words.size() > 0 ) {
if ( isNewlineWord((String) words.get(0)) && firstNewLineWord) {
result.append(commentPrefix).append("\n");
firstNewLineWord = false;
}
String line = commentPrefix + createLineText(words, commentTextLength) + "\n";
result.append(line);
}
result.append(" **/");
return result.toString();
}
private String createLineText(List words, int commentTextLength) {
final StringBuffer result = new StringBuffer();
while(canAddAnotherWord(result,words, commentTextLength)) {
addAnotherWord(result,words);
}
if ( result.length() == 0 ) {
addAnotherWord(result,words);
}
return result.toString();
}
private void addAnotherWord(StringBuffer result, List words) {
if ( result.length() > 0 ) {
result.append(" ");
}
result.append(words.remove(0));
}
private boolean canAddAnotherWord(StringBuffer current, List words, int maxLength) {
boolean result = false;
if ( words.size() > 0 ) {
String nextWord = (String) words.get(0);
if ( isNewlineWord(nextWord) ) {
result = current.length() == 0;
} else {
int nextLength = current.length() + nextWord.length() + LENGTH_OF_A_SPACE_CHARACTER;
result = nextLength < maxLength;
}
}
return result;
}
private boolean isNewlineWord(String word) {
return wordsRequiringNewline.contains(word);
}
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/LineIndenter.java
Index: LineIndenter.java
===================================================================
package org.componenthaus.ant;
public interface LineIndenter {
String indent(String lines, int numIndents);
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/LineIndenterImpl.java
Index: LineIndenterImpl.java
===================================================================
package org.componenthaus.ant;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.IOException;
public class LineIndenterImpl implements LineIndenter {
private static final String END_LINE = "\n";
private static final String TAB = "\t";
public String indent(String lines, int numIndents) {
String result = lines;
if ( lines != null && lines.length() > 0 && numIndents > 0 ) {
try {
result = indentLines(lines, numIndents);
} catch (IOException e) {
throw new RuntimeException("Got an IOException reading strings", e);
}
}
return result;
}
private String indentLines(String lines, int numIndents) throws IOException {
StringBuffer result = new StringBuffer();
final String indent = createIndentText(numIndents);
BufferedReader reader = new BufferedReader(new StringReader(lines));
String line = reader.readLine();
while ( line != null ) {
if ( result.length() > 0 ) {
result.append(END_LINE);
}
result.append(indent).append(line);
line = reader.readLine();
}
reader.close();
return result.toString();
}
private String createIndentText(int numIndents) {
String result = "";
for(int i=0;i<numIndents;i++) {
result += TAB;
}
return result;
}
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NotAClassException.java
Index: NotAClassException.java
===================================================================
package org.componenthaus.ant;
public class NotAClassException extends RuntimeException {
private String name;
public NotAClassException(String name) {
super("Not a class " + name);
this.name = name;
}
public String getName() {
return name;
}
}
1.1 spice/sandbox/repository/componenthaus/src/java/org/componenthaus/ant/NotPublicException.java
Index: NotPublicException.java
===================================================================
package org.componenthaus.ant;
public class NotPublicException extends RuntimeException {
private final String fullyQualifiedName;
public NotPublicException(String fullyQualifiedName) {
super("Class " + fullyQualifiedName + " is not public");
this.fullyQualifiedName = fullyQualifiedName;
}
public String getFullyQualifiedName() {
return fullyQualifiedName;
}
}
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/