|
Mirror API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.mirror.util.DeclarationFilter
public class DeclarationFilter
A filter for selecting just the items of interest from a collection of declarations. The filter is said to select or to match those declarations. Filters can be created in several ways: by the static methods described below, by negating or composing existing filters, or by subclasses that implement arbitrary matching rules.
A subclass can create an arbitrary filter simply by implementing
the matches(Declaration)
method.
Examples.
Selecting the public declarations from a collection:
Selecting class declarations (including enums):result = FILTER_PUBLIC.filter(decls);
Selecting class declarations but excluding enums:classFilter = DeclarationFilter.getFilter(ClassDeclaration.class); result = classFilter.filter(decls);
Selecting declarations named "Bob":enumFilter = DeclarationFilter.getFilter(EnumDeclaration.class); compoundFilter = classFilter.and(enumFilter.not()); result = compoundFilter.filter(decls);
nameFilter = new DeclarationFilter() { public boolean matches(Declaration d) { return d.getSimpleName().equals("Bob"); } }; result = nameFilter.filter(decls);
Field Summary | |
---|---|
static DeclarationFilter |
FILTER_PACKAGE
A filter that selects only package-private (default) declarations. |
static DeclarationFilter |
FILTER_PRIVATE
A filter that selects only private declarations. |
static DeclarationFilter |
FILTER_PROTECTED
A filter that selects only protected declarations. |
static DeclarationFilter |
FILTER_PUBLIC
A filter that selects only public declarations. |
static DeclarationFilter |
FILTER_PUBLIC_OR_PROTECTED
A filter that selects only public or protected declarations. |
Constructor Summary | |
---|---|
DeclarationFilter()
Constructs an identity filter: one that selects all declarations. |
Method Summary | ||
---|---|---|
DeclarationFilter |
and(DeclarationFilter f)
Returns a filter that selects those declarations selected by both this filter and another. |
|
|
filter(Collection<? extends Declaration> decls,
Class<D> resType)
Returns the declarations matched by this filter, with the result being restricted to declarations of a given kind. |
|
|
filter(Collection<D> decls)
Returns the declarations matched by this filter. |
|
static DeclarationFilter |
getFilter(Class<? extends Declaration> kind)
Returns a filter that selects declarations of a particular kind. |
|
static DeclarationFilter |
getFilter(Collection<Modifier> mods)
Returns a filter that selects declarations containing all of a collection of modifiers. |
|
boolean |
matches(Declaration decl)
Tests whether this filter matches a given declaration. |
|
DeclarationFilter |
not()
Returns a filter that selects those declarations not selected by this filter. |
|
DeclarationFilter |
or(DeclarationFilter f)
Returns a filter that selects those declarations selected by either this filter or another. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final DeclarationFilter FILTER_PUBLIC
public static final DeclarationFilter FILTER_PROTECTED
public static final DeclarationFilter FILTER_PUBLIC_OR_PROTECTED
public static final DeclarationFilter FILTER_PACKAGE
public static final DeclarationFilter FILTER_PRIVATE
Constructor Detail |
---|
public DeclarationFilter()
Method Detail |
---|
public static DeclarationFilter getFilter(Collection<Modifier> mods)
mods
- the modifiers to match (non-null)
public static DeclarationFilter getFilter(Class<? extends Declaration> kind)
kind
- the kind of declarations to select
public DeclarationFilter and(DeclarationFilter f)
f
- filter to be composed with this one
public DeclarationFilter or(DeclarationFilter f)
f
- filter to be composed with this one
public DeclarationFilter not()
public boolean matches(Declaration decl)
decl
- the declaration to match
public <D extends Declaration> Collection<D> filter(Collection<D> decls)
D
- type of the declarations being filtereddecls
- declarations being filtered
public <D extends Declaration> Collection<D> filter(Collection<? extends Declaration> decls, Class<D> resType)
D
- type of the declarations being returneddecls
- declarations being filteredresType
- type of the declarations being returned --
the reflective view of D
|
Mirror API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |