You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/01/20 23:23:10 UTC
[1/2] git commit: DELTASPIKE-45 AnnotationRedefiner removed
Updated Branches:
refs/heads/master f3f4eb155 -> 0532fabf2
DELTASPIKE-45 AnnotationRedefiner removed
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/32e56e1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/32e56e1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/32e56e1f
Branch: refs/heads/master
Commit: 32e56e1f7fdc69d2ac902e75cee551eade81c6ca
Parents: f3f4eb1
Author: gpetracek <gp...@apache.org>
Authored: Wed Jan 18 13:19:19 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Fri Jan 20 23:18:33 2012 +0100
----------------------------------------------------------------------
.../core/api/metadata/AnnotationRedefiner.java | 39 ------
.../core/api/metadata/RedefinitionContext.java | 100 ---------------
.../api/metadata/builder/AnnotatedTypeBuilder.java | 73 -----------
.../api/metadata/AnnotatedTypeBuilderTest.java | 21 +++-
.../api/metadata/NamedAnnotationRedefiner.java | 51 --------
5 files changed, 16 insertions(+), 268 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/32e56e1f/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
deleted file mode 100644
index 1b9c02a..0000000
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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;
-
-/**
- * An implementation {@link AnnotationRedefiner} can be applied to an
- * {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}, and receives callbacks for each annotation of
- * the type is it applied for.
- *
- * @see org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder
- */
-public interface AnnotationRedefiner
-{
- /**
- * Callback invoked for each annotation of the type the
- * {@link AnnotationRedefiner} is applied for.
- *
- * @param ctx
- */
- public void redefine(RedefinitionContext ctx);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/32e56e1f/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
deleted file mode 100644
index 9d90a2a..0000000
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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 org.apache.deltaspike.core.api.util.Reflections;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Type;
-
-/**
- * Provides access to the context of an annotation redefinition.
- *
- * @see org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder
- * @see AnnotationRedefiner
- */
-public class RedefinitionContext
-{
-
- 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 java.lang.reflect.Field}, if defined on a method, this may be cast to {@link java.lang.reflect.Method},
- * if defined on a constructor, this may be cast to {@link java.lang.reflect.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 org.apache.deltaspike.core.api.metadata.builder.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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/32e56e1f/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java
index 1df78fc..91dafe1 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java
@@ -19,8 +19,6 @@
package org.apache.deltaspike.core.api.metadata.builder;
-import org.apache.deltaspike.core.api.metadata.AnnotationRedefiner;
-import org.apache.deltaspike.core.api.metadata.RedefinitionContext;
import org.apache.deltaspike.core.api.util.Reflections;
import javax.enterprise.inject.spi.Annotated;
@@ -30,7 +28,6 @@ import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
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;
@@ -509,76 +506,6 @@ public class AnnotatedTypeBuilder<X>
}
/**
- * Redefine any annotations of the specified type. The redefinition callback
- * will be invoked for any annotation on the type definition or any of it's
- * members.
- *
- * @param annotationType the type of the annotation for which to call the
- * redefinition
- * @param redefinition the redefinition callback
- * @throws IllegalArgumentException if the annotationType or redefinition is
- * null
- */
- public <A extends Annotation> AnnotatedTypeBuilder<X> redefine(Class<A> annotationType, AnnotationRedefiner redefinition)
- {
- if (annotationType == null)
- {
- throw new IllegalArgumentException(String.format("%s parameter must not be null", "annotationType"));
- }
- if (redefinition == null)
- {
- throw new IllegalArgumentException(String.format("%s parameter must not be null", "redefinition"));
- }
- redefineAnnotationBuilder(annotationType, redefinition, javaClass, javaClass, typeAnnotations, null);
- for (Map.Entry<Field, AnnotationBuilder> field : fields.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, field.getKey(), field.getKey().getGenericType(), field.getValue(), field.getKey().getName());
- }
- for (Map.Entry<Method, AnnotationBuilder> method : methods.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, method.getKey(), method.getKey().getGenericReturnType(), method.getValue(), method.getKey().getName());
- }
- for (Map.Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, constructor.getKey(), constructor.getKey().getDeclaringClass(), constructor.getValue(), null);
- }
- for (Map.Entry<Method, AnnotationBuilder> method : methods.entrySet())
- {
- if (methodParameters.get(method.getKey()) != null)
- {
- for (Map.Entry<Integer, AnnotationBuilder> parameter : methodParameters.get(method.getKey()).entrySet())
- {
- Parameter<?> p = Parameter.create(method.getKey(), parameter.getKey());
- redefineAnnotationBuilder(annotationType, redefinition, p, p.getBaseType(), parameter.getValue(), null);
- }
- }
- }
- for (Map.Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
- {
- if (constructorParameters.get(constructor.getKey()) != null)
- {
- for (Map.Entry<Integer, AnnotationBuilder> parameter : constructorParameters.get(constructor.getKey()).entrySet())
- {
- Parameter<?> p = Parameter.create(constructor.getKey(), parameter.getKey());
- redefineAnnotationBuilder(annotationType, redefinition, p, p.getBaseType(), parameter.getValue(), null);
- }
- }
- }
- return this;
- }
-
- protected <A extends Annotation> void redefineAnnotationBuilder(Class<A> annotationType,
- AnnotationRedefiner redefinition,
- AnnotatedElement annotated, Type baseType,
- AnnotationBuilder builder, String elementName)
- {
- if (builder.isAnnotationPresent(annotationType))
- {
- redefinition.redefine(new RedefinitionContext(annotated, baseType, builder, elementName));
- }
- }
-
- /**
* Reads in from an existing AnnotatedType. Any elements not present are
* added. The javaClass will be read in. If the annotation already exists on
* that element in the builder the read annotation will be used.
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/32e56e1f/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
index 5bf2949..ea0f467 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
@@ -19,7 +19,10 @@
package org.apache.deltaspike.test.api.metadata;
+import org.apache.deltaspike.core.api.literal.AlternativeLiteral;
import org.apache.deltaspike.core.api.literal.AnyLiteral;
+import org.apache.deltaspike.core.api.literal.ApplicationScopedLiteral;
+import org.apache.deltaspike.core.api.literal.NamedLiteral;
import org.apache.deltaspike.core.api.literal.TypedLiteral;
import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
import org.junit.Test;
@@ -43,15 +46,24 @@ import static org.junit.Assert.assertTrue;
public class AnnotatedTypeBuilderTest
{
-
@Test
public void testTypeLevelAnnotationRedefinition()
{
AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
builder.readFromType(Cat.class);
- builder.redefine(Named.class, new NamedAnnotationRedefiner());
- final AnnotatedType<Cat> cat = builder.create();
+ AnnotatedType<Cat> cat = builder.create();
+
+ if ("cat".equals(cat.getAnnotation(Named.class).value()))
+ {
+ builder.addToClass(new AlternativeLiteral())
+ .addToClass(new ApplicationScopedLiteral())
+ .removeFromClass(Named.class)
+ .addToClass(new NamedLiteral("tomcat"));
+
+ cat = builder.create();
+ }
+
assertEquals(3, cat.getAnnotations().size());
assertTrue(cat.isAnnotationPresent(Named.class));
assertTrue(cat.isAnnotationPresent(Alternative.class));
@@ -102,5 +114,4 @@ public class AnnotatedTypeBuilderTest
}
}
}
-}
-
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/32e56e1f/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/NamedAnnotationRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/NamedAnnotationRedefiner.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/NamedAnnotationRedefiner.java
deleted file mode 100644
index c3609d7..0000000
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/NamedAnnotationRedefiner.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.test.api.metadata;
-
-import org.apache.deltaspike.core.api.literal.AlternativeLiteral;
-import org.apache.deltaspike.core.api.literal.ApplicationScopedLiteral;
-import org.apache.deltaspike.core.api.literal.NamedLiteral;
-import org.apache.deltaspike.core.api.metadata.AnnotationRedefiner;
-import org.apache.deltaspike.core.api.metadata.RedefinitionContext;
-import org.apache.deltaspike.core.api.metadata.builder.AnnotationBuilder;
-
-import javax.inject.Named;
-
-/**
- *
- */
-public class NamedAnnotationRedefiner implements AnnotationRedefiner
-{
- @Override
- public void redefine(RedefinitionContext ctx)
- {
- Named named = ctx.getAnnotatedElement().getAnnotation(Named.class);
- if ("cat".equals(named.value()))
- {
- AnnotationBuilder builder = ctx.getAnnotationBuilder();
- // add two annotations
- builder.add(new AlternativeLiteral());
- builder.add(new ApplicationScopedLiteral());
- // change the value of @Named
- builder.remove(Named.class);
- builder.add(new NamedLiteral("tomcat"));
- }
- }
-}