[jboss-cvs] JBossAS SVN: r95782 - projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 29 15:43:18 EDT 2009
Author: alesj
Date: 2009-10-29 15:43:17 -0400 (Thu, 29 Oct 2009)
New Revision: 95782
Modified:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
Log:
Simplify via abstraction.
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java 2009-10-29 19:29:07 UTC (rev 95781)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java 2009-10-29 19:43:17 UTC (rev 95782)
@@ -22,6 +22,7 @@
package org.jboss.mcann.repository;
import org.jboss.mcann.GroupingStrategy;
+import org.jboss.mcann.AnnotationRepository;
/**
* Abstract grouping strategy.
@@ -44,6 +45,25 @@
this.putToCache = putToCache;
}
+ public T group(AnnotationRepository repository)
+ {
+ if (repository instanceof DefaultAnnotationRepository)
+ {
+ return groupDefault(DefaultAnnotationRepository.class.cast(repository));
+ }
+ else
+ {
+ return groupGeneric(repository);
+ }
+ }
+
+ protected abstract T groupDefault(DefaultAnnotationRepository current);
+
+ protected T groupGeneric(AnnotationRepository current)
+ {
+ throw new IllegalArgumentException("Cannot handle non-default repository: " + current);
+ }
+
public Object cacheKey()
{
return getClass();
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java 2009-10-29 19:29:07 UTC (rev 95781)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java 2009-10-29 19:43:17 UTC (rev 95782)
@@ -45,24 +45,17 @@
this.repository = DefaultAnnotationRepository.class.cast(repository);
}
- public Void group(AnnotationRepository current)
+ protected Void groupDefault(DefaultAnnotationRepository current)
{
- // TODO - restrictions
-
- if (current instanceof DefaultAnnotationRepository)
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = repository.getEnv();
+ for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
{
- DefaultAnnotationRepository dar = DefaultAnnotationRepository.class.cast(current);
-
- Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = repository.getEnv();
- for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
{
- Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
- for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ for (ClassSignaturePair csp : et.getValue())
{
- for (ClassSignaturePair csp : et.getValue())
- {
- dar.putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
- }
+ current.putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
}
}
}
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java 2009-10-29 19:29:07 UTC (rev 95781)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java 2009-10-29 19:43:17 UTC (rev 95782)
@@ -46,22 +46,18 @@
super(useCache, putToCache);
}
- public Map<URL, AnnotationRepository> group(AnnotationRepository current)
+ protected Map<URL, AnnotationRepository> groupDefault(DefaultAnnotationRepository current)
{
Map<URL, AnnotationRepository> map = new HashMap<URL, AnnotationRepository>();
- if (current instanceof DefaultAnnotationRepository)
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = current.getEnv();
+ for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
{
- DefaultAnnotationRepository repository = DefaultAnnotationRepository.class.cast(current);
- Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = repository.getEnv();
- for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
{
- Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
- for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ for (ClassSignaturePair csp : et.getValue())
{
- for (ClassSignaturePair csp : et.getValue())
- {
- // TODO - group per source location
- }
+ // TODO - group per source location
}
}
}
More information about the jboss-cvs-commits
mailing list