Author: kylem
Date: Tue Apr 12 06:50:25 2005
New Revision: 161051

URL: http://svn.apache.org/viewcvs?view=rev&rev=161051
Log:
Improved implementation of the ControlClientAnnotationProcessor (responsible 
for @Control handling) to make it possible to reference bean types that will be 
generated by the current processor pass.  The CCAP is now able to map from a 
field (bean) type back to the associated control interface using either 
compiled class info or from the set of interfaces included on the apt input 
list.  The effectively removes the need for the 'compileByExtension' <apt> ant 
task option, which existed primarily to help resolve dependency ordering 
issues.   As a test case, the controls/test build.xml, which previously relied 
heavily upon compileByExtension usage and multiple <apt> invocations, now uses 
neither.

Added proper handling of the noCompile option to <apt> ant task to cause 
annotation processing/codegen but disable compilation.   Patch submitted by 
Chris Hogue.

Modified:
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlField.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptEventField.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptTask.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
    incubator/beehive/trunk/controls/test/build.xml

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlField.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlField.java?view=diff&r1=161050&r2=161051
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlField.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlField.java
 Tue Apr 12 06:50:25 2005
@@ -69,12 +69,34 @@
         // type it implements.
         //
         TypeDeclaration typeDecl = 
((DeclaredType)controlType).getDeclaration();
+        InterfaceDeclaration controlIntf = null;
 
+        //
+        // It is possible that the declared type is associated with a 
to-be-generated
+        // bean type.  In this case, look for the associated control interface 
on the
+        // processor input list.
+        //
         if ( typeDecl == null )
-            return null;
-        
-        InterfaceDeclaration controlIntf = null;
-        if (typeDecl instanceof ClassDeclaration)
+        {
+            String className = controlType.toString();
+            String intfName = className.substring(0, className.length() - 4);
+            controlIntf = 
(InterfaceDeclaration)_env.getTypeDeclaration(intfName);
+            if (controlIntf == null)
+            {
+                // The specified class name may not be fully qualified.  In 
this case, the
+                // best we can do is look for a best fit match against the 
input types
+                for (TypeDeclaration td :_env.getSpecifiedTypeDeclarations())
+                {
+                    if (td instanceof InterfaceDeclaration &&
+                        td.getSimpleName().equals(intfName))
+                    {
+                        controlIntf = (InterfaceDeclaration)td;
+                        break;
+                    }
+                }
+            }
+        }
+        else if (typeDecl instanceof ClassDeclaration)
         {
             Collection<InterfaceType> implIntfs = 
((ClassDeclaration)typeDecl).getSuperinterfaces();
             for (InterfaceType intfType : implIntfs)
@@ -91,23 +113,17 @@
                     break;
                 }
             }
-
-            if (controlIntf == null)
-            {
-                _env.getMessager().printError(_fieldDecl.getPosition(), 
-                                              "Unable to identify control type 
of field");
-                return null; 
-            }
         }
         else if (typeDecl instanceof InterfaceDeclaration)
         {
             controlIntf = (InterfaceDeclaration)typeDecl;
         }
-        else
+
+        if (controlIntf == null)
         {
-            _env.getMessager().printError(_fieldDecl.getPosition(),
-                                          "Control field is not a valid type");
-            return null;
+            _env.getMessager().printError(_fieldDecl.getPosition(), 
+                                      "Unable to identify control type of 
field");
+            return null; 
         }
 
         return new AptControlInterface(controlIntf, _env);

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptEventField.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptEventField.java?view=diff&r1=161050&r2=161051
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptEventField.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptEventField.java
 Tue Apr 12 06:50:25 2005
@@ -105,7 +105,8 @@
         if (_controlIntf == null)
         {
             _controlIntf = initControlInterface();
-            initTypeParameterBindings();
+            if (_controlIntf != null)
+                initTypeParameterBindings();
         }
         return _controlIntf;
     }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptTask.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptTask.java?view=diff&r1=161050&r2=161051
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptTask.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptTask.java
 Tue Apr 12 06:50:25 2005
@@ -196,6 +196,13 @@
         arg.setValue("-s");
         arg = createCompilerArg();
         arg.setFile(_genDir);
+
+        //add the -nocompile flag if set to true
+        if(_nocompile)
+        {
+            Commandline.Argument ncarg = createCompilerArg();
+            ncarg.setValue("-nocompile");
+        }
         
         //
         // Add processor options.

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?view=diff&r1=161050&r2=161051
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
 Tue Apr 12 06:50:25 2005
@@ -137,17 +137,17 @@
                 Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                 for ( TypeMirror controlType : controlTypes )
                 {
-                    InterfaceType controlIntfOrExt = 
getControlInterfaceOrExtension(controlType);
-                    InterfaceType controlIntf = 
getMostDerivedControlInterface( controlIntfOrExt );
+                    InterfaceDeclaration controlIntfOrExt = 
getControlInterfaceOrExtension(controlType);
+                    InterfaceDeclaration controlIntf = 
getMostDerivedControlInterface( controlIntfOrExt );
 
                     assert controlIntf != null : "Can't find most derived 
control intf for=" + controlIntfOrExt;
 
-                    ControlInterface annot = 
controlIntf.getDeclaration().getAnnotation(ControlInterface.class);
+                    ControlInterface annot = 
controlIntf.getAnnotation(ControlInterface.class);
                     String defBinding = annot.defaultBinding();
 
-                    defBinding = ControlBeanContext.resolveDefaultBinding( 
defBinding, controlIntf.getDeclaration().getQualifiedName() );
+                    defBinding = ControlBeanContext.resolveDefaultBinding( 
defBinding, controlIntf.getQualifiedName() );
 
-                    mf.addControlType( 
controlIntfOrExt.getDeclaration().getQualifiedName(), defBinding );
+                    mf.addControlType( controlIntfOrExt.getQualifiedName(), 
defBinding );
                 }
 
                 mf.emit( f, clientPkg, clientManifestName, null );
@@ -193,6 +193,7 @@
     {
          TypeMirror fieldType = f.getType();
 
+
          // Valid control field instances can be of an interface type
          // or a class type.
          if ( fieldType instanceof InterfaceType )
@@ -209,7 +210,7 @@
              // Valid class type decls must implements the ControlBean API.
 
              // Walk the implementation inheritance hierarchy, seeing if one 
of the
-             // classes implements ControlBean.
+             // classes implements ControlBean.  
              //
              // REVIEW: Does NOT check if the interfaces might implement 
ControlBean!
              // This is unnecessary for our impl, since our generated bean 
class directly
@@ -217,38 +218,50 @@
              boolean foundControlBean = false;
              ClassType classType = (ClassType)fieldType;
 
-             outer: while ( classType != null )
+             if (classType.getDeclaration() != null)
              {
-                 Collection<InterfaceType> intfs = 
classType.getSuperinterfaces();
-                 for ( InterfaceType intfType : intfs )
-                 {
-                     if ( intfType.getDeclaration().getQualifiedName().equals( 
"org.apache.beehive.controls.api.bean.ControlBean" ) )
-                     {
-                         foundControlBean = true;
-                         break outer;
-                     }
-                 }
-                 classType = classType.getSuperclass();
-             }
-             if ( !foundControlBean )
-                 printError( f, "control.field.bad.classtype" );
+                outer: while ( classType != null )
+                {
+                    Collection<InterfaceType> intfs = 
classType.getSuperinterfaces();
+                    for ( InterfaceType intfType : intfs )
+                    {
+                        if ( 
intfType.getDeclaration().getQualifiedName().equals( 
"org.apache.beehive.controls.api.bean.ControlBean" ) )
+                        {
+                            foundControlBean = true;
+                            break outer;
+                        }
+                    }
+                    classType = classType.getSuperclass();
+                }
+                if ( !foundControlBean )
+                    printError( f, "control.field.bad.classtype" );
 
-             // Valid generated beans should only "implement" the control 
interface/extension, and no others
-             classType = (ClassType)fieldType;
-             Collection<InterfaceType> intfs = classType.getSuperinterfaces();
-             if ( intfs.size() != 1 )
-             {
-                 printError( f, "control.field.bad.classtype.badinterface" );
-             }
+                // Valid generated beans should only "implement" the control 
interface/extension, and no others
+                classType = (ClassType)fieldType;
+                Collection<InterfaceType> intfs = 
classType.getSuperinterfaces();
+                if ( intfs.size() != 1 )
+                {
+                    printError( f, "control.field.bad.classtype.badinterface" 
);
+                }
 
-             for ( InterfaceType intfType : intfs )
-             {
-                 if ( 
intfType.getDeclaration().getAnnotation(ControlExtension.class) == null &&
-                      
intfType.getDeclaration().getAnnotation(ControlInterface.class) == null)
-                 {
-                     printError( f, 
"control.field.bad.classtype.badinterface");
-                 }
-             }
+                for ( InterfaceType intfType : intfs )
+                {
+                    if ( 
intfType.getDeclaration().getAnnotation(ControlExtension.class) == null &&
+                         
intfType.getDeclaration().getAnnotation(ControlInterface.class) == null)
+                    {
+                        printError( f, 
"control.field.bad.classtype.badinterface");
+                    }
+                }
+            }
+            else
+            {
+                // TODO: This could be a ControlBean type that is going to be 
generated by
+                // the current APT processing iteration.  It should be 
possible to do more
+                // specific verification here using the getTypeDeclaration API 
on
+                // AnnotationProcessorEnvironment.  In any event, the 
implementation of
+                // getControlInterface will properly handle this case, and if 
it cannot a
+                // malformed type error will be generated.
+            }
          }
          else
          {
@@ -262,8 +275,8 @@
          // malformed if the source for those types has errors (yet the apt 
type may still exist!).
          try
          {
-             InterfaceType controlIntfOrExt = 
getControlInterfaceOrExtension(fieldType);
-             InterfaceType controlIntf = getMostDerivedControlInterface( 
controlIntfOrExt );
+             InterfaceDeclaration controlIntfOrExt = 
getControlInterfaceOrExtension(fieldType);
+             InterfaceDeclaration controlIntf = 
getMostDerivedControlInterface( controlIntfOrExt );
 
              if ( controlIntf != null )
              {
@@ -306,22 +319,55 @@
      * @param intfOrBeanClass
      * @return
      */
-    private InterfaceType getControlInterfaceOrExtension( TypeMirror 
intfOrBeanClass )
+    private InterfaceDeclaration getControlInterfaceOrExtension( TypeMirror 
intfOrBeanClass )
     {
         if (intfOrBeanClass instanceof InterfaceType)
         {
-            return (InterfaceType)intfOrBeanClass;
+            return ((InterfaceType)intfOrBeanClass).getDeclaration();
         }
         else if (intfOrBeanClass instanceof ClassType)
         {
             ClassType classType = (ClassType)intfOrBeanClass;
-            Collection<InterfaceType> intfs = classType.getSuperinterfaces(); 
// direct supers only
 
-            // per the code in checkControlField, this set must be of size 1
-            // and the 1 super interface must be a control interface/extension
-            assert ( intfs.size() == 1 );
-            for ( InterfaceType intfType : intfs )
-                return intfType;
+            // If the bean type declaration cannot be found, then the only 
(valid) possibility
+            // is that it is a generated type from the current processor pass. 
  See if a base
+            // interface type can be determined from the current processor 
input list.
+            if (classType.getDeclaration() == null)
+            {
+                //
+                // Compute the bean type name, and the associated interface 
name by stripping
+                // the "Bean" suffix
+                //
+                String className = classType.toString();
+                String intfName = className.substring(0, className.length() - 
4);
+                AnnotationProcessorEnvironment ape = 
getAnnotationProcessorEnvironment();
+                InterfaceDeclaration id = 
(InterfaceDeclaration)ape.getTypeDeclaration(intfName);
+                if (id == null)
+                {
+                    // The specified class name may not be fully qualified.  
In this case, the
+                    // best we can do is look for a best fit match against the 
input types
+                    for (TypeDeclaration td 
:ape.getSpecifiedTypeDeclarations())
+                    {
+                        if (td instanceof InterfaceDeclaration && 
+                            td.getSimpleName().equals(intfName))
+                        {
+                            return (InterfaceDeclaration)td;
+                        }
+                    }
+                }
+                return id;
+            }
+            else
+            {
+                // direct supers only
+                Collection<InterfaceType> intfs = 
classType.getSuperinterfaces(); 
+
+                // per the code in checkControlField, this set must be of size 
1
+                // and the 1 super interface must be a control 
interface/extension
+                assert ( intfs.size() == 1 );
+                for ( InterfaceType intfType : intfs )
+                    return intfType.getDeclaration();
+            }
         }
         else
         {
@@ -340,33 +386,33 @@
      * @return most derived interface in the heirarchy annotated with 
@ControlInterface, null
      *         if no such interface found.
      */
-    private InterfaceType getMostDerivedControlInterface( InterfaceType 
controlIntfOrExt )
+    private InterfaceDeclaration getMostDerivedControlInterface( 
InterfaceDeclaration controlIntfOrExt )
     {
-        Queue<InterfaceType> q = new LinkedList<InterfaceType>();
+        Queue<InterfaceDeclaration> q = new LinkedList<InterfaceDeclaration>();
 
-        InterfaceType ci = controlIntfOrExt;
-        while ( ci != null )
+        InterfaceDeclaration id = controlIntfOrExt;
+        while ( id != null )
         {
-            if ( ci.getDeclaration().getAnnotation(ControlInterface.class) != 
null )
+            if ( id.getAnnotation(ControlInterface.class) != null )
                 break;
 
-            Collection<InterfaceType> supers = ci.getSuperinterfaces();
+            Collection<InterfaceType> supers = id.getSuperinterfaces();
             for ( InterfaceType s : supers )
-                q.offer( s );
+                q.offer( s.getDeclaration() );
 
-            ci = q.poll();
+            id = q.poll();
         }
 
-        return ci;
+        return id;
     }
 
     /**
      * Enforces the VersionRequired annotation for control fields.
      */
-    private void enforceVersionRequired( FieldDeclaration f, InterfaceType 
controlIntf )
+    private void enforceVersionRequired( FieldDeclaration f, 
InterfaceDeclaration controlIntf )
     {
         VersionRequired versionRequired = 
f.getAnnotation(VersionRequired.class);
-        Version versionPresent = 
controlIntf.getDeclaration().getAnnotation(Version.class);
+        Version versionPresent = controlIntf.getAnnotation(Version.class);
 
         if ( versionRequired != null )
         {

Modified: incubator/beehive/trunk/controls/test/build.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/build.xml?view=diff&r1=161050&r2=161051
==============================================================================
--- incubator/beehive/trunk/controls/test/build.xml (original)
+++ incubator/beehive/trunk/controls/test/build.xml Tue Apr 12 06:50:25 2005
@@ -194,22 +194,9 @@
 
     <target name="build-test-beans" depends="dirs,build-test-auxilaries">
 
-          <property name="cp" refid="test.classpath"/>
-        <echo message="classpath=${cp}"/>
-
-        <apt srcdir="${controls.test.controls}" destdir="${build.beans}" 
gendir="${build.beansrc}"
-             debug="on"
-             classpathref="test.classpath" compileByExtension="true"
-             srcExtensions="*.java,*.jcx,*.jcs" >
-            <include name="**/composition/InnerControl*"/>
-            <include name="**/property/ExtPropertySet*"/>
-        </apt>
-
-        <echo message="** Phase Two **"/>
+        <echo message="** Compiling Controls **"/>
         <apt srcdir="${controls.test.controls}" destdir="${build.beans}" 
gendir="${build.beansrc}"
-             debug="on"
-             compileByExtension="true"
-             classpathref="test.classpath"
+             debug="on" classpathref="test.classpath"
              srcExtensions="*.java,*.jcx,*.jcs">
         </apt>
 
@@ -242,7 +229,6 @@
             debug="on"  
             verbose="false"
             failonerror="true"
-            compileByExtension="true"
             srcExtensions="*.java"/>
 
         <property name="_build.test.auxilaries.ran" value="true"/>
@@ -283,7 +269,6 @@
             destdir="${build.tests}"
             gendir="${build.beansrc}"
             classpathref="test.classpath"
-            compileByExtension="true"
             srcExtensions="*.java"
             debug="on"
             optimize="on"
@@ -304,7 +289,6 @@
             destdir="${build.tests}"
             gendir="${build.beansrc}"
             classpathref="test.classpath"
-            compileByExtension="true"
             srcExtensions="*.java"
             debug="on"
             optimize="on"


Reply via email to