Author: nickarls
Date: 2008-12-08 03:34:33 -0500 (Mon, 08 Dec 2008)
New Revision: 466
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.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/AbstractAnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.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
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java
Log:
more toString simplifications
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -9,6 +9,7 @@
import javax.webbeans.IllegalProductException;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.util.Names;
public abstract class ProducerBean<T, S> extends AbstractBean<T, S> {
@@ -107,5 +108,23 @@
return getAnnotatedItem().isStatic() ?
null : manager.getInstance(getDeclaringBean());
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Annotated " + Names.scopeTypeToString(getScopeType()));
+ if (getName() == null)
+ {
+ buffer.append("unnamed producer bean");
+ }
+ else
+ {
+ buffer.append("simple producer bean '" + getName() +
"'");
+ }
+ buffer.append(" [" + getType().getName() + "]\n");
+ buffer.append(" API types " + getTypes() + ", binding types "
+ getBindingTypes() + "\n");
+ return buffer.toString();
+ }
}
\ No newline at end of file
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -22,6 +22,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.jlr.AnnotatedFieldImpl;
+import org.jboss.webbeans.util.Names;
/**
* Represents a producer method bean
@@ -98,6 +99,23 @@
public String toString()
{
StringBuilder buffer = new StringBuilder();
+ buffer.append("Annotated " + Names.scopeTypeToString(getScopeType()));
+ if (getName() == null)
+ {
+ buffer.append("unnamed producer field bean");
+ }
+ else
+ {
+ buffer.append("simple producer field bean '" + getName() +
"'");
+ }
+ buffer.append(" [" + getType().getName() + "]\n");
+ buffer.append(" API types " + getTypes() + ", binding types "
+ getBindingTypes() + "\n");
+ return buffer.toString();
+ }
+
+ public String toDetailedString()
+ {
+ StringBuilder buffer = new StringBuilder();
buffer.append("ProducerFieldBean:\n");
buffer.append(super.toString() + "\n");
buffer.append("Declaring bean: " + declaringBean.toString() +
"\n");
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -30,6 +30,7 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
+import org.jboss.webbeans.util.Names;
/**
* Represents a producer method bean
@@ -181,10 +182,28 @@
return removeMethod;
}
+
@Override
public String toString()
{
StringBuilder buffer = new StringBuilder();
+ buffer.append("Annotated " + Names.scopeTypeToString(getScopeType()));
+ if (getName() == null)
+ {
+ buffer.append("unnamed producer method bean");
+ }
+ else
+ {
+ buffer.append("simple producer method bean '" + getName() +
"'");
+ }
+ buffer.append(" [" + getType().getName() + "]\n");
+ buffer.append(" API types " + getTypes() + ", binding types "
+ getBindingTypes() + "\n");
+ return buffer.toString();
+ }
+
+ public String toDetailedString()
+ {
+ StringBuilder buffer = new StringBuilder();
buffer.append("ProducerMethodBean:\n");
buffer.append(super.toString() + "\n");
buffer.append("Declaring bean: " + declaringBean.toString() +
"\n");
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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -437,13 +437,18 @@
{
return toString;
}
+ toString = "Abstract annotated item " + getName();
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AbstractAnnotatedItem:\n");
buffer.append(Strings.collectionToString("Annotations: ",
getAnnotations()));
buffer.append(annotationMap == null ? "" : (annotationMap.toString() +
"\n"));
buffer.append(metaAnnotationMap == null ? "" :
(metaAnnotationMap.toString()) + "\n");
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
/**
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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -156,20 +156,26 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Abstract annotated member " + getName();
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AbstractAnnotatedMember:\n");
buffer.append(super.toString() + "\n");
buffer.append("Final: " + isFinal() + "\n");
buffer.append("Static: " + isStatic() + "\n");
buffer.append("Name: " + getName() + "\n");
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -106,16 +106,23 @@
}
/**
- * Gets a string representation of the annotated type
+ * Gets a string representation of the type
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Abstract annotated type " + getName();
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AbstractAnnotatedType:\n");
buffer.append(super.toString() + "\n");
@@ -123,8 +130,7 @@
buffer.append("Name: " + getName() + "\n");
buffer.append("Final: " + isFinal() + "\n");
buffer.append("Static: " + isStatic() + "\n");
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -172,26 +172,32 @@
{
return Collections.unmodifiableSet(annotatedMembers.get(annotationType));
}
-
+
/**
- * Gets a string representation of the constructor
+ * Gets a string representation of the annotation
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+// toString = "Annotated annotation " +
Names.annotation2String(getDelegate());
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedConstructorImpl:\n");
buffer.append(super.toString() + "\n");
buffer.append("Class: " + clazz.toString() + "\n");
buffer.append(Strings.collectionToString("Members: ", getMembers()));
buffer.append(annotatedMembers == null ? "" :
(annotatedMembers.toString() + "\n"));
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
protected Class<T> getDelegate()
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -35,6 +35,7 @@
import org.jboss.webbeans.introspector.AnnotatedConstructor;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Strings;
import com.google.common.collect.ForwardingMap;
@@ -504,16 +505,23 @@
}
/**
- * Gets a string representation of the constructor
+ * Gets a string representation of the class
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated class " + Names.class2String(getDelegate());
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedConstructorImpl:\n");
buffer.append(super.toString() + "\n");
@@ -527,8 +535,7 @@
buffer.append(annotatedMethods == null ? "" :
(annotatedMethods.toString() + "\n"));
buffer.append(constructorsByArgumentMap == null ? "" :
(constructorsByArgumentMap.toString() + "\n"));
buffer.append(metaAnnotatedFields == null ? "" :
(metaAnnotatedFields.toString() + "\n"));
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
}
\ No newline at end of file
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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -33,6 +33,7 @@
import org.jboss.webbeans.introspector.AnnotatedConstructor;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Strings;
/**
@@ -270,12 +271,19 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated method " + Names.constructor2String(constructor);
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedConstructorImpl:\n");
buffer.append(super.toString() + "\n");
@@ -286,8 +294,7 @@
buffer.append(constructor.toString() + "\n");
buffer.append(Strings.collectionToString("Parameters: ",
getParameters()));
buffer.append(annotatedParameters.toString() + "\n");
- toString = buffer.toString();
- return toString;
+ 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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -27,6 +27,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
@@ -127,6 +128,7 @@
Reflections.setAndWrap(getDelegate(), instance, getValue(manager));
}
+ @SuppressWarnings("unchecked")
public T get(Object instance) {
return (T) Reflections.getAndWrap(getDelegate(), instance);
}
@@ -160,12 +162,19 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated method " + Names.field2String(field);
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedFieldImpl:\n");
buffer.append(super.toString() + "\n");
@@ -173,8 +182,7 @@
buffer.append("Declaring class:\n");
buffer.append(declaringClass.getName() + "[ " + declaringClass.getType()
+ "]" + "\n");
buffer.append("Field: " + field + "\n");
- toString = buffer.toString();
- return toString;
+ 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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -21,6 +21,7 @@
import java.lang.reflect.Type;
import java.util.Arrays;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Strings;
/**
@@ -147,19 +148,25 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated item " +
Names.type2String(getDelegate().getClass());
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedItemImpl:\n");
buffer.append(super.toString() + "\n");
buffer.append(Strings.collectionToString("Actual type arguments: ",
Arrays.asList(getActualTypeArguments())));
buffer.append(Strings.collectionToString("Actual annotations: ",
Arrays.asList(getActualAnnotations())));
- toString = buffer.toString();
- return 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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -32,6 +32,7 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
@@ -293,12 +294,19 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated method " + Names.method2String(method);
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedMethodImpl:\n");
buffer.append(super.toString() + "\n");
@@ -310,8 +318,7 @@
buffer.append(method.toString());
buffer.append("Property name: " + propertyName + "\n");
buffer.append(Strings.collectionToString("Parameters: ",
getParameters()));
- toString = buffer.toString();
- return toString;
+ 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-12-08
01:09:19 UTC (rev 465)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -24,8 +24,8 @@
import javax.webbeans.BindingType;
import javax.webbeans.manager.Manager;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedParameter;
+import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Strings;
/**
@@ -152,12 +152,19 @@
*
* @return A string representation
*/
+ @Override
public String toString()
{
if (toString != null)
{
return toString;
}
+ toString = "Annotated parameter " +
Names.type2String(getDelegate().getClass());
+ return toString;
+ }
+
+ public String toDetailedString()
+ {
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedParameterImpl:\n");
buffer.append(super.toString() + "\n");
@@ -165,8 +172,7 @@
buffer.append("Final: " + _final + "\n");
buffer.append("Static: " + _static + "\n");
buffer.append(Strings.collectionToString("Actual type arguments: ",
Arrays.asList(getActualTypeArguments())));
- toString = buffer.toString();
- return toString;
+ return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java 2008-12-08
01:09:19 UTC (rev 465)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java 2008-12-08
08:34:33 UTC (rev 466)
@@ -1,10 +1,18 @@
package org.jboss.webbeans.util;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.webbeans.Observes;
+
import org.jboss.webbeans.ejb.EjbMetaData;
/**
@@ -51,7 +59,7 @@
return "unknown";
}
- public static int count(Iterable<?> iterable)
+ public static int count(@Observes final Iterable<?> iterable)
{
int count = 0;
for (Iterator<?> i = iterable.iterator(); i.hasNext();)
@@ -61,4 +69,153 @@
return count;
}
+ private static String list2String(List<String> list, String delimiter)
+ {
+ StringBuilder buffer = new StringBuilder();
+ for (String item : list)
+ {
+ buffer.append(item);
+ buffer.append(delimiter);
+ }
+ return buffer.toString();
+ }
+
+ private static List<String> parseModifiers(int modifier)
+ {
+ List<String> modifiers = new ArrayList<String>();
+ if (Modifier.isPrivate(modifier))
+ {
+ modifiers.add("private");
+ }
+ if (Modifier.isProtected(modifier))
+ {
+ modifiers.add("protected");
+ }
+ if (Modifier.isPublic(modifier))
+ {
+ modifiers.add("public");
+ }
+ if (Modifier.isAbstract(modifier))
+ {
+ modifiers.add("abstract");
+ }
+ if (Modifier.isFinal(modifier))
+ {
+ modifiers.add("final");
+ }
+ if (Modifier.isNative(modifier))
+ {
+ modifiers.add("native");
+ }
+ if (Modifier.isStatic(modifier))
+ {
+ modifiers.add("static");
+ }
+ if (Modifier.isStrict(modifier))
+ {
+ modifiers.add("strict");
+ }
+ if (Modifier.isSynchronized(modifier))
+ {
+ modifiers.add("synchronized");
+ }
+ if (Modifier.isTransient(modifier))
+ {
+ modifiers.add("transient");
+ }
+ if (Modifier.isVolatile(modifier))
+ {
+ modifiers.add("volatile");
+ }
+ if (Modifier.isInterface(modifier))
+ {
+ modifiers.add("interface");
+ }
+ return modifiers;
+ }
+
+ private static String annotations2String(Annotation[] annotations)
+ {
+ StringBuilder buffer = new StringBuilder();
+ for (Annotation annotation : annotations)
+ {
+ buffer.append("@" + annotation.annotationType().getSimpleName());
+ buffer.append(" ");
+ }
+ return buffer.toString();
+ }
+
+ public static String field2String(Field field)
+ {
+ return " Field " +
+ annotations2String(field.getAnnotations()) +
+ list2String(parseModifiers(field.getModifiers()), " ") +
+ field.getName() + ";";
+ }
+
+ public static String method2String(Method method)
+ {
+ return " Method " +
+ method.getReturnType().getSimpleName() + " " +
+ annotations2String(method.getAnnotations()) +
+ list2String(parseModifiers(method.getModifiers()), " ") +
+ method.getName() + "(" +
+ parameters2String(method.getParameterTypes(), method.getParameterAnnotations())
+
+ ");";
+ }
+
+ public static String annotation2String(Annotation annotation)
+ {
+ return "Annotation " +
+ annotations2String(annotation.annotationType().getAnnotations()) +
+ annotation.annotationType().getSimpleName();
+ }
+
+ public static String constructor2String(Constructor<?> method)
+ {
+ return " Constructor " +
+ annotations2String(method.getAnnotations()) +
+ list2String(parseModifiers(method.getModifiers()), " ") +
+ method.getName() + "(" +
+ parameters2String(method.getParameterTypes(), method.getParameterAnnotations())
+
+ ");";
+ }
+
+ private static String parameters2String(Class<?>[] parameterTypes,
Annotation[][] annotations)
+ {
+ StringBuilder buffer = new StringBuilder();
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ if (i > 0)
+ {
+ buffer.append(", ");
+ }
+ buffer.append(annotations2String(annotations[i]) +
type2String(parameterTypes[i]));
+ }
+ return buffer.toString();
+ }
+
+ public static String type2String(Class<?> clazz)
+ {
+ return annotations2String(clazz.getAnnotations()) + clazz.getName();
+ }
+
+ public static String class2String(Class<?> clazz) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Class " + type2String(clazz));
+ buffer.append("\n");
+ for (Field field : clazz.getFields())
+ {
+ buffer.append(field2String(field));
+ buffer.append("\n");
+ }
+ buffer.append("\n");
+ for (Method method : clazz.getMethods())
+ {
+ buffer.append(method2String(method));
+ buffer.append("\n");
+ }
+ return buffer.toString();
+ }
+
}