Author: nickarls
Date: 2010-03-28 17:03:47 -0400 (Sun, 28 Mar 2010)
New Revision: 6067
Added:
core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldParameterImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
Log:
WELD-374, jlr part
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-03-27
11:53:37 UTC (rev 6066)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -564,7 +564,7 @@
@Override
public String toString()
{
- return Names.toString(getJavaClass(), getAnnotations(), getActualTypeArguments());
+ return Names.classToString(getJavaClass(), getAnnotations(),
getActualTypeArguments());
}
public String getSimpleName()
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-03-27
11:53:37 UTC (rev 6066)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -40,6 +40,7 @@
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.Names;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.util.reflection.SecureReflections;
@@ -283,7 +284,7 @@
@Override
public String toString()
{
- return new StringBuilder().append("constructor
").append(constructor.toString()).toString();
+ return Names.constructorToString(getDelegate(), getAnnotations(),
getActualTypeArguments(), getParameters());
}
public ConstructorSignature getSignature()
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-03-27
11:53:37 UTC (rev 6066)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -30,6 +30,7 @@
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.Names;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.SecureReflections;
@@ -132,7 +133,7 @@
@Override
public String toString()
{
- return new StringBuilder().append("field
").append(getDeclaringType().getName()).append(".").append(field.getName()).toString();
+ return Names.fieldToString(getDelegate(), getAnnotations(),
getActualTypeArguments());
}
public boolean isGeneric()
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-03-27
11:53:37 UTC (rev 6066)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -39,6 +39,7 @@
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.Names;
import org.jboss.weld.util.collections.ArrayListSupplier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;
@@ -216,7 +217,7 @@
@Override
public String toString()
{
- return new StringBuilder().append(method.toString()).toString();
+ return Names.methodToString(getDelegate(), getAnnotations(),
getActualTypeArguments(), getParameters());
}
public MethodSignature getSignature()
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldParameterImpl.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldParameterImpl.java 2010-03-27
11:53:37 UTC (rev 6066)
+++
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldParameterImpl.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -30,6 +30,7 @@
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.Names;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
/**
@@ -139,7 +140,7 @@
@Override
public String toString()
{
- return new StringBuilder().append("parameter
").append(position).append(" of
").append(declaringMember.toString()).toString();
+ return Names.parameterToString(getJavaClass(), getAnnotations(),
getActualTypeArguments());
}
public AnnotatedCallable<X> getDeclaringCallable()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2010-03-27 11:53:37 UTC
(rev 6066)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2010-03-28 21:03:47 UTC
(rev 6067)
@@ -17,6 +17,9 @@
package org.jboss.weld.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.lang.reflect.Type;
import java.util.ArrayList;
@@ -31,6 +34,7 @@
* Utility class to produce friendly names e.g. for debugging
*
* @author Pete Muir
+ * @author Nicklas Karlsson
*
*/
public class Names
@@ -65,19 +69,37 @@
}
return result.toString();
}
-
- public static String toString(Class<?> rawType, Set<Annotation>
annotations, Type[] actualTypeArguments)
+
+ public static String classToString(Class<?> rawType, Set<Annotation>
annotations, Type[] actualTypeArguments)
{
- if (actualTypeArguments.length > 0)
- {
- return new
StringBuilder().append(Names.annotationsToString(annotations)).append("
").append(rawType.getName()).append("<").append(Arrays.asList(actualTypeArguments)).append(">").toString();
- }
- else
- {
- return new
StringBuilder().append(Names.annotationsToString(annotations)).append("
").append(rawType.getName()).toString();
- }
+ return new
NamesStringBuilder("class").add(modifiersToString(rawType.getModifiers())).add(annotationsToString(annotations)).add(rawType.getName()).add(typesToString(actualTypeArguments)).toString();
}
+ public static String fieldToString(Field field, Set<Annotation> annotations,
Type[] actualTypeArguments)
+ {
+ return new NamesStringBuilder("field in " +
field.getDeclaringClass().getName()).add(modifiersToString(field.getModifiers())).add(annotationsToString(annotations)).add(field.getType().getName()).add(typesToString(actualTypeArguments)).add(field.getName()).toString();
+ }
+
+ public static String methodToString(Method method, Set<Annotation> annotations,
Type[] actualTypeArguments, List<?> parameters)
+ {
+ return new NamesStringBuilder("method in " +
method.getDeclaringClass().getName()).add(modifiersToString(method.getModifiers())).add(annotationsToString(annotations)).add(method.getName()).add(typesToString(actualTypeArguments)).add(parametersToString(parameters)).toString();
+ }
+
+ private static String parametersToString(List<?> parameters)
+ {
+ return "(" + iterableToString(parameters, ", ") +
")";
+ }
+
+ public static String constructorToString(Constructor<?> constructor,
Set<Annotation> annotations, Type[] actualTypeArguments, List<?> parameters)
+ {
+ return new NamesStringBuilder("constructor for " +
constructor.getDeclaringClass().getName()).add(modifiersToString(constructor.getModifiers())).add(annotationsToString(annotations)).add(constructor.getName()).add(typesToString(actualTypeArguments)).add(parametersToString(parameters)).toString();
+ }
+
+ public static String parameterToString(Class<?> rawType, Set<Annotation>
annotations, Type[] actualTypeArguments)
+ {
+ return new
NamesStringBuilder().add(modifiersToString(rawType.getModifiers())).add(annotationsToString(annotations)).add(rawType.getName()).add(typesToString(actualTypeArguments)).toString();
+ }
+
/**
* Counts item in an iteratble
*
@@ -94,6 +116,27 @@
return count;
}
+ private static String modifiersToString(int modifiers)
+ {
+ return iterableToString(parseModifiers(modifiers), " ");
+ }
+
+ private static String iterableToString(Iterable<?> items, String delimiter)
+ {
+ StringBuffer stringBuffer = new StringBuffer();
+ int i = 0;
+ for (Object item : items)
+ {
+ if (i > 0)
+ {
+ stringBuffer.append(delimiter);
+ }
+ stringBuffer.append(item);
+ i++;
+ }
+ return stringBuffer.toString();
+ }
+
/**
* Parses a reflection modifier to a list of string
*
@@ -153,13 +196,17 @@
}
return modifiers;
}
-
- public static String typesToString(Set<? extends Type> types)
+
+ public static String typesToString(Type[] actualTypeArguments)
{
+ if (actualTypeArguments.length == 0)
+ {
+ return "";
+ }
StringBuilder buffer = new StringBuilder();
int i = 0;
- buffer.append("[");
- for (Type type : types)
+ buffer.append("<");
+ for (Type type : actualTypeArguments)
{
if (i > 0)
{
@@ -175,26 +222,21 @@
}
i++;
}
- buffer.append("]");
+ buffer.append(">");
return buffer.toString();
}
-
+
public static String annotationsToString(Iterable<Annotation> annotations)
{
StringBuilder builder = new StringBuilder();
- int i = 0;
for (Annotation annotation : annotations)
{
- if (i > 0)
- {
- builder.append(" ");
- }
+ builder.append(" ");
builder.append("(a)").append(annotation.annotationType().getSimpleName());
- i++;
}
- return builder.toString();
+ return builder.toString().trim();
}
-
+
/**
* Gets a string representation from an array of annotations
*
@@ -205,7 +247,7 @@
{
return annotationsToString(Arrays.asList(annotations));
}
-
+
public static String version(Package pkg)
{
if (pkg == null)
@@ -217,9 +259,9 @@
return version(pkg.getImplementationVersion());
}
}
-
+
public static String version(String version)
- {
+ {
if (version != null)
{
StringBuilder builder = new StringBuilder();
@@ -245,7 +287,7 @@
}
else
{
- builder.append(version);
+ builder.append(version);
}
return builder.toString();
}
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java
(rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java 2010-03-28
21:03:47 UTC (rev 6067)
@@ -0,0 +1,32 @@
+package org.jboss.weld.util;
+
+public class NamesStringBuilder
+{
+ private StringBuilder stringBuilder = new StringBuilder();
+
+ public NamesStringBuilder(String context)
+ {
+ stringBuilder.append("[");
+ stringBuilder.append(context);
+ stringBuilder.append("]");
+ }
+
+ public NamesStringBuilder()
+ {
+ }
+
+ public NamesStringBuilder add(String text)
+ {
+ if (text != null && !"".equals(text))
+ {
+ stringBuilder.append(" ");
+ stringBuilder.append(text);
+ }
+ return this;
+ }
+
+ public String toString()
+ {
+ return stringBuilder.toString().trim();
+ }
+}