commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test AttributesTestCase.java BeanAttribute.java RuntimeSample.java Sample.java
Date Thu, 15 Jan 2004 21:04:14 GMT
leosutic    2004/01/15 13:04:13

  Modified:    attributes/api/src/java overview.html
               attributes/api/src/java/org/apache/commons/attributes
                        Inheritable.java
               attributes/compiler/src/java/org/apache/commons/attributes/compiler
                        AttributeCompiler.java
                        AttributeExpressionParser.java
               attributes/site/xdocs index.xml
               attributes/unittest/src/test/org/apache/commons/attributes/test
                        AttributesTestCase.java BeanAttribute.java
                        RuntimeSample.java Sample.java
  Log:
  Addition of a Sealable interface to indicate that an attribute instance can
  become read-only.
  
  Correction of string literal handling.
  
  Corrected docs - removed references to old syntax.
  
  Revision  Changes    Path
  1.4       +5 -11     jakarta-commons-sandbox/attributes/api/src/java/overview.html
  
  Index: overview.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/overview.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- overview.html	20 Sep 2003 15:11:34 -0000	1.3
  +++ overview.html	15 Jan 2004 21:04:13 -0000	1.4
  @@ -10,7 +10,7 @@
           <blockquote><pre>public class MyAttribute {}
   
   /**
  - * @@MyAttribute
  + * @@MyAttribute()
    */
   public class MyClass { }</pre></blockquote>
           
  @@ -193,8 +193,8 @@
           <blockquote><pre>public class MyClass {
   
       /**
  -     * @@.myParameter MyOtherAttribute
  -     * @@.return MyAttribute
  +     * @@.myParameter MyOtherAttribute()
  +     * @@.return MyAttribute()
        */
       public Integer myMethod (int myParameter) {};
   
  @@ -208,8 +208,8 @@
           <p>Let's define the question a bit stricter. Suppose you have an attribute
(MyAttribute), and you have a class MyClass:</p>
           
           <blockquote><pre>/**
  - * @@MyAttribute
  - * @@MyAttribute
  + * @@MyAttribute()
  + * @@MyAttribute()
    */
   public class MyClass {}</pre></blockquote>
           
  @@ -234,15 +234,9 @@
           <p>The above also holds true if the attribute has been inherited.</p>
           
           
  -        <h3>What syntax is preferred for attributes - <code>@AttributeName</code>
or <code>@@AttributeName</code>?</h3>
  -        
  -        <p><code>@@AttributeName</code>, since this explicitely tells
the compiler that this is an attribute, and eliminates a lot of guesswork.</p>
  -        
  -        
           <h3>What are the requirements for an attribute class?</h3>
           
           <p>It must have a public constructor. That's all.</p>
  -        
         
           
           <h3>I tried adding attributes to an anonymous class and it didn't work.</h3>
  
  
  
  1.4       +2 -1      jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Inheritable.java
  
  Index: Inheritable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Inheritable.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Inheritable.java	12 Oct 2003 09:07:30 -0000	1.3
  +++ Inheritable.java	15 Jan 2004 21:04:13 -0000	1.4
  @@ -59,7 +59,8 @@
   /**
    * This attribute is used to mark attributes as being inheritable.
    * Inheritable attributes are inherited down the class and interface
  - * hierarchy. See Dependency for an example of an inheritable attribute.
  + * hierarchy. See Dependency in the unit tests for an example of an 
  + * inheritable attribute.
    */
   public class Inheritable {
   }
  
  
  
  1.8       +9 -8      jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java
  
  Index: AttributeCompiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AttributeCompiler.java	15 Jan 2004 00:25:11 -0000	1.7
  +++ AttributeCompiler.java	15 Jan 2004 21:04:13 -0000	1.8
  @@ -88,11 +88,16 @@
    * <pre><code>
    *     &lt;taskdef resource="org/apache/commons/attributes/anttasks.properties"/&gt;
    *     
  - *     &lt;attribute-compiler destDir="temp/"&gt;
  + *     &lt;attribute-compiler destDir="temp/"&gt; attributepackages="my.attributes;my.otherattributes"
    *         &lt;fileset dir="src/" includes="*.java"/&gt;
    *     &lt;/attribute-compiler&gt;
    * </code></pre>
    *
  + * <ul>
  + * <li>destDir<dd>Destination directory for generated source files
  + * <li>attributepackages<dd>A set of package names that will be automatically
searched for attributes.
  + * </ul>
  + *
    * The task should be run before compiling the Java sources, and will produce some
    * additional Java source files in the destination directory that should be compiled
    * along with the input source files. (See the overview for a diagram.)
  @@ -134,13 +139,6 @@
           }
       }
       
  -    /**
  -     * This attribute is only set when the compiler is running in Maven.
  -     * Grab all POM-related parameters here.
  -     */
  -    public void setInmaven (boolean inMaven) {
  -    }
  -    
       protected void copyImports (File source, PrintWriter dest) throws Exception {
           BufferedReader br = new BufferedReader (new FileReader (source));
           try {
  @@ -194,6 +192,9 @@
                   
                   pw.println ("        {");
                   outputAttributeExpression (pw, expression, fileName, tag.getLineNumber
(), "_attr");
  +                pw.println ("        if (_attr instanceof org.apache.commons.attributes.Sealable)
{");
  +                pw.println ("            ((org.apache.commons.attributes.Sealable) _attr).seal
();");
  +                pw.println ("        }");
                   pw.println ("        " + collectionName + ".add ( _attr );");
                   pw.println ("        }");
               }
  
  
  
  1.2       +26 -3     jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeExpressionParser.java
  
  Index: AttributeExpressionParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeExpressionParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeExpressionParser.java	15 Jan 2004 00:25:11 -0000	1.1
  +++ AttributeExpressionParser.java	15 Jan 2004 21:04:13 -0000	1.2
  @@ -64,9 +64,9 @@
   /**
    * Parser for attribute expressions.
    */
  -public class AttributeExpressionParser {
  +class AttributeExpressionParser {
       
  -    public static class Argument {
  +    static class Argument {
           public String field;
           public String text;
           public int length;
  @@ -76,7 +76,7 @@
           }
       }
       
  -    public static class ParseResult {
  +    static class ParseResult {
           public List arguments;
           public String className;
       }
  @@ -99,6 +99,29 @@
               case ']':
               case '}':
               case ')': depth--; break;
  +                
  +            case '\'':
  +            case '"': {
  +                    // handle string literals
  +                    char endChar = string.charAt (i);
  +                    sb.append (string.charAt (i));
  +                    i++;
  +                    while (true) {
  +                        char ch = string.charAt (i);
  +                        if (ch == '\\') {
  +                            sb.append (ch);
  +                            i++;
  +                            ch = string.charAt (i);
  +                            sb.append (ch);
  +                        } else {
  +                            if (ch == endChar) {
  +                                break;
  +                            }
  +                            sb.append (ch);                            
  +                        }
  +                        i++;
  +                    }
  +                }
               }
               
               sb.append (string.charAt (i));
  
  
  
  1.7       +8 -3      jakarta-commons-sandbox/attributes/site/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/site/xdocs/index.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- index.xml	20 Sep 2003 15:11:34 -0000	1.6
  +++ index.xml	15 Jan 2004 21:04:13 -0000	1.7
  @@ -61,7 +61,7 @@
   /**
    * Make this attribute inheritable...
    * 
  - * @@Inheritable
  + * @@Inheritable()
    */
   public class MyAttribute {
       private final float value;
  @@ -127,13 +127,18 @@
                   </tr>
                   <tr>
                       <td>Attribute inheritance</td>
  -                    <td>Yes, add the @@Inheritable attribue to any attribute you
wish to be inheritable.</td>
  +                    <td>Yes, add the @@Inheritable() attribue to any attribute you
wish to be inheritable.</td>
                   </tr>
                   <tr>
                       <td>Inheritance without access to superclass source code</td>
                       <td>Yes</td>
                   </tr>
                   <tr>
  +                    <td>Named parameters in attribute declaration</td>
  +                    <td>Yes, corresponds to setter methods. A Sealable interface
enables the instance to
  +                        become read-only when all relevant setters have been called.</td>
  +                </tr>
  +                <tr>
                       <td>Ability to quickly find all classes with a specific attribute</td>
                       <td>Yes, via attribute indexes.</td>
                   </tr>
  @@ -163,7 +168,7 @@
                   </tr>
                   <tr>
                       <td>Runtime code size</td>
  -                    <td>17kB</td>
  +                    <td>21kB</td>
                   </tr>
                   <tr>
                       <td>Unit test coverage</td>
  
  
  
  1.7       +13 -1     jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/AttributesTestCase.java
  
  Index: AttributesTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/AttributesTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AttributesTestCase.java	15 Jan 2004 00:25:11 -0000	1.6
  +++ AttributesTestCase.java	15 Jan 2004 21:04:13 -0000	1.7
  @@ -258,8 +258,20 @@
           assertEquals (1, Attributes.getAttributes (m, BeanAttribute.class).size ());
           assertTrue (Attributes.hasAttributeType (m, BeanAttribute.class));
           BeanAttribute ba = new BeanAttribute (1, "a");
  -        ba.setName ("John Smith");
  +        ba.setName ("Smith, John \"Agent\"");
           ba.setAnotherNumber (42);
           assertTrue (Attributes.hasAttribute (m, ba));
  +    }
  +    
  +    public void testSealable () throws Exception {
  +        Method m = Sample.class.getMethod ("methodWithNamedParameters", new Class[]{ });
  +        BeanAttribute attribute = (BeanAttribute) Attributes.getAttributes (m, BeanAttribute.class).iterator
().next ();
  +        
  +        try {
  +            attribute.setName ("Joe Doe");
  +            fail ("Attribute should be sealed!");
  +        } catch (IllegalStateException ise) {
  +            // -- OK, attribute should be sealed.
  +        }
       }
   }
  
  
  
  1.3       +17 -1     jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/BeanAttribute.java
  
  Index: BeanAttribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/BeanAttribute.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BeanAttribute.java	15 Jan 2004 00:27:26 -0000	1.2
  +++ BeanAttribute.java	15 Jan 2004 21:04:13 -0000	1.3
  @@ -1,21 +1,31 @@
   package org.apache.commons.attributes.test;
   
  +import org.apache.commons.attributes.Sealable;
  +
   /**
    * A sample attribute with bean-like properties. Used to test the 
    * named parameter syntax.
    */
  -public class BeanAttribute {
  +public class BeanAttribute implements Sealable {
       
       private final int number;
       private final String string;
       private String name;
       private int anotherNumber;
       
  +    private boolean sealed = false;
  +    
       public BeanAttribute (int number, String string) {
           this.number = number;
           this.string = string;
       }
       
  +    protected void checkSealed () {
  +        if (sealed) {
  +            throw new IllegalStateException ("Attribute has been sealed and is read-only.");
  +        }
  +    }
  +    
       public int getNumber () {
           return number;
       }
  @@ -33,10 +43,12 @@
       }
       
       public void setAnotherNumber (int anotherNumber) {
  +        checkSealed ();
           this.anotherNumber = anotherNumber;
       }
       
       public void setName (String name) {
  +        checkSealed ();
           this.name = name;
       }
       
  @@ -50,6 +62,10 @@
       
       public int hashCode () {
           return string.hashCode ();
  +    }
  +    
  +    public void seal () {
  +        sealed = true;
       }
       
       public String toString () {
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/RuntimeSample.java
  
  Index: RuntimeSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/RuntimeSample.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RuntimeSample.java	15 Jan 2004 00:25:11 -0000	1.2
  +++ RuntimeSample.java	15 Jan 2004 21:04:13 -0000	1.3
  @@ -22,7 +22,7 @@
               
               BeanAttribute ba = new BeanAttribute (1, "a");
               ba.setAnotherNumber (56 - 14);
  -            ba.setName ("John Smith");
  +            ba.setName ("Smith, John \"Agent\"");
               rar.addMethodAttribute ("methodWithNamedParameters", new Class[]{}, ba);
               
               Attributes.setAttributes (rar);
  
  
  
  1.4       +1 -1      jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Sample.java
  
  Index: Sample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Sample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Sample.java	15 Jan 2004 00:25:11 -0000	1.3
  +++ Sample.java	15 Jan 2004 21:04:13 -0000	1.4
  @@ -36,7 +36,7 @@
       }
       
       /**
  -     * @@BeanAttribute ( 1, "a", anotherNumber = (56 - 14), name = "John Smith" )
  +     * @@BeanAttribute ( 1, "a", anotherNumber = (56 - 14), name = "Smith, John \"Agent\""
)
        */
       public void methodWithNamedParameters () {
           
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message