Author: pete.muir(a)jboss.org
Date: 2010-04-29 15:24:23 -0400 (Thu, 29 Apr 2010)
New Revision: 6196
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/reannotated/
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
remove reannotated stuff (first pass, still needs more cleaning)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29
19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -16,38 +16,46 @@
*/
package org.jboss.weld.extensions;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
+
import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Qualifier;
-import org.jboss.weld.extensions.util.BeanImpl;
-import org.jboss.weld.extensions.util.reannotated.AnnotationRedefinition;
-import org.jboss.weld.extensions.util.reannotated.Reannotated;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedMember;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
+import org.jboss.weld.extensions.Exact.ExactLiteral;
+import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
+import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.jboss.weld.extensions.util.annotated.Parameter;
+import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
-public class CoreExtension implements Extension
+class CoreExtension implements Extension
{
- Collection<Bean<?>> additionalBeans = new
ArrayList<Bean<?>>();
+ private final Collection<Bean<?>> additionalBeans;
+ CoreExtension()
+ {
+ this.additionalBeans = new ArrayList<Bean<?>>();
+ }
+
<X> void processAnnotatedType(@Observes final ProcessAnnotatedType<X> pat,
BeanManager bm)
{
if (pat.getAnnotatedType().isAnnotationPresent(Veto.class))
@@ -57,30 +65,23 @@
}
final AnnotatedType<X> at = pat.getAnnotatedType();
+ NewAnnotatedTypeBuilder<X> builder =
NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
- ReannotatedType<X> rt = new ReannotatedType<X>(at);
-
// support for @Named packages
Package pkg = at.getJavaClass().getPackage();
if (pkg.isAnnotationPresent(Named.class))
{
final String packageName = getPackageName(pkg);
- if (at.isAnnotationPresent(Named.class))
+
+ builder.redefineMembers(Named.class, new
MemberAnnotationRedefiner<Named>()
{
- String className = at.getJavaClass().getSimpleName();
- String beanName = getName(at, className);
- rt.define(new NamedLiteral(packageName + '.' + beanName));
- }
- rt.redefineMembers(Named.class, new AnnotationRedefinition<Named>()
- {
-
- @SuppressWarnings("unchecked")
- public Named redefine(Named annotation, Reannotated reannotated)
+
+ public Named redefine(Named annotation, Member member, AnnotationBuilder
annotations)
{
- if (reannotated.isAnnotationPresent(Produces.class))
+ if (annotations.isAnnotationPresent(Produces.class))
{
- String memberName = ((ReannotatedMember<? super X>)
reannotated).getJavaMember().getName();
- String beanName = getName(reannotated, memberName);
+ String memberName = member.getName();
+ String beanName = getName(annotation, memberName);
return new NamedLiteral(packageName + '.' + beanName);
}
else
@@ -90,26 +91,31 @@
}
});
+
+ if (at.isAnnotationPresent(Named.class))
+ {
+ String className = at.getJavaClass().getSimpleName();
+ String beanName = getName(at.getAnnotation(Named.class), className);
+ builder.addToClass(new NamedLiteral(packageName + '.' + beanName));
+ }
+
}
// support for @Exact
- Set<Annotation> qualfiers = rt.getAnnotationsWithMetatype(Qualifier.class);
- boolean defaultQualifier = qualfiers.isEmpty() || (qualfiers.size() == 1 &&
qualfiers.iterator().next().annotationType() == Named.class);
- if (defaultQualifier)
+ Set<Annotation> qualfiers = getAnnotationsWithMetatype(at.getAnnotations(),
Qualifier.class);
+ if (qualfiers.isEmpty() || (qualfiers.size() == 1 &&
qualfiers.iterator().next().annotationType() == Named.class))
{
- rt.define(new AnnotationLiteral<Default>()
- {
- });
+ builder.addToClass(DefaultLiteral.INSTANCE);
}
- rt.define(new ExactLiteral(at.getJavaClass()));
- rt.redefineMembersAndParameters(Exact.class, new
AnnotationRedefinition<Exact>()
+ builder.addToClass(new Exact.ExactLiteral(at.getJavaClass()));
+ builder.redefineMembers(Exact.class, new MemberAnnotationRedefiner<Exact>()
{
-
- public Exact redefine(Exact annotation, Reannotated reannotated)
+
+ public Exact redefine(Exact annotation, Member annotated, AnnotationBuilder
annotations)
{
if (annotation.value() == void.class)
{
- return new ExactLiteral(reannotated.getJavaClass());
+ return new ExactLiteral(getMemberType(annotated));
}
else
{
@@ -118,43 +124,47 @@
}
});
- pat.setAnnotatedType(rt);
+ builder.redefineMemberParameters(Exact.class, new
ParameterAnnotationRedefiner<Exact>()
+ {
+ public Exact redefine(Exact annotation, Parameter annotated, AnnotationBuilder
annotations)
+ {
+ if (annotation.value() == void.class)
+ {
+ return new ExactLiteral(getMemberType(annotated.getDeclaringMember()));
+ }
+ else
+ {
+ return annotation;
+ }
+ }
+
+ });
+
+ pat.setAnnotatedType(builder.create());
+
// support for @Constructs
for (AnnotatedConstructor<X> constructor : at.getConstructors())
{
if (constructor.isAnnotationPresent(Constructs.class))
{
- ReannotatedType<X> rtc = new ReannotatedType<X>(at);
+ NewAnnotatedTypeBuilder<X> annotatedTypeBuilder =
NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
// remove class-level @Named annotation
- rtc.redefine(Named.class, new AnnotationRedefinition<Named>()
+ annotatedTypeBuilder.removeFromClass(Named.class);
+ // remove bean constructors annotated @Inject
+ for (AnnotatedConstructor<X> constructor2 : at.getConstructors())
{
-
- public Named redefine(Named annotation, Reannotated reannotated)
- {
- return null;
- }
- });
- // remove bean constructor annotated @Inject
- rtc.redefineConstructors(Inject.class, new
AnnotationRedefinition<Inject>()
- {
-
- public Inject redefine(Inject annotation, Reannotated reannotated)
- {
- return null;
- }
- });
+ annotatedTypeBuilder.removeFromConstructor(constructor2.getJavaMember(),
Inject.class);
+ }
// make the constructor annotated @Constructs the bean constructor
- rtc.getConstructor(constructor.getJavaMember()).define(new
AnnotationLiteral<Inject>()
- {
- });
+ annotatedTypeBuilder.addToConstructor(constructor.getJavaMember(),
InjectLiteral.INSTANCE);
// add all the annotations of this constructor to the class
for (Annotation ann : constructor.getAnnotations())
{
- rtc.define(ann);
+ annotatedTypeBuilder.addToClass(ann);
}
-
- additionalBeans.add(new BeanImpl<X>(bm.createInjectionTarget(rtc),
rtc));
+ AnnotatedType<X> construtsAnnotatedType = builder.create();
+ additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType,
bm).build());
}
}
}
@@ -177,9 +187,9 @@
return packageName;
}
- private <X> String getName(Annotated annotated, String defaultName)
+ private <X> String getName(Named named, String defaultName)
{
- String beanName = annotated.getAnnotation(Named.class).value();
+ String beanName = named.value();
if (beanName.length() == 0)
{
beanName = defaultName.substring(0, 1).toLowerCase() +
defaultName.substring(1);
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29
19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -26,20 +26,39 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
/**
- * An injection point qualifier that may be used to select
- * the exact bean to be injected, by specifying its implementation
- * class.
+ * An injection point qualifier that may be used to select the exact bean to be
+ * injected, by specifying its implementation class.
*
* @author Gavin King
- *
+ *
*/
@Retention(RUNTIME)
-@Target({METHOD, TYPE, FIELD, PARAMETER})
+@Target( { METHOD, TYPE, FIELD, PARAMETER })
@Documented
@Qualifier
-public @interface Exact {
- Class<?> value() default void.class;
+public @interface Exact
+{
+ Class<?> value() default void.class;
+
+ static class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
+ {
+
+ private static final long serialVersionUID = 4907169607105615674L;
+
+ final Class<?> clazz;
+
+ ExactLiteral(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ public Class<?> value()
+ {
+ return clazz;
+ }
+ }
}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java 2010-04-29
19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -1,37 +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.extensions;
-
-import javax.enterprise.util.AnnotationLiteral;
-
-class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
-{
-
- private static final long serialVersionUID = 4907169607105615674L;
-
- final Class<?> clazz;
-
- ExactLiteral(Class<?> clazz)
- {
- this.clazz = clazz;
- }
-
- public Class<?> value()
- {
- return clazz;
- }
-}
\ No newline at end of file
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -16,6 +16,8 @@
*/
package org.jboss.weld.extensions.bean.generic;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getField;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
@@ -23,12 +25,11 @@
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedField;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
-
/**
* injection target wrapper that injects the configuration for generic beans
*
@@ -53,9 +54,9 @@
private final InjectionTarget<T> delegate;
private final Annotation annotation;
- private final ReannotatedType<T> annotatedType;
+ private final AnnotatedType<T> annotatedType;
- public GenericBeanInjectionTargetWrapper(ReannotatedType<T> annotatedType,
InjectionTarget<T> delegate, Annotation annotation)
+ public GenericBeanInjectionTargetWrapper(AnnotatedType<T> annotatedType,
InjectionTarget<T> delegate, Annotation annotation)
{
this.annotation = annotation;
this.delegate = delegate;
@@ -69,8 +70,8 @@
if (annotation.annotationType().isAssignableFrom(f.getType()))
{
- ReannotatedField<? super T> reannotatedField =
annotatedType.getField(f);
- if (reannotatedField.isAnnotationPresent(InjectConfiguration.class))
+ AnnotatedField<? super T> annotatedField = getField(annotatedType, f);
+ if (annotatedField.isAnnotationPresent(InjectConfiguration.class))
{
try
{
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -41,14 +41,11 @@
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
-import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedField;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedParameter;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
public class GenericExtension implements Extension
{
@@ -92,7 +89,7 @@
event.veto();
}
- //make note of any producer fields that produce generic beans
+ // make note of any producer fields that produce generic beans
for (Object f : type.getFields())
{
AnnotatedField<?> field = (AnnotatedField<?>) f;
@@ -119,7 +116,8 @@
}
/**
- * wraps InjectionTarget to initialise producer fields that produce generic beans
+ * wraps InjectionTarget to initialise producer fields that produce generic
+ * beans
*/
public <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T>
event, BeanManager beanManager)
{
@@ -140,111 +138,115 @@
}
/**
- * Installs the generic beans.
+ * Installs the generic beans.
*/
- public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager
beanManager)
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager
beanManager)
{
- for (Entry<Class<?>, Set<AnnotatedType<?>>> i :
genericBeans.entrySet())
+ for (Entry<Class<?>, Set<AnnotatedType<?>>> entry :
genericBeans.entrySet())
{
- Set<Annotation> concretes = concreteGenerics.get(i.getKey());
+ Set<Annotation> concretes = concreteGenerics.get(entry.getKey());
if (concretes != null)
{
- for (AnnotatedType<?> at : i.getValue())
+ for (AnnotatedType<?> type : entry.getValue())
{
for (Annotation conc : concretes)
{
- final SyntheticQualifier newQualifier = getQualifierForGeneric(conc);
- ReannotatedType<?> rt = new ReannotatedType(at);
+ abd.addBean(redefineType(type, conc, beanManager));
+ }
+ }
+ }
+ }
+ }
- rt.define(newQualifier);
- for (AnnotatedField<?> f : rt.getFields())
- {
- ReannotatedField<?> field = (ReannotatedField<?>) f;
+ private <X> Bean<X> redefineType(AnnotatedType<X> at, Annotation
conc, BeanManager beanManager)
+ {
+ SyntheticQualifier newQualifier = getQualifierForGeneric(conc);
- if (field.isAnnotationPresent(Inject.class))
- {
- //if this is a configuration injection point
- if
(conc.annotationType().isAssignableFrom(field.getJavaMember().getType()))
- {
- field.undefine(Inject.class);
- field.define(new
AnnotationLiteral<InjectConfiguration>()
- {
- });
- }
- else
- {
- //check to see if we should be injecting a generic bean
- //we do this by checking if there are any beans that can be
injected into this point
- //if there is not then we assume it is a generic injection
point
- //this has the downside that if it is actually a deployment
error then it will confuse the user
- Annotation[] qls = getQualifiers(field.getAnnotations(),
beanManager);
- Set<Bean<?>> beans =
beanManager.getBeans(field.getJavaMember().getType(), qls);
- if (beans.isEmpty())
- {
- field.define(newQualifier);
- }
- }
- }
- else if (field.isAnnotationPresent(Produces.class))
- {
- //TODO: register a producer with the appropriate qualifier
- }
- }
- for (AnnotatedMethod<?> m : rt.getMethods())
- {
- //TODO: need to properly handle Observer methods and Disposal
methods
- if (m.isAnnotationPresent(Produces.class))
- {
- //TODO: we need to register the producer bean, so this is not
very useful at the moment
- for (AnnotatedParameter<?> pm : m.getParameters())
- {
- ReannotatedParameter<?> param =
(ReannotatedParameter<?>) pm;
+ NewAnnotatedTypeBuilder<X> builder =
NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
+ builder.addToClass(newQualifier);
+ for (AnnotatedField<? super X> f : at.getFields())
+ {
+ if (f.isAnnotationPresent(Inject.class))
+ {
+ // if this is a configuration injection point
+ if (conc.annotationType().isAssignableFrom(f.getJavaMember().getType()))
+ {
+ builder.removeFromField(f.getJavaMember(), Inject.class);
+ builder.addToField(f.getJavaMember(), InjectConfiguration.INSTANCE);
+ }
+ else
+ {
+ // check to see if we should be injecting a generic bean
+ // we do this by checking if there are any beans that can be
+ // injected into this point
+ // if there is not then we assume it is a generic injection
+ // point
+ // this has the downside that if it is actually a deployment
+ // error then it will confuse the user
+ Annotation[] qls = getQualifiers(f.getAnnotations(), beanManager);
+ Set<Bean<?>> beans =
beanManager.getBeans(f.getJavaMember().getType(), qls);
+ if (beans.isEmpty())
+ {
+ builder.addToField(f.getJavaMember(), newQualifier);
+ }
+ }
+ }
+ else if (f.isAnnotationPresent(Produces.class))
+ {
+ // TODO: register a producer with the appropriate qualifier
+ }
+ }
+ for (AnnotatedMethod<?> m : at.getMethods())
+ {
+ // TODO: need to properly handle Observer methods and Disposal
+ // methods
+ if (m.isAnnotationPresent(Produces.class))
+ {
+ // TODO: we need to register the producer bean, so this is not
+ // very useful at the moment
+ for (AnnotatedParameter<?> pm : m.getParameters())
+ {
+ Class<?> paramType =
m.getJavaMember().getParameterTypes()[pm.getPosition()];
- Class<?> paramType =
m.getJavaMember().getParameterTypes()[param.getPosition()];
+ // check to see if we should be injecting a generic bean
+ // we do this by checking if there are any beans that can be
+ // injected into this point
+ // if there is not then we assume it is a generic injection
+ // point
+ // this has the downside that if it is actually a deployment
+ // error then it will confuse the user
+ Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ if (beans.isEmpty())
+ {
+ builder.addToMethod(m.getJavaMember(), newQualifier);
+ }
+ }
+ }
+ }
- //check to see if we should be injecting a generic bean
- //we do this by checking if there are any beans that can be
injected into this point
- //if there is not then we assume it is a generic injection
point
- //this has the downside that if it is actually a deployment
error then it will confuse the user
- Annotation[] qls = getQualifiers(param.getAnnotations(),
beanManager);
- Set<Bean<?>> beans =
beanManager.getBeans(paramType, qls);
- if (beans.isEmpty())
- {
- param.define(newQualifier);
- }
- }
- }
- }
-
- for (AnnotatedConstructor<?> m : rt.getConstructors())
- {
- if (m.isAnnotationPresent(Inject.class))
- {
- for (AnnotatedParameter<?> pm : m.getParameters())
- {
- ReannotatedParameter<?> param =
(ReannotatedParameter<?>) pm;
-
- Class paramType =
m.getJavaMember().getParameterTypes()[param.getPosition()];
- Annotation[] qls = getQualifiers(param.getAnnotations(),
beanManager);
- Set<Bean<?>> beans =
beanManager.getBeans(paramType, qls);
- if (beans.isEmpty())
- {
- param.define(newQualifier);
- }
- }
- }
- }
- InjectionTarget<?> it = beanManager.createInjectionTarget(rt);
-
- it = new GenericBeanInjectionTargetWrapper(rt, it, conc);
- CustomBeanBuilder<?> builder = new
CustomBeanBuilder(rt,beanManager,it);
- event.addBean(builder.build());
-
+ for (AnnotatedConstructor<X> m : at.getConstructors())
+ {
+ if (m.isAnnotationPresent(Inject.class))
+ {
+ for (AnnotatedParameter<X> pm : m.getParameters())
+ {
+ Class<?> paramType =
m.getJavaMember().getParameterTypes()[pm.getPosition()];
+ Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ if (beans.isEmpty())
+ {
+ builder.addToConstructorParameter(m.getJavaMember(), pm.getPosition(),
newQualifier);
}
}
}
}
+ AnnotatedType<X> newAnnotatedType = builder.create();
+ InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
+ it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, conc);
+ CustomBeanBuilder<X> beanBuilder = new
CustomBeanBuilder<X>(newAnnotatedType, beanManager, it);
+ return beanBuilder.build();
}
public SyntheticQualifier getQualifierForGeneric(Annotation a)
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -19,6 +19,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import javax.enterprise.util.AnnotationLiteral;
+
/**
* synthetic qualifier that is added to Generic beans to signify configuration annotation
injection points
*
@@ -28,4 +30,14 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectConfiguration
{
+
+ public static class InjectConfigurationLiteral extends
AnnotationLiteral<InjectConfiguration> implements InjectConfiguration
+ {
+
+ private static final long serialVersionUID = 5365615929893138969L;
+
+ }
+
+ public static final InjectConfiguration INSTANCE = new InjectConfigurationLiteral();
+
}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java 2010-04-29
19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -1,152 +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.extensions.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Named;
-import javax.inject.Qualifier;
-import javax.inject.Scope;
-
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
-
-/**
- * This implementation of Bean is immutable and threadsafe.
- *
- * @author Gavin King
- * @author Pete Muir
- *
- * @param <T>
- */
-public class BeanImpl<T> implements Bean<T>
-{
-
- private final InjectionTarget<T> injectionTarget;
- private final Set<Type> types;
- private final String name;
- private final Set<Annotation> qualifiers;
- private final Class<? extends Annotation> scope;
- private final boolean alternative;
- private final Class<?> beanClass;
-
- public BeanImpl(InjectionTarget<T> it, ReannotatedType<T> rtc)
- {
- // create the Bean
- this.injectionTarget = it;
- // TODO: this stuff does not handle stereotypes
- Set<? extends Annotation> scopes =
rtc.getAnnotationsWithMetatype(Scope.class);
- this.scope = scopes.isEmpty() ? Dependent.class :
scopes.iterator().next().annotationType();
- if (rtc.isAnnotationPresent(Named.class))
- {
- this.name = rtc.getAnnotation(Named.class).value();
- // no name defaulting for constructors
- if (this.name.length() == 0)
- {
- throw new RuntimeException();
- }
- }
- else
- {
- this.name = null;
- }
- alternative = rtc.isAnnotationPresent(Alternative.class);
- qualifiers = rtc.getAnnotationsWithMetatype(Qualifier.class);
- types = rtc.getTypeClosure();
- beanClass = rtc.getJavaClass();
- }
-
- public BeanImpl(InjectionTarget<T> injectionTarget, Set<Type> types,
Set<Annotation> qualifiers, Class<? extends Annotation> scope, String name,
boolean alternative, Class<?> beanClass)
- {
- this.injectionTarget = injectionTarget;
- this.types = types;
- this.qualifiers = qualifiers;
- this.scope = scope;
- this.name = name;
- this.alternative = alternative;
- this.beanClass = beanClass;
- // TODO: stereotypes!!!
- }
-
- public Class<?> getBeanClass()
- {
- return beanClass;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return injectionTarget.getInjectionPoints();
- }
-
- public String getName()
- {
- return name;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return Collections.unmodifiableSet(qualifiers);
- }
-
- public Class<? extends Annotation> getScope()
- {
- return scope;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return Collections.emptySet(); // TODO
- }
-
- public Set<Type> getTypes()
- {
- return Collections.unmodifiableSet(types);
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public boolean isNullable()
- {
- return false;
- }
-
- public T create(CreationalContext<T> ctx)
- {
- T instance = injectionTarget.produce(ctx);
- injectionTarget.inject(instance, ctx);
- injectionTarget.postConstruct(instance);
- return instance;
- }
-
- public void destroy(T instance, CreationalContext<T> creationalContext)
- {
- injectionTarget.preDestroy(instance);
- creationalContext.release();
- }
-
-}
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -16,12 +16,17 @@
*/
package org.jboss.weld.extensions.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.util.HashSet;
import java.util.Set;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
/**
* class that provides a way of retrieving all methods and fields from a class
*
@@ -63,7 +68,33 @@
}
return null;
}
+
+ public static <X> AnnotatedField<? super X>
getField(AnnotatedType<X> annotatedType, Field field)
+ {
+ for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
+ {
+ if
(annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass())
&& annotatedField.getJavaMember().getName().equals(field.getName()))
+ {
+ return annotatedField;
+ }
+ }
+ return null;
+ }
+
+ public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation>
annotations, Class<? extends Annotation> metaAnnotationType)
+ {
+ Set<Annotation> set = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ set.add(annotation);
+ }
+ }
+ return set;
+ }
+
public static boolean methodExists(Class<?> parent, String name)
{
Class<?> p = parent;
@@ -134,7 +165,7 @@
public static Set<Constructor<?>> getConstructors(Class<?> clazz)
{
- HashSet<Constructor<?>> ret = new HashSet();
+ HashSet<Constructor<?>> ret = new
HashSet<Constructor<?>>();
Class<?> p = clazz;
while (p != null && p != Object.class)
{
@@ -146,4 +177,25 @@
}
return ret;
}
+
+ public static Class<?> getMemberType(Member member)
+ {
+ if (member instanceof Field)
+ {
+ return ((Field) member).getType();
+ }
+ else if (member instanceof Method)
+ {
+ return ((Method) member).getReturnType();
+ }
+ else if (member instanceof Constructor<?>)
+ {
+ return ((Constructor<?>) member).getDeclaringClass();
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Cannot operate on a member of type
" + member.getClass());
+ }
+ }
+
}
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -28,7 +28,7 @@
* @author Stuart Douglas
*
*/
-class AnnotationBuilder
+public class AnnotationBuilder
{
private HashMap<Class<? extends Annotation>, Annotation> annotationMap =
new HashMap<Class<? extends Annotation>, Annotation>();
private Set<Annotation> annotationSet = new HashSet<Annotation>();
@@ -90,5 +90,16 @@
{
return (T) annotationMap.get(anType);
}
+
+ public boolean isAnnotationPresent(Class<?> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+
+ @Override
+ public String toString()
+ {
+ return annotationSet.toString();
+ }
}
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -18,7 +18,7 @@
import java.lang.annotation.Annotation;
-public interface AnnotationRedefiner<X extends Annotation>
+public interface AnnotationRedefiner<T extends Annotation, A>
{
- public X redefine(X annotation, AnnotationBuilder annotations);
+ public T redefine(T annotation, A annotated, AnnotationBuilder annotations);
}
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-04-29
19:00:25 UTC (rev 6195)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-04-29
19:24:23 UTC (rev 6196)
@@ -38,7 +38,7 @@
* Class for constructing a new AnnotatedType. A new instance of builder must be
* used for each annotated type.
*
- * In can either be created with no annotations, or the annotations can be read
+ * In can either be created with no annotations, or the annotations can be read
* from the underlying class or an AnnotatedType
*
* @author Stuart Douglas
@@ -59,136 +59,89 @@
private Map<Method, Map<Integer, Type>> methodParameterTypes = new
HashMap<Method, Map<Integer, Type>>();
private Map<Constructor<?>, Map<Integer, Type>>
constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer,
Type>>();
- public NewAnnotatedTypeBuilder(Class<X> underlying)
+ public static <X> NewAnnotatedTypeBuilder<X> newInstance(Class<X>
underlying)
{
- this(underlying, false);
+ return new NewAnnotatedTypeBuilder<X>(underlying);
}
- public NewAnnotatedTypeBuilder(Class<X> underlying, boolean readAnnotations)
+ public static <X> NewAnnotatedTypeBuilder<X>
newInstance(AnnotatedType<X> underlying)
{
+ return new NewAnnotatedTypeBuilder<X>(underlying);
+ }
+
+ protected NewAnnotatedTypeBuilder(Class<X> underlying)
+ {
this.underlying = underlying;
- if (readAnnotations)
- {
- for (Annotation a : underlying.getAnnotations())
- {
- typeAnnotations.add(a);
- }
+ }
- for (Field f : ReflectionUtils.getFields(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f, ab);
- for (Annotation a : f.getAnnotations())
- {
- ab.add(a);
- }
- }
+ protected NewAnnotatedTypeBuilder(AnnotatedType<X> underlying)
+ {
+ this.underlying = underlying.getJavaClass();
- for (Method m : ReflectionUtils.getMethods(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer,
AnnotationBuilder>();
- methodParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- for (Constructor m : underlying.getConstructors())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer,
AnnotationBuilder>();
- constructorParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- }
}
- public NewAnnotatedTypeBuilder(AnnotatedType<X> type)
+ public NewAnnotatedTypeBuilder<X> readAnnotationsFromUnderlying()
{
- this.underlying = type.getJavaClass();
- for (Annotation a : type.getAnnotations())
+ for (Annotation a : underlying.getAnnotations())
{
typeAnnotations.add(a);
}
- for (AnnotatedField<? super X> f : type.getFields())
+ for (Field f : ReflectionUtils.getFields(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f.getJavaMember(), ab);
+ fields.put(f, ab);
+ f.setAccessible(true);
for (Annotation a : f.getAnnotations())
{
ab.add(a);
}
}
- for (AnnotatedMethod<? super X> m : type.getMethods())
+ for (Method m : ReflectionUtils.getMethods(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m.getJavaMember(), ab);
+ m.setAccessible(true);
+ methods.put(m, ab);
for (Annotation a : m.getAnnotations())
{
ab.add(a);
}
Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer,
AnnotationBuilder>();
- methodParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
+ methodParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
{
AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
{
mab.add(a);
}
}
}
- for (AnnotatedConstructor<X> m : type.getConstructors())
+ for (Constructor m : underlying.getDeclaredConstructors())
{
AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m.getJavaMember(), ab);
+ m.setAccessible(true);
+ constructors.put(m, ab);
for (Annotation a : m.getAnnotations())
{
ab.add(a);
}
Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer,
AnnotationBuilder>();
- constructorParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
+ constructorParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
{
AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
{
mab.add(a);
}
}
}
-
+ return this;
}
public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
@@ -375,47 +328,57 @@
return this;
}
- public <T extends Annotation> NewAnnotatedTypeBuilder<X>
redefine(Class<T> annotationType, AnnotationRedefiner<T> redefinition)
+ public <T extends Annotation> NewAnnotatedTypeBuilder<X>
redefineMemberParameters(Class<T> annotationType,
ParameterAnnotationRedefiner<T> redefinition)
{
- redefineAnnotationBuilder(annotationType, redefinition, typeAnnotations);
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
- }
for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
Map<Integer, AnnotationBuilder> params =
methodParameters.get(e.getKey());
if (params != null)
{
for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ redefineAnnotationBuilder(annotationType, redefinition, new
Parameter(e.getKey(), p.getKey()), p.getValue());
}
}
}
for (Entry<Constructor<X>, AnnotationBuilder> e :
constructors.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
Map<Integer, AnnotationBuilder> params =
constructorParameters.get(e.getKey());
if (params != null)
{
for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ redefineAnnotationBuilder(annotationType, redefinition, new
Parameter(e.getKey(), p.getKey()), p.getValue());
}
}
}
return this;
}
+
+ public <T extends Annotation> NewAnnotatedTypeBuilder<X>
redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T>
redefinition)
+ {
+ for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(),
e.getValue());
+ }
+ for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(),
e.getValue());
+ }
+ for (Entry<Constructor<X>, AnnotationBuilder> e :
constructors.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(),
e.getValue());
+ }
+ return this;
+ }
- protected <T extends Annotation> void redefineAnnotationBuilder(Class<T>
annotationType, AnnotationRedefiner<T> redefinition, AnnotationBuilder builder)
+ protected <T extends Annotation, A> void
redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T, A>
redefinition, A annotated, AnnotationBuilder builder)
{
T an = builder.getAnnotation(annotationType);
- if(an != null)
+ if (an != null)
{
builder.remove(annotationType);
- T newAn = redefinition.redefine(an, builder);
+ T newAn = redefinition.redefine(an, annotated, builder);
if (newAn != null)
{
builder.add(newAn);
@@ -424,8 +387,10 @@
}
/**
- * merges the annotations from an existing AnnoatedType. If they both have the same
annotation
- * on an element overwriteExisting determines which one to keep
+ * merges the annotations from an existing AnnotatedType. If they both have
+ * the same annotation on an element overwriteExisting determines which one
+ * to keep
+ *
* @param type
* @param overwriteExisting
* @return
@@ -461,7 +426,7 @@
methodParameters.put(method.getJavaMember(), params);
}
AnnotationBuilder builder = params.get(p.getPosition());
- if(builder == null)
+ if (builder == null)
{
builder = new AnnotationBuilder();
params.put(p.getPosition(), builder);
@@ -519,17 +484,17 @@
public AnnotatedType<X> create()
{
- Map<Constructor<X>, Map<Integer, AnnotationStore>>
constructorParameterAnnnotations = new HashMap<Constructor<X>,
Map<Integer,AnnotationStore>>();
+ Map<Constructor<X>, Map<Integer, AnnotationStore>>
constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,
AnnotationStore>>();
Map<Constructor<X>, AnnotationStore> constructorAnnotations = new
HashMap<Constructor<X>, AnnotationStore>();
- Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations
= new HashMap<Method, Map<Integer,AnnotationStore>>();
+ Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations
= new HashMap<Method, Map<Integer, AnnotationStore>>();
Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method,
AnnotationStore>();
Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field,
AnnotationStore>();
-
+
for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
{
fieldAnnotations.put(e.getKey(), e.getValue().create());
}
-
+
for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
{
methodAnnotations.put(e.getKey(), e.getValue().create());
@@ -543,7 +508,7 @@
parameterAnnotations.put(pe.getKey(), pe.getValue().create());
}
}
-
+
for (Entry<Constructor<X>, AnnotationBuilder> e :
constructors.entrySet())
{
constructorAnnotations.put(e.getKey(), e.getValue().create());