User: ara_e_w
Date: 02/02/22 14:50:28
Modified: src/xjavadoc AbstractClass.java BinaryClass.java
ProxyClass.java SourceClass.java XClass.java
XJavaDoc.java XJavaDocTest.java
Log:
- all map/arraylist lazy instantiated
- Use a single array if possible, no arraylist used, also moved
importedpackage/classes list to JavaParser
- getMethod()'s signature changed
Revision Changes Path
1.5 +215 -115 xjavadoc/src/xjavadoc/AbstractClass.java
Index: AbstractClass.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractClass.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- AbstractClass.java 22 Feb 2002 18:14:49 -0000 1.4
+++ AbstractClass.java 22 Feb 2002 22:50:27 -0000 1.5
@@ -53,83 +53,73 @@
/**
* @todo-javadoc Describe the field
*/
- protected ArrayList _importedClasses = new ArrayList();
-
+ protected Object[] _ximportedClasses;
/**
* @todo-javadoc Describe the field
*/
- protected ArrayList _importedPackages = new ArrayList();
+ protected Object[] _ximportedPackages;
/**
* @todo-javadoc Describe the field
*/
- private ArrayList _constructors = new ArrayList();
- /**
- * @todo-javadoc Describe the field
- */
- private XConstructor[] _xconstructors;
- /**
- * @todo-javadoc Describe the field
- */
- private XClass[] _ximportedClasses;
+ protected XConstructor[] _xconstructors;
/**
- * @todo-javadoc Describe the field
+ * The same Object[] is used to store the literal form of interfaces and it's
+ * converted/qualified to XClass[] on first use!
*/
- private boolean _isInterface;
-
+ protected Object[] _xinterfaces;
/**
* @todo-javadoc Describe the field
*/
- private String _superclass;
+ private ArrayList _constructors;
/**
* @todo-javadoc Describe the field
*/
- private XClass[] _xinterfaces;
-
+ private XMethod[] _xmethods;
/**
* @todo-javadoc Describe the field
*/
- private XMethod[] _xmethods;
+ private ArrayList _methods;
/**
* @todo-javadoc Describe the field
*/
private XField[] _xfields;
-
/**
* @todo-javadoc Describe the field
*/
- private HashSet _interfaces = new HashSet();
+ private ArrayList _fields;
/**
* @todo-javadoc Describe the field
*/
- private HashMap _innerClasses = new HashMap();
+ private HashMap _innerClasses;
/**
* @todo-javadoc Describe the field
*/
- private ArrayList _methods = new ArrayList();
+ private boolean _isInterface;
+
/**
* @todo-javadoc Describe the field
*/
- private HashMap _namedMethods = new HashMap();
+ private String _superclass;
/**
* @todo-javadoc Describe the field
*/
- private ArrayList _fields = new ArrayList();
+ private String _containingPackage = "";
+
/**
* @todo-javadoc Describe the field
*/
- private HashMap _namedFields = new HashMap();
-
+ protected final static XClass[] NULL_CLASSES = new XClass[0];
/**
* @todo-javadoc Describe the field
*/
- private String _containingPackage = "";
+ protected final static XConstructor[] NULL_CONSTRUCTORS = new XConstructor[0];
/**
* Get static reference to Log4J Logger
@@ -186,6 +176,57 @@
/**
+ * Sets the ImportedClasses attribute of the AbstractClass object
+ *
+ * @param imported_classes The new ImportedClasses value
+ */
+ public void setImportedClasses(String[] imported_classes) {
+ _ximportedClasses = imported_classes;
+ }
+
+
+ /**
+ * Sets the ImportedPackages attribute of the AbstractClass object
+ *
+ * @param imported_packages The new ImportedPackages value
+ */
+ public void setImportedPackages(String[] imported_packages) {
+ _ximportedPackages = imported_packages;
+ }
+
+
+ /**
+ * Describe the method
+ *
+ * @param nameList Describe the method parameter
+ * @todo-javadoc Describe the method
+ * @todo-javadoc Describe the method parameter
+ */
+ public final void setInterfaces(String nameList) {
+ StringTokenizer st = new StringTokenizer(nameList, ",");
+
+ _xinterfaces = new Object[st.countTokens()];
+
+ int i = 0;
+ while (st.hasMoreTokens()) {
+ _xinterfaces[i] = st.nextToken();
+ i++;
+ }
+
+ /*
+ * XClass interfaze = qualify(implementedInterface);
+ * _interfaces.add(interfaze);
+ * _interfaces.addAll(Arrays.asList(interfaze.interfaces()));
+ * /_log.debug("ADD INTERFACE: " + implementedInterface + " to " +
qualifiedName());
+ * /_log.debug("-------------> " + interfaze.qualifiedName());
+ * for (int i = interfaze.interfaces().length - 1; i >= 0; i--) {
+ * /_log.debug("-------------> " +
interfaze.interfaces()[i].qualifiedName());
+ * }
+ */
+ }
+
+
+ /**
* Gets the Interface attribute of the SourceClass object
*
* @return The Interface value
@@ -219,29 +260,61 @@
/**
- * Returns an XMethod with the given signature. The methodWithSignature must
- * not contain any spaces. <P>
- *
- * Example: getMethod("hello(java.lang.String,int)");
+ * Returns an XMethod with the given name and parameters. Because we're not
+ * going to call this method quite often there's no need for a Map-backed list
+ * of methods. Example: getMethod("hello",new
+ * String[]{"java.lang.String","int"});
*
- * @param methodWithSignature Describe what the parameter does
+ * @param methodName Describe what the parameter does
+ * @param parameters Describe what the parameter does
* @return The Method value
* @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
*/
- public final XMethod getMethod(String methodWithSignature) {
- return (XMethod)_namedMethods.get(methodWithSignature);
+ public final XMethod getMethod(String methodName, String[] parameters) {
+
+ if (_methods == null) {
+ return null;
+ }
+
+ for (int i = 0; i < _methods.size(); i++) {
+ XMethod method = (XMethod)_methods.get(i);
+
+ if (method.name().equals(methodName)) {
+ XParameter[] method_params = method.parameters();
+
+ if ((parameters == null && method_params.length == 0)
|| Arrays.equals(parameters, method_params) == true) {
+ return method;
+ }
+ }
+ }
+
+ return null;
}
/**
* Returns an XField with the given name. Example: getField("id");
*
- * @param name Describe what the parameter does
+ * @param filedName Describe what the parameter does
* @return The Field value
* @todo-javadoc Write javadocs for method parameter
*/
- public final XField getField(String name) {
- return (XField)_namedFields.get(name);
+ public final XField getField(String filedName) {
+
+ if (_fields == null) {
+ return null;
+ }
+
+ for (int i = 0; i < _fields.size(); i++) {
+ XField field = (XField)_fields.get(i);
+
+ if (field.name().equals(filedName)) {
+ return field;
+ }
+ }
+
+ return null;
}
@@ -270,44 +343,16 @@
* @todo-javadoc Write javadocs for return value
*/
public final XClass[] importedClasses() {
- if (_ximportedClasses == null) {
- _ximportedClasses = new XClass[_importedClasses.size()];
- Iterator iter = _importedClasses.iterator();
- int i = 0;
- while (iter.hasNext()) {
-// String imported_class_str = (String)iter.next();
+ for (int i = 0; i < _ximportedClasses.length; i++) {
+ Object imported_class = _ximportedClasses[i];
-// _ximportedClasses[i] = qualify(imported_class_str);
- i++;
+ if (imported_class instanceof String) {
+ _ximportedClasses[i] = qualify((String)imported_class);
}
}
- return _ximportedClasses;
- }
-
-
- /**
- * Describe the method
- *
- * @param importedClass Describe the method parameter
- * @todo-javadoc Describe the method
- * @todo-javadoc Describe the method parameter
- */
- public final void addImportedClass(String importedClass) {
- _importedClasses.add(importedClass);
- }
-
-
- /**
- * Describe the method
- *
- * @param packageName Describe the method parameter
- * @todo-javadoc Describe the method
- * @todo-javadoc Describe the method parameter
- */
- public final void addImportedPackage(String packageName) {
- _importedPackages.add(packageName);
+ return (XClass[])_ximportedClasses;
}
@@ -319,12 +364,19 @@
* @todo-javadoc Write javadocs for return value
*/
public final XPackage[] importedPackages() {
- XPackage[] importedPackages = new XPackage[_importedPackages.size()];
- for (int i = 0; i < importedPackages.length; i++) {
- String packageName = (String)_importedPackages.get(i);
- importedPackages[i] =
XJavaDoc.getInstance().addPackageMaybe(packageName);
+
+ if (_ximportedPackages == null) {
+
+ for (int i = 0; i < _ximportedPackages.length; i++) {
+ Object imported_package = _ximportedPackages[i];
+
+ if (imported_package instanceof String) {
+ _ximportedPackages[i] =
XJavaDoc.getInstance().addPackageMaybe((String)imported_package);
+ }
}
- return importedPackages;
+ }
+
+ return (XPackage[])_ximportedPackages;
}
@@ -352,10 +404,12 @@
* @todo-javadoc Write javadocs for return value
*/
public final XField[] fields() {
+
if (_xfields == null) {
_xfields = new XField[_fields.size()];
_xfields = (XField[])_fields.toArray(_xfields);
}
+
return _xfields;
}
@@ -370,16 +424,27 @@
* @return the constructors.
*/
public final XConstructor[] constructors() {
+ if (_constructors == null) {
+ return NULL_CONSTRUCTORS;
+ }
+
+ if (_xconstructors == null) {
+
+ //Aslak:
// Classic Javadoc reports a default constructor even if it is not
defined
// in the source. We'll do that too. Add it if none are defined
provided we're
// not abstract or interface
- if (_xconstructors == null) {
+ //Ara: I disagree. We're in business of code
generation/mutation unlike javadoc which is in business of docs.
+ // We should be accurate. We also support code mutation. How
are you going to mutate a nonexisting constructor?
+
// if (_constructors.size() == 0 && !isInterface() &&
!isAbstract()) {
// _constructors.add(new SourceConstructor(this));
// }
+
_xconstructors = new XConstructor[_constructors.size()];
_xconstructors =
(XConstructor[])_constructors.toArray(_xconstructors);
}
+
return _xconstructors;
}
@@ -393,16 +458,19 @@
*/
public final XClass[] interfaces() {
if (_xinterfaces == null) {
- _xinterfaces = new XClass[_interfaces.size()];
- Iterator iter = _interfaces.iterator();
- int i = 0;
- while (iter.hasNext()) {
- String intf_str = (String)iter.next();
- _xinterfaces[i] = qualify(intf_str);
- i++;
+ return NULL_CLASSES;
+ }
+
+ //elements of the array may be Strings so iterate and convert them to
XClass
+ for (int i = 0; i < _xinterfaces.length; i++) {
+ Object xinterface = _xinterfaces[i];
+
+ if (xinterface instanceof String) {
+ _xinterfaces[i] = qualify((String)xinterface);
}
}
- return _xinterfaces;
+
+ return (XClass[])_xinterfaces;
}
@@ -414,9 +482,7 @@
* @todo-javadoc Describe the method parameter
*/
public final void addMethod(XMethod method) {
- _methods.add(method);
- String methodWithSignature = new
StringBuffer(method.name()).append(method.signature()).toString();
- _namedMethods.put(methodWithSignature, method);
+ getMethods().add(method);
}
@@ -428,8 +494,7 @@
* @todo-javadoc Describe the method parameter
*/
public final void addField(XField field) {
- _fields.add(field);
- _namedFields.put(field.name(), field);
+ getFields().add(field);
}
@@ -441,7 +506,7 @@
* @todo-javadoc Describe the method parameter
*/
public final void addConstructor(XConstructor constructor) {
- _constructors.add(constructor);
+ getConstructors().add(constructor);
}
@@ -464,28 +529,6 @@
/**
- * Describe the method
- *
- * @param implementedInterface Describe the method parameter
- * @todo-javadoc Describe the method
- * @todo-javadoc Describe the method parameter
- */
- public final void addInterface(String implementedInterface) {
- _interfaces.add(implementedInterface);
- /*
- * XClass interfaze = qualify(implementedInterface);
- * _interfaces.add(interfaze);
- * _interfaces.addAll(Arrays.asList(interfaze.interfaces()));
- * /_log.debug("ADD INTERFACE: " + implementedInterface + " to " +
qualifiedName());
- * /_log.debug("-------------> " + interfaze.qualifiedName());
- * for (int i = interfaze.interfaces().length - 1; i >= 0; i--) {
- * /_log.debug("-------------> " +
interfaze.interfaces()[i].qualifiedName());
- * }
- */
- }
-
-
- /**
* Describe what the method does
*
* @param rootDir Describe what the parameter does
@@ -586,5 +629,62 @@
public XClass qualify(String unqualifiedClassName) {
// returns a proxy if the class isn't already loaded
return XJavaDoc.getInstance().getXClass(unqualifiedClassName, true);
+ }
+
+
+ /**
+ * Gets the Constructors attribute of the AbstractClass object
+ *
+ * @return The Constructors value
+ */
+ protected ArrayList getConstructors() {
+
+ if (_constructors == null) {
+ _constructors = new ArrayList();
+ }
+
+ return _constructors;
+ }
+
+
+ /**
+ * Gets the Fields attribute of the AbstractClass object
+ *
+ * @return The Fields value
+ */
+ protected ArrayList getFields() {
+ if (_fields == null) {
+ _fields = new ArrayList();
+ }
+
+ return _fields;
+ }
+
+
+ /**
+ * Gets the InnerClasses attribute of the AbstractClass object
+ *
+ * @return The InnerClasses value
+ */
+ protected HashMap getInnerClasses() {
+ if (_innerClasses == null) {
+ _innerClasses = new HashMap();
+ }
+
+ return _innerClasses;
+ }
+
+
+ /**
+ * Gets the Methods attribute of the AbstractClass object
+ *
+ * @return The Methods value
+ */
+ protected ArrayList getMethods() {
+ if (_methods == null) {
+ _methods = new ArrayList();
+ }
+
+ return _methods;
}
}
1.4 +1 -4 xjavadoc/src/xjavadoc/BinaryClass.java
Index: BinaryClass.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/BinaryClass.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- BinaryClass.java 22 Feb 2002 20:22:31 -0000 1.3
+++ BinaryClass.java 22 Feb 2002 22:50:27 -0000 1.4
@@ -110,10 +110,7 @@
* @todo-javadoc Write javadocs for return value
*/
private void setInterfaces(Class clazz) {
- Class[] interfaces = clazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- addInterface(interfaces[i].getName());
- }
+ _xinterfaces = clazz.getInterfaces();
}
1.4 +4 -2 xjavadoc/src/xjavadoc/ProxyClass.java
Index: ProxyClass.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ProxyClass.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- ProxyClass.java 22 Feb 2002 18:14:49 -0000 1.3
+++ ProxyClass.java 22 Feb 2002 22:50:27 -0000 1.4
@@ -145,12 +145,14 @@
* Gets the Method attribute of the ProxyClass object
*
* @param method Describe what the parameter does
+ * @param parameters Describe what the parameter does
* @return The Method value
* @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
*/
- public XMethod getMethod(String method) {
+ public XMethod getMethod(String method, String[] parameters) {
resolve();
- return _subject.getMethod(method);
+ return _subject.getMethod(method, null);
}
1.5 +57 -7 xjavadoc/src/xjavadoc/SourceClass.java
Index: SourceClass.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/SourceClass.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- SourceClass.java 22 Feb 2002 20:22:30 -0000 1.4
+++ SourceClass.java 22 Feb 2002 22:50:27 -0000 1.5
@@ -74,7 +74,6 @@
*/
public SourceClass(XClass containingClass, String qualifiedName) {
super(containingClass, qualifiedName);
- addImportedPackage("java.lang");
}
@@ -157,6 +156,7 @@
result =
isUnqualifiedNameInImportedClasses(unqualifiedClassName, result);
result =
isUnqualifiedNameInImportedPackages(unqualifiedClassName, result);
result =
isUnqualifiedNameInTheSamePackage(unqualifiedClassName, result);
+ result =
isUnqualifiedNameInJavaLangPackage(unqualifiedClassName, result);
}
if (result == null) {
// We'll get here when we use inner classes and nonexisting
classes
@@ -201,10 +201,21 @@
* @todo-javadoc Write javadocs for method parameter
*/
private XClass isUnqualifiedNameInImportedClasses(String unqualifiedClassName,
XClass result) {
- Iterator c = _importedClasses.iterator();
+
+ if (_ximportedClasses == null) {
+ return result;
+ }
+
String suffix = "." + unqualifiedClassName;
- while (c.hasNext()) {
- String imported_class_str = (String)c.next();
+
+ for (int i = 0; i < _ximportedClasses.length; i++) {
+ String imported_class_str = (String)_ximportedClasses[i];
+
+ //if( imported_class_str instanceof String )
+ // imported_class_str = (String)ximportedClass;
+ //else
+ // imported_class_str = ((XClass)ximportedClass).name();
+
if (imported_class_str.endsWith(suffix)) {
// We've found a candidate
XClass clazz =
XJavaDoc.getInstance().getXClass(imported_class_str, true);
@@ -220,6 +231,7 @@
}
}
}
+
return result;
}
@@ -235,18 +247,33 @@
* @todo-javadoc Write javadocs for method parameter
*/
private XClass isUnqualifiedNameInImportedPackages(String
unqualifiedClassName, XClass result) {
- Iterator i = _importedPackages.iterator();
- while (i.hasNext()) {
- String importedPackageName = (String)i.next();
+
+ if (_ximportedPackages == null) {
+ return result;
+ }
+
+ String suffix = "." + unqualifiedClassName;
+
+ for (int i = 0; i < _ximportedPackages.length; i++) {
+ String importedPackageName = (String)_ximportedPackages[i];
+
+ //if( imported_class_str instanceof String )
+ // importedPackageName = (String)ximportedClass;
+ //else
+ // importedPackageName = ((XClass)ximportedClass).name();
+
String qualifiedClassName = importedPackageName + "." +
unqualifiedClassName;
XClass clazz =
XJavaDoc.getInstance().getXClass(qualifiedClassName, true);
+
if (result != null && clazz != null) {
throw new IllegalStateException("Ambiguous class:" +
unqualifiedClassName);
}
+
if (clazz != null) {
result = clazz;
}
}
+
return result;
}
@@ -262,6 +289,29 @@
*/
private XClass isUnqualifiedNameInTheSamePackage(String unqualifiedClassName,
XClass result) {
String qualifiedClassName = containingPackage().name() + "." +
unqualifiedClassName;
+ XClass clazz = XJavaDoc.getInstance().getXClass(qualifiedClassName,
true);
+ if (result != null && clazz != null) {
+ throw new IllegalStateException("Ambiguous class:" +
unqualifiedClassName);
+ }
+ if (clazz != null) {
+ result = clazz;
+ }
+ return result;
+ }
+
+
+ /**
+ * Gets the UnqualifiedNameInJavaLangPackage attribute of the SourceClass
+ * object
+ *
+ * @param unqualifiedClassName Describe what the parameter does
+ * @param result Describe what the parameter does
+ * @return The UnqualifiedNameInJavaLangPackage value
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
+ */
+ private XClass isUnqualifiedNameInJavaLangPackage(String unqualifiedClassName,
XClass result) {
+ String qualifiedClassName = "java.lang." + unqualifiedClassName;
XClass clazz = XJavaDoc.getInstance().getXClass(qualifiedClassName,
true);
if (result != null && clazz != null) {
throw new IllegalStateException("Ambiguous class:" +
unqualifiedClassName);
1.14 +6 -3 xjavadoc/src/xjavadoc/XClass.java
Index: XClass.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XClass.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- XClass.java 22 Feb 2002 18:14:49 -0000 1.13
+++ XClass.java 22 Feb 2002 22:50:27 -0000 1.14
@@ -47,13 +47,16 @@
public interface XClass extends XProgramElement {
/**
- * Gets the Method attribute of the XClass object
+ * Returns an XMethod with the given name and parameters. Example:
+ * getMethod("hello",new String[]{"java.lang.String","int"});
*
- * @param method Describe what the parameter does
+ * @param methodName Describe what the parameter does
+ * @param parameters Describe what the parameter does
* @return The Method value
* @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
*/
- public XMethod getMethod(String method);
+ public XMethod getMethod(String methodName, String[] parameters);
/**
1.14 +7 -3 xjavadoc/src/xjavadoc/XJavaDoc.java
Index: XJavaDoc.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDoc.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- XJavaDoc.java 22 Feb 2002 20:22:30 -0000 1.13
+++ XJavaDoc.java 22 Feb 2002 22:50:27 -0000 1.14
@@ -188,13 +188,16 @@
* Describe what the method does
*
* @param className Describe what the parameter does
- * @param methodWithSignature Describe what the parameter does
* @param tagName Describe what the parameter does
* @param parameterName Describe what the parameter does
* @param parameterValue Describe what the parameter does
* @param tagIndex Describe what the parameter does
+ * @param methodName Describe what the parameter does
+ * @param parameters Describe what the parameter does
* @return Describe the return value
* @exception XJavaDocException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method parameter
@@ -207,14 +210,15 @@
*/
public XClass updateMethodTag(
String className,
- String methodWithSignature,
+ String methodName,
+ String[] parameters,
String tagName,
String parameterName,
String parameterValue,
int tagIndex
) throws XJavaDocException {
XClass clazz = getXClass(className, false);
- XMethod method = clazz.getMethod(methodWithSignature);
+ XMethod method = clazz.getMethod(methodName, parameters);
XDoc doc = method.doc();
doc.updateTagValue(tagName, parameterName, parameterValue, tagIndex);
return clazz;
1.12 +2 -1 xjavadoc/src/xjavadoc/XJavaDocTest.java
Index: XJavaDocTest.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDocTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -r1.11 -r1.12
--- XJavaDocTest.java 22 Feb 2002 18:14:49 -0000 1.11
+++ XJavaDocTest.java 22 Feb 2002 22:50:27 -0000 1.12
@@ -237,7 +237,8 @@
XClass clazz;
clazz = XJavaDoc.getInstance().updateMethodTag(
"Hello",
- "noComment()",
+ "noComment",
+ null,
"here",
"is",
"a tag for ya",
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel