[weld-commits] Weld SVN: r6906 - in core/trunk/impl/src/main: java/org/jboss/weld/bootstrap and 5 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Aug 4 15:14:28 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-08-04 15:14:27 -0400 (Wed, 04 Aug 2010)
New Revision: 6906

Removed:
   core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/InstanceImpl.java
   core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
   core/trunk/impl/src/main/java/org/jboss/weld/event/EventImpl.java
   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
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
   core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties
Log:
WELD-581, start on WELD-542

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/InstanceImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/InstanceImpl.java	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/InstanceImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -92,7 +92,7 @@
    @Override
    public String toString()
    {
-      return new StringBuilder().append(Names.annotationsToString(getQualifiers())).append(" Instance<").append(getType()).append(">").toString();
+      return new StringBuilder().append(Names.toString(getQualifiers())).append(" Instance<").append(getType()).append(">").toString();
    }
    
    private Set<Bean<?>> getBeans()

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -103,6 +103,7 @@
 import org.jboss.weld.metadata.cache.MetaAnnotationStore;
 import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
 import org.jboss.weld.util.Beans;
+import org.jboss.weld.util.Names;
 import org.jboss.weld.util.Proxies;
 import org.jboss.weld.util.reflection.Reflections;
 import org.slf4j.cal10n.LocLogger;
@@ -288,7 +289,7 @@
       Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij));
       if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager))
       {
-         throw new DeploymentException(INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES, ij, Arrays.toString(bindings));
+         throw new DeploymentException(INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES, ij, Names.toString(bindings), Names.toString(ij.getType()));
       }
       if (resolvedBeans.size() > 1 && !ij.isDelegate())
       {

Modified: core/trunk/impl/src/main/java/org/jboss/weld/event/EventImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/event/EventImpl.java	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/event/EventImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -86,7 +86,7 @@
    @Override
    public String toString()
    {
-      return new StringBuilder().append(Names.annotationsToString(getQualifiers())).append(" Event<").append(getType()).append(">").toString();
+      return new StringBuilder().append(Names.toString(getQualifiers())).append(" Event<").append(getType()).append(">").toString();
    }
 
    public void fire(T event)

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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -579,7 +579,7 @@
    @Override
    public String toString()
    {
-      return Names.classToString(getJavaClass(), getAnnotations(), getActualTypeArguments());
+      return Names.toString(this);
    }
 
    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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -293,7 +293,7 @@
    @Override
    public String toString()
    {
-      return Names.constructorToString(getDelegate(), getAnnotations(), getActualTypeArguments(), getParameters());
+      return Names.toString(this);
    }
 
    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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -133,7 +133,7 @@
    @Override
    public String toString()
    {
-      return Names.fieldToString(getDelegate(), getAnnotations(), getActualTypeArguments());
+      return Names.toString(this);
    }
    
    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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -214,7 +214,7 @@
    @Override
    public String toString()
    {
-      return Names.methodToString(getDelegate(), getAnnotations(), getActualTypeArguments(), getParameters());
+      return Names.toString(this);
    }
 
    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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldParameterImpl.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -140,7 +140,7 @@
    @Override
    public String toString()
    {
-      return Names.parameterToString(getPosition(), getDeclaringCallable().getJavaMember(), getJavaClass(), getAnnotations(), getActualTypeArguments());
+      return Names.toString(this);
    }
 
    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-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -17,20 +17,23 @@
 package org.jboss.weld.util;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
 import java.lang.reflect.Member;
-import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.jboss.weld.introspector.WeldCallable;
+import org.jboss.weld.introspector.WeldClass;
+import org.jboss.weld.introspector.WeldConstructor;
+import org.jboss.weld.introspector.WeldField;
+import org.jboss.weld.introspector.WeldMethod;
+import org.jboss.weld.introspector.WeldParameter;
+import org.jboss.weld.util.reflection.Reflections;
+
 /**
  * Utility class to produce friendly names e.g. for debugging
  * 
@@ -70,53 +73,84 @@
       }
       return result.toString();
    }
-
-   public static String classToString(Class<?> rawType, Set<Annotation> annotations, Type[] actualTypeArguments)
+   
+   public static String toString(Type baseType)
    {
-      return new NamesStringBuilder("class").add(modifiersToString(rawType.getModifiers())).add(annotationsToString(annotations)).add(rawType.getName()).add(typesToString(actualTypeArguments)).toString();
+      return new StringBuilder().append(Reflections.getRawType(baseType).getSimpleName()).append(toString(Reflections.getActualTypeArguments(baseType))).toString();
+      
    }
-
-   public static String fieldToString(Field field, Set<Annotation> annotations, Type[] actualTypeArguments)
+   
+   public static String toString(WeldClass<?> clazz)
    {
-      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();
+      return new StringBuilder().append(modifiersToString(clazz.getJavaClass().getModifiers())).append(toString(clazz.getAnnotations())).append(" class ").append(clazz.getName()).append(toString(clazz.getActualTypeArguments())).toString().trim();
    }
 
-   public static String methodToString(Method method, Set<Annotation> annotations, Type[] actualTypeArguments, List<?> parameters)
+   public static String toString(WeldField<?, ?> field)
    {
-      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();
+      return new StringBuilder().append("[field] ").append(addSpaceIfNeeded(toString(field.getAnnotations()))).append(addSpaceIfNeeded(modifiersToString(field.getJavaMember().getModifiers()))).append(field.getDeclaringType().getName()).append(".").append(field.getName()).toString().trim();
    }
-
-   private static String parametersToString(List<?> parameters)
+   
+   public static String toString(WeldCallable<?, ?, ? extends Member> callable)
    {
-      return "(" + iterableToString(parameters, ", ") + ")";
+      if (callable instanceof WeldMethod<?, ?>)
+      {
+         return toString((WeldMethod<?, ?>) callable);
+      }
+      else if (callable instanceof WeldConstructor<?>)
+      {
+         return toString((WeldConstructor<?>) callable);
+      }
+      else
+      {
+         throw new IllegalArgumentException("Unable to produce a toString representation of classes of type " + callable.getClass().getName());
+      }
    }
-
-   public static String constructorToString(Constructor<?> constructor, Set<Annotation> annotations, Type[] actualTypeArguments, List<?> parameters)
+   
+   public static String toString(WeldMethod<?, ?> method)
    {
-      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();
+      return new StringBuilder().append("[method] ").append(addSpaceIfNeeded(toString(method.getAnnotations()))).append(addSpaceIfNeeded(modifiersToString(method.getJavaMember().getModifiers()))).append(method.getDeclaringType().getName()).append(".").append(method.getName()).append(parametersToTypeString(method.getWeldParameters())).toString().trim();
    }
-
-   public static String parameterToString(int position, Member member, Class<?> rawType, Set<Annotation> annotations, Type[] actualTypeArguments)
+   
+   public static String toString(WeldConstructor<?> constructor)
    {
-      return new NamesStringBuilder().add("parameter " + position + " on " + member + "; " + modifiersToString(rawType.getModifiers())).add(annotationsToString(annotations)).add(rawType.getName()).add(typesToString(actualTypeArguments)).toString();
+      return new StringBuilder().append("[constructor] ").append(addSpaceIfNeeded(toString(constructor.getAnnotations()))).append(addSpaceIfNeeded(modifiersToString(constructor.getJavaMember().getModifiers()))).append(constructor.getDeclaringType().getName()).append(parametersToTypeString(constructor.getWeldParameters())).toString().trim();
    }
-
-   /**
-    * Counts item in an iteratble
-    * 
-    * @param iterable The iteraboe
-    * @return The count
-    */
-   public static int count(final Iterable<?> iterable)
+   
+   private static String addSpaceIfNeeded(String string)
    {
-      int count = 0;
-      for (Iterator<?> i = iterable.iterator(); i.hasNext();)
+      if (string.length() > 0)
       {
-         count++;
+         return new StringBuilder().append(string).append(" ").toString();
       }
-      return count;
+      else
+      {
+         return string;
+      }
    }
+   
+   
+   private static String parametersToTypeString(Iterable<? extends WeldParameter<?, ?>> parameters)
+   {
+      StringBuilder stringBuilder = new StringBuilder();
+      stringBuilder.append("(");
+      int i = 0;
+      for (WeldParameter<?, ?> parameter : parameters)
+      {
+         if (i > 0)
+         {
+            stringBuilder.append(", ");
+         }
+         stringBuilder.append(toString(parameter.getBaseType()));
+         i++;
+      }
+      return stringBuilder.append(")").toString();
+   }
 
+   public static String toString(WeldParameter<?, ?> parameter)
+   {
+      return new StringBuilder().append("[parameter ").append(parameter.getPosition() + 1).append("] of ").append(toString(parameter.getDeclaringWeldCallable())).toString();
+   }
+
    private static String modifiersToString(int modifiers)
    {
       return iterableToString(parseModifiers(modifiers), " ");
@@ -124,18 +158,18 @@
 
    private static String iterableToString(Iterable<?> items, String delimiter)
    {
-      StringBuffer stringBuffer = new StringBuffer();
+      StringBuilder stringBuilder = new StringBuilder();
       int i = 0;
       for (Object item : items)
       {
          if (i > 0)
          {
-            stringBuffer.append(delimiter);
+            stringBuilder.append(delimiter);
          }
-         stringBuffer.append(item);
+         stringBuilder.append(item);
          i++;
       }
-      return stringBuffer.toString();
+      return stringBuilder.toString();
    }
 
    /**
@@ -198,7 +232,7 @@
       return modifiers;
    }
 
-   public static String typesToString(Type[] actualTypeArguments)
+   public static String toString(Type[] actualTypeArguments)
    {
       if (actualTypeArguments.length == 0)
       {
@@ -227,7 +261,7 @@
       return buffer.toString();
    }
 
-   public static String annotationsToString(Iterable<Annotation> annotations)
+   public static String toString(Iterable<Annotation> annotations)
    {
       StringBuilder builder = new StringBuilder();
       for (Annotation annotation : annotations)
@@ -244,9 +278,9 @@
     * @param annotations The annotations
     * @return The string representation
     */
-   public static String annotationsToString(Annotation[] annotations)
+   public static String toString(Annotation[] annotations)
    {
-      return annotationsToString(Arrays.asList(annotations));
+      return toString(Arrays.asList(annotations));
    }
 
    public static String version(Package pkg)

Deleted: core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/NamesStringBuilder.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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();
-   }
-}

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java	2010-08-04 19:14:27 UTC (rev 6906)
@@ -241,6 +241,25 @@
          return EMPTY_TYPES;
       }
    }
+   
+   /**
+    * Gets the actual type arguments of a Type
+    * 
+    * @param type The type to examine
+    * @return The type arguments
+    */
+   public static Type[] getActualTypeArguments(Type type)
+   {
+      Type resolvedType = new HierarchyDiscovery(type).getResolvedType();
+      if (resolvedType instanceof ParameterizedType)
+      {
+         return ((ParameterizedType) resolvedType).getActualTypeArguments();
+      }
+      else
+      {
+         return EMPTY_TYPES;
+      }
+   }
 
    /**
     * Checks if raw type is array type

Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties	2010-08-04 17:36:38 UTC (rev 6905)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties	2010-08-04 19:14:27 UTC (rev 6906)
@@ -5,7 +5,7 @@
 INJECTION_INTO_NON_BEAN=Cannot inject {0} in a class which isn't a bean
 INJECTION_INTO_NON_DEPENDENT_BEAN=Cannot inject {0} in a non @Dependent scoped bean
 INJECTION_POINT_WITH_TYPE_VARIABLE=Cannot declare an injection point with a type variable: {0}
-INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES=Injection point has unsatisfied dependencies. Injection point: {0}; Qualifiers: {1}
+INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES=Unsatisfied dependencies for type [{2}] with qualifiers [{1}] at injection point [{0}]
 INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES=Injection point has ambiguous dependencies. Injection point: {0}; Qualifiers: {1}
 INJECTION_POINT_HAS_NON_PROXYABLE_DEPENDENCIES=The injection point {0} has non-proxyable dependencies
 INJECTION_POINT_HAS_NULLABLE_DEPENDENCIES=Injection point {0} has nullable dependencies



More information about the weld-commits mailing list