Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse JDT
Release 3.5

com.sun.mirror.util
Class DeclarationFilter

java.lang.Object
  extended by 
com.sun.mirror.util.DeclarationFilter

public class DeclarationFilter
extends Object

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:

     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);         

Since:
1.5

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.
<D extends Declaration>
Collection<D>
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>
Collection<D>
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

FILTER_PUBLIC

public static final 
DeclarationFilter FILTER_PUBLIC
A filter that selects only public declarations.


FILTER_PROTECTED

public static final 
DeclarationFilter FILTER_PROTECTED
A filter that selects only protected declarations.


FILTER_PUBLIC_OR_PROTECTED

public static final 
DeclarationFilter FILTER_PUBLIC_OR_PROTECTED
A filter that selects only public or protected declarations.


FILTER_PACKAGE

public static final 
DeclarationFilter FILTER_PACKAGE
A filter that selects only package-private (default) declarations.


FILTER_PRIVATE

public static final 
DeclarationFilter FILTER_PRIVATE
A filter that selects only private declarations.

Constructor Detail

DeclarationFilter

public DeclarationFilter()
Constructs an identity filter: one that selects all declarations.

Method Detail

getFilter

public static 
DeclarationFilter getFilter(
Collection<
Modifier> mods)
Returns a filter that selects declarations containing all of a collection of modifiers.

Parameters:
mods - the modifiers to match (non-null)
Returns:
a filter that matches declarations containing mods

getFilter

public static 
DeclarationFilter getFilter(
Class<? extends 
Declaration> kind)
Returns a filter that selects declarations of a particular kind. For example, there may be a filter that selects only class declarations, or only fields. The filter will select declarations of the specified kind, and also any subtypes of that kind; for example, a field filter will also select enum constants.

Parameters:
kind - the kind of declarations to select
Returns:
a filter that selects declarations of a particular kind

and

public 
DeclarationFilter and(
DeclarationFilter f)
Returns a filter that selects those declarations selected by both this filter and another.

Parameters:
f - filter to be composed with this one
Returns:
a filter that selects those declarations selected by both this filter and another

or

public 
DeclarationFilter or(
DeclarationFilter f)
Returns a filter that selects those declarations selected by either this filter or another.

Parameters:
f - filter to be composed with this one
Returns:
a filter that selects those declarations selected by either this filter or another

not

public 
DeclarationFilter not()
Returns a filter that selects those declarations not selected by this filter.

Returns:
a filter that selects those declarations not selected by this filter

matches

public boolean matches(
Declaration decl)
Tests whether this filter matches a given declaration. The default implementation always returns true; subclasses should override this.

Parameters:
decl - the declaration to match
Returns:
true if this filter matches the given declaration

filter

public <D extends 
Declaration> 
Collection<D> filter(
Collection<D> decls)
Returns the declarations matched by this filter. The result is a collection of the same type as the argument; the two-parameter version of filter offers control over the result type.

Type Parameters:
D - type of the declarations being filtered
Parameters:
decls - declarations being filtered
Returns:
the declarations matched by this filter

filter

public <D extends 
Declaration> 
Collection<D> 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. Similar to the simpler single-parameter version of filter, but the result type is specified explicitly.

Type Parameters:
D - type of the declarations being returned
Parameters:
decls - declarations being filtered
resType - type of the declarations being returned -- the reflective view of D
Returns:
the declarations matched by this filter, restricted to those of the specified type

Eclipse JDT
Release 3.5

Copyright (c) IBM Corp. and others 2000, 2008. All Rights Reserved.

 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire