You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2004/10/20 19:40:35 UTC

svn commit: rev 55168 - in incubator/beehive/trunk/netui/src: compiler/org/apache/beehive/netui/compiler compiler/org/apache/beehive/netui/compiler/genmodel compiler/org/apache/beehive/netui/compiler/grammar pageflow/org/apache/beehive/netui/pageflow

Author: rich
Date: Wed Oct 20 10:40:34 2004
New Revision: 55168

Modified:
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/CompilerUtils.java
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerInfo.java
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenActionOutputModel.java
   incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/DynaFormData.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/Forward.java
Log:
- Fixed a TODO for inferring of property names from form bean getters to conform to the JavaBean spec; specifically, fixed to deal with capitalized properties (e.g., getURI -> URI) and boolean properties (e.g., isGood -> good).
- Fixed the annotation processor and runtime to allow primitive array types (e.g., int[].class) for action outputs (@Jpf.ActionOutput).
- Fixed to prevent void types anywhere in annotations that accept Class attributes.
- Fixed a divide-by-zero error (!) when processing the following erroneous annotation:
    @Jpf.Forward(name="foo", returnAction="")

DRT: netui (WinXP)
BB: self (linux)



Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/CompilerUtils.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/CompilerUtils.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/CompilerUtils.java	Wed Oct 20 10:40:34 2004
@@ -24,6 +24,7 @@
 import com.sun.mirror.type.TypeMirror;
 import com.sun.mirror.type.DeclaredType;
 import com.sun.mirror.type.InterfaceType;
+import com.sun.mirror.type.ArrayType;
 import com.sun.mirror.util.SourcePosition;
 import com.sun.mirror.util.DeclarationVisitor;
 
@@ -836,28 +837,64 @@
         }
     }
     
-    public static BeanPropertyDescriptor getBeanProperty( String methodName, String returnType, int argCount )
+    public static class BeanPropertyDeclaration
+            extends BeanPropertyDescriptor
     {
-        if ( ! returnType.equals( "void" ) )
+        private MethodDeclaration _getter;
+        
+        
+        public BeanPropertyDeclaration( String propertyName, String type, MethodDeclaration getter )
         {
-            // TODO: more naive code that will have to be fixed
-            if ( methodName.startsWith( GETTER_PREFIX ) && methodName.length() > 3 && argCount == 0 )
-            {
-                String propertyName = Character.toLowerCase( methodName.charAt( 3 ) ) + methodName.substring( 4 );
-                return new BeanPropertyDescriptor( propertyName, returnType );
-            }
+            super( propertyName, type );
+            _getter = getter;
         }
         
-        return null;
+        public MethodDeclaration getGetter()
+        {
+            return _getter;
+        }
     }
     
-    public static BeanPropertyDescriptor getBeanProperty( MethodDeclaration method )
+    public static BeanPropertyDeclaration getBeanProperty( MethodDeclaration method )
     {
         if ( CompilerUtils.hasModifier( method, Modifier.PUBLIC )
              && ! CompilerUtils.hasModifier( method, Modifier.STATIC ) )
         {
-            return getBeanProperty( method.getSimpleName(), method.getReturnType().toString(),
-                                    method.getParameters().size() );
+            String returnType = method.getReturnType().toString();
+            
+            if ( ! returnType.equals( "void" ) && method.getParameters().size() == 0 )
+            {
+                String methodName = method.getSimpleName();
+                String propertyName = null;
+                
+                if ( methodName.startsWith( GETTER_PREFIX ) && methodName.length() > GETTER_PREFIX.length() )
+                {
+                    propertyName = methodName.substring( GETTER_PREFIX.length() );
+                }
+                else if ( methodName.startsWith( BOOLEAN_GETTER_PREFIX ) && returnType.equals( "boolean" )
+                          && methodName.length() > BOOLEAN_GETTER_PREFIX.length() )
+                {
+                    propertyName = methodName.substring( BOOLEAN_GETTER_PREFIX.length() );
+                }
+                
+                if ( propertyName != null )
+                {
+                    //
+                    // If the first two letters are uppercase, we don't change the first character to lowercase.
+                    // This is so that something like getURI has a property name of 'URI' (see JavaBeans spec).
+                    //
+                    if ( propertyName.length() == 1 )
+                    {
+                        propertyName = propertyName.toLowerCase();
+                    }
+                    else if ( ! Character.isUpperCase( propertyName.charAt( 1 ) ) )
+                    {
+                        propertyName = Character.toLowerCase( propertyName.charAt( 0 ) ) + propertyName.substring( 1 );
+                    }
+                    
+                    return new BeanPropertyDeclaration( propertyName, returnType, method );
+                }
+            }
         }
         
         return null;
@@ -874,35 +911,14 @@
         {
             if ( hasModifier( method, Modifier.PUBLIC ) )
             {
-                CompilerUtils.BeanPropertyDescriptor bpd =
-                        getBeanProperty( method.getSimpleName(), method.getReturnType().toString(),
-                                         method.getParameters().size() );
-                
-                if ( bpd != null ) ret.add( new BeanPropertyDeclaration( bpd, method ) );
+                BeanPropertyDeclaration bpd = getBeanProperty( method );
+                if ( bpd != null ) ret.add( bpd );
             }
         }
         
         return ret;
     }
     
-    public static class BeanPropertyDeclaration
-            extends BeanPropertyDescriptor
-    {
-        private MethodDeclaration _getter;
-        
-        
-        public BeanPropertyDeclaration( BeanPropertyDescriptor bpd, MethodDeclaration getter )
-        {
-            super( bpd.getPropertyName(), bpd.getType() );
-            _getter = getter;
-        }
-        
-        public MethodDeclaration getGetter()
-        {
-            return _getter;
-        }
-    }
-    
     public static boolean isPageFlowClass( ClassDeclaration jclass, AnnotationProcessorEnvironment env )
     {
         return getAnnotation( jclass, CONTROLLER_TAG_NAME ) != null && isAssignableFrom( JPF_BASE_CLASS, jclass, env );
@@ -1038,4 +1054,16 @@
         
          return false;
      }
+    
+    public static TypeMirror getArrayBaseType( ArrayType arrayType )
+    {
+        TypeMirror baseType = arrayType;
+        
+        do
+        {
+            baseType = ( ( ArrayType ) baseType ).getComponentType();
+        } while ( baseType instanceof ArrayType );
+        
+        return baseType;
+    }
 }

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java	Wed Oct 20 10:40:34 2004
@@ -234,7 +234,7 @@
         //
         // Only warn about nonserializable member data that's defined in this particular class.
         //
-        if ( CompilerUtils.typesAreEqual( field.getDeclaringType(), jclass ) )
+        if ( CompilerUtils.typesAreEqual( jclass, field.getDeclaringType() ) )
         {
             TypeMirror type = field.getType();
             

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerInfo.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerInfo.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerInfo.java	Wed Oct 20 10:40:34 2004
@@ -93,8 +93,9 @@
         
         public int hashCode()
         {
-            if ( _beanType == null ) return _name.hashCode();
-            return _beanType.hashCode() % _name.hashCode();
+            int nameHash = _name.hashCode();
+            if ( _beanType == null ) return nameHash;
+            return nameHash != 0 ? _beanType.hashCode() % nameHash : _beanType.hashCode();
         }
     }
     

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java	Wed Oct 20 10:40:34 2004
@@ -201,6 +201,7 @@
     
     public static final String ARRAY_TYPE_SUFFIX = "[]";    
     public static final String GETTER_PREFIX = "get";
+    public static final String BOOLEAN_GETTER_PREFIX = "is";
     
     public static final String PAGEFLOW_RUNTIME_JAR = '/' + WEBINF_DIR_NAME + "/lib/beehive-netui-pageflow.jar";    
     public static final String RUNTIME_VERSION_ATTRIBUTE = "PageFlow-Runtime-Version";

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties	Wed Oct 20 10:40:34 2004
@@ -106,6 +106,7 @@
 error.invalid-java-identifier-part = The character ''{0}'' may not be used in this identifier.
 error.array-type-not-allowed = This value may not be an array type.
 error.primitive-type-not-allowed = This value may not be an primitive type.
+error.void-type-not-allowed = This value may not be the void type.
 error.must-be-primitive-type = This value must be a primitive Class, e.g. int.class.
 error.invalid-type = This type is not allowed here.
 warning.action-not-found = Action "{0}" was not found.

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenActionOutputModel.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenActionOutputModel.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenActionOutputModel.java	Wed Oct 20 10:40:34 2004
@@ -25,6 +25,7 @@
 import com.sun.mirror.type.ArrayType;
 import com.sun.mirror.type.TypeMirror;
 import com.sun.mirror.type.DeclaredType;
+import com.sun.mirror.type.PrimitiveType;
 
 
 public class GenActionOutputModel
@@ -52,8 +53,17 @@
             baseType = ( ( ArrayType ) baseType ).getComponentType();
         }
         
-        assert baseType instanceof DeclaredType : baseType.getClass().getName();   // checker should enforce this
-        String typeName = CompilerUtils.getLoadableName( ( DeclaredType ) baseType ) + arrayDimensions.toString();
-        setType( typeName.toString() );
+        String baseTypeName;
+        if ( baseType instanceof PrimitiveType )
+        {
+            baseTypeName = ( ( PrimitiveType ) baseType ).getKind().name().toLowerCase( );
+        }
+        else
+        {
+            assert baseType instanceof DeclaredType : baseType.getClass().getName();   // checker should enforce this
+            baseTypeName = CompilerUtils.getLoadableName( ( DeclaredType ) baseType );
+        }
+        
+        setType( baseTypeName + arrayDimensions.toString() );
     }
 }

Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/TypeNameType.java	(original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/TypeNameType.java	Wed Oct 20 10:40:34 2004
@@ -27,6 +27,7 @@
 import com.sun.mirror.type.ArrayType;
 import com.sun.mirror.type.ReferenceType;
 import com.sun.mirror.type.PrimitiveType;
+import com.sun.mirror.type.VoidType;
 
 public class TypeNameType
         extends AnnotationMemberType
@@ -54,6 +55,11 @@
         if ( val instanceof PrimitiveType )
         {
             addError( value, "error.primitive-type-not-allowed" );
+            return null;
+        }
+        else if ( val instanceof VoidType )
+        {
+            addError( value, "error.void-type-not-allowed" );
             return null;
         }
         

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/DynaFormData.java
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/DynaFormData.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/DynaFormData.java	Wed Oct 20 10:40:34 2004
@@ -54,7 +54,7 @@
 
     public Object get( Object name )
     {
-        return ( ( DynaValidatorForm ) this ).get( name.toString() );
+        return super.get( name.toString() );
     }
 
     public boolean isEmpty()

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/Forward.java
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/Forward.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/Forward.java	Wed Oct 20 10:40:34 2004
@@ -72,6 +72,20 @@
     private static final String RETURN_TO_PAGE_LEGACY_STR = "page";
     private static final String RETURN_TO_PREVIOUS_ACTION_STR = "previousAction";
     private static final String RETURN_TO_ACTION_LEGACY_STR = "action";
+    
+    private static final Map< String, Class > PRIMITIVE_TYPES = new HashMap< String, Class >();
+    
+    static
+    {
+        PRIMITIVE_TYPES.put( "boolean", boolean.class );
+        PRIMITIVE_TYPES.put( "byte", byte.class );
+        PRIMITIVE_TYPES.put( "char", char.class );
+        PRIMITIVE_TYPES.put( "double", double.class );
+        PRIMITIVE_TYPES.put( "float", float.class );
+        PRIMITIVE_TYPES.put( "int", int.class );
+        PRIMITIVE_TYPES.put( "long", long.class );
+        PRIMITIVE_TYPES.put( "short", short.class );
+    }
 
     private List _outputForms;
     private String _path;
@@ -92,7 +106,6 @@
     private boolean _restoreQueryString = false;
     private boolean _externalRedirect = false;
     
-    
     /**
      * An alternate ModuleConfig from which to resolve forwards if they are not resolved
      * from the stored ActionMapping (and its stored ModuleConfig).
@@ -591,18 +604,21 @@
                         expectedTypeName = expectedTypeName.substring( 0, expectedTypeName.length() - 2 );
                     }
                     
-                    Class expectedType = null;
+                    Class expectedType = PRIMITIVE_TYPES.get( expectedTypeName );
                     
-                    try
+                    if ( expectedType == null )
                     {
-                        expectedType = Class.forName( expectedTypeName );
-                    }
-                    catch ( ClassNotFoundException e )
-                    {
-                        _log.error( "Could not load expected action output type " + expectedTypeName
-                                    + " for action output '" + actionOutput.getName() + "' on forward '"
-                                    + fc.getName() + "'; skipping type check." );
-                        continue;
+                        try
+                        {
+                            expectedType = Class.forName( expectedTypeName );
+                        }
+                        catch ( ClassNotFoundException e )
+                        {
+                            _log.error( "Could not load expected action output type " + expectedTypeName
+                                        + " for action output '" + actionOutput.getName() + "' on forward '"
+                                        + fc.getName() + "'; skipping type check." );
+                            continue;
+                        }
                     }
                     
                     Class actualType = actualActionOutput.getClass();