[Jpeergen-cvs] dev/src/java/org/progeeks/jni PeerDoclet.java,1.2,1.3
Status: Beta
Brought to you by:
pspeed
|
From: <ps...@us...> - 2004-08-15 06:50:20
|
Update of /cvsroot/jpeergen/dev/src/java/org/progeeks/jni In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27486/src/java/org/progeeks/jni Modified Files: PeerDoclet.java Log Message: Added some additional checking in the main peer doclet at the class level. This provides some earlier warnings and errors if there are problems with a given class file. Eventually, we may have a specific class-level peer tag that we'll check for here as well. Index: PeerDoclet.java =================================================================== RCS file: /cvsroot/jpeergen/dev/src/java/org/progeeks/jni/PeerDoclet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PeerDoclet.java 15 Aug 2004 05:55:18 -0000 1.2 --- PeerDoclet.java 15 Aug 2004 06:49:57 -0000 1.3 *************** *** 237,240 **** --- 237,328 ---- } + /** + * Returns true if the specified Doc object has the specified tag. + */ + public static boolean hasTag( Doc doc, String tag ) + { + Tag[] tags = doc.tags(); + for( int i = 0; i < tags.length; i++ ) + { + if( tags[i].name().equals( tag ) ) + return( true ); + } + return( false ); + } + + /** + * Returns true if the specified class doc has the specified field. + */ + private static boolean hasField( String fieldName, ClassDoc c ) + { + FieldDoc[] fields = c.fields(); + for( int i = 0; i < fields.length; i++ ) + { + if( fields[i].name().equals( fieldName ) ) + return( true ); + } + return( false ); + } + + /** + * Returns true if the specified class has any peerable static methods. + * In this case, we can peer the class even if we can't peer the instances. + */ + private static boolean isClassPeerable( ClassDoc c ) + { + MethodDoc[] methods = c.methods(); + for( int i = 0; i < methods.length; i++ ) + { + // Only interested in static methods since they don't + // require full object peering + if( !methods[i].isStatic() ) + continue; + + // Check for forward peering. + if( methods[i].isNative() ) + return( true ); + + // Check for reverse peering. + if( hasTag( methods[i], TAG_PEERED ) || hasTag( methods[i], TAG_PEERED_RAW ) ) + return( true ); + } + return( false ); + } + + /** + * Called to generate errors and warnings for the user when there is + * no peer field available. Any non-static native methods generate + * warnings while specifically "peered" methods will generate errors. + */ + private static void checkFullPeering( ClassDoc c ) + { + MethodDoc[] methods = c.methods(); + boolean hasNative = false; + boolean hasPeered = false; + for( int i = 0; i < methods.length; i++ ) + { + // Only interested in instance methods since the static + // ones don't need a peer field. + if( methods[i].isStatic() ) + continue; + + if( methods[i].isNative() ) + hasNative = true; + + if( hasTag( methods[i], TAG_PEERED ) || hasTag( methods[i], TAG_PEERED_RAW ) ) + { + throw new RuntimeException( c + " cannot be peered because it does not" + + " define a 'long peer' instance field." ); + } + } + + if( hasNative ) + { + System.out.println( "Warning: " + c + " has native instance methods bt does not define " + + "a 'peer' field. Code will not be generated for these methods." ); + } + } + + private static void processClass( ClassDoc c ) throws IOException { *************** *** 242,249 **** --- 330,356 ---- if( excludes.contains( c.qualifiedName() ) ) { + // No reason to do any other checking if the user has specifically + // excluded a class. System.out.println( "Skipping " + c.qualifiedName() + ", in exclude list." ); return; } + // Determine if the class is even peerable + boolean fullyPeerable = hasField( "peer", c ); + if( !fullyPeerable ) + { + // Generate errors if the class defines peering without a peer + // instance field. + checkFullPeering( c ); + + // If the class is not staticly peerable then no reason to process + // the file + if( !isClassPeerable( c ) ) + { + System.out.println( "Skipping " + c.qualifiedName() + ", no peerable methods." ); + return; + } + } + for( int i = 0; i < codelets.length; i++ ) { |