leosutic 2004/01/14 16:25:11
Modified: attributes/compiler/src/java/org/apache/commons/attributes/compiler
AttributeCompiler.java
attributes/unittest/src/cl1 TestClass.java
attributes/unittest/src/cl2 TestAttribute.java
TestClass.java
attributes/unittest/src/test/org/apache/commons/attributes/test
AttributesTestCase.java Dependency.java
RuntimeSample.java Sample.java SampleIF2.java
SuperSample.java
Added: attributes/compiler/src/java/org/apache/commons/attributes/compiler
AttributeExpressionParser.java
attributes/unittest/src/test/org/apache/commons/attributes/test
BeanAttribute.java
Log:
Added named parameters and attribute packages.
Revision Changes Path
1.7 +183 -134
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AttributeCompiler.java 12 Oct 2003 09:07:45 -0000 1.6
+++ AttributeCompiler.java 15 Jan 2004 00:25:11 -0000 1.7
@@ -103,10 +103,15 @@
private Path src;
private File destDir;
private int numGenerated;
+ private String attributePackages = "";
public AttributeCompiler () {
}
+ public void setAttributePackages (String attributePackages) {
+ this.attributePackages = attributePackages;
+ }
+
public void addFileset (FileSet set) {
super.addFileset (set);
fileSets.add (set);
@@ -164,9 +169,8 @@
String expression = tag.getName () + " " + tag.getValue ();
expression = expression.trim ();
- if (expression.startsWith ("@")) {
- expression = expression.substring (1);
- }
+ // Remove the second @-sign.
+ expression = expression.substring (1);
if (selector != null) {
if (expression.startsWith (".")) {
@@ -188,12 +192,40 @@
}
}
- if (!expression.endsWith (")")) {
- expression = expression + "()";
+ pw.println (" {");
+ outputAttributeExpression (pw, expression, fileName,
tag.getLineNumber (), "_attr");
+ pw.println (" " + collectionName + ".add ( _attr );");
+ pw.println (" }");
+ }
+ }
+ }
+
+ protected void outputAttributeExpression (PrintWriter pw, String expression,
String filename, int line, String tempVariableName) {
+ AttributeExpressionParser.ParseResult result =
AttributeExpressionParser.parse (expression, filename, line);
+ pw.print (" " + result.className + " " + tempVariableName + " =
new " + result.className + "(");
+
+ boolean first = true;
+ Iterator iter = result.arguments.iterator ();
+ while (iter.hasNext ()) {
+ AttributeExpressionParser.Argument arg =
(AttributeExpressionParser.Argument) iter.next ();
+ if (arg.field == null) {
+ if (!first) {
+ pw.print (", ");
}
-
- pw.println (" " + collectionName + ".add (\n" +
- "new " + expression + " // " + fileName + ":" +
tag.getLineNumber () + "\n" +
+ first = false;
+ pw.print (arg.text);
+ }
+ }
+ pw.println (" // " + filename + ":" + line);
+ pw.println (");");
+
+ iter = result.arguments.iterator ();
+ while (iter.hasNext ()) {
+ AttributeExpressionParser.Argument arg =
(AttributeExpressionParser.Argument) iter.next ();
+ if (arg.field != null) {
+ String methodName = "set" + arg.field.substring (0, 1).toUpperCase
() + arg.field.substring (1);
+ pw.println (" " + tempVariableName + "." + methodName +
"(\n" +
+ arg.text + " // " + filename + ":" + line + "\n" +
");");
}
}
@@ -223,7 +255,7 @@
}
return sb.toString ();
}
-
+
protected void generateClass (XClass xClass) throws Exception {
String name = null;
File sourceFile = null;
@@ -270,139 +302,158 @@
destFile.getParentFile ().mkdirs ();
PrintWriter pw = new PrintWriter (new FileWriter (destFile));
-
- if (packageName != null && !packageName.equals ("")) {
- pw.println ("package " + packageName + ";");
- }
-
- copyImports (sourceFile, pw);
-
- pw.println ("public class " + className + "$__attributeRepository
implements org.apache.commons.attributes.AttributeRepositoryClass {");
- {
- pw.println (" private static final java.util.Set classAttributes =
new java.util.HashSet ();");
- pw.println (" private static final java.util.Map fieldAttributes =
new java.util.HashMap ();");
- pw.println (" private static final java.util.Map methodAttributes =
new java.util.HashMap ();");
- pw.println (" private static final java.util.Map
constructorAttributes = new java.util.HashMap ();");
- pw.println ();
-
- pw.println (" static {");
- pw.println (" initClassAttributes ();");
- pw.println (" initMethodAttributes ();");
- pw.println (" initFieldAttributes ();");
- pw.println (" initConstructorAttributes ();");
- pw.println (" }");
- pw.println ();
+ try {
- pw.println (" public java.util.Set getClassAttributes () { return
classAttributes; }");
- pw.println (" public java.util.Map getFieldAttributes () { return
fieldAttributes; }");
- pw.println (" public java.util.Map getConstructorAttributes () {
return constructorAttributes; }");
- pw.println (" public java.util.Map getMethodAttributes () { return
methodAttributes; }");
- pw.println ();
- pw.println (" private static void initClassAttributes () {");
- addExpressions (xClass.getDoc ().getTags (), pw, "classAttributes",
sourceFile.getPath ());
- pw.println (" }");
- pw.println ();
+ if (packageName != null && !packageName.equals ("")) {
+ pw.println ("package " + packageName + ";");
+ }
- // ---- Field Attributes
+ copyImports (sourceFile, pw);
- pw.println (" private static void initFieldAttributes () {");
- pw.println (" java.util.Set attrs = null;");
- for (Iterator iter = xClass.getFields ().iterator (); iter.hasNext ();)
{
- XField member = (XField) iter.next ();
- if (member.getDoc ().getTags ().size () > 0) {
- String key = member.getName ();
-
- pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), pw, "attrs",
sourceFile.getPath ());
- pw.println (" fieldAttributes.put (\"" + key + "\",
attrs);");
- pw.println (" attrs = null;");
- pw.println ();
- }
+ StringTokenizer tok = new StringTokenizer (attributePackages, ";");
+ while (tok.hasMoreTokens ()) {
+ pw.println ("import " + tok.nextToken () + ".*;");
}
- pw.println (" }");
- // ---- Method Attributes
-
- pw.println (" private static void initMethodAttributes () {");
- pw.println (" java.util.Set attrs = null;");
- pw.println (" java.util.List bundle = null;");
- for (Iterator iter = xClass.getMethods ().iterator (); iter.hasNext
();) {
- XMethod member = (XMethod) iter.next ();
- if (member.getDoc ().getTags ().size () > 0) {
- StringBuffer sb = new StringBuffer ();
- sb.append (member.getName ()).append ("(");
- sb.append (getParameterTypes (member.getParameters ()));
- sb.append (")");
- String key = sb.toString ();
-
- pw.println (" bundle = new java.util.ArrayList ();");
- pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), null, pw, "attrs",
sourceFile.getPath ());
- pw.println (" bundle.add (attrs);");
- pw.println (" attrs = null;");
-
- pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), "return", pw,
"attrs", sourceFile.getPath ());
- pw.println (" bundle.add (attrs);");
- pw.println (" attrs = null;");
-
- for (Iterator parameters = member.getParameters ().iterator ();
parameters.hasNext ();) {
- XParameter parameter = (XParameter) parameters.next ();
+ pw.println ("public class " + className + "$__attributeRepository
implements org.apache.commons.attributes.AttributeRepositoryClass {");
+ {
+ pw.println (" private static final java.util.Set classAttributes
= new java.util.HashSet ();");
+ pw.println (" private static final java.util.Map fieldAttributes
= new java.util.HashMap ();");
+ pw.println (" private static final java.util.Map
methodAttributes = new java.util.HashMap ();");
+ pw.println (" private static final java.util.Map
constructorAttributes = new java.util.HashMap ();");
+ pw.println ();
+
+ pw.println (" static {");
+ pw.println (" initClassAttributes ();");
+ pw.println (" initMethodAttributes ();");
+ pw.println (" initFieldAttributes ();");
+ pw.println (" initConstructorAttributes ();");
+ pw.println (" }");
+ pw.println ();
+
+ pw.println (" public java.util.Set getClassAttributes () {
return classAttributes; }");
+ pw.println (" public java.util.Map getFieldAttributes () {
return fieldAttributes; }");
+ pw.println (" public java.util.Map getConstructorAttributes () {
return constructorAttributes; }");
+ pw.println (" public java.util.Map getMethodAttributes () {
return methodAttributes; }");
+ pw.println ();
+
+ pw.println (" private static void initClassAttributes () {");
+ addExpressions (xClass.getDoc ().getTags (), pw, "classAttributes",
sourceFile.getPath ());
+ pw.println (" }");
+ pw.println ();
+
+ // ---- Field Attributes
+
+ pw.println (" private static void initFieldAttributes () {");
+ pw.println (" java.util.Set attrs = null;");
+ for (Iterator iter = xClass.getFields ().iterator (); iter.hasNext
();) {
+ XField member = (XField) iter.next ();
+ if (member.getDoc ().getTags ().size () > 0) {
+ String key = member.getName ();
+
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
- pw.println (" bundle.add (attrs);");
+ addExpressions (member.getDoc ().getTags (), pw, "attrs",
sourceFile.getPath ());
+ pw.println (" fieldAttributes.put (\"" + key + "\",
attrs);");
pw.println (" attrs = null;");
+ pw.println ();
}
-
- pw.println (" methodAttributes.put (\"" + key + "\",
bundle);");
- pw.println (" bundle = null;");
- pw.println ();
- }
- }
- pw.println (" }");
-
-
- // ---- Constructor Attributes
-
- pw.println (" private static void initConstructorAttributes () {");
- pw.println (" java.util.Set attrs = null;");
- pw.println (" java.util.List bundle = null;");
- for (Iterator iter = xClass.getConstructors ().iterator ();
iter.hasNext ();) {
- XConstructor member = (XConstructor) iter.next ();
- if (member.getDoc ().getTags ().size () > 0) {
- StringBuffer sb = new StringBuffer ();
- sb.append ("(");
- sb.append (getParameterTypes (member.getParameters ()));
- sb.append (")");
- String key = sb.toString ();
-
- pw.println (" bundle = new java.util.ArrayList ();");
- pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (), null, pw, "attrs",
sourceFile.getPath ());
- pw.println (" bundle.add (attrs);");
- pw.println (" attrs = null;");
-
- for (Iterator parameters = member.getParameters ().iterator ();
parameters.hasNext ();) {
- XParameter parameter = (XParameter) parameters.next ();
+ }
+ pw.println (" }");
+
+ // ---- Method Attributes
+
+ pw.println (" private static void initMethodAttributes () {");
+ pw.println (" java.util.Set attrs = null;");
+ pw.println (" java.util.List bundle = null;");
+ for (Iterator iter = xClass.getMethods ().iterator (); iter.hasNext
();) {
+ XMethod member = (XMethod) iter.next ();
+ if (member.getDoc ().getTags ().size () > 0) {
+ StringBuffer sb = new StringBuffer ();
+ sb.append (member.getName ()).append ("(");
+ sb.append (getParameterTypes (member.getParameters ()));
+ sb.append (")");
+ String key = sb.toString ();
+
+ pw.println (" bundle = new java.util.ArrayList ();");
+ pw.println (" attrs = new java.util.HashSet ();");
+ addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile.getPath ());
+ pw.println (" bundle.add (attrs);");
+ pw.println (" attrs = null;");
+
pw.println (" attrs = new java.util.HashSet ();");
- addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
+ addExpressions (member.getDoc ().getTags (), "return", pw,
"attrs", sourceFile.getPath ());
pw.println (" bundle.add (attrs);");
pw.println (" attrs = null;");
+
+ for (Iterator parameters = member.getParameters ().iterator
(); parameters.hasNext ();) {
+ XParameter parameter = (XParameter) parameters.next ();
+ pw.println (" attrs = new java.util.HashSet
();");
+ addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
+ pw.println (" bundle.add (attrs);");
+ pw.println (" attrs = null;");
+ }
+
+ pw.println (" methodAttributes.put (\"" + key + "\",
bundle);");
+ pw.println (" bundle = null;");
+ pw.println ();
+ }
+ }
+ pw.println (" }");
+
+
+ // ---- Constructor Attributes
+
+ pw.println (" private static void initConstructorAttributes ()
{");
+ pw.println (" java.util.Set attrs = null;");
+ pw.println (" java.util.List bundle = null;");
+ for (Iterator iter = xClass.getConstructors ().iterator ();
iter.hasNext ();) {
+ XConstructor member = (XConstructor) iter.next ();
+ if (member.getDoc ().getTags ().size () > 0) {
+ StringBuffer sb = new StringBuffer ();
+ sb.append ("(");
+ sb.append (getParameterTypes (member.getParameters ()));
+ sb.append (")");
+ String key = sb.toString ();
+
+ pw.println (" bundle = new java.util.ArrayList ();");
+ pw.println (" attrs = new java.util.HashSet ();");
+ addExpressions (member.getDoc ().getTags (), null, pw,
"attrs", sourceFile.getPath ());
+ pw.println (" bundle.add (attrs);");
+ pw.println (" attrs = null;");
+
+ for (Iterator parameters = member.getParameters ().iterator
(); parameters.hasNext ();) {
+ XParameter parameter = (XParameter) parameters.next ();
+ pw.println (" attrs = new java.util.HashSet
();");
+ addExpressions (member.getDoc ().getTags (),
parameter.getName (), pw, "attrs", sourceFile.getPath ());
+ pw.println (" bundle.add (attrs);");
+ pw.println (" attrs = null;");
+ }
+
+ pw.println (" constructorAttributes.put (\"" + key +
"\", bundle);");
+ pw.println (" bundle = null;");
+ pw.println ();
}
-
- pw.println (" constructorAttributes.put (\"" + key +
"\", bundle);");
- pw.println (" bundle = null;");
- pw.println ();
}
+ pw.println (" }");
}
- pw.println (" }");
+ pw.println ("}");
+
+ pw.close ();
+ } catch (Exception e) {
+ pw.close ();
+ destFile.delete ();
+ throw e;
}
- pw.println ("}");
-
- pw.close ();
}
+ /**
+ * Finds the source file of a class.
+ *
+ * @param qualifiedName the fully qualified class name
+ * @return the file the class is defined in.
+ * @throws BuildException if the file could not be found.
+ */
protected File getSourceFile (String qualifiedName) throws BuildException {
String path = qualifiedName.replace ('.', '/') + ".java";
Iterator iter = fileSets.iterator ();
@@ -425,18 +476,13 @@
}
return false;
}
-
- protected boolean isClassName (String name) {
- StringTokenizer tok = new StringTokenizer (name, ".");
- String lastToken = null;
- while (tok.hasMoreTokens ()) {
- lastToken = tok.nextToken ();
- }
- return Character.isUpperCase (lastToken.charAt (0));
- }
+ /**
+ * Tests if a tag is an attribute. Currently the test is
+ * only "check if it is defined with two @-signs".
+ */
protected boolean isAttribute (XTag tag) {
- return tag.getName ().charAt (0) == '@' || isClassName (tag.getName ());
+ return tag.getName ().charAt (0) == '@';
}
protected void start() throws BuildException {
@@ -457,6 +503,9 @@
log ("Generated attribute information for " + numGenerated + " classes.");
}
+ /**
+ * Checks if a collection of XTags contain any tags specifying attributes.
+ */
protected boolean tagHasAttributes (Collection tags) {
Iterator iter = tags.iterator ();
while (iter.hasNext ()) {
1.1
jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeExpressionParser.java
Index: AttributeExpressionParser.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.attributes.compiler;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
/**
* Parser for attribute expressions.
*/
public class AttributeExpressionParser {
public static class Argument {
public String field;
public String text;
public int length;
public String toString () {
return "[Argument: " + field + ", " + text + ", " + length + "]";
}
}
public static class ParseResult {
public List arguments;
public String className;
}
protected static Argument nextArgument (String string, int startPos, String
filename, int line) {
if (string.charAt (startPos) == ')') {
return null;
}
StringBuffer sb = new StringBuffer ();
int i = startPos;
int depth = 0;
while (!( (string.charAt (i) == ',' || string.charAt (i) == ')') && depth ==
0)) {
switch (string.charAt (i)) {
case '[':
case '{':
case '(': depth++; break;
case ']':
case '}':
case ')': depth--; break;
}
sb.append (string.charAt (i));
i++;
if (i == string.length ()) {
throw new BuildException (filename + ":" + line + ": Unterminated
argument: " + string);
}
}
if (string.charAt (i) == ',') {
i++;
}
String text = sb.toString ();
String field = null;
int eqPos = text.indexOf ('=');
if (eqPos > -1) {
boolean identifier = true;
for (int j = 0; j < eqPos; j++) {
char ch = text.charAt (j);
if (Character.isJavaIdentifierPart (ch) || ch == ' ') {
} else {
identifier = false;
}
}
if (identifier) {
field = text.substring (0, eqPos).trim ();
text = text.substring (eqPos + 1).trim ();
}
}
Argument arg = new Argument ();
arg.text = text;
arg.field = field;
arg.length = i - startPos;
return arg;
}
public static ParseResult parse (String string, String filename, int line) {
StringBuffer sb = new StringBuffer ();
int i = 0;
while (i < string.length () && (Character.isJavaIdentifierPart
(string.charAt (i)) || string.charAt (i) == '.' || string.charAt (i) == ' ')) {
sb.append (string.charAt (i));
i++;
}
if (i == string.length () || string.charAt (i) != '(') {
throw new BuildException (filename + ":" + line + ": Illegal expression:
" + string);
}
ParseResult result = new ParseResult ();
result.className = sb.toString ();
result.arguments = new ArrayList ();
i++;
Argument arg = null;
boolean seenField = false;
while ((arg = nextArgument (string, i, filename, line)) != null) {
if (arg.field != null) {
seenField = true;
}
if (seenField && arg.field == null) {
throw new BuildException (filename + ":" + line + ": Un-named
parameters must come before the named parameters: " + string);
}
result.arguments.add (arg);
i += arg.length;
}
return result;
}
}
1.2 +1 -1
jakarta-commons-sandbox/attributes/unittest/src/cl1/TestClass.java
Index: TestClass.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/cl1/TestClass.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestClass.java 20 Aug 2003 23:16:16 -0000 1.1
+++ TestClass.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -1,6 +1,6 @@
/**
- * @TestAttribute ("1")
+ * @@TestAttribute ("1")
*/
public class TestClass {
1.2 +1 -1
jakarta-commons-sandbox/attributes/unittest/src/cl2/TestAttribute.java
Index: TestAttribute.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/cl2/TestAttribute.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAttribute.java 20 Aug 2003 23:16:16 -0000 1.1
+++ TestAttribute.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -1,6 +1,6 @@
/**
- * @org.apache.commons.attributes.Indexed
+ * @@org.apache.commons.attributes.Indexed ()
*/
public class TestAttribute {
1.2 +2 -2
jakarta-commons-sandbox/attributes/unittest/src/cl2/TestClass.java
Index: TestClass.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/cl2/TestClass.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestClass.java 20 Aug 2003 23:16:16 -0000 1.1
+++ TestClass.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -1,11 +1,11 @@
/**
- * @TestAttribute ("2")
+ * @@TestAttribute ("2")
*/
public class TestClass {
/**
- * @TestAttribute ("2inner")
+ * @@TestAttribute ("2inner")
*/
public static class Inner {}
1.6 +11 -0
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AttributesTestCase.java 28 Dec 2003 20:40:53 -0000 1.5
+++ AttributesTestCase.java 15 Jan 2004 00:25:11 -0000 1.6
@@ -251,4 +251,15 @@
assertTrue (Attributes.hasAttributeType (c, Dependency.class));
assertTrue (Attributes.hasAttribute (c, new Dependency (
SampleService.class, "inner-sample" )));
}
+
+ public void testNamedParameters () throws Exception {
+ Method m = Sample.class.getMethod ("methodWithNamedParameters", new
Class[]{ });
+ assertEquals (1, Attributes.getAttributes (m).size ());
+ 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.setAnotherNumber (42);
+ assertTrue (Attributes.hasAttribute (m, ba));
+ }
}
1.2 +1 -1
jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Dependency.java
Index: Dependency.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Dependency.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Dependency.java 20 Aug 2003 23:16:16 -0000 1.1
+++ Dependency.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -3,7 +3,7 @@
/**
* Declares a dependency.
*
- * @org.apache.commons.attributes.Inheritable
+ * @@org.apache.commons.attributes.Inheritable()
*/
public class Dependency {
1.2 +9 -0
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RuntimeSample.java 28 Dec 2003 20:40:37 -0000 1.1
+++ RuntimeSample.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -20,6 +20,11 @@
rar.addMethodAttribute ("someMethod", new Class[]{ Integer.TYPE }, new
Dependency ( SampleService.class, "sample-some-method2" ));
+ BeanAttribute ba = new BeanAttribute (1, "a");
+ ba.setAnotherNumber (56 - 14);
+ ba.setName ("John Smith");
+ rar.addMethodAttribute ("methodWithNamedParameters", new Class[]{}, ba);
+
Attributes.setAttributes (rar);
} catch (Exception e) {
throw new Error ("Unable to set attribute information: " + e.toString
());
@@ -39,6 +44,10 @@
}
public void someMethod (int parameter) {
+
+ }
+
+ public void methodWithNamedParameters () {
}
1.3 +12 -5
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Sample.java 20 Sep 2003 15:11:34 -0000 1.2
+++ Sample.java 15 Jan 2004 00:25:11 -0000 1.3
@@ -1,27 +1,27 @@
package org.apache.commons.attributes.test;
/**
- * @ThreadSafe ()
- * @Dependency ( SampleService.class, "sample" )
+ * @@ThreadSafe ()
+ * @@Dependency ( SampleService.class, "sample" )
*/
public class Sample extends SuperSample implements SampleIFJoin {
/**
- * @ThreadSafe ()
+ * @@ThreadSafe ()
*/
public Object field;
public Object noAttributesInSubClass;
/**
- * @Dependency ( SampleService.class, "sample-some-method1" )
+ * @@Dependency ( SampleService.class, "sample-some-method1" )
*/
public void someMethod () {
}
/**
- * @@.param2 ThreadSafe
+ * @@.param2 ThreadSafe ()
* @@.return Dependency ( SampleService.class, "sample-return" )
*/
public Integer methodWithAttributes (int param1, int param2) {
@@ -32,6 +32,13 @@
* @@Dependency ( SampleService.class, "sample-some-method2" )
*/
public void someMethod (int parameter) {
+
+ }
+
+ /**
+ * @@BeanAttribute ( 1, "a", anotherNumber = (56 - 14), name = "John Smith" )
+ */
+ public void methodWithNamedParameters () {
}
1.2 +3 -3
jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SampleIF2.java
Index: SampleIF2.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SampleIF2.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SampleIF2.java 20 Aug 2003 23:16:16 -0000 1.1
+++ SampleIF2.java 15 Jan 2004 00:25:11 -0000 1.2
@@ -1,13 +1,13 @@
package org.apache.commons.attributes.test;
/**
- * @Dependency ( SampleService.class, "sample-if-2-c" )
+ * @@Dependency ( SampleService.class, "sample-if-2-c" )
*/
public interface SampleIF2 {
/**
- * @Dependency ( SampleService.class, "sample-if-2" )
- * @ThreadSafe ()
+ * @@Dependency ( SampleService.class, "sample-if-2" )
+ * @@ThreadSafe ()
*/
public void someMethod (int parameter);
}
1.3 +8 -8
jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SuperSample.java
Index: SuperSample.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SuperSample.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SuperSample.java 29 Sep 2003 21:17:08 -0000 1.2
+++ SuperSample.java 15 Jan 2004 00:25:11 -0000 1.3
@@ -1,30 +1,30 @@
package org.apache.commons.attributes.test;
/**
- * @Dependency ( SampleService.class, "super-sample" )
+ * @@Dependency ( SampleService.class, "super-sample" )
*/
public class SuperSample {
/**
- * @ThreadSafe ()
- * @Dependency ( SampleService.class, "super-field" )
+ * @@ThreadSafe ()
+ * @@Dependency ( SampleService.class, "super-field" )
*/
public Object field;
/**
- * @Dependency ( SampleService.class, "super-noattrs" )
+ * @@Dependency ( SampleService.class, "super-noattrs" )
*/
public Object noAttributesInSubClass;
/**
- * @Dependency ( SampleService.class, "sample-ctor1" )
+ * @@Dependency ( SampleService.class, "sample-ctor1" )
*/
public SuperSample () {
}
/**
- * @Dependency ( SampleService.class, "sample-ctor2" )
+ * @@Dependency ( SampleService.class, "sample-ctor2" )
* @@.array ThreadSafe()
*/
public SuperSample (String input, String[][] array) {
@@ -32,8 +32,8 @@
}
/**
- * @Dependency ( SampleService.class, "super-some-method-sample" )
- * @ThreadSafe ()
+ * @@Dependency ( SampleService.class, "super-some-method-sample" )
+ * @@ThreadSafe ()
*/
public void someMethod (int parameter) {
1.1
jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/BeanAttribute.java
Index: BeanAttribute.java
===================================================================
package org.apache.commons.attributes.test;
/**
* A sample attribute with bean-like properties. Used to test the
* named parameter syntax.
*
* @org.apache.commons.attributes.Inheritable
*/
public class BeanAttribute {
private final int number;
private final String string;
private String name;
private int anotherNumber;
public BeanAttribute (int number, String string) {
this.number = number;
this.string = string;
}
public int getNumber () {
return number;
}
public String getString () {
return string;
}
public String getName () {
return name;
}
public int getAnotherNumber () {
return anotherNumber;
}
public void setAnotherNumber (int anotherNumber) {
this.anotherNumber = anotherNumber;
}
public void setName (String name) {
this.name = name;
}
public boolean equals (Object o) {
return o instanceof BeanAttribute &&
((BeanAttribute) o).string.equals (string) &&
((BeanAttribute) o).anotherNumber == anotherNumber &&
((BeanAttribute) o).number == number &&
((BeanAttribute) o).name.equals (name);
}
public int hashCode () {
return string.hashCode ();
}
public String toString () {
return "[BeanAttribute " + number + ", " + string + "; " + name + ", " +
anotherNumber + "\"]";
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]