You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/12/11 21:54:14 UTC
svn commit: r1213059 - in /commons/sandbox/meiyo/trunk/src:
main/java/org/apache/commons/meiyo/classvisitor/
test/java/org/apache/commons/meiyo/classvisitor/
Author: simonetripodi
Date: Sun Dec 11 20:54:14 2011
New Revision: 1213059
URL: http://svn.apache.org/viewvc?rev=1213059&view=rev
Log:
changed internal Class visitor architecture to allow type inference in chain builder methods
Added:
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java (with props)
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java (with props)
Modified:
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AbstractVisitorConfiguration.java
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinder.java
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinderImpl.java
commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/Key.java
commons/sandbox/meiyo/trunk/src/test/java/org/apache/commons/meiyo/classvisitor/ClassVisitorTestCase.java
Modified: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AbstractVisitorConfiguration.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AbstractVisitorConfiguration.java?rev=1213059&r1=1213058&r2=1213059&view=diff
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AbstractVisitorConfiguration.java (original)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AbstractVisitorConfiguration.java Sun Dec 11 20:54:14 2011
@@ -77,7 +77,7 @@ public abstract class AbstractVisitorCon
* @return a new builder to associate an annotation handler to the given annotated element.
* @see AnnotationHandlerBinder#handleType()
*/
- protected final AnnotatedHandlerBuilder<Class> handleType()
+ protected final AnnotatedHandlerBuilder<Class<?>> handleType()
{
return wrapped.handleType();
}
@@ -88,7 +88,7 @@ public abstract class AbstractVisitorCon
* @return a new builder to associate an annotation handler to the given annotated element.
* @see AnnotationHandlerBinder#handleConstructor()
*/
- protected final AnnotatedHandlerBuilder<Constructor> handleConstructor()
+ protected final AnnotatedHandlerBuilder<Constructor<?>> handleConstructor()
{
return wrapped.handleConstructor();
}
Modified: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinder.java?rev=1213059&r1=1213058&r2=1213059&view=diff
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinder.java (original)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinder.java Sun Dec 11 20:54:14 2011
@@ -41,14 +41,14 @@ public interface AnnotationHandlerBinder
*
* @return a new builder to associate an annotation handler to the given annotated element.
*/
- AnnotatedHandlerBuilder<Class> handleType();
+ AnnotatedHandlerBuilder<Class<?>> handleType();
/**
* Configure a new scanning rule for {@code Constructor}.
*
* @return a new builder to associate an annotation handler to the given annotated element.
*/
- AnnotatedHandlerBuilder<Constructor> handleConstructor();
+ AnnotatedHandlerBuilder<Constructor<?>> handleConstructor();
/**
* Configure a new scanning rule for {@code Field}.
Modified: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinderImpl.java?rev=1213059&r1=1213058&r2=1213059&view=diff
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinderImpl.java (original)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/AnnotationHandlerBinderImpl.java Sun Dec 11 20:54:14 2011
@@ -37,31 +37,31 @@ final class AnnotationHandlerBinderImpl
/**
* The registry used to store {@code (AnnotatedElement/Annotation, AnnotationHandler)}
*/
- private final Map<Key, AnnotationHandler<AnnotatedElement, Annotation>> registry =
- new HashMap<Key, AnnotationHandler<AnnotatedElement, Annotation>>();
+ private final Map<Key, AnnotationHandler<? extends AnnotatedElement, ? extends Annotation>> registry =
+ new HashMap<Key, AnnotationHandler<? extends AnnotatedElement, ? extends Annotation>>();
/**
* {@inheritDoc}
*/
public AnnotatedHandlerBuilder<Package> handlePackage()
{
- return handleElement( Package.class );
+ return new DefaultAnnotatedHandlerBuilder<Package>( Package.class, registry );
}
/**
* {@inheritDoc}
*/
- public AnnotatedHandlerBuilder<Class> handleType()
+ public AnnotatedHandlerBuilder<Class<?>> handleType()
{
- return handleElement( Class.class );
+ return new DefaultAnnotatedHandlerBuilder<Class<?>>( Class.class, registry );
}
/**
* {@inheritDoc}
*/
- public AnnotatedHandlerBuilder<Constructor> handleConstructor()
+ public AnnotatedHandlerBuilder<Constructor<?>> handleConstructor()
{
- return handleElement( Constructor.class );
+ return new DefaultAnnotatedHandlerBuilder<Constructor<?>>( Constructor.class, registry );
}
/**
@@ -69,7 +69,7 @@ final class AnnotationHandlerBinderImpl
*/
public AnnotatedHandlerBuilder<Field> handleField()
{
- return handleElement( Field.class );
+ return new DefaultAnnotatedHandlerBuilder<Field>( Field.class, registry );
}
/**
@@ -77,39 +77,7 @@ final class AnnotationHandlerBinderImpl
*/
public AnnotatedHandlerBuilder<Method> handleMethod()
{
- return handleElement( Method.class );
- }
-
- /**
- * {@inheritDoc}
- */
- private <E extends AnnotatedElement> AnnotatedHandlerBuilder<E> handleElement( final Class<E> annotatedElementType )
- {
- return new AnnotatedHandlerBuilder<E>()
- {
- public <A extends Annotation> LinkedHandlingBuilder<E, A> annotatedWith( final Class<A> annotationType )
- {
- if ( annotationType == null )
- {
- throw new IllegalArgumentException( "Parameter 'annotationType' must not be null" );
- }
-
- return new LinkedHandlingBuilder<E, A>()
- {
- @SuppressWarnings( "unchecked" )
- public void withHandler( AnnotationHandler<E, A> handler )
- {
- if ( handler == null )
- {
- throw new IllegalArgumentException( "Parameter 'handler' must not be null" );
- }
-
- registry.put( new Key( annotatedElementType, annotationType ),
- (AnnotationHandler<AnnotatedElement, Annotation>) handler );
- }
- };
- }
- };
+ return new DefaultAnnotatedHandlerBuilder<Method>( Method.class, registry );
}
/**
@@ -123,7 +91,11 @@ final class AnnotationHandlerBinderImpl
public AnnotationHandler<AnnotatedElement, Annotation> getHandler( Class<? extends AnnotatedElement> annotatedElementType,
Class<? extends Annotation> annotationType )
{
- return registry.get( new Key( annotatedElementType, annotationType ) );
+ @SuppressWarnings( "unchecked" ) // types driven by annotatedElementType/annotationType
+ AnnotationHandler<AnnotatedElement, Annotation> handler =
+ (AnnotationHandler<AnnotatedElement, Annotation>) registry.get( new Key( annotatedElementType,
+ annotationType ) );
+ return handler;
}
}
Added: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java?rev=1213059&view=auto
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java (added)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java Sun Dec 11 20:54:14 2011
@@ -0,0 +1,56 @@
+package org.apache.commons.meiyo.classvisitor;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+final class DefaultAnnotatedHandlerBuilder<E extends AnnotatedElement>
+ implements AnnotatedHandlerBuilder<E>
+{
+
+ private final Type rawType;
+
+ private final Map<Key, AnnotationHandler<? extends AnnotatedElement, ? extends Annotation>> registry;
+
+ DefaultAnnotatedHandlerBuilder( Type rawType,
+ Map<Key, AnnotationHandler<? extends AnnotatedElement,
+ ? extends Annotation>> registry )
+ {
+ this.rawType = rawType;
+ this.registry = registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <A extends Annotation> LinkedHandlingBuilder<E, A> annotatedWith( Class<A> annotationType )
+ {
+ if ( annotationType == null )
+ {
+ throw new IllegalArgumentException( "Parameter 'annotationType' must not be null" );
+ }
+
+ return new DefaultLinkedHandlingBuilder<E, A>( new Key( rawType, annotationType ), registry );
+ }
+
+}
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultAnnotatedHandlerBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java?rev=1213059&view=auto
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java (added)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java Sun Dec 11 20:54:14 2011
@@ -0,0 +1,54 @@
+package org.apache.commons.meiyo.classvisitor;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Map;
+
+final class DefaultLinkedHandlingBuilder<E extends AnnotatedElement, A extends Annotation>
+ implements LinkedHandlingBuilder<E, A>
+{
+
+ private final Key bindingKey;
+
+ private final Map<Key, AnnotationHandler<? extends AnnotatedElement, ? extends Annotation>> registry;
+
+ DefaultLinkedHandlingBuilder( Key bindingKey,
+ Map<Key, AnnotationHandler<? extends AnnotatedElement, ? extends Annotation>> registry )
+ {
+ this.bindingKey = bindingKey;
+ this.registry = registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void withHandler( AnnotationHandler<E, A> handler )
+ {
+ if ( handler == null )
+ {
+ throw new IllegalArgumentException( "Parameter 'handler' must not be null" );
+ }
+
+ registry.put( bindingKey, handler );
+ }
+
+}
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/DefaultLinkedHandlingBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/Key.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/Key.java?rev=1213059&r1=1213058&r2=1213059&view=diff
==============================================================================
--- commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/Key.java (original)
+++ commons/sandbox/meiyo/trunk/src/main/java/org/apache/commons/meiyo/classvisitor/Key.java Sun Dec 11 20:54:14 2011
@@ -23,6 +23,7 @@ import static java.lang.String.format;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
/**
* A {@code Key} is a support class to quickly access to {@code AnnotationHandler}s given
@@ -31,7 +32,7 @@ import java.lang.reflect.AnnotatedElemen
final class Key
{
- private final Class<? extends AnnotatedElement> annotatedElementType;
+ private final Type annotatedElementType;
private final Class<? extends Annotation> annotationType;
@@ -41,7 +42,7 @@ final class Key
* @param annotatedElementType the {@link AnnotatedElement} type
* @param annotationType the {@link Annotation} type
*/
- public Key( Class<? extends AnnotatedElement> annotatedElementType, Class<? extends Annotation> annotationType )
+ public Key( Type annotatedElementType, Class<? extends Annotation> annotationType )
{
this.annotatedElementType = annotatedElementType;
this.annotationType = annotationType;
@@ -52,7 +53,7 @@ final class Key
*
* @return the {@link AnnotatedElement} type represented by this {@code Key}.
*/
- protected Class<? extends AnnotatedElement> getAnnotatedElementType()
+ protected Type getAnnotatedElementType()
{
return annotatedElementType;
}
Modified: commons/sandbox/meiyo/trunk/src/test/java/org/apache/commons/meiyo/classvisitor/ClassVisitorTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/meiyo/trunk/src/test/java/org/apache/commons/meiyo/classvisitor/ClassVisitorTestCase.java?rev=1213059&r1=1213058&r2=1213059&view=diff
==============================================================================
--- commons/sandbox/meiyo/trunk/src/test/java/org/apache/commons/meiyo/classvisitor/ClassVisitorTestCase.java (original)
+++ commons/sandbox/meiyo/trunk/src/test/java/org/apache/commons/meiyo/classvisitor/ClassVisitorTestCase.java Sun Dec 11 20:54:14 2011
@@ -49,18 +49,18 @@ public final class ClassVisitorTestCase
@Override
public void configure()
{
- handleType().annotatedWith( ClassAnnotation.class ).withHandler( new AnnotationHandler<Class, ClassAnnotation>()
+ handleType().annotatedWith( ClassAnnotation.class ).withHandler( new AnnotationHandler<Class<?>, ClassAnnotation>()
{
- public void handle( Class annnotatedElement,
+ public void handle( Class<?> annnotatedElement,
ClassAnnotation annotation )
{
foundClassAnnotation = true;
}
} );
- handleConstructor().annotatedWith( ConstructorAnnotation.class ).withHandler( new AnnotationHandler<Constructor, ConstructorAnnotation>()
+ handleConstructor().annotatedWith( ConstructorAnnotation.class ).withHandler( new AnnotationHandler<Constructor<?>, ConstructorAnnotation>()
{
- public void handle( Constructor annnotatedElement,
+ public void handle( Constructor<?> annnotatedElement,
ConstructorAnnotation annotation )
{
foundConstructorAnnotation =