public class DeclarationFilter extends Object
A subclass can create an arbitrary filter simply by implementing
the matches(Declaration) method.
Examples.
Selecting the public declarations from a collection:
result = FILTER_PUBLIC.filter(decls);
Selecting class declarations (including enums):
classFilter = DeclarationFilter.getFilter(ClassDeclaration.class);
result = classFilter.filter(decls);
Selecting class declarations but excluding enums:
enumFilter = DeclarationFilter.getFilter(EnumDeclaration.class);
compoundFilter = classFilter.and(enumFilter.not());
result = compoundFilter.filter(decls);
Selecting declarations named "Bob":
nameFilter = new DeclarationFilter() {
public boolean matches(Declaration d) {
return d.getSimpleName().equals("Bob");
}
};
result = nameFilter.filter(decls); | Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
DeclarationFilter()
Constructs an identity filter: one that selects all declarations.
|
| Modifier and Type | Method and Description |
|---|---|
DeclarationFilter |
and(DeclarationFilter f)
Returns a filter that selects those declarations selected
by both this filter and another.
|
<D extends Declaration> |
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.
|
<D extends Declaration> |
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.
|
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
public DeclarationFilter()
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 selectpublic DeclarationFilter and(DeclarationFilter f)
f - filter to be composed with this onepublic DeclarationFilter or(DeclarationFilter f)
f - filter to be composed with this onepublic DeclarationFilter not()
public boolean matches(Declaration decl)
decl - the declaration to matchpublic <D extends Declaration> Collection<D> filter(Collection<D> decls)
D - type of the declarations being filtereddecls - declarations being filteredpublic <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 DCopyright (c) IBM Corp. and others 2000, 2006. All Rights Reserved.