xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam ParserJamTest.java GoldenMethod.java JamTestBase.java
Date Tue, 02 Mar 2004 04:26:19 GMT
pcal        2004/03/01 20:26:19

  Modified:    v2       build.xml
               v2/src/jam java.g
               v2/src/jam/org/apache/xmlbeans/impl/jam JClassLoader.java
                        JFactory.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/editable
                        EAnnotation.java EClass.java EElement.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl
                        EAnnotationImpl.java EClassImpl.java
                        EElementImpl.java EResultImpl.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ref
                        JClassRefContext.java UnqualifiedJClassRef.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/internal
                        BaseJClassLoader.java RootJClassLoader.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/provider
                        DefaultJResultFactory.java JResultParamsImpl.java
               v2/test/src/jamtest build.xml
               v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
                        FooImpl.java
               v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam
                        GoldenMethod.java JamTestBase.java
  Added:       v2/src/jam/org/apache/xmlbeans/impl/jam/internal
                        JClassLoaderImpl.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser
                        ParserClassBuilder.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/provider
                        CompositeClassBuilder.java EClassBuilder.java
                        EClassInitializer.java NewJResultFactory.java
                        ReflectionClassBuilder.java
               v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam
                        ParserJamTest.java
  Removed:     v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser
                        JavaSourceParser.java SourceClassLoader.java
               v2/src/jam/org/apache/xmlbeans/impl/jam/internal/reflect
                        RClass.java RClassLoader.java RConstructor.java
                        RField.java RMember.java RMethod.java
                        RParameter.java package.html
  Log:
  jam: lot of refactoring, new tests
  
  Revision  Changes    Path
  1.42      +6 -1      xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- build.xml	29 Feb 2004 23:42:03 -0000	1.41
  +++ build.xml	2 Mar 2004 04:26:17 -0000	1.42
  @@ -793,10 +793,12 @@
     </target>
   
       <target name="jam.parser.check">
  +<!--
         <uptodate property="jam.parser.notRequired" targetfile="${jam_gendir}">
           <srcfiles dir="${jam_gendir}" includes="**/*"/>
           <srcfiles dir="src/jam" includes="java.g"/>
         </uptodate>
  +-->
       </target>
   
     <target name='jam.parser' depends="jam.parser.check" unless="jam.parser.notRequired">
  @@ -815,13 +817,16 @@
     </target>
   
     <target name="jam.compile.check">
  +<!--
        <uptodate property="jam.compile.notRequired" targetfile="build/classes/jam">
           <srcfiles dir="${jam_gendir}" includes="**/*"/>
           <srcfiles dir="src/jam" includes="**/*"/>
        </uptodate>
  +-->
     </target>
   
  -  <target name='jam.compile' depends='dirs, jam.compile.check' unless="jam.compile.notRequired" >
  +
  +  <target name='jam.compile' depends='dirs,jam.compile.check' unless='jam.compile.notRequired'  >
       <mkdir dir='build/classes/jam'/>
       <javac srcdir='src/jam' destdir='build/classes/jam' source='1.4' debug='on'>
         <src path='src/jam'/>
  
  
  
  1.5       +6 -9      xml-xmlbeans/v2/src/jam/java.g
  
  Index: java.g
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/java.g,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- java.g	1 Mar 2004 21:20:05 -0000	1.4
  +++ java.g	2 Mar 2004 04:26:17 -0000	1.5
  @@ -164,30 +164,26 @@
     // ========================================================================
     // Constants
   
  -  private static final boolean VERBOSE = false;
  +  private static final boolean VERBOSE = true;
   
     // ========================================================================
     // Variables
   
     private String mLastJavadoc = null;
     private String /*EPackage*/ mPackage;
  -  private EResult mResult;
     private List mErrors = null;
     private List mImports = new ArrayList();
     private List mClasses = new ArrayList();
   
     private List mParamList = new ArrayList();
     private List mExceptionList = new ArrayList();
  +  private JClassLoader mLoader = null;
   
     // ========================================================================
     // Public methods
   
  -  public void init(EResult result, EClass clazz) {
  -    mResult = result;
  -  }
  -
  -  public void setService(EResult result) {
  -    mResult = result;
  +  public void setClassLoader(JClassLoader l) {
  +    mLoader = l;
     }
   
     public EClass[] getResults() {
  @@ -240,7 +236,8 @@
   
       private EClass newClass(String simpleName) {
       //FIXME more to do here
  -      EClass clazz = mResult.addNewClass(mPackage,simpleName/*,mImports*/);
  +      //EClass clazz = mResult.addNewClass(mPackage,simpleName/*,mImports*/);
  +      EClass clazz = new EClassImpl(mPackage,simpleName,mLoader);
         mClasses.add(clazz);
         return clazz;
       }
  
  
  
  1.5       +1 -1      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JClassLoader.java
  
  Index: JClassLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JClassLoader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JClassLoader.java	12 Feb 2004 20:06:09 -0000	1.4
  +++ JClassLoader.java	2 Mar 2004 04:26:18 -0000	1.5
  @@ -72,5 +72,5 @@
     /**
      * Returns this JClassLoaders's parent.
      */
  -  public JClassLoader getParent();
  +  //public JClassLoader getParent();
   }
  
  
  
  1.10      +5 -3      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java
  
  Index: JFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JFactory.java	1 Mar 2004 21:20:05 -0000	1.9
  +++ JFactory.java	2 Mar 2004 04:26:18 -0000	1.10
  @@ -23,7 +23,8 @@
   import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
   import org.apache.xmlbeans.impl.jam.internal.javadoc.JDClassLoader;
   import org.apache.xmlbeans.impl.jam.internal.javadoc.JDClassLoaderFactory;
  -import org.apache.xmlbeans.impl.jam.internal.reflect.RClassLoader;
  +import org.apache.xmlbeans.impl.jam.provider.ReflectionClassBuilder;
  +
   
   /**
    * Start here! Entry point into the JAM subsystem.  JFactory is a singleton
  @@ -65,7 +66,8 @@
     // Constants
   
     private JClassLoader SYSTEM_CL =
  -    new RClassLoader(ClassLoader.getSystemClassLoader());
  +          ReflectionClassBuilder.createRClassLoader
  +          (ClassLoader.getSystemClassLoader());
     // REVIEW i think this needs to be even more special
   
     // ========================================================================
  @@ -218,7 +220,7 @@
     public JClassLoader createClassLoader(ClassLoader cl,
                                           JClassLoader parent,
                                           JAnnotationLoader annLoader) {
  -    return new RClassLoader(cl,parent);//FIXME
  +    return ReflectionClassBuilder.createRClassLoader(cl);//FIXME
     }
   
     public JClassLoader getSystemClassLoader() { return SYSTEM_CL; }
  
  
  
  1.4       +7 -0      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EAnnotation.java
  
  Index: EAnnotation.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EAnnotation.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EAnnotation.java	1 Mar 2004 00:10:18 -0000	1.3
  +++ EAnnotation.java	2 Mar 2004 04:26:18 -0000	1.4
  @@ -16,6 +16,7 @@
   package org.apache.xmlbeans.impl.jam.editable;
   
   import org.apache.xmlbeans.impl.jam.JAnnotation;
  +import org.apache.xmlbeans.impl.jam.JAnnotationDefinition;
   
   /**
    *
  @@ -28,6 +29,12 @@
     public EAnnotationMember[] getEditableMembers();
   
     public EAnnotationMember getEditableMember(String named);
  +
  +  public void setDefinition(JAnnotationDefinition jad);
  +
  +  public void setDefinition(String qualifiedClassName);
  +
  +  public void setDefinitionUnqualified(String unqualifiedClassName);
   
     public void setAnnotationObject(Object o);
   
  
  
  
  1.5       +2 -0      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EClass.java
  
  Index: EClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EClass.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EClass.java	1 Mar 2004 00:10:18 -0000	1.4
  +++ EClass.java	2 Mar 2004 04:26:18 -0000	1.5
  @@ -28,6 +28,8 @@
   
     public void setIsInterface(boolean b);
   
  +  public void setIsUnresolved(boolean b);
  +
     /**
      * Sets the class which this class extends.  The class name must be fully-
      * qualified.  Pass null to make the class extend nothing.
  
  
  
  1.4       +2 -2      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EElement.java
  
  Index: EElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EElement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EElement.java	1 Mar 2004 00:10:18 -0000	1.3
  +++ EElement.java	2 Mar 2004 04:26:18 -0000	1.4
  @@ -31,7 +31,7 @@
   
     public ESourcePosition getEditableSourcePosition();
   
  -  //public EAnnotation createAnnotation();
  +  public EAnnotation addNewAnnotation();
   
  -  //public void removeAnnotation(EAnnotation ann);
  +  public void removeAnnotation(EAnnotation ann);
   }
  
  
  
  1.2       +9 -1      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EAnnotationImpl.java
  
  Index: EAnnotationImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EAnnotationImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EAnnotationImpl.java	1 Mar 2004 00:10:18 -0000	1.1
  +++ EAnnotationImpl.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -46,7 +46,6 @@
     // ========================================================================
     // EAnnotation implementation
   
  -
     public EAnnotationMember addNewMember() {
       if (mMembers == null) mMembers = new ArrayList();
       EAnnotationMemberImpl out =
  @@ -71,6 +70,15 @@
         if (named.equals(out.getName())) return out;
       }
       return null;
  +  }
  +
  +  public void setDefinition(JAnnotationDefinition jad) {
  +  }
  +
  +  public void setDefinition(String qualifiedClassName) {
  +  }
  +
  +  public void setDefinitionUnqualified(String unqualifiedClassName) {
     }
   
     public void setAnnotationObject(Object o) {
  
  
  
  1.5       +11 -3     xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EClassImpl.java
  
  Index: EClassImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EClassImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EClassImpl.java	1 Mar 2004 00:10:18 -0000	1.4
  +++ EClassImpl.java	2 Mar 2004 04:26:18 -0000	1.5
  @@ -36,6 +36,7 @@
     // ========================================================================
     // Variables
   
  +  private boolean mIsUnresolved = false;
     private String mPackageName = null;
   
     // name of the class we extend, or null
  @@ -200,7 +201,7 @@
     }
   
     public boolean isUnresolved() {
  -    return false;
  +    return mIsUnresolved;
     }
   
     // ========================================================================
  @@ -211,8 +212,7 @@
     }
   
     public void setSuperclassUnqualified(String unqualifiedClassName) {
  -    //FIXME
  -    setSuperclass(unqualifiedClassName);
  +    mSuperClassRef = UnqualifiedJClassRef.create(unqualifiedClassName,this);
     }
   
     public void setSuperclass(JClass clazz) {
  @@ -336,6 +336,10 @@
       mIsInterface = b;
     }
   
  +  public void setIsUnresolved(boolean b) {
  +    mIsUnresolved = b;
  +  }
  +
     public String getQualifiedName() {
       return mPackageName+ '.' +getSimpleName();
     }
  @@ -350,6 +354,10 @@
   
     // ========================================================================
     // JClassRefContext implementation
  +
  +  public String getPackageName() {
  +    return mPackageName;
  +  }
   
     public String[] getImportSpecs() {
       if (mImports == null) return new String[0];
  
  
  
  1.5       +24 -15    xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EElementImpl.java
  
  Index: EElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EElementImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EElementImpl.java	1 Mar 2004 00:10:18 -0000	1.4
  +++ EElementImpl.java	2 Mar 2004 04:26:18 -0000	1.5
  @@ -20,6 +20,8 @@
   import org.apache.xmlbeans.impl.jam.editable.EAnnotation;
   import org.apache.xmlbeans.impl.jam.*;
   
  +import java.util.List;
  +
   /**
    *
    * @author Patrick Calahan <pcal@bea.com>
  @@ -32,6 +34,7 @@
     private String mSimpleName;
     private ESourcePosition mPosition = null;
     private JClassLoader mClassLoader;
  +  private List mAnnotations = null;
   
     // ========================================================================
     // Constructors
  @@ -45,6 +48,10 @@
       mClassLoader = loader;
     }
   
  +  public JElement getParent() {
  +    throw new IllegalStateException("NYI");//FIXME
  +  }
  +
     // ========================================================================
     // JElement implementation
   
  @@ -61,23 +68,16 @@
       return new JComment[0];
     }
   
  -
  -  //FIXME
     public JAnnotation[] getAnnotations() {
  -    return new JAnnotation[0];
  +    return getEditableAnnotations();
     }
   
  -  //FIXME
     public JAnnotation[] getAnnotations(String named) {
  -    return new JAnnotation[0];
  +    return getAnnotations(); //FIXME remove this method please
     }
   
     public JAnnotation getAnnotation(String named) {
  -    return null;
  -  }
  -
  -  public JElement getParent() {
  -    return null;
  +    return getEditableAnnotation(named);
     }
   
     // ========================================================================
  @@ -103,18 +103,27 @@
       return mPosition;
     }
   
  +  public EAnnotation addNewAnnotation() {
  +    return null;
  +  }
  +
     public void removeAnnotation(EAnnotation ann) {
     }
   
     public EAnnotation[] getEditableAnnotations() {
  -    return null;
  +    if (mAnnotations == null) return new EAnnotation[0];
  +    EAnnotation[] out = new EAnnotation[mAnnotations.size()];
  +    mAnnotations.toArray(out);
  +    return out;
     }
   
     public EAnnotation getEditableAnnotation(String named) {
  -    return null;
  -  }
  -
  -  public EAnnotation[] getEditableAnnotations(String named) {
  +    if (mAnnotations == null) return null;
  +    //FIXME this is fairly gross
  +    for(int i=0; i<mAnnotations.size(); i++) {
  +      EAnnotation out = (EAnnotation)mAnnotations.get(i);
  +      if (out.getSimpleName().equals(named)) return out;
  +    }
       return null;
     }
   
  
  
  
  1.2       +12 -1     xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EResultImpl.java
  
  Index: EResultImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EResultImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EResultImpl.java	1 Mar 2004 21:20:05 -0000	1.1
  +++ EResultImpl.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -39,6 +39,8 @@
     // Constructors
   
     public EResultImpl(EResultParamsImpl params) {
  +    System.out.println("\n\n\n\n============= NEW ERESULTIMPL");
  +    Thread.dumpStack();
       mBaseClassLoader = params.getParentClassLoader();
       mAnnotationLoader = params.getAnnotationLoader();
     }
  @@ -48,6 +50,7 @@
   
     public EClass addNewClass(String packageName, String className) {
       EClassImpl out = new EClassImpl(packageName,className,this);
  +    System.out.println("---= adding '"+out.getQualifiedName()+"'");
       mClasses.put(out.getQualifiedName(),out);
       return out;
     }
  @@ -83,8 +86,16 @@
     // JClassLoader implementation
   
     public JClass loadClass(String classname) {
  +    System.out.println("@@@@@@ loading '"+classname+"'");
  +    System.out.flush();
  +    Thread.dumpStack();
       JClass out = (JClass)mClasses.get(classname);
  -    if (out != null) return out;
  +
  +    if (out != null) {
  +      System.out.println("FOUND IT");
  +      return out;
  +    }
  +    System.out.println("NOPE");
       return mBaseClassLoader.loadClass(classname);
     }
   
  
  
  
  1.2       +2 -0      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ref/JClassRefContext.java
  
  Index: JClassRefContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ref/JClassRefContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JClassRefContext.java	25 Feb 2004 18:56:49 -0000	1.1
  +++ JClassRefContext.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -25,6 +25,8 @@
    */
   public interface JClassRefContext {
   
  +  public String getPackageName();
  +
     public String[] getImportSpecs();
   
     public JClassLoader getClassLoader();
  
  
  
  1.2       +30 -10    xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ref/UnqualifiedJClassRef.java
  
  Index: UnqualifiedJClassRef.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ref/UnqualifiedJClassRef.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnqualifiedJClassRef.java	25 Feb 2004 18:56:49 -0000	1.1
  +++ UnqualifiedJClassRef.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -22,7 +22,12 @@
    */
   public class UnqualifiedJClassRef implements JClassRef {
   
  -    // ========================================================================
  +  // ========================================================================
  +  // Constants
  +
  +  private static final boolean VERBOSE = true;
  +
  +  // ========================================================================
     // Variables
   
     private String mUnqualifiedClassname;
  @@ -43,11 +48,12 @@
     // ========================================================================
     // Constructors
   
  -  private UnqualifiedJClassRef(String qualifiedClassname,
  +  private UnqualifiedJClassRef(String unqualifiedClassname,
                                  JClassRefContext ctx)
     {
       mContext = ctx;
  -    mUnqualifiedClassname = qualifiedClassname;
  +    mUnqualifiedClassname = unqualifiedClassname;
  +    if (VERBOSE) System.out.println("[UnqualifiedJClassRef] "+unqualifiedClassname);
     }
   
     // ========================================================================
  @@ -60,12 +66,16 @@
   
     public String getQualifiedName() {
       if (mQualifiedClassname != null) return mQualifiedClassname;
  -    mQualifiedClassname = getAlreadyQualified();
  +    mQualifiedClassname = checkExplicitImport();
  +    if (mQualifiedClassname != null) return mQualifiedClassname;
  +    mQualifiedClassname = checkSamePackage();
       if (mQualifiedClassname != null) return mQualifiedClassname;
  -    mQualifiedClassname = getExplicitImport();
  +    mQualifiedClassname = checkAlreadyQualified();
       if (mQualifiedClassname != null) return mQualifiedClassname;
       //FIXME '*' imports!
  -    return "void";  //FIXME uh oh
  +    throw new IllegalStateException("unable to handle unqualified java type "+
  +                                    "reference '"+mUnqualifiedClassname+"'. "+
  +                                    "This is still partially NYI.");
     }
   
     // ========================================================================
  @@ -74,11 +84,21 @@
     /**
      * Check to see if the unqualified name actually is already qualified.
      */
  -  private String getAlreadyQualified() {
  +  private String checkSamePackage() {
  +    String name = mContext.getPackageName()+"."+mUnqualifiedClassname;
  +    JClass clazz = mContext.getClassLoader().loadClass(name);
  +    if (VERBOSE) System.out.println("checkSamePackage '"+name+"'  "+
  +                                    clazz.isUnresolved()+"  "+mContext.getClassLoader().getClass());
  +    return (clazz.isUnresolved()) ? null : clazz.getQualifiedName();
  +  }
  +
  +  /**
  +   * Check to see if the unqualified name actually is already qualified.
  +   */
  +  private String checkAlreadyQualified() {
       JClass clazz =
               mContext.getClassLoader().loadClass(mUnqualifiedClassname);
  -    if (clazz != null) return clazz.getQualifiedName();
  -    return null;
  +    return (clazz.isUnresolved()) ? null : clazz.getQualifiedName();
     }
   
   
  @@ -86,7 +106,7 @@
      * Run through the list of import specs and see if the class was explicitly
      * (i.e. without '*') imported.
      */
  -  private String getExplicitImport() {
  +  private String checkExplicitImport() {
       String[] imports = mContext.getImportSpecs();
       for(int i=0; i<imports.length; i++) {
         //FIXME this does not cover inner classes
  
  
  
  1.2       +1 -0      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/BaseJClassLoader.java
  
  Index: BaseJClassLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/BaseJClassLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseJClassLoader.java	25 Feb 2004 18:56:49 -0000	1.1
  +++ BaseJClassLoader.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -23,6 +23,7 @@
   import java.util.Collections;
   
   /**
  + * @deprecated to be replaced by JClassLoaderImpl
    *
    * @author Patrick Calahan <pcal@bea.com>
    */
  
  
  
  1.3       +2 -15     xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/RootJClassLoader.java
  
  Index: RootJClassLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/RootJClassLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RootJClassLoader.java	12 Feb 2004 20:06:15 -0000	1.2
  +++ RootJClassLoader.java	2 Mar 2004 04:26:18 -0000	1.3
  @@ -33,11 +33,6 @@
   public class RootJClassLoader implements JClassLoader {
   
     // ========================================================================
  -  // Variables
  -
  -  private JAnnotationLoader mAnnotationLoader;
  -
  -  // ========================================================================
     // Static initializer
   
     private static final Map mFd2Class = new HashMap();
  @@ -55,13 +50,7 @@
     // ========================================================================
     // Constructors
   
  -  public RootJClassLoader() {
  -    mAnnotationLoader = null;
  -  }
  -
  -  public RootJClassLoader(JAnnotationLoader loader) {
  -    mAnnotationLoader = loader;
  -  }
  +  public RootJClassLoader() {}
   
     // ========================================================================
     // JClassLoader implementation
  @@ -79,9 +68,7 @@
       return new JPackageImpl(name);
     }
   
  -  public JAnnotationLoader getAnnotationLoader() {
  -    return mAnnotationLoader;
  -  }
  +  public JAnnotationLoader getAnnotationLoader() { return null; }
   
     public JClassLoader getParent() {
       return null;
  
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/JClassLoaderImpl.java
  
  Index: JClassLoaderImpl.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.internal;
  
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  import org.apache.xmlbeans.impl.jam.JAnnotationLoader;
  import org.apache.xmlbeans.impl.jam.JClass;
  import org.apache.xmlbeans.impl.jam.JPackage;
  import org.apache.xmlbeans.impl.jam.editable.impl.EClassImpl;
  import org.apache.xmlbeans.impl.jam.editable.EClass;
  import org.apache.xmlbeans.impl.jam.provider.EClassBuilder;
  import org.apache.xmlbeans.impl.jam.provider.EClassInitializer;
  import org.apache.xmlbeans.impl.jam.internal.javadoc.JDFactory;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Collection;
  import java.util.Collections;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class JClassLoaderImpl implements JClassLoader {
  
  
    // ========================================================================
    // Variables
  
    private boolean mVerbose = true;
    private Map mName2Package = new HashMap();
    private Map mFd2ClassCache = new HashMap();
    private JAnnotationLoader mAnnotationLoader = null;//FIXME
    private EClassBuilder mBuilder;
    private EClassInitializer mInitializer = null;
  
    private static final JClassLoader ROOT = new RootJClassLoader();
  
    // ========================================================================
    // Constructor
  
    public JClassLoaderImpl(EClassBuilder builder,
                            EClassInitializer initializer) {
      if (builder == null) throw new IllegalArgumentException("null builder");
      mBuilder = builder;
      mInitializer = initializer;
    }
  
    // ========================================================================
    // JClassLoader implementation
  
    public final JClass loadClass(String fd)
    {
      fd = fd.trim();//REVIEW is this paranoid?
      JClass out = (JClass)mFd2ClassCache.get(fd);
      if (out != null) return out;
      if (fd.startsWith("[")) {
        return ArrayJClass.createClassFor(fd,this);
      } else {
        if (fd.equals("java.lang.Object")) return ObjectJClass.getInstance();
        if (fd.equals("void")) return VoidJClass.getInstance();
      }
      // parse out the package and class names - kinda broken
      int dot = fd.lastIndexOf('.');
      String pkg;
      String name;
      if (dot == -1) {
        //System.out.println("==== "+fd);
        pkg = "";
        name = fd;
      } else {
        pkg  = fd.substring(0,dot);
        name = fd.substring(dot+1);
      }
      out = mBuilder.build(pkg,name,this);
      if (out == null) {
        out = ROOT.loadClass(fd);
      }
      if (out == null) {
        out = new EClassImpl(pkg,name,this);
        ((EClassImpl)out).setIsUnresolved(true);
        if (mVerbose) System.out.println("[JClassLoaderImpl] unresolve class '"+
                                         pkg+" "+name+"'!!");
      }
      if (out instanceof EClassImpl) {
        if (mInitializer != null) mInitializer.initialize((EClassImpl)out);
      }
      mFd2ClassCache.put(fd,out);
      return out;
    }
  
    public JAnnotationLoader getAnnotationLoader() {
      return mAnnotationLoader;
    }
  
    //FIXME
    public JPackage getPackage(String named) {
      JPackage out = (JPackage)mName2Package.get(named);
      if (out == null) {
        out = JDFactory.getInstance().createPackage(named);
        mName2Package.put(named,out);
      }
      return out;
    }
  
    // ========================================================================
    // Public methods
  
    /**
     * Returns an unmodifiable collection containing the JClasses which
     * have been resolved by this JClassLoader.
     */
    public Collection getResolvedClasses() {
      return Collections.unmodifiableCollection(mFd2ClassCache.values());
    }
  
  }
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParserClassBuilder.java
  
  Index: ParserClassBuilder.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.internal.parser;
  
  import org.apache.xmlbeans.impl.jam.JClass;
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  import org.apache.xmlbeans.impl.jam.editable.EClass;
  import org.apache.xmlbeans.impl.jam.editable.EResult;
  import org.apache.xmlbeans.impl.jam.editable.EResultFactory;
  import org.apache.xmlbeans.impl.jam.editable.EResultParams;
  import org.apache.xmlbeans.impl.jam.provider.JStoreParams;
  import org.apache.xmlbeans.impl.jam.provider.JPath;
  import org.apache.xmlbeans.impl.jam.provider.EClassBuilder;
  import org.apache.xmlbeans.impl.jam.internal.BaseJClassLoader;
  import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
  import org.apache.xmlbeans.impl.jam.internal.parser.generated.JavaLexer;
  import org.apache.xmlbeans.impl.jam.internal.parser.generated.JavaParser;
  
  import java.io.*;
  import java.util.List;
  import java.util.ArrayList;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class ParserClassBuilder implements EClassBuilder {
  
    // ========================================================================
    // Constants
  
    private static final boolean VERBOSE = true;
  
    // ========================================================================
    // Variables
  
    private JPath mSourcePath;
    private boolean mVerbose = VERBOSE;
    private PrintWriter mOut;
  
    // ========================================================================
    // Constructors
  
    private ParserClassBuilder() {}
  
    public ParserClassBuilder(JStoreParams jsp) {
      mSourcePath = jsp.getInputSourcepath();
      mOut = jsp.getOut();
    }
  
    // ========================================================================
    // BaseJClassLoader implementation
  
    public EClass build(String pkg, String name, JClassLoader loader) {
      if (loader == null) throw new IllegalArgumentException("null loader");
      if (pkg == null) throw new IllegalArgumentException("null pkg");
      if (name == null) throw new IllegalArgumentException("null name");
      String filespec = pkg.replace('.',File.separatorChar)+
              File.separatorChar+name+".java";
      if (name.indexOf(".") != -1) {
        throw new IllegalArgumentException("inner classes are NYI at the moment");
      }
      InputStream in = mSourcePath.findInPath(filespec);
      if (in == null) {
        if (mVerbose) {
          mOut.println("[ParserClassBuilder] could not find "+filespec);
        }
        return null;
      } else {
        if (mVerbose) {
          mOut.println("[ParserClassBuilder] loading class "+pkg+"  "+name);
          mOut.println("[ParserClassBuilder] from file "+filespec);
        }
      }
      Reader rin = new InputStreamReader(in);
      try {
        EClass[] clazz = parse(rin,loader);
        if (clazz.length > 1) {
          System.out.println("WARNING: multiple classes per package are not "+
                             "handled correctly at the moment.  FIXME");
        }
        return clazz[0]; //FIXME deal properly with multiple classes
      } catch(Throwable t) {
        t.printStackTrace();
      }
      return null;
    }
  
    // ========================================================================
    // Private methods
  
    private static EClass[] parse(Reader in, JClassLoader loader) throws Exception {
      if (in == null) throw new IllegalArgumentException("null in");
      if (loader == null) throw new IllegalArgumentException("null loader");
      JavaLexer lexer = new JavaLexer(in);
      JavaParser parser = new JavaParser(lexer);
      parser.setClassLoader(loader);
      parser.start();
      return parser.getResults();
    }
  
    // ========================================================================
    // main method
  
    public static void main(String[] files) {
      new ParserClassBuilder.MainTool().process(files);
    }
  
    static class MainTool {
      private List mFailures = new ArrayList();
      private int mCount = 0;
      private PrintWriter mOut = new PrintWriter(System.out);
      private long mStartTime = System.currentTimeMillis();
  
      public void process(String[] files) {
        try {
          for(int i=0; i<files.length; i++) {
            File input = new File(files[i]);
            parse(new ParserClassBuilder(),input);
          }
        } catch(Exception e) {
          e.printStackTrace();
        }
        mOut.println("\n\n\n");
        int fails = mFailures.size();
        if (fails != 0) {
          mOut.println("The following files failed to parse:");
          for(int i=0; i<fails; i++) {
            mOut.println(((File)mFailures.get(i)).getAbsolutePath());
          }
        }
        mOut.println((((mCount-fails)*100)/mCount)+
                     "% ("+(mCount-fails)+"/"+mCount+") "+
                     "of input java files successfully parsed.");
        mOut.println("Total time: "+
                     ((System.currentTimeMillis()-mStartTime)/1000)+
                     " seconds.");
        mOut.flush();
        System.out.flush();
        System.err.flush();
      }
  
      private void parse(ParserClassBuilder parser, File input)
              throws Exception
      {
        System.gc();
        if (input.isDirectory()) {
          if (VERBOSE) mOut.println("scanning in directory "+input);
          File[] files = input.listFiles();
          for(int i=0; i<files.length; i++) {
            parse(parser,files[i]);
          }
        } else {
          if (!input.getName().endsWith(".java")) return;
          if (VERBOSE) {
            mOut.println("-----------------------------------------");
            mOut.println("processing "+input);
            mOut.println("-----------------------------------------");
          }
          mCount++;
          EClass[] results = null;
          try {
            results = parser.parse(new FileReader(input),null);
            if (results == null) {
              mOut.println("[error, parser result is null]");
              addFailure(input);
            } else {
              if (VERBOSE) {
                JamPrinter jp = JamPrinter.newInstance();
                for(int i=0; i<results.length; i++) {
                  jp.print(results[i],mOut);
                }
              }
            }
          } catch(Throwable e) {
            e.printStackTrace(mOut);
            addFailure(input);
          }
        }
      }
  
      private void addFailure(File file) {
        mFailures.add(file);
      }
    }
  }
  
  
  1.2       +8 -5      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/DefaultJResultFactory.java
  
  Index: DefaultJResultFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/DefaultJResultFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultJResultFactory.java	1 Mar 2004 21:20:05 -0000	1.1
  +++ DefaultJResultFactory.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -19,7 +19,6 @@
   import org.apache.xmlbeans.impl.jam.JResult;
   import org.apache.xmlbeans.impl.jam.JClassLoader;
   import org.apache.xmlbeans.impl.jam.internal.RootJClassLoader;
  -import org.apache.xmlbeans.impl.jam.internal.reflect.RClassLoader;
   import org.apache.xmlbeans.impl.jam.internal.javadoc.JDClassLoaderFactory;
   
   import java.io.IOException;
  @@ -78,7 +77,7 @@
   
     /**
      * <p>Creates the main classloader to be used given the input params.
  -   * This is usually a composite of the a source classloader and a
  +   * This is usually a composite of the source classloader and a
      * classfile classloader.  Subclasses may override to change the behavior.
      * </p>
      */
  @@ -89,11 +88,12 @@
       // used as a parent of the next.
       //
       // The root classloader deals with Object, void, primitives, arrays...
  -    JClassLoader loader = new RootJClassLoader(params.getAnnotationLoader());
  +    JClassLoader loader = new RootJClassLoader();
       // Usually they will also want the system classloader in there, but this
       // is optional
       if (params.isUseSystemClasspath()) {
  -      loader = new RClassLoader(ClassLoader.getSystemClassLoader(),loader);
  +      loader = ReflectionClassBuilder.createRClassLoader
  +              (ClassLoader.getSystemClassLoader());
       }
       // Now create a loader for any classfile loading they specified
       JClassLoader classfileLoader = createClassfileLoader(params,loader);
  @@ -144,6 +144,7 @@
                                                  JClassLoader parent)
             throws IOException
     {
  +
       //FIXME someday should make the name of the service class to use here
       //settable via a system property
       JPath cp = jp.getInputClasspath();
  @@ -151,7 +152,9 @@
         return null;
       } else {
         URL[] urls = cp.toUrlPath();
  -      return new RClassLoader(new URLClassLoader(urls),parent);
  +      ClassLoader cl = new URLClassLoader(urls);
  +      return ReflectionClassBuilder.createRClassLoader(cl);
  +    //  return new RClassLoader(,parent);
       }
     }
   }
  
  
  
  1.2       +1 -1      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JResultParamsImpl.java
  
  Index: JResultParamsImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JResultParamsImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JResultParamsImpl.java	1 Mar 2004 21:20:05 -0000	1.1
  +++ JResultParamsImpl.java	2 Mar 2004 04:26:18 -0000	1.2
  @@ -222,7 +222,7 @@
     }
   
     public PrintWriter getOut() {
  -    return null;
  +    return new PrintWriter(System.out,true);
     }
   
     public Properties getProperties() {
  
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/CompositeClassBuilder.java
  
  Index: CompositeClassBuilder.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.provider;
  
  import org.apache.xmlbeans.impl.jam.editable.EClass;
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class CompositeClassBuilder implements EClassBuilder {
  
    private EClassBuilder[] mBuilders;
  
    // ========================================================================
    // Constructors
  
    public CompositeClassBuilder(EClassBuilder[] builders) {
      mBuilders = builders;
    }
  
    // ========================================================================
    // EClassBuilder implementation
  
    public EClass build(String pkg, String cname, JClassLoader cl) {
      EClass out = null;
      for(int i=0; i<mBuilders.length; i++) {
        out = mBuilders[i].build(pkg,cname,cl);
        if (out != null) return out;
      }
      return null;
    }
  
  }
  
  
  
  1.4       +4 -2      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/EClassBuilder.java
  
  
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/EClassInitializer.java
  
  Index: EClassInitializer.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.provider;
  
  import org.apache.xmlbeans.impl.jam.editable.EClass;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public interface EClassInitializer {
  
    /**
     * <p>Initializes the given EClass.  Returns true if the implementation
     * was able to resolve the java type represented by the clazz parameter
     * and do something to initialize it.</p>
     *
     * <p>Note that the type to be initialized will never be an array type,
     * a primitive, 'void', or 'java.lang.Object'.</p>
     *
     * @return
     */
    public boolean initialize(EClass clazz);
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/NewJResultFactory.java
  
  Index: NewJResultFactory.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.provider;
  
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  import org.apache.xmlbeans.impl.jam.internal.parser.ParserClassBuilder;
  import org.apache.xmlbeans.impl.jam.internal.JClassLoaderImpl;
  
  import java.io.IOException;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class NewJResultFactory extends DefaultJResultFactory {
  
    /**
     * <p>Creates the sourcefile classloader to be used given the input params.
     * Returns null if no source files are specified in the params.  Subclasses
     * may override to change the way in which java sources are loaded.</p>
     */
    protected JClassLoader createSourceLoader(JResultParamsImpl params,
                                              JClassLoader parent)
            throws IOException
    {
      ParserClassBuilder pcb = new ParserClassBuilder(params);
      return new JClassLoaderImpl(pcb,null);
    }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/ReflectionClassBuilder.java
  
  Index: ReflectionClassBuilder.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.impl.jam.provider;
  
  import org.apache.xmlbeans.impl.jam.provider.EClassBuilder;
  import org.apache.xmlbeans.impl.jam.editable.*;
  import org.apache.xmlbeans.impl.jam.editable.impl.EClassImpl;
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  import org.apache.xmlbeans.impl.jam.internal.JClassLoaderImpl;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Field;
  import java.lang.reflect.Constructor;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class ReflectionClassBuilder implements EClassBuilder {
  
    // ========================================================================
    // Constants
  
    private static final boolean REALLY_VERBOSE = false;
  
    // ========================================================================
    // Variables
  
    private ClassLoader mLoader;
  
    /**
     * @deprecated just to wean us off the R* impls.
     */
    public static JClassLoader createRClassLoader(ClassLoader cl) {
      return new JClassLoaderImpl(new ReflectionClassBuilder(cl),null);
    }
  
    // ========================================================================
    // Constructors
  
    public ReflectionClassBuilder(ClassLoader rcl) {
      if (rcl == null) throw new IllegalArgumentException("null rcl");
      mLoader = rcl;
    }
  
    // ========================================================================
    // EClassBuilder implementation
  
    public EClass build(String packageName,
                        String className,
                        JClassLoader loader) {
      try {
        Class rclass = mLoader.loadClass(packageName+"."+className);
        EClass out = new EClassImpl(packageName, className, loader);
        populate(out,rclass);
        return out;
      } catch(ClassNotFoundException cnfe) {
        if (REALLY_VERBOSE) cnfe.printStackTrace();
        return null;
      }
    }
  
    // ========================================================================
    // Private methods
  
    private void populate(EClass dest, Class src) {
      dest.setModifiers(src.getModifiers());
      dest.setIsInterface(src.isInterface());
      // set the superclass
      Class s = src.getSuperclass();
      if (s != null) dest.setSuperclass(s.getName());
      // set the interfaces
      Class[] ints = src.getInterfaces();
      for(int i=0; i<ints.length; i++) dest.addInterface(ints[i].getName());
      // add the fields
      Field[] fields = src.getFields();
      for(int i=0; i<fields.length; i++) populate(dest.addNewField(),fields[i]);
      // add the methods
      Method[] methods = src.getDeclaredMethods();
      for(int i=0; i<methods.length; i++) populate(dest.addNewMethod(),methods[i]);
      // add the constructors
      Constructor[] ctors = src.getDeclaredConstructors();
      for(int i=0; i<ctors.length; i++) populate(dest.addNewConstructor(),ctors[i]);
      // add the annotations
      add175Annotations(dest, src);
    }
  
    private void populate(EField dest, Field src) {
      dest.setSimpleName(src.getName());
      dest.setType(src.getType().getName());
      dest.setModifiers(src.getModifiers());
    }
  
    private void populate(EConstructor dest, Constructor src) {
      dest.setSimpleName(src.getName());
      dest.setModifiers(src.getModifiers());
      Class[] exceptions = src.getExceptionTypes();
      Class[] params = src.getParameterTypes();
      populate(dest,exceptions,params);
    }
  
    private void populate(EMethod dest, Method src) {
      dest.setSimpleName(src.getName());
      dest.setModifiers(src.getModifiers());
      dest.setReturnType(src.getReturnType().getName());
      Class[] exceptions = src.getExceptionTypes();
      Class[] params = src.getParameterTypes();
      populate(dest,exceptions,params);
    }
  
    private void populate(EInvokable dest, Class[] exceptions, Class[] params) {
      for(int i=0; i<exceptions.length; i++) {
        dest.addException(exceptions[i].getName());
      }
      for(int i=0; i<params.length; i++) {
        EParameter p = dest.addNewParameter();
        p.setSimpleName("param"+i);
        p.setType(params[i].getName());
      }
    }
  
    private void add175Annotations(EElement dest, Object src) {
      /*Annotation[]*/Object[] anns = get175AnnotationsOn(src);
      if (anns == null || anns.length == 0) return;
      for(int i=0; i<anns.length; i++) {
        populate(dest.addNewAnnotation(),anns[i]);
      }
    }
  
    private void populate(EAnnotation dest, Object ann) {
      dest.setSimpleName(ann.getClass().getName()); //REVIEW
      dest.setAnnotationObject(ann);
      dest.setDefinition(ann.getClass().getName());
      populateAnnotationMembers(dest, ann, ann.getClass());
    }
  
    /**
     * Introspects the src object for annotation member methods, invokes them
     * and creates corresponding EAnnotationMembers in the given dest object.
     */
    private void populateAnnotationMembers(EAnnotation dest,
                                           Object src,
                                           Class srcClass)
    {
      Method[] methods = srcClass.getDeclaredMethods();
      for(int i=0; i<methods.length; i++) {
        if (methods[i].getParameterTypes().length > 0) continue;
        EAnnotationMember member = dest.addNewMember();
        member.setSimpleName(methods[i].getName());
        try {
          member.setValue(methods[i].invoke(src,null));
        } catch(IllegalAccessException iae) {
          iae.printStackTrace(); // this is not expected
        } catch(InvocationTargetException ite) {
          ite.printStackTrace();
        }
      }
      //REVIEW will it be a superclass or an interface?  this might be broken
      srcClass = srcClass.getSuperclass();
      if (srcClass != null &&
              !srcClass.getName().equals("java.lang.annotation.Annotation") &&
              !srcClass.getName().equals("java.lang.Object")) {
        populateAnnotationMembers(dest,src,srcClass);
      }
    }
  
    //FIXME this needs to support annotation inheritance
    /**
     * <p>Utility method for returning the java.lang.annoatation.Annotations
     * associated with a given reflection object.  This method accesses the
     * annotations via reflection so that the code will still compile
     * and run under 1.4.</p>
     */
    private Object[] get175AnnotationsOn(Object reflectionThing) {
      Method annGetter;
      try {
        annGetter = reflectionThing.getClass().getMethod("getDeclaredAnnotations",
                                               null);
        return (Object[])annGetter.invoke(reflectionThing,null);
      } catch(NoSuchMethodException nsme) {
        if (REALLY_VERBOSE) nsme.printStackTrace();
      } catch(IllegalAccessException iae) {
        iae.printStackTrace(); // this is not expected
      } catch(InvocationTargetException ite) {
        ite.printStackTrace();
      }
      return null;
    }
  
    private static String simpleName(Class clazz) {
      String out = clazz.getName();
      int dot = out.lastIndexOf('.');
      if (dot != -1) out = out.substring(dot+1);
      return out;
    }
  
  
  //salvaged from RClassLoader, may be useful for parser
    private void validateClassName(String className)
            throws IllegalArgumentException
    {
      if (!Character.isJavaIdentifierStart(className.charAt(0))) {
        throw new IllegalArgumentException
                ("Invalid first character in class name: "+className);
      }
      for(int i=1; i<className.length(); i++) {
        char c = className.charAt(i);
        if (c == '.') {
          if (className.charAt(i-1) == '.') {
            throw new IllegalArgumentException
                    ("'..' not allowed in class name: "+className);
          }
          if (i == className.length()-1) {
            throw new IllegalArgumentException
                    ("'.' not allowed at end of class name: "+className);
          }
        } else {
          if (!Character.isJavaIdentifierPart(c)) {
            throw new IllegalArgumentException
                    ("Illegal character '"+c+"' in class name: "+className);
          }
        }
      }
    }
  }
  
  
  
  1.5       +2 -0      xml-xmlbeans/v2/test/src/jamtest/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml	1 Mar 2004 00:10:19 -0000	1.4
  +++ build.xml	2 Mar 2004 04:26:18 -0000	1.5
  @@ -58,8 +58,10 @@
           <pathelement path='${classpath-value}'/> <!--ref no workie-->
         </classpath>
         <formatter type='plain' usefile='false'/>
  +      <test name='org.apache.xmlbeans.test.jam.ParserJamTest'/>
         <test name='org.apache.xmlbeans.test.jam.SourcesJamTest'/>
         <test name='org.apache.xmlbeans.test.jam.ClassesJamTest'/>
  +
       </junit>
     </target>
   
  
  
  
  1.3       +5 -0      xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java
  
  Index: FooImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FooImpl.java	1 Mar 2004 21:20:06 -0000	1.2
  +++ FooImpl.java	2 Mar 2004 04:26:19 -0000	1.3
  @@ -16,4 +16,9 @@
     protected synchronized void setId3(double id, double id2) {}
   
     protected abstract void setId4(double id, double id2, double id3);
  +
  +  String[][] methodDealingWithArrays(int[] foo, Object[] bar) {
  +    return null;
  +  }
  +
   }
  
  
  
  1.2       +3 -1      xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/GoldenMethod.java
  
  Index: GoldenMethod.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/GoldenMethod.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GoldenMethod.java	1 Mar 2004 21:20:06 -0000	1.1
  +++ GoldenMethod.java	2 Mar 2004 04:26:19 -0000	1.2
  @@ -107,7 +107,9 @@
     public void compare(JMethod method, boolean compareParamNames, Assert a) {
       a.assertTrue("method names are different",
                    method.getSimpleName().equals(mName));
  -    a.assertTrue("return types are different",
  +    a.assertTrue("return types are different ["+
  +                 method.getReturnType().getQualifiedName()+","+
  +                 mReturnType+"]",
                    method.getReturnType().getQualifiedName().equals(mReturnType));
       a.assertTrue("modifiers are different on "+method.getSimpleName()+
                    "["+method.getModifiers()+","+mModifers+"]",
  
  
  
  1.4       +75 -20    xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java
  
  Index: JamTestBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JamTestBase.java	1 Mar 2004 21:20:06 -0000	1.3
  +++ JamTestBase.java	2 Mar 2004 04:26:19 -0000	1.4
  @@ -60,9 +60,7 @@
   
   import java.io.File;
   import java.io.IOException;
  -import java.util.Arrays;
  -import java.util.List;
  -import java.util.ArrayList;
  +import java.util.*;
   
   /**
    * <p>Abstract base class for basic jam test cases.  These test cases work
  @@ -93,17 +91,18 @@
   
     // this needs to correspond to the methods on the FooImpl dummyclass
     private static final String[][] FOOIMPL_METHODS = {
  -    {"public",                       "int",      "getId",  null},
  -    {"public",                       "void",     "setId",  "int id"},
  -    {"private final static",         "void",     "setId2",  "double id"},
  -    {"protected synchronized ", "void",  "setId3",  "double id, double id2"},
  -    {"protected abstract",           "void",     "setId4",  "double id, double id2, double id3"},
  +    {"public",                   "int",      "getId",  null},
  +    {"public",                   "void",     "setId",  "int id"},
  +    {"private final static",     "void",     "setId2",  "double id"},
  +    {"protected synchronized ",  "void",     "setId3",  "double id, double id2"},
  +    {"protected abstract",       "void",     "setId4",  "double id, double id2, double id3"},
  +    {"",             "java.lang.String[][]", "methodDealingWithArrays",  "int[] foo, java.lang.Object[] bar"}
     };
   
  -
     protected static final String
             DUMMY = "org.apache.xmlbeans.test.jam.dummyclasses";
   
  +  private static final boolean VERBOSE = false;
   
   
     // ========================================================================
  @@ -173,30 +172,35 @@
       JClass[] classes = mResult.getAllClasses();
       List classNames = new ArrayList(classes.length);
       for(int i=0; i<classes.length; i++) {
  +      resolved(classes[i]);
         classNames.add(classes[i].getQualifiedName());
       }
       List expected = Arrays.asList(ALL_CLASSES);
       assertTrue("result does not contain all expected classes",
                  classNames.containsAll(expected));
  -
       assertTrue("result contains more than expected classes",
                  expected.containsAll(classNames));
     }
   
  +  public void testRecursiveResolve() {
  +    resolveCheckRecursively(mResult.getAllClasses(),new HashSet());
  +  }
  +
     /**
      * Verify that FooImpl has the correct methods with the correct
      * number of parameters and correct return types.
      */
     public void testFooImplMethods() {
  -    JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
  +    JClass fooImpl = resolved(mLoader.loadClass(DUMMY+".FooImpl"));
       GoldenMethod[] methods = GoldenMethod.createArray(FOOIMPL_METHODS);
  -    GoldenMethod.doComparison(fooImpl.getDeclaredMethods(),methods,isParameterNamesKnown(),this);
  +    GoldenMethod.doComparison(fooImpl.getDeclaredMethods(),
  +                              methods,isParameterNamesKnown(),this);
     }
   
     public void testInterfaceIsAssignableFrom()
     {
  -    JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
  -    JClass foo = mLoader.loadClass(DUMMY+".Foo");
  +    JClass fooImpl = resolved(mLoader.loadClass(DUMMY+".FooImpl"));
  +    JClass foo = resolved(mLoader.loadClass(DUMMY+".Foo"));
       assertTrue("Foo should be assignableFrom FooImpl",
                  foo.isAssignableFrom(fooImpl));
       assertTrue("FooImpl should not be assignableFrom Foo",
  @@ -205,8 +209,8 @@
   
     public void testClassIsAssignableFrom() 
     {
  -    JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
  -    JClass base = mLoader.loadClass(DUMMY+".Base");
  +    JClass fooImpl = resolved(mLoader.loadClass(DUMMY+".FooImpl"));
  +    JClass base = resolved(mLoader.loadClass(DUMMY+".Base"));
       assertTrue("Base should be assignableFrom FooImpl",
                  base.isAssignableFrom(fooImpl));
       assertTrue("FooImpl should not be assignableFrom Base",
  @@ -215,8 +219,8 @@
   
     public void testClassIsAssignableFromDifferentClassLoaders() 
     {
  -    JClass baz = mLoader.loadClass(DUMMY+".Baz");
  -    JClass runnable = mLoader.loadClass("java.lang.Runnable");
  +    JClass baz = resolved(mLoader.loadClass(DUMMY+".Baz"));
  +    JClass runnable = resolved(mLoader.loadClass("java.lang.Runnable"));
       assertTrue("Runnable should be assignableFrom Baz",
                  runnable.isAssignableFrom(baz));
       assertTrue("Baz should not be assignableFrom Runnable",
  @@ -226,8 +230,8 @@
   
     public void testAnnotationsAndInheritance()
     {
  -    JClass ejb = mLoader.loadClass(DUMMY+".ejb.TraderEJB");
  -    JClass ienv = ejb.getInterfaces()[0];
  +    JClass ejb = resolved(mLoader.loadClass(DUMMY+".ejb.TraderEJB"));
  +    JClass ienv = resolved(ejb.getInterfaces()[0]);
       JMethod ejbBuy = ejb.getMethods()[0];
       JMethod ienvBuy = ienv.getMethods()[0];
       String INTER_ANN = "ejbgen:remote-method@transaction-attribute";
  @@ -250,6 +254,57 @@
   
     // ========================================================================
     // Private methods
  +
  +  private void resolveCheckRecursively(JClass[] clazzes, Set resolved) {
  +    for(int i=0; i<clazzes.length; i++) {
  +      resolveCheckRecursively(clazzes[i],resolved);
  +    }
  +  }
  +
  +  private void resolveCheckRecursively(JClass clazz, Set set) {
  +    if (clazz == null || set.contains(clazz)) return;
  +    assertTrue(clazz.getQualifiedName()+" is not resolved",
  +               !clazz.isUnresolved());
  +    if (VERBOSE) System.out.println("checking "+clazz.getQualifiedName());
  +    set.add(clazz);
  +    resolveCheckRecursively(clazz.getSuperclass(),set);
  +    resolveCheckRecursively(clazz.getInterfaces(),set);
  +    {
  +      //check methods
  +      JMethod[] methods = clazz.getDeclaredMethods();
  +      for(int i=0; i<methods.length; i++) {
  +        resolveCheckRecursively(methods[i].getReturnType(),set);
  +        JParameter[] params = methods[i].getParameters();
  +        for(int j=0; j<params.length; j++) {
  +          resolveCheckRecursively(params[j].getType(),set);
  +        }
  +      }
  +    }
  +    {
  +      //check constructors
  +      JConstructor[] ctors = clazz.getConstructors();
  +      for(int i=0; i<ctors.length; i++) {
  +        JParameter[] params = ctors[i].getParameters();
  +        for(int j=0; j<params.length; j++) {
  +          resolveCheckRecursively(params[j].getType(),set);
  +        }
  +      }
  +    }
  +    {
  +      //check fields
  +      JField[] fields = clazz.getFields();
  +      for(int i=0; i<fields.length; i++) {
  +        resolveCheckRecursively(fields[i].getType(),set);
  +      }
  +    }
  +  }
  +
  +
  +  private JClass resolved(JClass c) {
  +    assertTrue("class "+c.getQualifiedName()+" is not resolved",
  +               !c.isUnresolved());
  +    return c;
  +  }
   
     private void verifyAnnotation(JElement j, String ann, String val) {
       JAnnotation a = j.getAnnotation(ann);
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ParserJamTest.java
  
  Index: ParserJamTest.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.test.jam;
  
  import org.apache.xmlbeans.impl.jam.JResult;
  import org.apache.xmlbeans.impl.jam.JResultFactory;
  import org.apache.xmlbeans.impl.jam.JResultParams;
  import org.apache.xmlbeans.impl.jam.provider.NewJResultFactory;
  
  import java.io.IOException;
  
  /**
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class ParserJamTest extends JamTestBase {
  
    // ========================================================================
    // Constructors
  
    public ParserJamTest(String name) {
      super(name);
    }
  
    // ========================================================================
    // JamTestBase implementation
  
    protected JResult getResultToTest() throws IOException {
      JResultFactory jsf = new NewJResultFactory();
      JResultParams params = jsf.createResultParams();
      params.includeSourceFiles(getDummyclassesSourceRoot(),"**/*.java");
      return jsf.createResult(params);
    }
  
    protected boolean isAnnotationsAvailable() {
      return true;
    }
  
    protected boolean isParameterNamesKnown() {
      return true;
    }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message