Author: nickarls
Date: 2008-11-27 17:49:18 -0500 (Thu, 27 Nov 2008)
New Revision: 373
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
Log:
javadocs/comments/toStrings
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import javax.webbeans.manager.Context;
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -30,7 +30,7 @@
{
/**
- * Gets the value of the parameter
+ * Gets the actual value of the parameter from the manager
*
* @param manager The Web Beans Manager
* @return The value
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -73,6 +73,24 @@
return delegate;
}
+ /**
+ * Gets a string representation of the Map
+ *
+ * @return A string representation
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Annotation type -> annotation mappings: " +
super.size() + "\n");
+ int i = 0;
+ for (Entry<Class<? extends Annotation>, Annotation> entry :
delegate.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().toString() + ":
" + entry.getValue().toString() + "\n");
+ }
+ return buffer.toString();
+ }
+
}
/**
@@ -118,6 +136,27 @@
return annotations;
}
+ /**
+ * Gets a string representation of the Map
+ *
+ * @return A string representation
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Annotation type -> meta annotation mappings: " +
super.size() + "\n");
+ int i = 0;
+ for (Entry<Class<? extends Annotation>, Set<Annotation>> entry
: delegate.entrySet())
+ {
+ for (Annotation annotation : entry.getValue())
+ {
+ buffer.append(++i + " - " + entry.getKey().toString() + ":
" + annotation.toString() + "\n");
+ }
+ }
+ return buffer.toString();
+ }
+
}
// The array of default binding types
@@ -131,7 +170,8 @@
// The annotation map (annotation type -> annotation) of the item
private AnnotationMap annotationMap;
- // The meta-annotation map (annotation type -> set of annotations containing
meta-annotation) of the item
+ // The meta-annotation map (annotation type -> set of annotations containing
+ // meta-annotation) of the item
private MetaAnnotationMap metaAnnotationMap;
// The set of all annotations on the item
private Set<Annotation> annotationSet;
@@ -234,6 +274,8 @@
*
* @param annotationType the annotation type to match
* @return The annotation if found, null if no match was found
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getAnnotation(Class)
*/
@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<? extends A>
annotationType)
@@ -247,6 +289,8 @@
* @param metaAnnotationType The meta-annotation type to match
* @return The set of annotations containing this meta-annotation. An empty
* set is returned if no match is found.
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getMetaAnnotations(Class)
*/
public Set<Annotation> getMetaAnnotations(Class<? extends Annotation>
metaAnnotationType)
{
@@ -262,6 +306,8 @@
* @param metaAnnotationType meta-annotation type to match
* @return The array of annotations to match. An empty array is returned if
* no match is found.
+ *
+ * @see
org.jboss.webbeans.introspector.AnnotatedItem#getMetaAnnotationsAsArray(Class)
*/
public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation>
metaAnnotationType)
{
@@ -279,6 +325,8 @@
* Populates the annotationSet if it was empty
*
* @return The set of annotations on this item.
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getAnnotations()
*/
public Set<Annotation> getAnnotations()
{
@@ -295,6 +343,8 @@
*
* @param annotatedType The annotation type to check for
* @return True if present, false otherwise.
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isAnnotationPresent(Class)
*/
public boolean isAnnotationPresent(Class<? extends Annotation> annotatedType)
{
@@ -334,6 +384,8 @@
*
* @param that The other annotated item to check against
* @return True if assignable, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isAssignableFrom(AnnotatedItem)
*/
public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
{
@@ -345,6 +397,8 @@
*
* @param types The set of types to check against
* @return True if assignable, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isAssignableFrom(Set)
*/
public boolean isAssignableFrom(Set<Class<?>> types)
{
@@ -389,22 +443,17 @@
@Override
public String toString()
{
- String string = getType().toString();
- if (getActualTypeArguments().length > 0)
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AbstractAnnotatedItem:\n");
+ buffer.append("Annotations: " + getAnnotations().size() +
"\n");
+ int i = 0;
+ for (Annotation annotation : getAnnotations())
{
- string += "<";
- for (int i = 0; i < getActualTypeArguments().length; i++)
- {
- string += getActualTypeArguments()[i].toString();
- if (i < getActualTypeArguments().length - 1)
- {
- string += ",";
- }
- }
- string += ">";
+ buffer.append(++i + " - " + annotation.toString() + "\n");
}
- string += getAnnotations();
- return string;
+ buffer.append(annotationMap == null ? "" : (annotationMap.toString() +
"\n"));
+ buffer.append(metaAnnotationMap == null ? "" :
(metaAnnotationMap.toString()) + "\n");
+ return buffer.toString();
}
/**
@@ -414,6 +463,8 @@
* meta-annotation. Returns default binding (current) if none specified.
*
* @return A set of (binding type) annotations
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getBindingTypes()
*/
public Set<Annotation> getBindingTypes()
{
@@ -434,6 +485,8 @@
* meta-annotation. Returns default binding (current) if none specified.
*
* @return An array of (binding type) annotations
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getBindingTypesAsArray()
*/
public Annotation[] getBindingTypesAsArray()
{
@@ -451,6 +504,8 @@
* Indicates if the type is proxyable to a set of pre-defined rules
*
* @return True if proxyable, false otherwise.
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isProxyable()
*/
public boolean isProxyable()
{
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -51,6 +51,8 @@
* Indicates if the member is static (through the delegate)
*
* @return True if static, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isStatic()
*/
public boolean isStatic()
{
@@ -61,6 +63,8 @@
* Indicates if the member if final (through the delegate)
*
* @return True if final, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isFinal()
*/
public boolean isFinal()
{
@@ -82,6 +86,8 @@
* Gets the name of the member
*
* @returns The name (or the name of the delegate if none is defined)
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getName()
*/
public String getName()
{
@@ -92,4 +98,21 @@
return name;
}
+ /**
+ * Gets a string representation of the member
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AbstractAnnotatedMember:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Final: " + isFinal() + "\n");
+ buffer.append("Static: " + isStatic() + "\n");
+ buffer.append("Name: " + getName() + "\n");
+ return buffer.toString();
+ }
+
+
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -321,5 +321,17 @@
{
return declaringClass;
}
+
+ /**
+ * Gets a string representation of the constructor
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ return buffer.toString();
+ }
+
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -26,14 +26,31 @@
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.Reflections;
+/**
+ * Represents an annotated field
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class AnnotatedFieldImpl<T> extends AbstractAnnotatedMember<T, Field>
implements AnnotatedField<T>
{
-
+ // The actual type arguments
private Type[] actualTypeArguments = new Type[0];
-
+ // The underlying field
private Field field;
+ // The abstraction of the declaring class
private AnnotatedType<?> declaringClass;
-
+
+ /**
+ * Constructor
+ *
+ * Initializes the superclass with the built annotation map and detects the
+ * type arguments
+ *
+ * @param field The actual field
+ * @param declaringClass The abstraction of the declaring class
+ */
public AnnotatedFieldImpl(Field field, AnnotatedType<?> declaringClass)
{
super(buildAnnotationMap(field));
@@ -46,6 +63,11 @@
}
}
+ /**
+ * Gets the underlying field
+ *
+ * @return The fields
+ */
public Field getAnnotatedField()
{
return field;
@@ -55,30 +77,87 @@
{
return field;
}
-
+
+ /**
+ * Gets the type
+ *
+ * @return The type
+ */
+ @SuppressWarnings("unchecked")
public Class<T> getType()
{
return (Class<T>) field.getType();
}
-
+
+ /**
+ * Gets the actual type arguments
+ *
+ * @return The type arguments
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedField#getActualTypeArguments()
+ */
public Type[] getActualTypeArguments()
{
return actualTypeArguments;
}
+ /**
+ * Gets the current value and injects this instance into an instance
+ *
+ * @param instance The instance to inject into
+ * @param manager The Web Beans manager
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedField#inject(Object, ManagerImpl)
+ */
public void inject(Object instance, ManagerImpl manager)
{
Reflections.setAndWrap(getDelegate(), instance, getValue(manager));
}
-
+
+ /**
+ * Gets the property name
+ *
+ * @return The property name
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedField#getName()
+ */
public String getPropertyName()
{
return getName();
}
-
+
+ /**
+ * Gets the abstracted declaring class
+ *
+ * @return The declaring class
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedField#getDeclaringClass()
+ */
public AnnotatedType<?> getDeclaringClass()
{
return declaringClass;
}
+ /**
+ * Gets a string representation of the field
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AnnotatedFieldImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Actual type arguments: " + actualTypeArguments.length +
"\n");
+ int i = 0;
+ for (Type actualTypeArgument : actualTypeArguments)
+ {
+ buffer.append(++i + " - " + actualTypeArgument.toString());
+ }
+ buffer.append("Declaring class:\n");
+ buffer.append(declaringClass.toString() + "\n");
+ buffer.append("Field: " + field + "\n");
+ return buffer.toString();
+ }
+
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -23,24 +23,58 @@
import javax.webbeans.TypeLiteral;
+/**
+ * Represents an annotated item
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ * @param <S>
+ */
public class AnnotatedItemImpl<T, S> extends AbstractAnnotatedItem<T, S>
{
-
+ // The actual type arguments
private Type[] actualTypeArguments = new Type[0];
+ // The type of the item
private Class<T> type;
+ // The actual annotations
private Annotation[] actualAnnotations;
-
+
+ /**
+ * Constructor
+ *
+ * Initializes the superclass with the annotation map
+ *
+ * @param annotationMap The annotated map
+ */
private AnnotatedItemImpl(AnnotationMap annotationMap)
{
super(annotationMap);
}
-
+
+ /**
+ * Constructor
+ *
+ * Initializes the superclass with the annotation map and sets the type
+ *
+ * @param annotationMap The annotation map
+ * @param type The type of the item
+ */
private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type)
{
super(annotationMap);
this.type = type;
}
-
+
+ /**
+ * Constructor
+ *
+ * Initializes the superclass with the annotation map, sets the api type and
+ * determines the type arguments
+ *
+ * @param annotationMap The annotation map
+ * @param apiType The api type
+ */
private AnnotatedItemImpl(AnnotationMap annotationMap, TypeLiteral<T> apiType)
{
super(annotationMap);
@@ -50,70 +84,173 @@
actualTypeArguments = ((ParameterizedType)
apiType.getType()).getActualTypeArguments();
}
}
-
+
+ /**
+ * Constructor
+ *
+ * @param annotationMap The annotation map
+ * @param type The type
+ * @param actualTypeArguments The actual type arguments
+ */
private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type, Type[]
actualTypeArguments)
{
this(annotationMap, type);
this.actualTypeArguments = actualTypeArguments;
}
-
+
+ /**
+ * Constructor
+ *
+ * @param annotations The annotations array of the type
+ */
public AnnotatedItemImpl(Annotation[] annotations)
{
this(buildAnnotationMap(annotations));
this.actualAnnotations = annotations;
}
-
+
+ /**
+ * Constructor
+ *
+ * @param annotations The annotations array of the type
+ * @param type The type
+ */
public AnnotatedItemImpl(Annotation[] annotations, Class<T> type)
{
this(buildAnnotationMap(annotations), type);
this.actualAnnotations = annotations;
}
-
+
+ /**
+ * Constructor
+ *
+ * @param annotations The annotations array of the type
+ * @param apiType The API typeliteral
+ */
public AnnotatedItemImpl(Annotation[] annotations, TypeLiteral<T> apiType)
{
this(buildAnnotationMap(annotations), apiType);
this.actualAnnotations = annotations;
}
-
+
+ /**
+ * Constructor
+ *
+ * @param annotations The annotations array of the type
+ * @param type The type of the item
+ * @param actualTypeArguments The actual type arguments array
+ */
public AnnotatedItemImpl(Annotation[] annotations, Class<T> type, Type[]
actualTypeArguments)
{
this(buildAnnotationMap(annotations), type, actualTypeArguments);
this.actualAnnotations = annotations;
}
+ /**
+ * Gets the delegate (null)
+ *
+ * @return null
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getDelegate()
+ */
public S getDelegate()
{
return null;
}
-
+
+ /**
+ * Gets the item type
+ *
+ * @return The type
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getType()
+ */
public Class<T> getType()
{
return type;
}
+ /**
+ * Gets the actual type arguments
+ *
+ * @return The actual type arguments array
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getActualTypeArguments()
+ */
public Type[] getActualTypeArguments()
{
return actualTypeArguments;
}
-
+
+ /**
+ * Gets the actual annotations
+ *
+ * @return The annotations array
+ */
public Annotation[] getActualAnnotations()
{
return actualAnnotations;
}
-
+
+ /**
+ * Indicates if the item is static
+ *
+ * @return false
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isStatic()
+ */
public boolean isStatic()
{
return false;
}
-
+
+ /**
+ * Indicates if the item is final
+ *
+ * @return false
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isFinal()
+ */
public boolean isFinal()
{
return false;
}
+ /**
+ * Gets the name. Should be overridden
+ *
+ * @throws IllegalArgumentException.
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getName()
+ */
public String getName()
{
throw new IllegalArgumentException("Unable to determine name");
}
-
+
+ /**
+ * Gets a string representation of the item
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AnnotatedItemImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Actual type arguments: " + actualTypeArguments.length +
"\n");
+ int i = 0;
+ for (Type actualTypeArgument : actualTypeArguments)
+ {
+ buffer.append(++i + " - " + actualTypeArgument.toString());
+ }
+ buffer.append("Actual annotations: " + actualAnnotations.length +
"\n");
+ i = 0;
+ for (Annotation actualAnnotation : actualAnnotations)
+ {
+ buffer.append(++i + " - " + actualAnnotation.toString());
+ }
+ return buffer.toString();
+ }
+
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -32,20 +32,79 @@
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.Reflections;
+import com.google.common.collect.ForwardingMap;
+
+/**
+ * Represents an annotated method
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class AnnotatedMethodImpl<T> extends AbstractAnnotatedMember<T,
Method> implements AnnotatedMethod<T>
{
-
+ /**
+ * A annotation type -> list of parameter abstractions with given annotations
+ * present mapping
+ */
+ private class AnnotatedParameters extends ForwardingMap<Class<? extends
Annotation>, List<AnnotatedParameter<Object>>>
+ {
+ private Map<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>> delegate;
+
+ public AnnotatedParameters()
+ {
+ delegate = new HashMap<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>>();
+ }
+
+ @Override
+ protected Map<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>> delegate()
+ {
+ return delegate;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Annotation -> parameter mappings: " + super.size() +
"\n");
+ int i = 0;
+ for (Entry<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>> entry : delegate.entrySet())
+ {
+ for (AnnotatedParameter<?> parameter : entry.getValue())
+ {
+ buffer.append(++i + " - " + entry.getKey().toString() + ":
" + parameter.toString() + "\n");
+ }
+ }
+ return buffer.toString();
+ }
+ }
+
+ // The actual type arguments
private Type[] actualTypeArguments = new Type[0];
-
+ // The underlying method
private Method method;
-
+
+ // The abstracted parameters
private List<AnnotatedParameter<Object>> parameters;
- private Map<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>> annotatedParameters;
+ // A mapping from annotation type to parameter abstraction with that
+ // annotation present
+ private AnnotatedParameters annotatedParameters;
+ // The property name
private String propertyName;
+ // The abstracted declaring class
private AnnotatedType<?> declaringClass;
-
+
+ /**
+ * Constructor
+ *
+ * Initializes the superclass with the built annotation map, sets the method
+ * and declaring class abstraction and detects the actual type arguments
+ *
+ * @param method The underlying method
+ * @param declaringClass The declaring class abstraction
+ */
public AnnotatedMethodImpl(Method method, AnnotatedType<?> declaringClass)
{
super(buildAnnotationMap(method));
@@ -57,26 +116,58 @@
}
}
+ /**
+ * Gets the annotated method
+ *
+ * @return The method
+ */
public Method getAnnotatedMethod()
{
return method;
}
+ /**
+ * Gets the delegate
+ *
+ * @return The delegate
+ */
public Method getDelegate()
{
return method;
}
-
+
+ /**
+ * Gets the type of the method
+ *
+ * @return The return type of the method
+ */
+ @SuppressWarnings("unchecked")
public Class<T> getType()
{
return (Class<T>) method.getReturnType();
}
-
+
+ /**
+ * Gets the actual type arguments
+ *
+ * @return The actual type arguments
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getActualTypeArguments()
+ */
public Type[] getActualTypeArguments()
{
return actualTypeArguments;
}
-
+
+ /**
+ * Gets the annotated parameters
+ *
+ * If the parameters are null, they are initialized first
+ *
+ * @return The annotated parameters
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedMethod#getParameters()
+ */
public List<AnnotatedParameter<Object>> getParameters()
{
if (parameters == null)
@@ -85,7 +176,14 @@
}
return parameters;
}
-
+
+ /**
+ * Initializes the parameter abstractions
+ *
+ * Iterates over the method abstraction parameters and creates an abstraction
+ * of the parameter
+ */
+ @SuppressWarnings("unchecked")
private void initParameters()
{
this.parameters = new ArrayList<AnnotatedParameter<Object>>();
@@ -105,31 +203,40 @@
}
}
}
-
- public List<AnnotatedParameter<Object>> getAnnotatedMethods(Class<?
extends Annotation> annotationType)
- {
- if (annotatedParameters == null)
- {
- initAnnotatedParameters();
- }
-
- if (!annotatedParameters.containsKey(annotationType))
- {
- return new ArrayList<AnnotatedParameter<Object>>();
- }
- else
- {
- return annotatedParameters.get(annotationType);
- }
- }
+ // TODO: Don't get this one - NIK
+ // public List<AnnotatedParameter<Object>> getAnnotatedMethods(Class<?
+ // extends Annotation> annotationType)
+ // {
+ // if (annotatedParameters == null)
+ // {
+ // initAnnotatedParameters();
+ // }
+ //
+ // if (!annotatedParameters.containsKey(annotationType))
+ // {
+ // return new ArrayList<AnnotatedParameter<Object>>();
+ // }
+ // else
+ // {
+ // return annotatedParameters.get(annotationType);
+ // }
+ // }
+
+ /**
+ * Initializes the annotated parameters
+ *
+ * If the parameters are null, they are initialized first. Iterates over the
+ * parameter abstractions and for each annotation present, maps the parameter
+ * abstraction under that annotation type key.
+ */
private void initAnnotatedParameters()
{
if (parameters == null)
{
initParameters();
}
- annotatedParameters = new HashMap<Class<? extends Annotation>,
List<AnnotatedParameter<Object>>>();
+ annotatedParameters = new AnnotatedParameters();
for (AnnotatedParameter<Object> parameter : parameters)
{
for (Annotation annotation : parameter.getAnnotations())
@@ -143,6 +250,15 @@
}
}
+ /**
+ * Gets the parameter abstractions with a given annotation type
+ *
+ * If the parameter abstractions are null, they are initialized first
+ *
+ * @param annotationType The annotation type to match
+ * @return The list of abstracted parameters with given annotation type
+ * present. An empty list is returned if there are no matches
+ */
public List<AnnotatedParameter<Object>> getAnnotatedParameters(Class<?
extends Annotation> annotationType)
{
if (annotatedParameters == null)
@@ -155,7 +271,12 @@
}
return annotatedParameters.get(annotationType);
}
-
+
+ /**
+ * Compares two annotated methods (delegates)
+ *
+ * @return True if equals, false otherwise
+ */
@Override
public boolean equals(Object other)
{
@@ -169,23 +290,55 @@
return false;
}
}
-
+
+ /**
+ * Gets the hash code (of the delegate)
+ *
+ * @return The hash code
+ */
@Override
public int hashCode()
{
return getDelegate().hashCode();
}
+ /**
+ * Invokes the method on an instance with current parameters from manager
+ *
+ * @param mananger The Web Beans manager
+ * @param instance The instance to invoke on
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedMethod#invoke(ManagerImpl,
+ * Object)
+ */
+ @SuppressWarnings("unchecked")
public T invoke(ManagerImpl manager, Object instance)
{
return (T) Reflections.invokeAndWrap(getDelegate(), instance,
getParameterValues(parameters, manager));
}
-
+
+ /**
+ * Invokes the method on an instance with given parameters
+ *
+ * @param instance The instance to invoke on
+ * @param parameters The parameters
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedMethod#invoke(Object,
+ * Object...)
+ */
+ @SuppressWarnings("unchecked")
public T invoke(Object instance, Object... parameters)
{
return (T) Reflections.invokeAndWrap(getDelegate(), instance, parameters);
}
-
+
+ /**
+ * Gets the name of the property
+ *
+ * @return The name
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedMethod#getPropertyName()
+ */
public String getPropertyName()
{
if (propertyName == null)
@@ -199,9 +352,47 @@
return propertyName;
}
+ /**
+ * Gets the declaring class
+ *
+ * @return The declaring class
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedMethod#getDeclaringClass()
+ */
public AnnotatedType<?> getDeclaringClass()
{
return declaringClass;
}
+ /**
+ * Gets a string representation of the method
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AnnotatedMethodImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Actual type arguments: " + actualTypeArguments.length +
"\n");
+ int i = 0;
+ for (Type actualTypeArgument : actualTypeArguments)
+ {
+ buffer.append(++i + " - " + actualTypeArgument.toString());
+ }
+ buffer.append(annotatedParameters == null ? "" :
(annotatedParameters.toString() + "\n"));
+ buffer.append("Declaring class:\n");
+ buffer.append(declaringClass.toString());
+ buffer.append("Method:\n");
+ buffer.append(method.toString());
+ buffer.append("Property name: " + propertyName + "\n");
+ i = 0;
+ buffer.append("Parameters: " + getParameters().size() + "\n");
+ for (AnnotatedParameter<?> parameter : parameters)
+ {
+ buffer.append(++i + " - " + parameter.toString() + "\n");
+ }
+ return buffer.toString();
+ }
+
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2008-11-27
14:19:40 UTC (rev 372)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2008-11-27
22:49:18 UTC (rev 373)
@@ -25,53 +25,142 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedParameter;
+/**
+ * Represents a parameter
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class AnnotatedParameterImpl<T> extends AbstractAnnotatedItem<T,
Object> implements AnnotatedParameter<T>
{
-
+ // The type
private Class<T> type;
+ // The actual type arguments
private Type[] actualTypeArguments = new Type[0];
+ // The final state
private boolean _final;
+ // The static state
private boolean _static;
+ /**
+ * Constructor
+ *
+ * @param annotations The annotations array
+ * @param type The type of the parameter
+ */
public AnnotatedParameterImpl(Annotation[] annotations, Class<T> type)
{
super(buildAnnotationMap(annotations));
this.type = type;
}
+ /**
+ * Gets the actual type arguments
+ *
+ * @return The type arguments
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getActualTypeArguments()
+ */
public Type[] getActualTypeArguments()
{
return actualTypeArguments;
}
+ /**
+ * Gets the delegate
+ *
+ * @return The delegate (null)
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getDelegate()
+ */
public Object getDelegate()
{
return null;
}
+ /**
+ * Gets the type of the parameter
+ *
+ * @return The type
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getType()
+ */
public Class<T> getType()
{
return type;
}
+ /**
+ * Indicates if the parameter is final
+ *
+ * @return True if final, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isFinal()
+ */
public boolean isFinal()
{
return _final;
}
+ /**
+ * Indicates if the parameter is static
+ *
+ * @return True if static, false otherwise
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#isStatic()
+ */
public boolean isStatic()
{
return _static;
}
-
+
+ /**
+ * Gets the current value
+ *
+ * @param manager The Web Beans manager
+ * @return the value
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedParameter
+ */
public T getValue(ManagerImpl manager)
{
return manager.getInstanceByType(getType(),
getMetaAnnotationsAsArray(BindingType.class));
}
+ /**
+ * Gets the name of the parameter
+ *
+ * @throws IllegalArgumentException (not supported)
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem#getName()
+ */
public String getName()
{
throw new IllegalArgumentException("Unable to determine name of
parameter");
}
-
+
+ /**
+ * Gets a string representation of the parameter
+ *
+ * @return A string representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("AnnotatedParameterImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Type: " + type.toString() + "\n");
+ buffer.append("Final: " + _final + "\n");
+ buffer.append("Static: " + _static + "\n");
+ buffer.append("Actual type arguments: " + actualTypeArguments.length +
"\n");
+ int i = 0;
+ for (Type actualTypeArgument : actualTypeArguments)
+ {
+ buffer.append(++i + " - " + actualTypeArgument.toString() +
"\n");
+ }
+
+ return buffer.toString();
+ }
+
}