You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by li...@apache.org on 2012/01/18 00:19:58 UTC

[5/14] git commit: [DELTASPIKE-45] Adding AnnotatedTypeBuilder and needed classes

[DELTASPIKE-45] Adding AnnotatedTypeBuilder and needed classes

I think we need to go over these and make sure everything is good.

Fixing IP issues

Submitted on behalf of a third-part: Red Hat, Inc. under the terms of
the ALv2


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/952aa26f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/952aa26f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/952aa26f

Branch: refs/heads/master
Commit: 952aa26f31e8df58b29bf940e58ee586f93a6d83
Parents: c1949eb
Author: Jason Porter <li...@apache.org>
Authored: Fri Jan 6 23:12:10 2012 -0700
Committer: Jason Porter <li...@apache.org>
Committed: Tue Jan 17 16:13:20 2012 -0700

----------------------------------------------------------------------
 .../core/api/metadata/AnnotatedCallableImpl.java   |   85 +
 .../api/metadata/AnnotatedConstructorImpl.java     |   59 +
 .../core/api/metadata/AnnotatedFieldImpl.java      |   37 +
 .../core/api/metadata/AnnotatedImpl.java           |   98 +
 .../core/api/metadata/AnnotatedMemberImpl.java     |   58 +
 .../core/api/metadata/AnnotatedMethodImpl.java     |   39 +
 .../core/api/metadata/AnnotatedParameterImpl.java  |   52 +
 .../core/api/metadata/AnnotatedTypeImpl.java       |  129 ++
 .../core/api/metadata/AnnotationRedefiner.java     |   43 +
 .../core/api/metadata/AnnotationStore.java         |   65 +
 .../deltaspike/core/api/metadata/Parameter.java    |  206 +++
 .../core/api/metadata/ParameterizedTypeImpl.java   |  102 ++
 .../core/api/metadata/RedefinitionContext.java     |  105 ++
 .../api/metadata/builder/AnnotatedTypeBuilder.java |  987 ++++++++++
 .../api/metadata/builder/AnnotationBuilder.java    |  126 ++
 .../core/api/util/HierarchyDiscovery.java          |  227 +++
 .../deltaspike/core/api/util/Reflections.java      | 1383 +++++++++++++++
 .../api/util/SetAccessiblePrivilegedAction.java    |   44 +
 .../org/apache/deltaspike/core/api/util/Types.java |   97 +
 19 files changed, 3942 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java
new file mode 100644
index 0000000..c90e954
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import org.apache.deltaspike.core.api.metadata.builder.AnnotationBuilder;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+abstract class AnnotatedCallableImpl<X, Y extends Member> extends AnnotatedMemberImpl<X, Y>
+        implements AnnotatedCallable<X>
+{
+
+    private final List<AnnotatedParameter<X>> parameters;
+
+    protected AnnotatedCallableImpl(AnnotatedType<X> declaringType, Y member, Class<?> memberType,
+                                    Class<?>[] parameterTypes, Type[] genericTypes, AnnotationStore annotations,
+                                    Map<Integer, AnnotationStore> parameterAnnotations, Type genericType,
+                                    Map<Integer, Type> parameterTypeOverrides)
+    {
+        super(declaringType, member, memberType, annotations, genericType, null);
+        this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations,
+                parameterTypeOverrides);
+    }
+
+    public List<AnnotatedParameter<X>> getParameters()
+    {
+        return Collections.unmodifiableList(parameters);
+    }
+
+    public AnnotatedParameter<X> getParameter(int index)
+    {
+        return parameters.get(index);
+
+    }
+
+    private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+    {
+        List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+        int len = parameterTypes.length;
+        for (int i = 0; i < len; ++i)
+        {
+            AnnotationBuilder builder = new AnnotationBuilder();
+            if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+            {
+                builder.addAll(parameterAnnotations.get(i));
+            }
+            Type over = null;
+            if (parameterTypeOverrides != null)
+            {
+                over = parameterTypeOverrides.get(i);
+            }
+            AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
+            parameters.add(p);
+        }
+        return parameters;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java
new file mode 100644
index 0000000..aeae547
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+/**
+ *
+ */
+class AnnotatedConstructorImpl<X> extends AnnotatedCallableImpl<X, Constructor<X>> implements AnnotatedConstructor<X>
+{
+
+    AnnotatedConstructorImpl(AnnotatedTypeImpl<X> type, Constructor<?> constructor, AnnotationStore annotations,
+                             Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> typeOverrides)
+    {
+
+        super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(),
+                getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides);
+    }
+
+    private static Type[] getGenericArray(Constructor<?> constructor)
+    {
+        Type[] genericTypes = constructor.getGenericParameterTypes();
+        // for inner classes genericTypes and parameterTypes can be different
+        // length, this is a hack to fix this.
+        // TODO: investigate this behavior further, on different JVM's and
+        // compilers
+        if (genericTypes.length + 1 == constructor.getParameterTypes().length)
+        {
+            genericTypes = new Type[constructor.getGenericParameterTypes().length + 1];
+            genericTypes[0] = constructor.getParameterTypes()[0];
+            for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i)
+            {
+                genericTypes[i + 1] = constructor.getGenericParameterTypes()[i];
+            }
+        }
+        return genericTypes;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java
new file mode 100644
index 0000000..1723d21
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+
+/**
+ *
+ */
+class AnnotatedFieldImpl<X> extends AnnotatedMemberImpl<X, Field> implements AnnotatedField<X>
+{
+
+    AnnotatedFieldImpl(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations, Type overridenType)
+    {
+        super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java
new file mode 100644
index 0000000..06851c2
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import org.apache.deltaspike.core.api.util.HierarchyDiscovery;
+
+import javax.enterprise.inject.spi.Annotated;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The base class for all New Annotated types.
+ */
+abstract class AnnotatedImpl implements Annotated
+{
+
+    private final Type type;
+    private final Set<Type> typeClosure;
+    private final AnnotationStore annotations;
+
+    protected AnnotatedImpl(Class<?> type, AnnotationStore annotations, Type genericType, Type overridenType)
+    {
+        if (overridenType == null)
+        {
+            if (genericType != null)
+            {
+                typeClosure = new HierarchyDiscovery(genericType).getTypeClosure();
+                this.type = genericType;
+            }
+            else
+            {
+                typeClosure = new HierarchyDiscovery(type).getTypeClosure();
+                this.type = type;
+            }
+        }
+        else
+        {
+            this.type = overridenType;
+            this.typeClosure = Collections.singleton(overridenType);
+        }
+
+
+        if (annotations == null)
+        {
+            this.annotations = new AnnotationStore();
+        }
+        else
+        {
+            this.annotations = annotations;
+        }
+    }
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+    {
+        return annotations.getAnnotation(annotationType);
+    }
+
+    public Set<Annotation> getAnnotations()
+    {
+        return annotations.getAnnotations();
+    }
+
+    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+    {
+        return annotations.isAnnotationPresent(annotationType);
+    }
+
+    public Set<Type> getTypeClosure()
+    {
+        return new HashSet<Type>(typeClosure);
+    }
+
+    public Type getBaseType()
+    {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java
new file mode 100644
index 0000000..990b313
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+
+/**
+ *
+ */
+abstract class AnnotatedMemberImpl<X, M extends Member> extends AnnotatedImpl implements AnnotatedMember<X>
+{
+    private final AnnotatedType<X> declaringType;
+    private final M javaMember;
+
+    protected AnnotatedMemberImpl(AnnotatedType<X> declaringType, M member, Class<?> memberType,
+                                  AnnotationStore annotations, Type genericType, Type overridenType)
+    {
+        super(memberType, annotations, genericType, overridenType);
+        this.declaringType = declaringType;
+        this.javaMember = member;
+    }
+
+    public AnnotatedType<X> getDeclaringType()
+    {
+        return declaringType;
+    }
+
+    public M getJavaMember()
+    {
+        return javaMember;
+    }
+
+    public boolean isStatic()
+    {
+        return Modifier.isStatic(javaMember.getModifiers());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java
new file mode 100644
index 0000000..7f38b7e
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+/**
+ * @author Stuart Douglas
+ */
+class AnnotatedMethodImpl<X> extends AnnotatedCallableImpl<X, Method> implements AnnotatedMethod<X>
+{
+    AnnotatedMethodImpl(AnnotatedType<X> type, Method method, AnnotationStore annotations,
+                        Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+    {
+        super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(),
+                annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java
new file mode 100644
index 0000000..8b7feb5
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import java.lang.reflect.Type;
+
+/**
+ *
+ */
+class AnnotatedParameterImpl<X> extends AnnotatedImpl implements AnnotatedParameter<X>
+{
+
+    private final int position;
+    private final AnnotatedCallable<X> declaringCallable;
+
+    AnnotatedParameterImpl(AnnotatedCallable<X> declaringCallable, Class<?> type, int position,
+                           AnnotationStore annotations, Type genericType, Type typeOverride)
+    {
+        super(type, annotations, genericType, typeOverride);
+        this.declaringCallable = declaringCallable;
+        this.position = position;
+    }
+
+    public AnnotatedCallable<X> getDeclaringCallable()
+    {
+        return declaringCallable;
+    }
+
+    public int getPosition()
+    {
+        return position;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java
new file mode 100644
index 0000000..a500f76
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class AnnotatedTypeImpl<X> extends AnnotatedImpl implements AnnotatedType<X>
+{
+
+    private final Set<AnnotatedConstructor<X>> constructors;
+    private final Set<AnnotatedField<? super X>> fields;
+    private final Set<AnnotatedMethod<? super X>> methods;
+
+    private final Class<X> javaClass;
+
+    /**
+     * We make sure that there is a NewAnnotatedMember for every public
+     * method/field/constructor
+     * <p/>
+     * If annotation have been added to other methods as well we add them to
+     */
+    public AnnotatedTypeImpl(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<?>, AnnotationStore> constructorAnnotations, Map<Constructor<?>, Map<Integer, AnnotationStore>> constructorParameterAnnotations, Map<Field, Type> fieldTypes, Map<Method, Map<Integer, Type>> methodParameterTypes, Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes)
+    {
+        super(clazz, typeAnnotations, null, null);
+        this.javaClass = clazz;
+        this.constructors = new HashSet<AnnotatedConstructor<X>>();
+        Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
+        Set<Method> mset = new HashSet<Method>();
+        Set<Field> fset = new HashSet<Field>();
+        for (Constructor<?> c : clazz.getConstructors())
+        {
+            AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), constructorParameterTypes.get(c));
+            constructors.add(nc);
+            cset.add(c);
+        }
+        for (Map.Entry<Constructor<?>, AnnotationStore> c : constructorAnnotations.entrySet())
+        {
+            if (!cset.contains(c.getKey()))
+            {
+                AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<X>(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()), constructorParameterTypes.get(c.getKey()));
+                constructors.add(nc);
+            }
+        }
+        this.methods = new HashSet<AnnotatedMethod<? super X>>();
+        for (Method m : clazz.getMethods())
+        {
+            if (!m.getDeclaringClass().equals(Object.class))
+            {
+                AnnotatedMethodImpl<X> met = new AnnotatedMethodImpl<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m));
+                methods.add(met);
+                mset.add(m);
+            }
+        }
+        for (Map.Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
+        {
+            if (!c.getKey().getDeclaringClass().equals(Object.class) && !mset.contains(c.getKey()))
+            {
+                AnnotatedMethodImpl<X> nc = new AnnotatedMethodImpl<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
+                methods.add(nc);
+            }
+        }
+        this.fields = new HashSet<AnnotatedField<? super X>>();
+        for (Field f : clazz.getFields())
+        {
+            AnnotatedField<X> b = new AnnotatedFieldImpl<X>(this, f, fieldAnnotations.get(f), fieldTypes.get(f));
+            fields.add(b);
+            fset.add(f);
+        }
+        for (Map.Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
+        {
+            if (!fset.contains(e.getKey()))
+            {
+                fields.add(new AnnotatedFieldImpl<X>(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey())));
+            }
+        }
+    }
+
+    public Set<AnnotatedConstructor<X>> getConstructors()
+    {
+        return Collections.unmodifiableSet(constructors);
+    }
+
+    public Set<AnnotatedField<? super X>> getFields()
+    {
+        return Collections.unmodifiableSet(fields);
+    }
+
+    public Class<X> getJavaClass()
+    {
+        return javaClass;
+    }
+
+    public Set<AnnotatedMethod<? super X>> getMethods()
+    {
+        return Collections.unmodifiableSet(methods);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java
new file mode 100644
index 0000000..6774867
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * An implementation {@link AnnotationRedefiner} can be applied to an
+ * {@link AnnotatedTypeBuilder}, and receives callbacks for each annotation of
+ * the type is it applied for.
+ *
+ * @author Pete Muir
+ * @see AnnotatedTypeBuilder
+ */
+public interface AnnotationRedefiner<A extends Annotation>
+{
+    /**
+     * Callback invoked for each annotation of the type the
+     * {@link AnnotationRedefiner} is applied for.
+     *
+     * @param ctx
+     */
+    public void redefine(RedefinitionContext<A> ctx);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java
new file mode 100644
index 0000000..9594293
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Set;
+
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableSet;
+
+/**
+ * A helper class used to hold annotations on a type or member.
+ */
+//X TODO: JavaDoc
+public class AnnotationStore
+{
+    private final Map<Class<? extends Annotation>, Annotation> annotationMap;
+    private final Set<Annotation> annotationSet;
+
+    public AnnotationStore(Map<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
+    {
+        this.annotationMap = annotationMap;
+        this.annotationSet = unmodifiableSet(annotationSet);
+    }
+
+    public AnnotationStore()
+    {
+        this.annotationMap = emptyMap();
+        this.annotationSet = emptySet();
+    }
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+    {
+        return annotationType.cast(annotationMap.get(annotationType));
+    }
+
+    public Set<Annotation> getAnnotations()
+    {
+        return annotationSet;
+    }
+
+    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+    {
+        return annotationMap.containsKey(annotationType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java
new file mode 100644
index 0000000..3dd8016
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import org.apache.deltaspike.core.api.util.Reflections;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+
+/**
+ * An implementation of Member for parameters
+ *
+ * @author pmuir
+ */
+abstract public class Parameter<X> implements AnnotatedElement
+{
+
+    public static <X> Parameter<X> create(Member declaringMember, int position)
+    {
+        if (declaringMember instanceof Method)
+        {
+            return new MethodParameter<X>((Method) declaringMember, position);
+        }
+        else if (declaringMember instanceof Constructor<?>)
+        {
+            return new ConstructorParameter<X>(Reflections.<Constructor<X>>cast(declaringMember), position);
+        }
+        else
+        {
+            throw new IllegalArgumentException("Can only process members of type Method and Constructor, cannot process " + declaringMember);
+        }
+    }
+
+    private static class MethodParameter<X> extends Parameter<X>
+    {
+
+        private final Method declaringMethod;
+
+        private MethodParameter(Method declaringMethod, int position)
+        {
+            super(position);
+            this.declaringMethod = declaringMethod;
+        }
+
+        @Override
+        public Method getDeclaringMember()
+        {
+            return declaringMethod;
+        }
+
+        public Annotation[] getAnnotations()
+        {
+            if (declaringMethod.getParameterAnnotations().length > getPosition())
+            {
+                return declaringMethod.getParameterAnnotations()[getPosition()];
+            }
+            else
+            {
+                return Reflections.EMPTY_ANNOTATION_ARRAY;
+            }
+        }
+
+        @Override
+        public Type getBaseType()
+        {
+            if (declaringMethod.getGenericParameterTypes().length > getPosition())
+            {
+                return declaringMethod.getGenericParameterTypes()[getPosition()];
+            }
+            else
+            {
+                return declaringMethod.getParameterTypes()[getPosition()];
+            }
+        }
+
+    }
+
+    private static class ConstructorParameter<X> extends Parameter<X>
+    {
+
+        private final Constructor<X> declaringConstructor;
+
+        private ConstructorParameter(Constructor<X> declaringConstructor, int position)
+        {
+            super(position);
+            this.declaringConstructor = declaringConstructor;
+        }
+
+        @Override
+        public Constructor<X> getDeclaringMember()
+        {
+            return declaringConstructor;
+        }
+
+        public Annotation[] getAnnotations()
+        {
+            if (declaringConstructor.getParameterAnnotations().length > getPosition())
+            {
+                return declaringConstructor.getParameterAnnotations()[getPosition()];
+            }
+            else
+            {
+                return Reflections.EMPTY_ANNOTATION_ARRAY;
+            }
+        }
+
+        @Override
+        public Type getBaseType()
+        {
+            if (declaringConstructor.getGenericParameterTypes().length > getPosition())
+            {
+                return declaringConstructor.getGenericParameterTypes()[getPosition()];
+            }
+            else
+            {
+                return declaringConstructor.getParameterTypes()[getPosition()];
+            }
+        }
+
+    }
+
+    private final int position;
+
+    Parameter(int position)
+    {
+        this.position = position;
+    }
+
+    public abstract Member getDeclaringMember();
+
+    public int getPosition()
+    {
+        return position;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 1;
+        hash = hash * 31 + getDeclaringMember().hashCode();
+        hash = hash * 31 + Integer.valueOf(position).hashCode();
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj instanceof Parameter<?>)
+        {
+            Parameter<?> that = (Parameter<?>) obj;
+            return this.getDeclaringMember().equals(that.getDeclaringMember()) && this.getPosition() == that.getPosition();
+        }
+        else
+        {
+            return false;
+        }
+
+    }
+
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+    {
+        for (Annotation annotation : getAnnotations())
+        {
+            if (annotation.annotationType().equals(annotationClass))
+            {
+                return annotationClass.cast(annotation);
+            }
+        }
+        return null;
+    }
+
+    public Annotation[] getDeclaredAnnotations()
+    {
+        return getAnnotations();
+    }
+
+    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
+    {
+        return getAnnotation(annotationClass) != null;
+    }
+
+    public abstract Type getBaseType();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java
new file mode 100644
index 0000000..123eab9
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+
+/**
+ * A basic implementation of {@link ParameterizedType}.
+ */
+public class ParameterizedTypeImpl implements ParameterizedType
+{
+    private final Type[] actualTypeArguments;
+    private final Type rawType;
+    private final Type ownerType;
+
+    public ParameterizedTypeImpl(Type rawType, Type[] actualTypeArguments, Type ownerType)
+    {
+        this.actualTypeArguments = actualTypeArguments;
+        this.rawType = rawType;
+        this.ownerType = ownerType;
+    }
+
+    public Type[] getActualTypeArguments()
+    {
+        return Arrays.copyOf(actualTypeArguments, actualTypeArguments.length);
+    }
+
+    public Type getOwnerType()
+    {
+        return ownerType;
+    }
+
+    public Type getRawType()
+    {
+        return rawType;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return Arrays.hashCode(actualTypeArguments) ^ (ownerType == null ? 0 : ownerType.hashCode()) ^ (rawType == null ? 0 : rawType.hashCode());
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        else if (obj instanceof ParameterizedType)
+        {
+            ParameterizedType that = (ParameterizedType) obj;
+            Type thatOwnerType = that.getOwnerType();
+            Type thatRawType = that.getRawType();
+            return (ownerType == null ? thatOwnerType == null : ownerType.equals(thatOwnerType)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && Arrays.equals(actualTypeArguments, that.getActualTypeArguments());
+        }
+        else
+        {
+            return false;
+        }
+
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append(rawType);
+        if (actualTypeArguments.length > 0)
+        {
+            sb.append("<");
+            for (Type actualType : actualTypeArguments)
+            {
+                sb.append(actualType);
+                sb.append(",");
+            }
+            sb.delete(sb.length() - 1, sb.length());
+            sb.append(">");
+        }
+        return sb.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/952aa26f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java
new file mode 100644
index 0000000..8e51683
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.api.metadata;
+
+import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.api.metadata.builder.AnnotationBuilder;
+import org.apache.deltaspike.core.api.util.Reflections;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+/**
+ * Provides access to the context of an annotation redefinition.
+ *
+ * @author Pete Muir
+ * @see AnnotatedTypeBuilder
+ * @see AnnotationRedefiner
+ */
+public class RedefinitionContext<A extends Annotation>
+{
+
+    private final AnnotatedElement annotatedElement;
+    private final Type baseType;
+    private final AnnotationBuilder annotationBuilder;
+    private final String elementName;
+
+    public RedefinitionContext(AnnotatedElement annotatedElement, Type baseType, AnnotationBuilder annotationBuilder, String elementName)
+    {
+        this.annotatedElement = annotatedElement;
+        this.baseType = baseType;
+        this.annotationBuilder = annotationBuilder;
+        this.elementName = elementName;
+    }
+
+    /**
+     * Access to the {@link AnnotatedElement} on which this annotation is
+     * defined. If the annotation is defined on a Field, this may be cast to
+     * {@link Field}, if defined on a method, this may be cast to {@link Method},
+     * if defined on a constructor, this may be cast to {@link Constructor}, if
+     * defined on a class, this may be cast to {@link Class}, or if
+     * defined on a parameter, this may be cast to {@link Parameter}
+     */
+    public AnnotatedElement getAnnotatedElement()
+    {
+        return annotatedElement;
+    }
+
+    /**
+     * Access to the {@link Type} of the element on which this annotation is
+     * defined
+     */
+    public Type getBaseType()
+    {
+        return baseType;
+    }
+
+    /**
+     * Access to the raw type of the element on which the annotation is defined
+     *
+     * @return
+     */
+    public Class<?> getRawType()
+    {
+        return Reflections.getRawType(baseType);
+    }
+
+    /**
+     * Access to the annotations present on the element. It is safe to modify the
+     * annotations present using the {@link AnnotationBuilder}
+     */
+    public AnnotationBuilder getAnnotationBuilder()
+    {
+        return annotationBuilder;
+    }
+
+    /**
+     * Access to the name of the element, or null if this represents a
+     * constructor, parameter or class.
+     */
+    public String getElementName()
+    {
+        return elementName;
+    }
+
+}