[weld-commits] Weld SVN: r5853 - in core/trunk: impl/src/main/java/org/jboss/weld/resolution and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Tue Feb 16 16:20:01 EST 2010


Author: pete.muir at jboss.org
Date: 2010-02-16 16:20:00 -0500 (Tue, 16 Feb 2010)
New Revision: 5853

Added:
   core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/resolution/ResolvableBuilder.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanConsumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanTest.java
Log:
WELD-435

Added: core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java	2010-02-16 21:20:00 UTC (rev 5853)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.literal;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Named;
+
+/**
+ * Annotation literal for @Current
+ * 
+ * @author Pete Muir
+ */
+public class NamedLiteral extends AnnotationLiteral<Named> implements Named
+{
+   
+   private final String value;
+
+   public String value()
+   {
+      return value;
+   }
+
+   public NamedLiteral(String value)
+   {
+      this.value = value;
+   }
+
+}


Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/ResolvableBuilder.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/ResolvableBuilder.java	2010-02-16 21:08:57 UTC (rev 5852)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/ResolvableBuilder.java	2010-02-16 21:20:00 UTC (rev 5853)
@@ -21,6 +21,7 @@
 import static org.jboss.weld.logging.messages.ResolutionMessage.CANNOT_EXTRACT_RAW_TYPE;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collections;
@@ -34,12 +35,14 @@
 import javax.enterprise.inject.New;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Named;
 import javax.inject.Provider;
 
 import org.jboss.weld.Container;
 import org.jboss.weld.exceptions.ForbiddenArgumentException;
 import org.jboss.weld.literal.AnyLiteral;
 import org.jboss.weld.literal.DefaultLiteral;
+import org.jboss.weld.literal.NamedLiteral;
 import org.jboss.weld.literal.NewLiteral;
 import org.jboss.weld.metadata.cache.MetaAnnotationStore;
 import org.jboss.weld.util.reflection.Reflections;
@@ -78,6 +81,18 @@
    {
       this(injectionPoint.getType());
       addQualifiers(injectionPoint.getQualifiers());
+      if (mappedQualifiers.containsKey(Named.class) && injectionPoint.getMember() instanceof Field)
+      {
+         Named named = (Named) mappedQualifiers.get(Named.class);
+         if (named.value().equals(""))
+         {
+            qualifiers.remove(named);
+            // This is field injection point with an @Named qualifier, with no value specified, we need to assume the name of the field is the value
+            named = new NamedLiteral(injectionPoint.getMember().getName());
+            qualifiers.add(named);
+            mappedQualifiers.put(Named.class, named);
+         }
+      }
       setDeclaringBean(injectionPoint.getBean());
    }
 

Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanConsumer.java	2010-02-16 21:08:57 UTC (rev 5852)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanConsumer.java	2010-02-16 21:20:00 UTC (rev 5853)
@@ -1,10 +1,13 @@
 package org.jboss.weld.tests.resolution.named;
 
+import javax.inject.Inject;
+import javax.inject.Named;
 
+
 public class NamedBeanConsumer
 {
    
-   /*@Inject @Named*/ FooBean foo;
+   @Inject @Named FooBean foo;
    
    public FooBean getFoo()
    {

Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanTest.java	2010-02-16 21:08:57 UTC (rev 5852)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/named/NamedBeanTest.java	2010-02-16 21:20:00 UTC (rev 5853)
@@ -36,7 +36,7 @@
       assert instance != null;
    }
    
-   @Test(description = "WELD-435", groups = "broken")
+   @Test(description = "WELD-435")
    public void testNamedInjectedFieldUsesFieldName()
    {
       assert getReference(NamedBeanConsumer.class).getFoo() != null;



More information about the weld-commits mailing list