org.tinyjee.maven.dim.utils
Class AbstractSelectableJavaEntitiesList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by org.tinyjee.maven.dim.utils.SelectableArrayList<E>
                  extended by org.tinyjee.maven.dim.utils.AbstractSelectableJavaEntitiesList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
Direct Known Subclasses:
SelectableJavaEntitiesList, SelectableMappedJavaEntitiesList

public abstract class AbstractSelectableJavaEntitiesList<E>
extends SelectableArrayList<E>

Implements a base class for selectable lists of qdox based java entities (AbstractJavaEntity) using an AOP-like expressions syntax to select classes, methods and fields.

Lists of this type may contain, classes, methods, fields or any other element that derives from the AbstractJavaEntity.

Expression samples:

The matching is implemented using regular expressions with the logic: ".." translates to ".*($|\.|\$)" outside an argument list, to ".*" inside an argument list and "*" translates to "[^\s\.\$]*". All other characters are escaped and matched as specified with the exception that modifiers (e.g. public) and the character "@" get special treatment to get rid of ordering problems.
The following example illustrates how java entities are converted to strings that are then matched with regular expressions:

Note: The selection logic that this list implements is similar to the logic used in AOP but it is not the same in order reduce the overall complexity.

Author:
Juergen_Kellerer, 2011-10-10
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.tinyjee.maven.dim.utils.SelectableArrayList
SelectableArrayList.Selector<E>
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected AbstractSelectableJavaEntitiesList()
           
protected AbstractSelectableJavaEntitiesList(Collection<? extends E> collection)
           
 
Method Summary
 Map<String,E> asMap()
          Converts this list to a map view where elements are mapped against their simple name.
 AbstractSelectableJavaEntitiesList<E> clone()
           
static boolean isAnnotation(JavaClass javaClass)
          Returns true if the given java class is an annotation.
 AbstractSelectableJavaEntitiesList<E> selectAnnotated(String annotationNameExpression)
          Selects all java entities that are annotated with an annotation that is matching the given AOP-like expression.
 AbstractSelectableJavaEntitiesList<E> selectDerived(String classNameExpression)
          Selects all java entities that derive from a class that is matching the given AOP-like expression.
 AbstractSelectableJavaEntitiesList<E> selectMatching(String entityExpression)
          Selects all java entities that match the given AOP-like expression.
 AbstractSelectableJavaEntitiesList<E> selectNonAnnotated(String annotationNameExpression)
          Selects all java entities that are not annotated with an annotation that is matching the given AOP-like expression.
 AbstractSelectableJavaEntitiesList<E> selectNonDerived(String classNameExpression)
          Selects all java entities that do not derive from a class that is matching the given AOP-like expression.
 AbstractSelectableJavaEntitiesList<E> selectNonMatching(String entityExpression)
          Selects all java entities that do not match the given AOP-like expression.
protected abstract  Object unwrap(E element)
          Unwraps the given list element to something that can be converted to a valid AbstractJavaEntity inside unwrapToEntity(Object).
protected  AbstractJavaEntity unwrapToEntity(E element)
          Converts the given list element to AbstractJavaEntity.
 
Methods inherited from class org.tinyjee.maven.dim.utils.SelectableArrayList
createInvertSelector, createOrSelector, createRegularExpressionSelector, select, selectMatching
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

AbstractSelectableJavaEntitiesList

protected AbstractSelectableJavaEntitiesList()

AbstractSelectableJavaEntitiesList

protected AbstractSelectableJavaEntitiesList(Collection<? extends E> collection)
Method Detail

unwrap

protected abstract Object unwrap(E element)
Unwraps the given list element to something that can be converted to a valid AbstractJavaEntity inside unwrapToEntity(Object).

Parameters:
element - the list element to unwrap.
Returns:
the raw JavaEntity or compatible instance of the behind the list element.

unwrapToEntity

protected final AbstractJavaEntity unwrapToEntity(E element)
Converts the given list element to AbstractJavaEntity.

Parameters:
element - the element to convert.
Returns:
the corresponding AbstractJavaEntity or 'null' if not available.

clone

public AbstractSelectableJavaEntitiesList<E> clone()
Overrides:
clone in class SelectableArrayList<E>

asMap

public Map<String,E> asMap()
Converts this list to a map view where elements are mapped against their simple name. If this list contains methods, the methods are mapped with simple name AND full call signature (2 keys for 1 element). If java methods are overloaded, the last occurrence will be accessible via the simple name.

Returns:
A map view of this list.

selectMatching

public AbstractSelectableJavaEntitiesList<E> selectMatching(String entityExpression)
Selects all java entities that match the given AOP-like expression.

Note: Prefixing the expression with "!" inverts the meaning.

Overrides:
selectMatching in class SelectableArrayList<E>
Parameters:
entityExpression - an expression that matches entities contained in this list.
Returns:
all java entities that match the given AOP-like expression.

selectNonMatching

public AbstractSelectableJavaEntitiesList<E> selectNonMatching(String entityExpression)
Selects all java entities that do not match the given AOP-like expression.

Note: Prefixing the expression with "!" inverts the meaning.

Overrides:
selectNonMatching in class SelectableArrayList<E>
Parameters:
entityExpression - an expression that matches entities contained in this list.
Returns:
all java entities that do not match the given AOP-like expression.

selectDerived

public AbstractSelectableJavaEntitiesList<E> selectDerived(String classNameExpression)
Selects all java entities that derive from a class that is matching the given AOP-like expression.

Parameters:
classNameExpression - an expression matching a super class or interface.
Returns:
all java entities that derive from a class that is matching the given AOP-like expression.

selectNonDerived

public AbstractSelectableJavaEntitiesList<E> selectNonDerived(String classNameExpression)
Selects all java entities that do not derive from a class that is matching the given AOP-like expression.

Parameters:
classNameExpression - an expression matching a super class or interface that must not be present in selected classes.
Returns:
all java entities that do not derive from a class that is matching the given AOP-like expression.

selectAnnotated

public AbstractSelectableJavaEntitiesList<E> selectAnnotated(String annotationNameExpression)
Selects all java entities that are annotated with an annotation that is matching the given AOP-like expression.

Parameters:
annotationNameExpression - an expression matching an annotation (optionally including key & value pairs in method braces).
Returns:
all java entities that are annotated with an annotation that is matching the given AOP-like expression.

selectNonAnnotated

public AbstractSelectableJavaEntitiesList<E> selectNonAnnotated(String annotationNameExpression)
Selects all java entities that are not annotated with an annotation that is matching the given AOP-like expression.

Parameters:
annotationNameExpression - an expression matching an annotation (optionally including key & value pairs in method braces).
Returns:
all java entities that are not annotated with an annotation that is matching the given AOP-like expression.

isAnnotation

public static boolean isAnnotation(JavaClass javaClass)
Returns true if the given java class is an annotation.

Parameters:
javaClass - the class to test.
Returns:
true if the given java class is an annotation.