ElementFilter
.@Deprecated 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:
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);
Modifier and Type | Field and Description |
---|---|
static DeclarationFilter |
FILTER_PACKAGE
Deprecated.
A filter that selects only package-private (default)
declarations.
|
static DeclarationFilter |
FILTER_PRIVATE
Deprecated.
A filter that selects only private declarations.
|
static DeclarationFilter |
FILTER_PROTECTED
Deprecated.
A filter that selects only protected declarations.
|
static DeclarationFilter |
FILTER_PUBLIC
Deprecated.
A filter that selects only public declarations.
|
static DeclarationFilter |
FILTER_PUBLIC_OR_PROTECTED
Deprecated.
A filter that selects only public or protected
declarations.
|
Constructor and Description |
---|
DeclarationFilter()
Deprecated.
Constructs an identity filter: one that selects all declarations.
|
Modifier and Type | Method and Description |
---|---|
DeclarationFilter |
and(DeclarationFilter f)
Deprecated.
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)
Deprecated.
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)
Deprecated.
Returns the declarations matched by this filter.
|
static DeclarationFilter |
getFilter(Class<? extends Declaration> kind)
Deprecated.
Returns a filter that selects declarations of a particular kind.
|
static DeclarationFilter |
getFilter(Collection<Modifier> mods)
Deprecated.
Returns a filter that selects declarations containing all of a
collection of modifiers.
|
boolean |
matches(Declaration decl)
Deprecated.
Tests whether this filter matches a given declaration.
|
DeclarationFilter |
not()
Deprecated.
Returns a filter that selects those declarations not selected
by this filter.
|
DeclarationFilter |
or(DeclarationFilter f)
Deprecated.
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 D
Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved.