Skip to content

Commit

Permalink
more toString simplifications
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@466 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Dec 8, 2008
1 parent 1add40f commit 0d8610c
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 26 deletions.
Expand Up @@ -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> {

Expand Down Expand Up @@ -107,5 +108,23 @@ protected Object getReceiver() {
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();
}

}
Expand Up @@ -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
Expand Down Expand Up @@ -96,6 +97,23 @@ protected String getDefaultName()

@Override
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");
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -181,8 +182,26 @@ public AnnotatedMethod<?> getDisposalMethod()
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");
Expand Down
Expand Up @@ -437,13 +437,18 @@ public String toString()
{
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();
}

/**
Expand Down
Expand Up @@ -156,20 +156,26 @@ public String getName()
*
* @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();
}

}
Expand Up @@ -106,25 +106,31 @@ public AnnotatedClass<Object> getSuperclass()
}

/**
* 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");
buffer.append("Superclass: " + (superclass == null ? "" : superclass.toString()) + "\n");
buffer.append("Name: " + getName() + "\n");
buffer.append("Final: " + isFinal() + "\n");
buffer.append("Static: " + isStatic() + "\n");
toString = buffer.toString();
return toString;
return buffer.toString();
}

}
Expand Up @@ -172,26 +172,32 @@ public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> a
{
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()
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -504,16 +505,23 @@ public Set<AnnotatedMethod<Object>> getMethodsWithAnnotatedParameters(Class<? ex
}

/**
* 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");
Expand All @@ -527,8 +535,7 @@ public String toString()
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();
}

}
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -270,12 +271,19 @@ public AnnotatedType<T> getDeclaringClass()
*
* @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");
Expand All @@ -286,8 +294,7 @@ public String toString()
buffer.append(constructor.toString() + "\n");
buffer.append(Strings.collectionToString("Parameters: ", getParameters()));
buffer.append(annotatedParameters.toString() + "\n");
toString = buffer.toString();
return toString;
return buffer.toString();
}

}
Expand Up @@ -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;

Expand Down Expand Up @@ -127,6 +128,7 @@ public void inject(Manager manager, Object instance)
Reflections.setAndWrap(getDelegate(), instance, getValue(manager));
}

@SuppressWarnings("unchecked")
public T get(Object instance) {
return (T) Reflections.getAndWrap(getDelegate(), instance);
}
Expand Down Expand Up @@ -160,21 +162,27 @@ public AnnotatedType<?> getDeclaringClass()
*
* @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");
buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
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();
}

}
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -147,19 +148,25 @@ public String getName()
*
* @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();
}

}

0 comments on commit 0d8610c

Please sign in to comment.