You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2013/05/04 00:52:18 UTC
svn commit: r1479001 - in /commons/sandbox/weaver/trunk/processor/src:
main/java/org/apache/commons/weaver/
main/java/org/apache/commons/weaver/model/
test/java/org/apache/commons/weaver/
test/java/org/apache/commons/weaver/test/ test/java/org/apache/c...
Author: mbenson
Date: Fri May 3 22:52:17 2013
New Revision: 1479001
URL: http://svn.apache.org/r1479001
Log:
add ability to scan for subclasses and interface implementations
Added:
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java (with props)
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java (with props)
Modified:
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanRequest.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanResult.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java Fri May 3 22:52:17 2013
@@ -205,12 +205,10 @@ class Finder extends AnnotationFinder im
}
private List<Annotation> classfileAnnotationsFor(Info info) {
- synchronized (CLASSFILE_ANNOTATIONS) {
- if (!CLASSFILE_ANNOTATIONS.get().containsKey(info)) {
- final List<Annotation> result = new ArrayList<Annotation>();
- CLASSFILE_ANNOTATIONS.get().put(info, result);
- return result;
- }
+ if (!CLASSFILE_ANNOTATIONS.get().containsKey(info)) {
+ final List<Annotation> result = new ArrayList<Annotation>();
+ CLASSFILE_ANNOTATIONS.get().put(info, result);
+ return result;
}
return CLASSFILE_ANNOTATIONS.get().get(info);
}
@@ -325,6 +323,29 @@ class Finder extends AnnotationFinder im
return result;
}
+ public List<Annotated<Class<?>>> findAssignableTypes(Class<?> supertype) {
+ final List<Annotated<Class<?>>> result = new ArrayList<Annotated<Class<?>>>();
+ final List<?> assignableTypes;
+ if (supertype.isInterface()) {
+ assignableTypes = Finder.this.findImplementations(supertype);
+ } else {
+ assignableTypes = Finder.this.findSubclasses(supertype);
+ }
+
+ for (Object object : assignableTypes) {
+ final ClassInfo classInfo = classInfos.get(((Class<?>) object).getName());
+ final IncludesClassfile<Class<?>> annotated;
+ try {
+ annotated =
+ new IncludesClassfile<Class<?>>(classInfo.get(), classfileAnnotationsFor(classInfo));
+ } catch (ClassNotFoundException e) {
+ continue;
+ }
+ result.add(annotated);
+ }
+ return result;
+ }
+
public List<Annotated<Method>> findAnnotatedMethods(Class<? extends Annotation> annotation) {
Finder.this.findAnnotatedMethods(annotation);
final List<Annotated<Method>> result = new ArrayList<Annotated<Method>>();
@@ -468,6 +489,11 @@ class Finder extends AnnotationFinder im
private static final int ASM_FLAGS = ClassReader.SKIP_CODE + ClassReader.SKIP_DEBUG + ClassReader.SKIP_FRAMES;
+ /**
+ * The {@link #classfileAnnotations} member stores these; however the scanning takes place in the scope of the super
+ * constructor call, thus there is no opportunity to set the reference beforehand. To work around this, we use a
+ * static ThreadLocal with an initializer and pull/clear its value when we return from the super constructor. :P
+ */
private static final ThreadLocal<Map<Info, List<Annotation>>> CLASSFILE_ANNOTATIONS =
new ThreadLocal<Map<Info, List<Annotation>>>() {
protected java.util.Map<Info, java.util.List<Annotation>> initialValue() {
@@ -475,37 +501,20 @@ class Finder extends AnnotationFinder im
}
};
- private Class<?> toClass(Type type) {
- final String className = (type.getSort() == Type.ARRAY ? type.getElementType() : type).getClassName();
- Class<?> result;
- try {
- result = Class.forName(className);
- } catch (ClassNotFoundException e) {
- try {
- result = getArchive().loadClass(className);
- } catch (ClassNotFoundException e1) {
- throw new RuntimeException(e1);
- }
- }
- if (type.getSort() == Type.ARRAY) {
- int[] dims = new int[type.getDimensions()];
- Arrays.fill(dims, 0);
- result = Array.newInstance(result, dims).getClass();
- }
- return result;
- }
-
private final Map<Info, List<Annotation>> classfileAnnotations;
private final WithAnnotations withAnnotations = new WithAnnotations();
/**
* Create a new {@link Finder} instance.
+ *
* @param archive
*/
public Finder(Archive archive) {
super(archive, false);
classfileAnnotations = CLASSFILE_ANNOTATIONS.get();
CLASSFILE_ANNOTATIONS.remove();
+ enableFindImplementations();
+ enableFindSubclasses();
}
public WithAnnotations withAnnotations() {
@@ -542,51 +551,77 @@ class Finder extends AnnotationFinder im
for (WeaveInterest interest : request.getInterests()) {
switch (interest.target) {
- case PACKAGE:
- for (Annotated<Package> pkg : this.withAnnotations().findAnnotatedPackages(interest.annotationType)) {
- result.getWeavable(pkg.get()).addAnnotations(pkg.getAnnotation(interest.annotationType));
- }
- case TYPE:
- for (Annotated<Class<?>> type : this.withAnnotations().findAnnotatedClasses(interest.annotationType)) {
- result.getWeavable(type.get()).addAnnotations(type.getAnnotation(interest.annotationType));
- }
- break;
- case METHOD:
- for (Annotated<Method> method : this.withAnnotations().findAnnotatedMethods(interest.annotationType)) {
- result.getWeavable(method.get()).addAnnotations(method.getAnnotation(interest.annotationType));
- }
- break;
- case CONSTRUCTOR:
- for (Annotated<Constructor<?>> cs : this.withAnnotations().findAnnotatedConstructors(
- interest.annotationType)) {
- result.getWeavable(cs.get()).addAnnotations(cs.getAnnotation(interest.annotationType));
- }
- break;
- case FIELD:
- for (Annotated<Field> fld : this.withAnnotations().findAnnotatedFields(interest.annotationType)) {
- result.getWeavable(fld.get()).addAnnotations(fld.getAnnotation(interest.annotationType));
- }
- break;
- case PARAMETER:
- for (Annotated<Parameter<Method>> parameter : this.withAnnotations().findAnnotatedMethodParameters(
- interest.annotationType)) {
- result.getWeavable(parameter.get().getDeclaringExecutable())
- .getWeavableParameter(parameter.get().getIndex())
- .addAnnotations(parameter.getAnnotation(interest.annotationType));
- }
- for (Annotated<Parameter<Constructor<?>>> parameter : this.withAnnotations()
- .findAnnotatedConstructorParameters(interest.annotationType)) {
- result.getWeavable(parameter.get().getDeclaringExecutable())
- .getWeavableParameter(parameter.get().getIndex())
- .addAnnotations(parameter.getAnnotation(interest.annotationType));
- }
- break;
- default:
- // should we log something?
- break;
+ case PACKAGE:
+ for (Annotated<Package> pkg : this.withAnnotations().findAnnotatedPackages(interest.annotationType)) {
+ result.getWeavable(pkg.get()).addAnnotations(pkg.getAnnotations());
+ }
+ case TYPE:
+ for (Annotated<Class<?>> type : this.withAnnotations()
+ .findAnnotatedClasses(interest.annotationType)) {
+ result.getWeavable(type.get()).addAnnotations(type.getAnnotations());
+ }
+ break;
+ case METHOD:
+ for (Annotated<Method> method : this.withAnnotations()
+ .findAnnotatedMethods(interest.annotationType)) {
+ result.getWeavable(method.get()).addAnnotations(method.getAnnotations());
+ }
+ break;
+ case CONSTRUCTOR:
+ for (Annotated<Constructor<?>> cs : this.withAnnotations().findAnnotatedConstructors(
+ interest.annotationType)) {
+ result.getWeavable(cs.get()).addAnnotations(cs.getAnnotations());
+ }
+ break;
+ case FIELD:
+ for (Annotated<Field> fld : this.withAnnotations().findAnnotatedFields(interest.annotationType)) {
+ result.getWeavable(fld.get()).addAnnotations(fld.getAnnotations());
+ }
+ break;
+ case PARAMETER:
+ for (Annotated<Parameter<Method>> parameter : this.withAnnotations().findAnnotatedMethodParameters(
+ interest.annotationType)) {
+ result.getWeavable(parameter.get().getDeclaringExecutable())
+ .getWeavableParameter(parameter.get().getIndex())
+ .addAnnotations(parameter.getAnnotations());
+ }
+ for (Annotated<Parameter<Constructor<?>>> parameter : this.withAnnotations()
+ .findAnnotatedConstructorParameters(interest.annotationType)) {
+ result.getWeavable(parameter.get().getDeclaringExecutable())
+ .getWeavableParameter(parameter.get().getIndex())
+ .addAnnotations(parameter.getAnnotations());
+ }
+ break;
+ default:
+ // should we log something?
+ break;
+ }
+ for (Class<?> supertype : request.getSupertypes()) {
+ for (Annotated<Class<?>> type : this.withAnnotations().findAssignableTypes(supertype)) {
+ result.getWeavable(type.get()).addAnnotations(type.getAnnotations());
+ }
}
}
return result;
}
+ private Class<?> toClass(Type type) {
+ final String className = (type.getSort() == Type.ARRAY ? type.getElementType() : type).getClassName();
+ Class<?> result;
+ try {
+ result = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ try {
+ result = getArchive().loadClass(className);
+ } catch (ClassNotFoundException e1) {
+ throw new RuntimeException(e1);
+ }
+ }
+ if (type.getSort() == Type.ARRAY) {
+ int[] dims = new int[type.getDimensions()];
+ Arrays.fill(dims, 0);
+ result = Array.newInstance(result, dims).getClass();
+ }
+ return result;
+ }
}
Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanRequest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanRequest.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanRequest.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanRequest.java Fri May 3 22:52:17 2013
@@ -21,14 +21,22 @@ package org.apache.commons.weaver.model;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.weaver.spi.Cleaner;
+import org.apache.commons.weaver.spi.Weaver;
/**
- * Weave plan, extensible in future to include e.g. scanning strategy hints.
+ * Scan request object describing the types of elements in which a given {@link Weaver} or {@link Cleaner} is
+ * interested.
*/
public class ScanRequest {
private final List<WeaveInterest> interests = new ArrayList<WeaveInterest>();
+ private final Set<Class<?>> supertypes = new LinkedHashSet<Class<?>>();
public ScanRequest add(WeaveInterest interest) {
if (interest == null) {
@@ -38,7 +46,17 @@ public class ScanRequest {
return this;
}
+ public ScanRequest addSupertypes(Class<?>... types) {
+ Collections.addAll(supertypes, Validate.noNullElements(types, "null element at [%s]"));
+ return this;
+ }
+
public Iterable<WeaveInterest> getInterests() {
return Collections.unmodifiableList(interests);
}
+
+ public Set<Class<?>> getSupertypes() {
+ return Collections.unmodifiableSet(supertypes);
+ }
+
}
Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanResult.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanResult.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanResult.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/ScanResult.java Fri May 3 22:52:17 2013
@@ -29,6 +29,7 @@ import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
+import org.apache.commons.lang3.Validate;
import org.apache.commons.weaver.WeaveProcessor;
import org.apache.commons.weaver.spi.Weaver;
@@ -52,7 +53,7 @@ import org.apache.commons.weaver.spi.Wea
*/
public class ScanResult {
private static abstract class Projection<PARENT, CHILD extends AnnotatedElement> implements
- AnnotatedElements<CHILD> {
+ AnnotatedElements<CHILD> {
private final Iterable<PARENT> parents;
Projection(Iterable<PARENT> parents) {
@@ -167,7 +168,8 @@ public class ScanResult {
}
- private final ConcurrentNavigableMap<String, WeavablePackage> packages = new ConcurrentSkipListMap<String, WeavablePackage>();
+ private final ConcurrentNavigableMap<String, WeavablePackage> packages =
+ new ConcurrentSkipListMap<String, WeavablePackage>();
/**
* Public for use by {@link WeaveProcessor}.
@@ -250,6 +252,60 @@ public class ScanResult {
};
}
+ public AnnotatedElements<WeavableClass<?>> getClassesAssignableTo(final Class<?> supertype) {
+ Validate.notNull(supertype, "supertype");
+
+ return new Projection<WeavablePackage, WeavableClass<?>>(getPackages()) {
+
+ @Override
+ protected Iterable<WeavableClass<?>> childrenOf(WeavablePackage parent) {
+ return parent.getClasses();
+ }
+
+ @Override
+ public Iterator<WeavableClass<?>> iterator() {
+ final Iterator<WeavableClass<?>> toWrap = super.iterator();
+ return new Iterator<WeavableClass<?>>() {
+ {
+ read();
+ }
+
+ private WeavableClass<?> next;
+
+ private void read() {
+ while (toWrap.hasNext()) {
+ final WeavableClass<?> test = toWrap.next();
+ if (supertype.isAssignableFrom(test.getTarget())) {
+ next = test;
+ return;
+ }
+ }
+ next = null;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next != null;
+ }
+
+ @Override
+ public WeavableClass<?> next() {
+ try {
+ return next;
+ } finally {
+ read();
+ }
+ }
+
+ @Override
+ public void remove() {
+ toWrap.remove();
+ }
+ };
+ }
+ };
+ }
+
public AnnotatedElements<WeavableField<?>> getFields() {
return new Projection<WeavableClass<?>, WeavableField<?>>(getClasses()) {
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java Fri May 3 22:52:17 2013
@@ -15,13 +15,19 @@ import java.lang.reflect.Field;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.weaver.test.WeaverTestBase;
+import org.apache.commons.weaver.test.beans.AbstractTestBean;
import org.apache.commons.weaver.test.beans.ComplexAnnotations;
import org.apache.commons.weaver.test.beans.ComplexAnnotations.NestAnnotation;
import org.apache.commons.weaver.test.beans.ComplexAnnotations.Stooge;
import org.apache.commons.weaver.test.beans.ComplexAnnotations.TestAnnotation;
+import org.apache.commons.weaver.test.beans.TestBeanInterface;
+import org.apache.commons.weaver.test.beans.TestBeanWithClassAnnotation;
+import org.apache.commons.weaver.test.beans.TestBeanWithMethodAnnotation;
import org.apache.commons.weaver.utils.URLArray;
import org.apache.xbean.finder.Annotated;
import org.apache.xbean.finder.archive.FileArchive;
@@ -235,4 +241,27 @@ public class FinderTest extends WeaverTe
assertTrue(anno.equals(anno));
}
}
+
+ @Test
+ public void testFindAssignableTypes() throws IOException {
+ addClassForScanning(TestBeanInterface.class);
+ addClassForScanning(AbstractTestBean.class);
+ addClassForScanning(TestBeanWithClassAnnotation.class);
+ addClassForScanning(TestBeanWithMethodAnnotation.class);
+
+ final Set<Class<?>> implementors = new HashSet<Class<?>>();
+ for (Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(TestBeanInterface.class)) {
+ implementors.add(annotated.get());
+ }
+ assertEquals(1, implementors.size());
+ assertTrue(implementors.contains(TestBeanWithClassAnnotation.class));
+
+ final Set<Class<?>> subclasses = new HashSet<Class<?>>();
+ for (Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(AbstractTestBean.class)) {
+ subclasses.add(annotated.get());
+ }
+ assertEquals(2, subclasses.size());
+ assertTrue(subclasses.contains(TestBeanWithClassAnnotation.class));
+ assertTrue(subclasses.contains(TestBeanWithMethodAnnotation.class));
+ }
}
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java Fri May 3 22:52:17 2013
@@ -18,6 +18,7 @@
*/
package org.apache.commons.weaver.test;
+import java.util.Arrays;
import java.util.Properties;
import org.apache.commons.weaver.test.beans.TestBeanWithClassAnnotation;
@@ -53,5 +54,12 @@ public class WeaveProcessorTest extends
Assert.assertEquals(1, TestWeaver.wovenMethods.size());
Assert.assertEquals(TestBeanWithMethodAnnotation.class, TestWeaver.wovenMethods.get(0).getDeclaringClass());
+
+ Assert.assertEquals(1, TestWeaver.implementors.size());
+ Assert.assertEquals(TestBeanWithClassAnnotation.class, TestWeaver.implementors.get(0));
+
+ Assert.assertEquals(2, TestWeaver.subclasses.size());
+ Assert.assertTrue(TestWeaver.subclasses.containsAll(Arrays.<Class<?>> asList(
+ TestBeanWithClassAnnotation.class, TestBeanWithMethodAnnotation.class)));
}
}
Added: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java?rev=1479001&view=auto
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java (added)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java Fri May 3 22:52:17 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.commons.weaver.test.beans;
+
+public abstract class AbstractTestBean {
+
+}
Propchange: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java
------------------------------------------------------------------------------
svn:executable = *
Added: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java?rev=1479001&view=auto
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java (added)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java Fri May 3 22:52:17 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.commons.weaver.test.beans;
+
+public interface TestBeanInterface {
+
+}
Propchange: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java
------------------------------------------------------------------------------
svn:executable = *
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java Fri May 3 22:52:17 2013
@@ -22,8 +22,8 @@ package org.apache.commons.weaver.test.b
* Simple test bean
*/
@TestAnnotation
-public class TestBeanWithClassAnnotation
-{
+public class TestBeanWithClassAnnotation extends AbstractTestBean implements TestBeanInterface {
+ @SuppressWarnings("unused")
private int someMethod() {
return 42;
}
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java Fri May 3 22:52:17 2013
@@ -21,13 +21,13 @@ package org.apache.commons.weaver.test.b
/**
* Simple test bean
*/
-public class TestBeanWithMethodAnnotation
-{
+public class TestBeanWithMethodAnnotation extends AbstractTestBean {
@TestAnnotation
private int annotatedMethod() {
return 42;
}
+ @SuppressWarnings("unused")
private int nonAnnotatedMethod() {
return 21;
}
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java?rev=1479001&r1=1479000&r2=1479001&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java Fri May 3 22:52:17 2013
@@ -31,14 +31,19 @@ import org.apache.commons.weaver.model.W
import org.apache.commons.weaver.model.WeaveEnvironment;
import org.apache.commons.weaver.model.WeaveInterest;
import org.apache.commons.weaver.spi.Weaver;
+import org.apache.commons.weaver.test.beans.AbstractTestBean;
import org.apache.commons.weaver.test.beans.TestAnnotation;
+import org.apache.commons.weaver.test.beans.TestBeanInterface;
import org.junit.Assert;
/**
+ *
*/
public class TestWeaver implements Weaver {
public static List<Method> wovenMethods = new ArrayList<Method>();
public static List<Class<?>> wovenClasses = new ArrayList<Class<?>>();
+ public static List<Class<?>> implementors = new ArrayList<Class<?>>();
+ public static List<Class<?>> subclasses = new ArrayList<Class<?>>();
@Override
public boolean process(WeaveEnvironment environment, Scanner scanner) {
@@ -51,8 +56,9 @@ public class TestWeaver implements Weave
boolean result = false;
final ScanRequest scanRequest =
- new ScanRequest().add(WeaveInterest.of(TestAnnotation.class, ElementType.TYPE)).add(
- WeaveInterest.of(TestAnnotation.class, ElementType.METHOD));
+ new ScanRequest().add(WeaveInterest.of(TestAnnotation.class, ElementType.TYPE))
+ .add(WeaveInterest.of(TestAnnotation.class, ElementType.METHOD))
+ .addSupertypes(AbstractTestBean.class, TestBeanInterface.class);
final ScanResult scanResult = scanner.scan(scanRequest);
@@ -66,6 +72,16 @@ public class TestWeaver implements Weave
result = true;
}
}
+ for (WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(TestBeanInterface.class)) {
+ if (implementors.add(weavableClass.getTarget())) {
+ result = true;
+ }
+ }
+ for (WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(AbstractTestBean.class)) {
+ if (subclasses.add(weavableClass.getTarget())) {
+ result = true;
+ }
+ }
return result;
}