leosutic 2004/01/29 07:42:38
Modified: attributes/compiler/src/java/org/apache/commons/attributes/compiler
AttributeCompiler.java
Log:
Implemented better way of finding source files for classes.
Revision Changes Path
1.12 +33 -29
jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java
Index: AttributeCompiler.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AttributeCompiler.java 26 Jan 2004 20:07:57 -0000 1.11
+++ AttributeCompiler.java 29 Jan 2004 15:42:37 -0000 1.12
@@ -31,6 +31,7 @@
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
+import xjavadoc.SourceClass;
import xjavadoc.XClass;
import xjavadoc.XConstructor;
import xjavadoc.XJavaDoc;
@@ -40,6 +41,7 @@
import xjavadoc.XProgramElement;
import xjavadoc.XTag;
import xjavadoc.ant.XJavadocTask;
+import xjavadoc.filesystem.AbstractFile;
/**
* Ant task to compile attributes. Usage:
@@ -112,12 +114,12 @@
}
}
- protected void addExpressions (Collection tags, PrintWriter pw, String
collectionName, String fileName) {
- addExpressions (tags, null, pw, collectionName, fileName);
+ protected void addExpressions (Collection tags, PrintWriter pw, String
collectionName, File sourceFile) {
+ addExpressions (tags, null, pw, collectionName, sourceFile);
}
- protected void addExpressions (Collection tags, String selector, PrintWriter
pw, String collectionName, String fileName) {
- fileName = fileName.replace ('\\', '/');
+ protected void addExpressions (Collection tags, String selector, PrintWriter
pw, String collectionName, File sourceFile) {
+ String fileName = sourceFile != null ? sourceFile.getPath ().replace ('\\',
'/') : "<unknown>";
Iterator iter = tags.iterator ();
while (iter.hasNext ()) {
XTag tag = (XTag) iter.next ();
@@ -228,18 +230,21 @@
if (xClass.isInner ()) {
name = xClass.getQualifiedName ().substring (packageName.length ());
- StringTokenizer tok = new StringTokenizer (name, ".");
- String outermostClass = packageName + (packageName.length () > 0 ? "."
: "") + tok.nextToken ();
- sourceFile = getSourceFile (outermostClass);
+
+ sourceFile = getSourceFile (xClass);
className = xClass.getName ().replace ('.', '$');
name = packageName + (packageName.length () > 0 ? "." : "") +
className;
} else {
name = xClass.getQualifiedName ();
- sourceFile = getSourceFile (name);
+ sourceFile = getSourceFile (xClass);
className = xClass.getName ();
}
+ if (sourceFile == null) {
+ log ("Unable to find source file for: " + name);
+ }
+
destFile = new File (destDir, name.replace ('.', '/') +
"$__attributeRepository.java");
if (xClass.isAnonymous ()) {
@@ -254,7 +259,7 @@
return;
}
- if (destFile.exists () && destFile.lastModified () >=
sourceFile.lastModified ()) {
+ if (destFile.exists () && sourceFile != null && destFile.lastModified () >=
sourceFile.lastModified ()) {
return;
}
@@ -264,13 +269,13 @@
destFile.getParentFile ().mkdirs ();
PrintWriter pw = new PrintWriter (new FileWriter (destFile));
try {
-
-
if (packageName != null && !packageName.equals ("")) {
pw.println ("package " + packageName + ";");
}
- copyImports (sourceFile, pw);
+ if (sourceFile != null) {
+ copyImports (sourceFile, pw);
+ }
StringTokenizer tok = new StringTokenizer (attributePackages, ";");
while (tok.hasMoreTokens ()) {
@@ -300,7 +305,7 @@
pw.println ();
pw.println (" private void initClassAttributes () {");
- addExpressions (xClass.getDoc ().getTags (), pw, "classAttributes",
sourceFile.getPath ());
+ addExpressions (xClass.getDoc ().getTags (), pw, "classAttributes",
sourceFile);
pw.println (" }");
pw.println ();
@@ -314,7 +319,7 @@
String key = member.getName ();
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), pw, "attrs",
sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (), pw, "attrs",
sourceFile);
pw.println (" fieldAttributes.put (\"" + key + "\",
attrs);");
pw.println (" attrs = null;");
pw.println ();
@@ -338,19 +343,19 @@
pw.println (" bundle = new java.util.ArrayList ();");
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile);
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), "return", pw,
"attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (), "return", pw,
"attrs", sourceFile);
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
for (Iterator parameters = member.getParameters ().iterator
(); parameters.hasNext ();) {
XParameter parameter = (XParameter) parameters.next ();
pw.println (" attrs = new java.util.HashSet
();");
- addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile);
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
}
@@ -379,14 +384,14 @@
pw.println (" bundle = new java.util.ArrayList ();");
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile);
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
for (Iterator parameters = member.getParameters ().iterator
(); parameters.hasNext ();) {
XParameter parameter = (XParameter) parameters.next ();
pw.println (" attrs = new java.util.HashSet
();");
- addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile);
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
}
@@ -415,17 +420,16 @@
* @return the file the class is defined in.
* @throws BuildException if the file could not be found.
*/
- protected File getSourceFile (String qualifiedName) throws BuildException {
- String path = qualifiedName.replace ('.', '/') + ".java";
- Iterator iter = fileSets.iterator ();
- while (iter.hasNext ()) {
- FileSet fs = (FileSet) iter.next ();
- File maybe = new File (fs.getDir (project), path);
- if (maybe.exists ()) {
- return maybe;
- }
+ protected File getSourceFile (XClass xClass) throws BuildException {
+ while (xClass != null && xClass.isInner ()) {
+ xClass = xClass.getContainingClass ();
+ }
+
+ if (xClass != null && xClass instanceof SourceClass) {
+ AbstractFile af = ((SourceClass) xClass).getFile ();
+ return new File (af.getPath ());
}
- throw new BuildException ("Could not find source file for " +
qualifiedName);
+ return null;
}
protected boolean hasAttributes (XClass xClass) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]