User: rinkrank Date: 02/10/18 07:50:18 Modified: src/xjavadoc Tag: XDOCLET_2_0 AbstractClass.java CodeTest.java SourceClass.java Util.java XJavaDoc.java XJavaDocTest.java Log: Simplified XJavadoc API -passing qualifiedName to SourceClass no longer needed, it's discovered during parse (it wasn't before) -deprecated all methods that pass qualifiedName -deprecated methods that pass useNodeParser. This must be set prior to parsing with XJavaDoc.setUseNodeParser(boolean) -Simplified CodeTestCase API, only takes File as argument Revision Changes Path No revision No revision 1.52.2.3 +62 -182 xjavadoc/src/xjavadoc/AbstractClass.java Index: AbstractClass.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractClass.java,v retrieving revision 1.52.2.2 retrieving revision 1.52.2.3 diff -u -w -r1.52.2.2 -r1.52.2.3 --- AbstractClass.java 16 Oct 2002 23:06:30 -0000 1.52.2.2 +++ AbstractClass.java 18 Oct 2002 14:50:17 -0000 1.52.2.3 @@ -16,8 +16,7 @@ * * @author Ara Abrahamian * @author <a href="mailto:aslak.hellesoy@;bekk.no">Aslak Hellesøy</a> - * @created February 17, 2002 - * @todo-javadoc Write javadocs + * @created 18. oktober 2002 */ abstract class AbstractClass extends AbstractProgramElement implements XClass { @@ -31,47 +30,39 @@ private List _allInterfaces; /** - * @todo-javadoc Describe the field */ private List _importedClasses; + private List _importedClassNames; /** - * @todo-javadoc Describe the field */ private List _importedPackages; /** - * @todo-javadoc Describe the field */ private List _constructors; /** - * @todo-javadoc Describe the field */ private Map _namedConstructors; /** - * @todo-javadoc Describe the field */ private List _methods; /** - * @todo-javadoc Describe the field */ private HashMap _namedMethods; /** - * @todo-javadoc Describe the field */ private List _fields; /** - * @todo-javadoc Describe the field */ private List _innerClasses; /** - * @todo-javadoc Describe the field */ private XPackage _containingPackage; @@ -86,12 +77,10 @@ private boolean _isAnonymous = false; /** - * @todo-javadoc Describe the field */ private XClass _superclass; /** - * @todo-javadoc Describe the field */ private int _hash = Integer.MIN_VALUE; @@ -112,32 +101,6 @@ } /** - * Describe what the method does - * - * @param qualifiedName Describe what the parameter does - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for return value - */ - static String getPackageNameFor( String qualifiedName ) - { - String packageName = null; - int lastDotIndex = qualifiedName.lastIndexOf( '.' ); - - if( lastDotIndex == -1 ) - { - // default package - packageName = ""; - } - else - { - packageName = qualifiedName.substring( 0, lastDotIndex ); - } - return packageName; - } - - /** * Gets the Interface attribute of the SourceClass object * * @return The Interface value @@ -193,7 +156,6 @@ * * @param constructorNameWithSignature Describe what the parameter does * @return The Constructor value - * @todo-javadoc Write javadocs for method parameter */ public final XConstructor getConstructor( String constructorNameWithSignature ) { @@ -210,8 +172,6 @@ * * @param fieldName Describe what the parameter does * @return The Field value - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for method parameter */ public final XField getField( String fieldName ) { @@ -234,9 +194,7 @@ /** * Describe what the method does * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public final Collection getImportedClasses() { @@ -246,9 +204,7 @@ /** * Describe what the method does * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public final Collection getImportedPackages() { @@ -309,9 +265,7 @@ /** * Describe what the method does * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public final Collection getFields() { @@ -322,10 +276,6 @@ * Gets the constructors. * * @return the constructors. - * @todo If there are no constructors in the source code, we must add a - * public default one. This must have a node/token, and be inserted - * immediately after the class declaration's {. Each source class should - * therefore remember the node where this can be inserted. */ public final Collection getConstructors() { @@ -395,9 +345,7 @@ /** * Describe what the method does * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public String getQualifiedName() { @@ -408,9 +356,7 @@ * Returns all the implemented interfaces (if this is a class) or all the * extended interfaces (if this is an interface) * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public Collection getInterfaces() { @@ -448,11 +394,22 @@ } /** + * Returns the interfaces that are declared in the source code. This excludes + * any interfaces that might be implicitly implemented. This method is only + * useful for CodeUnit, which compares source codes, and should normally not be + * called. + * + * @return + */ + public Collection getDeclaredInterfaces() + { + return _declaredInterfaces != null ? _declaredInterfaces : EMPTY_LIST; + } + + /** * Describe what the method does * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value + * @return Describe the return value for method for return value */ public XClass getSuperclass() { @@ -578,10 +535,6 @@ * Describe what the method does * * @return Describe the return value - * @todo handle primitives. (But nobody will ask for a primitive's - * package I hope) - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value */ public XPackage getContainingPackage() { @@ -596,8 +549,6 @@ * Describe what the method does * * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value */ public Collection getInnerClasses() { @@ -607,76 +558,34 @@ * Describe what the method does * * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value */ public XProgramElement getSuperElement() { return getSuperclass(); } - /** - * whether this class is anonymous - * - * @return - */ public boolean isAnonymous() { return _isAnonymous; } - /** - * Describe what the method does - * - * @param o Describe what the parameter does - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for return value - */ public final int compareTo( Object o ) { XClass other = ( XClass ) o; return getQualifiedName().compareTo( other.getQualifiedName() ); } - /** - * Describe what the method does - * - * @return - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ + public final String toString() { return getQualifiedName(); } - /** - * Describe what the method does - * - * @param rootDir Describe what the parameter does - * @return Describe the return value - * @exception IOException Describe the exception - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for return value - * @todo-javadoc Write javadocs for exception - */ public String save( File rootDir ) throws IOException { throw new UnsupportedOperationException( getClass().getName() ); } - /** - * Describe what the method does - * - * @param obj Describe what the parameter does - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for return value - */ public boolean equals( Object obj ) { if( !( obj instanceof XClass ) ) @@ -688,13 +597,7 @@ return getQualifiedName().equals( other_clazz.getQualifiedName() ); } - /** - * Describe what the method does - * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ + public int hashCode() { if( _hash == Integer.MIN_VALUE ) @@ -704,31 +607,16 @@ return _hash; } - /** - * Describe what the method does - * - * @param unqualifiedClassName Describe what the parameter does - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for method parameter - * @todo-javadoc Write javadocs for return value - */ public XClass qualify( String unqualifiedClassName ) { return XJavaDoc.getInstance().getXClass( unqualifiedClassName ); } - /** - * Describe what the method does - * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ public long lastModified() { return Long.MIN_VALUE; } + /** * update javadoc */ @@ -755,45 +643,22 @@ ( ( XClass ) i.next() ).updateDoc(); } } - /** - * Describe what the method does - * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ + protected final boolean hasImportedClasses() { return _importedClasses != null; } - /** - * Describe what the method does - * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ + protected final boolean hasInnerClasses() { return _innerClasses != null; } - /** - * Describe what the method does - * - * @return Describe the return value - * @todo-javadoc Write javadocs for method - * @todo-javadoc Write javadocs for return value - */ + protected final boolean hasImportedPackages() { return _importedPackages != null; } - /** - * Gets the InnerClasses attribute of the AbstractClass object - * - * @param clazz Describe the method parameter - * @todo-javadoc Describe the method parameter - */ + protected void addInnerClass( XClass clazz ) { if( _innerClasses == null ) @@ -841,7 +706,6 @@ final void setContainingPackage( String containingPackage ) { _containingPackage = XJavaDoc.getInstance().addPackageMaybe( containingPackage ); - } /** @@ -875,6 +739,7 @@ * } */ } + /** * This method is called for anonymous classes only. Anon classes come in 2 * flavours. They either realise a class or an interface. @@ -918,6 +783,7 @@ } // The *real* name is the containing class' name + '.' + the name + String realName = getContainingClass().getName() + '.' + name; if( _name != null && !_name.equals( realName ) ) @@ -945,9 +811,6 @@ * interface that this interface extends (if this is an interface) * * @param interfaceName Describe the method parameter - * @todo-javadoc Describe the method parameter - * @todo-javadoc Describe the method - * @todo-javadoc Describe the method parameter */ final void addInterface( String interfaceName ) { @@ -957,25 +820,44 @@ } _declaredInterfaces.add( qualify( interfaceName ) ); } + + void resolveImportedClasses() + { + if( _importedClassNames == null ) + { + // No imported classes + return; + } + + // The first time we're called, none of the imported classes are resolved. + if( _importedClasses == null ) + { + _importedClasses = new ArrayList( _importedClassNames.size() ); + for( Iterator i = _importedClassNames.iterator(); i.hasNext(); ) + { + String importedClassName = ( String ) i.next(); + + _importedClasses.add( qualify( importedClassName ) ); + } + } + } /** * Sets the ImportedClasses attribute of the AbstractClass object * * @param importedClass Describe the method parameter - * @todo-javadoc Describe the method parameter */ void addImportedClass( String importedClass ) { - if( _importedClasses == null ) + if( _importedClassNames == null ) { - _importedClasses = new LinkedList(); + _importedClassNames = new LinkedList(); } - _importedClasses.add( qualify( importedClass ) ); + _importedClassNames.add( importedClass ); } /** * Sets the ImportedPackages attribute of the AbstractClass object * * @param importedPackage Describe the method parameter - * @todo-javadoc Describe the method parameter */ void addImportedPackage( String importedPackage ) { @@ -993,7 +875,6 @@ * Gets the Constructors attribute of the AbstractClass object * * @param constructor Describe the method parameter - * @todo-javadoc Describe the method parameter */ void addConstructor( XConstructor constructor ) { @@ -1009,7 +890,6 @@ * Gets the Fields attribute of the AbstractClass object * * @param field Describe the method parameter - * @todo-javadoc Describe the method parameter */ void addField( XField field ) { @@ -1024,7 +904,6 @@ * Gets the Methods attribute of the AbstractClass object * * @param method Describe the method parameter - * @todo-javadoc Describe the method parameter */ void addMethod( XMethod method ) { @@ -1044,6 +923,7 @@ _declaredInterfaces = null; _allInterfaces = null; _importedClasses = null; + _importedClassNames = null; _importedPackages = null; _constructors = null; _namedConstructors = null; 1.1.2.2 +5 -5 xjavadoc/src/xjavadoc/Attic/CodeTest.java Index: CodeTest.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/Attic/CodeTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -w -r1.1.2.1 -r1.1.2.2 --- CodeTest.java 16 Oct 2002 23:06:31 -0000 1.1.2.1 +++ CodeTest.java 18 Oct 2002 14:50:18 -0000 1.1.2.2 @@ -26,20 +26,20 @@ public void testT1SameApiAsT2() throws Exception { - SourceClass t1 = new SourceClass( "codeunit.CodeUnit", new File( "test/codeunit/CodeUnit1.java" ), false ); - SourceClass t2 = new SourceClass( "codeunit.CodeUnit", new File( "test/codeunit/CodeUnit2.java" ), false ); + File t1 = new File( "test/codeunit/CodeUnit1.java" ); + File t2 = new File( "test/codeunit/CodeUnit2.java" ); assertApiEquals( t1, t2 ); } public void testT1DifferentAstFromT2() throws Exception { - SourceClass t1 = new SourceClass( "codeunit.CodeUnit", new File( "test/codeunit/CodeUnit1.java" ), true ); - SourceClass t2 = new SourceClass( "codeunit.CodeUnit", new File( "test/codeunit/CodeUnit2.java" ), true ); + File t1 = new File( "test/codeunit/CodeUnit1.java" ); + File t2 = new File( "test/codeunit/CodeUnit2.java" ); try { - assertAstEquals( t1.getCompilationUnit(), t2.getCompilationUnit() ); + assertAstEquals( t1, t2 ); fail( "The ASTs should not be equal" ); } catch( AssertionFailedError e ) 1.48.2.2 +41 -21 xjavadoc/src/xjavadoc/SourceClass.java Index: SourceClass.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/SourceClass.java,v retrieving revision 1.48.2.1 retrieving revision 1.48.2.2 diff -u -w -r1.48.2.1 -r1.48.2.2 --- SourceClass.java 16 Oct 2002 23:06:30 -0000 1.48.2.1 +++ SourceClass.java 18 Oct 2002 14:50:18 -0000 1.48.2.2 @@ -20,20 +20,15 @@ */ public final class SourceClass extends AbstractClass { - - /** - * @todo-javadoc Describe the field - */ public static int instanceCount = 0; public static Map _qualifiedClasses = new HashMap(); + /** * The root node of the AST */ private ASTCompilationUnit _compilationUnit; - /** - * @todo-javadoc Describe the field - */ + private Reader _in = null; /** @@ -60,32 +55,61 @@ } /** + * @param qualifiedName + * @param sourceFile + * @deprecated Use a method that doesn't take qualifiedName + */ + public SourceClass( String qualifiedName, File sourceFile ) + { + this( sourceFile ); + } + + /** + * @param qualifiedName + * @param sourceFile + * @param useNodeParser + * @deprecated Use a method that doesn't take qualifiedName + */ + public SourceClass( String qualifiedName, File sourceFile, boolean useNodeParser ) + { + this( sourceFile, useNodeParser ); + } + + /** + * @param qualifiedName + * @param sourceFile + * @param useNodeParser + * @deprecated Use a method that doesn't take qualifiedName + */ + public SourceClass( String qualifiedName, AbstractFile sourceFile, boolean useNodeParser ) + { + this( sourceFile, useNodeParser ); + } + + /** * Constructor to use for outer classes * - * @param qualifiedName The qualified name of the class * @param sourceFile The file containing the source */ - public SourceClass( String qualifiedName, File sourceFile ) + public SourceClass( File sourceFile ) { - this( qualifiedName, new XJavadocFile( sourceFile ), false ); + this( new XJavadocFile( sourceFile ), false ); } - public SourceClass( String qualifiedName, File sourceFile, boolean useNodeParser ) + public SourceClass( File sourceFile, boolean useNodeParser ) { - this( qualifiedName, new XJavadocFile( sourceFile ), useNodeParser ); + this( new XJavadocFile( sourceFile ), useNodeParser ); } /** * Constructor to use for outer classes * - * @param qualifiedName The qualified name of the class * @param sourceFile The file containing the source * @param useNodeParser */ - public SourceClass( String qualifiedName, AbstractFile sourceFile, boolean useNodeParser ) + public SourceClass( AbstractFile sourceFile, boolean useNodeParser ) { super( null ); - setQualifiedName( qualifiedName ); if( sourceFile == null ) { throw new IllegalArgumentException( "sourceFile can't be null for outer classes!" ); @@ -100,12 +124,8 @@ catch( IOException e ) { // That's tough. Shouldn't happen - throw new IllegalStateException( "Couldn't find source for " + qualifiedName + " at " + sourceFile ); + throw new IllegalStateException( "Couldn't find " + sourceFile ); } - - String packageName = AbstractClass.getPackageNameFor( qualifiedName ); - - XJavaDoc.getInstance().addPackageMaybe( packageName ).addClass( this ); instanceCount++; _dirty = false; 1.11.2.1 +35 -0 xjavadoc/src/xjavadoc/Util.java Index: Util.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/Util.java,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -w -r1.11 -r1.11.2.1 --- Util.java 4 Aug 2002 20:48:30 -0000 1.11 +++ Util.java 18 Oct 2002 14:50:18 -0000 1.11.2.1 @@ -57,6 +57,41 @@ return ( String[] ) javaFileNames.toArray( new String[javaFileNames.size()] ); } + /** + * Describe what the method does + * + * @param qualifiedName Describe what the parameter does + * @return Describe the return value + */ + public static String getPackageNameFor( String qualifiedName ) + { + String packageName = null; + int lastDotIndex = qualifiedName.lastIndexOf( '.' ); + + if( lastDotIndex == -1 ) + { + // default package + packageName = ""; + } + else + { + packageName = qualifiedName.substring( 0, lastDotIndex ); + } + return packageName; + } + + public static String getQualifiedNameFor( String packageName, String unqualifiedName ) + { + if( packageName.equals( "" ) ) + { + return unqualifiedName; + } + else + { + return packageName + "." + unqualifiedName; + } + } + public final static StringBuffer appendDimensionAsString( final int n, final StringBuffer sb ) { for( int i = 0; i < n; i++ ) 1.60.2.3 +69 -5 xjavadoc/src/xjavadoc/XJavaDoc.java Index: XJavaDoc.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDoc.java,v retrieving revision 1.60.2.2 retrieving revision 1.60.2.3 diff -u -w -r1.60.2.2 -r1.60.2.3 --- XJavaDoc.java 16 Oct 2002 23:06:31 -0000 1.60.2.2 +++ XJavaDoc.java 18 Oct 2002 14:50:18 -0000 1.60.2.3 @@ -315,6 +315,36 @@ } /** + * @param useNodeParser + * @param inner + * @return + * @deprecated Call setUseNodeParser() prior to parsing and call the + * no-arg getSourceClasses() or getSourceClasses(Predicate) with a + * Predicate that doesn't accept inner classes. + */ + public Collection getSourceClasses( boolean useNodeParser, boolean inner ) + { + if( inner ) + { + return getSourceClasses(); + } + else + { + return getSourceClasses( new NoInnerClassesPredicate() ); + } + } + + /** + * @param useNodeParser + * @return + * @deprecated Call setUseNodeParser() prior to parsing and call the + * no-arg getSourceClasses() + */ + public Collection getSourceClasses( boolean useNodeParser ) { + return getSourceClasses(); + } + + /** * Returns all classes in the registered source sets, including inner classes * * @return A Collection of XClass @@ -434,6 +464,29 @@ } /** + * Returns the package. The package must be one of the packages of the sources. + * Other packages, such as java.lang are not available. + * + * @param packageName + * @return an XPackage, or null if the packageName is not among the + * sources. + */ + public XPackage getSourcePackage( String packageName ) + { + // This is not optimal, but this method is primarily used for testing. + for( Iterator i = getSourcePackages().iterator(); i.hasNext(); ) + { + XPackage p = ( XPackage ) i.next(); + + if( p.getName().equals( packageName ) ) + { + return p; + } + } + return null; + } + + /** * This method can be called prior to parsing so that all classes are parsed * with AST (to make it possible to write the source back to disk) * @@ -866,9 +919,7 @@ } /** - * Scan's a class' header and puts it in the cache. If the class' body methods - * are called (like methods()), the thread will block until the rest is parsed - * (if not already done). + * Scan's a class and puts it in the cache. * * @param qualifiedName Describe what the parameter does * @return Describe the return value @@ -889,11 +940,24 @@ throw new IllegalStateException( "No source found for " + qualifiedName ); } - SourceClass sourceClass = new SourceClass( qualifiedName, sourceFile, _useNodeParser ); + SourceClass sourceClass = new SourceClass( sourceFile, _useNodeParser ); - addSourceClass( sourceClass ); +// addSourceClass( sourceClass ); return sourceClass; + } + + /** + * @created 18. oktober 2002 + */ + public final static class NoInnerClassesPredicate implements Predicate + { + public boolean evaluate( Object o ) + { + XClass clazz = ( XClass ) o; + + return !clazz.isInner(); + } } /** 1.38.2.2 +9 -1 xjavadoc/src/xjavadoc/XJavaDocTest.java Index: XJavaDocTest.java =================================================================== RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDocTest.java,v retrieving revision 1.38.2.1 retrieving revision 1.38.2.2 diff -u -w -r1.38.2.1 -r1.38.2.2 --- XJavaDocTest.java 16 Oct 2002 23:06:31 -0000 1.38.2.1 +++ XJavaDocTest.java 18 Oct 2002 14:50:18 -0000 1.38.2.2 @@ -53,7 +53,7 @@ XJavaDoc.getInstance().reset(); XJavaDoc.getInstance().setPropertyMap( propertyMap ); - XJavaDoc.getInstance().addSourceSet( new FileSourceSet( dir, null ) ); + XJavaDoc.getInstance().addSourceSet( new FileSourceSet( dir ) ); } /** @@ -357,5 +357,13 @@ assertEquals( "java.lang.Exception", anonClassExtends.getSuperclass().getQualifiedName() ); assertTrue( anonClassExtends.isA( "java.io.Serializable" ) ); + } + + public void testPackageHasInnerClasses() throws Exception + { + XPackage pakkage = XJavaDoc.getInstance().getSourcePackage( "hanoi" ); + + assertNotNull( pakkage ); + assertEquals( 8, pakkage.getClasses().size() ); } }
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel